-
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
19 changed files
with
267 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,3 +28,5 @@ linters-settings: | |
xml: snake | ||
form: snake | ||
msgpack: snake | ||
staticcheck: | ||
checks: ["all"] |
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,22 @@ | ||
package class | ||
|
||
import ( | ||
"fmt" | ||
"github.com/phith0n/zkar/commons" | ||
) | ||
|
||
type AttrAnnotationDefault struct { | ||
*AttributeBase | ||
|
||
DefaultValue *ElementValue | ||
} | ||
|
||
func (a *AttrAnnotationDefault) readInfo(stream *commons.Stream) error { | ||
value, err := NewElementValue(stream) | ||
if err != nil { | ||
return fmt.Errorf("read AttrAnnotationDefault failed, caused by: %v", err) | ||
} | ||
|
||
a.DefaultValue = value | ||
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
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,40 @@ | ||
package class | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
"github.com/phith0n/zkar/commons" | ||
) | ||
|
||
// AttrMethodParameters https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.24 | ||
type AttrMethodParameters struct { | ||
*AttributeBase | ||
|
||
Parameters []*MethodParameter | ||
} | ||
|
||
type MethodParameter struct { | ||
NameIndex uint16 | ||
AccessFlags ParameterAccessFlag | ||
} | ||
|
||
func (a *AttrMethodParameters) readInfo(stream *commons.Stream) error { | ||
bs, err := stream.ReadN(1) | ||
if err != nil { | ||
return fmt.Errorf("read AttrMethodParameters NameIndex failed, no enough data in the stream") | ||
} | ||
|
||
length := bs[0] | ||
for i := uint8(0); i < length; i++ { | ||
bs, err = stream.ReadN(4) | ||
if err != nil { | ||
return fmt.Errorf("read AttrMethodParameters NameIndex and AccessFlag failed, no enough data in the stream") | ||
} | ||
|
||
a.Parameters = append(a.Parameters, &MethodParameter{ | ||
NameIndex: binary.BigEndian.Uint16(bs[:2]), | ||
AccessFlags: ParameterAccessFlag(binary.BigEndian.Uint16(bs[2:])), | ||
}) | ||
} | ||
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,111 @@ | ||
package class | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
"github.com/phith0n/zkar/commons" | ||
) | ||
|
||
type AttrModule struct { | ||
*AttributeBase | ||
|
||
ModuleName uint16 | ||
ModuleFlags uint16 | ||
ModuleVersionIndex uint16 | ||
|
||
Requires []*ModuleRequires | ||
Exports []*ModuleExports | ||
Opens []*ModuleOpens | ||
UsesIndex []uint16 | ||
Provides []*ModuleProvides | ||
} | ||
|
||
func (a *AttrModule) readInfo(stream *commons.Stream) error { | ||
bs, err := stream.ReadN(6) | ||
if err != nil { | ||
return fmt.Errorf("read AttrModule failed, no enough data in the stream") | ||
} | ||
|
||
a.ModuleName = binary.BigEndian.Uint16(bs[:2]) | ||
a.ModuleFlags = binary.BigEndian.Uint16(bs[2:4]) | ||
a.ModuleVersionIndex = binary.BigEndian.Uint16(bs[4:]) | ||
return nil | ||
} | ||
|
||
type ModuleRequires struct { | ||
RequiresIndex uint16 | ||
RequiresFlags uint16 | ||
RequiresVersionIndex uint16 | ||
} | ||
|
||
func (a *AttrModule) readRequires(stream *commons.Stream) ([]*ModuleRequires, error) { | ||
bs, err := stream.ReadN(2) | ||
if err != nil { | ||
return nil, fmt.Errorf("read AttrModule Requires failed, no enough data in the stream") | ||
} | ||
|
||
var requires []*ModuleRequires | ||
length := binary.BigEndian.Uint16(bs) | ||
for i := uint16(0); i < length; i++ { | ||
bs, err = stream.ReadN(6) | ||
if err != nil { | ||
return nil, fmt.Errorf("read AttrModule Requires[%d] failed, no enough data in the stream", i) | ||
} | ||
|
||
requires = append(requires, &ModuleRequires{ | ||
RequiresIndex: binary.BigEndian.Uint16(bs[:2]), | ||
RequiresFlags: binary.BigEndian.Uint16(bs[2:4]), | ||
RequiresVersionIndex: binary.BigEndian.Uint16(bs[4:]), | ||
}) | ||
} | ||
return requires, nil | ||
} | ||
|
||
type ModuleExports struct { | ||
ExportsIndex uint16 | ||
ExportsFlags uint16 | ||
ExportsToIndex []uint16 | ||
} | ||
|
||
func (a *AttrModule) readExports(stream *commons.Stream) ([]*ModuleExports, error) { | ||
bs, err := stream.ReadN(2) | ||
if err != nil { | ||
return nil, fmt.Errorf("read AttrModule Exports failed, no enough data in the stream") | ||
} | ||
|
||
var exports []*ModuleExports | ||
length := binary.BigEndian.Uint16(bs) | ||
for i := uint16(0); i < length; i++ { | ||
bs, err = stream.ReadN(6) | ||
if err != nil { | ||
return nil, fmt.Errorf("read AttrModule Exports[%d] failed, no enough data in the stream", i) | ||
} | ||
|
||
export := &ModuleExports{ | ||
ExportsIndex: binary.BigEndian.Uint16(bs[:2]), | ||
ExportsFlags: binary.BigEndian.Uint16(bs[2:4]), | ||
} | ||
|
||
for j := uint16(0); j < binary.BigEndian.Uint16(bs[4:]); j++ { | ||
data, err := stream.ReadN(2) | ||
if err != nil { | ||
return nil, fmt.Errorf("read AttrModule Exports[%d] ExportsToIndex[%d] failed, no enough data in the stream", i, j) | ||
} | ||
|
||
export.ExportsToIndex = append(export.ExportsToIndex, binary.BigEndian.Uint16(data)) | ||
} | ||
exports = append(exports, export) | ||
} | ||
return exports, nil | ||
} | ||
|
||
type ModuleOpens struct { | ||
OpensIndex uint16 | ||
OpensFlags uint16 | ||
OpensToIndex []uint16 | ||
} | ||
|
||
type ModuleProvides struct { | ||
ProvidesIndex uint16 | ||
ProvidesWithIndex []uint16 | ||
} |
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,33 @@ | ||
package class | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
"github.com/phith0n/zkar/commons" | ||
) | ||
|
||
// AttrRuntimeInvisibleTypeAnnotations https://docs.oracle.com/javase/specs/jvms/se17/html/jvms-4.html#jvms-4.7.21 | ||
type AttrRuntimeInvisibleTypeAnnotations struct { | ||
*AttributeBase | ||
|
||
Annotations []*TypeAnnotation | ||
} | ||
|
||
func (a *AttrRuntimeInvisibleTypeAnnotations) readInfo(stream *commons.Stream) error { | ||
bs, err := stream.ReadN(2) | ||
if err != nil { | ||
return fmt.Errorf("read AttrRuntimeInvisibleTypeAnnotations failed, no enough data in the stream") | ||
} | ||
|
||
for i := uint16(0); i < binary.BigEndian.Uint16(bs); i++ { | ||
var annotation *TypeAnnotation | ||
annotation, err = NewTypeAnnotation(stream) | ||
if err != nil { | ||
return fmt.Errorf("read AttrRuntimeInvisibleTypeAnnotations TypeAnnotation[%d] failed, caused by: %v", i, err) | ||
} | ||
|
||
a.Annotations = append(a.Annotations, annotation) | ||
} | ||
|
||
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
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,13 @@ | ||
package class | ||
|
||
type ParameterAccessFlag uint16 | ||
|
||
const ( | ||
ParameterAccFinal ParameterAccessFlag = 0x0010 | ||
ParameterAccSynthetic ParameterAccessFlag = 0x1000 | ||
ParameterAccMandated ParameterAccessFlag = 0x8000 | ||
) | ||
|
||
func (caf ParameterAccessFlag) HasAccessFlag(flag ParameterAccessFlag) bool { | ||
return (flag & caf) == flag | ||
} |
Oops, something went wrong.