Skip to content

Commit

Permalink
rename most operand variants, make them structy rather than tupley
Browse files Browse the repository at this point in the history
  • Loading branch information
iximeow committed Jun 24, 2024
1 parent b8a294d commit 1b8019d
Show file tree
Hide file tree
Showing 10 changed files with 868 additions and 894 deletions.
39 changes: 38 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
## 1.3.0
## 2.0.0

* upgrade to `yaxpeax-arch 0.3.1`, which brings with it a deprecation of the
`Colorize` and `ShowContextual` traits.
* because common use of yaxpeax-x86 involves using both this crate and
`yaxpeax-arch`, moving to a newer major version of `yaxpeax-arch` is a major
version bump of `yaxpeax-x86` as well. so, 2.0.0!

changes:

* `Operand` variants have had their naming made more consistent.
- many variants starting with "Reg" actually describe a memory access. they
now begin with "Mem" instead.
- several variants mentioned "Scale" in their name, but not "Index", even
though they use an index register. they now do.
- several variants mentioned their constituent parts out of order. for
example, "RegIndexBaseScaleDisp", even though the parts were specified as
base, then index, then scale, then displacement. these names have been
adjusted to reflect the order of their fields, which is roughly the order
those fields are shown when printed.
- `DisplacementU*` operands have always been access to memory at the absolute
address they specify. their names are now `AbsoluteU*`
* `Operand`, across the board, now uses struct-style enum variants, rather than tuple-style.
* the two changes together mean an operand that was
`RegIndexBaseScaleDisp(reg, reg, u8, i32)`
is now
`MemBaseIndexScaleDisp { base, index, scale, disp }`
and similar for other variants.
* two operand kinds, and their masked variants, were never actually constructed, and have been deleted.
- long ago yaxpeax-x86 returned different Operand variants when an index
register was used with scale 1, to hint that no scaling actually occurred.
this was eventually changed to return a scaling Operand variant with
scale==1, but the old variants remained.
- RegIndexBase has been removed
- RegIndexBaseDisp has been removed
* `Prefixes::selects_cs()` has been moved to `Prefixes::cs()`, and the old
useless functions are no more. `inst.prefixes().cs()` is finally a reasonable
way to determine if an instruction reads or writes through the cs prefix.

fixes:

* fix 32-bit call/jmp not respecting 66 prefix if set - such cases use 16-bit
operands, but decoded as if they used 32-bit operands.

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
//! #[cfg(features="fmt")]
//! assert_eq!("xor eax, dword [rcx]", inst.to_string());
//!
//! assert_eq!(Operand::Register(RegSpec::eax()), inst.operand(0));
//! assert_eq!(Operand::Register { reg: RegSpec::eax() }, inst.operand(0));
//! #[cfg(features="fmt")]
//! assert_eq!("eax", inst.operand(0).to_string());
//! assert_eq!(Operand::RegDeref(RegSpec::rcx()), inst.operand(1));
//! assert_eq!(Operand::MemDeref { base: RegSpec::rcx() }, inst.operand(1));
//!
//! // an operand in isolation does not know the size of memory it references, if any
//! #[cfg(features="fmt")]
Expand Down
76 changes: 38 additions & 38 deletions src/long_mode/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
}
#[cfg_attr(not(feature="profiling"), inline(always))]
#[cfg_attr(feature="profiling", inline(never))]
fn visit_disp(&mut self, reg: RegSpec, disp: i32) -> Result<Self::Ok, Self::Error> {
fn visit_disp(&mut self, base: RegSpec, disp: i32) -> Result<Self::Ok, Self::Error> {
self.f.write_char('[')?;
self.f.write_reg(reg)?;
self.f.write_reg(base)?;
self.f.write_fixed_size(" ")?;

{
Expand All @@ -447,23 +447,23 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
}
self.f.write_fixed_size("]")
}
fn visit_deref(&mut self, reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_deref(&mut self, base: RegSpec) -> Result<Self::Ok, Self::Error> {
self.f.write_fixed_size("[")?;
self.f.write_reg(reg)?;
self.f.write_reg(base)?;
self.f.write_fixed_size("]")
}
fn visit_reg_scale(&mut self, reg: RegSpec, scale: u8) -> Result<Self::Ok, Self::Error> {
fn visit_index_scale(&mut self, index: RegSpec, scale: u8) -> Result<Self::Ok, Self::Error> {
self.f.write_fixed_size("[")?;
self.f.write_reg(reg)?;
self.f.write_reg(index)?;
self.f.write_fixed_size(" * ")?;
self.f.write_char((0x30 + scale) as char)?; // translate scale=1 to '1', scale=2 to '2', etc
self.f.write_fixed_size("]")?;

Ok(())
}
fn visit_reg_scale_disp(&mut self, reg: RegSpec, scale: u8, disp: i32) -> Result<Self::Ok, Self::Error> {
fn visit_index_scale_disp(&mut self, index: RegSpec, scale: u8, disp: i32) -> Result<Self::Ok, Self::Error> {
self.f.write_fixed_size("[")?;
self.f.write_reg(reg)?;
self.f.write_reg(index)?;
self.f.write_fixed_size(" * ")?;
self.f.write_char((0x30 + scale) as char)?; // translate scale=1 to '1', scale=2 to '2', etc
self.f.write_fixed_size(" ")?;
Expand All @@ -480,7 +480,7 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
}
self.f.write_char(']')
}
fn visit_index_base_scale(&mut self, base: RegSpec, index: RegSpec, scale: u8) -> Result<Self::Ok, Self::Error> {
fn visit_base_index_scale(&mut self, base: RegSpec, index: RegSpec, scale: u8) -> Result<Self::Ok, Self::Error> {
self.f.write_fixed_size("[")?;
self.f.write_reg(base)?;
self.f.write_fixed_size(" + ")?;
Expand All @@ -489,7 +489,7 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_char((0x30 + scale) as char)?; // translate scale=1 to '1', scale=2 to '2', etc
self.f.write_fixed_size("]")
}
fn visit_index_base_scale_disp(&mut self, base: RegSpec, index: RegSpec, scale: u8, disp: i32) -> Result<Self::Ok, Self::Error> {
fn visit_base_index_scale_disp(&mut self, base: RegSpec, index: RegSpec, scale: u8, disp: i32) -> Result<Self::Ok, Self::Error> {
self.f.write_fixed_size("[")?;
self.f.write_reg(base)?;
self.f.write_fixed_size(" + ")?;
Expand All @@ -510,9 +510,9 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
}
self.f.write_fixed_size("]")
}
fn visit_reg_disp_masked(&mut self, spec: RegSpec, disp: i32, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_disp_masked(&mut self, base: RegSpec, disp: i32, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
self.f.write_char('[')?;
self.f.write_reg(spec)?;
self.f.write_reg(base)?;
self.f.write_char(' ')?;
let mut v = disp as u32;
if disp < 0 {
Expand All @@ -528,18 +528,18 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_char('}')?;
Ok(())
}
fn visit_reg_deref_masked(&mut self, spec: RegSpec, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_deref_masked(&mut self, base: RegSpec, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
self.f.write_fixed_size("[")?;
self.f.write_reg(spec)?;
self.f.write_reg(base)?;
self.f.write_fixed_size("]")?;
self.f.write_char('{')?;
self.f.write_reg(mask_reg)?;
self.f.write_char('}')?;
Ok(())
}
fn visit_reg_scale_masked(&mut self, spec: RegSpec, scale: u8, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_index_scale_masked(&mut self, index: RegSpec, scale: u8, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
self.f.write_fixed_size("[")?;
self.f.write_reg(spec)?;
self.f.write_reg(index)?;
self.f.write_fixed_size(" * ")?;
self.f.write_char((0x30 + scale) as char)?; // translate scale=1 to '1', scale=2 to '2', etc
self.f.write_fixed_size("]")?;
Expand All @@ -548,9 +548,9 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_char('}')?;
Ok(())
}
fn visit_reg_scale_disp_masked(&mut self, spec: RegSpec, scale: u8, disp: i32, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_index_scale_disp_masked(&mut self, index: RegSpec, scale: u8, disp: i32, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
self.f.write_fixed_size("[")?;
self.f.write_reg(spec)?;
self.f.write_reg(index)?;
self.f.write_fixed_size(" * ")?;
self.f.write_char((0x30 + scale) as char)?; // translate scale=1 to '1', scale=2 to '2', etc
self.f.write_fixed_size(" ")?;
Expand All @@ -568,7 +568,7 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_char('}')?;
Ok(())
}
fn visit_index_base_masked(&mut self, base: RegSpec, index: RegSpec, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_base_index_masked(&mut self, base: RegSpec, index: RegSpec, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
self.f.write_fixed_size("[")?;
self.f.write_reg(base)?;
self.f.write_fixed_size(" + ")?;
Expand All @@ -579,7 +579,7 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_char('}')?;
Ok(())
}
fn visit_index_base_disp_masked(&mut self, base: RegSpec, index: RegSpec, disp: i32, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_base_index_disp_masked(&mut self, base: RegSpec, index: RegSpec, disp: i32, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
self.f.write_fixed_size("[")?;
self.f.write_reg(base)?;
self.f.write_fixed_size(" + ")?;
Expand All @@ -599,7 +599,7 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_char('}')?;
Ok(())
}
fn visit_index_base_scale_masked(&mut self, base: RegSpec, index: RegSpec, scale: u8, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_base_index_scale_masked(&mut self, base: RegSpec, index: RegSpec, scale: u8, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
self.f.write_fixed_size("[")?;
self.f.write_reg(base)?;
self.f.write_fixed_size(" + ")?;
Expand All @@ -612,7 +612,7 @@ impl <T: DisplaySink> super::OperandVisitor for DisplayingOperandVisitor<'_, T>
self.f.write_char('}')?;
Ok(())
}
fn visit_index_base_scale_disp_masked(&mut self, base: RegSpec, index: RegSpec, scale: u8, disp: i32, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_base_index_scale_disp_masked(&mut self, base: RegSpec, index: RegSpec, scale: u8, disp: i32, mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
self.f.write_fixed_size("[")?;
self.f.write_reg(base)?;
self.f.write_fixed_size(" + ")?;
Expand Down Expand Up @@ -3860,7 +3860,7 @@ pub(crate) fn contextualize_c<T: DisplaySink>(instr: &Instruction, out: &mut T)
let mut out = yaxpeax_arch::display::FmtSink::new(out);
use core::fmt::Write;
match op {
Operand::ImmediateI8(rel) => {
Operand::ImmediateI8 { imm: rel } => {
let rel = if rel >= 0 {
out.write_str("$+")?;
rel as u8
Expand All @@ -3870,7 +3870,7 @@ pub(crate) fn contextualize_c<T: DisplaySink>(instr: &Instruction, out: &mut T)
};
out.write_prefixed_u8(rel)
}
Operand::ImmediateI32(rel) => {
Operand::ImmediateI32 { imm: rel } => {
let rel = if rel >= 0 {
out.write_str("$+")?;
rel as u32
Expand Down Expand Up @@ -4272,10 +4272,10 @@ impl<'a, F: DisplaySink> super::OperandVisitor for RelativeBranchPrinter<'a, F>
fn visit_reg(&mut self, _reg: RegSpec) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
fn visit_deref(&mut self, _reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_deref(&mut self, _base: RegSpec) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
fn visit_disp(&mut self, _reg: RegSpec, _disp: i32) -> Result<Self::Ok, Self::Error> {
fn visit_disp(&mut self, _base: RegSpec, _disp: i32) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
#[cfg_attr(feature="profiling", inline(never))]
Expand Down Expand Up @@ -4338,16 +4338,16 @@ impl<'a, F: DisplaySink> super::OperandVisitor for RelativeBranchPrinter<'a, F>
fn visit_abs_u64(&mut self, _imm: u64) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
fn visit_reg_scale(&mut self, _reg: RegSpec, _scale: u8) -> Result<Self::Ok, Self::Error> {
fn visit_index_scale(&mut self, _index: RegSpec, _scale: u8) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
fn visit_index_base_scale(&mut self, _base: RegSpec, _index: RegSpec, _scale: u8) -> Result<Self::Ok, Self::Error> {
fn visit_base_index_scale(&mut self, _base: RegSpec, _index: RegSpec, _scale: u8) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
fn visit_reg_scale_disp(&mut self, _reg: RegSpec, _scale: u8, _disp: i32) -> Result<Self::Ok, Self::Error> {
fn visit_index_scale_disp(&mut self, _index: RegSpec, _scale: u8, _disp: i32) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
fn visit_index_base_scale_disp(&mut self, _base: RegSpec, _index: RegSpec, _scale: u8, _disp: i32) -> Result<Self::Ok, Self::Error> {
fn visit_base_index_scale_disp(&mut self, _base: RegSpec, _index: RegSpec, _scale: u8, _disp: i32) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
fn visit_other(&mut self) -> Result<Self::Ok, Self::Error> {
Expand All @@ -4362,28 +4362,28 @@ impl<'a, F: DisplaySink> super::OperandVisitor for RelativeBranchPrinter<'a, F>
fn visit_reg_mask_merge_sae_noround(&mut self, _spec: RegSpec, _mask: RegSpec, _merge_mode: MergeMode) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
fn visit_reg_disp_masked(&mut self, _spec: RegSpec, _disp: i32, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_disp_masked(&mut self, _base: RegSpec, _disp: i32, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
fn visit_reg_deref_masked(&mut self, _spec: RegSpec, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_deref_masked(&mut self, _base: RegSpec, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
fn visit_reg_scale_masked(&mut self, _spec: RegSpec, _scale: u8, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_index_scale_masked(&mut self, _index: RegSpec, _scale: u8, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
fn visit_reg_scale_disp_masked(&mut self, _spec: RegSpec, _scale: u8, _disp: i32, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_index_scale_disp_masked(&mut self, _index: RegSpec, _scale: u8, _disp: i32, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
fn visit_index_base_masked(&mut self, _base: RegSpec, _index: RegSpec, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_base_index_masked(&mut self, _base: RegSpec, _index: RegSpec, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
fn visit_index_base_disp_masked(&mut self, _base: RegSpec, _index: RegSpec, _disp: i32, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_base_index_disp_masked(&mut self, _base: RegSpec, _index: RegSpec, _disp: i32, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
fn visit_index_base_scale_masked(&mut self, _base: RegSpec, _index: RegSpec, _scale: u8, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_base_index_scale_masked(&mut self, _base: RegSpec, _index: RegSpec, _scale: u8, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
fn visit_index_base_scale_disp_masked(&mut self, _base: RegSpec, _index: RegSpec, _scale: u8, _disp: i32, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
fn visit_base_index_scale_disp_masked(&mut self, _base: RegSpec, _index: RegSpec, _scale: u8, _disp: i32, _mask_reg: RegSpec) -> Result<Self::Ok, Self::Error> {
Ok(false)
}
}
Expand Down
Loading

0 comments on commit 1b8019d

Please sign in to comment.