Struct iced_x86::MasmFormatter[][src]

pub struct MasmFormatter { /* fields omitted */ }

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

impl MasmFormatter[src]

#[must_use]pub fn new() -> Self[src]

Creates a masm formatter

#[must_use]pub fn with_options(
    symbol_resolver: Option<Box<dyn SymbolResolver>>,
    options_provider: Option<Box<dyn FormatterOptionsProvider>>
) -> Self
[src]

Creates a masm formatter

Arguments

  • symbol_resolver: Symbol resolver or None
  • options_provider: Operand options provider or None

Trait Implementations

impl Default for MasmFormatter[src]

impl Formatter for MasmFormatter[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.