Crate capstone [] [src]

Bindings to the capstone library disassembly framework.

This crate is a wrapper around the Capstone disassembly library, a "lightweight multi-platform, multi-architecture disassembly framework."

The Capstone struct is the main interface to the library.

extern crate capstone;
use capstone::prelude::*;

const CODE: &'static [u8] = b"\x55\x48\x8b\x05\xb8\x13\x00\x00";
fn main() {
    match Capstone::new().x86().mode(arch::x86::ArchMode::Mode32).build() {
        Ok(cs) => {
            match cs.disasm_all(CODE, 0x1000) {
                Ok(insns) => {
                    println!("Got {} instructions", insns.len());

                    for i in insns.iter() {
                        println!("{}", i);
                    }
                },
                Err(err) => {
                    println!("Error: {}", err)
                }
            }
        },
        Err(err) => {
            println!("Error: {}", err)
        }
    }
}

Produces:

Got 2 instructions
0x1000: push rbp
0x1001: mov rax, qword ptr [rip + 0x13b8]

Modules

arch

Contains architecture-specific types and modules

prelude

Contains items that you probably want to always import

Structs

Capstone

An instance of the capstone disassembler

Detail

Contains extra information about an instruction such as register reads in addition to architecture-specific information

EmptyExtraModeIter

Represents an empty set of ExtraMode.

Insn

A wrapper for the raw capstone-sys instruction

InstructionIterator

An iterator over the instructions returned by disasm

Instructions

Representation of the array of instructions returned by disasm

Enums

Arch

Architectures for the disassembler

CapstoneError

Error for Capstone

Endian

Disassembler endianness

Error

An error enum for this library

ExtraMode

Extra modes or features that can be enabled with some modes

Mode

Disassembler modes

Syntax

Disassembly syntax

Statics

NO_EXTRA_MODE

Represents that no extra modes are enabled. Can be passed to Capstone::new_raw() as the extra_mode argument.

Type Definitions

CsResult