Skip to content

Commit

Permalink
added some attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
phith0n committed Apr 3, 2024
1 parent d9b3e4d commit eea28d9
Show file tree
Hide file tree
Showing 18 changed files with 245 additions and 23 deletions.
12 changes: 6 additions & 6 deletions class/attr_annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (

// AttrAnnotations
//
// https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.16
// https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.17
// https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.18
// https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.19
// https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.20
// https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.21
// https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.16
// https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.17
// https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.18
// https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.19
// https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.20
// https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.21
type AttrAnnotations struct {
*AttributeBase

Expand Down
63 changes: 63 additions & 0 deletions class/attr_bootstrap_methods.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package class

import (
"encoding/binary"
"fmt"
"github.com/phith0n/zkar/commons"
)

// AttrBootstrapMethods https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.23
type AttrBootstrapMethods struct {
*AttributeBase

BootstrapMethods []*BootstrapMethod
}

type BootstrapMethod struct {
// The value of the bootstrap_method_ref item must be a valid index into the constant_pool table.
// The constant_pool entry at that index must be a CONSTANT_MethodHandle_info structure.
BootstrapMethodRef uint16

// Each entry in the bootstrap_arguments array must be a valid index into the constant_pool table.
// The constant_pool entry at that index must be loadable.
BoostrapArguments []uint16
}

func (a *AttrBootstrapMethods) readInfo(stream *commons.Stream) error {
bs, err := stream.ReadN(2)
if err != nil {
return fmt.Errorf("read AttrBootstrapMethods failed, no enough data in the stream")
}

for i := uint16(0); i < binary.BigEndian.Uint16(bs); i++ {
method, err := a.readBootstrapMethod(stream)
if err != nil {
return err
}

a.BootstrapMethods = append(a.BootstrapMethods, method)
}

return nil
}

func (a *AttrBootstrapMethods) readBootstrapMethod(stream *commons.Stream) (*BootstrapMethod, error) {
bs, err := stream.ReadN(4)
if err != nil {
return nil, fmt.Errorf("read AttrBootstrapMethods BootstrapMethod failed, no enough data in the stream")
}

method := &BootstrapMethod{
BootstrapMethodRef: binary.BigEndian.Uint16(bs[:2]),
}
for i := uint16(0); i < binary.BigEndian.Uint16(bs[2:]); i++ {
bs, err = stream.ReadN(2)
if err != nil {
return nil, fmt.Errorf("read AttrBootstrapMethods BootstrapMethod argument[%d] failed, no enough data in the stream", i)
}

method.BoostrapArguments = append(method.BoostrapArguments, binary.BigEndian.Uint16(bs))
}

return method, nil
}
2 changes: 1 addition & 1 deletion class/attr_code.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// AttrCode attribute of Method
// https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.3
// https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.3
type AttrCode struct {
*AttributeBase

Expand Down
2 changes: 1 addition & 1 deletion class/attr_const_value.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// AttrConstValue attribute of Field
// https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.2
// https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.2
type AttrConstValue struct {
*AttributeBase

Expand Down
2 changes: 1 addition & 1 deletion class/attr_deprecated.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package class

import "github.com/phith0n/zkar/commons"

// AttrDeprecated https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.15
// AttrDeprecated https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.15
type AttrDeprecated struct {
*AttributeBase
}
Expand Down
2 changes: 1 addition & 1 deletion class/attr_enclosing_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/phith0n/zkar/commons"
)

// AttrEnclosingMethod https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.7
// AttrEnclosingMethod https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.7
type AttrEnclosingMethod struct {
*AttributeBase

Expand Down
2 changes: 1 addition & 1 deletion class/attr_exception.go → class/attr_exceptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/phith0n/zkar/commons"
)

// AttrExceptions https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.5
// AttrExceptions https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.5
type AttrExceptions struct {
*AttributeBase

Expand Down
12 changes: 6 additions & 6 deletions class/attr_innerclass.go → class/attr_innerclasses.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"github.com/phith0n/zkar/commons"
)

// AttrInnerClass https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.6
type AttrInnerClass struct {
// AttrInnerClasses https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.6
type AttrInnerClasses struct {
*AttributeBase

InnerClasses []*InnerClass
Expand All @@ -28,10 +28,10 @@ type InnerClass struct {
InnerClassAccessFlags uint16
}

func (a *AttrInnerClass) readInfo(stream *commons.Stream) error {
func (a *AttrInnerClasses) readInfo(stream *commons.Stream) error {
bs, err := stream.ReadN(2)
if err != nil {
return fmt.Errorf("read AttrInnerClass failed, no enough data in the stream")
return fmt.Errorf("read AttrInnerClasses failed, no enough data in the stream")
}

for i := uint16(0); i < binary.BigEndian.Uint16(bs); i++ {
Expand All @@ -46,10 +46,10 @@ func (a *AttrInnerClass) readInfo(stream *commons.Stream) error {
return nil
}

func (a *AttrInnerClass) readInnerClass(stream *commons.Stream) (*InnerClass, error) {
func (a *AttrInnerClasses) readInnerClass(stream *commons.Stream) (*InnerClass, error) {
bs, err := stream.ReadN(8)
if err != nil {
return nil, fmt.Errorf("read AttrInnerClass InnerClass failed, no enough data in the stream")
return nil, fmt.Errorf("read AttrInnerClasses InnerClass failed, no enough data in the stream")
}

c := &InnerClass{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/phith0n/zkar/commons"
)

// AttrLineNumberTable https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.12
// AttrLineNumberTable https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.12
type AttrLineNumberTable struct {
*AttributeBase

Expand Down
2 changes: 1 addition & 1 deletion class/attr_localvartypetable.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/phith0n/zkar/commons"
)

// AttrLocalVariableTypeTable https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.14
// AttrLocalVariableTypeTable https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.14
type AttrLocalVariableTypeTable struct {
*AttributeBase

Expand Down
26 changes: 26 additions & 0 deletions class/attr_nest_host.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package class

import (
"encoding/binary"
"fmt"
"github.com/phith0n/zkar/commons"
)

// AttrNestHost https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.28
type AttrNestHost struct {
*AttributeBase

// The value of the host_class_index item must be a valid index into the constant_pool table.
// The constant_pool entry at that index must be a CONSTANT_Class_info structure (§4.4.1) representing a class or interface which is the nest host for the current class or interface.
HostClassIndex uint16
}

func (a *AttrNestHost) readInfo(stream *commons.Stream) error {
bs, err := stream.ReadN(2)
if err != nil {
return fmt.Errorf("read AttrNestHost failed, no enough data in the stream")
}

a.HostClassIndex = binary.BigEndian.Uint16(bs)
return nil
}
34 changes: 34 additions & 0 deletions class/attr_nest_members.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package class

import (
"encoding/binary"
"fmt"
"github.com/phith0n/zkar/commons"
)

// AttrNestMembers https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.29
type AttrNestMembers struct {
*AttributeBase

// Each value in the classes array must be a valid index into the constant_pool table.
// The constant_pool entry at that index must be a CONSTANT_Class_info structure representing a class or interface which is a member of the nest hosted by the current class or interface.
classes []uint16
}

func (a *AttrNestMembers) readInfo(stream *commons.Stream) error {
bs, err := stream.ReadN(2)
if err != nil {
return fmt.Errorf("read AttrNestMembers failed, no enough data in the stream")
}

for i := uint16(0); i < binary.BigEndian.Uint16(bs); i++ {
bs, err = stream.ReadN(2)
if err != nil {
return fmt.Errorf("read AttrNestMembers class[%d] failed, no enough data in the stream", i)
}

a.classes = append(a.classes, binary.BigEndian.Uint16(bs))
}

return nil
}
34 changes: 34 additions & 0 deletions class/attr_permitted_subclasses.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package class

import (
"encoding/binary"
"fmt"
"github.com/phith0n/zkar/commons"
)

// AttrPermittedSubclasses https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.31
type AttrPermittedSubclasses struct {
*AttributeBase

// Each value in the classes array must be a valid index into the constant_pool table.
// The constant_pool entry at that index must be a CONSTANT_Class_info structure (§4.4.1) representing a class or interface which is authorized to directly extend or implement the current class or interface.
classes []uint16
}

func (a *AttrPermittedSubclasses) readInfo(stream *commons.Stream) error {
bs, err := stream.ReadN(2)
if err != nil {
return fmt.Errorf("read AttrPermittedSubclasses failed, no enough data in the stream")
}

for i := uint16(0); i < binary.BigEndian.Uint16(bs); i++ {
bs, err = stream.ReadN(2)
if err != nil {
return fmt.Errorf("read AttrPermittedSubclasses class[%d] failed, no enough data in the stream", i)
}

a.classes = append(a.classes, binary.BigEndian.Uint16(bs))
}

return nil
}
65 changes: 65 additions & 0 deletions class/attr_record.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package class

import (
"encoding/binary"
"fmt"
"github.com/phith0n/zkar/commons"
)

// AttrRecord https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.3
type AttrRecord struct {
*AttributeBase

Components []*RecordComponentInfo
}

type RecordComponentInfo struct {
// The value of the name_index item must be a valid index into the constant_pool table.
// The constant_pool entry at that index must be a CONSTANT_Utf8_info structure (§4.4.7) representing a valid unqualified name denoting the record component (§4.2.2).
NameIndex uint16

// The value of the descriptor_index item must be a valid index into the constant_pool table.
// The constant_pool entry at that index must be a CONSTANT_Utf8_info structure (§4.4.7) representing a field descriptor which encodes the type of the record component (§4.3.2).
DescriptorIndex uint16

// Each value of the attributes table must be an attribute_info structure (§4.7).
Attributes []Attribute
}

func (a *AttrRecord) readInfo(stream *commons.Stream) error {
bs, err := stream.ReadN(2)
if err != nil {
return fmt.Errorf("read AttrRecord failed, no enough data in the stream")
}

for i := uint16(0); i < binary.BigEndian.Uint16(bs); i++ {
component, err := a.readComponent(stream)
if err != nil {
return err
}

a.Components = append(a.Components, component)
}

return nil
}

func (a *AttrRecord) readComponent(stream *commons.Stream) (*RecordComponentInfo, error) {
bs, err := stream.ReadN(4)
if err != nil {
return nil, fmt.Errorf("read AttrRecord Component[%d] failed, no enough data in the stream", i)

Check failure on line 50 in class/attr_record.go

View workflow job for this annotation

GitHub Actions / lint

undefined: i
}

component := &RecordComponentInfo{
NameIndex: binary.BigEndian.Uint16(bs[:2]),
DescriptorIndex: binary.BigEndian.Uint16(bs[2:]),
}

attr, err := a.class.readAttribute(stream)
if err != nil {
return nil, fmt.Errorf("read AttrCode attribute failed, no enough data in the stream")
}

component.Attributes = append(component.Attributes, attr)
return component, nil
}
2 changes: 1 addition & 1 deletion class/attr_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/phith0n/zkar/commons"
)

// AttrSignature https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.9
// AttrSignature https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.9
type AttrSignature struct {
*AttributeBase

Expand Down
2 changes: 1 addition & 1 deletion class/attr_source_debug_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"github.com/phith0n/zkar/commons"
)

// AttrSourceDebugExtension https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.11
// AttrSourceDebugExtension https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.11
type AttrSourceDebugExtension struct {
*AttributeBase

Expand Down
2 changes: 1 addition & 1 deletion class/attr_source_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// AttrSourceFile attribute of ClassFile
// https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.10
// https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.10
type AttrSourceFile struct {
*AttributeBase
SourceFileIndex uint16 // indicate the name of the source file of the class
Expand Down
2 changes: 1 addition & 1 deletion class/attr_synthetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package class

import "github.com/phith0n/zkar/commons"

// AttrSynthetic https://docs.oracle.com/javase/specs/jvms/se14/html/jvms-4.html#jvms-4.7.8
// AttrSynthetic https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.8
type AttrSynthetic struct {
*AttributeBase
}
Expand Down

0 comments on commit eea28d9

Please sign in to comment.