aboutsummaryrefslogtreecommitdiff
path: root/src/long_mode/display.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2026-05-31 05:51:50 +0000
committeriximeow <me@iximeow.net>2026-07-05 00:08:38 +0000
commit9b24ada2c3a7afa42448fff7ee441ad983530d88 (patch)
treee6a1ed54f5ce4fe5fc1fe5f462c25b4eada678c8 /src/long_mode/display.rs
parent9c676ba70cdbf0edfeae7b8a13e881724711383b (diff)
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!
Diffstat (limited to 'src/long_mode/display.rs')
-rw-r--r--src/long_mode/display.rs28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/long_mode/display.rs b/src/long_mode/display.rs
index 67e359e..9f2022c 100644
--- a/src/long_mode/display.rs
+++ b/src/long_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
@@ -3573,7 +3575,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 rax, [rdx + rcx * 2 + 0x1234]`
@@ -3581,6 +3590,12 @@ pub enum DisplayStyle {
/// C-style syntax for instructions, like
/// `rax += [rdx + rcx * 2 + 0x1234]`
C,
+ /// format instructions in the syntax used by the Microsoft Assembler (MASM), like
+ /// `add rax, dword ptr [rdx + rcx * 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.
@@ -3626,7 +3641,10 @@ impl <'instr, T: fmt::Write, Y: YaxColors> Colorize<T, Y> for InstructionDisplay
struct NoContext;
impl Instruction {
- /// format this instruction into `out` as a plain text string.
+ /// format this instruction into `out` as a plain text string, in the default display
+ /// configuration for an `x86_64` instruction (that is, roughly Intel syntax).
+ ///
+ /// for more customizable formatting options, see [`Instruction::display_with`].
#[cfg_attr(feature="profiling", inline(never))]
pub fn write_to<T: fmt::Write>(&self, out: &mut T) -> fmt::Result {
let mut out = yaxpeax_arch::display::FmtSink::new(out);
@@ -4148,6 +4166,9 @@ impl <'instr, T: fmt::Write, Y: YaxColors> ShowContextual<u64, NoContext, T, Y>
DisplayStyle::C => {
contextualize_c(instr, &mut out)
}
+ DisplayStyle::Masm => {
+ masm::contextualize(&instr, &mut out)
+ }
}
}
}
@@ -4442,6 +4463,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())