about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2025-09-30 19:07:42 +0200
committerptitSeb <sebastien.chev@gmail.com>2025-09-30 19:07:42 +0200
commitba9731838e1df5afd9c2e303ac1868aeeae07820 (patch)
treed3331fe54c6442b0f1a090807214c0aac298f005
parent7c064ef16c8285478df3321eb6fbe5a6e59e126e (diff)
downloadbox64-ba9731838e1df5afd9c2e303ac1868aeeae07820.tar.gz
box64-ba9731838e1df5afd9c2e303ac1868aeeae07820.zip
[TRACE] Small improvment in x64 decoder trace when decoder fails
-rw-r--r--src/emu/x64trace.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/emu/x64trace.c b/src/emu/x64trace.c
index 5ee1b0f9..f4645c94 100644
--- a/src/emu/x64trace.c
+++ b/src/emu/x64trace.c
@@ -199,11 +199,12 @@ const char* DecodeX64Trace(zydis_dec_t* dec, uintptr_t p, int withhex)
     static char buff[512];
 #ifndef ZYDIS3
     if (ZYAN_SUCCESS(dec->ZydisDecoderDecodeFull(&dec->decoder, (char*)p, 15,
-            &dec->instruction, dec->operands))) {
+            &dec->instruction, dec->operands)))
 #else
     if (ZYAN_SUCCESS(dec->ZydisDecoderDecodeBuffer(&dec->decoder, (char*)p, 15,
-            &dec->instruction))) {
+            &dec->instruction)))
 #endif
+    {
         char tmp[511];
         buff[0] = '\0';
         if (withhex) {
@@ -217,9 +218,16 @@ const char* DecodeX64Trace(zydis_dec_t* dec, uintptr_t p, int withhex)
 #else
         dec->ZydisFormatterFormatInstruction(&dec->formatter, &dec->instruction, tmp, sizeof(tmp), p);
 #endif
-        strcat(buff, tmp);
+        strncat(buff, tmp, sizeof(buff)-1);
     } else {
-        sprintf(buff, "Decoder failed @%p", (void*)p);
+        snprintf(buff, sizeof(buff), "Decoder failed @%p: ", (void*)p);
+        if (withhex) {
+            char tmp[10];
+            for (int i = 0; i < 15; ++i) {
+                sprintf(tmp, "%02X ", *((unsigned char*)p + i));
+                strcat(buff, tmp);
+            }
+        }
     }
     return buff;
 #endif