UNPKG

shift-interpreter

Version:

Shift-interpreter is an experimental JavaScript meta-interpreter useful for reverse engineering and analysis. One notable difference from other projects is that shift-interpreter retains state over an entire script but can be fed expressions and statement

76 lines (75 loc) 2.93 kB
import { ArrayBinding, BindingIdentifier, BindingWithDefault, Expression, Node, ObjectBinding, Script, Statement, VariableDeclaration } from 'shift-ast'; import { Scope, ScopeLookup, Variable } from 'shift-scope'; import { BasicContext } from './context'; import { InstructionBuffer, Instruction } from './instruction-buffer'; import { NodeHandler } from './node-handler'; import { BlockType, FuncType, Identifier, InstructionNode } from './types'; interface Options { skipUnsupported?: boolean; handler?: { new (interpreter: Interpreter): NodeHandler; }; } export declare enum InterpreterEventName { COMPLETE = "complete" } export declare abstract class InterpreterEvent { static type: typeof InterpreterEventName; } export declare class InterpreterCompleteEvent extends InterpreterEvent { result: any; constructor(result: any); } export declare class Interpreter { contexts: BasicContext[]; globalScope: Scope; lookupTable: ScopeLookup; scopeMap: WeakMap<Variable, Scope>; scopeOwnerMap: WeakMap<Node, Scope>; variableMap: Map<Variable, any>; options: Options; loadedScript: Script; handler: NodeHandler; contextProxies: WeakMap<ProxyConstructor, any>; pointer: InstructionBuffer; lastStatement: Statement; lastInstruction: Instruction; _isReturning: boolean; _isBreaking: boolean; _isContinuing: boolean; errorLocation?: { lastInstruction: Instruction; lastStatement: Statement; }; constructor(options?: Options); print(node?: Node): any; logNode(node: Node): void; codegen(node: Node): void; skipOrThrow(type: string): void; load(script: Script, context?: BasicContext): void; private buildScopeMap; pushContext(context: any): void; popContext(): Record<string, any> | undefined; getCurrentContext(): Record<string, any>; getContexts(): Record<string, any>[]; getContext(index: number): Record<string, any>; isReturning(state?: boolean): boolean; isBreaking(state?: boolean): boolean; isContinuing(state?: boolean): boolean; run(passedNode?: InstructionNode): Promise<any>; private handleError; runToFirstError(passedNode?: Script | Statement | Expression): Promise<any> | undefined; evaluateInstruction(instruction: Instruction): any; evaluate(node: InstructionNode | null): any; hoistFunctions(block: BlockType): void; hoistVars(block: BlockType): void; declareVariables(decl: VariableDeclaration): void; createFunction(node: FuncType): ((this: any, ...args: any) => any) & { _interp: boolean; }; bindVariable(binding: BindingIdentifier | ArrayBinding | ObjectBinding | BindingWithDefault, init: any): void; updateVariableValue(node: Identifier, value: any): any; setRuntimeValue(variable: Variable, value: any): void; getRuntimeValue(node: Identifier): any; } export {};