/ad supports glob matching now ##search

This commit is contained in:
pancake 2024-05-21 21:38:53 +02:00 committed by GitHub
parent 5c94754c63
commit e4fc197e59
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 23 additions and 5 deletions

View File

@ -1,8 +1,6 @@
/* radare - LGPL - Copyright 2009-2019 - nibble, pancake */
/* radare - LGPL - Copyright 2009-2024 - nibble, pancake */
#include <r_types.h>
#include <r_core.h>
#include <r_asm.h>
#define IFDBG if (0)
@ -214,9 +212,15 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6
if (mode == 'a') { // check for case sensitive
matches = !r_str_ncasecmp (opst, tokens[matchcount], strlen (tokens[matchcount]));
} else if (!regexp) {
matches = !!strstr (opst, tokens[matchcount]);
const char *curtok = tokens[matchcount];
if (strchr (curtok, '$') || strchr (curtok, '*') || strchr (curtok, '^')) {
matches = r_str_glob (opst, curtok);
} else {
matches = !!strstr (opst, tokens[matchcount]);
}
} else {
rx = r_regex_new (tokens[matchcount], "es");
eprintf ("JEJE pene\n");
matches = r_regex_exec (rx, opst, 0, 0, 0) == 0;
r_regex_free (rx);
}

View File

@ -62,7 +62,8 @@ static RCoreHelpMessage help_msg_slash_pattern = {
static RCoreHelpMessage help_msg_slash_ad = {
"Usage: /ad[/<*jq>]", "[value]", "Backward search subcommands",
"/ad", " rax", "search in disasm plaintext for matching instructions",
"/ad", " rax", "search in plaintext disasm for matching instructions",
"/ad", " rax$", "search in plaintext disasm for instruction matchin given glob expression",
"/adj", " rax", "json output searching in disasm with plaintext",
"/adq", " rax", "quiet mode ideal for scripting",
"/ad/", " ins1;ins2", "search for regex instruction 'ins1' followed by regex 'ins2'",

View File

@ -419,3 +419,16 @@ EXPECT=<<EOF
EOF
RUN
NAME=glob search with /ad
ARGS=-a arm -b64
FILE=bins/mach0/ls-m1
CMDS=<<EOF
/ad ret~?
/ad ret$~?
EOF
EXPECT=<<EOF
40
18
EOF
RUN