Capstone.js

The Capstone disassembler framework, now available for JavaScript.

Download » Github » Capstone »

Demo

Machine code
0x
Disassembly
Addr. Bytes Instr. Operands

Information

Capstone.js is a port of the Capstone disassembler framework for JavaScript+WASM, powered by Emscripten. The released 3.5 MiB bundle supports the architectures: ARM, ARM64, BPF, EVM, M680X, M68K, MIPS, MOS65xx, PowerPC, RISC-V, SH, SPARC, SystemZ, TMS320C64x, TriCore, WebAssembly, x86 and XCore. Follow the Readme to compile a subset of these, with an average size of 300 KiB per platform.

Capstone is a lightweight multi-architecture disassembly framework originally developed by Nguyen Anh Quynh, with support of other developers and released under BSD license. None of its source code has been altered for this port.

Installation

To use Capstone.js in your web application, download and include it with:

<script src="capstone.js"></script>

or install it with the NPM command:

npm install @alexaltea/capstone-js

Tutorial

// Input: Machine code bytes and offset where they are located
var buffer = [0x55, 0x31, 0xD2, 0x89, 0xE5, 0x8B, 0x45, 0x08];
var offset = 0x10000;

MCapstone().then((cs) => {
    // Initialize the decoder
    var d = new cs.Capstone(cs.ARCH_X86, cs.MODE_32);

    // Output: Array of cs.Instruction objects
    var instructions = d.disasm(buffer, offset);

    // Display results
    instructions.forEach((instr) => {
        console.log("0x%s:\t%s\t%s",
            instr.address.toString(16),
            instr.mnemonic,
            instr.op_str
        );
    });

    // Delete decoder
    d.close();
});