keystone

Bindings to the Keystone Assembler.

Pure Nim score 30/100 · tests present · docs generated

Summary

Latest Version Unknown
License MIT
CI Status Failing
Downloads 0
Last Indexed 2026-07-21 05:24

Installation

nimble install keystone
choosenim install keystone
git clone https://github.com/6A/Keystone.nim

OS Compatibility

Platform Linux macOS Windows FreeBSD OpenBSD NetBSD Android iOS WASM Embedded
keystone - - - - - - -

Source

Repository https://github.com/6A/Keystone.nim
Homepage https://github.com/6A/Keystone.nim
Documentation View Documentation
Registry Source nimble_official

README

Keystone.nim

Nim bindings for the Keystone assembler.

# Create engine safely
let engine = newX86Engine()

defer:
  engine.close()

# Emit to tuple
let enc = engine.assemble("add eax, eax ; ret")

assert enc.buf == @[ 0x01, 0xC0, 0xC3 ]
assert enc.size == 3
assert enc.statementsCount == 2

# Emit using dot operator
let enc = engine.add("eax", "eax")

# Emit to buffer now
var buf = newSeqOfCap[byte](0)

engine.assemble("add eax, eax", buf)
engine.ret(buf)

assert buf == @[ 0x01, 0xC0, 0xC3 ]

# No silent errors
try:
  engine.assemble("add 42")
expect KeystoneError:
  echo "Error encountered: ", getCurrentExceptionMsg()

Thanks to macros, emitting any assembly code is very easy.

let engine = newX86Engine()

# To a new buffer
let buf = assembly engine:
  add eax, eax
  ret

# To an existing buffer
assembly engine, buf:
  add eax, eax
  ret