From 3a1de246641e14e51dc138120d67842448c2bf21 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 3 Jul 2021 16:18:28 -0700 Subject: factor out MemoryAccessSize --- src/protected_mode/display.rs | 13 ++----------- src/protected_mode/mod.rs | 30 ++---------------------------- 2 files changed, 4 insertions(+), 39 deletions(-) (limited to 'src/protected_mode') diff --git a/src/protected_mode/display.rs b/src/protected_mode/display.rs index ac869aa..32eeace 100644 --- a/src/protected_mode/display.rs +++ b/src/protected_mode/display.rs @@ -1,5 +1,7 @@ extern crate yaxpeax_arch; +use MEM_SIZE_STRINGS; + use core::fmt; use yaxpeax_arch::{Colorize, ShowContextual, NoColors, YaxColors}; @@ -3321,17 +3323,6 @@ impl Instruction { } } -const MEM_SIZE_STRINGS: [&'static str; 64] = [ - "byte", "word", "BUG", "dword", "far", "ptr", "BUG", "qword", - "BUG", "mword", "BUG", "BUG", "BUG", "BUG", "BUG", "xmmword", - "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", - "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "ymmword", - "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", - "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", - "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", - "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "ptr", "zmmword", -]; - fn contextualize_intel(instr: &Instruction, colors: &Y, _address: u32, _context: Option<&NoContext>, out: &mut T) -> fmt::Result { if instr.prefixes.lock() { write!(out, "lock ")?; diff --git a/src/protected_mode/mod.rs b/src/protected_mode/mod.rs index a088ad6..5e19676 100644 --- a/src/protected_mode/mod.rs +++ b/src/protected_mode/mod.rs @@ -4,6 +4,8 @@ mod evex; mod display; pub mod uarch; +use MemoryAccessSize; + #[cfg(feature = "fmt")] pub use self::display::DisplayStyle; @@ -4112,34 +4114,6 @@ impl Default for Instruction { } } -const MEM_SIZE_STRINGS: [&'static str; 64] = [ - "byte", "word", "BUG", "dword", "far", "ptr", "BUG", "qword", - "BUG", "mword", "BUG", "BUG", "BUG", "BUG", "BUG", "xmmword", - "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", - "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "ymmword", - "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", - "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", - "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", - "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "ptr", "zmmword", -]; - -pub struct MemoryAccessSize { - size: u8, -} -impl MemoryAccessSize { - pub fn bytes_size(&self) -> Option { - if self.size == 63 { - None - } else { - Some(self.size) - } - } - - pub fn size_name(&self) -> &'static str { - MEM_SIZE_STRINGS[self.size as usize - 1] - } -} - impl Instruction { pub fn opcode(&self) -> Opcode { self.opcode -- cgit v1.1