From 31e65061ca3bc6da1f9985746e7e70efdee9a347 Mon Sep 17 00:00:00 2001 From: phith0n Date: Wed, 10 Apr 2024 02:20:48 +0800 Subject: [PATCH] finished all attrs --- class/attr_module_main_class.go | 24 ++++++++++++++++++++++++ class/attr_module_packages.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 class/attr_module_main_class.go create mode 100644 class/attr_module_packages.go diff --git a/class/attr_module_main_class.go b/class/attr_module_main_class.go new file mode 100644 index 0000000..87ac1bd --- /dev/null +++ b/class/attr_module_main_class.go @@ -0,0 +1,24 @@ +package class + +import ( + "encoding/binary" + "fmt" + "github.com/phith0n/zkar/commons" +) + +// AttrModuleMainClass https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.27 +type AttrModuleMainClass struct { + *AttributeBase + + MainClassIndex uint16 +} + +func (a *AttrModuleMainClass) readInfo(stream *commons.Stream) error { + bs, err := stream.ReadN(2) + if err != nil { + return fmt.Errorf("read AttrModuleMainClass failed, no enough data in the stream") + } + + a.MainClassIndex = binary.BigEndian.Uint16(bs) + return nil +} diff --git a/class/attr_module_packages.go b/class/attr_module_packages.go new file mode 100644 index 0000000..4a6eff5 --- /dev/null +++ b/class/attr_module_packages.go @@ -0,0 +1,33 @@ +package class + +import ( + "encoding/binary" + "fmt" + "github.com/phith0n/zkar/commons" +) + +// AttrModulePackages https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.26 +type AttrModulePackages struct { + *AttributeBase + + PackageIndex []uint16 +} + +func (a *AttrModulePackages) readInfo(stream *commons.Stream) error { + bs, err := stream.ReadN(2) + if err != nil { + return fmt.Errorf("read AttrModulePackages failed, no enough data in the stream") + } + + length := binary.BigEndian.Uint16(bs) + for i := uint16(0); i < length; i++ { + bs, err = stream.ReadN(2) + if err != nil { + return fmt.Errorf("read AttrModulePackages[%d] failed, no enough data in the stream", i) + } + + a.PackageIndex = append(a.PackageIndex, binary.BigEndian.Uint16(bs)) + } + + return nil +}