Keystone.js

The Keystone assembler framework, now available for JavaScript.

Download » Github » Keystone »

Demo

Before going to the Installation / Tutorial panels below, you might want to see how Keystone.js works. Here you have a simple demo, providing realtime client-side instruction assembling thanks to Keystone.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.)

Assembly

Offset
inc rax; call 0x10040; mov rax, qword ptr[rdx + 4]; sub esp, 0x100; xchg rdi, rsi; pop rbx;

Machine Code


Information

Keystone.js is a port of the Keystone assembler framework for JavaScript, done with Emscripten. It's released as a 12 MB JavaScript file supporting the architectures: ARM, ARM64, Hexagon, MIPS, PowerPC, SPARC, SystemZ and x86. Follow the Readme to build Keystone.js manually.

Keystone is a lightweight multi-architecture assembler framework originally developed by Nguyen Anh Quynh et al. and released under GPLv2.

Installation

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

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

or install it through the Bower command:

bower install keystonejs

Tutorial

// Input: Assembly
var assembly = `
  inc   rax;
  call  0x10040;
  mov   rax, qword ptr[rdx + 4];
  sub   esp, 0x100;
  pop   rbx;
`;

// Initialize the encoder
var a = new ks.Keystone(ks.ARCH_X86, ks.MODE_64);

// Choose preferred syntax
a.option(ks.OPT_SYNTAX, ks.OPT_SYNTAX_INTEL);

// Assemble instructions
var result = a.asm(assembly);
/* result.failed = false; */
/* result.count = 5; */
/* result.mc = new Uint8Array([0x48, 0xFF, 0xC0, 0xE8, ...]); */

// Close encoder
a.close();