Crate capstone_sys

source ·
Expand description

Low-level, unsafe Rust bindings for the Capstone disassembly library.

We recommend against using this crate directly. Instead, consider using capstone-rs, which provides a high-level, safe, “Rusty” interface.

§Supported disassembly architectures

  • arm: ARM
  • arm64: ARM64 (also known as AArch64)
  • mips: MIPS
  • ppc: PowerPC
  • sparc: SPARC
  • sysz: System z
  • x86: x86 family (includes 16, 32, and 64 bit modes)
  • xcore: XCore

For each architecture, at least the following types are defined (replace ARCH with architecture names shown above):

  • enum ARCH_insn: instruction ids
  • enum ARCH_insn_group: architecture-specific group ids
  • enum ARCH_op_type: instruction operand types ids
  • enum ARCH_reg1: register ids
  • struct ARCH_op_mem: operand referring to memory
  • struct cs_ARCH_op: instruction operand
  • struct cs_ARCH: instruction

Note: documentation for functions/types was taken directly from Capstone C headers.

1: Defined as a “constified” enum modules because discriminant values are not unique. Rust requires discriminant values to be unique.

Modules§

Structs§

Enums§

Constants§

Statics§

Functions§

  • Close CS handle: MUST do to release the handle when it is not used anymore. NOTE: this must be only called when there is no longer usage of Capstone, not even access to cs_insn array. The reason is the this API releases some cached memory, thus access to any Capstone API after cs_close() might crash your application.
  • Disassemble binary code, given the code buffer, size, address and number of instructions to be decoded. This API dynamically allocate memory to contain disassembled instruction. Resulting instructions will be put into @*insn
  • Fast API to disassemble binary code, given the code buffer, size, address and number of instructions to be decoded. This API puts the resulting instruction into a given cache in @insn. See tests/test_iter.c for sample code demonstrating this API.
  • Report the last error number when some API function fail. Like glibc’s errno, cs_errno might not retain its old value once accessed.
  • Free memory allocated by cs_malloc() or cs_disasm() (argument @insn)
  • Return friendly name of a group id (that an instruction can belong to) Find the group id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, …)
  • Check if a disassembled instruction belong to a particular group. Find the group id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, …) Internally, this simply verifies if @group_id matches any member of insn->groups array.
  • Return friendly name of an instruction in a string. Find the instruction id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, …)
  • Allocate memory for 1 instruction to be used by cs_disasm_iter().
  • Count the number of operands of a given type. Find the operand type in header file of corresponding architecture (arm.h for ARM, x86.h for X86, …)
  • Retrieve the position of operand of given type in .operands[] array. Later, the operand can be accessed using the returned position. Find the operand type in header file of corresponding architecture (arm.h for ARM, x86.h for X86, …)
  • Initialize CS handle: this must be done before any usage of CS.
  • Set option for disassembling engine at runtime
  • Return friendly name of register in a string. Find the instruction id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, …)
  • Check if a disassembled instruction IMPLICITLY used a particular register. Find the register id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, …) Internally, this simply verifies if @reg_id matches any member of insn->regs_read array.
  • Check if a disassembled instruction IMPLICITLY modified a particular register. Find the register id from header file of corresponding architecture (arm.h for ARM, x86.h for X86, …) Internally, this simply verifies if @reg_id matches any member of insn->regs_write array.
  • Retrieve all the registers accessed by an instruction, either explicitly or implicitly.
  • Return a string describing given error code.
  • This API can be used to either ask for archs supported by this library, or check to see if the library was compile with ‘diet’ option (or called in ‘diet’ mode).
  • Return combined API version & major and minor version numbers.

Type Aliases§

Unions§