summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/x86.c3
-rw-r--r--src/x86.h4
-rw-r--r--test/x86.test.c42
3 files changed, 27 insertions, 22 deletions
diff --git a/src/x86.c b/src/x86.c
index 7a5d00e..e0431d6 100644
--- a/src/x86.c
+++ b/src/x86.c
@@ -1,5 +1,5 @@
/*
- * Copyright © 2023 Michael Smith <mikesmiffy128@gmail.com>
+ * Copyright © 2024 Michael Smith <mikesmiffy128@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -25,6 +25,7 @@ static int mrmsib(const uchar *p, int addrlen) {
// But it's confusingly-written enough that the code I wrote before didn't
// work, so with any luck nobody will need to refer to it again and this is
// actually correct now. Fingers crossed.
+ if ((*p & 0xC6) == 0x06) return 3; // special case for disp16
if (addrlen == 4 || *p & 0xC0) {
int sib = addrlen == 4 && *p < 0xC0 && (*p & 7) == 4;
switch (*p & 0xC0) {
diff --git a/src/x86.h b/src/x86.h
index a62c0ee..52e4f9b 100644
--- a/src/x86.h
+++ b/src/x86.h
@@ -143,8 +143,6 @@
X(X86_XORALI, 0x34) \
X(X86_CMPALI, 0x3C) \
X(X86_PUSHI8, 0x6A) \
- X(X86_MOVALII, 0xA0) /* From offset (indirect) */ \
- X(X86_MOVIIAL, 0xA2) /* To offset (indirect) */ \
X(X86_TESTALI, 0xA8) \
X(X86_JO, 0x70) \
X(X86_JNO, 0x71) \
@@ -190,7 +188,9 @@
X(X86_XOREAXI, 0x35) \
X(X86_CMPEAXI, 0x3D) \
X(X86_PUSHIW, 0x68) \
+ X(X86_MOVALII, 0xA0) /* From offset (indirect) */ \
X(X86_MOVEAXII, 0xA1) /* From offset (indirect) */ \
+ X(X86_MOVIIAL, 0xA2) /* To offset (indirect) */ \
X(X86_MOVIIEAX, 0xA3) /* To offset (indirect) */ \
X(X86_TESTEAXI, 0xA9) \
X(X86_MOVEAXI, 0xB8) \
diff --git a/test/x86.test.c b/test/x86.test.c
index ab0a679..c0c825a 100644
--- a/test/x86.test.c
+++ b/test/x86.test.c
@@ -5,25 +5,15 @@
#include "../src/x86.c"
#include "../src/intdefs.h"
+#include "../src/ppmagic.h"
+
TEST("The \"crazy\" instructions should be given correct lengths\n") {
- const uchar test8[] = {
- 0xF6, 0x05, 0x12, 0x34, 0x56, 0x78, 0x12
- };
- const uchar test16[] = {
- 0x66, 0xF7, 0x05, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34
- };
- const uchar test32[] = {
- 0xF7, 0x05, 0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78
- };
- const uchar not8[] = {
- 0xF6, 0x15, 0x12, 0x34, 0x56, 0x78
- };
- const uchar not16[] = {
- 0x66, 0xF7, 0x15, 0x12, 0x34, 0x56, 0x78
- };
- const uchar not32[] = {
- 0xF7, 0x15, 0x12, 0x34, 0x56, 0x78
- };
+ const uchar test8[] = HEXBYTES(F6, 05, 12, 34, 56, 78, 12);
+ const uchar test16[] = HEXBYTES(66, F7, 05, 12, 34, 56, 78, 12, 34);
+ const uchar test32[] = HEXBYTES(F7, 05, 12, 34, 56, 78, 12, 34, 56, 78);
+ const uchar not8[] = HEXBYTES(F6, 15, 12, 34, 56, 78);
+ const uchar not16[] = HEXBYTES(66, F7, 15, 12, 34, 56, 78);
+ const uchar not32[] = HEXBYTES(F7, 15, 12, 34, 56, 78);
if (x86_len(test8) != 7) return false;
if (x86_len(test16) != 9) return false;
if (x86_len(test32) != 10) return false;
@@ -34,8 +24,22 @@ TEST("The \"crazy\" instructions should be given correct lengths\n") {
}
TEST("SIB bytes should be decoded correctly") {
- const uchar fstp[] = {0xD9, 0x1C, 0x24}; // old buggy case, for regressions
+ const uchar fstp[] = HEXBYTES(D9, 1C, 24); // old buggy case for regressions
return x86_len(fstp) == 3;
}
+TEST("mov AL, moff8 instructions should be decoded correctly") {
+ // more fixed buggy cases for regressions
+ const uchar mov_moff8_al[] = HEXBYTES(A2, DA, 78, B4, 0D);
+ const uchar mov_al_moff8[] = HEXBYTES(A0, 28, DF, 5C, 66);
+ if (x86_len(mov_moff8_al) != 5) return false;
+ if (x86_len(mov_al_moff8) != 5) return false;
+ return true;
+}
+
+TEST("fiadd [off16] instructions should be decoded correctly") {
+ const uchar fiadd_off16[] = HEXBYTES(67, DA, 06, DF, 11);
+ return x86_len(fiadd_off16) == 5;
+}
+
// vi: sw=4 ts=4 noet tw=80 cc=80