Struct zydis::Formatter

source ·
#[repr(C)]
pub struct Formatter<UserData = ()> { /* private fields */ }
Expand description

Formats decoded instructions to human-readable text.

Implementations§

source§

impl Formatter<()>

source

pub fn new(style: FormatterStyle) -> Self

Creates a new formatter instance (no user-data).

source

pub fn intel() -> Self

Creates a new formatter for Intel syntax.

Convenience wrapper for Self::new(FormatterStyle::INTEL).

source

pub fn att() -> Self

Creates a new formatter for AT&T syntax.

Convenience wrapper for Self::new(FormatterStyle::ATT).

source§

impl<UserData> Formatter<UserData>

source

pub fn set_pre_instruction( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_post_instruction( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_pre_operand( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_post_operand( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_format_instruction( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_format_operand_reg( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_format_operand_mem( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_format_operand_ptr( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_format_operand_imm( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_print_mnemonic( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_print_register( &mut self, new_func: Box<WrappedRegisterFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_print_address_abs( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_print_address_rel( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_print_disp( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_print_imm( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_print_typecast( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_print_prefixes( &mut self, new_func: Box<WrappedGeneralFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn set_print_decorator( &mut self, new_func: Box<WrappedDecoratorFunc<UserData>> ) -> Result<Hook>

Sets the formatter hook to the provided value.

This function accepts a wrapped version of the raw hook. It returns the previous set raw hook.

source

pub fn raw(&self) -> &Formatter

source

pub fn new_custom_userdata(style: FormatterStyle) -> Self

Creates a new formatter instance.

source

pub fn set_property<'this, 'b: 'this>( &'this mut self, prop: FormatterProperty<'b> ) -> Result<()>

Sets the given FormatterProperty on this formatter instance.

source

pub fn format<const N: usize>( &self, ip: Option<u64>, insn: &Instruction<OperandArrayVec<N>> ) -> Result<String>

Format an instruction as a String.

The ip may be None, in which case relative address formatting is used. Otherwise absolute addresses are used.

source

pub fn format_into<const N: usize>( &self, ip: Option<u64>, insn: &Instruction<OperandArrayVec<N>>, f: &mut Formatter<'_> ) -> Result

Format an instruction and append it to a fmt::Formatter.

The ip may be None, in which case relative address formatting is used. Otherwise absolute addresses are used.

source

pub fn format_ex<const N: usize>( &self, ip: Option<u64>, insn: &Instruction<OperandArrayVec<N>>, buffer: &mut OutputBuffer<'_>, user_data: Option<&mut UserData> ) -> Result<()>

Format an instruction into an OutputBuffer.

The ip may be None, in which case relative address formatting is used. Otherwise absolute addresses are used.

This variant is “rawer” than the other format function in that it accepts the raw FFI structs. It further allows the user to pass a custom user_data argument` that is passed to the formatter hooks.

§Examples
static INT3: &'static [u8] = &[0xCC];

let mut buffer = [0u8; 256];
let mut buffer = OutputBuffer::new(&mut buffer[..]);

let formatter = Formatter::intel();
let dec = Decoder::new64();

let insn = dec.decode_first::<VisibleOperands>(INT3).unwrap().unwrap();

formatter
    .format_ex(Some(0), &insn, &mut buffer, None)
    .unwrap();

assert_eq!(buffer.as_str().unwrap(), "int3");
source

pub fn format_operand<const N: usize>( &self, ip: Option<u64>, insn: &Instruction<OperandArrayVec<N>>, buffer: &mut OutputBuffer<'_>, operand_index: usize, user_data: Option<&mut UserData> ) -> Result<()>

Formats just the given operand at operand_index from the given instruction, using buffer for storage.

The ip may be None, in which case relative address formatting is used. Otherwise absolute addresses are used.

user_data may contain any data to pass on to the formatter hooks.

§Panics

If operand_index is out of bounds.

source

pub fn tokenize<'buffer, const N: usize>( &self, ip: Option<u64>, insn: &Instruction<OperandArrayVec<N>>, buffer: &'buffer mut [u8], user_data: Option<&mut UserData> ) -> Result<&'buffer FormatterToken<'buffer>>

Tokenize the given instruction.

The recommended amount of memory to allocate is 256 bytes.

source

pub fn tokenize_operand<'buffer, const N: usize>( &self, ip: Option<u64>, insn: &Instruction<OperandArrayVec<N>>, buffer: &'buffer mut [u8], operand_index: usize, user_data: Option<&mut UserData> ) -> Result<&'buffer FormatterToken<'buffer>>

Tokenizes the given operand at operand_index.

§Examples
static PUSH: &'static [u8] = &[0x51]; // push rcx

let dec = Decoder::new64();
let formatter = Formatter::intel();

let mut buffer = [0; 256];
let insn = dec.decode_first::<VisibleOperands>(PUSH).unwrap().unwrap();
let (ty, val) = formatter
    .tokenize_operand(None, &insn, &mut buffer[..], 0, None)
    .unwrap()
    .value()
    .unwrap();

assert_eq!(ty, TOKEN_REGISTER);
assert_eq!(val, "rcx");
§Panics

If operand_index is out of bounds.

source

pub unsafe fn set_raw_hook(&mut self, hook: Hook) -> Result<Hook>

Sets a raw hook, allowing for customizations along the formatting process.

This is the raw C style version of the formatter hook mechanism. No wrapping occurs, your callback will receive raw pointers. You might want to consider using any of the wrapped variants instead.

Auto Trait Implementations§

§

impl<UserData = ()> !RefUnwindSafe for Formatter<UserData>

§

impl<UserData = ()> !Send for Formatter<UserData>

§

impl<UserData = ()> !Sync for Formatter<UserData>

§

impl<UserData> Unpin for Formatter<UserData>

§

impl<UserData = ()> !UnwindSafe for Formatter<UserData>

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>,

§

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>,

§

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.