mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-21 23:01:03 +00:00
rafind2: print heading (filename) before matches
The headings are enabled by default when searching multiple files or a directory. The headings can be disabled with the quiet mode (-q).
This commit is contained in:
parent
e17cc1c6ae
commit
3c15e4348d
@ -22,6 +22,7 @@ static ut64 from = 0LL, to = -1;
|
|||||||
static char *mask = NULL;
|
static char *mask = NULL;
|
||||||
static int nonstop = 0;
|
static int nonstop = 0;
|
||||||
static bool identify = false;
|
static bool identify = false;
|
||||||
|
static bool quiet = false;
|
||||||
static int mode = R_SEARCH_STRING;
|
static int mode = R_SEARCH_STRING;
|
||||||
static ut64 cur = 0;
|
static ut64 cur = 0;
|
||||||
static ut8 *buf = NULL;
|
static ut8 *buf = NULL;
|
||||||
@ -81,7 +82,7 @@ static int hit(RSearchKeyword *kw, void *user, ut64 addr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int show_help(char *argv0, int line) {
|
static int show_help(char *argv0, int line) {
|
||||||
printf ("Usage: %s [-mXnzZhv] [-a align] [-b sz] [-f/t from/to] [-[e|s|S] str] [-x hex] file|dir ..\n", argv0);
|
printf ("Usage: %s [-mXnzZhqv] [-a align] [-b sz] [-f/t from/to] [-[e|s|S] str] [-x hex] file|dir ..\n", argv0);
|
||||||
if (line) return 0;
|
if (line) return 0;
|
||||||
printf (
|
printf (
|
||||||
" -a [align] only accept aligned hits\n"
|
" -a [align] only accept aligned hits\n"
|
||||||
@ -97,6 +98,7 @@ static int show_help(char *argv0, int line) {
|
|||||||
" -s [str] search for a specific string (can be used multiple times)\n"
|
" -s [str] search for a specific string (can be used multiple times)\n"
|
||||||
" -S [str] search for a specific wide string (can be used multiple times)\n"
|
" -S [str] search for a specific wide string (can be used multiple times)\n"
|
||||||
" -t [to] stop search at address 'to'\n"
|
" -t [to] stop search at address 'to'\n"
|
||||||
|
" -q quiet - do not show headings (filenames) above matching contents (default for searching a single file)\n"
|
||||||
" -v print version and exit\n"
|
" -v print version and exit\n"
|
||||||
" -x [hex] search for hexpair string (909090) (can be used multiple times)\n"
|
" -x [hex] search for hexpair string (909090) (can be used multiple times)\n"
|
||||||
" -X show hexdump of search results\n"
|
" -X show hexdump of search results\n"
|
||||||
@ -114,6 +116,10 @@ static int rafind_open_file(char *file) {
|
|||||||
bool last = false;
|
bool last = false;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
|
if (!quiet) {
|
||||||
|
printf ("File: %s\n", file);
|
||||||
|
}
|
||||||
|
|
||||||
if (identify) {
|
if (identify) {
|
||||||
char *cmd = r_str_newf ("r2 -e search.show=false -e search.maxhits=1 -nqcpm '%s'", file);
|
char *cmd = r_str_newf ("r2 -e search.show=false -e search.maxhits=1 -nqcpm '%s'", file);
|
||||||
r_sandbox_system (cmd, 1);
|
r_sandbox_system (cmd, 1);
|
||||||
@ -242,7 +248,7 @@ int main(int argc, char **argv) {
|
|||||||
int c;
|
int c;
|
||||||
|
|
||||||
keywords = r_list_new ();
|
keywords = r_list_new ();
|
||||||
while ((c = getopt (argc, argv, "a:ie:b:mM:s:S:x:Xzf:t:rnhvZ")) != -1) {
|
while ((c = getopt (argc, argv, "a:ie:b:mM:s:S:x:Xzf:t:rqnhvZ")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'a':
|
case 'a':
|
||||||
align = r_num_math (NULL, optarg);
|
align = r_num_math (NULL, optarg);
|
||||||
@ -298,6 +304,9 @@ int main(int argc, char **argv) {
|
|||||||
case 'X':
|
case 'X':
|
||||||
pr = r_print_new ();
|
pr = r_print_new ();
|
||||||
break;
|
break;
|
||||||
|
case 'q':
|
||||||
|
quiet = true;
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
printf ("rafind2 v"R2_VERSION"\n");
|
printf ("rafind2 v"R2_VERSION"\n");
|
||||||
return 0;
|
return 0;
|
||||||
@ -316,6 +325,10 @@ int main(int argc, char **argv) {
|
|||||||
if (optind == argc) {
|
if (optind == argc) {
|
||||||
return show_help (argv[0], 1);
|
return show_help (argv[0], 1);
|
||||||
}
|
}
|
||||||
|
/* Enable quiet mode if searching just a single file */
|
||||||
|
if (optind + 1 == argc && !r_file_is_directory (argv[optind])) {
|
||||||
|
quiet = true;
|
||||||
|
}
|
||||||
for (; optind < argc; optind++) {
|
for (; optind < argc; optind++) {
|
||||||
rafind_open (argv[optind]);
|
rafind_open (argv[optind]);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
.Nd Advanced commandline hexadecimal editor
|
.Nd Advanced commandline hexadecimal editor
|
||||||
.Sh SYNOPSIS
|
.Sh SYNOPSIS
|
||||||
.Nm rafind2
|
.Nm rafind2
|
||||||
.Op Fl izZXnrhv
|
.Op Fl izZXnrhqv
|
||||||
.Op Fl b Ar size
|
.Op Fl b Ar size
|
||||||
.Op Fl f Ar from
|
.Op Fl f Ar from
|
||||||
.Op Fl t Ar to
|
.Op Fl t Ar to
|
||||||
@ -49,6 +49,8 @@ Do not stop the search when a read error occurs
|
|||||||
Show output in radare commands
|
Show output in radare commands
|
||||||
.It Fl b Ar size
|
.It Fl b Ar size
|
||||||
Define block size
|
Define block size
|
||||||
|
.It Fl q
|
||||||
|
Quiet mode - do not show headings (filenames) above matching contents (default for searching a single file)
|
||||||
.It Fl h
|
.It Fl h
|
||||||
Show help message
|
Show help message
|
||||||
.It Fl v
|
.It Fl v
|
||||||
|
Loading…
x
Reference in New Issue
Block a user