From 5f8663f3cc721025bd4f8e9ce46db8f41c966e69 Mon Sep 17 00:00:00 2001 From: wargio Date: Mon, 15 Jan 2024 17:25:58 +0800 Subject: [PATCH 1/3] Blind patch for windows to convert utf16 to utf8 --- librz/debug/p/debug_native.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/librz/debug/p/debug_native.c b/librz/debug/p/debug_native.c index 50073133784..e5856497391 100644 --- a/librz/debug/p/debug_native.c +++ b/librz/debug/p/debug_native.c @@ -325,14 +325,15 @@ static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { bool autoload_pdb = dbg->corebind.cfggeti(core, "pdb.autoload"); if (autoload_pdb) { PLIB_ITEM lib = native_info->lib; - if (rz_file_exists(lib->Path)) { + char *lib_path = rz_utf16_to_utf8(lib->Path); + if (lib_path && rz_file_exists(lib_path)) { if (tracelib(dbg, "load", native_info->lib)) { reason = RZ_DEBUG_REASON_TRAP; } RzBinOptions opts = { 0 }; opts.obj_opts.baseaddr = (uintptr_t)lib->BaseOfDll; RzBinFile *cur = rz_bin_cur(core->bin); - RzBinFile *bf = rz_bin_open(core->bin, lib->Path, &opts); + RzBinFile *bf = rz_bin_open(core->bin, lib_path, &opts); if (bf) { const RzBinInfo *info = rz_bin_object_get_info(bf->o); if (RZ_STR_ISNOTEMPTY(info->debug_file_name)) { @@ -344,8 +345,9 @@ static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { rz_bin_file_set_cur_binfile(core->bin, cur); } } else { - RZ_LOG_VERBOSE("The library %s does not exist.\n", lib->Path); + RZ_LOG_VERBOSE("The library %s does not exist.\n", lib_path); } + free(lib_path); } } else { RZ_LOG_WARN("Loading unknown library.\n"); From b6209a4195d21248253579a84e19c1c5ffcf1481 Mon Sep 17 00:00:00 2001 From: wargio Date: Mon, 15 Jan 2024 18:06:06 +0800 Subject: [PATCH 2/3] Increase verbosity --- librz/debug/p/debug_native.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/librz/debug/p/debug_native.c b/librz/debug/p/debug_native.c index e5856497391..215326f5420 100644 --- a/librz/debug/p/debug_native.c +++ b/librz/debug/p/debug_native.c @@ -345,7 +345,7 @@ static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { rz_bin_file_set_cur_binfile(core->bin, cur); } } else { - RZ_LOG_VERBOSE("The library %s does not exist.\n", lib_path); + RZ_LOG_ERROR("The library %s does not exist.\n", lib_path); } free(lib_path); } From 00a8edb6b9e0c84ef320a50f8396f949d706d949 Mon Sep 17 00:00:00 2001 From: billow Date: Mon, 15 Jan 2024 09:43:42 -0800 Subject: [PATCH 3/3] Fix windows debug plugin #2 --- librz/debug/p/debug_native.c | 8 +++----- librz/debug/p/native/windows/windows_debug.c | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/librz/debug/p/debug_native.c b/librz/debug/p/debug_native.c index 215326f5420..3ebe03e133e 100644 --- a/librz/debug/p/debug_native.c +++ b/librz/debug/p/debug_native.c @@ -325,15 +325,14 @@ static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { bool autoload_pdb = dbg->corebind.cfggeti(core, "pdb.autoload"); if (autoload_pdb) { PLIB_ITEM lib = native_info->lib; - char *lib_path = rz_utf16_to_utf8(lib->Path); - if (lib_path && rz_file_exists(lib_path)) { + if (rz_file_exists(lib->Path)) { if (tracelib(dbg, "load", native_info->lib)) { reason = RZ_DEBUG_REASON_TRAP; } RzBinOptions opts = { 0 }; opts.obj_opts.baseaddr = (uintptr_t)lib->BaseOfDll; RzBinFile *cur = rz_bin_cur(core->bin); - RzBinFile *bf = rz_bin_open(core->bin, lib_path, &opts); + RzBinFile *bf = rz_bin_open(core->bin, lib->Path, &opts); if (bf) { const RzBinInfo *info = rz_bin_object_get_info(bf->o); if (RZ_STR_ISNOTEMPTY(info->debug_file_name)) { @@ -345,9 +344,8 @@ static RzDebugReasonType rz_debug_native_wait(RzDebug *dbg, int pid) { rz_bin_file_set_cur_binfile(core->bin, cur); } } else { - RZ_LOG_ERROR("The library %s does not exist.\n", lib_path); + RZ_LOG_ERROR("The library %s does not exist.\n", lib->Path); } - free(lib_path); } } else { RZ_LOG_WARN("Loading unknown library.\n"); diff --git a/librz/debug/p/native/windows/windows_debug.c b/librz/debug/p/native/windows/windows_debug.c index f04dee032fa..d6a8b807d65 100644 --- a/librz/debug/p/native/windows/windows_debug.c +++ b/librz/debug/p/native/windows/windows_debug.c @@ -706,7 +706,7 @@ static char *get_file_name_from_handle(HANDLE handle_file) { CloseHandle(handle_file_map); } if (filename) { - char *ret = rz_sys_conv_win_to_utf8(filename); + char *ret = rz_utf16_to_utf8(filename); free(filename); return ret; }