Skip to content

Commit

Permalink
Improve Capstone dyn loader
Browse files Browse the repository at this point in the history
  • Loading branch information
dd86k committed Oct 20, 2023
1 parent 9eb63af commit 141556b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
13 changes: 10 additions & 3 deletions app/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions src/adbg/include/capstone/v4.d
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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");
Expand All @@ -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;
}

}
2 changes: 1 addition & 1 deletion src/adbg/v1/debugger/debugger.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/adbg/v2/debugger/memory.d
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 141556b

Please sign in to comment.