pub struct Instruction<'a> { /* private fields */ }
Expand description
Wrapper structure for a qemu_plugin_insn *
§Safety
This structure is safe to use as long as the pointer is valid. The pointer is always opaque, and therefore may not be dereferenced.
§Example
struct MyPlugin;
impl qemu_plugin::plugin::Register for MyPlugin {}
impl qemu_plugin::plugin::HasCallbacks for MyPlugin {
fn on_translation_block_translate(
&mut self,
id: qemu_plugin::PluginId,
tb: qemu_plugin::TranslationBlock,
) -> anyhow::Result<()> {
for insn in tb.instructions() {
let vaddr = insn.vaddr();
let disas = insn.disas()?;
// Register a callback to be run on execution of this instruction
insn.register_execute_callback(move |vcpu_index| {
println!("{vcpu_index}@{vaddr:#x}: {disas}");
});
}
Ok(())
}
}
Implementations§
Source§impl<'a> Instruction<'a>
impl<'a> Instruction<'a>
Sourcepub fn read_data(&self, data: &mut [u8]) -> usize
pub fn read_data(&self, data: &mut [u8]) -> usize
Reads the data for this instruction returning number of bytes read. This method may only be called inside the callback in which the instruction is obtained.
Sourcepub fn data(&self) -> Vec<u8> ⓘ
pub fn data(&self) -> Vec<u8> ⓘ
Returns the data for this instruction. This method may only be called inside the callback in which the instruction is obtained, but the resulting data is owned.
Sourcepub fn symbol(&self) -> Result<Option<String>>
pub fn symbol(&self) -> Result<Option<String>>
Returns the symbol associated with this instruction, if one exists and the binary contains a symbol table
Sourcepub fn register_execute_callback<F>(&self, cb: F)
pub fn register_execute_callback<F>(&self, cb: F)
Register a callback to be run on execution of this instruction with no capability to inspect registers
§Arguments
cb
: The callback to be run
Sourcepub fn register_execute_callback_flags<F>(&self, cb: F, flags: CallbackFlags)
pub fn register_execute_callback_flags<F>(&self, cb: F, flags: CallbackFlags)
Register a callback to be run on execution of this instruction with a choice of capability whether to inspect or modify registers or not
§Arguments
cb
: The callback to be runflags
: The flags for the callback specifying whether the callback needs permission to read or write registers
Sourcepub fn register_conditional_execute_callback<F>(
&self,
cb: F,
cond: PluginCondition,
entry: PluginU64,
immediate: u64,
)
pub fn register_conditional_execute_callback<F>( &self, cb: F, cond: PluginCondition, entry: PluginU64, immediate: u64, )
Register a callback to be conditionally run on execution of this instruction with no capability to inspect registers
§Arguments
cb
: The callback to be runcond
: The condition for the callback to be runentry
: The entry to increment the scoreboard forimmediate
: The immediate value to use for the callback
Sourcepub fn register_conditional_execute_callback_flags<F>(
&self,
cb: F,
flags: CallbackFlags,
cond: PluginCondition,
entry: PluginU64,
immediate: u64,
)
pub fn register_conditional_execute_callback_flags<F>( &self, cb: F, flags: CallbackFlags, cond: PluginCondition, entry: PluginU64, immediate: u64, )
Register a callback to be conditionally run on execution of this instruction with a choice of capability whether to inspect or modify registers or not
§Arguments
cb
: The callback to be runflags
: The flags for the callback specifying whether the callback needs permission to read or write registerscond
: The condition for the callback to be runentry
: The entry to increment the scoreboard forimmediate
: The immediate value to use for the callback
Sourcepub fn register_memory_access_callback<F>(&self, cb: F, rw: MemRW)
pub fn register_memory_access_callback<F>(&self, cb: F, rw: MemRW)
Register a callback to be run on memory access of this instruction
§Arguments
cb
: The callback to be runrw
: The type of memory access to trigger the callback on
Sourcepub fn register_memory_access_callback_flags<F>(
&self,
cb: F,
rw: MemRW,
flags: CallbackFlags,
)
pub fn register_memory_access_callback_flags<F>( &self, cb: F, rw: MemRW, flags: CallbackFlags, )
Register a callback to be run on memory access of this instruction
§Arguments
cb
: The callback to be runrw
: The type of memory access to trigger the callback on