From 282645e18ac920b2c1051a0bdf3e3236ee5839d6 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 3 Jul 2021 16:13:48 -0700 Subject: add tests for MemoryAccessSize, consistentify style on docs --- src/protected_mode/mod.rs | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'src/protected_mode') diff --git a/src/protected_mode/mod.rs b/src/protected_mode/mod.rs index 589d7a3..a088ad6 100644 --- a/src/protected_mode/mod.rs +++ b/src/protected_mode/mod.rs @@ -2684,9 +2684,9 @@ pub struct InstDecoder { } impl InstDecoder { - /// Instantiates an x86 decoder that decodes the bare minimum of protected-mode x86. + /// instantiates an x86 decoder that decodes the bare minimum of protected-mode x86. /// - /// Pedantic and only decodes what the spec says is well-defined, rejecting undefined sequences + /// pedantic and only decodes what the spec says is well-defined, rejecting undefined sequences /// and any instructions defined by extensions. pub fn minimal() -> Self { InstDecoder { @@ -2694,6 +2694,15 @@ impl InstDecoder { } } + /// helper to decode an instruction directly from a byte slice. + /// + /// this lets callers avoid the work of setting up a [`yaxpeax_arch::U8Reader`] for the slice + /// to decode. + pub fn decode_slice(&self, data: &[u8]) -> Result { + let mut reader = yaxpeax_arch::U8Reader::new(data); + self.decode(&mut reader) + } + pub fn sse3(&self) -> bool { self.flags & (1 << 0) != 0 } @@ -4103,6 +4112,17 @@ 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, } @@ -4116,7 +4136,7 @@ impl MemoryAccessSize { } pub fn size_name(&self) -> &'static str { - "name_strings" + MEM_SIZE_STRINGS[self.size as usize - 1] } } -- cgit v1.1