DisasmIter

Struct DisasmIter 

Source
pub struct DisasmIter<'cs, 'buf> { /* private fields */ }
Expand description

Structure to handle iterative disassembly.

Create with a Capstone instance: Capstone::disasm_iter().

§Lifetimes

'cs is the lifetime of the Capstone instance. 'buf is the lifetime of the user provided code buffer in Capstone::disasm_iter().

Implementations§

Source§

impl<'cs, 'buf> DisasmIter<'cs, 'buf>

Source

pub fn next<'iter>(&'iter mut self) -> Option<Insn<'iter>>

Get next instruction if available.

§Examples
let code = b"\x90";
let mut iter = cs.disasm_iter(code, 0x1000).unwrap();
while let Some(insn) = iter.next() {
    println!("{insn}");
}

At most one instruction can be accessed at the same time:

let code = b"\x90";
let mut iter = cs.disasm_iter(code, 0x1000).unwrap();
let insn1 = iter.next().unwrap();
let insn2 = iter.next().unwrap();
// fails with: cannot borrow `iter` as mutable more than once at a time,
// `insn1` cannot be used after calling `iter.next()` again,
// as `iter` is mutably borrowed during the second call to `next()`.
println!("{insn1}");
Source

pub fn code(&self) -> &[u8]

Get the slice of the code yet to be disassembled

let code = b"\x90";
let mut iter = cs.disasm_iter(code, 0x1000).unwrap();
assert_eq!(iter.code(), code);
iter.next();
assert_eq!(iter.code(), b"");
Source

pub fn addr(&self) -> u64

Get the address of the next instruction to be disassembled

let code = b"\x90";
let mut iter = cs.disasm_iter(code, 0x1000).unwrap();
assert_eq!(iter.addr(), 0x1000);
iter.next();
assert_eq!(iter.addr(), 0x1001);
Source

pub fn reset(&mut self, code: &'buf [u8], addr: u64)

Reset the iterator to disassemble in the specified code buffer

let code = b"\x90";
let mut iter = cs.disasm_iter(code, 0x1000).unwrap();
assert_eq!(iter.addr(), 0x1000);
assert_eq!(iter.code(), code);
iter.next();
assert_eq!(iter.addr(), 0x1001);
assert_eq!(iter.code(), b"");
let new_code = b"\xc3";
iter.reset(new_code, 0x2000);
assert_eq!(iter.addr(), 0x2000);
assert_eq!(iter.code(), new_code);

Trait Implementations§

Source§

impl<'cs, 'buf> Drop for DisasmIter<'cs, 'buf>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'cs, 'buf> Freeze for DisasmIter<'cs, 'buf>

§

impl<'cs, 'buf> RefUnwindSafe for DisasmIter<'cs, 'buf>

§

impl<'cs, 'buf> !Send for DisasmIter<'cs, 'buf>

§

impl<'cs, 'buf> !Sync for DisasmIter<'cs, 'buf>

§

impl<'cs, 'buf> Unpin for DisasmIter<'cs, 'buf>

§

impl<'cs, 'buf> UnwindSafe for DisasmIter<'cs, 'buf>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.