aptos-disassemble
Version:
Aptos Move disassembler for TypeScript. This package provides utilities to disassemble Move bytecode and modules for the Aptos blockchain.
1,004 lines (986 loc) • 28.5 kB
text/typescript
import * as aptos_bcs from 'aptos-bcs';
import { BcsType, Deserializer } from 'aptos-bcs';
type ModuleHandleIndex = number;
type StructHandleIndex = number;
type FunctionHandleIndex = number;
type FieldHandleIndex = number;
type SignatureIndex = number;
type IdentifierIndex = number;
type AddressIdentifierIndex = number;
type ConstantPoolIndex = number;
type TypeParameterIndex = number;
type VariantIndex = number;
type FieldInstantiationIndex = number;
type StructDefinitionIndex = number;
type StructDefInstantiationIndex = number;
type StructVariantHandleIndex = number;
type StructVariantInstantiationIndex = number;
type VariantFieldHandleIndex = number;
type VariantFieldInstantiationIndex = number;
type FunctionInstantiationIndex = number;
type LocalIndex = number;
type CodeOffset = number;
type ClosureMask = number;
type MemberCount = number;
interface MoveModule {
magic: number;
version: number;
selfModuleHandleIdx: number;
module_handles: Array<ModuleHandle>;
struct_handles: Array<StructHandle>;
function_handles: Array<FunctionHandle>;
field_handles: Array<FieldHandle>;
friend_decls: Array<ModuleHandle>;
struct_defs_inst: Array<StructDefInstantiation>;
function_inst: Array<FunctionInstantiation>;
field_insts: Array<FieldInstantiation>;
signatures: Array<Array<SignatureToken>>;
identifiers: Array<string>;
address_identifiers: Array<string>;
constant_pool: Array<Constant>;
metadatas: Array<Metadata>;
struct_defs: Array<StructDefinition>;
function_defs: Array<FunctionDefinition>;
struct_variant_handles: Array<StructVariantHandle>;
struct_variant_inst: Array<StructVariantInstantiation>;
variant_field_handles: Array<VariantFieldHandle>;
variant_field_inst: Array<VariantFieldInstantiation>;
}
interface ModuleHandle {
address: AddressIdentifierIndex;
name: IdentifierIndex;
}
interface FieldHandle {
owner: StructDefinitionIndex;
field: MemberCount;
}
interface StructDefInstantiation {
def: StructDefinitionIndex;
typeParameters: SignatureIndex;
}
interface FunctionInstantiation {
handle: FunctionHandleIndex;
type_parameters: SignatureIndex;
}
interface FieldInstantiation {
handle: FieldHandleIndex;
typeParameters: SignatureIndex;
}
interface StructDefinition {
struct_handle: StructHandleIndex;
field_information: StructFieldInformation;
}
type StructFieldInformation = {
kind: "Native";
} | {
kind: "Declared";
fields: FieldDefinition[];
} | {
kind: "DeclaredVariants";
variants: VariantDefinition[];
};
interface FieldDefinition {
name: IdentifierIndex;
type: SignatureToken;
}
interface VariantDefinition {
name: IdentifierIndex;
fields: FieldDefinition[];
}
type Visibility = "public" | "private" | "friend";
interface FunctionDefinition {
function: FunctionHandleIndex;
visibility: Visibility;
isEntry: boolean;
acquiresGlobalResources: StructHandleIndex[];
code?: CodeUnit;
}
interface CodeUnit {
locals: SignatureIndex;
code: Bytecode[];
}
interface StructVariantHandle {
struct_index: StructDefinitionIndex;
variant: VariantIndex;
}
interface StructVariantInstantiation {
handle: StructVariantHandleIndex;
type_parameters: SignatureIndex;
}
interface VariantFieldHandle {
struct_index: StructDefinitionIndex;
variants: VariantIndex[];
field: MemberCount;
}
interface VariantFieldInstantiation {
handle: VariantFieldHandleIndex;
typeParameters: SignatureIndex;
}
interface Constant {
type: SignatureToken;
data: Uint8Array;
}
interface Metadata {
key: Uint8Array;
value: Uint8Array;
}
declare enum Ability {
Copy = "copy",
Drop = "drop",
Store = "store",
Key = "key"
}
type AbilitySet = number;
type SignatureToken = ({
kind: "Bool";
} & {
__signatureTokenBrand: true;
}) | ({
kind: "U8";
} & {
__signatureTokenBrand: true;
}) | ({
kind: "U16";
} & {
__signatureTokenBrand: true;
}) | ({
kind: "U32";
} & {
__signatureTokenBrand: true;
}) | ({
kind: "U64";
} & {
__signatureTokenBrand: true;
}) | ({
kind: "U128";
} & {
__signatureTokenBrand: true;
}) | ({
kind: "U256";
} & {
__signatureTokenBrand: true;
}) | ({
kind: "Address";
} & {
__signatureTokenBrand: true;
}) | ({
kind: "Signer";
} & {
__signatureTokenBrand: true;
}) | ({
kind: "Vector";
type: SignatureToken;
} & {
__signatureTokenBrand: true;
}) | ({
kind: "Function";
args: SignatureToken[];
results: SignatureToken[];
abilities: AbilitySet;
} & {
__signatureTokenBrand: true;
}) | ({
kind: "Struct";
handle: StructHandleIndex;
} & {
__signatureTokenBrand: true;
}) | ({
kind: "StructInstantiation";
handle: StructHandleIndex;
typeParams: SignatureToken[];
} & {
__signatureTokenBrand: true;
}) | ({
kind: "Reference";
type: SignatureToken;
} & {
__signatureTokenBrand: true;
}) | ({
kind: "MutableReference";
type: SignatureToken;
} & {
__signatureTokenBrand: true;
}) | ({
kind: "TypeParameter";
index: TypeParameterIndex;
} & {
__signatureTokenBrand: true;
});
type Bytecode = {
kind: "Pop";
} | {
kind: "Ret";
} | {
kind: "BrTrue";
codeOffset: CodeOffset;
} | {
kind: "BrFalse";
codeOffset: CodeOffset;
} | {
kind: "Branch";
codeOffset: CodeOffset;
} | {
kind: "LdU8";
value: number;
} | {
kind: "LdU16";
value: number;
} | {
kind: "LdU32";
value: number;
} | {
kind: "LdU64";
value: bigint;
} | {
kind: "LdU128";
value: bigint;
} | {
kind: "LdU256";
value: string;
} | {
kind: "CastU8";
} | {
kind: "CastU16";
} | {
kind: "CastU32";
} | {
kind: "CastU64";
} | {
kind: "CastU128";
} | {
kind: "CastU256";
} | {
kind: "LdConst";
constIdx: ConstantPoolIndex;
} | {
kind: "LdTrue";
} | {
kind: "LdFalse";
} | {
kind: "CopyLoc";
localIdx: LocalIndex;
} | {
kind: "MoveLoc";
localIdx: LocalIndex;
} | {
kind: "StLoc";
localIdx: LocalIndex;
} | {
kind: "Call";
funcHandleIdx: FunctionHandleIndex;
} | {
kind: "CallGeneric";
funcInstIdx: FunctionInstantiationIndex;
} | {
kind: "Pack";
structDefIdx: StructDefinitionIndex;
} | {
kind: "PackGeneric";
structInstIdx: StructDefInstantiationIndex;
} | {
kind: "PackVariant";
structVariantHandleIdx: StructVariantHandleIndex;
} | {
kind: "PackVariantGeneric";
structVariantInstIdx: StructVariantInstantiationIndex;
} | {
kind: "Unpack";
structDefIdx: StructDefinitionIndex;
} | {
kind: "UnpackGeneric";
structInstIdx: StructDefInstantiationIndex;
} | {
kind: "UnpackVariant";
structVariantHandleIdx: StructVariantHandleIndex;
} | {
kind: "UnpackVariantGeneric";
structVariantInstIdx: StructVariantInstantiationIndex;
} | {
kind: "TestVariant";
structVariantHandleIdx: StructVariantHandleIndex;
} | {
kind: "TestVariantGeneric";
structVariantInstIdx: StructVariantInstantiationIndex;
} | {
kind: "ReadRef";
} | {
kind: "WriteRef";
} | {
kind: "FreezeRef";
} | {
kind: "MutBorrowLoc";
localIdx: LocalIndex;
} | {
kind: "ImmBorrowLoc";
localIdx: LocalIndex;
} | {
kind: "MutBorrowField";
fieldHandleIdx: FieldHandleIndex;
} | {
kind: "MutBorrowVariantField";
variantFieldHandleIdx: VariantFieldHandleIndex;
} | {
kind: "MutBorrowFieldGeneric";
fieldInstIdx: FieldInstantiationIndex;
} | {
kind: "MutBorrowVariantFieldGeneric";
variantFieldInstIdx: VariantFieldInstantiationIndex;
} | {
kind: "ImmBorrowField";
fieldHandleIdx: FieldHandleIndex;
} | {
kind: "ImmBorrowVariantField";
variantFieldHandleIdx: VariantFieldHandleIndex;
} | {
kind: "ImmBorrowFieldGeneric";
fieldInstIdx: FieldInstantiationIndex;
} | {
kind: "ImmBorrowVariantFieldGeneric";
variantFieldInstIdx: VariantFieldInstantiationIndex;
} | {
kind: "MutBorrowGlobal";
structDefIdx: StructDefinitionIndex;
} | {
kind: "MutBorrowGlobalGeneric";
structInstIdx: StructDefInstantiationIndex;
} | {
kind: "ImmBorrowGlobal";
structDefIdx: StructDefinitionIndex;
} | {
kind: "ImmBorrowGlobalGeneric";
structInstIdx: StructDefInstantiationIndex;
} | {
kind: "Add";
} | {
kind: "Sub";
} | {
kind: "Mul";
} | {
kind: "Mod";
} | {
kind: "Div";
} | {
kind: "BitOr";
} | {
kind: "BitAnd";
} | {
kind: "Xor";
} | {
kind: "Or";
} | {
kind: "And";
} | {
kind: "Not";
} | {
kind: "Eq";
} | {
kind: "Neq";
} | {
kind: "Lt";
} | {
kind: "Gt";
} | {
kind: "Le";
} | {
kind: "Ge";
} | {
kind: "Abort";
} | {
kind: "Nop";
} | {
kind: "Exists";
structDefIdx: StructDefinitionIndex;
} | {
kind: "ExistsGeneric";
structInstIdx: StructDefInstantiationIndex;
} | {
kind: "MoveFrom";
structDefIdx: StructDefinitionIndex;
} | {
kind: "MoveFromGeneric";
structInstIdx: StructDefInstantiationIndex;
} | {
kind: "MoveTo";
structDefIdx: StructDefinitionIndex;
} | {
kind: "MoveToGeneric";
structInstIdx: StructDefInstantiationIndex;
} | {
kind: "Shl";
} | {
kind: "Shr";
} | {
kind: "VecPack";
elemTyIdx: SignatureIndex;
numElements: bigint;
} | {
kind: "VecLen";
elemTyIdx: SignatureIndex;
} | {
kind: "VecImmBorrow";
elemTyIdx: SignatureIndex;
} | {
kind: "VecMutBorrow";
elemTyIdx: SignatureIndex;
} | {
kind: "VecPushBack";
elemTyIdx: SignatureIndex;
} | {
kind: "VecPopBack";
elemTyIdx: SignatureIndex;
} | {
kind: "VecUnpack";
elemTyIdx: SignatureIndex;
numElements: bigint;
} | {
kind: "VecSwap";
elemTyIdx: SignatureIndex;
} | {
kind: "PackClosure";
fun: FunctionHandleIndex;
mask: ClosureMask;
} | {
kind: "PackClosureGeneric";
fun: FunctionInstantiationIndex;
mask: ClosureMask;
} | {
kind: "CallClosure";
sigIdx: SignatureIndex;
};
declare const StructTypeParameter: BcsType<{
constraints: number;
is_phantom: boolean;
}, {
constraints: number;
is_phantom: boolean;
}>;
interface StructHandle {
module: ModuleHandleIndex;
name: IdentifierIndex;
abilities: number;
type_parameters: Array<{
constraints: number;
is_phantom: boolean;
}>;
}
declare const StructHandle: BcsType<{
module: number;
name: number;
abilities: number;
typeParameters: {
constraints: number;
is_phantom: boolean;
}[];
}, {
module: number;
name: number;
abilities: number;
typeParameters: {
constraints: number;
is_phantom: boolean;
}[];
}>;
declare const AccessKind: BcsType<aptos_bcs.EnumOutputShapeWithKeys<{
Reads: true;
Writes: true;
}, "Reads" | "Writes">, aptos_bcs.EnumInputShape<{
Reads: boolean | object | null;
Writes: boolean | object | null;
}>>;
declare const ResourceInstantiation: BcsType<{
StructHandleIndex: number;
SignatureIndex: number;
}, {
StructHandleIndex: number;
SignatureIndex: number;
}>;
declare const ResourceSpecifier: BcsType<aptos_bcs.EnumOutputShapeWithKeys<{
Any: true;
DeclaredAtAddress: number;
DeclaredInModule: number;
Resource: number;
ResourceInstantiation: {
StructHandleIndex: number;
SignatureIndex: number;
};
}, "Any" | "DeclaredAtAddress" | "DeclaredInModule" | "Resource" | "ResourceInstantiation">, aptos_bcs.EnumInputShape<{
Any: boolean | object | null;
DeclaredAtAddress: number;
DeclaredInModule: number;
Resource: number;
ResourceInstantiation: {
StructHandleIndex: number;
SignatureIndex: number;
};
}>>;
declare const AddressSpecifier: BcsType<aptos_bcs.EnumOutputShapeWithKeys<{
Any: true;
Literal: number;
Parameter: number;
}, "Any" | "Literal" | "Parameter">, aptos_bcs.EnumInputShape<{
Any: boolean | object | null;
Literal: number;
Parameter: number;
}>>;
declare const AccessSpecifier: BcsType<{
kind: aptos_bcs.EnumOutputShapeWithKeys<{
Reads: true;
Writes: true;
}, "Reads" | "Writes">;
negated: boolean;
resource: aptos_bcs.EnumOutputShapeWithKeys<{
Any: true;
DeclaredAtAddress: number;
DeclaredInModule: number;
Resource: number;
ResourceInstantiation: {
StructHandleIndex: number;
SignatureIndex: number;
};
}, "Any" | "DeclaredAtAddress" | "DeclaredInModule" | "Resource" | "ResourceInstantiation">;
address: aptos_bcs.EnumOutputShapeWithKeys<{
Any: true;
Literal: number;
Parameter: number;
}, "Any" | "Literal" | "Parameter">;
}, {
kind: aptos_bcs.EnumInputShape<{
Reads: boolean | object | null;
Writes: boolean | object | null;
}>;
negated: boolean;
resource: aptos_bcs.EnumInputShape<{
Any: boolean | object | null;
DeclaredAtAddress: number;
DeclaredInModule: number;
Resource: number;
ResourceInstantiation: {
StructHandleIndex: number;
SignatureIndex: number;
};
}>;
address: aptos_bcs.EnumInputShape<{
Any: boolean | object | null;
Literal: number;
Parameter: number;
}>;
}>;
declare const FunctionAttribute: BcsType<aptos_bcs.EnumOutputShapeWithKeys<{
Persistent: true;
ModuleLock: true;
}, "Persistent" | "ModuleLock">, aptos_bcs.EnumInputShape<{
Persistent: boolean | object | null;
ModuleLock: boolean | object | null;
}>>;
interface FunctionHandle {
module: ModuleHandleIndex;
name: IdentifierIndex;
parameters: SignatureIndex;
return_: SignatureIndex;
type_parameters: number[];
access_specifiers?: BcsType<typeof AccessSpecifier>;
attributes?: any;
}
declare const FunctionHandle: BcsType<{
module: number;
name: number;
parameters: number;
return_: number;
typeParameters: number[];
access_specifiers: {
kind: aptos_bcs.EnumInputShape<{
Reads: boolean | object | null;
Writes: boolean | object | null;
}>;
negated: boolean;
resource: aptos_bcs.EnumInputShape<{
Any: boolean | object | null;
DeclaredAtAddress: number;
DeclaredInModule: number;
Resource: number;
ResourceInstantiation: {
StructHandleIndex: number;
SignatureIndex: number;
};
}>;
address: aptos_bcs.EnumInputShape<{
Any: boolean | object | null;
Literal: number;
Parameter: number;
}>;
}[] | null;
attributes: aptos_bcs.EnumInputShape<{
Persistent: boolean | object | null;
ModuleLock: boolean | object | null;
}>[];
}, {
module: number;
name: number;
parameters: number;
return_: number;
typeParameters: number[];
access_specifiers: {
kind: aptos_bcs.EnumInputShape<{
Reads: boolean | object | null;
Writes: boolean | object | null;
}>;
negated: boolean;
resource: aptos_bcs.EnumInputShape<{
Any: boolean | object | null;
DeclaredAtAddress: number;
DeclaredInModule: number;
Resource: number;
ResourceInstantiation: {
StructHandleIndex: number;
SignatureIndex: number;
};
}>;
address: aptos_bcs.EnumInputShape<{
Any: boolean | object | null;
Literal: number;
Parameter: number;
}>;
}[] | null;
attributes: aptos_bcs.EnumInputShape<{
Persistent: boolean | object | null;
ModuleLock: boolean | object | null;
}>[];
}>;
type TypeBuilder = ({
kind: "Saturated";
token: SignatureToken;
} & {
__typeBuilderBrand: true;
}) | ({
kind: "Vector";
} & {
__typeBuilderBrand: true;
}) | ({
kind: "Reference";
} & {
__typeBuilderBrand: true;
}) | ({
kind: "MutableReference";
} & {
__typeBuilderBrand: true;
}) | ({
kind: "StructInst";
sh_idx: StructHandleIndex;
arity: number;
ty_args: SignatureToken[];
} & {
__typeBuilderBrand: true;
}) | ({
kind: "Function";
abilities: AbilitySet;
arg_count: number;
result_count: number;
args: SignatureToken[];
results: SignatureToken[];
} & {
__typeBuilderBrand: true;
});
declare const read_next: (deSignatures: Deserializer, version: number) => SignatureToken | TypeBuilder | null;
declare function load_signature_token(deSignatures: Deserializer, version: number): SignatureToken;
declare enum Opcodes {
POP = 1,
RET = 2,
BR_TRUE = 3,
BR_FALSE = 4,
BRANCH = 5,
LD_U64 = 6,
LD_CONST = 7,
LD_TRUE = 8,
LD_FALSE = 9,
COPY_LOC = 10,
MOVE_LOC = 11,
ST_LOC = 12,
MUT_BORROW_LOC = 13,
IMM_BORROW_LOC = 14,
MUT_BORROW_FIELD = 15,
IMM_BORROW_FIELD = 16,
CALL = 17,
PACK = 18,
UNPACK = 19,
READ_REF = 20,
WRITE_REF = 21,
ADD = 22,
SUB = 23,
MUL = 24,
MOD = 25,
DIV = 26,
BIT_OR = 27,
BIT_AND = 28,
XOR = 29,
OR = 30,
AND = 31,
NOT = 32,
EQ = 33,
NEQ = 34,
LT = 35,
GT = 36,
LE = 37,
GE = 38,
ABORT = 39,
NOP = 40,
EXISTS = 41,
MUT_BORROW_GLOBAL = 42,
IMM_BORROW_GLOBAL = 43,
MOVE_FROM = 44,
MOVE_TO = 45,
FREEZE_REF = 46,
SHL = 47,
SHR = 48,
LD_U8 = 49,
LD_U128 = 50,
CAST_U8 = 51,
CAST_U64 = 52,
CAST_U128 = 53,
MUT_BORROW_FIELD_GENERIC = 54,
IMM_BORROW_FIELD_GENERIC = 55,
CALL_GENERIC = 56,
PACK_GENERIC = 57,
UNPACK_GENERIC = 58,
EXISTS_GENERIC = 59,
MUT_BORROW_GLOBAL_GENERIC = 60,
IMM_BORROW_GLOBAL_GENERIC = 61,
MOVE_FROM_GENERIC = 62,
MOVE_TO_GENERIC = 63,
VEC_PACK = 64,
VEC_LEN = 65,
VEC_IMM_BORROW = 66,
VEC_MUT_BORROW = 67,
VEC_PUSH_BACK = 68,
VEC_POP_BACK = 69,
VEC_UNPACK = 70,
VEC_SWAP = 71,
LD_U16 = 72,
LD_U32 = 73,
LD_U256 = 74,
CAST_U16 = 75,
CAST_U32 = 76,
CAST_U256 = 77,
IMM_BORROW_VARIANT_FIELD = 78,
MUT_BORROW_VARIANT_FIELD = 79,
IMM_BORROW_VARIANT_FIELD_GENERIC = 80,
MUT_BORROW_VARIANT_FIELD_GENERIC = 81,
PACK_VARIANT = 82,
PACK_VARIANT_GENERIC = 83,
UNPACK_VARIANT = 84,
UNPACK_VARIANT_GENERIC = 85,
TEST_VARIANT = 86,
TEST_VARIANT_GENERIC = 87,
PACK_CLOSURE = 88,
PACK_CLOSURE_GENERIC = 89,
CALL_CLOSURE = 90
}
declare function load_code(deserializer: Deserializer, version: number): Array<Bytecode>;
declare const apply: (self: TypeBuilder, tok: SignatureToken) => SignatureToken | TypeBuilder;
declare const AbilityValues: {
Copy: number;
Drop: number;
Store: number;
Key: number;
};
/**
* Configuration options for the disassembler
*/
interface DisassemblerOptions {
/** Whether to print basic block markers (B0:, B1:, etc.) in function code */
printBasicBlocks?: boolean;
}
declare class DisassemblerContext {
private readonly module;
readonly options: DisassemblerOptions;
constructor(module: MoveModule, options?: Partial<DisassemblerOptions>);
get version(): number;
get selfModuleHandleIdx(): number;
getSelfModule(): ModuleHandle;
getSelfModuleAddress(): string;
getSelfModuleName(): string;
getIdentifier(index: number): string;
getAddressIdentifier(index: number): string;
getSignature(index: number): SignatureToken[];
parseSignatureToken(token: SignatureToken): string;
parseAbilities(abilities: number): string[];
getModuleHandle(index: number): ModuleHandle;
getStructHandle(index: number): StructHandle;
getFunctionHandle(index: number): FunctionHandle;
getFieldHandle(index: number): FieldHandle;
getStructDefinition(index: number): StructDefinition;
getFunctionDefinition(index: number): FunctionDefinition;
getStructDefInstantiation(index: number): StructDefInstantiation;
getFunctionInstantiation(index: number): FunctionInstantiation;
getFieldInstantiation(index: number): FieldInstantiation;
getStructVariantHandle(index: number): StructVariantHandle;
getStructVariantInstantiation(index: number): StructVariantInstantiation;
getVariantFieldHandle(index: number): VariantFieldHandle;
getVariantFieldInstantiation(index: number): VariantFieldInstantiation;
getRawModule(): MoveModule;
}
/**
* Control Flow Graph implementation for Move bytecode verification
* Based on the Rust implementation from Move VM
*
* Copyright (c) The Diem Core Contributors
* Copyright ( // Build a mapping from a block id to the next block id in the traversal order
const traversalSuccessors = new Map<BlockId, BlockId>();
for (let i = 0; i < traversalOrder.length - 1; i++) {
traversalSuccessors.set(traversalOrder[i], traversalOrder[i + 1]);
}
this.traversalSuccessors = traversalSuccessors;
this.loopHeads = loopHeads;ove Contributors
* SPDX-License-Identifier: Apache-2.0
*/
type BlockId = CodeOffset;
/**
* A trait that specifies the basic requirements for a CFG
*/
interface ControlFlowGraph {
/** Start index of the block ID in the bytecode vector */
blockStart(blockId: BlockId): CodeOffset;
/** End index of the block ID in the bytecode vector */
blockEnd(blockId: BlockId): CodeOffset;
/** Successors of the block ID in the bytecode vector */
successors(blockId: BlockId): BlockId[];
/** Return the next block in traversal order */
nextBlock(blockId: BlockId): BlockId | null;
/** Iterator over the indexes of instructions in this block */
instrIndexes(blockId: BlockId): Iterable<CodeOffset>;
/** Return an iterator over the blocks of the CFG */
blocks(): BlockId[];
/** Return the number of blocks (vertices) in the control flow graph */
numBlocks(): number;
/** Return the id of the entry block for this control-flow graph */
entryBlockId(): BlockId;
/** Checks if the block ID is a loop head */
isLoopHead(blockId: BlockId): boolean;
/** Checks if the edge from cur->next is a back edge */
isBackEdge(cur: BlockId, next: BlockId): boolean;
/** Return the number of back edges in the cfg */
numBackEdges(): number;
}
/**
* The control flow graph that we build from the bytecode.
*/
declare class VMControlFlowGraph implements ControlFlowGraph {
/** The basic blocks */
private readonly basicBlocks;
/** Basic block ordering for traversal */
private readonly traversalSuccessors;
/** Map of loop heads with all of their back edges */
private readonly loopHeads;
constructor(code: Bytecode[]);
display(): void;
private isEndOfBlock;
private static recordBlockIds;
private static getOffset;
private static isBranch;
private getSuccessors;
/**
* A utility function that implements BFS-reachability from blockId
*/
private traverseBy;
reachableFrom(blockId: BlockId): BlockId[];
traversalIndex(blockId: BlockId): number;
blockStart(blockId: BlockId): CodeOffset;
blockEnd(blockId: BlockId): CodeOffset;
successors(blockId: BlockId): BlockId[];
nextBlock(blockId: BlockId): BlockId | null;
instrIndexes(blockId: BlockId): Iterable<CodeOffset>;
blocks(): BlockId[];
numBlocks(): number;
entryBlockId(): BlockId;
isLoopHead(blockId: BlockId): boolean;
isBackEdge(cur: BlockId, next: BlockId): boolean;
numBackEdges(): number;
}
/**
* ModuleDisassembler - Handles disassembly of entire Move modules
*/
declare class ModuleDisassembler {
private readonly context;
private readonly options;
constructor(context: DisassemblerContext);
disassemble(): string;
private buildModuleAliases;
private generateHeader;
private generateImports;
private generateStructs;
private generateFunctions;
}
/**
* InstructionDisassembler - Handles disassembly of individual bytecode instructions
*/
declare class InstructionDisassembler {
private readonly context;
private readonly params;
private readonly locals;
constructor(context: DisassemblerContext, params: string[], locals: string[]);
disassemble(instruction: Bytecode): string;
private formatLocalInstruction;
private getLocalVariable;
private formatCall;
private formatCallGeneric;
private formatCallClosure;
private formatPackClosure;
private formatPackClosureGeneric;
private formatStructOperation;
private formatGenericStructOperation;
private formatVariantOperation;
private formatGenericVariantOperation;
private formatFieldOperation;
private formatGenericFieldOperation;
private formatVariantFieldOperation;
private formatGenericVariantFieldOperation;
private formatVectorOperation;
private formatLdConst;
private formatConstantData;
private getFieldInfo;
private getVariantInfo;
}
/**
* Loader for Move bytecode modules.
*/
declare class BytecodeLoader {
static loadFromBytecode(bytecode: Uint8Array): MoveModule;
}
/**
* Utility functions for parsing signature tokens and abilities
*/
declare function parseAbilities(abilities: number): string[];
declare function parseSignatureToken(token: SignatureToken, module: MoveModule): string;
declare function disassembleMoveModule(bytecode: Uint8Array): MoveModule;
declare function disassemble_instruction(instruction: Bytecode, params: string[], locals: string[], module: MoveModule): string;
/**
* Main entry point for the aptos-disassemble package
* Provides clean, class-based API for Move bytecode disassembly
*/
/**
* Main disassembly function - improved version with class-based architecture
*/
declare function disassemble(module: MoveModule, options?: Partial<DisassemblerOptions>): string;
/**
* Convenience function to disassemble bytecode directly to string
*/
declare function disassemble_to_string(bytecode: Uint8Array, options?: Partial<DisassemblerOptions>): string;
/**
* Class-based API for more advanced usage
*/
declare class MoveDisassembler {
private context;
private moduleDisassembler;
constructor(module: MoveModule, options?: Partial<DisassemblerOptions>);
static fromBytecode(bytecode: Uint8Array, options?: Partial<DisassemblerOptions>): MoveDisassembler;
disassemble(): string;
getContext(): DisassemblerContext;
getModule(): MoveModule;
getSelfModuleName(): string;
getSelfModuleAddress(): string;
getVersion(): number;
/**
* Create a control flow graph for a specific function in the module
*/
createControlFlowGraph(functionIndex: number): VMControlFlowGraph;
}
export { Ability, type AbilitySet, AbilityValues, AccessKind, AccessSpecifier, type AddressIdentifierIndex, AddressSpecifier, type Bytecode, BytecodeLoader, type ClosureMask, type CodeOffset, type CodeUnit, type Constant, type ConstantPoolIndex, type ControlFlowGraph, DisassemblerContext, type DisassemblerOptions, type FieldDefinition, type FieldHandle, type FieldHandleIndex, type FieldInstantiation, type FieldInstantiationIndex, FunctionAttribute, type FunctionDefinition, FunctionHandle, type FunctionHandleIndex, type FunctionInstantiation, type FunctionInstantiationIndex, type IdentifierIndex, InstructionDisassembler, type LocalIndex, type MemberCount, type Metadata, ModuleDisassembler, type ModuleHandle, type ModuleHandleIndex, MoveDisassembler, type MoveModule, Opcodes, ResourceInstantiation, ResourceSpecifier, type SignatureIndex, type SignatureToken, type StructDefInstantiation, type StructDefInstantiationIndex, type StructDefinition, type StructDefinitionIndex, type StructFieldInformation, StructHandle, type StructHandleIndex, StructTypeParameter, type StructVariantHandle, type StructVariantHandleIndex, type StructVariantInstantiation, type StructVariantInstantiationIndex, type TypeBuilder, type TypeParameterIndex, VMControlFlowGraph, type VariantDefinition, type VariantFieldHandle, type VariantFieldHandleIndex, type VariantFieldInstantiation, type VariantFieldInstantiationIndex, type VariantIndex, type Visibility, apply, disassemble, disassembleMoveModule, disassemble_instruction, disassemble_to_string, load_code, load_signature_token, parseAbilities, parseSignatureToken, read_next };