Fix some possible null-deref and merge drr/pxr internals

This commit is contained in:
pancake 2015-09-28 02:28:20 +02:00
parent c94dd22f4d
commit bff8c1d264
5 changed files with 43 additions and 94 deletions

View File

@ -892,99 +892,24 @@ static int cmd_debug_map(RCore *core, const char *input) {
}
R_API void r_core_debug_rr (RCore *core, RReg *reg) {
// also get section and map names
RIOSection *sect;
char *mapname = NULL;
ut64 type, value;
int i, bits = core->assembler->bits;
ut64 value;
int bits = core->assembler->bits;
RList *list = r_reg_get_list (reg, R_REG_TYPE_GPR);
RAnalFunction *fcn;
RListIter *iter;
RFlagItem *fi;
RRegItem *r;
r_debug_map_sync (core->dbg);
r_list_foreach (list, iter, r) {
char *rrstr;
if (r->size != bits)
continue;
value = r_reg_get_value (core->dbg->reg, r);
fi = r_flag_get_i2 (core->flags, value);
type = r_core_anal_address (core, value);
fcn = r_anal_get_fcn_in (core->anal, value, 0);
{
RDebugMap *map;
map = r_debug_map_get (core->dbg, value);
if (map && map->name && map->name[0])
mapname = strdup (map->name);
else mapname = NULL;
}
sect = r_io_section_vget (core->io, value);
rrstr = r_core_anal_hasrefs(core, value);
if (bits == 64) {
r_cons_printf ("%6s 0x%016"PFMT64x, r->name, value);
} else {
r_cons_printf ("%6s 0x%08"PFMT64x, r->name, value);
}
if (value && fi) {
if (strcmp (fi->name, r->name))
r_cons_printf (" %s", fi->name);
}
if (fcn) {
if (strcmp (fcn->name, r->name))
r_cons_printf (" %s", fcn->name);
}
if (type) {
const char *c = r_core_anal_optype_colorfor (core, value);
const char *cend = (c&&*c)? Color_RESET: "";
if (!c) c = "";
if (type & R_ANAL_ADDR_TYPE_HEAP) {
r_cons_printf (" %sheap%s", c, cend);
} else if (type & R_ANAL_ADDR_TYPE_STACK) {
r_cons_printf (" %sstack%s", c, cend);
}
if (type & R_ANAL_ADDR_TYPE_PROGRAM)
r_cons_printf (" %sprogram%s", c, cend);
if (type & R_ANAL_ADDR_TYPE_LIBRARY)
r_cons_printf (" %slibrary%s", c, cend);
if (type & R_ANAL_ADDR_TYPE_ASCII)
r_cons_printf (" %sascii%s", c, cend);
if (type & R_ANAL_ADDR_TYPE_SEQUENCE)
r_cons_printf (" %ssequence%s", c, cend);
if (type & R_ANAL_ADDR_TYPE_READ)
r_cons_printf (" %sR%s", c, cend);
if (type & R_ANAL_ADDR_TYPE_WRITE)
r_cons_printf (" %sW%s", c, cend);
if (type & R_ANAL_ADDR_TYPE_EXEC)
r_cons_printf (" %sX%s", c, cend);
{
int ret, len = 0;
int is_text = 0;
ut8 buf[128];
buf[0]=0;
ret = r_io_read_at (core->io, value, buf, sizeof (buf));
if (ret && buf[0] && buf[0] != 0xff)
for (i=0; i<sizeof(buf)-1; i++) {
if (buf[i]==0) {
is_text = len;
break;
}
if (!IS_PRINTABLE(buf[i])) {
is_text = 0;
break;
}
len++;
}
if (is_text) {
r_cons_printf (" \"%s\"", buf);
}
}
}
if (sect && sect->name[0]) {
r_cons_printf (" (%s)", sect->name);
}
if (mapname) {
r_cons_printf (" (%s)", mapname);
free (mapname);
}
r_cons_newline ();
r_cons_printf (" %s\n", rrstr);
}
}

View File

@ -2719,14 +2719,16 @@ static int cmd_print(void *data, const char *input) {
bitsize = 32;
core->print->cols = 1;
core->print->flags |= R_PRINT_FLAGS_REFS;
r_print_hexdump (core->print, core->offset, core->block, len,
r_print_hexdump (core->print, core->offset,
core->block, len,
bitsize, bitsize/8);
core->print->flags &= ~R_PRINT_FLAGS_REFS;
core->print->cols = ocols;
}
break;
case 'h':
r_print_hexdump (core->print, core->offset, core->block, len, 32, 2);
r_print_hexdump (core->print, core->offset,
core->block, len, 32, 2);
break;
case 'H':
len = len - (len % 2);

View File

@ -721,11 +721,21 @@ static char *getbitfield(void *_core, const char *name, ut64 val) {
R_API char *r_core_anal_hasrefs(RCore *core, ut64 value) {
RStrBuf *s = r_strbuf_new (NULL);
ut64 type;
RIOSection *sect;
char *mapname;
RAnalFunction *fcn;
RFlagItem *fi;
fi = r_flag_get_i (core->flags, value);
type = r_core_anal_address (core, value);
fcn = r_anal_get_fcn_in (core->anal, value, 0);
{
RDebugMap *map;
map = r_debug_map_get (core->dbg, value);
if (map && map->name && map->name[0])
mapname = strdup (map->name);
else mapname = NULL;
}
sect = r_io_section_vget (core->io, value);
if (fi) {
r_strbuf_appendf (s, " %s", fi->name);
@ -755,17 +765,16 @@ R_API char *r_core_anal_hasrefs(RCore *core, ut64 value) {
if (type & R_ANAL_ADDR_TYPE_WRITE)
r_strbuf_appendf (s, " %sW%s", c, cend);
if (type & R_ANAL_ADDR_TYPE_EXEC) {
RAsmOp op;
ut8 buf[32];
r_strbuf_appendf (s, " %sX%s", c, cend);
{
RAsmOp op;
ut8 buf[32];
r_io_read_at (core->io, value, buf, sizeof (buf));
r_asm_set_pc (core->assembler, value);
r_asm_disassemble (core->assembler, &op, buf, sizeof (buf));
r_strbuf_appendf (s, " '%s'", op.buf_asm);
}
/* instruction disassembly */
r_io_read_at (core->io, value, buf, sizeof (buf));
r_asm_set_pc (core->assembler, value);
r_asm_disassemble (core->assembler, &op, buf, sizeof (buf));
r_strbuf_appendf (s, " '%s'", op.buf_asm);
/* get library name */
{
{ // NOTE: dup for mapname?
RDebugMap *map;
RListIter *iter;
r_list_foreach (core->dbg->maps, iter, map) {
@ -779,6 +788,13 @@ R_API char *r_core_anal_hasrefs(RCore *core, ut64 value) {
}
}
}
if (sect && sect->name[0]) {
r_strbuf_appendf (s," (%s)", sect->name);
}
if (mapname) {
r_strbuf_appendf (s, " (%s)", mapname);
free (mapname);
}
{
char *rs = strdup (r_strbuf_get (s));
r_strbuf_free (s);

View File

@ -202,6 +202,7 @@ R_API RFlagItem *r_flag_get_i2(RFlag *f, ut64 off) {
RList *list;
#if USE_SDB
char buf[128];
if (!f) return NULL;
char * foo = sdb_get (db, sdb_itoa (off, buf, 16), 0);
return r_flag_get (f, foo);
#else
@ -266,7 +267,9 @@ R_API char *r_flag_get_liststr(RFlag *f, ut64 off) {
#define R_FLAG_TEST 0
R_API RFlagItem *r_flag_get_i(RFlag *f, ut64 off) {
RList *list = r_hashtable64_lookup (f->ht_off, XOROFF(off));
RList *list;
if (!f) return NULL;
list = r_hashtable64_lookup (f->ht_off, XOROFF(off));
//if (off == 0x4005c4) { eprintf ("FLAG GET IT %llx = %p\n", off, list); }
if (list) {
RFlagItem *item = r_list_get_top (list);

View File

@ -179,8 +179,11 @@ R_API void ht_(free)(RHT *ht) {
}
R_API void *ht_(lookup)(RHT *ht, utH hash) {
RHTE *entry = ht_(search) (ht, hash);
return entry? entry->data : NULL;
if (ht) {
RHTE *entry = ht_(search) (ht, hash);
return entry? entry->data : NULL;
}
return NULL;
}
/**