-
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
18 changed files
with
245 additions
and
23 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
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 | ||
} |
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
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
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,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 | ||
} |
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" | ||
) | ||
|
||
// 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 | ||
} |
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" | ||
) | ||
|
||
// 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 | ||
} |
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,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) | ||
} | ||
|
||
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 | ||
} |
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
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