From 43c64eee8dd08d61d029be5a30c0edc098d282ab Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Sat, 7 Sep 2024 12:57:38 +0100 Subject: 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. --- tools/x86test.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 tools/x86test.c (limited to 'tools') 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 +#include + +#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); +} + -- cgit v1.2.3