Struct iced_x86::MasmFormatter
source · [−]pub struct MasmFormatter { /* private fields */ }
Expand description
Masm formatter
Examples
use iced_x86::*;
let bytes = b"\x62\xF2\x4F\xDD\x72\x50\x01";
let mut decoder = Decoder::new(64, bytes, DecoderOptions::NONE);
let instr = decoder.decode();
let mut output = String::new();
let mut formatter = MasmFormatter::new();
formatter.options_mut().set_uppercase_mnemonics(true);
formatter.format(&instr, &mut output);
assert_eq!("VCVTNE2PS2BF16 zmm2{k5}{z},zmm6,dword bcst [rax+4]", output);
Using a symbol resolver
use iced_x86::*;
use std::collections::HashMap;
let bytes = b"\x48\x8B\x8A\xA5\x5A\xA5\x5A";
let mut decoder = Decoder::new(64, bytes, DecoderOptions::NONE);
let instr = decoder.decode();
struct MySymbolResolver { map: HashMap<u64, String> }
impl SymbolResolver for MySymbolResolver {
fn symbol(&mut self, _instruction: &Instruction, _operand: u32, _instruction_operand: Option<u32>,
address: u64, _address_size: u32) -> Option<SymbolResult> {
if let Some(symbol_string) = self.map.get(&address) {
// The 'address' arg is the address of the symbol and doesn't have to be identical
// to the 'address' arg passed to symbol(). If it's different from the input
// address, the formatter will add +N or -N, eg. '[rax+symbol+123]'
Some(SymbolResult::with_str(address, symbol_string.as_str()))
} else {
None
}
}
}
// Hard code the symbols, it's just an example!😄
let mut sym_map: HashMap<u64, String> = HashMap::new();
sym_map.insert(0x5AA55AA5, String::from("my_data"));
let mut output = String::new();
let resolver = Box::new(MySymbolResolver { map: sym_map });
let mut formatter = MasmFormatter::with_options(Some(resolver), None);
formatter.format(&instr, &mut output);
assert_eq!("mov rcx,[rdx+my_data]", output);
Implementations
sourceimpl MasmFormatter
impl MasmFormatter
sourcepub fn with_options(
symbol_resolver: Option<Box<dyn SymbolResolver>>,
options_provider: Option<Box<dyn FormatterOptionsProvider>>
) -> Self
pub fn with_options(
symbol_resolver: Option<Box<dyn SymbolResolver>>,
options_provider: Option<Box<dyn FormatterOptionsProvider>>
) -> Self
Creates a masm formatter
Arguments
symbol_resolver
: Symbol resolver orNone
options_provider
: Operand options provider orNone
Trait Implementations
sourceimpl Default for MasmFormatter
impl Default for MasmFormatter
sourceimpl Formatter for MasmFormatter
impl Formatter for MasmFormatter
sourcefn options(&self) -> &FormatterOptions
fn options(&self) -> &FormatterOptions
Gets the formatter options (immutable)
sourcefn options_mut(&mut self) -> &mut FormatterOptions
fn options_mut(&mut self) -> &mut FormatterOptions
Gets the formatter options (mutable)
sourcefn format_mnemonic_options(
&mut self,
instruction: &Instruction,
output: &mut dyn FormatterOutput,
options: u32
)
fn format_mnemonic_options(
&mut self,
instruction: &Instruction,
output: &mut dyn FormatterOutput,
options: u32
)
Formats the mnemonic and/or any prefixes Read more
sourcefn operand_count(&mut self, instruction: &Instruction) -> u32
fn operand_count(&mut self, instruction: &Instruction) -> u32
Gets the number of operands that will be formatted. A formatter can add and remove operands Read more
sourcefn op_access(
&mut self,
instruction: &Instruction,
operand: u32
) -> Result<Option<OpAccess>, IcedError>
fn op_access(
&mut self,
instruction: &Instruction,
operand: u32
) -> Result<Option<OpAccess>, IcedError>
Returns the operand access but only if it’s an operand added by the formatter. If it’s an
operand that is part of
Instruction
, you should call eg. InstructionInfoFactory::info()
. Read moresourcefn get_instruction_operand(
&mut self,
instruction: &Instruction,
operand: u32
) -> Result<Option<u32>, IcedError>
fn get_instruction_operand(
&mut self,
instruction: &Instruction,
operand: u32
) -> Result<Option<u32>, IcedError>
Converts a formatter operand index to an instruction operand index. Returns
None
if it’s an operand added by the formatter Read moresourcefn get_formatter_operand(
&mut self,
instruction: &Instruction,
instruction_operand: u32
) -> Result<Option<u32>, IcedError>
fn get_formatter_operand(
&mut self,
instruction: &Instruction,
instruction_operand: u32
) -> Result<Option<u32>, IcedError>
Converts an instruction operand index to a formatter operand index. Returns
None
if the instruction operand isn’t used by the formatter Read moresourcefn format_operand(
&mut self,
instruction: &Instruction,
output: &mut dyn FormatterOutput,
operand: u32
) -> Result<(), IcedError>
fn format_operand(
&mut self,
instruction: &Instruction,
output: &mut dyn FormatterOutput,
operand: u32
) -> Result<(), IcedError>
Formats an operand. This is a formatter operand and not necessarily a real instruction operand.
A formatter can add and remove operands. Read more
sourcefn format_operand_separator(
&mut self,
_instruction: &Instruction,
output: &mut dyn FormatterOutput
)
fn format_operand_separator(
&mut self,
_instruction: &Instruction,
output: &mut dyn FormatterOutput
)
Formats an operand separator Read more
sourcefn format_all_operands(
&mut self,
instruction: &Instruction,
output: &mut dyn FormatterOutput
)
fn format_all_operands(
&mut self,
instruction: &Instruction,
output: &mut dyn FormatterOutput
)
Formats all operands Read more
sourcefn format(&mut self, instruction: &Instruction, output: &mut dyn FormatterOutput)
fn format(&mut self, instruction: &Instruction, output: &mut dyn FormatterOutput)
Formats the whole instruction: prefixes, mnemonic, operands Read more
sourcefn format_register(&mut self, register: Register) -> &str
fn format_register(&mut self, register: Register) -> &str
Formats a register Read more
sourcefn format_i16(&mut self, value: i16) -> &str
fn format_i16(&mut self, value: i16) -> &str
Formats a
i16
Read moresourcefn format_i32(&mut self, value: i32) -> &str
fn format_i32(&mut self, value: i32) -> &str
Formats a
i32
Read moresourcefn format_i64(&mut self, value: i64) -> &str
fn format_i64(&mut self, value: i64) -> &str
Formats a
i64
Read moresourcefn format_u16(&mut self, value: u16) -> &str
fn format_u16(&mut self, value: u16) -> &str
Formats a
u16
Read moresourcefn format_u32(&mut self, value: u32) -> &str
fn format_u32(&mut self, value: u32) -> &str
Formats a
u32
Read moresourcefn format_u64(&mut self, value: u64) -> &str
fn format_u64(&mut self, value: u64) -> &str
Formats a
u64
Read moresourcefn format_i8_options(
&mut self,
value: i8,
number_options: &NumberFormattingOptions<'_>
) -> &str
fn format_i8_options(
&mut self,
value: i8,
number_options: &NumberFormattingOptions<'_>
) -> &str
Formats a
i8
Read moresourcefn format_i16_options(
&mut self,
value: i16,
number_options: &NumberFormattingOptions<'_>
) -> &str
fn format_i16_options(
&mut self,
value: i16,
number_options: &NumberFormattingOptions<'_>
) -> &str
Formats a
i16
Read moresourcefn format_i32_options(
&mut self,
value: i32,
number_options: &NumberFormattingOptions<'_>
) -> &str
fn format_i32_options(
&mut self,
value: i32,
number_options: &NumberFormattingOptions<'_>
) -> &str
Formats a
i32
Read moresourcefn format_i64_options(
&mut self,
value: i64,
number_options: &NumberFormattingOptions<'_>
) -> &str
fn format_i64_options(
&mut self,
value: i64,
number_options: &NumberFormattingOptions<'_>
) -> &str
Formats a
i64
Read moresourcefn format_u8_options(
&mut self,
value: u8,
number_options: &NumberFormattingOptions<'_>
) -> &str
fn format_u8_options(
&mut self,
value: u8,
number_options: &NumberFormattingOptions<'_>
) -> &str
Formats a
u8
Read moresourcefn format_u16_options(
&mut self,
value: u16,
number_options: &NumberFormattingOptions<'_>
) -> &str
fn format_u16_options(
&mut self,
value: u16,
number_options: &NumberFormattingOptions<'_>
) -> &str
Formats a
u16
Read moresourcefn format_u32_options(
&mut self,
value: u32,
number_options: &NumberFormattingOptions<'_>
) -> &str
fn format_u32_options(
&mut self,
value: u32,
number_options: &NumberFormattingOptions<'_>
) -> &str
Formats a
u32
Read moresourcefn format_u64_options(
&mut self,
value: u64,
number_options: &NumberFormattingOptions<'_>
) -> &str
fn format_u64_options(
&mut self,
value: u64,
number_options: &NumberFormattingOptions<'_>
) -> &str
Formats a
u64
Read moresourcefn format_mnemonic(
&mut self,
instruction: &Instruction,
output: &mut dyn FormatterOutput
)
fn format_mnemonic(
&mut self,
instruction: &Instruction,
output: &mut dyn FormatterOutput
)
Formats the mnemonic and any prefixes Read more
Auto Trait Implementations
impl !RefUnwindSafe for MasmFormatter
impl !Send for MasmFormatter
impl !Sync for MasmFormatter
impl Unpin for MasmFormatter
impl !UnwindSafe for MasmFormatter
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more