mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-21 23:01:03 +00:00
fix some coverities
This commit is contained in:
parent
520f57a962
commit
224b3c3319
@ -592,6 +592,7 @@ static int build_range(void *p, const char *k, const char *v) {
|
||||
r_list_append (list_range, range);
|
||||
}
|
||||
}
|
||||
r_anal_hint_free (hint);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -448,7 +448,7 @@ R_API char* r_anal_reflines_str(void *_core, ut64 addr, int opts) {
|
||||
r_list_free (lvls);
|
||||
//r_buf_free_to_string already free b and if that is the case
|
||||
//b will be NULL and r_buf_free will return but if there was
|
||||
//an error we free b here
|
||||
//an error we free b here so in other words is safe
|
||||
r_buf_free (b);
|
||||
return NULL;
|
||||
}
|
||||
|
@ -2065,7 +2065,8 @@ static void list_xtr_archs(RBin *bin, int mode) {
|
||||
int bits, i = 0;
|
||||
char *arch, *machine;
|
||||
r_list_foreach (binfile->xtr_data, iter_xtr, xtr_data) {
|
||||
if (!xtr_data->metadata && !xtr_data->metadata->arch) {
|
||||
if (!xtr_data || !xtr_data->metadata ||
|
||||
!xtr_data->metadata->arch) {
|
||||
continue;
|
||||
}
|
||||
arch = xtr_data->metadata->arch;
|
||||
|
@ -85,11 +85,14 @@ struct r_bin_bflt_obj *r_bin_bflt_new_buf(struct r_buf_t *buf) {
|
||||
if (bin && r_bin_bflt_init (bin, buf)) {
|
||||
return bin;
|
||||
}
|
||||
r_bin_bflt_free (bin);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void r_bin_bflt_free(struct r_bin_bflt_obj *obj) {
|
||||
R_FREE (obj->hdr);
|
||||
R_FREE (obj->b);
|
||||
R_FREE (obj);
|
||||
if (obj) {
|
||||
R_FREE (obj->hdr);
|
||||
R_FREE (obj->b);
|
||||
R_FREE (obj);
|
||||
}
|
||||
}
|
||||
|
@ -179,7 +179,7 @@ static RList *relocs(RBinFile *arch) {
|
||||
}
|
||||
len = r_buf_read_at (obj->b, obj->hdr->data_start + offset,
|
||||
(ut8 *)&got_entry, sizeof (ut32));
|
||||
if (!VALID_GOT_ENTRY (got_entry)) {
|
||||
if (!VALID_GOT_ENTRY (got_entry) || len != sizeof (ut32)) {
|
||||
break;
|
||||
} else {
|
||||
got_table[i].addr_to_patch = got_entry;
|
||||
@ -206,21 +206,27 @@ static RList *relocs(RBinFile *arch) {
|
||||
|
||||
amount = n_reloc * sizeof (ut32);
|
||||
if (amount < n_reloc || amount > UT32_MAX) {
|
||||
free (reloc_table);
|
||||
goto out_error;
|
||||
}
|
||||
ut32 *reloc_pointer_table = calloc (1, amount + 1);
|
||||
if (!reloc_pointer_table) {
|
||||
free (reloc_table);
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
if (obj->hdr->reloc_start + amount > obj->size ||
|
||||
obj->hdr->reloc_start + amount < amount) {
|
||||
free (reloc_table);
|
||||
free (reloc_pointer_table);
|
||||
goto out_error;
|
||||
}
|
||||
len = r_buf_read_at (obj->b, obj->hdr->reloc_start,
|
||||
(ut8 *)reloc_pointer_table,
|
||||
amount);
|
||||
if (len != amount) {
|
||||
free (reloc_table);
|
||||
free (reloc_pointer_table);
|
||||
goto out_error;
|
||||
}
|
||||
for (i = 0; i < obj->hdr->reloc_count; i++) {
|
||||
@ -233,6 +239,8 @@ static RList *relocs(RBinFile *arch) {
|
||||
ut32 reloc_fixed, reloc_data_offset;
|
||||
if (reloc_offset + sizeof (ut32) > obj->size ||
|
||||
reloc_offset + sizeof (ut32) < reloc_offset) {
|
||||
free (reloc_table);
|
||||
free (reloc_pointer_table);
|
||||
goto out_error;
|
||||
}
|
||||
len = r_buf_read_at (obj->b, reloc_offset,
|
||||
@ -240,6 +248,8 @@ static RList *relocs(RBinFile *arch) {
|
||||
sizeof (ut32));
|
||||
if (len != sizeof (ut32)) {
|
||||
eprintf ("problem while reading relocation entries\n");
|
||||
free (reloc_table);
|
||||
free (reloc_pointer_table);
|
||||
goto out_error;
|
||||
}
|
||||
reloc_data_offset = r_swap_ut32 (reloc_fixed) + BFLT_HDR_SIZE;
|
||||
|
@ -483,7 +483,9 @@ R_API int r_cons_yesno(int def, const char *fmt, ...) {
|
||||
|
||||
R_API char *r_cons_input(const char *msg) {
|
||||
char *oprompt = r_line_get_prompt (); //r_cons_singleton()->line->prompt);
|
||||
if (!oprompt) return NULL;
|
||||
if (!oprompt) {
|
||||
return NULL;
|
||||
}
|
||||
char buf[1024];
|
||||
if (msg) {
|
||||
//r_cons_printf ("%s\n", msg);
|
||||
|
@ -79,16 +79,16 @@ RList* search_virtual_tables(RCore *core){
|
||||
ut64 endAddress;
|
||||
RListIter * iter;
|
||||
RIOSection *section;
|
||||
RList *vtables = r_list_new();
|
||||
ut64 bits = r_config_get_i (core->config, "asm.bits");
|
||||
int wordSize = bits / 8;
|
||||
RList *vtables = r_list_newf ((RListFree)free);
|
||||
if (!vtables) {
|
||||
return NULL;
|
||||
}
|
||||
ut64 bits = r_config_get_i (core->config, "asm.bits");
|
||||
int wordSize = bits / 8;
|
||||
r_list_foreach (core->io->sections, iter, section) {
|
||||
if (!strcmp (section->name, ".rodata")) {
|
||||
ut8 *segBuff = calloc (1, section->size);
|
||||
r_io_read_at( core->io, section->offset, segBuff, section->size);
|
||||
r_io_read_at (core->io, section->offset, segBuff, section->size);
|
||||
startAddress = section->vaddr;
|
||||
endAddress = startAddress + (section->size) - (bits/8);
|
||||
while (startAddress <= endAddress) {
|
||||
@ -127,38 +127,43 @@ R_API void r_core_anal_list_vtables(void *core, bool printJson) {
|
||||
RListIter* vtableIter;
|
||||
vtable_info* table;
|
||||
|
||||
if (vtables) {
|
||||
if (printJson) {
|
||||
bool isFirstElement = true;
|
||||
r_cons_print ("[");
|
||||
r_list_foreach (vtables, vtableIter, table) {
|
||||
if (!isFirstElement) {
|
||||
r_cons_print (",");
|
||||
}
|
||||
r_cons_printf ("{\"offset\":%"PFMT64d",\"methods\":%d}",
|
||||
table->saddr, table->methods);
|
||||
isFirstElement = false;
|
||||
if (!vtables) {
|
||||
return;
|
||||
}
|
||||
if (printJson) {
|
||||
bool isFirstElement = true;
|
||||
r_cons_print ("[");
|
||||
r_list_foreach (vtables, vtableIter, table) {
|
||||
if (!isFirstElement) {
|
||||
r_cons_print (",");
|
||||
}
|
||||
r_cons_println ("]");
|
||||
} else {
|
||||
r_list_foreach (vtables, vtableIter, table) {
|
||||
ut64 vtableStartAddress = table->saddr;
|
||||
RList *vtableMethods = getVtableMethods ((RCore *)core, table);
|
||||
if (vtableMethods) {
|
||||
r_cons_printf ("\nVtable Found at 0x%08"PFMT64x"\n", vtableStartAddress);
|
||||
r_list_foreach (vtableMethods, vtableMethodNameIter, curMethod) {
|
||||
if (curMethod->name) {
|
||||
r_cons_printf ("0x%08"PFMT64x" : %s\n", vtableStartAddress, curMethod->name);
|
||||
} else {
|
||||
r_cons_printf ("0x%08"PFMT64x" : %s\n", vtableStartAddress, noMethodName);
|
||||
}
|
||||
vtableStartAddress += wordSize;
|
||||
r_cons_printf ("{\"offset\":%"PFMT64d",\"methods\":%d}",
|
||||
table->saddr, table->methods);
|
||||
isFirstElement = false;
|
||||
}
|
||||
r_cons_println ("]");
|
||||
} else {
|
||||
r_list_foreach (vtables, vtableIter, table) {
|
||||
ut64 vtableStartAddress = table->saddr;
|
||||
RList *vtableMethods = getVtableMethods ((RCore *)core, table);
|
||||
if (vtableMethods) {
|
||||
r_cons_printf ("\nVtable Found at 0x%08"PFMT64x"\n",
|
||||
vtableStartAddress);
|
||||
r_list_foreach (vtableMethods, vtableMethodNameIter, curMethod) {
|
||||
if (curMethod->name) {
|
||||
r_cons_printf ("0x%08"PFMT64x" : %s\n",
|
||||
vtableStartAddress, curMethod->name);
|
||||
} else {
|
||||
r_cons_printf ("0x%08"PFMT64x" : %s\n",
|
||||
vtableStartAddress, noMethodName);
|
||||
}
|
||||
r_cons_newline ();
|
||||
vtableStartAddress += wordSize;
|
||||
}
|
||||
r_cons_newline ();
|
||||
}
|
||||
}
|
||||
}
|
||||
r_list_free (vtables);
|
||||
}
|
||||
|
||||
static void r_core_anal_list_vtables_all(void *core) {
|
||||
|
@ -977,6 +977,7 @@ static void print_rop (RCore *core, RList *hitlist, char mode, bool *json_first)
|
||||
ropList = r_list_newf (free);
|
||||
if (!db) {
|
||||
eprintf ("Error: Could not create SDB 'rop' namespace\n");
|
||||
r_list_free (ropList);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,9 @@ static RList* parse_list (const char *str) {
|
||||
|
||||
str_n = strdup (str);
|
||||
list = r_list_newf (free);
|
||||
if (!list) {
|
||||
return NULL;
|
||||
}
|
||||
line = strtok (str_n, "\n");
|
||||
data = strchr (line, '=');
|
||||
p = strtok (data + 1, ",");
|
||||
@ -197,14 +200,27 @@ static void esil_split_flg (char *esil_str, char **esil_main, char **esil_flg) {
|
||||
}
|
||||
}
|
||||
|
||||
#define FREE_ROP \
|
||||
R_FREE (out); \
|
||||
R_FREE (esil_flg); \
|
||||
R_FREE (esil_main); \
|
||||
r_list_free (ops_list); \
|
||||
r_list_free (flg_read); \
|
||||
r_list_free (flg_write); \
|
||||
r_list_free (reg_read); \
|
||||
r_list_free (reg_write); \
|
||||
r_list_free (mem_read); \
|
||||
r_list_free (mem_write)
|
||||
|
||||
static char* rop_classify_constant(RCore *core, RList *ropList) {
|
||||
char *esil_str, *constant;
|
||||
char *ct = NULL, *esil_main = NULL, *esil_flg = NULL;
|
||||
char *ct = NULL, *esil_main = NULL, *esil_flg = NULL, *out = NULL;
|
||||
RListIter *iter_r, *iter_dst, *iter_const;
|
||||
RRegItem *item_dst;
|
||||
RList *head, *constants;
|
||||
RList *ops_list = NULL, *flg_read = NULL, *flg_write = NULL, *reg_read = NULL,
|
||||
*reg_write = NULL, *mem_read = NULL, *mem_write = NULL;
|
||||
RList *ops_list = NULL, *flg_read = NULL, *flg_write = NULL,
|
||||
*reg_read = NULL, *reg_write = NULL, *mem_read = NULL,
|
||||
*mem_write = NULL;
|
||||
const bool romem = r_config_get_i (core->config, "esil.romem");
|
||||
const bool stats = r_config_get_i (core->config, "esil.stats");
|
||||
|
||||
@ -219,59 +235,42 @@ static char* rop_classify_constant(RCore *core, RList *ropList) {
|
||||
if (r_list_empty (constants)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// init regs with known values
|
||||
fillRegisterValues (core);
|
||||
head = r_reg_get_list (core->dbg->reg, 0);
|
||||
if (!head) {
|
||||
ct = NULL;
|
||||
goto out_error;
|
||||
goto continue_error;
|
||||
}
|
||||
|
||||
esil_split_flg (esil_str, &esil_main, &esil_flg);
|
||||
|
||||
// r_cons_printf ("Split : <%s> + <%s>\n", esil_main, esil_flg);
|
||||
if (esil_main) {
|
||||
// r_cons_printf ("Emulating const pattern:%s\n", esil_main);
|
||||
cmd_anal_esil (core, esil_main);
|
||||
} else {
|
||||
// r_cons_printf ("Emulating const pattern:%s\n", esil_str);
|
||||
cmd_anal_esil (core, esil_str);
|
||||
}
|
||||
char *out = sdb_querys (core->anal->esil->stats, NULL, 0, "*");
|
||||
// r_cons_println (out);
|
||||
out = sdb_querys (core->anal->esil->stats, NULL, 0, "*");
|
||||
if (out) {
|
||||
ops_list = parse_list (strstr (out, "ops.list"));
|
||||
flg_read = parse_list (strstr (out, "flg.read"));
|
||||
ops_list = parse_list (strstr (out, "ops.list"));
|
||||
flg_read = parse_list (strstr (out, "flg.read"));
|
||||
flg_write = parse_list (strstr (out, "flg.write"));
|
||||
reg_read = parse_list (strstr (out, "reg.read"));
|
||||
reg_read = parse_list (strstr (out, "reg.read"));
|
||||
reg_write = parse_list (strstr (out, "reg.write"));
|
||||
mem_read = parse_list (strstr (out, "mem.read"));
|
||||
mem_read = parse_list (strstr (out, "mem.read"));
|
||||
mem_write = parse_list (strstr (out, "mem.write"));
|
||||
} else {
|
||||
R_FREE (esil_flg);
|
||||
R_FREE (esil_main);
|
||||
continue;
|
||||
goto continue_error;
|
||||
}
|
||||
|
||||
if (!r_list_find (ops_list, "=", (RListComparator)strcmp)) {
|
||||
free (out);
|
||||
R_FREE (esil_flg);
|
||||
R_FREE (esil_main);
|
||||
continue;
|
||||
goto continue_error;
|
||||
}
|
||||
|
||||
head = r_reg_get_list (core->dbg->reg, 0);
|
||||
if (!head) {
|
||||
free (out);
|
||||
R_FREE (esil_flg);
|
||||
R_FREE (esil_main);
|
||||
return NULL;
|
||||
goto out_error;
|
||||
}
|
||||
r_list_foreach (head, iter_dst, item_dst) {
|
||||
ut64 diff_dst, value_dst;
|
||||
|
||||
if (!r_list_find (reg_write, item_dst->name, (RListComparator)strcmp)) {
|
||||
if (!r_list_find (reg_write, item_dst->name,
|
||||
(RListComparator)strcmp)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -290,31 +289,28 @@ static char* rop_classify_constant(RCore *core, RList *ropList) {
|
||||
}
|
||||
}
|
||||
}
|
||||
out_error:
|
||||
free (out);
|
||||
R_FREE (esil_flg);
|
||||
R_FREE (esil_main);
|
||||
r_list_free (ops_list);
|
||||
r_list_free (flg_read);
|
||||
r_list_free (flg_write);
|
||||
r_list_free (reg_read);
|
||||
r_list_free (reg_write);
|
||||
r_list_free (mem_read);
|
||||
r_list_free (mem_write);
|
||||
r_list_free (constants);
|
||||
continue_error:
|
||||
// coverity may complain here but as long as the pointer is set back to
|
||||
// NULL is safe that is why is used R_FREE
|
||||
FREE_ROP;
|
||||
r_list_free (constants);
|
||||
}
|
||||
|
||||
return ct;
|
||||
out_error:
|
||||
FREE_ROP;
|
||||
r_list_free (constants);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char* rop_classify_mov(RCore *core, RList *ropList) {
|
||||
char *esil_str;
|
||||
char *mov = NULL, *esil_main = NULL, *esil_flg = NULL;
|
||||
char *mov = NULL, *esil_main = NULL, *esil_flg = NULL, *out = NULL;
|
||||
RListIter *iter_src, *iter_r, *iter_dst;
|
||||
RRegItem *item_src, *item_dst;
|
||||
RList *head;
|
||||
RList *ops_list = NULL, *flg_read = NULL, *flg_write = NULL, *reg_read = NULL,
|
||||
*reg_write = NULL, *mem_read = NULL, *mem_write = NULL;
|
||||
RList *ops_list = NULL, *flg_read = NULL, *flg_write = NULL,
|
||||
*reg_read = NULL, *reg_write = NULL, *mem_read = NULL,
|
||||
*mem_write = NULL;
|
||||
const bool romem = r_config_get_i (core->config, "esil.romem");
|
||||
const bool stats = r_config_get_i (core->config, "esil.stats");
|
||||
|
||||
@ -328,53 +324,39 @@ static char* rop_classify_mov(RCore *core, RList *ropList) {
|
||||
fillRegisterValues (core);
|
||||
head = r_reg_get_list (core->dbg->reg, 0);
|
||||
if (!head) {
|
||||
return NULL;
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
esil_split_flg (esil_str, &esil_main, &esil_flg);
|
||||
|
||||
// r_cons_printf ("Split : <%s> + <%s>\n", esil_main, esil_flg);
|
||||
if (esil_main) {
|
||||
// r_cons_printf ("Emulating mov pattern:%s\n", esil_main);
|
||||
cmd_anal_esil (core, esil_main);
|
||||
} else {
|
||||
// r_cons_printf ("Emulating mov pattern:%s\n", esil_str);
|
||||
cmd_anal_esil (core, esil_str);
|
||||
}
|
||||
char *out = sdb_querys (core->anal->esil->stats, NULL, 0, "*");
|
||||
// r_cons_println (out);
|
||||
out = sdb_querys (core->anal->esil->stats, NULL, 0, "*");
|
||||
if (out) {
|
||||
ops_list = parse_list (strstr (out, "ops.list"));
|
||||
flg_read = parse_list (strstr (out, "flg.read"));
|
||||
ops_list = parse_list (strstr (out, "ops.list"));
|
||||
flg_read = parse_list (strstr (out, "flg.read"));
|
||||
flg_write = parse_list (strstr (out, "flg.write"));
|
||||
reg_read = parse_list (strstr (out, "reg.read"));
|
||||
reg_read = parse_list (strstr (out, "reg.read"));
|
||||
reg_write = parse_list (strstr (out, "reg.write"));
|
||||
mem_read = parse_list (strstr (out, "mem.read"));
|
||||
mem_read = parse_list (strstr (out, "mem.read"));
|
||||
mem_write = parse_list (strstr (out, "mem.write"));
|
||||
} else {
|
||||
R_FREE (esil_flg);
|
||||
R_FREE (esil_main);
|
||||
continue;
|
||||
goto continue_error;
|
||||
}
|
||||
|
||||
if (!r_list_find (ops_list, "=", (RListComparator)strcmp)) {
|
||||
free (out);
|
||||
R_FREE (esil_flg);
|
||||
R_FREE (esil_main);
|
||||
continue;
|
||||
goto continue_error;
|
||||
}
|
||||
|
||||
head = r_reg_get_list (core->dbg->reg, 0);
|
||||
if (!head) {
|
||||
free (out);
|
||||
R_FREE (esil_flg);
|
||||
R_FREE (esil_main);
|
||||
return NULL;
|
||||
goto out_error;
|
||||
}
|
||||
r_list_foreach (head, iter_dst, item_dst) {
|
||||
ut64 diff_dst, value_dst;
|
||||
|
||||
if (!r_list_find (reg_write, item_dst->name, (RListComparator)strcmp)) {
|
||||
if (!r_list_find (reg_write, item_dst->name,
|
||||
(RListComparator)strcmp)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -387,62 +369,47 @@ static char* rop_classify_mov(RCore *core, RList *ropList) {
|
||||
r_reg_arena_swap (core->dbg->reg, false);
|
||||
diff_dst = r_reg_get_value (core->dbg->reg, item_dst);
|
||||
r_reg_arena_swap (core->dbg->reg, false);
|
||||
//restore initial value
|
||||
// r_reg_set_value (core->dbg->reg, item_dst, diff_dst);
|
||||
|
||||
r_list_foreach (head, iter_src, item_src) {
|
||||
ut64 diff_src, value_src;
|
||||
|
||||
if (!r_list_find (reg_read, item_src->name, (RListComparator)strcmp)) {
|
||||
if (!r_list_find (reg_read, item_src->name,
|
||||
(RListComparator)strcmp)) {
|
||||
continue;
|
||||
}
|
||||
if (item_src == item_dst) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// you never mov from flags
|
||||
if (isFlag (item_src)) {
|
||||
if (item_src == item_dst || isFlag (item_src)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
value_src = r_reg_get_value (core->dbg->reg, item_src);
|
||||
r_reg_arena_swap (core->dbg->reg, false);
|
||||
diff_src = r_reg_get_value (core->dbg->reg, item_src);
|
||||
r_reg_arena_swap (core->dbg->reg, false);
|
||||
//restore initial value
|
||||
r_reg_set_value (core->dbg->reg, item_src, diff_src);
|
||||
|
||||
// r_cons_printf ("Checking mov %s = %s\n", item_dst->name, item_src->name);
|
||||
// r_cons_printf ("Current values %llu, %llu\n", value_dst, value_src);
|
||||
if (value_dst == value_src && value_dst != diff_dst) {
|
||||
mov = r_str_concatf (mov, "%s <-- %s;",
|
||||
item_dst->name, item_src->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
free (out);
|
||||
R_FREE (esil_flg);
|
||||
R_FREE (esil_main);
|
||||
r_list_free (ops_list);
|
||||
r_list_free (flg_read);
|
||||
r_list_free (flg_write);
|
||||
r_list_free (reg_read);
|
||||
r_list_free (reg_write);
|
||||
r_list_free (mem_read);
|
||||
r_list_free (mem_write);
|
||||
continue_error:
|
||||
FREE_ROP;
|
||||
}
|
||||
|
||||
return mov;
|
||||
out_error:
|
||||
FREE_ROP;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char* rop_classify_arithmetic(RCore *core, RList *ropList) {
|
||||
char *esil_str, *op;
|
||||
char *arithmetic = NULL, *esil_flg = NULL, *esil_main = NULL;
|
||||
char *arithmetic = NULL, *esil_flg = NULL, *esil_main = NULL,
|
||||
*out = NULL;
|
||||
RListIter *iter_src1, *iter_src2, *iter_r, *iter_dst, *iter_ops;
|
||||
RRegItem *item_src1, *item_src2, *item_dst;
|
||||
RList *head;
|
||||
RList *ops_list = NULL, *flg_read = NULL, *flg_write = NULL, *reg_read = NULL,
|
||||
*reg_write = NULL, *mem_read = NULL, *mem_write = NULL;
|
||||
RList *ops_list = NULL, *flg_read = NULL, *flg_write = NULL,
|
||||
*reg_read = NULL, *reg_write = NULL, *mem_read = NULL,
|
||||
*mem_write = NULL;
|
||||
const bool romem = r_config_get_i (core->config, "esil.romem");
|
||||
const bool stats = r_config_get_i (core->config, "esil.stats");
|
||||
ut64 *op_result = R_NEW0 (ut64);
|
||||
@ -460,35 +427,26 @@ static char* rop_classify_arithmetic(RCore *core, RList *ropList) {
|
||||
fillRegisterValues (core);
|
||||
head = r_reg_get_list (core->dbg->reg, 0);
|
||||
if (!head) {
|
||||
free (op_result);
|
||||
free (op_result_r);
|
||||
return NULL;
|
||||
goto out_error;
|
||||
}
|
||||
|
||||
esil_split_flg (esil_str, &esil_main, &esil_flg);
|
||||
|
||||
// r_cons_printf ("Split : <%s> + <%s>\n", esil_main, esil_flg);
|
||||
if (esil_main) {
|
||||
// r_cons_printf ("Emulating arithmetic pattern:%s\n", esil_main);
|
||||
cmd_anal_esil (core, esil_main);
|
||||
} else {
|
||||
// r_cons_printf ("Emulating arithmetic pattern:%s\n", esil_str);
|
||||
cmd_anal_esil (core, esil_str);
|
||||
}
|
||||
char *out = sdb_querys (core->anal->esil->stats, NULL, 0, "*");
|
||||
out = sdb_querys (core->anal->esil->stats, NULL, 0, "*");
|
||||
// r_cons_println (out);
|
||||
if (out) {
|
||||
ops_list = parse_list (strstr (out, "ops.list"));
|
||||
flg_read = parse_list (strstr (out, "flg.read"));
|
||||
ops_list = parse_list (strstr (out, "ops.list"));
|
||||
flg_read = parse_list (strstr (out, "flg.read"));
|
||||
flg_write = parse_list (strstr (out, "flg.write"));
|
||||
reg_read = parse_list (strstr (out, "reg.read"));
|
||||
reg_read = parse_list (strstr (out, "reg.read"));
|
||||
reg_write = parse_list (strstr (out, "reg.write"));
|
||||
mem_read = parse_list (strstr (out, "mem.read"));
|
||||
mem_read = parse_list (strstr (out, "mem.read"));
|
||||
mem_write = parse_list (strstr (out, "mem.write"));
|
||||
} else {
|
||||
R_FREE (esil_flg);
|
||||
R_FREE (esil_main);
|
||||
continue;
|
||||
goto continue_error;
|
||||
}
|
||||
|
||||
r_list_foreach (ops_list, iter_ops, op) {
|
||||
@ -499,20 +457,19 @@ static char* rop_classify_arithmetic(RCore *core, RList *ropList) {
|
||||
r_reg_arena_swap (core->dbg->reg, false);
|
||||
diff_src1 = r_reg_get_value (core->dbg->reg, item_src1);
|
||||
r_reg_arena_swap (core->dbg->reg, false);
|
||||
|
||||
if (!r_list_find (reg_read, item_src1->name, (RListComparator)strcmp)) {
|
||||
if (!r_list_find (reg_read, item_src1->name,
|
||||
(RListComparator)strcmp)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
r_list_foreach (head, iter_src2, item_src2) {
|
||||
ut64 value_src2, diff_src2;
|
||||
|
||||
value_src2 = r_reg_get_value (core->dbg->reg, item_src2);
|
||||
r_reg_arena_swap (core->dbg->reg, false);
|
||||
diff_src2 = r_reg_get_value (core->dbg->reg, item_src2);
|
||||
r_reg_arena_swap (core->dbg->reg, false);
|
||||
|
||||
if (!r_list_find (reg_read, item_src2->name, (RListComparator)strcmp)) {
|
||||
if (!r_list_find (reg_read, item_src2->name,
|
||||
(RListComparator)strcmp)) {
|
||||
continue;
|
||||
}
|
||||
// TODO check condition
|
||||
@ -526,19 +483,16 @@ static char* rop_classify_arithmetic(RCore *core, RList *ropList) {
|
||||
|
||||
value_dst = r_reg_get_value (core->dbg->reg, item_dst);
|
||||
r_reg_arena_swap (core->dbg->reg, false);
|
||||
if (!r_list_find (reg_write, item_dst->name, (RListComparator)strcmp)) {
|
||||
if (!r_list_find (reg_write, item_dst->name,
|
||||
(RListComparator)strcmp)) {
|
||||
continue;
|
||||
}
|
||||
// dont check flags for arithmetic
|
||||
if (isFlag (item_dst)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// r_cons_printf ("Checking %s = %s %s %s\n", item_dst->name, item_src1->name, op, item_src2->name);
|
||||
// r_cons_printf ("Current values: %s = %llu; %s = %llu; %s = %llu, old_%s = %llu old_%s = %llu\n", item_dst->name, value_dst, item_src1->name, value_src1, item_src2->name, value_src2, item_src1->name, diff_src1, item_src2->name, diff_src2);
|
||||
simulate = simulate_op (op, value_src1, value_src2, diff_src1, diff_src2, op_result, item_dst->size);
|
||||
simulate_r = simulate_op (op, value_src2, value_src1, diff_src2, diff_src1, op_result_r, item_dst->size);
|
||||
// r_cons_printf ("Simulate = %llu, reversed = %llu\n", *op_result, *op_result_r);
|
||||
if (/*value_src1 != 0 && value_src2 != 0 && */simulate && value_dst == *op_result) {
|
||||
// r_cons_println ("Debug: FOUND ONE !");
|
||||
char *tmp = r_str_newf ("%s <-- %s %s %s;", item_dst->name, item_src1->name, op, item_src2->name);
|
||||
@ -563,21 +517,17 @@ static char* rop_classify_arithmetic(RCore *core, RList *ropList) {
|
||||
}
|
||||
}
|
||||
}
|
||||
free (out);
|
||||
R_FREE (esil_flg);
|
||||
R_FREE (esil_main);
|
||||
r_list_free (ops_list);
|
||||
r_list_free (flg_read);
|
||||
r_list_free (flg_write);
|
||||
r_list_free (reg_read);
|
||||
r_list_free (reg_write);
|
||||
r_list_free (mem_read);
|
||||
r_list_free (mem_write);
|
||||
continue_error:
|
||||
FREE_ROP;
|
||||
}
|
||||
free (op_result);
|
||||
free (op_result_r);
|
||||
|
||||
return arithmetic;
|
||||
out_error:
|
||||
FREE_ROP;
|
||||
free (op_result);
|
||||
free (op_result_r);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static char* rop_classify_arithmetic_const(RCore *core, RList *ropList) {
|
||||
@ -611,34 +561,28 @@ static char* rop_classify_arithmetic_const(RCore *core, RList *ropList) {
|
||||
head = r_reg_get_list (core->dbg->reg, 0);
|
||||
if (!head) {
|
||||
arithmetic = NULL;
|
||||
goto out_error;
|
||||
continue;
|
||||
}
|
||||
esil_split_flg (esil_str, &esil_main, &esil_flg);
|
||||
|
||||
// r_cons_printf ("Split : <%s> + <%s>\n", esil_main, esil_flg);
|
||||
if (esil_main) {
|
||||
// r_cons_printf ("Emulating arithmetic_const pattern:%s\n", esil_main);
|
||||
cmd_anal_esil (core, esil_main);
|
||||
} else {
|
||||
// r_cons_printf ("Emulating arithmetic_const pattern:%s\n", esil_str);
|
||||
cmd_anal_esil (core, esil_str);
|
||||
}
|
||||
char *out = sdb_querys (core->anal->esil->stats, NULL, 0, "*");
|
||||
// r_cons_println (out);
|
||||
if (out) {
|
||||
ops_list = parse_list (strstr (out, "ops.list"));
|
||||
flg_read = parse_list (strstr (out, "flg.read"));
|
||||
ops_list = parse_list (strstr (out, "ops.list"));
|
||||
flg_read = parse_list (strstr (out, "flg.read"));
|
||||
flg_write = parse_list (strstr (out, "flg.write"));
|
||||
reg_read = parse_list (strstr (out, "reg.read"));
|
||||
reg_read = parse_list (strstr (out, "reg.read"));
|
||||
reg_write = parse_list (strstr (out, "reg.write"));
|
||||
mem_read = parse_list (strstr (out, "mem.read"));
|
||||
mem_read = parse_list (strstr (out, "mem.read"));
|
||||
mem_write = parse_list (strstr (out, "mem.write"));
|
||||
} else {
|
||||
free (op_result);
|
||||
free (op_result_r);
|
||||
R_FREE (esil_flg);
|
||||
R_FREE (esil_main);
|
||||
continue;
|
||||
goto continue_error;
|
||||
}
|
||||
|
||||
r_list_foreach (ops_list, iter_ops, op) {
|
||||
@ -649,7 +593,8 @@ static char* rop_classify_arithmetic_const(RCore *core, RList *ropList) {
|
||||
diff_src1 = r_reg_get_value (core->dbg->reg, item_src1);
|
||||
r_reg_arena_swap (core->dbg->reg, false);
|
||||
|
||||
if (!r_list_find (reg_read, item_src1->name, (RListComparator)strcmp)) {
|
||||
if (!r_list_find (reg_read, item_src1->name,
|
||||
(RListComparator)strcmp)) {
|
||||
continue;
|
||||
}
|
||||
r_list_foreach (head, iter_dst, item_dst) {
|
||||
@ -659,20 +604,23 @@ static char* rop_classify_arithmetic_const(RCore *core, RList *ropList) {
|
||||
r_reg_arena_swap (core->dbg->reg, false);
|
||||
diff_dst = r_reg_get_value (core->dbg->reg, item_dst);
|
||||
r_reg_arena_swap (core->dbg->reg, false);
|
||||
|
||||
if (!r_list_find (reg_write, item_dst->name, (RListComparator)strcmp)) {
|
||||
if (!r_list_find (reg_write, item_dst->name,
|
||||
(RListComparator)strcmp)) {
|
||||
continue;
|
||||
}
|
||||
// dont check flags for arithmetic
|
||||
if (isFlag (item_dst)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (value_dst != diff_dst) {
|
||||
r_list_foreach (constants, iter_const, constant) {
|
||||
ut64 value_ct = r_num_get (NULL, constant);
|
||||
simulate = simulate_op (op, value_src1, value_ct, diff_src1, value_ct, op_result, item_dst->size);
|
||||
simulate_r = simulate_op (op, value_ct, value_src1, value_ct, diff_src1, op_result_r, item_dst->size);
|
||||
simulate = simulate_op (op, value_src1, value_ct,
|
||||
diff_src1, value_ct, op_result,
|
||||
item_dst->size);
|
||||
simulate_r = simulate_op (op, value_ct, value_src1,
|
||||
value_ct, diff_src1, op_result_r,
|
||||
item_dst->size);
|
||||
if (simulate && value_dst == *op_result) {
|
||||
char *tmp = r_str_newf ("%s <-- %s %s %s;", item_dst->name, item_src1->name, op, constant);
|
||||
if (arithmetic && !strstr (arithmetic, tmp)) {
|
||||
@ -696,22 +644,12 @@ static char* rop_classify_arithmetic_const(RCore *core, RList *ropList) {
|
||||
}
|
||||
}
|
||||
}
|
||||
out_error:
|
||||
free (out);
|
||||
R_FREE (esil_flg);
|
||||
R_FREE (esil_main);
|
||||
r_list_free (flg_read);
|
||||
r_list_free (flg_write);
|
||||
r_list_free (reg_read);
|
||||
r_list_free (reg_write);
|
||||
r_list_free (mem_read);
|
||||
r_list_free (mem_write);
|
||||
r_list_free (ops_list);
|
||||
continue_error:
|
||||
FREE_ROP;
|
||||
r_list_free (constants);
|
||||
}
|
||||
free (op_result);
|
||||
free (op_result_r);
|
||||
|
||||
return arithmetic;
|
||||
}
|
||||
|
||||
|
@ -244,6 +244,7 @@ static bool GH(r_resolve_main_arena)(RCore *core, GHT *m_arena, GH(RHeap_MallocS
|
||||
}
|
||||
|
||||
if (is_debug_file[0] || is_debug_file[1]) {
|
||||
free (path);
|
||||
path = r_str_newf ("%s", libc_ver_end);
|
||||
if (r_file_exists (path)) {
|
||||
goto arena;
|
||||
@ -251,6 +252,7 @@ static bool GH(r_resolve_main_arena)(RCore *core, GHT *m_arena, GH(RHeap_MallocS
|
||||
}
|
||||
|
||||
if ((is_debug_file[2] || is_debug_file[3]) && r_file_is_directory ("/usr/lib/debug")) {
|
||||
free (path);
|
||||
path = r_str_newf ("%s%s", dir_dbg, libc_ver_end);
|
||||
if (r_file_exists (path)) {
|
||||
goto arena;
|
||||
@ -260,6 +262,7 @@ static bool GH(r_resolve_main_arena)(RCore *core, GHT *m_arena, GH(RHeap_MallocS
|
||||
if ((is_debug_file[2] || is_debug_file[3]) && r_file_is_directory ("/usr/lib/debug/.build-id")) {
|
||||
get_hash_debug_file (libc_ver_end, hash, sizeof (hash) - 1);
|
||||
libc_ver_end = hash;
|
||||
free (path);
|
||||
path = r_str_newf ("%s%s%s", dir_dbg, dir_build_id, libc_ver_end);
|
||||
if (r_file_exists (path)) {
|
||||
goto arena;
|
||||
@ -278,7 +281,9 @@ arena:
|
||||
}
|
||||
}
|
||||
not_arena:
|
||||
eprintf ("Warning: glibc library with symbol main_arena could not be found. Is libc6-dbg installed?\n");
|
||||
eprintf (
|
||||
"Warning: glibc library with symbol main_arena could not be "
|
||||
"found. Is libc6-dbg installed?\n");
|
||||
free (path);
|
||||
return false;
|
||||
} else {
|
||||
@ -1161,4 +1166,3 @@ static int GH(cmd_dbg_map_heap_glibc)(RCore *core, const char *input) {
|
||||
free (main_arena);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2449,12 +2449,16 @@ dodo:
|
||||
}
|
||||
wheel = r_config_get_i (core->config, "scr.wheel");
|
||||
r_cons_show_cursor (false);
|
||||
if (wheel) r_cons_enable_mouse (true);
|
||||
if (wheel) {
|
||||
r_cons_enable_mouse (true);
|
||||
}
|
||||
core->cons->event_data = core;
|
||||
core->cons->event_resize = (RConsEvent)visual_refresh;
|
||||
flags = core->print->flags;
|
||||
color = r_config_get_i (core->config, "scr.color");
|
||||
if (color) flags |= R_PRINT_FLAGS_COLOR;
|
||||
if (color) {
|
||||
flags |= R_PRINT_FLAGS_COLOR;
|
||||
}
|
||||
debug = r_config_get_i (core->config, "cfg.debug");
|
||||
flags |= R_PRINT_FLAGS_ADDRMOD | R_PRINT_FLAGS_HEADER;
|
||||
r_print_set_flags (core->print, core->print->flags);
|
||||
|
@ -83,7 +83,7 @@ R_API int r_search_pattern(RSearch *s, ut64 from, ut64 to) {
|
||||
bproc = bact + patlen ;
|
||||
// read ( fd, sblk, patlen );
|
||||
//XXX bytepattern should be used with a read callback
|
||||
nr = ((bytes-bproc) < BSIZE)?(bytes-bproc):BSIZE;
|
||||
nr = ((bytes - bproc) < BSIZE)?(bytes - bproc):BSIZE;
|
||||
//XXX radare_read_at(bact, sblk, patlen);
|
||||
rb = s->iob.read_at (s->iob.io, addr, sblk, nr);
|
||||
sblk[patlen] = 0; // XXX
|
||||
@ -92,17 +92,17 @@ R_API int r_search_pattern(RSearch *s, ut64 from, ut64 to) {
|
||||
cnt = 0;
|
||||
while (bproc < bytes) {
|
||||
// TODO: handle ^C here
|
||||
nr = ((bytes-bproc) < BSIZE)?(bytes-bproc):BSIZE;
|
||||
nr = ((bytes - bproc) < BSIZE)?(bytes - bproc):BSIZE;
|
||||
nr += (patlen - (nr % patlen)); // tamany de bloc llegit multiple superior de tamany busqueda
|
||||
rb = s->iob.read_at (s->iob.io, bproc, block, nr);
|
||||
if (rb<1) {
|
||||
bproc +=nr;
|
||||
if (rb < 1) {
|
||||
bproc += nr;
|
||||
break;
|
||||
}
|
||||
nr = rb;
|
||||
addr += nr;
|
||||
moar = 0;
|
||||
for (i=0; i<nr; i++) {
|
||||
for (i = 0; i<nr; i++) {
|
||||
if (!memcmp (&block[i], sblk, patlen) && !is_fi_present (root, sblk, patlen)){
|
||||
if (cnt == 0) {
|
||||
add_fi (root, sblk, patlen);
|
||||
@ -121,7 +121,7 @@ R_API int r_search_pattern(RSearch *s, ut64 from, ut64 to) {
|
||||
eprintf ("\ncount: %d: %d\n", pcnt, moar+1);
|
||||
bproc += rb;
|
||||
}
|
||||
bact += (moar>0)? patlen: 1;
|
||||
bact += (moar > 0)? patlen: 1;
|
||||
}
|
||||
eprintf ("\n");
|
||||
fini_fi (root);
|
||||
|
@ -499,20 +499,17 @@ static int fd_forward(int in_fd, int out_fd, char **buff) {
|
||||
perror ("ioctl");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (size == 0) { // child process exited or socket is closed
|
||||
if (!size) { // child process exited or socket is closed
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *new_buff = realloc (*buff, size);
|
||||
if (new_buff == NULL) {
|
||||
if (!new_buff) {
|
||||
eprintf ("Failed to allocate buffer for redirection");
|
||||
return -1;
|
||||
}
|
||||
*buff = new_buff;
|
||||
|
||||
read (in_fd, *buff, size);
|
||||
|
||||
(void)read (in_fd, *buff, size);
|
||||
if (write (out_fd, *buff, size) != size) {
|
||||
perror ("write");
|
||||
return -1;
|
||||
|
@ -682,7 +682,7 @@ R_API int r_buf_append_string (RBuffer *b, const char *str) {
|
||||
return r_buf_append_bytes (b, (const ut8*)str, strlen (str));
|
||||
}
|
||||
|
||||
R_API char *r_buf_free_to_string (RBuffer *b) {
|
||||
R_API char *r_buf_free_to_string(RBuffer *b) {
|
||||
char *p;
|
||||
if (!b) {
|
||||
return NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user