Capstone.js

The Capstone disassembler framework, now available for JavaScript.

Download » Github » Capstone »

Demo

Before going to the Installation / Tutorial panels below, you might want to know how Capstone.js tastes like. Here you have a simple demo, providing realtime client-side machine code disassembling thanks to Capstone.js and Angular. The architecture/endianness/mode combination is not verified in this demonstration, thus leading to a JavaScript error if you choose them wrong (e.g. '16-bit PowerPC', 'Big-endian x86', etc.)

Machine code

Architecture
Endianness:
Mode:
Offset:

Disassembly

Addr. Bytes Instr. Operands
{{ instr.address | hexadecimal }} {{ byte | hexadecimal:2 }} {{ instr.mnemonic }} {{ instr.op_str }}

Information

Capstone.js is a port of the Capstone disassembler framework for JavaScript, done with Emscripten. It's released as a 5 MB JavaScript file supporting the architectures: ARM, ARM64, MIPS, PowerPC, Sparc, SystemZ, XCore and x86. Follow the Readme to compile a subset of these, with a size of 500 KB 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 the Capstone.js in your web application, download and include it with:

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

or install it through the Bower command:

bower install capstonejs

Tutorial

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

// 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(function (instr) {
    console.log("0x%s:\t%s\t%s",
        instr.address.toString(16),
        instr.mnemonic,
        instr.op_str
    );
});

// Delete decoder
d.close();