Capstone Disassembly Engine

5.0.7 · active · verified Sat Apr 11

Capstone is a lightweight, multi-platform, and multi-architecture disassembly framework. It provides robust Python bindings, allowing developers to programmatically disassemble machine code for various architectures like X86, ARM, Mips, and PowerPC. Widely used in binary analysis and reverse engineering, Capstone aims to be a comprehensive disassembly engine for the security community. The library is actively maintained, with the current stable version being 5.0.7, and receives regular updates including new architecture support and bug fixes.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Capstone engine for different architectures (X86 64-bit and ARM) and then disassemble a byte string, printing the address, mnemonic, and operand string for each instruction.

from capstone import Cs, CS_ARCH_X86, CS_MODE_64

# X86 64-bit code to disassemble
CODE = b"\x55\x48\x8b\x05\xb8\x13\x00\x00\x48\x8b\x01\x49\x8b\x40\x10\x48\x8d\x34\x24"

# Initialize Capstone for X86 64-bit architecture
md = Cs(CS_ARCH_X86, CS_MODE_64)

# Disassemble the code
print("Disassembling X86 64-bit code:")
for i in md.disasm(CODE, 0x1000):
    print("0x%x:\t%s\t%s" % (i.address, i.mnemonic, i.op_str))

# Example with a different architecture (ARM)
from capstone import CS_ARCH_ARM, CS_MODE_ARM
ARM_CODE = b"\x04\xe0\x2d\xe5\x00\x00\x00\x00"
md_arm = Cs(CS_ARCH_ARM, CS_MODE_ARM)

print("\nDisassembling ARM code:")
for i in md_arm.disasm(ARM_CODE, 0x1000):
    print("0x%x:\t%s\t%s" % (i.address, i.mnemonic, i.op_str))

view raw JSON →