From 7c0bd7cd036d6500bb2ef29adf3d50f0529786a8 Mon Sep 17 00:00:00 2001 From: Anton Kochkov Date: Thu, 29 Sep 2022 18:44:51 +0800 Subject: [PATCH] Convert `dW` command to the rzshell --- librz/core/cmd/cmd_debug.c | 29 ++++++++++++++++++++--------- librz/core/cmd_descs/cmd_debug.yaml | 11 +++++++++++ librz/core/cmd_descs/cmd_descs.c | 24 ++++++++++++++++++++++++ librz/core/cmd_descs/cmd_descs.h | 2 ++ 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/librz/core/cmd/cmd_debug.c b/librz/core/cmd/cmd_debug.c index 3bab2a2aad7..b475cf337e4 100644 --- a/librz/core/cmd/cmd_debug.c +++ b/librz/core/cmd/cmd_debug.c @@ -2050,15 +2050,6 @@ RZ_IPI int rz_cmd_debug(void *data, const char *input) { case 'k': // "dk" rz_core_debug_kill(core, input + 1); break; -#if __WINDOWS__ - case 'W': // "dW" - if (input[1] == 'i') { - rz_w32_identify_window(); - } else { - rz_w32_print_windows(core->dbg); - } - break; -#endif case '?': // "d?" default: rz_core_cmd_help(core, help_msg_d); @@ -3404,3 +3395,23 @@ RZ_IPI RzCmdStatus rz_cmd_debug_wait_handler(RzCore *core, int argc, const char rz_cons_break_pop(); return RZ_CMD_STATUS_OK; } + +RZ_IPI RzCmdStatus rz_cmd_debug_windows_list_handler(RzCore *core, int argc, const char **argv) { +#if __WINDOWS__ + rz_w32_print_windows(core->dbg); + return RZ_CMD_STATUS_OK; +#else + RZ_LOG_ERROR("This command works only on Microsoft Windows\n"); + return RZ_CMD_STATUS_ERROR; +#endif +} + +RZ_IPI RzCmdStatus rz_cmd_debug_window_identify_handler(RzCore *core, int argc, const char **argv) { +#if __WINDOWS__ + rz_w32_identify_window(); + return RZ_CMD_STATUS_OK; +#else + RZ_LOG_ERROR("This command works only on Microsoft Windows\n"); + return RZ_CMD_STATUS_ERROR; +#endif +} diff --git a/librz/core/cmd_descs/cmd_debug.yaml b/librz/core/cmd_descs/cmd_debug.yaml index bfe165f5fbc..71a6f1725b8 100644 --- a/librz/core/cmd_descs/cmd_debug.yaml +++ b/librz/core/cmd_descs/cmd_debug.yaml @@ -1178,6 +1178,17 @@ commands: - name: pid type: RZ_CMD_ARG_TYPE_NUM optional: true + - name: dW + summary: Windows process commands + subcommands: + - name: dW + summary: List process windows + cname: cmd_debug_windows_list + args: [] + - name: dWi + summary: Identify window under cursor + cname: cmd_debug_window_identify + args: [] - name: dx summary: Code injection commands subcommands: diff --git a/librz/core/cmd_descs/cmd_descs.c b/librz/core/cmd_descs/cmd_descs.c index 97de03506dc..a5eb94abf98 100644 --- a/librz/core/cmd_descs/cmd_descs.c +++ b/librz/core/cmd_descs/cmd_descs.c @@ -8610,6 +8610,25 @@ static const RzCmdDescHelp cmd_debug_wait_help = { .args = cmd_debug_wait_args, }; +static const RzCmdDescHelp dW_help = { + .summary = "Windows process commands", +}; +static const RzCmdDescArg cmd_debug_windows_list_args[] = { + { 0 }, +}; +static const RzCmdDescHelp cmd_debug_windows_list_help = { + .summary = "List process windows", + .args = cmd_debug_windows_list_args, +}; + +static const RzCmdDescArg cmd_debug_window_identify_args[] = { + { 0 }, +}; +static const RzCmdDescHelp cmd_debug_window_identify_help = { + .summary = "Identify window under cursor", + .args = cmd_debug_window_identify_args, +}; + static const RzCmdDescHelp dx_help = { .summary = "Code injection commands", }; @@ -17269,6 +17288,11 @@ RZ_IPI void rzshell_cmddescs_init(RzCore *core) { RzCmdDesc *cmd_debug_wait_cd = rz_cmd_desc_argv_new(core->rcmd, cmd_debug_cd, "dw", rz_cmd_debug_wait_handler, &cmd_debug_wait_help); rz_warn_if_fail(cmd_debug_wait_cd); + RzCmdDesc *dW_cd = rz_cmd_desc_group_new(core->rcmd, cmd_debug_cd, "dW", rz_cmd_debug_windows_list_handler, &cmd_debug_windows_list_help, &dW_help); + rz_warn_if_fail(dW_cd); + RzCmdDesc *cmd_debug_window_identify_cd = rz_cmd_desc_argv_new(core->rcmd, dW_cd, "dWi", rz_cmd_debug_window_identify_handler, &cmd_debug_window_identify_help); + rz_warn_if_fail(cmd_debug_window_identify_cd); + RzCmdDesc *dx_cd = rz_cmd_desc_group_new(core->rcmd, cmd_debug_cd, "dx", rz_cmd_debug_inject_opcode_handler, &cmd_debug_inject_opcode_help, &dx_help); rz_warn_if_fail(dx_cd); RzCmdDesc *cmd_debug_inject_assembly_cd = rz_cmd_desc_argv_new(core->rcmd, dx_cd, "dxa", rz_cmd_debug_inject_assembly_handler, &cmd_debug_inject_assembly_help); diff --git a/librz/core/cmd_descs/cmd_descs.h b/librz/core/cmd_descs/cmd_descs.h index dbb00cd6c16..7bff25049cb 100644 --- a/librz/core/cmd_descs/cmd_descs.h +++ b/librz/core/cmd_descs/cmd_descs.h @@ -594,6 +594,8 @@ RZ_IPI RzCmdStatus rz_debug_reg_roles_handler(RzCore *core, int argc, const char RZ_IPI RzCmdStatus rz_debug_drx_handler(RzCore *core, int argc, const char **argv); RZ_IPI RzCmdStatus rz_debug_drx_unset_handler(RzCore *core, int argc, const char **argv); RZ_IPI RzCmdStatus rz_cmd_debug_wait_handler(RzCore *core, int argc, const char **argv); +RZ_IPI RzCmdStatus rz_cmd_debug_windows_list_handler(RzCore *core, int argc, const char **argv); +RZ_IPI RzCmdStatus rz_cmd_debug_window_identify_handler(RzCore *core, int argc, const char **argv); RZ_IPI RzCmdStatus rz_cmd_debug_inject_opcode_handler(RzCore *core, int argc, const char **argv); RZ_IPI RzCmdStatus rz_cmd_debug_inject_assembly_handler(RzCore *core, int argc, const char **argv); RZ_IPI RzCmdStatus rz_cmd_debug_inject_egg_handler(RzCore *core, int argc, const char **argv);