From 141556b2c15ca239b18bb01dc1b61b9ac8474835 Mon Sep 17 00:00:00 2001 From: dd86k Date: Fri, 20 Oct 2023 09:53:24 -0400 Subject: [PATCH] Improve Capstone dyn loader --- app/main.d | 13 ++++++++++--- src/adbg/include/capstone/v4.d | 7 ++++--- src/adbg/v1/debugger/debugger.d | 2 +- src/adbg/v2/debugger/memory.d | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/main.d b/app/main.d index 197f0556..1912e9a3 100644 --- a/app/main.d +++ b/app/main.d @@ -342,12 +342,19 @@ int cli_version() { import adbg.include.capstone : capstone_dyn_init, cs_version; printf("Capstone: "); - if (capstone_dyn_init() == false) { + if (capstone_dyn_init()) { + puts("error"); + version (Trace) { + import adbg.error : trace; + import bindbc.loader.sharedlib : errors; + foreach (e; errors) { + trace("%s", e.message); + } + } + } else { int major = void, minor = void; cs_version(&major, &minor); printf("%d.%d\n", major, minor); - } else { - puts("error"); } exit(0); diff --git a/src/adbg/include/capstone/v4.d b/src/adbg/include/capstone/v4.d index c71be9a9..2eeccfcc 100644 --- a/src/adbg/include/capstone/v4.d +++ b/src/adbg/include/capstone/v4.d @@ -814,7 +814,7 @@ __gshared pcs_op_count cs_op_count; __gshared pcs_op_index cs_op_index; __gshared pcs_regs_access cs_regs_access; -size_t capstone_dyn_init() +bool capstone_dyn_init() { version (Windows) { @@ -841,7 +841,8 @@ size_t capstone_dyn_init() foreach (libname; libraries) { if ((lib = load(libname)) == invalidHandle) - return true; + continue; + break; } bindSymbol(lib, cast(void**)&cs_version, "cs_version"); @@ -866,7 +867,7 @@ size_t capstone_dyn_init() bindSymbol(lib, cast(void**)&cs_op_index, "cs_op_index"); bindSymbol(lib, cast(void**)&cs_regs_access, "cs_regs_access"); - return errorCount(); + return errorCount() > 0; } } diff --git a/src/adbg/v1/debugger/debugger.d b/src/adbg/v1/debugger/debugger.d index 98639599..c2479925 100644 --- a/src/adbg/v1/debugger/debugger.d +++ b/src/adbg/v1/debugger/debugger.d @@ -898,7 +898,7 @@ int adbg_mm_maps(adbg_mm_map **mmaps, size_t *mcount, ...) { //TODO: Adjust memory region permissions like libscanmem does - version (Trace) trace("entry: %zx %s", range_start, path.ptr); + version (Trace) trace("entry: %zx %s", range_start, map.name.ptr); map.base = cast(void*)range_start; map.size = range_end - range_start; diff --git a/src/adbg/v2/debugger/memory.d b/src/adbg/v2/debugger/memory.d index e5bf5f58..af33e1e8 100644 --- a/src/adbg/v2/debugger/memory.d +++ b/src/adbg/v2/debugger/memory.d @@ -391,7 +391,7 @@ L_OPT: //TODO: Adjust memory region permissions like libscanmem does - version (Trace) trace("entry: %zx %s", range_start, path.ptr); + version (Trace) trace("entry: %zx %s", range_start, map.name.ptr); map.base = cast(void*)range_start; map.size = range_end - range_start;