Documentation ¶
Overview ¶
Package bytecode provides utilities to parse ActionScript 3 bytecode Terms are used according to the specification's definitions (see http://wwwimages.adobe.com/content/dam/Adobe/en/devnet/actionscript/articles/avm2overview.pdf)
Index ¶
- Constants
- Variables
- func Extract(w io.Writer, abc AbcFile) error
- type AbcFile
- type ClassInfo
- type CpoolInfo
- type ExceptionInfo
- type InstanceInfo
- type Instr
- type InstrModel
- type InstrOperand
- type ItemInfo
- type MetadataInfo
- type MethodBodyInfo
- type MethodInfo
- type MultinameInfo
- type NamespaceInfo
- type NsSetInfo
- type OptionDetail
- type OptionInfo
- type ParamInfo
- type Reader
- type ScriptInfo
- type TraitsInfo
- type Writer
Constants ¶
const ( InstrOperandU30 = InstrOperand(iota) InstrOperandU8 InstrOperandS24 InstrOperandCaseCount )
These are possible operand types
const ( MultinameKindQName = 0x07 MultinameKindQNameA = 0x0d MultinameKindRTQName = 0x0f MultinameKindRTQNameA = 0x10 MultinameKindRTQNameL = 0x11 MultinameKindRTQNameLA = 0x12 MultinameKindMultiname = 0x09 MultinameKindMultinameA = 0x0e MultinameKindMultinameL = 0x1b MultinameKindMultinameLA = 0x1c MultinameKindTypename = 0x1d )
These constants are possible value of the kind field of a MultinameInfo struct
const ( MethodNeedArguments = 1 << iota MethodNeedActivation MethodNeedRest MethodHasOptional MethodSetDxns = 0x40 MethodHasParamNames = 0x80 )
These constants are possible flags of the flags field of a MethodInfo struct
const ( InstanceInfoClassSealed = 1 << iota InstanceInfoClassFinal InstanceInfoClassInterface InstanceInfoClassProtectedNs )
These constants are possible flags of the flags field of a InstanceInfo struct
const ( TraitsInfoSlot = iota TraitsInfoMethod TraitsInfoGetter TraitsInfoSetter TraitsInfoClass TraitsInfoFunction TraitsInfoConst )
These constants are possible values of the kind field of a TraitsInfo struct
const ( TraitsInfoAttributeFinal = 1 << (4 + iota) TraitsInfoAttributeOverride TraitsInfoAttributeMetadata )
These constants are possible flags of the kind field of a TraitsInfo struct
const ( NamespaceKindNamespace = 0x08 NamespaceKindPackageNamespace = 0x16 NamespaceKindPackageInternalNs = 0x17 NamespaceKindProtectedNamespace = 0x18 NamespaceKindExplicitNamespace = 0x19 NamespaceKindStaticProtectedNs = 0x1A NamespaceKindPrivateNs = 0x05 )
These constants are possible values of the kind field of a NamespaceInfo struct
const ( SlotKindInt = 0x03 SlotKindUInt = 0x04 SlotKindDouble = 0x06 SlotKindUtf8 = 0x01 SlotKindTrue = 0x0b SlotKindFalse = 0x0a SlotKindNull = 0x0c SlotKindUndefined = 0x00 SlotKindNamespace = 0x08 SlotKindPackageNamespace = 0x16 SlotKindPackageInternalNs = 0x17 SlotKindProtectedNamespace = 0x18 SlotKindExplicitNamespace = 0x19 SlotKindStaticProtectedNs = 0x1a SlotKindPrivateNs = 0x05 )
These constants are possible values for the vkind field of a slot/constant TraitsInfo struct
Variables ¶
var ErrMalformedVariableInteger = errors.New("malformed variable integer")
ErrMalformedVariableInteger means that an encoded variable integer is malformed (its length is >5 bytes)
var ErrUnknownInstruction = errors.New("unknown instruction")
ErrUnknownInstruction means that an invalid instruction code was read when disassembling a method.
var ErrUnknownInstructionOperand = errors.New("unknown instruction operand")
ErrUnknownInstructionOperand means that an invalid instruction operand was found in the Instructions map
var ErrUnknownMultinameKind = errors.New("unknown multiname kind")
ErrUnknownMultinameKind means that an unknown multiname was found in the constant pool
var ErrUnknownTraitsInfoKind = errors.New("unknown traits_info kind")
ErrUnknownTraitsInfoKind means that an unknown traits_info was found in classes
var Instructions = map[uint8]InstrModel{}/* 143 elements not displayed */
Instructions is a map of Instruction. Each key represents the instruction code
Functions ¶
Types ¶
type AbcFile ¶
type AbcFile struct { MinorVersion uint16 MajorVersion uint16 ConstantPool CpoolInfo Methods []MethodInfo Metadatas []MetadataInfo Instances []InstanceInfo Classes []ClassInfo Scripts []ScriptInfo MethodBodies []MethodBodyInfo }
AbcFile is the root structure of an AS3 file
type ClassInfo ¶
type ClassInfo struct { CInit uint32 Traits []TraitsInfo }
ClassInfo represents a class_info data structure
type CpoolInfo ¶
type CpoolInfo struct { Integers []int32 UIntegers []uint32 Doubles []float64 Strings []string Namespaces []NamespaceInfo NsSets []NsSetInfo Multinames []MultinameInfo }
CpoolInfo represents the constant pool informations of an AbcFile
func (*CpoolInfo) MultinameString ¶
MultinameString converts a multiname to a string
func (*CpoolInfo) NamespaceString ¶
NamespaceString converts a namespace to a string
type ExceptionInfo ¶
ExceptionInfo represents a exception_info data structure
type InstanceInfo ¶
type InstanceInfo struct { Name uint32 SuperName uint32 Flags uint8 ProtectedNs uint32 Interfaces []uint32 IInit uint32 Traits []TraitsInfo }
InstanceInfo represents a instance_info data structure
type Instr ¶
type Instr struct { Model InstrModel Operands []uint32 }
Instr represents a disassembled avm2 instruction. Since all the operands are at most 30 bits, operands are stored as uint32.
type InstrModel ¶
type InstrModel struct { Code uint8 Name string Operands []InstrOperand }
InstrModel represents the model for an avm2 instruction
type MetadataInfo ¶
MetadataInfo represents a metadata_info data structure
type MethodBodyInfo ¶
type MethodBodyInfo struct { Method uint32 MaxStack uint32 LocalCount uint32 InitScopeLength uint32 MaxScopeLength uint32 Code []byte Exceptions []ExceptionInfo Traits []TraitsInfo Instructions []Instr }
MethodBodyInfo represents a method_body_info data structure
func (*MethodBodyInfo) Disassemble ¶
func (m *MethodBodyInfo) Disassemble() (err error)
Disassemble parses the instructions of the method body
type MethodInfo ¶
type MethodInfo struct { ParamCount uint32 ReturnType uint32 ParamTypes []uint32 Name uint32 Flags uint8 OptionInfo OptionInfo ParamInfo ParamInfo }
MethodInfo represents a method_info data structure
type MultinameInfo ¶
type MultinameInfo struct { Kind uint8 Name uint32 // reserved for QName, RTQName, Multiname and Typename Namespace uint32 // reserved for Namespace NsSet uint32 // reserved for Multiname and MultinameL Params []uint32 // reserved for Typename }
MultinameInfo represents a multiname info data structure
type NamespaceInfo ¶
NamespaceInfo represents a namespace info data structure
type OptionDetail ¶
OptionDetail represents a option_detail data structure
type OptionInfo ¶
type OptionInfo struct {
Options []OptionDetail
}
OptionInfo represents a option_info data structure
type ParamInfo ¶
type ParamInfo struct {
ParamNames []uint32
}
ParamInfo represents a param_info data structure
type Reader ¶
type Reader interface { ReadU8() (uint8, error) ReadU16() (uint16, error) ReadS24() (int32, error) ReadU30() (uint32, error) ReadU32() (uint32, error) ReadS32() (int32, error) ReadD64() (float64, error) ReadBytes(n uint32) ([]byte, error) }
Reader is the minimal interface required to read as3 bytecode
type ScriptInfo ¶
type ScriptInfo struct { Init uint32 Traits []TraitsInfo }
ScriptInfo represents a script_info data structure
type TraitsInfo ¶
type TraitsInfo struct { Name uint32 Kind uint8 SlotID uint32 // Reserved for slot, constant, class and function Typename uint32 // Reserved for slot and constant VIndex uint32 // Reserved for slot and constant VKind uint8 // Reserved for slot and constant ClassI uint32 // Reserved for class Function uint32 // Reserved for function DispID uint32 // Reserved for method, getter and setter Method uint32 // Reserved for method, getter and setter Metadatas []uint32 }
TraitsInfo represents a traits_info data structure
func (TraitsInfo) GetType ¶
func (t TraitsInfo) GetType() uint8
GetType isolates the type (4 lower bits) of a TraitsInfo.