-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
289 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
) | ||
|
||
type ConstantDynamic struct { | ||
BootstrapMethodIndex uint16 // a reference to the BootstrapMethod in ClassFile.Attributes | ||
NameAndTypeIndex uint16 | ||
} | ||
|
||
func (c *ConstantDynamic) ToBytes() []byte { | ||
var bs = []byte{CONSTANT_DYNAMIC_INFO} | ||
bs = append(bs, commons.NumberToBytes(c.BootstrapMethodIndex)...) | ||
bs = append(bs, commons.NumberToBytes(c.NameAndTypeIndex)...) | ||
return bs | ||
} | ||
|
||
func readConstantDynamic(stream *commons.Stream) (*ConstantDynamic, error) { | ||
_, _ = stream.ReadN(1) | ||
bs, err := stream.ReadN(4) | ||
if err != nil { | ||
return nil, fmt.Errorf("read constant dynamic failed, no enough data in the stream") | ||
} | ||
|
||
var c = &ConstantDynamic{} | ||
c.BootstrapMethodIndex = binary.BigEndian.Uint16(bs[:2]) | ||
c.NameAndTypeIndex = binary.BigEndian.Uint16(bs[2:]) | ||
|
||
return c, nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,33 @@ | ||
package class | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
"github.com/phith0n/zkar/commons" | ||
) | ||
|
||
type ConstantFieldRef struct { | ||
|
||
ClassIndex uint16 | ||
NameAndTypeIndex uint16 | ||
} | ||
|
||
func (c *ConstantFieldRef) ToBytes() []byte { | ||
var bs = []byte{CONSTANT_FIELD_REF_INFO} | ||
bs = append(bs, commons.NumberToBytes(c.ClassIndex)...) | ||
bs = append(bs, commons.NumberToBytes(c.NameAndTypeIndex)...) | ||
return bs | ||
} | ||
|
||
func readConstantFieldRef(stream *commons.Stream) (*ConstantFieldRef, error) { | ||
_, _ = stream.ReadN(1) | ||
bs, err := stream.ReadN(4) | ||
if err != nil { | ||
return nil, fmt.Errorf("read constant field ref failed, no enough data in the stream") | ||
} | ||
|
||
var c = &ConstantFieldRef{} | ||
c.ClassIndex = binary.BigEndian.Uint16(bs[:2]) | ||
c.NameAndTypeIndex = binary.BigEndian.Uint16(bs[2:]) | ||
|
||
return c, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package class | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
"github.com/phith0n/zkar/commons" | ||
) | ||
|
||
type ConstantInterfaceMethodRef struct { | ||
ClassIndex uint16 | ||
NameAndTypeIndex uint16 | ||
} | ||
|
||
func (c *ConstantInterfaceMethodRef) ToBytes() []byte { | ||
var bs = []byte{CONSTANT_INTERFACE_METHOD_REF} | ||
bs = append(bs, commons.NumberToBytes(c.ClassIndex)...) | ||
bs = append(bs, commons.NumberToBytes(c.NameAndTypeIndex)...) | ||
return bs | ||
} | ||
|
||
func readConstantInterfaceMethodRef(stream *commons.Stream) (*ConstantInterfaceMethodRef, error) { | ||
_, _ = stream.ReadN(1) | ||
bs, err := stream.ReadN(4) | ||
if err != nil { | ||
return nil, fmt.Errorf("read constant interface method ref failed, no enough data in the stream") | ||
} | ||
|
||
var c = &ConstantInterfaceMethodRef{} | ||
c.ClassIndex = binary.BigEndian.Uint16(bs[:2]) | ||
c.NameAndTypeIndex = binary.BigEndian.Uint16(bs[2:]) | ||
|
||
return c, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package class | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
"github.com/phith0n/zkar/commons" | ||
) | ||
|
||
type ConstantInvokeDynamic struct { | ||
BootstrapMethodIndex uint16 // a reference to the BootstrapMethod in ClassFile.Attributes | ||
NameAndTypeIndex uint16 | ||
} | ||
|
||
func (c *ConstantInvokeDynamic) ToBytes() []byte { | ||
var bs = []byte{CONSTANT_INVOKE_DYNAMIC_INFO} | ||
bs = append(bs, commons.NumberToBytes(c.BootstrapMethodIndex)...) | ||
bs = append(bs, commons.NumberToBytes(c.NameAndTypeIndex)...) | ||
return bs | ||
} | ||
|
||
func readConstantInvokeDynamic(stream *commons.Stream) (*ConstantInvokeDynamic, error) { | ||
_, _ = stream.ReadN(1) | ||
bs, err := stream.ReadN(4) | ||
if err != nil { | ||
return nil, fmt.Errorf("read constant invoke dynamic failed, no enough data in the stream") | ||
} | ||
|
||
var c = &ConstantInvokeDynamic{} | ||
c.BootstrapMethodIndex = binary.BigEndian.Uint16(bs[:2]) | ||
c.NameAndTypeIndex = binary.BigEndian.Uint16(bs[2:]) | ||
|
||
return c, nil | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package class | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
"github.com/phith0n/zkar/commons" | ||
) | ||
|
||
type ConstantMethodRef struct { | ||
ClassIndex uint16 | ||
NameAndTypeIndex uint16 | ||
} | ||
|
||
func (c *ConstantMethodRef) ToBytes() []byte { | ||
var bs = []byte{CONSTANT_METHOD_REF_INFO} | ||
bs = append(bs, commons.NumberToBytes(c.ClassIndex)...) | ||
bs = append(bs, commons.NumberToBytes(c.NameAndTypeIndex)...) | ||
return bs | ||
} | ||
|
||
func readConstantMethodRef(stream *commons.Stream) (*ConstantMethodRef, error) { | ||
_, _ = stream.ReadN(1) | ||
bs, err := stream.ReadN(4) | ||
if err != nil { | ||
return nil, fmt.Errorf("read constant method ref failed, no enough data in the stream") | ||
} | ||
|
||
var c = &ConstantMethodRef{} | ||
c.ClassIndex = binary.BigEndian.Uint16(bs[:2]) | ||
c.NameAndTypeIndex = binary.BigEndian.Uint16(bs[2:]) | ||
|
||
return c, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package class | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
"github.com/phith0n/zkar/commons" | ||
) | ||
|
||
type ConstantModule struct { | ||
NameIndex uint16 | ||
} | ||
|
||
func (c *ConstantModule) ToBytes() []byte { | ||
var bs = []byte{CONSTANT_MODULE_INFO} | ||
bs = append(bs, commons.NumberToBytes(c.NameIndex)...) | ||
return bs | ||
} | ||
|
||
func readConstantModule(stream *commons.Stream) (*ConstantModule, error) { | ||
_, _ = stream.ReadN(1) | ||
bs, err := stream.ReadN(2) | ||
if err != nil { | ||
return nil, fmt.Errorf("read constant module failed, no enough data in the stream") | ||
} | ||
|
||
return &ConstantModule{ | ||
NameIndex: binary.BigEndian.Uint16(bs), | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package class | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
"github.com/phith0n/zkar/commons" | ||
) | ||
|
||
type ConstantNameAndType struct { | ||
NameIndex uint16 | ||
DescriptorIndex uint16 | ||
} | ||
|
||
func (c *ConstantNameAndType) ToBytes() []byte { | ||
var bs = []byte{CONSTANT_NAME_AND_TYPE_INFO} | ||
bs = append(bs, commons.NumberToBytes(c.NameIndex)...) | ||
bs = append(bs, commons.NumberToBytes(c.DescriptorIndex)...) | ||
return bs | ||
} | ||
|
||
func readConstantNameAndType(stream *commons.Stream) (*ConstantNameAndType, error) { | ||
_, _ = stream.ReadN(1) | ||
bs, err := stream.ReadN(4) | ||
if err != nil { | ||
return nil, fmt.Errorf("read constant name and type failed, no enough data in the stream") | ||
} | ||
|
||
var c = &ConstantNameAndType{} | ||
c.NameIndex = binary.BigEndian.Uint16(bs[:2]) | ||
c.DescriptorIndex = binary.BigEndian.Uint16(bs[2:]) | ||
|
||
return c, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package class | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
"github.com/phith0n/zkar/commons" | ||
) | ||
|
||
type ConstantPackage struct { | ||
NameIndex uint16 | ||
} | ||
|
||
func (c *ConstantPackage) ToBytes() []byte { | ||
var bs = []byte{CONSTANT_PACKAGE_INFO} | ||
bs = append(bs, commons.NumberToBytes(c.NameIndex)...) | ||
return bs | ||
} | ||
|
||
func readConstantPackage(stream *commons.Stream) (*ConstantPackage, error) { | ||
_, _ = stream.ReadN(1) | ||
bs, err := stream.ReadN(2) | ||
if err != nil { | ||
return nil, fmt.Errorf("read constant package failed, no enough data in the stream") | ||
} | ||
|
||
return &ConstantPackage{ | ||
NameIndex: binary.BigEndian.Uint16(bs), | ||
}, nil | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters