aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2021-03-21 01:02:00 -0700
committeriximeow <me@iximeow.net>2021-03-21 01:21:55 -0700
commita493b4d267c4fb6a042cf071301c8885196b4a91 (patch)
tree9be24cf43e2fef9f48d6f88e0b7716eb5f66ccca /test
parent0c8dccaf591748e6acb9b437d69ba028e59a73cf (diff)
rewrite 0f-based instruction handling
this is... a more significant rewrite than i expected yaxpeax-x86 to ever need. it turns out that capstone is extremely permissive about duplicative 66/f2/f3 prefixes to the point that the implemented prefex handling was unsalvageable. while this replaces the *0f* opcode tables, i haven't profiled these changes. it's possible this is a net improvement for single-byte opcodes, it could be a net loss. code size may be severely impacted. there is still work to do. but this in total gets very close to iced/xed/zydis parity, far more than before. also adds several small extensions, gfni, 3dnow, enqcmd, invpcid, some of cet, and a few missing avx instructions.
Diffstat (limited to 'test')
-rw-r--r--test/long_mode/display.rs3
-rw-r--r--test/long_mode/mod.rs194
2 files changed, 151 insertions, 46 deletions
diff --git a/test/long_mode/display.rs b/test/long_mode/display.rs
index 988e360..7017270 100644
--- a/test/long_mode/display.rs
+++ b/test/long_mode/display.rs
@@ -152,7 +152,8 @@ fn test_instructions_c() {
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)");
+ 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
diff --git a/test/long_mode/mod.rs b/test/long_mode/mod.rs
index a1e8c36..b024103 100644
--- a/test/long_mode/mod.rs
+++ b/test/long_mode/mod.rs
@@ -13,7 +13,7 @@ fn test_invalid(data: &[u8]) {
fn test_invalid_under(decoder: &InstDecoder, data: &[u8]) {
if let Ok(inst) = decoder.decode(data.into_iter().cloned()) {
- assert_eq!(inst.opcode(), Opcode::Invalid, "decoded {:?} from {:02x?} under decoder {}", inst.opcode(), data, decoder);
+ panic!("decoded {:?} from {:02x?} under decoder {}", inst.opcode(), data, decoder);
} else {
// this is fine
}
@@ -161,7 +161,11 @@ fn test_mmx() {
test_display(&[0x0f, 0x75, 0xc2], "pcmpeqw mm0, mm2");
test_display(&[0x0f, 0x76, 0xc2], "pcmpeqd mm0, mm2");
+ test_display(&[0x66, 0x0f, 0xc5, 0xd8, 0xff], "pextrw ebx, xmm0, 0xff");
+ test_invalid(&[0x66, 0x0f, 0xc5, 0x08, 0xff]);
+
test_display(&[0x0f, 0xc5, 0xd1, 0x00], "pextrw edx, mm1, 0x0");
+ test_invalid(&[0x0f, 0xc5, 0x01, 0x00]);
test_display(&[0x0f, 0xd8, 0xc2], "psubusb mm0, mm2");
test_display(&[0x0f, 0xd9, 0xc2], "psubusw mm0, mm2");
@@ -256,7 +260,6 @@ fn test_sse2() {
test_instr(&[0xf2, 0x0f, 0x10, 0x0c, 0xc7], "movsd xmm1, [rdi + rax * 8]");
test_instr(&[0xf2, 0x0f, 0x11, 0x0c, 0xc7], "movsd [rdi + rax * 8], xmm1");
test_instr(&[0x66, 0x0f, 0x11, 0x0c, 0xc7], "movupd [rdi + rax * 8], xmm1");
- test_instr(&[0x66, 0x4f, 0x0f, 0x12, 0xc3], "movhlps xmm8, xmm11"); // reg-reg form is movhlps
test_instr(&[0x66, 0x4f, 0x0f, 0x12, 0x03], "movlpd xmm8, [r11]"); // reg-mem is movlpd
test_instr(&[0x66, 0x4f, 0x0f, 0x13, 0x03], "movlpd [r11], xmm8");
test_invalid(&[0x66, 0x4f, 0x0f, 0x13, 0xc3]);
@@ -265,7 +268,6 @@ fn test_sse2() {
test_instr(&[0x66, 0x4f, 0x0f, 0x15, 0x03], "unpckhpd xmm8, [r11]");
test_instr(&[0x66, 0x4f, 0x0f, 0x15, 0xc3], "unpckhpd xmm8, xmm11");
test_instr(&[0x66, 0x4f, 0x0f, 0x16, 0x03], "movhpd xmm8, [r11]");
- test_instr(&[0x66, 0x4f, 0x0f, 0x16, 0xc3], "movlhps xmm8, xmm11");
test_instr(&[0x66, 0x4f, 0x0f, 0x17, 0x03], "movhpd [r11], xmm8");
test_invalid(&[0x66, 0x4f, 0x0f, 0x17, 0xc3]);
@@ -541,8 +543,11 @@ fn test_sse2() {
test_instr(&[0x66, 0x0f, 0xfd, 0x01], "paddw xmm0, [rcx]");
test_instr(&[0x66, 0x0f, 0xfe, 0xc1], "paddd xmm0, xmm1");
test_instr(&[0x66, 0x0f, 0xfe, 0x01], "paddd xmm0, [rcx]");
- test_instr(&[0x66, 0x0f, 0xff, 0xc1], "paddq xmm0, xmm1");
- test_instr(&[0x66, 0x0f, 0xff, 0x01], "paddq xmm0, [rcx]");
+ test_instr(&[0x66, 0x0f, 0xff, 0xc1], "ud0 eax, ecx");
+ test_instr(&[0xf2, 0x0f, 0xff, 0xc1], "ud0 eax, ecx");
+ test_instr(&[0xf3, 0x0f, 0xff, 0xc1], "ud0 eax, ecx");
+ test_instr(&[0x66, 0x0f, 0xff, 0x01], "ud0 eax, [rcx]");
+ test_instr(&[0x66, 0x4f, 0x0f, 0xff, 0xc1], "ud0 r8d, r9d");
test_instr(&[0x66, 0x0f, 0x74, 0xc1], "pcmpeqb xmm0, xmm1");
test_instr(&[0x66, 0x0f, 0x74, 0x12], "pcmpeqb xmm2, [rdx]");
@@ -571,6 +576,7 @@ fn test_sse3() {
test_instr_invalid(&[0xf2, 0x0f, 0xf0, 0xcf]);
test_instr(&[0xf2, 0x0f, 0xd0, 0x0f], "addsubps xmm1, [rdi]");
test_instr(&[0xf2, 0x0f, 0xd0, 0xcf], "addsubps xmm1, xmm7");
+ test_invalid(&[0xf3, 0x0f, 0xd0, 0x0f]);
test_instr(&[0xf2, 0x4f, 0x0f, 0xd0, 0xcf], "addsubps xmm9, xmm15");
test_instr(&[0x66, 0x0f, 0xd0, 0x0f], "addsubpd xmm1, [rdi]");
test_instr(&[0x66, 0x0f, 0xd0, 0xcf], "addsubpd xmm1, xmm7");
@@ -662,10 +668,10 @@ fn test_sse4_1() {
test_invalid_under(&InstDecoder::default(), bytes);
}
- test_instr(&[0x66, 0x0f, 0x38, 0x0c, 0x06], "blendps xmm0, [rsi]");
- test_invalid(&[0x0f, 0x38, 0x0c, 0x06]);
- test_instr(&[0x66, 0x0f, 0x38, 0x0d, 0x06], "blendpd xmm0, [rsi]");
- test_invalid(&[0x0f, 0x38, 0x0d, 0x06]);
+ test_instr(&[0x66, 0x0f, 0x3a, 0x0c, 0x11, 0x22], "blendps xmm2, [rcx], 0x22");
+ test_instr(&[0x66, 0x0f, 0x3a, 0x0c, 0xc1, 0x22], "blendps xmm0, xmm1, 0x22");
+ test_instr(&[0x66, 0x0f, 0x3a, 0x0d, 0x11, 0x22], "blendpd xmm2, [rcx], 0x22");
+ test_instr(&[0x66, 0x0f, 0x3a, 0x0d, 0xc1, 0x22], "blendpd xmm0, xmm1, 0x22");
test_instr(&[0x66, 0x0f, 0x38, 0x10, 0x06], "pblendvb xmm0, [rsi]");
test_invalid(&[0x0f, 0x38, 0x10, 0x06]);
@@ -696,6 +702,7 @@ fn test_sse4_1() {
test_instr(&[0x66, 0x0f, 0x38, 0x29, 0x06], "pcmpeqq xmm0, [rsi]");
test_invalid(&[0x0f, 0x38, 0x29, 0x06]);
test_instr(&[0x66, 0x0f, 0x38, 0x2a, 0x06], "movntdqa xmm0, [rsi]");
+ test_invalid(&[0x66, 0x0f, 0x38, 0x2a, 0xc6]);
test_invalid(&[0x0f, 0x38, 0x2a, 0x06]);
test_instr(&[0x66, 0x0f, 0x38, 0x2b, 0x06], "packusdw xmm0, [rsi]");
test_invalid(&[0x0f, 0x38, 0x2b, 0x06]);
@@ -878,6 +885,9 @@ fn test_0f01() {
test_display(&[0x0f, 0x01, 0xdd], "clgi");
test_display(&[0x0f, 0x01, 0xde], "skinit eax");
test_display(&[0x0f, 0x01, 0xdf], "invlpga rax, ecx");
+ test_display(&[0x0f, 0x01, 0xfe], "invlpgb rax, edx, ecx");
+ test_display(&[0x0f, 0x01, 0xff], "tlbsync");
+ test_display(&[0x2e, 0x67, 0x65, 0x2e, 0x46, 0x0f, 0x01, 0xff], "tlbsync");
test_display(&[0x4f, 0x0f, 0x01, 0xe0], "smsw r8w");
test_display(&[0x0f, 0x01, 0xe0], "smsw ax");
test_display(&[0x0f, 0x01, 0xe1], "smsw cx");
@@ -911,8 +921,6 @@ fn test_0f01() {
test_display(&[0x0f, 0x01, 0xfb], "mwaitx");
test_display(&[0x0f, 0x01, 0xfc], "clzero");
test_display(&[0x0f, 0x01, 0xfd], "rdpru ecx");
- test_invalid(&[0x0f, 0x01, 0xfe]);
- test_invalid(&[0x0f, 0x01, 0xff]);
}
#[test]
@@ -923,6 +931,9 @@ fn test_0fae() {
let minimal = InstDecoder::minimal();
// drawn heavily from "Table A-6. Opcode Extensions for One- and Two-byte Opcodes by Group
// Number"
+ test_invalid(&[0xf3, 0x0f, 0xae, 0x87]);
+ test_invalid(&[0xf3, 0x0f, 0xae, 0x04, 0x4f]);
+ test_display(&[0x0f, 0xae, 0x04, 0x4f], "fxsave [rdi + rcx * 2]");
test_display(&[0x0f, 0xae, 0x04, 0x4f], "fxsave [rdi + rcx * 2]");
test_display(&[0x0f, 0xae, 0x0c, 0x4f], "fxrstor [rdi + rcx * 2]");
test_display(&[0x0f, 0xae, 0x14, 0x4f], "ldmxcsr [rdi + rcx * 2]");
@@ -968,16 +979,16 @@ fn test_system() {
test_display(&[0x66, 0x4f, 0x0f, 0xb2, 0x00], "lss r8, [r8]");
test_display(&[0x67, 0x4f, 0x0f, 0xb2, 0x00], "lss r8, [r8d]");
test_display(&[0x4f, 0x0f, 0xb2, 0x00], "lss r8, [r8]");
- test_display(&[0x45, 0x0f, 0x22, 0xc8], "mov cr9, r8");
- test_display(&[0x45, 0x0f, 0x20, 0xc8], "mov r8, cr9");
- test_display(&[0x40, 0x0f, 0x22, 0xc8], "mov cr1, rax");
- test_display(&[0x0f, 0x22, 0xc8], "mov cr1, rax");
- test_display(&[0x44, 0x0f, 0x22, 0xcf], "mov cr9, rdi");
- test_display(&[0x0f, 0x22, 0xcf], "mov cr1, rdi");
- test_display(&[0x0f, 0x20, 0xc8], "mov rax, cr1");
-
- test_display(&[0x45, 0x0f, 0x23, 0xc8], "mov dr9, r8");
- test_display(&[0x45, 0x0f, 0x21, 0xc8], "mov r8, dr9");
+ test_invalid(&[0x45, 0x0f, 0x22, 0xc8]);
+ test_invalid(&[0x45, 0x0f, 0x20, 0xc8]);
+ test_display(&[0x40, 0x0f, 0x22, 0xd0], "mov cr2, rax");
+ test_display(&[0x0f, 0x22, 0xd0], "mov cr2, rax");
+ test_invalid(&[0x44, 0x0f, 0x22, 0xcf]);
+ test_display(&[0x0f, 0x22, 0xd7], "mov cr2, rdi");
+ test_display(&[0x0f, 0x20, 0xd0], "mov rax, cr2");
+
+ test_invalid(&[0x45, 0x0f, 0x23, 0xc8]);
+ test_invalid(&[0x45, 0x0f, 0x21, 0xc8]);
test_display(&[0x40, 0x0f, 0x23, 0xc8], "mov dr1, rax");
test_display(&[0x0f, 0x23, 0xc8], "mov dr1, rax");
test_display(&[0x0f, 0x21, 0xc8], "mov rax, dr1");
@@ -1125,10 +1136,10 @@ fn test_mov() {
test_display(&[0x0f, 0x97, 0xc8], "seta al");
test_display(&[0x0f, 0x97, 0x00], "seta [rax]");
test_display(&[0x0f, 0x97, 0x08], "seta [rax]");
- test_display(&[0xd6], "salc");
+// test_display(&[0xd6], "salc");
test_display(&[0x8e, 0x00], "mov es, [rax]");
- // cs is not an allowed destination - would #ud on execution
- test_display(&[0x8e, 0x08], "mov cs, [rax]");
+ // cs is not an allowed destination
+ test_invalid(&[0x8e, 0x08]);
test_display(&[0x8e, 0x10], "mov ss, [rax]");
test_display(&[0x8e, 0x18], "mov ds, [rax]");
test_display(&[0x8e, 0x20], "mov fs, [rax]");
@@ -1158,7 +1169,17 @@ fn test_prefixes() {
test_invalid(&[0xf0, 0x33, 0xc0]);
test_display(&[0xf0, 0x31, 0x00], "lock xor [rax], eax");
test_display(&[0xf0, 0x80, 0x30, 0x00], "lock xor [rax], 0x0");
+ test_display(&[0xf0, 0x0f, 0xbb, 0x17], "lock btc [rdi], edx");
+ test_display(&[0x66, 0x2e, 0xf2, 0xf0, 0x0f, 0xbb, 0x13], "lock btc [rbx], dx");
test_invalid(&[0xf0, 0xc7, 0x00, 0x00, 0x00, 0x00]);
+ test_display(&[0x0f, 0xc1, 0xcc], "xadd esp, ecx");
+ test_display(&[0x66, 0x0f, 0xc1, 0xcc], "xadd sp, cx");
+ test_display(&[0xf2, 0x0f, 0xc1, 0xcc], "xadd esp, ecx");
+ test_display(&[0xf3, 0x0f, 0xc1, 0xcc], "xadd esp, ecx");
+ test_display(&[0x0f, 0xc0, 0xcc], "xadd ah, cl");
+ test_display(&[0x66, 0x0f, 0xc0, 0xcc], "xadd ah, cl");
+ test_display(&[0xf2, 0x0f, 0xc0, 0xcc], "xadd ah, cl");
+ test_display(&[0xf3, 0x0f, 0xc0, 0xcc], "xadd ah, cl");
}
#[test]
@@ -1215,8 +1236,10 @@ fn test_push_pop() {
fn test_bmi1() {
let bmi1 = InstDecoder::minimal().with_bmi1();
let no_bmi1 = InstDecoder::minimal();
- test_display_under(&bmi1, &[0x41, 0x0f, 0xbc, 0xd3], "tzcnt edx, r11d");
- test_display_under(&no_bmi1, &[0x41, 0x0f, 0xbc, 0xd3], "bsf edx, r11d");
+ test_display_under(&bmi1, &[0xf3, 0x41, 0x0f, 0xbc, 0xd3], "tzcnt edx, r11d");
+ test_display_under(&bmi1, &[0xf2, 0x41, 0x0f, 0xbc, 0xd3], "bsf edx, r11d");
+ test_display_under(&bmi1, &[0x41, 0x0f, 0xbc, 0xd3], "bsf edx, r11d");
+ test_display_under(&no_bmi1, &[0xf3, 0x41, 0x0f, 0xbc, 0xd3], "bsf edx, r11d");
// just 0f38
test_display_under(&bmi1, &[0xc4, 0xc2, 0x60, 0xf2, 0x01], "andn eax, ebx, [r9]");
@@ -1276,6 +1299,8 @@ fn test_popcnt() {
#[test]
fn test_bitwise() {
test_display_under(&InstDecoder::minimal(), &[0x41, 0x0f, 0xbc, 0xd3], "bsf edx, r11d");
+ test_display_under(&InstDecoder::minimal(), &[0x0f, 0xbb, 0x17], "btc [rdi], edx");
+ test_display_under(&InstDecoder::minimal(), &[0xf0, 0x0f, 0xbb, 0x17], "lock btc [rdi], edx");
test_display(&[0x48, 0x0f, 0xa3, 0xd0], "bt rax, rdx");
test_display(&[0x48, 0x0f, 0xab, 0xd0], "bts rax, rdx");
test_display(&[0x48, 0x0f, 0xb3, 0xd0], "btr rax, rdx");
@@ -1333,6 +1358,10 @@ fn test_misc() {
test_display(&[0xf3, 0x48, 0xa5], "rep movs es:[rdi], ds:[rsi]");
test_display(&[0xf3, 0x45, 0x0f, 0xbc, 0xd7], "tzcnt r10d, r15d");
+ test_display(&[0xf3, 0x0f, 0xae, 0x26], "ptwrite [rsi]");
+ test_display(&[0xf3, 0x0f, 0xae, 0xe6], "ptwrite esi");
+ test_invalid(&[0x66, 0xf3, 0x0f, 0xae, 0xe6]);
+ test_display(&[0xf3, 0x49, 0x0f, 0xae, 0x26], "ptwrite [r14]");
test_display(&[0xf3, 0x0f, 0xae, 0xc4], "rdfsbase esp");
test_display(&[0xf3, 0x4f, 0x0f, 0xae, 0xc4], "rdfsbase r12");
test_display(&[0xf3, 0x0f, 0xae, 0xcc], "rdgsbase esp");
@@ -1345,6 +1374,18 @@ fn test_misc() {
test_invalid(&[0x66, 0x0f, 0xae, 0xff]);
test_display(&[0x66, 0x0f, 0xae, 0x37], "clwb [rdi]");
test_invalid(&[0x66, 0x0f, 0xae, 0xf7]);
+ test_display(&[0x66, 0x0f, 0x38, 0x80, 0x2f], "invept ebp, [rdi]");
+ test_display(&[0x66, 0x49, 0x0f, 0x38, 0x80, 0x2f], "invept rbp, [r15]");
+ test_invalid(&[0x0f, 0x38, 0x80, 0x2f]);
+ test_invalid(&[0x43, 0x0f, 0x38, 0x80, 0x2f]);
+ test_display(&[0x66, 0x0f, 0x38, 0x81, 0x2f], "invvpid ebp, [rdi]");
+ test_display(&[0x66, 0x49, 0x0f, 0x38, 0x81, 0x2f], "invvpid rbp, [r15]");
+ test_invalid(&[0x0f, 0x38, 0x81, 0x2f]);
+ test_invalid(&[0x43, 0x0f, 0x38, 0x81, 0x2f]);
+ test_display(&[0x66, 0x0f, 0x38, 0x82, 0x2f], "invpcid ebp, [rdi]");
+ test_display(&[0x66, 0x49, 0x0f, 0x38, 0x82, 0x2f], "invpcid rbp, [r15]");
+ test_invalid(&[0x0f, 0x38, 0x82, 0x2f]);
+ test_invalid(&[0x43, 0x0f, 0x38, 0x82, 0x2f]);
}
#[test]
@@ -1494,6 +1535,12 @@ fn test_vex() {
test_instr(&[0xc5, 0xf1, 0xc4, 0xd8, 0x78], "vpinsrw xmm3, xmm1, eax, 0x78");
test_instr(&[0xc5, 0xf1, 0xc4, 0x18, 0x78], "vpinsrw xmm3, xmm1, [rax], 0x78");
+
+ // uh oh, i think these sizes are backwards...
+ test_instr(&[0xc5, 0xe0, 0x54, 0x03], "vandpd xmm0, xmm3, [rbx]");
+ test_instr(&[0xc5, 0xe1, 0x54, 0x03], "vandps xmm0, xmm3, [rbx]");
+ test_instr(&[0xc5, 0xe0, 0x55, 0x03], "vandnpd xmm0, xmm3, [rbx]");
+ test_instr(&[0xc5, 0xe1, 0x55, 0x03], "vandnps xmm0, xmm3, [rbx]");
}
#[test]
@@ -1531,13 +1578,14 @@ fn prefixed_0f() {
test_display(&[0x0f, 0x16, 0xc0], "movlhps xmm0, xmm0");
test_invalid(&[0x0f, 0x17, 0xc0]);
test_display(&[0x0f, 0x17, 0x00], "movhps [rax], xmm0");
- test_invalid(&[0x0f, 0x18, 0xc0]);
+ test_display(&[0x0f, 0x18, 0xc0], "nop eax"); // capstone says invalid, xed says nop
test_display(&[0x0f, 0x18, 0x00], "prefetchnta [rax]");
test_display(&[0x0f, 0x18, 0x08], "prefetch0 [rax]");
test_display(&[0x0f, 0x18, 0x10], "prefetch1 [rax]");
test_display(&[0x0f, 0x18, 0x18], "prefetch2 [rax]");
test_display(&[0x0f, 0x18, 0x20], "nop [rax]");
test_display(&[0x4f, 0x0f, 0x18, 0x20], "nop [r8]");
+ test_display(&[0x0f, 0x18, 0xcc], "nop esp");
test_display(&[0x0f, 0x19, 0x20], "nop [rax]");
test_display(&[0x0f, 0x1a, 0x20], "nop [rax]");
test_display(&[0x0f, 0x1b, 0x20], "nop [rax]");
@@ -1545,19 +1593,23 @@ fn prefixed_0f() {
test_display(&[0x0f, 0x1d, 0x20], "nop [rax]");
test_display(&[0x0f, 0x1e, 0x20], "nop [rax]");
test_display(&[0x0f, 0x1f, 0x20], "nop [rax]");
- test_display(&[0x45, 0x0f, 0x20, 0xc8], "mov r8, cr9");
- test_display(&[0x0f, 0x20, 0xc8], "mov rax, cr1");
- test_display(&[0x45, 0x0f, 0x21, 0xc8], "mov r8, dr9");
+ test_invalid(&[0x45, 0x0f, 0x20, 0xc8]);
+ test_display(&[0x45, 0x0f, 0x20, 0xc0], "mov r8, cr8");
+ test_invalid(&[0x0f, 0x20, 0xc8]);
+ test_invalid(&[0x45, 0x0f, 0x21, 0xc8]);
test_display(&[0x0f, 0x21, 0xc8], "mov rax, dr1");
- test_display(&[0x45, 0x0f, 0x22, 0xc8], "mov cr9, r8");
- test_display(&[0x40, 0x0f, 0x22, 0xc8], "mov cr1, rax");
- test_display(&[0x0f, 0x22, 0xc8], "mov cr1, rax");
- test_display(&[0x44, 0x0f, 0x22, 0xcf], "mov cr9, rdi");
- test_display(&[0x0f, 0x22, 0xcf], "mov cr1, rdi");
- test_display(&[0x45, 0x0f, 0x23, 0xc8], "mov dr9, r8");
+ test_invalid(&[0x45, 0x0f, 0x22, 0xc8]);
+ test_display(&[0x45, 0x0f, 0x22, 0xc0], "mov cr8, r8");
+ test_invalid(&[0x40, 0x0f, 0x22, 0xc8]);
+ test_invalid(&[0x0f, 0x22, 0xc8]);
+ test_display(&[0x0f, 0x22, 0xc0], "mov cr0, rax");
+ test_invalid(&[0x44, 0x0f, 0x22, 0xcf]);
+ test_display(&[0x0f, 0x22, 0xc7], "mov cr0, rdi");
+ test_invalid(&[0x0f, 0x22, 0xcf]);
+ test_invalid(&[0x45, 0x0f, 0x23, 0xc8]);
test_display(&[0x40, 0x0f, 0x23, 0xc8], "mov dr1, rax");
test_display(&[0x0f, 0x23, 0xc8], "mov dr1, rax");
- test_display(&[0x44, 0x0f, 0x23, 0xcf], "mov dr9, rdi");
+ test_invalid(&[0x44, 0x0f, 0x23, 0xcf]);
test_display(&[0x0f, 0x23, 0xcf], "mov dr1, rdi");
test_display(&[0x0f, 0x30], "wrmsr");
test_display(&[0x0f, 0x31], "rdtsc");
@@ -1567,6 +1619,9 @@ fn prefixed_0f() {
test_display(&[0x0f, 0x35], "sysexit");
test_invalid(&[0x0f, 0x36]);
test_display(&[0x0f, 0x37], "getsec");
+ test_invalid(&[0x66, 0x0f, 0x37]);
+ test_invalid(&[0xf2, 0x0f, 0x37]);
+ test_invalid(&[0xf3, 0x0f, 0x37]);
test_display(&[0x0f, 0x60, 0x00], "punpcklbw mm0, [rax]");
test_display(&[0x0f, 0x60, 0xc2], "punpcklbw mm0, mm2");
test_display(&[0x0f, 0x61, 0x00], "punpcklwd mm0, [rax]");
@@ -1637,14 +1692,14 @@ fn prefixed_660f() {
test_display(&[0x66, 0x4b, 0x0f, 0x10, 0xc0], "movupd xmm0, xmm8");
test_display(&[0x66, 0x4c, 0x0f, 0x10, 0xc0], "movupd xmm8, xmm0");
test_display(&[0x66, 0x4d, 0x0f, 0x10, 0xc0], "movupd xmm8, xmm8");
- test_display(&[0xf2, 0x66, 0x66, 0x4d, 0x0f, 0x10, 0xc0], "movupd xmm8, xmm8");
+ test_display(&[0xf2, 0x66, 0x66, 0x4d, 0x0f, 0x10, 0xc0], "movsd xmm8, xmm8");
}
#[test]
fn prefixed_f20f() {
test_invalid(&[0xf2, 0x0f, 0x16, 0xcf]);
test_invalid(&[0xf2, 0x4d, 0x0f, 0x16, 0xcf]);
- test_display(&[0x40, 0x66, 0xf2, 0x66, 0x4d, 0x0f, 0x16, 0xcf], "movlhps xmm9, xmm15");
+ test_invalid(&[0x40, 0x66, 0xf2, 0x66, 0x4d, 0x0f, 0x16, 0xcf]);
}
#[test]
@@ -1697,6 +1752,11 @@ fn test_svm() {
fn test_movbe() {
test_display(&[0x0f, 0x38, 0xf0, 0x06], "movbe eax, [rsi]");
test_display(&[0x4f, 0x0f, 0x38, 0xf0, 0x06], "movbe r8, [r14]");
+ test_invalid(&[0x4f, 0x0f, 0x38, 0xf0, 0xc6]);
+ test_display(&[0x0f, 0x38, 0xf1, 0x06], "movbe [rsi], eax");
+ test_display(&[0x4f, 0x0f, 0x38, 0xf1, 0x06], "movbe [r14], r8");
+ test_display(&[0x66, 0x0f, 0x38, 0xf1, 0x06], "movbe [rsi], ax");
+ test_invalid(&[0x66, 0x0f, 0x38, 0xf1, 0xc6]);
}
#[test]
@@ -1721,6 +1781,7 @@ fn test_rand() {
#[test]
fn test_sha() {
test_display(&[0x0f, 0x3a, 0xcc, 0x12, 0x40], "sha1rnds4 xmm2, [rdx], 0x40");
+ test_display(&[0x0f, 0x3a, 0xcc, 0x12, 0xff], "sha1rnds4 xmm2, [rdx], 0xff");
test_display(&[0x0f, 0x38, 0xc8, 0x12], "sha1nexte xmm2, [rdx]");
test_display(&[0x0f, 0x38, 0xc9, 0x12], "sha1msg1 xmm2, [rdx]");
test_display(&[0x0f, 0x38, 0xca, 0x12], "sha1msg2 xmm2, [rdx]");
@@ -1754,7 +1815,13 @@ fn test_rdpid() {
#[test]
fn test_cmpxchg8b() {
test_display(&[0x0f, 0xc7, 0x0f], "cmpxchg8b [rdi]");
+ test_display(&[0xf2, 0x0f, 0xc7, 0x0f], "cmpxchg8b [rdi]");
+ test_display(&[0xf3, 0x0f, 0xc7, 0x0f], "cmpxchg8b [rdi]");
+ test_display(&[0x66, 0x0f, 0xc7, 0x0f], "cmpxchg8b [rdi]");
test_display(&[0x4f, 0x0f, 0xc7, 0x0f], "cmpxchg16b [r15]");
+ test_display(&[0xf2, 0x4f, 0x0f, 0xc7, 0x0f], "cmpxchg16b [r15]");
+ test_display(&[0xf3, 0x4f, 0x0f, 0xc7, 0x0f], "cmpxchg16b [r15]");
+ test_display(&[0x66, 0x4f, 0x0f, 0xc7, 0x0f], "cmpxchg16b [r15]");
}
#[test]
@@ -2142,27 +2209,28 @@ fn test_mishegos_finds() {
test_display(&[0x65, 0x67, 0x65, 0x65, 0x0f, 0x0e], "femms");
test_display(&[0x26, 0x66, 0x67, 0x41, 0x0f, 0x38, 0xdf, 0xe4], "aesdeclast xmm4, xmm12");
test_display(&[0x65, 0x66, 0x66, 0x64, 0x48, 0x0f, 0x38, 0xdb, 0x0f], "aesimc xmm1, fs:[rdi]");
+ test_invalid(&[0xf3, 0xf2, 0x41, 0x0f, 0xae, 0x8f, 0x54, 0x3c, 0x58, 0xb7]);
/*
test_display(&[652e662e0f3814ff], "blendvps");
test_display(&[66666565450f3acf2b4b], "gf2 ");
- test_display(&[2e64f2f3400f38fbf8], "encodekey256");
*/
// might just be yax trying to do a f20f decode when it should not be f2
// impossible instruction if operands could be read: lock is illegal here.
// test_display(&[f06565f2640f16], "???");
// test_display(&[0x0f, 0x38, 0xf6, 0x8c, 0x98, 0x4d, 0x33, 0xf5, 0xd3, ], "wrssd");
- test_display(&[0x26, 0x36, 0x0f, 0x0f, 0x70, 0xfb, 0x0c], "pi2fw");
+ test_display(&[0x26, 0x36, 0x0f, 0x0f, 0x70, 0xfb, 0x0c], "pi2fw mm6, [rax - 0x5]");
test_display(&[0x0f, 0xc7, 0x0f], "cmpxchg8b [rdi]");
test_display(&[0x4f, 0x0f, 0xc7, 0x0f], "cmpxchg16b [r15]");
test_display(&[0x66, 0x3e, 0x26, 0x2e, 0x2e, 0x0f, 0x38, 0x2a, 0x2b, ], "movntdqa xmm5, [rbx]");
test_display(&[0x66, 0x2e, 0x67, 0x0f, 0x3a, 0x0d, 0xb8, 0xf0, 0x2f, 0x7c, 0xf0, 0x63, ], "blendpd xmm7, [eax - 0xf83d010], 0x63");
- test_display(&[0x66, 0x66, 0x64, 0x3e, 0x0f, 0x38, 0x23, 0x9d, 0x69, 0x0f, 0xa8, 0x2d, ], "pmovsxwd xmm3, [rbp + 0x2da80f69]");
+ test_display(&[0x66, 0x66, 0x64, 0x3e, 0x0f, 0x38, 0x23, 0x9d, 0x69, 0x0f, 0xa8, 0x2d, ], "pmovsxwd xmm3, fs:[rbp + 0x2da80f69]");
test_display(&[0x2e, 0x66, 0x26, 0x64, 0x49, 0x0f, 0x3a, 0x21, 0x0b, 0xb1, ], "insertps xmm1, fs:[r11], -0x4f");
test_display(&[0x66, 0x26, 0x45, 0x0f, 0x3a, 0x42, 0x96, 0x74, 0x29, 0x96, 0xf9, 0x6a], "mpsadbw xmm10, [r14 - 0x669d68c], 0x6a");
test_display(&[0x67, 0x26, 0x66, 0x65, 0x0f, 0x38, 0x3f, 0x9d, 0xcc, 0x03, 0xb3, 0xfa], "pmaxud xmm3, gs:[ebp - 0x54cfc34]");
test_display(&[0x36, 0x36, 0x2e, 0x0f, 0x38, 0xf9, 0x55, 0x3e, ], "movdiri [rbp + 0x3e], edx");
test_display(&[0x36, 0x26, 0x66, 0x0f, 0x38, 0xf8, 0xad, 0x0b, 0x08, 0x29, 0x07], "movdir64b rbp, [rbp + 0x729080b]");
+ test_invalid(&[0x66, 0x2e, 0x64, 0x66, 0x46, 0x0f, 0x38, 0xf8, 0xe2]);
test_display(&[0x36, 0x26, 0x66, 0x67, 0x0f, 0x38, 0xf8, 0xad, 0x0b, 0x08, 0x29, 0x07], "movdir64b ebp, [ebp + 0x729080b]");
test_display(&[0x67, 0x66, 0x65, 0x3e, 0x0f, 0x6d, 0xd1], "punpckhqdq xmm2, xmm1");
test_display(&[0x2e, 0x66, 0x40, 0x0f, 0x3a, 0x0d, 0x40, 0x2d, 0x57], "blendpd xmm0, [rax + 0x2d], 0x57");
@@ -2172,10 +2240,11 @@ fn test_mishegos_finds() {
test_display(&[0x2e, 0x36, 0x47, 0x0f, 0x18, 0xe7], "nop r15d");
test_display(&[0x65, 0xf0, 0x87, 0x0f], "lock xchg gs:[rdi], ecx");
test_display(&[0x66, 0x4e, 0x0f, 0x3a, 0x44, 0x88, 0xb3, 0xad, 0x26, 0x35, 0x75], "pclmulqdq xmm9, [rax + 0x3526adb3], 0x75");
- test_display(&[0x4c, 0x0f, 0xff, 0x6b, 0xac], "ud0 r13, [rbx - 0x54]");
+ test_display(&[0x4c, 0x0f, 0xff, 0x6b, 0xac], "ud0 r13d, [rbx - 0x54]");
test_display(&[0xf2, 0xf2, 0x2e, 0x36, 0x47, 0x0f, 0x38, 0xf8, 0x83, 0x09, 0x1c, 0x9d, 0x3f], "enqcmd r8d, [r11 + 0x3f9d1c09]");
test_display(&[0x3e, 0x64, 0xf3, 0x64, 0x0f, 0x38, 0xf8, 0x72, 0x54], "enqcmds esi, fs:[rdx + 0x54]");
+ test_invalid(&[0xf3, 0x0f, 0x38, 0xf8, 0xf3]);
test_display(&[0xf3, 0x64, 0x2e, 0x65, 0x0f, 0x38, 0xdc, 0xe8], "loadiwkey xmm5, xmm0");
@@ -2198,18 +2267,44 @@ fn test_cet() {
// clrssbsy f3 0f ae /6
// endbr64 f3 0f ae fa
// endbr32 f3 0f ae fb
+ test_display(&[0x3e, 0x4f, 0x0f, 0x38, 0xf6, 0x23], "wrss [r11], r12");
+ test_display(&[0x66, 0x0f, 0x38, 0xf5, 0x47, 0xe9], "wruss [rdi - 0x17], eax");
+ test_invalid(&[0x0f, 0x38, 0xf5, 0x47, 0xe9]);
+ test_invalid(&[0x66, 0x3e, 0x65, 0x3e, 0x0f, 0x38, 0xf5, 0xf0]);
}
#[test]
fn test_sse4a() {
- // really gotta get some test cases for this
+ fn test_instr(bytes: &[u8], text: &'static str) {
+ test_display_under(&InstDecoder::minimal().with_sse4a(), bytes, text);
+ test_display_under(&InstDecoder::default(), bytes, text);
+ test_invalid_under(&InstDecoder::minimal(), bytes);
+ }
+
+ test_instr(&[0xf2, 0x0f, 0x2b, 0x06], "movntsd [rsi], xmm0");
+ test_invalid(&[0xf2, 0x0f, 0x2b, 0xc6]);
+ test_instr(&[0xf3, 0x0f, 0x2b, 0x06], "movntss [rsi], xmm0");
+ test_invalid(&[0xf3, 0x0f, 0xba, 0xc6]);
+ test_instr(&[0x66, 0xf2, 0x0f, 0x79, 0xcf], "insertq xmm1, xmm7");
+ test_invalid(&[0x66, 0xf2, 0x0f, 0x79, 0x0f]);
+ test_instr(&[0xf2, 0x0f, 0x79, 0xcf], "insertq xmm1, xmm7");
+ test_instr(&[0xf2, 0x0f, 0x78, 0xf1, 0x4e, 0x76], "insertq xmm6, xmm1, 0x4e, 0x76");
+ test_invalid(&[0xf2, 0x0f, 0x79, 0x0f]);
+ test_instr(&[0x66, 0x0f, 0x79, 0xcf], "extrq xmm1, xmm7");
+ test_invalid(&[0x66, 0x0f, 0x79, 0x0f]);
+ test_instr(&[0x66, 0x0f, 0x78, 0xc1, 0x4e, 0x76], "extrq xmm1, 0x4e, 0x76");
+ test_invalid(&[0x66, 0x0f, 0x78, 0xc9, 0x4e, 0x76]);
}
#[test]
fn test_3dnow() {
+ test_display(&[0x0f, 0x0f, 0xe0, 0x8a], "pfnacc mm4, mm0");
+ test_display(&[0x0f, 0x0f, 0x38, 0x8e], "pfpnacc mm7, [rax]");
test_display(&[0x65, 0x67, 0x65, 0x65, 0x0f, 0x0e], "femms");
test_display(&[0x3e, 0xf3, 0x2e, 0xf2, 0x0f, 0x0f, 0x64, 0x93, 0x93, 0xa4], "pfmax mm4, [rbx + rdx * 4 - 0x6d]");
- test_display(&[0x26, 0x36, 0x0f, 0x0f, 0x70, 0xfb, 0x0c], "pi2fw");
+ test_display(&[0x26, 0x36, 0x0f, 0x0f, 0x70, 0xfb, 0x0c], "pi2fw mm6, [rax - 0x5]");
+ test_display(&[0x66, 0x0f, 0x0f, 0xc6, 0xb7], "pmulhrw mm0, mm6");
+ test_display(&[0x0f, 0x0f, 0xc6, 0xb7], "pmulhrw mm0, mm6");
}
// first appeared in tremont
@@ -2223,6 +2318,8 @@ fn test_direct_stores() {
#[test]
fn test_key_locker() {
test_display(&[0xf3, 0x64, 0x2e, 0x65, 0x0f, 0x38, 0xdc, 0xe8], "loadiwkey xmm5, xmm0");
+ test_display(&[0xf3, 0x0f, 0x38, 0xfa, 0xde], "encodekey128 ebx, esi");
+ test_display(&[0xf3, 0x0f, 0x38, 0xfb, 0xde], "encodekey256 ebx, esi");
}
// started shipping in sapphire rapids
@@ -2231,3 +2328,10 @@ fn test_enqcmd() {
test_display(&[0xf2, 0xf2, 0x2e, 0x36, 0x47, 0x0f, 0x38, 0xf8, 0x83, 0x09, 0x1c, 0x9d, 0x3f], "enqcmd r8d, [r11 + 0x3f9d1c09]");
test_display(&[0x3e, 0x64, 0xf3, 0x64, 0x0f, 0x38, 0xf8, 0x72, 0x54], "enqcmds esi, fs:[rdx + 0x54]");
}
+
+#[test]
+fn test_gfni() {
+ test_display(&[0x3e, 0x64, 0x64, 0x66, 0x4e, 0x0f, 0x3a, 0xcf, 0xba, 0x13, 0x23, 0x04, 0xba, 0x6b], "gf2p8affineinvqb xmm15, fs:[rdx - 0x45fbdced], 0x6b");
+ test_display(&[0x66, 0x36, 0x0f, 0x3a, 0xce, 0x8c, 0x56, 0x9e, 0x82, 0xd1, 0xbe, 0xad], "gf2p8affineqb xmm1, [rsi + rdx * 2 - 0x412e7d62], 0xad");
+ test_display(&[0x66, 0x4e, 0x0f, 0x38, 0xcf, 0x1c, 0x54], "gf2p8mulb xmm11, [rsp + r10 * 2]");
+}