mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-21 06:40:33 +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 int nonstop = 0;
|
||||
static bool identify = false;
|
||||
static bool quiet = false;
|
||||
static int mode = R_SEARCH_STRING;
|
||||
static ut64 cur = 0;
|
||||
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) {
|
||||
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;
|
||||
printf (
|
||||
" -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 wide string (can be used multiple times)\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"
|
||||
" -x [hex] search for hexpair string (909090) (can be used multiple times)\n"
|
||||
" -X show hexdump of search results\n"
|
||||
@ -114,6 +116,10 @@ static int rafind_open_file(char *file) {
|
||||
bool last = false;
|
||||
int ret;
|
||||
|
||||
if (!quiet) {
|
||||
printf ("File: %s\n", file);
|
||||
}
|
||||
|
||||
if (identify) {
|
||||
char *cmd = r_str_newf ("r2 -e search.show=false -e search.maxhits=1 -nqcpm '%s'", file);
|
||||
r_sandbox_system (cmd, 1);
|
||||
@ -242,7 +248,7 @@ int main(int argc, char **argv) {
|
||||
int c;
|
||||
|
||||
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) {
|
||||
case 'a':
|
||||
align = r_num_math (NULL, optarg);
|
||||
@ -298,6 +304,9 @@ int main(int argc, char **argv) {
|
||||
case 'X':
|
||||
pr = r_print_new ();
|
||||
break;
|
||||
case 'q':
|
||||
quiet = true;
|
||||
break;
|
||||
case 'v':
|
||||
printf ("rafind2 v"R2_VERSION"\n");
|
||||
return 0;
|
||||
@ -316,6 +325,10 @@ int main(int argc, char **argv) {
|
||||
if (optind == argc) {
|
||||
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++) {
|
||||
rafind_open (argv[optind]);
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
.Nd Advanced commandline hexadecimal editor
|
||||
.Sh SYNOPSIS
|
||||
.Nm rafind2
|
||||
.Op Fl izZXnrhv
|
||||
.Op Fl izZXnrhqv
|
||||
.Op Fl b Ar size
|
||||
.Op Fl f Ar from
|
||||
.Op Fl t Ar to
|
||||
@ -49,6 +49,8 @@ Do not stop the search when a read error occurs
|
||||
Show output in radare commands
|
||||
.It Fl b Ar 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
|
||||
Show help message
|
||||
.It Fl v
|
||||
|
Loading…
x
Reference in New Issue
Block a user