From 9b24ada2c3a7afa42448fff7ee441ad983530d88 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sun, 31 May 2026 05:51:50 +0000 Subject: add MASM-style formatting support in all modes this includes a mildly nightmarish bit of test harness to compare against ml.exe/ml64.exe/dumpbin.exe, which in turn chased out a bunch of bugs. yay! --- src/protected_mode/display.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/protected_mode/display.rs') diff --git a/src/protected_mode/display.rs b/src/protected_mode/display.rs index dc0cb1d..328ee5a 100644 --- a/src/protected_mode/display.rs +++ b/src/protected_mode/display.rs @@ -1,3 +1,5 @@ +mod masm; + use core::fmt; // allowing these deprecated items for the time being, not yet breaking yaxpeax-x86 apis @@ -2134,7 +2136,14 @@ impl<'instr> fmt::Display for InstructionDisplayer<'instr> { /// enum controlling how `Instruction::display_with` renders instructions. `Intel` is more or less /// intel syntax, though memory operand sizes are elided if they can be inferred from other /// operands. -#[derive(Copy, Clone)] +/// +/// note that `yaxpeax-x86` does not (and can not!) try to guarantee that formatting through any +/// `DisplayStyle` round-trips through an assembler to produce the same bytes as were intially +/// disassembled. opcode choice (for example, `0x31` vs `0x33` encodings of register-register +/// `xor`) may not be controllable, immediates and displacements may have multiple valid encodings, +/// and prefix handling in general is very lossy especially in the presence of repeat or +/// ineffectual prefixes. +#[derive(Copy, Clone, Debug)] pub enum DisplayStyle { /// intel-style syntax for instructions, like /// `add eax, [edx + ecx * 2 + 0x1234]` @@ -2142,6 +2151,12 @@ pub enum DisplayStyle { /// C-style syntax for instructions, like /// `eax += [edx + ecx * 2 + 0x1234]` C, + /// format instructions in the syntax used by the Microsoft Assembler (MASM), like + /// `add eax, dword ptr [edx + ecx * 2 + 1234h]` + /// + /// some instructions are decoded by `dumpbin.exe` and `yaxpeax-x86` but cannot be assembled by + /// `masm.exe` or `ml64.exe`. as one example, `ud0`. + Masm, // one might imagine an ATT style here, which is mostly interesting for reversing operand // order. // well. @@ -2705,6 +2720,9 @@ impl <'instr, T: fmt::Write, Y: YaxColors> ShowContextual DisplayStyle::C => { contextualize_c(instr, &mut out) } + DisplayStyle::Masm => { + masm::contextualize(&instr, &mut out) + } } } } @@ -2988,6 +3006,9 @@ mod buffer_sink { DisplayStyle::C => { contextualize_c(&display.instr, &mut handle)?; } + DisplayStyle::Masm => { + super::masm::contextualize(&display.instr, &mut handle)?; + } } Ok(self.text_str()) -- cgit v1.1