pub struct Capstone { /* private fields */ }Expand description
A capstone instance that can be used for disassembly.
Implementations§
Source§impl Capstone
impl Capstone
Sourcepub fn open(arch: Arch, mode: Mode) -> Result<Self, Error>
pub fn open(arch: Arch, mode: Mode) -> Result<Self, Error>
Initializes capstone with the given arch and mode.
Sourcepub fn details<'i>(&self, insn: &'i Insn<'_>) -> Details<'i>
pub fn details<'i>(&self, insn: &'i Insn<'_>) -> Details<'i>
Retrieves some general details about an instruction. This value is only available if the engine was not compiled in DIET mode and details mode is turned on for this instance of Capstone. If details about an instruction are not available, this will panic.
§Panics
If instruction details were not turned on for this Capstone instance or if Capstone was compiled in DIET mode.
Sourcepub fn try_details<'i>(&self, insn: &'i Insn<'_>) -> Option<Details<'i>>
pub fn try_details<'i>(&self, insn: &'i Insn<'_>) -> Option<Details<'i>>
Retrieves some general details about an instruction. This value is
only available if the engine was not compiled in DIET mode and details
mode is turned on for this instance of Capstone. If details about an
instruction are not available, this will return Option::None.
Sourcepub fn disasm<'s>(
&'s self,
code: &[u8],
address: u64,
) -> Result<InsnBuffer<'s>, Error>
pub fn disasm<'s>( &'s self, code: &[u8], address: u64, ) -> Result<InsnBuffer<'s>, Error>
Disassembles all of the instructions in a buffer with the given starting address. This will dynamically allocate memory to contain the disassembled instructions.
Sourcepub fn disasm_count<'s>(
&'s self,
code: &[u8],
address: u64,
count: usize,
) -> Result<InsnBuffer<'s>, Error>
pub fn disasm_count<'s>( &'s self, code: &[u8], address: u64, count: usize, ) -> Result<InsnBuffer<'s>, Error>
Disassembles at most count instructions from the buffer using
the given starting address. This will dynamically allocate memory
to contain the disassembled instructions.
Sourcepub fn disasm_iter<'s>(&'s self, code: &[u8], address: u64) -> InsnIter<'s> ⓘ
pub fn disasm_iter<'s>(&'s self, code: &[u8], address: u64) -> InsnIter<'s> ⓘ
Returns an iterator that will lazily disassemble the instructions in the given binary.
Sourcepub fn set_syntax(&mut self, syntax: Syntax) -> Result<(), Error>
pub fn set_syntax(&mut self, syntax: Syntax) -> Result<(), Error>
Sets the assembly syntax for the disassembling engine at runtime.
If the syntax is supported then Result::Ok is returned
with no value. If the syntax is not supported then Result::Err
is returned.
Sourcepub fn set_mode(&mut self, mode: Mode) -> Result<(), Error>
pub fn set_mode(&mut self, mode: Mode) -> Result<(), Error>
Change the engine’s mode at runtime after it has been initialized.
Sourcepub fn set_details_enabled(&mut self, detail: bool) -> Result<(), Error>
pub fn set_details_enabled(&mut self, detail: bool) -> Result<(), Error>
Setting detail to true will make the disassembling engine break
down instruction structure into details.
Sourcepub fn set_unsigned(&mut self, unsigned: bool) -> Result<(), Error>
pub fn set_unsigned(&mut self, unsigned: bool) -> Result<(), Error>
Setting unsigned to true will make the disassembling engine print
immediate operands in unsigned form.
Sourcepub fn reset_mnemonic<I>(&mut self, insn: I) -> Result<(), Error>
pub fn reset_mnemonic<I>(&mut self, insn: I) -> Result<(), Error>
Removes a custom mnemonic that was previously set by Capstone::set_mnemonic.
Sourcepub fn set_mnemonic<I, M>(&mut self, insn: I, mnemonic: M) -> Result<(), Error>
pub fn set_mnemonic<I, M>(&mut self, insn: I, mnemonic: M) -> Result<(), Error>
Customize the mnemonic for an instruction with an alternative name.
Sourcepub fn setup_skipdata<M, F>(
&mut self,
mnemonic: Option<M>,
callback: Option<F>,
) -> Result<(), Error>
pub fn setup_skipdata<M, F>( &mut self, mnemonic: Option<M>, callback: Option<F>, ) -> Result<(), Error>
Sets a custom setup for SKIPDATA mode.
Setting mnemonic allows for customizing the mnemonic of the instruction
used to represent data. By default this will be .byte.
The user defined callback (if there is one) will be called whenever
Capstone hits data. If the returned value from the callback is positive (greater than 0), Capstone
will skip exactly that number of bytes and continue. Otherwise, if the callback retruns 0,
Capstone stops disassembling and returns immediately from Capstone::disasm or causes
the Iterator from Capstone::disasm_iter to return None.
§Note
If the callback is None, Capstone will skip a number of bytes depending on the
architecture:
- Arm: 2 bytes (Thumb mode) or 4 bytes.
- Arm64: 4 bytes.
- Mips: 4 bytes.
- M680x: 1 byte.
- PowerPC: 4 bytes.
- Sparc: 4 bytes.
- SystemZ: 2 bytes.
- X86: 1 bytes.
- XCore: 2 bytes.
- EVM: 1 bytes.
- MOS65XX: 1 bytes.
Sourcepub fn set_skipdata_mode(&mut self, skipdata: bool) -> Result<(), Error>
pub fn set_skipdata_mode(&mut self, skipdata: bool) -> Result<(), Error>
Place the disassembling engine in SKIPDATA mode.
Use Capstone::setup_skipdata to configure this mode.
Sourcepub fn details_enabled(&self) -> bool
pub fn details_enabled(&self) -> bool
Returns true if this Capstone instance has instruction details enabled.
Sourcepub fn skipdata_mode(&self) -> bool
pub fn skipdata_mode(&self) -> bool
Returns true if the disassembling engine is currently in SKIPDATA mode.
Sourcepub fn arch(&self) -> Arch
pub fn arch(&self) -> Arch
Returns the current arch that this instance of the Capstone disassembly engine is set to disassemble.
Sourcepub fn reg_name<R>(&self, reg: R) -> &str
pub fn reg_name<R>(&self, reg: R) -> &str
Returns the user friendly name of a register. This will return an empty string if the register is not valid for the current architecture.
Sourcepub fn insn_name<I>(&self, insn: I) -> &str
pub fn insn_name<I>(&self, insn: I) -> &str
Returns the user friendly name of an instruction. This will return an empty string if the instruction is not valid for the current architecture.
Sourcepub fn group_name<G>(&self, group: G) -> &str
pub fn group_name<G>(&self, group: G) -> &str
Returns the user friendly name of an instruction group. This will return an empty string if the instruction group is not valid for the current architecture.