Add /V value range support in rafind2 ##search

* Updated help message and usage info, ensured coding standards
This commit is contained in:
Sarveshwaar SS 2024-10-06 15:53:55 +05:30 committed by GitHub
parent 1f5defe34f
commit 09ee59c92a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 48 additions and 32 deletions

View File

@ -189,7 +189,7 @@ static int show_help(const char *argv0, int line) {
" -t [to] stop search at address 'to'\n"
" -q quiet: fewer output do not show headings or filenames.\n"
" -v print version and exit\n"
" -V [s:num] search for given value in given endian (-V 4:123)\n"
" -V [s:num | s:num1,num2] search for a value or range in the specified endian (-V 4:123 or -V 4:100,200)\n"
" -x [hex] search for hexpair string (909090) (can be used multiple times)\n"
" -X show hexdump of search results\n"
" -z search for zero-terminated strings\n"
@ -498,18 +498,31 @@ R_API int r_main_rafind2(int argc, const char **argv) {
{
char *arg = strdup (opt.arg);
char *colon = strchr (arg, ':');
char *comma = NULL;
ut8 buf[8] = {0};
int size = (R_SYS_BITS & R_SYS_BITS_64)? 8: 4;
ut64 value = 0;
ut64 value, min_value = 0, max_value = 0;
if (colon) {
*colon++ = 0;
size = atoi (arg);
size = R_MIN (8, size);
size = R_MAX (1, size);
value = r_num_math (NULL, colon);
comma = strchr (colon, ',');
if (comma) {
*comma++ = 0;
min_value = r_num_math (NULL, colon);
max_value = r_num_math (NULL, comma);
} else {
value = r_num_math (NULL, arg);
min_value = r_num_math (NULL, colon);
max_value = min_value;
}
} else {
min_value = r_num_math (NULL, arg);
max_value = min_value;
}
for (value = min_value; value <= max_value; value++) {
switch (size) {
case 1:
buf[0] = value;
@ -526,6 +539,7 @@ R_API int r_main_rafind2(int argc, const char **argv) {
default:
R_LOG_ERROR ("Invalid value size. Must be 1, 2, 4 or 8");
rafind_options_fini (&ro);
free (arg);
return 1;
}
char *hexdata = r_hex_bin2strdup ((ut8*)buf, size);
@ -537,6 +551,8 @@ R_API int r_main_rafind2(int argc, const char **argv) {
r_list_append (ro.keywords, (void*)hexdata);
}
}
free (arg);
}
break;
case 'v':
rafind_options_fini (&ro);

View File

@ -24,7 +24,7 @@
.Op Fl S Ar str
.Op Fl t Ar to
.Op Fl v
.Op Fl V Ar s:num
.Op Fl V Ar s:num | s:num1,num2
.Op Fl x Ar hex
.Op Fl X
.Op Fl z
@ -74,8 +74,8 @@ Search for wide strings (Unicode) in the file(s).
Specify the ending address for the search. (See -f)
.It Fl v
Display the version of rafind2 and exit.
.It Fl V Ar s:num
Search for the given value using little-endian notation (e.g., -V 4:123).
.It Fl V Ar s:num | s:num1,num2
Search for the given value using little-endian notation. A single value can be specified (e.g., -V 4:123) or a range of values can be searched by providing two values separated by a comma (e.g., -V 4:100,200).
.It Fl x Ar hex
Search for the specified hex pattern(s) in the file(s).
.It Fl X