bin.strpurge: allow more fine-grained purging of strings (disasm only) (#9194)

This commit is contained in:
Khairul Azhar Kasmiran 2018-01-15 01:09:22 +08:00 committed by radare
parent 9a63f43d01
commit b117fbd12e
4 changed files with 35 additions and 10 deletions

View File

@ -2128,6 +2128,7 @@ R_API RBin *r_bin_new() {
bin->cb_printf = (PrintfCallback)printf;
bin->plugins = r_list_newf ((RListFree)plugin_free);
bin->minstrlen = 0;
bin->strpurge_addrs = NULL;
bin->want_dbginfo = true;
bin->cur = NULL;
bin->io_owned = false;

View File

@ -780,7 +780,9 @@ static int cb_usextr(void *user, void *data) {
static int cb_strpurge(void *user, void *data) {
RCore *core = (RCore*) user;
RConfigNode *node = (RConfigNode*) data;
core->bin->strpurge = node->i_value;
core->bin->strpurge = !strncmp (node->value, "true", 4);
free (core->bin->strpurge_addrs);
core->bin->strpurge_addrs = strdup (node->value);
return true;
}
@ -2369,7 +2371,8 @@ R_API int r_core_config_init(RCore *core) {
SETOPTIONS (n, "latin1", "utf8", "utf16le", "utf32le", "guess", NULL);
SETCB ("bin.usextr", "true", &cb_usextr, "Use extract plugins when loading files");
SETCB ("bin.useldr", "true", &cb_useldr, "Use loader plugins when loading files");
SETCB ("bin.strpurge", "false", &cb_strpurge, "Try to purge false positive strings");
SETCB ("bin.strpurge", "", &cb_strpurge, "Try to purge false positive strings (true: use the classifier in "
"r_core_bin_strpurge(), [+addr]*: specific string addresses to purge)");
SETPREF ("bin.b64str", "false", "Try to debase64 the strings");
SETPREF ("bin.libs", "false", "Try to load libraries after loading main binary");
n = NODECB ("bin.strfilter", "", &cb_strfilter);

View File

@ -288,7 +288,7 @@ static void ds_print_asmop_payload(RDisasmState *ds, const ut8 *buf);
static char *ds_esc_str(RDisasmState *ds, const char *str, int len, const char **prefix_out);
static void ds_print_comments_right(RDisasmState *ds);
static void ds_print_ptr(RDisasmState *ds, int len, int idx);
static void ds_print_str(RDisasmState *ds, const char *str, int len);
static void ds_print_str(RDisasmState *ds, const char *str, int len, ut64 refaddr);
static ut64 p2v(RDisasmState *ds, ut64 addr) {
#if 0
@ -3023,10 +3023,30 @@ static char *ds_esc_str(RDisasmState *ds, const char *str, int len, const char *
return escstr;
}
static void ds_print_str(RDisasmState *ds, const char *str, int len) {
static void ds_print_str(RDisasmState *ds, const char *str, int len, ut64 refaddr) {
const char *prefix;
if (ds->core->bin->strpurge && r_core_bin_strpurge (str)) {
return;
if (ds->core->bin->strpurge_addrs) {
char *addrs = strdup (ds->core->bin->strpurge_addrs);
if (addrs) {
int splits = r_str_split (addrs, '+');
int i;
char *ptr;
ut64 addr;
for (i = 0, ptr = addrs; i < splits; i++, ptr += strlen (ptr) + 1) {
if (!strcmp (ptr, "true") && r_core_bin_strpurge (str)) {
free (addrs);
return;
}
addr = r_num_get (NULL, ptr);
if (addr != 0 || *ptr == '0') {
if (refaddr == addr) {
free (addrs);
return;
}
}
}
free (addrs);
}
}
char *escstr = ds_esc_str (ds, str, len, &prefix);
if (escstr) {
@ -3154,7 +3174,7 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) {
(ut8 *)str, sizeof (str) - 1);
str[sizeof (str) - 1] = 0;
if (!string_printed && str[0] && r_str_is_printable_incl_newlines (str)) {
ds_print_str (ds, str, sizeof (str));
ds_print_str (ds, str, sizeof (str), ds->analop.ptr);
string_printed = true;
}
}
@ -3275,7 +3295,7 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) {
}
if (*msg) {
if (!string_printed) {
ds_print_str (ds, msg, len);
ds_print_str (ds, msg, len, refaddr);
string_printed = true;
}
} else if (!flag_printed && (!ds->opstr || !strstr (ds->opstr, f->name))) {
@ -3323,7 +3343,7 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) {
} else {
if (r_core_anal_address (core, refaddr) & R_ANAL_ADDR_TYPE_ASCII) {
if (!string_printed && *msg) {
ds_print_str (ds, msg, len);
ds_print_str (ds, msg, len, refaddr);
string_printed = true;
}
}
@ -3334,7 +3354,7 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) {
if (kind) {
if (!strcmp (kind, "text")) {
if (!string_printed && *msg) {
ds_print_str (ds, msg, len);
ds_print_str (ds, msg, len, refaddr);
string_printed = true;
}
} else if (!strcmp (kind, "invalid")) {

View File

@ -274,6 +274,7 @@ typedef struct r_bin_t {
int filter; // symbol filtering
char strfilter; // string filtering
int strpurge; // purge false positive strings
char *strpurge_addrs;
char *srcdir; // dir.source
char *prefix; // bin.prefix
ut64 filter_rules;