bytecode

package
v0.0.0-...-c5d5a29 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2017 License: MIT Imports: 5 Imported by: 0

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

View Source
const (
	InstrOperandU30 = InstrOperand(iota)
	InstrOperandU8
	InstrOperandS24
	InstrOperandCaseCount
)

These are possible operand types

View Source
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

View Source
const (
	MethodNeedArguments = 1 << iota
	MethodNeedActivation
	MethodNeedRest
	MethodHasOptional
	MethodSetDxns       = 0x40
	MethodHasParamNames = 0x80
)

These constants are possible flags of the flags field of a MethodInfo struct

View Source
const (
	InstanceInfoClassSealed = 1 << iota
	InstanceInfoClassFinal
	InstanceInfoClassInterface
	InstanceInfoClassProtectedNs
)

These constants are possible flags of the flags field of a InstanceInfo struct

View Source
const (
	TraitsInfoSlot = iota
	TraitsInfoMethod
	TraitsInfoGetter
	TraitsInfoSetter
	TraitsInfoClass
	TraitsInfoFunction
	TraitsInfoConst
)

These constants are possible values of the kind field of a TraitsInfo struct

View Source
const (
	TraitsInfoAttributeFinal = 1 << (4 + iota)
	TraitsInfoAttributeOverride
	TraitsInfoAttributeMetadata
)

These constants are possible flags of the kind field of a TraitsInfo struct

View Source
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

View Source
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

View Source
var ErrMalformedVariableInteger = errors.New("malformed variable integer")

ErrMalformedVariableInteger means that an encoded variable integer is malformed (its length is >5 bytes)

View Source
var ErrUnknownInstruction = errors.New("unknown instruction")

ErrUnknownInstruction means that an invalid instruction code was read when disassembling a method.

View Source
var ErrUnknownInstructionOperand = errors.New("unknown instruction operand")

ErrUnknownInstructionOperand means that an invalid instruction operand was found in the Instructions map

View Source
var ErrUnknownMultinameKind = errors.New("unknown multiname kind")

ErrUnknownMultinameKind means that an unknown multiname was found in the constant pool

View Source
var ErrUnknownTraitsInfoKind = errors.New("unknown traits_info kind")

ErrUnknownTraitsInfoKind means that an unknown traits_info was found in classes

View Source
var Instructions = map[uint8]InstrModel{}/* 143 elements not displayed */

Instructions is a map of Instruction. Each key represents the instruction code

Functions

func Extract

func Extract(w io.Writer, abc AbcFile) error

Extract is used to serialize an AbcFile

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

func Parse

func Parse(r Reader) (AbcFile, error)

Parse parses 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

func (c *CpoolInfo) MultinameString(m uint32) string

MultinameString converts a multiname to a string

func (*CpoolInfo) NamespaceString

func (c *CpoolInfo) NamespaceString(n uint32) string

NamespaceString converts a namespace to a string

type ExceptionInfo

type ExceptionInfo struct {
	From    uint32
	To      uint32
	Target  uint32
	ExcType uint32
	VarName uint32
}

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 InstrOperand

type InstrOperand uint8

InstrOperand is the type of an operand

type ItemInfo

type ItemInfo struct {
	Key   uint32
	Value uint32
}

ItemInfo represents a item_info data structure

type MetadataInfo

type MetadataInfo struct {
	Names uint32
	Items []ItemInfo
}

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

type NamespaceInfo struct {
	Kind uint8
	Name uint32
}

NamespaceInfo represents a namespace info data structure

type NsSetInfo

type NsSetInfo struct {
	Count      uint32
	Namespaces []uint32
}

NsSetInfo represents a namespace set info data structure

type OptionDetail

type OptionDetail struct {
	Value uint32
	Kind  uint8
}

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

func NewReader

func NewReader(r io.Reader) Reader

NewReader provides a simple way to create an as3 bytecode reader

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.

type Writer

type Writer interface {
	io.Writer
	WriteU8(uint8) error
	WriteU16(uint16) error
	WriteS24(int32) error
	WriteU30(uint32) error
	WriteU32(uint32) error
	WriteS32(int32) error
	WriteD64(float64) error
}

Writer is used to serialize as3 bytecode

func NewWriter

func NewWriter(w io.Writer) Writer

NewWriter provides a simple way to create an as3 bytecode writer

Jump to

Keyboard shortcuts

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