From f73d18205c7eee4cb410e4979f3e055bfd4ec477 Mon Sep 17 00:00:00 2001 From: Murphy Date: Fri, 22 Oct 2021 01:18:34 +0200 Subject: [PATCH] Fix 19164 add help message (#19279) * Add /o and /O help messages * Add /w subcommands help message * Add help message to /i * Add /f help msg * Update /d cmd msg help * add a8 help cmd --- libr/core/cmd_anal.c | 91 ++++++++++++++++++++++++++++++++---------- libr/core/cmd_search.c | 73 ++++++++++++++++++++++++++++++++- 2 files changed, 141 insertions(+), 23 deletions(-) diff --git a/libr/core/cmd_anal.c b/libr/core/cmd_anal.c index da2d5a823c..0e6b45216a 100644 --- a/libr/core/cmd_anal.c +++ b/libr/core/cmd_anal.c @@ -38,14 +38,45 @@ static const char *help_msg_a[] = { NULL }; +static const char *help_msg_afna[] = { + "Usage:", "afna", " # construct a function name and rename the function for the current offset.", + "", "", "Based on flags or methods calls found inside that function.", + NULL +}; + +static const char *help_msg_afu[] = { + "Usage:", "afu", "[addr] # resize and analyze function from current address until addr.", + "afu", " 0x100004093", "Resize and analyze function from current address until 0x100004093", + NULL +}; + +static const char *help_msg_afm[] = { + "Usage:", "afm", "[name] # merge two functions.", + "afm", " sym.func.100003d74", "Merge current function into 0x100003d74", + NULL +}; + +static const char *help_msg_aF[] = { + "Usage:", "aF", " # analyze a function, but using anal.depth=1", + "aF", "", "Check af? for more options and information.", + NULL +}; + +static const char *help_msg_a8[] = { + "Usage:", "a8", "[hexpairs] # analyze the byte array given as input", + "a8 ", "5548", "analyzes 5548 byte array", + NULL +}; + + static const char *help_msg_ap[] = { - "Usage:", "ap[?]", "analyze prelude in current offset", + "Usage:", "ap[?]", " # analyze prelude in current offset", "ap", "", "check if current offset contains a function prelude", NULL }; static const char *help_msg_avg[] = { - "Usage:", "avg", "analyze variable global", + "Usage:", "avg", " # analyze variable global", "avg", "", "Use ESIL emulation to find out arguments of a call (uses 'abte')", "avg", " [type] [name]", "add global", "avg-", "", "delete global", @@ -53,7 +84,7 @@ static const char *help_msg_avg[] = { }; static const char *help_msg_aC[] = { - "Usage:", "aC[fej] [addr-of-call]", "analyze call args", + "Usage:", "aC[fej] [addr-of-call]", " # analyze call args", "aCe", "", "Use ESIL emulation to find out arguments of a call (uses 'abte')", "aCf", "", "Same as .aCe* $$ @@=`pdr~call`", NULL @@ -3806,7 +3837,11 @@ static int cmd_anal_fcn(RCore *core, const char *input) { } break; case 'u': // "afu" - { + if (input[2] == '?') { + r_core_cmd_help (core, help_msg_afu); + break; + } + if (input[2] != ' ') { eprintf ("Missing argument\n"); return false; @@ -3839,7 +3874,6 @@ static int cmd_anal_fcn(RCore *core, const char *input) { r_config_set_i (core->config, "anal.to", b); r_config_set (core->config, "anal.limits", r_str_get (c)); } - } break; case '+': { // "af+" if (input[2] != ' ') { @@ -4162,6 +4196,10 @@ static int cmd_anal_fcn(RCore *core, const char *input) { } break; case 'm': // "afm" - merge two functions + if (input[2] == '?') { + r_core_cmd_help (core, help_msg_afm); + break; + } r_core_anal_fcn_merge (core, core->offset, r_num_math (core->num, input + 2)); break; case 'M': // "afM" - print functions map @@ -4415,14 +4453,17 @@ static int cmd_anal_fcn(RCore *core, const char *input) { free (r_core_anal_fcn_autoname (core, core->offset, 1, 0)); } break; - case 'a': { // "afna" - char *name = r_core_anal_fcn_autoname (core, core->offset, 0, 0); - if (name) { - r_cons_printf ("afn %s 0x%08" PFMT64x "\n", name, core->offset); - free (name); - } - break; - } + case 'a': // "afna" + if (input[3] == '?') { + r_core_cmd_help (core, help_msg_afna); + break; + } + char *name = r_core_anal_fcn_autoname (core, core->offset, 0, 0); + if (name) { + r_cons_printf ("afn %s 0x%08" PFMT64x "\n", name, core->offset); + free (name); + } + break; case '.': // "afn." case 0: { // "afn" RAnalFunction *fcn = r_anal_get_fcn_in (core->anal, core->offset, -1); @@ -11345,16 +11386,18 @@ static int cmd_anal(void *data, const char *input) { free (buf); } break; - case '8': // "a8" - { - ut8 *buf = malloc (strlen (input) + 1); - if (buf) { - int len = r_hex_str2bin (input + 1, buf); - if (len > 0) { - core_anal_bytes (core, buf, len, 0, input[1]); - } - free (buf); + case '8': // "a8" + if (input[1] == '?') { + r_core_cmd_help (core, help_msg_a8); + break; + } + ut8 *buf = malloc (strlen (input) + 1); + if (buf) { + int len = r_hex_str2bin (input + 1, buf); + if (len > 0) { + core_anal_bytes (core, buf, len, 0, input[1]); } + free (buf); } break; case 'b': // "ab" @@ -11418,6 +11461,10 @@ static int cmd_anal(void *data, const char *input) { case 'o': cmd_anal_opcode (core, input + 1); break; // "ao" case 'O': cmd_anal_bytes (core, input + 1); break; // "aO" case 'F': // "aF" + if (input[1] == '?') { + r_core_cmd_help (core, help_msg_aF); + break; + } r_core_anal_fcn (core, core->offset, UT64_MAX, R_ANAL_REF_TYPE_NULL, 1); break; case 'f': // "af" diff --git a/libr/core/cmd_search.c b/libr/core/cmd_search.c index a08f63eb32..17cae90953 100644 --- a/libr/core/cmd_search.c +++ b/libr/core/cmd_search.c @@ -14,6 +14,30 @@ static int cmd_search(void *data, const char *input); #define AES_SEARCH_LENGTH 40 #define PRIVATE_KEY_SEARCH_LENGTH 11 +static const char *help_msg_search_wide_string[] = { + "Usage: /w[ij]", "[str]", "Wide string search subcommands", + "/w ", "foo", "search for wide string 'f\\0o\\0o\\0'", + "/wj ", "foo", "search for wide string 'f\\0o\\0o\\0' (json output)", + "/wi ", "foo", "search for wide string 'f\\0o\\0o\\0' but ignoring case", + "/wij ", "foo", "search for wide string 'f\\0o\\0o\\0' but ignoring case (json output)", + NULL +}; + +static const char *help_msg_search_offset[] = { + "Usage: /o", "[n]", "Shows offset of 'n' Backward instruction", + NULL +}; + +static const char *help_msg_search_offset_without_anal[] = { + "Usage: /O", "[n]", "Shows offset of 'n' Backward instruction, but with a different fallback if anal cannot be used.", + NULL +}; + +static const char *help_msg_search_string_no_case[] = { + "Usage: /i", "[str]", "Search str string ignorning case", + NULL +}; + static const char *help_msg_search_esil[] = { "/E", " [esil-expr]", "search offsets matching a specific esil expression", "/Ej", " [esil-expr]", "same as above but using the given magic file", @@ -30,6 +54,21 @@ static const char *help_msg_search_backward[] = { NULL }; +static const char *help_msg_search_forward[] = { + "Usage: /f", " ", "search forwards, command modifier, followed by other command", + NULL +}; + +static const char *help_msg_search_sections[] = { + "Usage: /s[*]", "[threshold]", "finds sections by grouping blocks with similar entropy.", + NULL +}; + +static const char *help_msg_search_delta[] = { + "Usage: /d", "delta", "search for a deltified sequence of bytes.", + NULL +}; + static const char *help_msg_search_pattern[] = { "Usage: /p[p]", " [pattern]", "Search for patterns or preludes", "/p", " [hexpattern]", "search in hexpairs pattern in search.in", @@ -3289,6 +3328,10 @@ reread: } goto reread; case 'o': { // "/o" print the offset of the Previous opcode + if (input[1] == '?') { + r_core_cmd_help (core, help_msg_search_offset); + break; + } ut64 addr, n = input[param_offset - 1] ? r_num_math (core->num, input + param_offset) : 1; n = R_ABS((st64)n); if (((st64)n) < 1) { @@ -3306,6 +3349,10 @@ reread: break; } case 'O': { // "/O" alternative to "/o" + if (input[1] == '?') { + r_core_cmd_help (core, help_msg_search_offset_without_anal); + break; + } ut64 addr, n = input[param_offset - 1] ? r_num_math (core->num, input + param_offset) : 1; if (!n) { n = 1; @@ -3953,7 +4000,15 @@ reread: dosearch = true; break; case 'w': // "/w" search wide string, includes ignorecase search functionality (/wi cmd)! - if (input[2] ) { + if (input[1] == '?') { + r_core_cmd_help (core, help_msg_search_wide_string); + break; + } + if (input[2]) { + if (input[2] == '?') { + r_core_cmd_help (core, help_msg_search_wide_string); + break; + } if (input[1] == 'j' || input[2] == 'j') { param.outmode = R_MODE_JSON; } @@ -3998,6 +4053,10 @@ reread: break; } case 'i': // "/i" + if (input[1] == '?') { + r_core_cmd_help (core, help_msg_search_string_no_case); + break; + } if (input[param_offset - 1] != ' ') { eprintf ("Missing ' ' after /i\n"); ret = false; @@ -4069,6 +4128,10 @@ reread: do_esil_search (core, ¶m, input); goto beach; case 'd': // "/d" search delta key + if (input[1] == '?') { + r_core_cmd_help (core, help_msg_search_delta); + break; + } if (input[1]) { r_search_reset (core->search, R_SEARCH_DELTAKEY); r_search_kw_add (core->search, @@ -4109,6 +4172,10 @@ reread: } break; case 'f': // "/f" forward search + if (input[1] == '?') { + r_core_cmd_help (core, help_msg_search_forward); + break; + } if (core->offset) { st64 coff = core->offset; RInterval itv = {core->offset, -coff}; @@ -4222,6 +4289,10 @@ reread: } break; case 's': // "/s" + if (input[1] == '?') { + r_core_cmd_help (core, help_msg_search_sections); + break; + } do_section_search (core, ¶m, input + 1); break; case '+': // "/+"