summaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2024-09-07 12:57:38 +0100
committerMichael Smith <mikesmiffy128@gmail.com>2024-09-07 12:57:38 +0100
commit43c64eee8dd08d61d029be5a30c0edc098d282ab (patch)
treea71e412b1fefd3abf89093ca4830a5cf3ba1c46e /tools
parent8bb4226f07b1e9ee79f3429a1495eaa694b13334 (diff)
Un-break and re-fix x86
The last fix was, uh, not good. With any luck this is actually correct now. Certainly, running many millions of test cases fails to find any mismatch with udis, so it's at least a lot less wrong than it was.
Diffstat (limited to 'tools')
-rw-r--r--tools/x86test.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/x86test.c b/tools/x86test.c
new file mode 100644
index 0000000..18fc72f
--- /dev/null
+++ b/tools/x86test.c
@@ -0,0 +1,43 @@
+/* This file is dedicated to the public domain. */
+
+#include <stdbool.h>
+#include <stdio.h>
+
+#include "../src/udis86.h"
+#include "../src/udis86.c"
+#include "../src/intdefs.h"
+#include "../src/x86.h"
+#include "../src/x86.c"
+#include "../src/os.h"
+#include "../src/os.c"
+
+/*
+ * Quick hacked-up test program to more exhaustively test x86.c. This is not run
+ * as part of the build; it is just here for development and reference purposes.
+ */
+
+int main(void) {
+ uchar buf[15];
+ int bad = 0;
+ for (int i = 0; i < 100000000 && bad < 30; ++i) {
+ os_randombytes(buf, sizeof(buf));
+ struct ud u;
+ ud_init(&u);
+ ud_set_mode(&u, 32);
+ ud_set_input_buffer(&u, buf, sizeof(buf));
+ ud_set_syntax(&u, UD_SYN_INTEL);
+ int len = ud_disassemble(&u);
+ if (len && ud_insn_mnemonic(&u) != UD_Iinvalid) {
+ int mylen = x86_len(buf);
+ if (mylen != -1 && mylen != len) {
+ ++bad;
+ fprintf(stderr, "Uh oh! %s\nExp: %d\nGot: %d\nBytes:",
+ ud_insn_asm(&u), len, mylen);
+ for (int i = 0; i < len; ++i) fprintf(stderr, " %02X", buf[i]);
+ fputs("\n\n", stderr);
+ }
+ }
+ }
+ fprintf(stderr, "%d bad cases\n", bad);
+}
+