aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG4
-rw-r--r--Cargo.toml2
-rw-r--r--fuzz/Cargo.toml6
-rw-r--r--fuzz/fuzz_targets/display_c_does_not_panic.rs21
-rw-r--r--src/long_mode/display.rs4
-rw-r--r--src/protected_mode/display.rs4
-rw-r--r--src/real_mode/display.rs4
-rw-r--r--test/long_mode/display.rs176
-rw-r--r--test/protected_mode/display.rs104
9 files changed, 187 insertions, 138 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 3e147bc..74ee269 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,7 @@
+## 1.1.4
+* fix reachable unreachable under `DisplayStyle::C` in 64-, 32-, and 16-bit modes
+* add fuzz target to cover `DisplayStyle::C` formatter for 64-, 32-, and 16-bit modes
+
## 1.1.3
* fix reachable unsoundness via `RegSpec` helper functions
- helpers should only permit creating valid `RegSpec` structs, but three
diff --git a/Cargo.toml b/Cargo.toml
index 1b68279..877d99c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name = "yaxpeax-x86"
-version = "1.1.3"
+version = "1.1.4"
authors = [ "iximeow <me@iximeow.net>" ]
license = "0BSD"
repository = "http://git.iximeow.net/yaxpeax-x86/"
diff --git a/fuzz/Cargo.toml b/fuzz/Cargo.toml
index 5c49296..53bcb81 100644
--- a/fuzz/Cargo.toml
+++ b/fuzz/Cargo.toml
@@ -26,3 +26,9 @@ name = "display_does_not_panic"
path = "fuzz_targets/display_does_not_panic.rs"
test = false
doc = false
+
+[[bin]]
+name = "display_c_does_not_panic"
+path = "fuzz_targets/display_c_does_not_panic.rs"
+test = false
+doc = false
diff --git a/fuzz/fuzz_targets/display_c_does_not_panic.rs b/fuzz/fuzz_targets/display_c_does_not_panic.rs
new file mode 100644
index 0000000..129a560
--- /dev/null
+++ b/fuzz/fuzz_targets/display_c_does_not_panic.rs
@@ -0,0 +1,21 @@
+#![no_main]
+#[macro_use] extern crate libfuzzer_sys;
+extern crate yaxpeax_x86;
+
+fuzz_target!(|data: &[u8]| {
+ let x86_64_decoder = yaxpeax_x86::long_mode::InstDecoder::default();
+ let x86_32_decoder = yaxpeax_x86::protected_mode::InstDecoder::default();
+ let x86_16_decoder = yaxpeax_x86::real_mode::InstDecoder::default();
+
+ if let Ok(inst) = x86_64_decoder.decode_slice(data) {
+ let _ = inst.display_with(yaxpeax_x86::long_mode::DisplayStyle::C).to_string();
+ };
+
+ if let Ok(inst) = x86_32_decoder.decode_slice(data) {
+ let _ = inst.display_with(yaxpeax_x86::protected_mode::DisplayStyle::C).to_string();
+ };
+
+ if let Ok(inst) = x86_16_decoder.decode_slice(data) {
+ let _ = inst.display_with(yaxpeax_x86::real_mode::DisplayStyle::C).to_string();
+ };
+});
diff --git a/src/long_mode/display.rs b/src/long_mode/display.rs
index 3295ae7..9ba128d 100644
--- a/src/long_mode/display.rs
+++ b/src/long_mode/display.rs
@@ -3532,7 +3532,9 @@ fn contextualize_c<T: fmt::Write, Y: YaxColors>(instr: &Instruction, colors: &Y,
write!(out, "${}", colors.number(signed_i32_hex(rel)))
}
}
- _ => { unreachable!() }
+ other => {
+ write!(out, "{}", other)
+ }
}
}
diff --git a/src/protected_mode/display.rs b/src/protected_mode/display.rs
index c2b52eb..69cdbc7 100644
--- a/src/protected_mode/display.rs
+++ b/src/protected_mode/display.rs
@@ -3545,7 +3545,9 @@ fn contextualize_c<T: fmt::Write, Y: YaxColors>(instr: &Instruction, colors: &Y,
write!(out, "${}", colors.number(signed_i32_hex(rel)))
}
}
- _ => { unreachable!() }
+ other => {
+ write!(out, "{}", other)
+ }
}
}
diff --git a/src/real_mode/display.rs b/src/real_mode/display.rs
index 0ae0a46..070ca56 100644
--- a/src/real_mode/display.rs
+++ b/src/real_mode/display.rs
@@ -3545,7 +3545,9 @@ fn contextualize_c<T: fmt::Write, Y: YaxColors>(instr: &Instruction, colors: &Y,
write!(out, "${}", colors.number(signed_i32_hex(rel)))
}
}
- _ => { unreachable!() }
+ other => {
+ write!(out, "{}", other)
+ }
}
}
diff --git a/test/long_mode/display.rs b/test/long_mode/display.rs
index fc59427..fedb183 100644
--- a/test/long_mode/display.rs
+++ b/test/long_mode/display.rs
@@ -4,10 +4,14 @@ use yaxpeax_arch::{AddressBase, Decoder, LengthedInstruction};
use yaxpeax_x86::long_mode::{DisplayStyle, InstDecoder};
fn test_display(data: &[u8], expected: &'static str) {
- test_display_under(&InstDecoder::default(), data, expected);
+ test_display_under(&InstDecoder::default(), DisplayStyle::Intel, data, expected);
}
-fn test_display_under(decoder: &InstDecoder, data: &[u8], expected: &'static str) {
+fn test_c_display(data: &[u8], expected: &'static str) {
+ test_display_under(&InstDecoder::default(), DisplayStyle::C, data, expected);
+}
+
+fn test_display_under(decoder: &InstDecoder, style: DisplayStyle, data: &[u8], expected: &'static str) {
let mut hex = String::new();
for b in data {
write!(hex, "{:02x}", b).unwrap();
@@ -15,7 +19,7 @@ fn test_display_under(decoder: &InstDecoder, data: &[u8], expected: &'static str
let mut reader = yaxpeax_arch::U8Reader::new(data);
match decoder.decode(&mut reader) {
Ok(instr) => {
- let text = format!("{}", instr.display_with(DisplayStyle::C));
+ let text = format!("{}", instr.display_with(style));
assert!(
text == expected,
"display error for {}:\n decoded: {:?} under decoder {}\n displayed: {}\n expected: {}\n",
@@ -93,94 +97,96 @@ fn test_instructions_atnt() {
#[test]
fn test_instructions_c() {
// just modrm
- test_display(&[0x33, 0x08], "ecx ^= [rax]");
- test_display(&[0x33, 0x20], "esp ^= [rax]");
- test_display(&[0x33, 0x05, 0x78, 0x56, 0x34, 0x12], "eax ^= [rip + 0x12345678]");
- test_display(&[0x33, 0x41, 0x23], "eax ^= [rcx + 0x23]");
- test_display(&[0x33, 0x81, 0x23, 0x01, 0x65, 0x43], "eax ^= [rcx + 0x43650123]");
- test_display(&[0x33, 0xc1], "eax ^= ecx");
+ test_c_display(&[0x33, 0x08], "ecx ^= [rax]");
+ test_c_display(&[0x33, 0x20], "esp ^= [rax]");
+ test_c_display(&[0x33, 0x05, 0x78, 0x56, 0x34, 0x12], "eax ^= [rip + 0x12345678]");
+ test_c_display(&[0x33, 0x41, 0x23], "eax ^= [rcx + 0x23]");
+ test_c_display(&[0x33, 0x81, 0x23, 0x01, 0x65, 0x43], "eax ^= [rcx + 0x43650123]");
+ test_c_display(&[0x33, 0xc1], "eax ^= ecx");
// modrm + rex.w
- test_display(&[0x48, 0x33, 0x08], "rcx ^= [rax]");
- test_display(&[0x48, 0x33, 0x20], "rsp ^= [rax]");
- test_display(&[0x48, 0x33, 0x05, 0x78, 0x56, 0x34, 0x12], "rax ^= [rip + 0x12345678]");
- test_display(&[0x48, 0x33, 0x41, 0x23], "rax ^= [rcx + 0x23]");
- test_display(&[0x48, 0x33, 0x81, 0x23, 0x01, 0x65, 0x43], "rax ^= [rcx + 0x43650123]");
- test_display(&[0x48, 0x33, 0xc1], "rax ^= rcx");
+ test_c_display(&[0x48, 0x33, 0x08], "rcx ^= [rax]");
+ test_c_display(&[0x48, 0x33, 0x20], "rsp ^= [rax]");
+ test_c_display(&[0x48, 0x33, 0x05, 0x78, 0x56, 0x34, 0x12], "rax ^= [rip + 0x12345678]");
+ test_c_display(&[0x48, 0x33, 0x41, 0x23], "rax ^= [rcx + 0x23]");
+ test_c_display(&[0x48, 0x33, 0x81, 0x23, 0x01, 0x65, 0x43], "rax ^= [rcx + 0x43650123]");
+ test_c_display(&[0x48, 0x33, 0xc1], "rax ^= rcx");
// modrm + rex.r
- test_display(&[0x44, 0x33, 0x08], "r9d ^= [rax]");
- test_display(&[0x44, 0x33, 0x20], "r12d ^= [rax]");
- test_display(&[0x44, 0x33, 0x05, 0x78, 0x56, 0x34, 0x12], "r8d ^= [rip + 0x12345678]");
- test_display(&[0x44, 0x33, 0x41, 0x23], "r8d ^= [rcx + 0x23]");
- test_display(&[0x44, 0x33, 0x81, 0x23, 0x01, 0x65, 0x43], "r8d ^= [rcx + 0x43650123]");
- test_display(&[0x44, 0x33, 0xc1], "r8d ^= ecx");
+ test_c_display(&[0x44, 0x33, 0x08], "r9d ^= [rax]");
+ test_c_display(&[0x44, 0x33, 0x20], "r12d ^= [rax]");
+ test_c_display(&[0x44, 0x33, 0x05, 0x78, 0x56, 0x34, 0x12], "r8d ^= [rip + 0x12345678]");
+ test_c_display(&[0x44, 0x33, 0x41, 0x23], "r8d ^= [rcx + 0x23]");
+ test_c_display(&[0x44, 0x33, 0x81, 0x23, 0x01, 0x65, 0x43], "r8d ^= [rcx + 0x43650123]");
+ test_c_display(&[0x44, 0x33, 0xc1], "r8d ^= ecx");
// modrm + rex.rb
- test_display(&[0x45, 0x33, 0x08], "r9d ^= [r8]");
- test_display(&[0x45, 0x33, 0x20], "r12d ^= [r8]");
- test_display(&[0x45, 0x33, 0x05, 0x78, 0x56, 0x34, 0x12], "r8d ^= [rip + 0x12345678]");
- test_display(&[0x45, 0x33, 0x41, 0x23], "r8d ^= [r9 + 0x23]");
- test_display(&[0x45, 0x33, 0x81, 0x23, 0x01, 0x65, 0x43], "r8d ^= [r9 + 0x43650123]");
- test_display(&[0x45, 0x33, 0xc1], "r8d ^= r9d");
+ test_c_display(&[0x45, 0x33, 0x08], "r9d ^= [r8]");
+ test_c_display(&[0x45, 0x33, 0x20], "r12d ^= [r8]");
+ test_c_display(&[0x45, 0x33, 0x05, 0x78, 0x56, 0x34, 0x12], "r8d ^= [rip + 0x12345678]");
+ test_c_display(&[0x45, 0x33, 0x41, 0x23], "r8d ^= [r9 + 0x23]");
+ test_c_display(&[0x45, 0x33, 0x81, 0x23, 0x01, 0x65, 0x43], "r8d ^= [r9 + 0x43650123]");
+ test_c_display(&[0x45, 0x33, 0xc1], "r8d ^= r9d");
// sib
- test_display(&[0x33, 0x04, 0x25, 0x11, 0x22, 0x33, 0x44], "eax ^= [0x44332211]");
- test_display(&[0x41, 0x33, 0x04, 0x25, 0x11, 0x22, 0x33, 0x44], "eax ^= [0x44332211]");
-
- test_display(&[0x41, 0x33, 0x44, 0x65, 0x11], "eax ^= [r13 + 0x11]");
-
- test_display(&[0x42, 0x33, 0x34, 0x25, 0x20, 0x30, 0x40, 0x50], "esi ^= [r12 * 1 + 0x50403020]");
-
- test_display(&[0x4f, 0x0f, 0xe7, 0x03], "[r11] = movntq(mm0)");
- test_display(&[0x0f, 0xe7, 0x03], "[rbx] = movntq(mm0)");
-
- test_display(&[0x4f, 0x0f, 0x7f, 0x0f], "[r15] = movq(mm1)");
- test_display(&[0x0f, 0xc4, 0xc0, 0x14], "mm0 = pinsrw(mm0, eax, 0x14)");
-
- test_display(&[0x4f, 0x0f, 0xd1, 0x00], "mm0 = psrlw(mm0, [r8])");
- test_display(&[0x0f, 0xe5, 0x3d, 0xaa, 0xbb, 0xcc, 0x77], "mm7 = pmulhw(mm7, [rip + 0x77ccbbaa])");
-
- test_display(&[0xf3, 0x48, 0xa5], "rep qword { es:[rdi++] = ds:[rsi++] }");
- test_display(&[0xf3, 0xa5], "rep dword { es:[rdi++] = ds:[rsi++] }");
- test_display(&[0xf3, 0x66, 0xa5], "rep word { es:[rdi++] = ds:[rsi++] }");
- test_display(&[0xf3, 0xa4], "rep byte { es:[rdi++] = ds:[rsi++] }");
-
- test_display(&[0xf6, 0xc2, 0x18], "rflags = flags(dl & 0x18)");
- test_display(&[0xf6, 0xc2, 0x18], "rflags = flags(dl & 0x18)");
- test_display(&[0x84, 0xc0], "rflags = flags(al & al)");
- test_display(&[0x85, 0xc0], "rflags = flags(eax & eax)");
- test_display(&[0x3a, 0xc0], "rflags = flags(al - al)");
- test_display(&[0x3b, 0xc0], "rflags = flags(eax - eax)");
-
- test_display(&[0x41, 0x0f, 0xbc, 0xd3], "edx = lsb(r11d) (x86 bsf)");
- test_display(&[0xf3, 0x41, 0x0f, 0xbc, 0xd3], "edx = lsb(r11d)");
- // test_display(&[0x41, 0x0f, 0xbc, 0xd3], "edx = lsb(r11d) (x86 bsf"); // for non-bm1
- test_display(&[0x41, 0x0f, 0xbd, 0xd3], "edx = msb(r11d)");
- // test_display(&[0x41, 0x0f, 0xbc, 0xd3], "edx = lsb(r11d) (x86 bsr"); // for non-bm1
- test_display(&[0xd2, 0xc0], "al = al rol cl");
- test_display(&[0xd2, 0xc8], "al = al ror cl");
- test_display(&[0xd2, 0xd0], "al = al rcl cl");
- test_display(&[0xd2, 0xd8], "al = al rcr cl");
- test_display(&[0xd2, 0xe0], "al = al << cl");
- test_display(&[0xd2, 0xe8], "al = al >> cl");
- test_display(&[0xd2, 0xf0], "al = al <<< cl");
- test_display(&[0xd2, 0xf8], "al = al >>> cl");
-
- test_display(&[0xc4, 0xc3, 0x7b, 0xf0, 0x01, 0x05], "eax = [r9] ror 0x5 (x86 rorx)");
- test_display(&[0xc4, 0xc2, 0xe3, 0xf7, 0x01], "rax = [r9] >> rbx (x86 shrx)");
- test_display(&[0xc4, 0xc2, 0xe1, 0xf7, 0x01], "rax = [r9] << rbx (x86 shlx)");
-
- test_display(&[0xd2, 0xe0], "al = al << cl");
-
- test_display(&[0x66, 0x0f, 0xac, 0xcf, 0x11], "di = shrd(di, cx, 0x11)");
- test_display(&[0x0f, 0xa5, 0xc9], "ecx = shld(ecx, ecx, cl)");
-
- test_display(&[0x66, 0x0f, 0x38, 0xf6, 0x01], "eax += [rcx] + rflags.cf");
- test_display(&[0xf3, 0x4f, 0x0f, 0x38, 0xf6, 0x01], "r8 += [r9] + rflags.of");
-
- test_display(&[0xfe, 0x00], "byte [rax]++");
- test_display(&[0x66, 0xff, 0x08], "word [rax]--");
- test_display(&[0xff, 0x00], "dword [rax]++");
- test_display(&[0x48, 0xff, 0x00], "qword [rax]++");
+ test_c_display(&[0x33, 0x04, 0x25, 0x11, 0x22, 0x33, 0x44], "eax ^= [0x44332211]");
+ test_c_display(&[0x41, 0x33, 0x04, 0x25, 0x11, 0x22, 0x33, 0x44], "eax ^= [0x44332211]");
+
+ test_c_display(&[0x41, 0x33, 0x44, 0x65, 0x11], "eax ^= [r13 + 0x11]");
+
+ test_c_display(&[0x42, 0x33, 0x34, 0x25, 0x20, 0x30, 0x40, 0x50], "esi ^= [r12 * 1 + 0x50403020]");
+
+ test_c_display(&[0x4f, 0x0f, 0xe7, 0x03], "[r11] = movntq(mm0)");
+ test_c_display(&[0x0f, 0xe7, 0x03], "[rbx] = movntq(mm0)");
+
+ test_c_display(&[0x4f, 0x0f, 0x7f, 0x0f], "[r15] = movq(mm1)");
+ test_c_display(&[0x0f, 0xc4, 0xc0, 0x14], "mm0 = pinsrw(mm0, eax, 0x14)");
+
+ test_c_display(&[0x4f, 0x0f, 0xd1, 0x00], "mm0 = psrlw(mm0, [r8])");
+ test_c_display(&[0x0f, 0xe5, 0x3d, 0xaa, 0xbb, 0xcc, 0x77], "mm7 = pmulhw(mm7, [rip + 0x77ccbbaa])");
+
+ test_c_display(&[0xf3, 0x48, 0xa5], "rep qword { es:[rdi++] = ds:[rsi++] }");
+ test_c_display(&[0xf3, 0xa5], "rep dword { es:[rdi++] = ds:[rsi++] }");
+ test_c_display(&[0xf3, 0x66, 0xa5], "rep word { es:[rdi++] = ds:[rsi++] }");
+ test_c_display(&[0xf3, 0xa4], "rep byte { es:[rdi++] = ds:[rsi++] }");
+
+ test_c_display(&[0xf6, 0xc2, 0x18], "rflags = flags(dl & 0x18)");
+ test_c_display(&[0xf6, 0xc2, 0x18], "rflags = flags(dl & 0x18)");
+ test_c_display(&[0x84, 0xc0], "rflags = flags(al & al)");
+ test_c_display(&[0x85, 0xc0], "rflags = flags(eax & eax)");
+ test_c_display(&[0x3a, 0xc0], "rflags = flags(al - al)");
+ test_c_display(&[0x3b, 0xc0], "rflags = flags(eax - eax)");
+
+ test_c_display(&[0x41, 0x0f, 0xbc, 0xd3], "edx = lsb(r11d) (x86 bsf)");
+ test_c_display(&[0xf3, 0x41, 0x0f, 0xbc, 0xd3], "edx = lsb(r11d)");
+ // test_c_display(&[0x41, 0x0f, 0xbc, 0xd3], "edx = lsb(r11d) (x86 bsf"); // for non-bm1
+ test_c_display(&[0x41, 0x0f, 0xbd, 0xd3], "edx = msb(r11d)");
+ // test_c_display(&[0x41, 0x0f, 0xbc, 0xd3], "edx = lsb(r11d) (x86 bsr"); // for non-bm1
+ test_c_display(&[0xd2, 0xc0], "al = al rol cl");
+ test_c_display(&[0xd2, 0xc8], "al = al ror cl");
+ test_c_display(&[0xd2, 0xd0], "al = al rcl cl");
+ test_c_display(&[0xd2, 0xd8], "al = al rcr cl");
+ test_c_display(&[0xd2, 0xe0], "al = al << cl");
+ test_c_display(&[0xd2, 0xe8], "al = al >> cl");
+ test_c_display(&[0xd2, 0xf0], "al = al <<< cl");
+ test_c_display(&[0xd2, 0xf8], "al = al >>> cl");
+
+ test_c_display(&[0xc4, 0xc3, 0x7b, 0xf0, 0x01, 0x05], "eax = [r9] ror 0x5 (x86 rorx)");
+ test_c_display(&[0xc4, 0xc2, 0xe3, 0xf7, 0x01], "rax = [r9] >> rbx (x86 shrx)");
+ test_c_display(&[0xc4, 0xc2, 0xe1, 0xf7, 0x01], "rax = [r9] << rbx (x86 shlx)");
+
+ test_c_display(&[0xd2, 0xe0], "al = al << cl");
+
+ test_c_display(&[0x66, 0x0f, 0xac, 0xcf, 0x11], "di = shrd(di, cx, 0x11)");
+ test_c_display(&[0x0f, 0xa5, 0xc9], "ecx = shld(ecx, ecx, cl)");
+
+ test_c_display(&[0x66, 0x0f, 0x38, 0xf6, 0x01], "eax += [rcx] + rflags.cf");
+ test_c_display(&[0xf3, 0x4f, 0x0f, 0x38, 0xf6, 0x01], "r8 += [r9] + rflags.of");
+
+ test_c_display(&[0xfe, 0x00], "byte [rax]++");
+ test_c_display(&[0x66, 0xff, 0x08], "word [rax]--");
+ test_c_display(&[0xff, 0x00], "dword [rax]++");
+ test_c_display(&[0x48, 0xff, 0x00], "qword [rax]++");
+
+ test_c_display(&[0xff, 0xe0], "jmp rax");
}
diff --git a/test/protected_mode/display.rs b/test/protected_mode/display.rs
index 694c38c..5f0c68d 100644
--- a/test/protected_mode/display.rs
+++ b/test/protected_mode/display.rs
@@ -4,10 +4,14 @@ use yaxpeax_arch::{AddressBase, Decoder, LengthedInstruction};
use yaxpeax_x86::protected_mode::{DisplayStyle, InstDecoder};
fn test_display(data: &[u8], expected: &'static str) {
- test_display_under(&InstDecoder::default(), data, expected);
+ test_display_under(&InstDecoder::default(), DisplayStyle::Intel, data, expected);
}
-fn test_display_under(decoder: &InstDecoder, data: &[u8], expected: &'static str) {
+fn test_c_display(data: &[u8], expected: &'static str) {
+ test_display_under(&InstDecoder::default(), DisplayStyle::C, data, expected);
+}
+
+fn test_display_under(decoder: &InstDecoder, style: DisplayStyle, data: &[u8], expected: &'static str) {
let mut hex = String::new();
for b in data {
write!(hex, "{:02x}", b).unwrap();
@@ -15,7 +19,7 @@ fn test_display_under(decoder: &InstDecoder, data: &[u8], expected: &'static str
let mut reader = yaxpeax_arch::U8Reader::new(data);
match decoder.decode(&mut reader) {
Ok(instr) => {
- let text = format!("{}", instr.display_with(DisplayStyle::C));
+ let text = format!("{}", instr.display_with(style));
assert!(
text == expected,
"display error for {}:\n decoded: {:?} under decoder {}\n displayed: {}\n expected: {}\n",
@@ -68,65 +72,67 @@ fn test_instructions_atnt() {
#[test]
fn test_instructions_c() {
// just modrm
- test_display(&[0x33, 0x08], "ecx ^= [eax]");
- test_display(&[0x33, 0x20], "esp ^= [eax]");
- test_display(&[0x33, 0x05, 0x78, 0x56, 0x34, 0x12], "eax ^= [0x12345678]");
- test_display(&[0x33, 0x41, 0x23], "eax ^= [ecx + 0x23]");
- test_display(&[0x33, 0x81, 0x23, 0x01, 0x65, 0x43], "eax ^= [ecx + 0x43650123]");
- test_display(&[0x33, 0xc1], "eax ^= ecx");
+ test_c_display(&[0x33, 0x08], "ecx ^= [eax]");
+ test_c_display(&[0x33, 0x20], "esp ^= [eax]");
+ test_c_display(&[0x33, 0x05, 0x78, 0x56, 0x34, 0x12], "eax ^= [0x12345678]");
+ test_c_display(&[0x33, 0x41, 0x23], "eax ^= [ecx + 0x23]");
+ test_c_display(&[0x33, 0x81, 0x23, 0x01, 0x65, 0x43], "eax ^= [ecx + 0x43650123]");
+ test_c_display(&[0x33, 0xc1], "eax ^= ecx");
// sib
- test_display(&[0x33, 0x04, 0x25, 0x11, 0x22, 0x33, 0x44], "eax ^= [0x44332211]");
+ test_c_display(&[0x33, 0x04, 0x25, 0x11, 0x22, 0x33, 0x44], "eax ^= [0x44332211]");
+
+ test_c_display(&[0x33, 0x44, 0x65, 0x11], "eax ^= [ebp + 0x11]");
- test_display(&[0x33, 0x44, 0x65, 0x11], "eax ^= [ebp + 0x11]");
+ test_c_display(&[0x33, 0x34, 0x25, 0x20, 0x30, 0x40, 0x50], "esi ^= [0x50403020]");
- test_display(&[0x33, 0x34, 0x25, 0x20, 0x30, 0x40, 0x50], "esi ^= [0x50403020]");
+ test_c_display(&[0x0f, 0xe7, 0x03], "[ebx] = movntq(mm0)");
- test_display(&[0x0f, 0xe7, 0x03], "[ebx] = movntq(mm0)");
+ test_c_display(&[0x0f, 0x7f, 0x0f], "[edi] = movq(mm1)");
+ test_c_display(&[0x0f, 0xc4, 0xc0, 0x14], "mm0 = pinsrw(mm0, eax, 0x14)");
- test_display(&[0x0f, 0x7f, 0x0f], "[edi] = movq(mm1)");
- test_display(&[0x0f, 0xc4, 0xc0, 0x14], "mm0 = pinsrw(mm0, eax, 0x14)");
+ test_c_display(&[0x0f, 0xd1, 0x00], "mm0 = psrlw(mm0, [eax])");
+ test_c_display(&[0x0f, 0xe5, 0x3d, 0xaa, 0xbb, 0xcc, 0x77], "mm7 = pmulhw(mm7, [0x77ccbbaa])");
- test_display(&[0x0f, 0xd1, 0x00], "mm0 = psrlw(mm0, [eax])");
- test_display(&[0x0f, 0xe5, 0x3d, 0xaa, 0xbb, 0xcc, 0x77], "mm7 = pmulhw(mm7, [0x77ccbbaa])");
+ test_c_display(&[0xf3, 0xa5], "rep dword { es:[edi++] = ds:[esi++] }");
+ test_c_display(&[0xf3, 0x66, 0xa5], "rep word { es:[edi++] = ds:[esi++] }");
+ test_c_display(&[0xf3, 0xa4], "rep byte { es:[edi++] = ds:[esi++] }");
- test_display(&[0xf3, 0xa5], "rep dword { es:[edi++] = ds:[esi++] }");
- test_display(&[0xf3, 0x66, 0xa5], "rep word { es:[edi++] = ds:[esi++] }");
- test_display(&[0xf3, 0xa4], "rep byte { es:[edi++] = ds:[esi++] }");
+ test_c_display(&[0xf6, 0xc2, 0x18], "eflags = flags(dl & 0x18)");
+ test_c_display(&[0xf6, 0xc2, 0x18], "eflags = flags(dl & 0x18)");
+ test_c_display(&[0x84, 0xc0], "eflags = flags(al & al)");
+ test_c_display(&[0x85, 0xc0], "eflags = flags(eax & eax)");
+ test_c_display(&[0x3a, 0xc0], "eflags = flags(al - al)");
+ test_c_display(&[0x3b, 0xc0], "eflags = flags(eax - eax)");
- test_display(&[0xf6, 0xc2, 0x18], "eflags = flags(dl & 0x18)");
- test_display(&[0xf6, 0xc2, 0x18], "eflags = flags(dl & 0x18)");
- test_display(&[0x84, 0xc0], "eflags = flags(al & al)");
- test_display(&[0x85, 0xc0], "eflags = flags(eax & eax)");
- test_display(&[0x3a, 0xc0], "eflags = flags(al - al)");
- test_display(&[0x3b, 0xc0], "eflags = flags(eax - eax)");
+ test_c_display(&[0x0f, 0xbc, 0xd3], "edx = lsb(ebx) (x86 bsf)");
+ test_c_display(&[0xf3, 0x0f, 0xbc, 0xd3], "edx = lsb(ebx)");
+ // test_c_display(&[0x41, 0x0f, 0xbc, 0xd3], "edx = lsb(ebx) (x86 bsf"); // for non-bm1
+ test_c_display(&[0x0f, 0xbd, 0xd3], "edx = msb(ebx)");
+ // test_c_display(&[0x41, 0x0f, 0xbc, 0xd3], "edx = lsb(ebx) (x86 bsr"); // for non-bm1
+ test_c_display(&[0xd2, 0xc0], "al = al rol cl");
+ test_c_display(&[0xd2, 0xc8], "al = al ror cl");
+ test_c_display(&[0xd2, 0xd0], "al = al rcl cl");
+ test_c_display(&[0xd2, 0xd8], "al = al rcr cl");
+ test_c_display(&[0xd2, 0xe0], "al = al << cl");
+ test_c_display(&[0xd2, 0xe8], "al = al >> cl");
+ test_c_display(&[0xd2, 0xf0], "al = al <<< cl");
+ test_c_display(&[0xd2, 0xf8], "al = al >>> cl");
- test_display(&[0x0f, 0xbc, 0xd3], "edx = lsb(ebx) (x86 bsf)");
- test_display(&[0xf3, 0x0f, 0xbc, 0xd3], "edx = lsb(ebx)");
- // test_display(&[0x41, 0x0f, 0xbc, 0xd3], "edx = lsb(ebx) (x86 bsf"); // for non-bm1
- test_display(&[0x0f, 0xbd, 0xd3], "edx = msb(ebx)");
- // test_display(&[0x41, 0x0f, 0xbc, 0xd3], "edx = lsb(ebx) (x86 bsr"); // for non-bm1
- test_display(&[0xd2, 0xc0], "al = al rol cl");
- test_display(&[0xd2, 0xc8], "al = al ror cl");
- test_display(&[0xd2, 0xd0], "al = al rcl cl");
- test_display(&[0xd2, 0xd8], "al = al rcr cl");
- test_display(&[0xd2, 0xe0], "al = al << cl");
- test_display(&[0xd2, 0xe8], "al = al >> cl");
- test_display(&[0xd2, 0xf0], "al = al <<< cl");
- test_display(&[0xd2, 0xf8], "al = al >>> cl");
+ test_c_display(&[0xc4, 0xc3, 0x7b, 0xf0, 0x01, 0x05], "eax = [ecx] ror 0x5 (x86 rorx)");
+ test_c_display(&[0xc4, 0xc2, 0xe3, 0xf7, 0x01], "eax = [ecx] >> ebx (x86 shrx)");
+ test_c_display(&[0xc4, 0xc2, 0xe1, 0xf7, 0x01], "eax = [ecx] << ebx (x86 shlx)");
- test_display(&[0xc4, 0xc3, 0x7b, 0xf0, 0x01, 0x05], "eax = [ecx] ror 0x5 (x86 rorx)");
- test_display(&[0xc4, 0xc2, 0xe3, 0xf7, 0x01], "eax = [ecx] >> ebx (x86 shrx)");
- test_display(&[0xc4, 0xc2, 0xe1, 0xf7, 0x01], "eax = [ecx] << ebx (x86 shlx)");
+ test_c_display(&[0xd2, 0xe0], "al = al << cl");
- test_display(&[0xd2, 0xe0], "al = al << cl");
+ test_c_display(&[0x66, 0x0f, 0xac, 0xcf, 0x11], "di = shrd(di, cx, 0x11)");
+ test_c_display(&[0x0f, 0xa5, 0xc9], "ecx = shld(ecx, ecx, cl)");
- test_display(&[0x66, 0x0f, 0xac, 0xcf, 0x11], "di = shrd(di, cx, 0x11)");
- test_display(&[0x0f, 0xa5, 0xc9], "ecx = shld(ecx, ecx, cl)");
+ test_c_display(&[0x66, 0x0f, 0x38, 0xf6, 0x01], "eax += [ecx] + eflags.cf");
- test_display(&[0x66, 0x0f, 0x38, 0xf6, 0x01], "eax += [ecx] + eflags.cf");
+ test_c_display(&[0xfe, 0x00], "byte [eax]++");
+ test_c_display(&[0x66, 0xff, 0x08], "word [eax]--");
+ test_c_display(&[0xff, 0x00], "dword [eax]++");
- test_display(&[0xfe, 0x00], "byte [eax]++");
- test_display(&[0x66, 0xff, 0x08], "word [eax]--");
- test_display(&[0xff, 0x00], "dword [eax]++");
+ test_c_display(&[0xff, 0xe0], "jmp eax");
}