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>
impl<'cs, 'buf> DisasmIter<'cs, 'buf>
Sourcepub fn next<'iter>(&'iter mut self) -> Option<Insn<'iter>>
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}");Sourcepub fn code(&self) -> &[u8] ⓘ
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"");Sourcepub fn addr(&self) -> u64
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);Sourcepub fn reset(&mut self, code: &'buf [u8], addr: u64)
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more