Keystone Engine Assembler

0.9.2 · active · verified Fri Apr 17

Keystone Engine is a lightweight multi-architecture assembler framework, providing Python bindings to its powerful C core. It supports various architectures including X86, ARM, ARM64, MIPS, PowerPC, SPARC, SystemZ, and more. The current version is 0.9.2, and it maintains a stable release cadence focused on feature enhancements and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Keystone assembler for a specific architecture and mode (X86-32bit) and then assemble a simple assembly instruction string into its corresponding bytecode. It also shows basic error handling.

from keystone import * 

try:
    # Initialize Keystone for X86-32bit architecture
    ks = Ks(KS_ARCH_X86, KS_MODE_32)
    
    # Assemble a simple instruction
    opcode, count = ks.asm(b"inc eax")
    
    print(f"Assembled instruction bytes: {opcode}")
    print(f"Number of instructions assembled: {count}")
    
    # Example with multiple instructions
    opcode_multi, count_multi = ks.asm(b"add ecx, 10; mov eax, ebx")
    print(f"Assembled multiple instructions bytes: {opcode_multi}")
    print(f"Number of instructions assembled: {count_multi}")

except KeystoneError as e:
    print(f"Keystone error: {e}")

view raw JSON →