mirror of
https://github.com/radareorg/radare2.git
synced 2025-01-27 00:05:10 +00:00
Fix #18699 - fix search hit dumps outside the current block in rafind2
This commit is contained in:
parent
f7d3ec4fc4
commit
9242bc2328
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2020 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2021 - pancake */
|
||||
|
||||
#include <r_main.h>
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* radare - LGPL - Copyright 2009-2020 - pancake */
|
||||
/* radare - LGPL - Copyright 2009-2021 - pancake */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -14,8 +14,10 @@
|
||||
|
||||
|
||||
typedef struct {
|
||||
RIO *io;
|
||||
bool showstr;
|
||||
bool rad;
|
||||
bool color;
|
||||
bool identify;
|
||||
bool quiet;
|
||||
bool hexstr;
|
||||
@ -54,18 +56,22 @@ static int rafind_open(RafindOptions *ro, const char *file);
|
||||
|
||||
static int hit(RSearchKeyword *kw, void *user, ut64 addr) {
|
||||
RafindOptions *ro = (RafindOptions*)user;
|
||||
ut8 *buf = ro->buf;
|
||||
int delta = addr - ro->cur;
|
||||
if (ro->cur > addr && (ro->cur - addr == kw->keyword_length - 1)) {
|
||||
// This case occurs when there is hit in search left over
|
||||
delta = ro->cur - addr;
|
||||
}
|
||||
if (delta < 0) {
|
||||
delta = 0;
|
||||
}
|
||||
if (delta >= ro->bsize) {
|
||||
if (delta > 0 && delta >= ro->bsize) {
|
||||
eprintf ("Invalid delta %d from 0x%08"PFMT64x"\n", delta, addr);
|
||||
return 0;
|
||||
}
|
||||
if (delta < 0) {
|
||||
// rollback the buffer and reset the delta
|
||||
buf = calloc (1, ro->bsize * 2);
|
||||
r_io_pread_at (ro->io, addr, buf, ro->bsize * 2);
|
||||
delta = 0;
|
||||
}
|
||||
char _str[128];
|
||||
char *str = _str;
|
||||
*_str = 0;
|
||||
@ -73,8 +79,8 @@ static int hit(RSearchKeyword *kw, void *user, ut64 addr) {
|
||||
if (ro->widestr) {
|
||||
str = _str;
|
||||
int i, j = 0;
|
||||
for (i = delta; ro->buf[i] && i < sizeof (_str) - 1; i++) {
|
||||
char ch = ro->buf[i];
|
||||
for (i = delta; buf[i] && i < sizeof (_str) - 1; i++) {
|
||||
char ch = buf[i];
|
||||
if (ch == '"' || ch == '\\') {
|
||||
ch = '\'';
|
||||
}
|
||||
@ -88,7 +94,7 @@ static int hit(RSearchKeyword *kw, void *user, ut64 addr) {
|
||||
j += 3;
|
||||
break;
|
||||
}
|
||||
if (ro->buf[i]) {
|
||||
if (buf[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -96,7 +102,7 @@ static int hit(RSearchKeyword *kw, void *user, ut64 addr) {
|
||||
} else {
|
||||
size_t i;
|
||||
for (i = 0; i < sizeof (_str) - 1; i++) {
|
||||
char ch = ro->buf[delta + i];
|
||||
char ch = buf[delta + i];
|
||||
if (ch == '"' || ch == '\\') {
|
||||
ch = '\'';
|
||||
}
|
||||
@ -110,7 +116,7 @@ static int hit(RSearchKeyword *kw, void *user, ut64 addr) {
|
||||
} else {
|
||||
size_t i;
|
||||
for (i = 0; i < sizeof (_str) - 1; i++) {
|
||||
char ch = ro->buf[delta + i];
|
||||
char ch = buf[delta + i];
|
||||
if (ch == '"' || ch == '\\') {
|
||||
ch = '\'';
|
||||
}
|
||||
@ -139,11 +145,14 @@ static int hit(RSearchKeyword *kw, void *user, ut64 addr) {
|
||||
} else {
|
||||
printf ("0x%"PFMT64x"\n", addr);
|
||||
if (ro->pr) {
|
||||
r_print_hexdump (ro->pr, addr, (ut8*)ro->buf + delta, 78, 16, 1, 1);
|
||||
r_print_hexdump (ro->pr, addr, (ut8*)buf + delta, 78, 16, 1, 1);
|
||||
r_cons_flush ();
|
||||
}
|
||||
}
|
||||
}
|
||||
if (buf != ro->buf) {
|
||||
free (buf);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -201,6 +210,7 @@ static int rafind_open_file(RafindOptions *ro, const char *file, const ut8 *data
|
||||
free (efile);
|
||||
return 1;
|
||||
}
|
||||
ro->io = io;
|
||||
|
||||
if (!r_io_open_nomap (io, file, R_PERM_R, 0)) {
|
||||
eprintf ("Cannot open file '%s'\n", file);
|
||||
@ -357,7 +367,6 @@ static int rafind_open(RafindOptions *ro, const char *file) {
|
||||
: rafind_open_file (ro, file, NULL, -1);
|
||||
}
|
||||
|
||||
|
||||
R_API int r_main_rafind2(int argc, const char **argv) {
|
||||
RafindOptions ro;
|
||||
rafind_options_init (&ro);
|
||||
@ -486,7 +495,6 @@ R_API int r_main_rafind2(int argc, const char **argv) {
|
||||
}
|
||||
for (; opt.ind < argc; opt.ind++) {
|
||||
file = argv[opt.ind];
|
||||
|
||||
if (file && !*file) {
|
||||
eprintf ("Cannot open empty path\n");
|
||||
return 1;
|
||||
|
@ -1,14 +1,55 @@
|
||||
NAME=rafind2 -s 1234 -X -b 0x100 -c
|
||||
FILE=--
|
||||
CMDS=!rafind2 -s 1234 -X -b 0x100 -c bins/other/search.bin
|
||||
EXPECT=<<EOF
|
||||
0xfe
|
||||
[35m- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
|
||||
[0m[32m0x000000fe[0m [35m31[0m[35m32[0m [35m33[0m[35m34[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [35m1[0m[35m2[0m[35m3[0m[35m4[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m
|
||||
[32m0x0000010e[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m
|
||||
[32m0x0000011e[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m
|
||||
[32m0x0000012e[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m
|
||||
[32m0x0000013e[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m
|
||||
EOF
|
||||
RUN
|
||||
NAME=rafind2 -s 1234 -X -b 0x100
|
||||
FILE=--
|
||||
CMDS=!rafind2 -s 1234 -X -b 0x100 bins/other/search.bin
|
||||
EXPECT=<<EOF
|
||||
0xfe
|
||||
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
|
||||
0x000000fe 3132 3334 0000 0000 0000 0000 0000 0000 1234............
|
||||
0x0000010e 0000 0000 0000 0000 0000 0000 0000 0000 ................
|
||||
0x0000011e 0000 0000 0000 0000 0000 0000 0000 0000 ................
|
||||
0x0000012e 0000 0000 0000 0000 0000 0000 0000 0000 ................
|
||||
0x0000013e 0000 0000 0000 0000 0000 0000 0000 ..............
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=rafind2 -s 1234 -X
|
||||
FILE=--
|
||||
CMDS=!rafind2 -q -s 1234 -X bins/other/search.bin
|
||||
EXPECT=<<EOF
|
||||
0xfe
|
||||
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
|
||||
0x000000fe 3132 3334 0000 0000 0000 0000 0000 0000 1234............
|
||||
0x0000010e 0000 0000 0000 0000 0000 0000 0000 0000 ................
|
||||
0x0000011e 0000 0000 0000 0000 0000 0000 0000 0000 ................
|
||||
0x0000012e 0000 0000 0000 0000 0000 0000 0000 0000 ................
|
||||
0x0000013e 0000 0000 0000 0000 0000 0000 0000 ..............
|
||||
EOF
|
||||
RUN
|
||||
|
||||
NAME=rafind2 -X -s
|
||||
FILE=-
|
||||
CMDS=!rafind2 -X -s 250382 bins/elf/ioli/crackme0x00
|
||||
EXPECT=<<EOF
|
||||
0x58f
|
||||
[35m- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
|
||||
[0m[32m0x0000058f[0m [35m32[0m[35m35[0m [35m30[0m[35m33[0m [35m38[0m[35m32[0m [32m00[0m[35m49[0m [35m6e[0m[35m76[0m [35m61[0m[35m6c[0m [35m69[0m[35m64[0m [35m20[0m[35m50[0m [35m2[0m[35m5[0m[35m0[0m[35m3[0m[35m8[0m[35m2[0m[32m.[0m[35mI[0m[35mn[0m[35mv[0m[35ma[0m[35ml[0m[35mi[0m[35md[0m[35m [0m[35mP[0m
|
||||
[32m0x0000059f[0m [35m61[0m[35m73[0m [35m73[0m[35m77[0m [35m6f[0m[35m72[0m [35m64[0m[35m21[0m [37m0a[0m[32m00[0m [35m50[0m[35m61[0m [35m73[0m[35m73[0m [35m77[0m[35m6f[0m [35ma[0m[35ms[0m[35ms[0m[35mw[0m[35mo[0m[35mr[0m[35md[0m[35m![0m[37m.[0m[32m.[0m[35mP[0m[35ma[0m[35ms[0m[35ms[0m[35mw[0m[35mo[0m
|
||||
[32m0x000005af[0m [35m72[0m[35m64[0m [35m20[0m[35m4f[0m [35m4b[0m[35m20[0m [35m3a[0m[35m29[0m [37m0a[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [35mr[0m[35md[0m[35m [0m[35mO[0m[35mK[0m[35m [0m[35m:[0m[35m)[0m[37m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m
|
||||
[32m0x000005bf[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m
|
||||
[32m0x000005cf[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m00[0m[32m00[0m [32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m[32m.[0m
|
||||
- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF
|
||||
0x0000058f 3235 3033 3832 0049 6e76 616c 6964 2050 250382.Invalid P
|
||||
0x0000059f 6173 7377 6f72 6421 0a00 5061 7373 776f assword!..Passwo
|
||||
0x000005af 7264 204f 4b20 3a29 0a00 0000 0000 0000 rd OK :)........
|
||||
0x000005bf 0000 0000 0000 0000 0000 0000 0000 0000 ................
|
||||
0x000005cf 0000 0000 0000 0000 0000 0000 0000 ..............
|
||||
EOF
|
||||
RUN
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user