jclass

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 14, 2017 License: Apache-2.0 Imports: 9 Imported by: 1

README

jclass

Golang library for Java class file format.

install:

go get github.com/wdsgyj/jclass

demo:

go get github.com/wdsgyj/jclass/cmd/jprint
jprint xxx.class

Documentation

Index

Constants

View Source
const (
	MAGIC uint32 = 0xCAFEBABE
	DEBUG bool   = false
)

Variables

View Source
var (
	ERR_NOT_CLASS_FILE = errors.New("not class file")
)

Functions

This section is empty.

Types

type Annotation

type Annotation struct {
	TypeIndex            uint16
	NumElementValuePairs uint16
	ElementValuePairs    []*ElementValuePair
	// contains filtered or unexported fields
}

func NewAnnotation

func NewAnnotation(r io.Reader, buf []byte, cp []*ConstantPoolInfo) (*Annotation, []byte, error)

func (*Annotation) ConstantPoolInfo

func (a *Annotation) ConstantPoolInfo(i uint16) *ConstantPoolInfo

func (*Annotation) TypeString added in v1.1.0

func (a *Annotation) TypeString() string

type AttributeInfo

type AttributeInfo struct {
	NameIndex uint16
	Length    uint32
	Info      []byte

	Annotations []*Annotation
	// contains filtered or unexported fields
}

func NewAttributeInfo

func NewAttributeInfo(r io.Reader, buf []byte, cp []*ConstantPoolInfo) (*AttributeInfo, []byte, error)

func (*AttributeInfo) ConstantPoolInfo

func (a *AttributeInfo) ConstantPoolInfo(i uint16) *ConstantPoolInfo

func (*AttributeInfo) NameString

func (i *AttributeInfo) NameString() string

func (*AttributeInfo) String

func (i *AttributeInfo) String() string

type ClassAccessFlags

type ClassAccessFlags uint16
const (
	CLASS_ACC_PUBLIC     ClassAccessFlags = 0x0001
	CLASS_ACC_FINAL      ClassAccessFlags = 0x0010
	CLASS_ACC_SUPER      ClassAccessFlags = 0x0020
	CLASS_ACC_INTERFACE  ClassAccessFlags = 0x0200
	CLASS_ACC_ABSTRACT   ClassAccessFlags = 0x0400
	CLASS_ACC_SYNTHETIC  ClassAccessFlags = 0x1000
	CLASS_ACC_ANNOTATION ClassAccessFlags = 0x2000
	CLASS_ACC_ENUM       ClassAccessFlags = 0x4000
)

type ClassFile

type ClassFile struct {
	Magic uint32

	MinorVersion uint16
	MajorVersion uint16

	ConstantPoolCount uint16
	ConstantPool      []*ConstantPoolInfo

	AccessFlags ClassAccessFlags
	ThisClass   uint16
	SuperClass  uint16

	InterfaceCount uint16
	Interfaces     []uint16

	FieldsCount uint16
	Fields      []*FieldInfo

	MethodsCount uint16
	Methods      []*MethodInfo

	AttributesCount uint16
	Attributes      []*AttributeInfo
}

func NewClassFile

func NewClassFile(r io.Reader) (*ClassFile, error)

func NewClassFileFromPath

func NewClassFileFromPath(path string) (*ClassFile, error)

func (*ClassFile) AccessFlagsString

func (cf *ClassFile) AccessFlagsString() string

func (*ClassFile) HasField

func (cf *ClassFile) HasField() bool

func (*ClassFile) HasInterfaces

func (cf *ClassFile) HasInterfaces() bool

func (*ClassFile) HasMethod

func (cf *ClassFile) HasMethod() bool

func (*ClassFile) InterfaceStrings

func (cf *ClassFile) InterfaceStrings() []string

func (*ClassFile) IsAbstract

func (cf *ClassFile) IsAbstract() bool

是抽象类或者接口

func (*ClassFile) IsAnnotation

func (cf *ClassFile) IsAnnotation() bool

是 @interface

func (*ClassFile) IsClass

func (cf *ClassFile) IsClass() bool

是 class 但不是 enum

func (*ClassFile) IsEnum

func (cf *ClassFile) IsEnum() bool

是 enum

func (*ClassFile) IsFinal

func (cf *ClassFile) IsFinal() bool

如果为 true 则表明一定为类或 enum,不是接口、@interface 或者抽象类

func (*ClassFile) IsInterface

func (cf *ClassFile) IsInterface() bool

是 interface 但不是 @interface

func (*ClassFile) IsPublic

func (cf *ClassFile) IsPublic() bool

如果为 true 则表示是 public 的类、interface、@interface 或 enum;否则为 package 的

func (*ClassFile) IsSynthetic

func (cf *ClassFile) IsSynthetic() bool

是编译器生成的类或者接口

func (*ClassFile) String

func (cf *ClassFile) String() string

func (*ClassFile) SuperClassString

func (cf *ClassFile) SuperClassString() string

func (*ClassFile) ThisClassString

func (cf *ClassFile) ThisClassString() string

type ConstantClassInfo

type ConstantClassInfo ConstantPoolInfo

CONSTANT_Class 7

func (*ConstantClassInfo) NameIndex

func (i *ConstantClassInfo) NameIndex() uint16

func (*ConstantClassInfo) String

func (i *ConstantClassInfo) String() string

type ConstantDoubleInfo

type ConstantDoubleInfo ConstantPoolInfo

CONSTANT_Double 6

func (*ConstantDoubleInfo) Double

func (i *ConstantDoubleInfo) Double() float64

func (*ConstantDoubleInfo) String

func (i *ConstantDoubleInfo) String() string

type ConstantFieldrefInfo

type ConstantFieldrefInfo ConstantPoolInfo

CONSTANT_Fieldref 9

func (*ConstantFieldrefInfo) ClassIndex

func (i *ConstantFieldrefInfo) ClassIndex() uint16

func (*ConstantFieldrefInfo) NameAndTypeIndex

func (i *ConstantFieldrefInfo) NameAndTypeIndex() uint16

func (*ConstantFieldrefInfo) String

func (i *ConstantFieldrefInfo) String() string

type ConstantFloatInfo

type ConstantFloatInfo ConstantPoolInfo

CONSTANT_Float 4

func (*ConstantFloatInfo) Float

func (i *ConstantFloatInfo) Float() float32

func (*ConstantFloatInfo) String

func (i *ConstantFloatInfo) String() string

type ConstantIntegerInfo

type ConstantIntegerInfo ConstantPoolInfo

CONSTANT_Integer 3

func (*ConstantIntegerInfo) Integer

func (i *ConstantIntegerInfo) Integer() int32

func (*ConstantIntegerInfo) String

func (i *ConstantIntegerInfo) String() string

type ConstantInterfaceMethodrefInfo

type ConstantInterfaceMethodrefInfo ConstantPoolInfo

CONSTANT_InterfaceMethodref 11

func (*ConstantInterfaceMethodrefInfo) ClassIndex

func (i *ConstantInterfaceMethodrefInfo) ClassIndex() uint16

func (*ConstantInterfaceMethodrefInfo) NameAndTypeIndex

func (i *ConstantInterfaceMethodrefInfo) NameAndTypeIndex() uint16

func (*ConstantInterfaceMethodrefInfo) String

type ConstantInvokeDynamicInfo

type ConstantInvokeDynamicInfo ConstantPoolInfo

CONSTANT_InvokeDynamic 18

func (*ConstantInvokeDynamicInfo) BootstrapMethodAttrIndex

func (i *ConstantInvokeDynamicInfo) BootstrapMethodAttrIndex() uint16

func (*ConstantInvokeDynamicInfo) NameAndTypeIndex

func (i *ConstantInvokeDynamicInfo) NameAndTypeIndex() uint16

func (*ConstantInvokeDynamicInfo) String

func (i *ConstantInvokeDynamicInfo) String() string

type ConstantLongInfo

type ConstantLongInfo ConstantPoolInfo

CONSTANT_Long 5

func (*ConstantLongInfo) Long

func (i *ConstantLongInfo) Long() int64

func (*ConstantLongInfo) String

func (i *ConstantLongInfo) String() string

type ConstantMethodHandleInfo

type ConstantMethodHandleInfo ConstantPoolInfo

CONSTANT_MethodHandle 15

func (*ConstantMethodHandleInfo) ReferenceIndex

func (i *ConstantMethodHandleInfo) ReferenceIndex() uint16

func (*ConstantMethodHandleInfo) ReferenceKind

func (i *ConstantMethodHandleInfo) ReferenceKind() uint8

func (*ConstantMethodHandleInfo) String

func (i *ConstantMethodHandleInfo) String() string

type ConstantMethodTypeInfo

type ConstantMethodTypeInfo ConstantPoolInfo

CONSTANT_MethodType 16

func (*ConstantMethodTypeInfo) DescriptorIndex

func (i *ConstantMethodTypeInfo) DescriptorIndex() uint16

func (*ConstantMethodTypeInfo) String

func (i *ConstantMethodTypeInfo) String() string

type ConstantMethodrefInfo

type ConstantMethodrefInfo ConstantPoolInfo

CONSTANT_Methodref 10

func (*ConstantMethodrefInfo) ClassIndex

func (i *ConstantMethodrefInfo) ClassIndex() uint16

func (*ConstantMethodrefInfo) NameAndTypeIndex

func (i *ConstantMethodrefInfo) NameAndTypeIndex() uint16

func (*ConstantMethodrefInfo) String

func (i *ConstantMethodrefInfo) String() string

type ConstantNameAndTypeInfo

type ConstantNameAndTypeInfo ConstantPoolInfo

CONSTANT_NameAndType 12

func (*ConstantNameAndTypeInfo) DescriptorIndex

func (i *ConstantNameAndTypeInfo) DescriptorIndex() uint16

func (*ConstantNameAndTypeInfo) NameIndex

func (i *ConstantNameAndTypeInfo) NameIndex() uint16

func (*ConstantNameAndTypeInfo) String

func (i *ConstantNameAndTypeInfo) String() string

type ConstantPoolInfo

type ConstantPoolInfo struct {
	Tag  uint8
	Info []byte
}

func NewConstantPoolInfo

func NewConstantPoolInfo(r io.Reader, buf []byte) (*ConstantPoolInfo, []byte, error)

func (*ConstantPoolInfo) String

func (i *ConstantPoolInfo) String() string

type ConstantStringInfo

type ConstantStringInfo ConstantPoolInfo

CONSTANT_String 8

func (*ConstantStringInfo) String

func (i *ConstantStringInfo) String() string

func (*ConstantStringInfo) StringIndex

func (i *ConstantStringInfo) StringIndex() uint16

type ConstantUtf8Info

type ConstantUtf8Info ConstantPoolInfo

CONSTANT_Utf8 1

func (*ConstantUtf8Info) Bytes

func (i *ConstantUtf8Info) Bytes() []byte

func (*ConstantUtf8Info) Length

func (i *ConstantUtf8Info) Length() uint16

func (*ConstantUtf8Info) String

func (i *ConstantUtf8Info) String() string

func (*ConstantUtf8Info) Utf8

func (info *ConstantUtf8Info) Utf8() string

type ElementValue

type ElementValue struct {
	Tag               string
	Info              []byte
	ConstantPoolIndex uint16
	// contains filtered or unexported fields
}

func NewElementValue

func NewElementValue(r io.Reader, buf []byte, cp []*ConstantPoolInfo) (*ElementValue, []byte, error)

func (*ElementValue) ConstantPoolInfo

func (ev *ElementValue) ConstantPoolInfo(i uint16) *ConstantPoolInfo

type ElementValuePair

type ElementValuePair struct {
	ElementNameIndex uint16
	Value            *ElementValue
	// contains filtered or unexported fields
}

func NewElementValuePair

func NewElementValuePair(r io.Reader, buf []byte, cp []*ConstantPoolInfo) (*ElementValuePair, []byte, error)

func (*ElementValuePair) ConstantPoolInfo

func (evp *ElementValuePair) ConstantPoolInfo(i uint16) *ConstantPoolInfo

func (*ElementValuePair) ElementNameString added in v1.2.0

func (evp *ElementValuePair) ElementNameString() string

type FieldAccessFlags

type FieldAccessFlags uint16
const (
	FIELD_ACC_PUBLIC    FieldAccessFlags = 0x0001
	FIELD_ACC_PRIVATE   FieldAccessFlags = 0x0002
	FIELD_ACC_PROTECTED FieldAccessFlags = 0x0004
	FIELD_ACC_STATIC    FieldAccessFlags = 0x0008
	FIELD_ACC_FINAL     FieldAccessFlags = 0x0010
	FIELD_ACC_VOLATILE  FieldAccessFlags = 0x0040
	FIELD_ACC_TRANSIENT FieldAccessFlags = 0x0080
	FIELD_ACC_SYNTHETIC FieldAccessFlags = 0x1000
	FIELD_ACC_ENUM      FieldAccessFlags = 0x4000
)

type FieldInfo

type FieldInfo struct {
	AccessFlags     FieldAccessFlags
	NameIndex       uint16
	DescriptorIndex uint16
	AttributesCount uint16
	Attributes      []*AttributeInfo
	// contains filtered or unexported fields
}

func NewFieldInfo

func NewFieldInfo(r io.Reader, buf []byte, cp []*ConstantPoolInfo) (*FieldInfo, []byte, error)

func (*FieldInfo) AccessFlagsString

func (i *FieldInfo) AccessFlagsString() string

func (*FieldInfo) DescriptorString

func (i *FieldInfo) DescriptorString() string

func (*FieldInfo) NameString

func (i *FieldInfo) NameString() string

func (*FieldInfo) String

func (i *FieldInfo) String() string

type MethodAccessFlags

type MethodAccessFlags uint16
const (
	METHOD_ACC_PUBLIC       MethodAccessFlags = 0x0001
	METHOD_ACC_PRIVATE      MethodAccessFlags = 0x0002
	METHOD_ACC_PROTECTED    MethodAccessFlags = 0x0004
	METHOD_ACC_STATIC       MethodAccessFlags = 0x0008
	METHOD_ACC_FINAL        MethodAccessFlags = 0x0010
	METHOD_ACC_SYNCHRONIZED MethodAccessFlags = 0x0020
	METHOD_ACC_BRIDGE       MethodAccessFlags = 0x0040
	METHOD_ACC_VARARGS      MethodAccessFlags = 0x0080
	METHOD_ACC_NATIVE       MethodAccessFlags = 0x0100
	METHOD_ACC_ABSTRACT     MethodAccessFlags = 0x0400
	METHOD_ACC_STRICT       MethodAccessFlags = 0x0800
	METHOD_ACC_SYNTHETIC    MethodAccessFlags = 0x1000
)

type MethodInfo

type MethodInfo struct {
	AccessFlags     MethodAccessFlags
	NameIndex       uint16
	DescriptorIndex uint16
	AttributesCount uint16
	Attributes      []*AttributeInfo
	// contains filtered or unexported fields
}

func NewMethodInfo

func NewMethodInfo(r io.Reader, buf []byte, cp []*ConstantPoolInfo) (*MethodInfo, []byte, error)

func (*MethodInfo) AccessFlagsString

func (i *MethodInfo) AccessFlagsString() string

func (*MethodInfo) DescriptorString

func (i *MethodInfo) DescriptorString() string

func (*MethodInfo) NameString

func (i *MethodInfo) NameString() string

func (*MethodInfo) String

func (i *MethodInfo) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL