Skip to content

Commit

Permalink
add some attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
phith0n committed Sep 3, 2021
1 parent 4db5c80 commit ab82c54
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 3 deletions.
30 changes: 30 additions & 0 deletions class/attr_annotations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package class

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

// 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
type AttrAnnotations struct {
*AttributeBase

Data []byte
}

// readInfo TODO: not implement
func (a *AttrAnnotations) readInfo(stream *commons.Stream) error {
var err error
a.Data, err = stream.ReadN(int(a.AttributeLength))
if err != nil {
return fmt.Errorf("read AttrAnnotations failed, no enough data in the stream")
}

return nil
}
12 changes: 12 additions & 0 deletions class/attr_deprecated.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
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
type AttrDeprecated struct {
*AttributeBase
}

func (a *AttrDeprecated) readInfo(stream *commons.Stream) error {
return nil
}
4 changes: 2 additions & 2 deletions class/attr_linenumber.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type AttrLineNumberTable struct {
*AttributeBase

LineNumberTables []*LineNumberTable
Tables []*LineNumberTable
}

type LineNumberTable struct {
Expand All @@ -37,7 +37,7 @@ func (a *AttrLineNumberTable) readInfo(stream *commons.Stream) error {
StartPC: binary.BigEndian.Uint16(bs[:2]),
LineNumber: binary.BigEndian.Uint16(bs[2:]),
}
a.LineNumberTables = append(a.LineNumberTables, table)
a.Tables = append(a.Tables, table)
}

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

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

type AttrLocalVariableTable struct {
*AttributeBase

Tables []*LocalVariableTable
}

type LocalVariableTable struct {
StartPC uint16
Length uint16
NameIndex uint16
DescriptorIndex uint16
Index uint16
}

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

for i := uint16(0); i < binary.BigEndian.Uint16(bs); i++ {
bs, err = stream.ReadN(10)
if err != nil {
return fmt.Errorf("read AttrLocalVariableTable tables failed, no enough data in the stream")
}

table := &LocalVariableTable{
StartPC: binary.BigEndian.Uint16(bs[:2]),
Length: binary.BigEndian.Uint16(bs[2:4]),
NameIndex: binary.BigEndian.Uint16(bs[4:6]),
DescriptorIndex: binary.BigEndian.Uint16(bs[6:8]),
Index: binary.BigEndian.Uint16(bs[8:]),
}
a.Tables = append(a.Tables, table)
}

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

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

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

Tables []*LocalVariableTypeTable
}

type LocalVariableTypeTable struct {
StartPC uint16
Length uint16
NameIndex uint16
SignatureIndex uint16
Index uint16
}

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

for i := uint16(0); i < binary.BigEndian.Uint16(bs); i++ {
bs, err = stream.ReadN(10)
if err != nil {
return fmt.Errorf("read AttrLocalVariableTypeTable tables failed, no enough data in the stream")
}

table := &LocalVariableTypeTable{
StartPC: binary.BigEndian.Uint16(bs[:2]),
Length: binary.BigEndian.Uint16(bs[2:4]),
NameIndex: binary.BigEndian.Uint16(bs[4:6]),
SignatureIndex: binary.BigEndian.Uint16(bs[6:8]),
Index: binary.BigEndian.Uint16(bs[8:]),
}
a.Tables = append(a.Tables, table)
}

return nil
}

3 changes: 2 additions & 1 deletion class/attr_stackmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ type AttrStackMapTable struct {
Data []byte
}

// readInfo TODO: read detail information of AttrStackMapTable
// readInfo not implement
// TODO: read detail information of AttrStackMapTable
func (a *AttrStackMapTable) readInfo(stream *commons.Stream) error {
var err error
a.Data, err = stream.ReadN(int(a.AttributeLength))
Expand Down

0 comments on commit ab82c54

Please sign in to comment.