mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-25 23:34:57 +00:00
Fix #3506 - align in rafind2
This commit is contained in:
parent
38b2db2dfb
commit
d79e576305
@ -16,6 +16,7 @@ static struct r_io_t *io;
|
||||
static RIODesc *fd = NULL;
|
||||
static int showstr = 0;
|
||||
static int rad = 0;
|
||||
static int align = 0;
|
||||
struct r_search_t *rs;
|
||||
static ut64 from = 0LL, to = -1;
|
||||
static char *mask = NULL;
|
||||
@ -49,26 +50,24 @@ static int hit(RSearchKeyword *kw, void *user, ut64 addr) {
|
||||
}
|
||||
|
||||
static int show_help(char *argv0, int line) {
|
||||
printf ("Usage: %s [-Xnzhv] [-b sz] [-f/t from/to] [-[m|s|S|e] str] [-x hex] file ..\n", argv0);
|
||||
printf ("Usage: %s [-Xnzhv] [-a align] [-b sz] [-f/t from/to] [-[m|s|S|e] str] [-x hex] file ..\n", argv0);
|
||||
if (line) return 0;
|
||||
printf (
|
||||
" -h show this help\n"
|
||||
" -v print version and exit\n"
|
||||
" -a [align] only accept aligned hits\n"
|
||||
" -b [size] set block size\n"
|
||||
|
||||
" -e [regex] search for regular expression string matches\n"
|
||||
" -f [from] start searching from address 'from'\n"
|
||||
" -t [to] stop search at address 'to'\n"
|
||||
" -h show this help\n"
|
||||
" -m [str] set a binary mask to be applied on keywords\n"
|
||||
" -n do not stop on read errors\n"
|
||||
|
||||
" -r print using radare commands\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"
|
||||
" -t [to] stop search at address 'to'\n"
|
||||
" -v print version and exit\n"
|
||||
" -x [hex] search for hexpair string (909090) (can be used multiple times)\n"
|
||||
" -e [regex] search for regular expression string matches\n"
|
||||
" -m [str] set a binary mask to be applied on keywords\n"
|
||||
" -z search for zero-terminated strings\n"
|
||||
|
||||
" -r print using radare commands\n"
|
||||
" -X show hexdump of search results\n"
|
||||
" -z search for zero-terminated strings\n"
|
||||
" -Z show zero-terminated strings of search results\n"
|
||||
);
|
||||
return 0;
|
||||
@ -77,7 +76,8 @@ static int show_help(char *argv0, int line) {
|
||||
static int rafind_open(char *file) {
|
||||
const char *kw;
|
||||
RListIter *iter;
|
||||
int ret, last = 0;
|
||||
bool last = false;
|
||||
int ret;
|
||||
|
||||
io = r_io_new ();
|
||||
fd = r_io_open_nomap (io, file, R_IO_READ, 0);
|
||||
@ -88,11 +88,12 @@ static int rafind_open(char *file) {
|
||||
|
||||
r_cons_new ();
|
||||
rs = r_search_new (mode);
|
||||
buf = malloc (bsize);
|
||||
if (buf==NULL) {
|
||||
buf = calloc (1, bsize);
|
||||
if (!buf) {
|
||||
eprintf ("Cannot allocate %"PFMT64d" bytes\n", bsize);
|
||||
return 1;
|
||||
}
|
||||
rs->align = align;
|
||||
r_search_set_callback (rs, &hit, buf);
|
||||
if (to == -1)
|
||||
to = r_io_size(io);
|
||||
@ -121,7 +122,7 @@ static int rafind_open(char *file) {
|
||||
for (cur = from; !last && cur < to; cur += bsize) {
|
||||
if ((cur+bsize)>to) {
|
||||
bsize = to-cur;
|
||||
last=1;
|
||||
last = true;
|
||||
}
|
||||
ret = r_io_pread (io, cur, buf, bsize);
|
||||
if (ret == 0) {
|
||||
@ -147,8 +148,11 @@ int main(int argc, char **argv) {
|
||||
int c;
|
||||
|
||||
keywords = r_list_new ();
|
||||
while ((c = getopt(argc, argv, "e:b:m:s:S:x:Xzf:t:rnhvZ")) != -1) {
|
||||
while ((c = getopt(argc, argv, "a:e:b:m:s:S:x:Xzf:t:rnhvZ")) != -1) {
|
||||
switch (c) {
|
||||
case 'a':
|
||||
align = r_num_math (NULL, optarg);
|
||||
break;
|
||||
case 'r':
|
||||
rad = 1;
|
||||
break;
|
||||
|
@ -19,6 +19,8 @@ The options are:
|
||||
.Bl -tag -width Fl
|
||||
.It Fl z
|
||||
Search for zero-terminated strings
|
||||
.It Fl a Ar align
|
||||
Only accept aligned hits
|
||||
.It Fl s Ar str
|
||||
Search for a specific string
|
||||
.It Fl S Ar str
|
||||
|
Loading…
x
Reference in New Issue
Block a user