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
31 lines (27 loc) • 675 B
text/typescript
import { InstructionNode } from './types';
export enum InstructionBufferEventName {
REQUEST_EXECUTION = 'requestExecution',
HALT = 'halt',
CONTINUE = 'continue',
}
export class Instruction {
node: InstructionNode;
id: number;
result: any;
constructor(node: InstructionNode, id: number) {
this.node = node;
this.id = id;
}
}
export class InstructionBuffer {
buffer: Instruction[] = [];
numInstructions = 0;
add(node: InstructionNode): Instruction {
const instruction = new Instruction(node, this.numInstructions++);
this.buffer.push(instruction);
return instruction;
}
nextInstruction() {
return this.buffer.shift();
}
}