Disobey rabin2 -B if bin is not pie, enhace dmm* and mach0

This commit is contained in:
pancake 2015-10-19 02:41:21 +02:00
parent 6a317977ae
commit 1b5cd887ce
8 changed files with 82 additions and 51 deletions

View File

@ -1811,6 +1811,9 @@ R_API ut64 r_bin_get_vaddr (RBin *bin, ut64 paddr, ut64 vaddr) {
static ut64 binobj_a2b (RBinObject *o, ut64 addr) {
if (!o) return addr;
/* if bin is not PIE dot not allow to relocate */
if (o->info && !o->info->has_pi)
return addr;
return o->baddr_shift + addr;
}

View File

@ -1229,10 +1229,10 @@ struct reloc_t* MACH0_(get_relocs)(struct MACH0_(obj_t)* bin) {
if (bin->dyld_info->bind_off+bind_size+lazy_size > bin->size)
return NULL;
// NOTE(eddyb) it's a waste of memory, but we don't know the actual number of relocs.
if (!(relocs = malloc ((bind_size + lazy_size) * sizeof (struct reloc_t))))
if (!(relocs = calloc (1, (bind_size + lazy_size) * sizeof (struct reloc_t))))
return NULL;
opcodes = malloc (bind_size + lazy_size);
opcodes = calloc (1, bind_size + lazy_size);
if (!opcodes) {
free (relocs);
return NULL;
@ -1408,7 +1408,7 @@ struct addr_t* MACH0_(get_entrypoint)(struct MACH0_(obj_t)* bin) {
if (bin->entry) {
entry->addr = entry_to_vaddr(bin);
entry->offset = addr_to_offset(bin, entry->addr);
entry->offset = addr_to_offset (bin, entry->addr);
}
if (!bin->entry || entry->offset == 0) {
@ -1455,7 +1455,6 @@ ut64 MACH0_(get_baddr)(struct MACH0_(obj_t)* bin) {
for (i = 0; i < bin->nsegs; ++i)
if (bin->segs[i].fileoff == 0 && bin->segs[i].filesize != 0)
return bin->segs[i].vmaddr;
return 0;
}

View File

@ -59,12 +59,9 @@ static int destroy(RBinFile *arch) {
static ut64 baddr(RBinFile *arch) {
struct MACH0_(obj_t) *bin;
if (!arch || !arch->o || !arch->o->bin_obj)
return 0;
return 0LL;
bin = arch->o->bin_obj;
return MACH0_(get_baddr)(bin);
}

View File

@ -33,12 +33,15 @@ static void pair(const char *a, const char *b, int mode, bool last) {
r_cons_printf ("%s%s%s\n", a, ws, b);
}
}
static void pair_bool (const char *a, bool t, int mode, bool last) {
pair (a, r_str_bool (t), mode, last);
}
static void pair_int (const char *a, int n, int mode, bool last) {
pair (a, sdb_fmt (0, "%d", n), mode, last);
}
static void pair_str (const char *a, const char *b, int mode, int last) {
if (IS_MODE_JSON (mode)) {
if (!b) b = "";

View File

@ -686,6 +686,19 @@ static void cmd_debug_modules(RCore *core, int mode) { // "dmm"
list = r_debug_modules_list (core->dbg);
r_list_foreach (list, iter, map) {
switch (mode) {
case ':':
if (addr >= map->addr && addr < map->addr_end) {
char *fn = strdup (map->file);
r_name_filter (fn, 0);
//r_cons_printf ("fs+module_%s\n", fn);
r_cons_printf ("f mod.%s = 0x%08"PFMT64x"\n",
fn, map->addr);
r_cons_printf (".!rabin2 -rsB 0x%08"PFMT64x" '%s'\n",
map->addr, map->file);
//r_cons_printf ("fs-\n");
free (fn);
}
break;
case '.':
if (addr >= map->addr && addr < map->addr_end) {
r_cons_printf ("0x%08"PFMT64x" %s\n",
@ -694,15 +707,19 @@ static void cmd_debug_modules(RCore *core, int mode) { // "dmm"
}
break;
case 'j':
r_cons_printf ("{\"address\":%"PFMT64d",\"file\":\"%s\"}%s",
map->addr, map->file, iter->n?",":"");
r_cons_printf ("{\"address\":%"PFMT64d",\"name\":\"%s\",\"file\":\"%s\"}%s",
map->addr, map->name, map->file, iter->n?",":"");
break;
case '*':
{
char *fn = strdup (map->file);
r_name_filter (fn, 0);
//r_cons_printf ("fs+module_%s\n", fn);
r_cons_printf ("f mod.%s = 0x%08"PFMT64x"\n",
fn, map->addr);
r_cons_printf (".!rabin2 -rsB 0x%08"PFMT64x" '%s'\n",
map->addr, map->file);
//r_cons_printf ("fs-\n");
free (fn);
}
break;
@ -755,7 +772,9 @@ static int cmd_debug_map(RCore *core, const char *input) {
}
break;
case 'm': // "dmm"
cmd_debug_modules (core, input[1]);
if (!strcmp (input+1, ".*")) {
cmd_debug_modules (core, ':');
} else cmd_debug_modules (core, input[1]);
break;
case '?':
r_core_cmd_help (core, help_msg);

View File

@ -6,7 +6,7 @@
R_API void r_debug_map_list(RDebug *dbg, ut64 addr, int rad) {
const char *fmtstr;
char buf[128];
int notfirst = R_FALSE;
bool notfirst = false;
RListIter *iter;
RDebugMap *map;
if (!dbg) return;
@ -17,20 +17,24 @@ R_API void r_debug_map_list(RDebug *dbg, ut64 addr, int rad) {
r_list_foreach (dbg->maps, iter, map) {
if (notfirst) dbg->cb_printf (",");
dbg->cb_printf ("{\"name\":\"%s\",",map->name);
if (map->file && *map->file)
dbg->cb_printf ("\"file\":\"%s\",", map->file);
dbg->cb_printf ("\"addr\":%"PFMT64u",", map->addr);
dbg->cb_printf ("\"addr_end\":%"PFMT64u",", map->addr_end);
dbg->cb_printf ("\"type\":\"%c\",", map->user?'u':'s');
dbg->cb_printf ("\"perm\":\"%s\"}", r_str_rwx_i (map->perm));
notfirst = R_TRUE;
notfirst = true;
}
r_list_foreach (dbg->maps_user, iter, map) {
if (notfirst) dbg->cb_printf (",");
dbg->cb_printf ("{\"name\":\"%s\",",map->name);
dbg->cb_printf ("{\"name\":\"%s\",", map->name);
if (map->file && *map->file)
dbg->cb_printf ("\"file\":\"%s\",", map->file);
dbg->cb_printf ("\"addr\":%"PFMT64u",", map->addr);
dbg->cb_printf ("\"addr_end\":%"PFMT64u",", map->addr_end);
dbg->cb_printf ("\"type\":\"%c\",", map->user?'u':'s');
dbg->cb_printf ("\"perm\":\"%s\"}", r_str_rwx_i (map->perm));
notfirst = R_TRUE;
notfirst = true;
}
dbg->cb_printf ("]\n");
break;
@ -54,30 +58,32 @@ R_API void r_debug_map_list(RDebug *dbg, ut64 addr, int rad) {
break;
default:
fmtstr = dbg->bits& R_SYS_BITS_64?
"sys %04s 0x%016"PFMT64x" %c 0x%016"PFMT64x" %c %s %s\n":
"sys %04s 0x%08"PFMT64x" %c 0x%08"PFMT64x" %c %s %s\n";
"sys %04s 0x%016"PFMT64x" %c 0x%016"PFMT64x" %c %s %s %s\n":
"sys %04s 0x%08"PFMT64x" %c 0x%08"PFMT64x" %c %s %s %s\n";
r_list_foreach (dbg->maps, iter, map) {
r_num_units (buf, map->size);
dbg->cb_printf (fmtstr,
buf, map->addr, (addr>=map->addr && addr<map->addr_end)?'*':'-',
map->addr_end, map->user?'u':'s',
r_str_rwx_i (map->perm), map->name, buf);
r_str_rwx_i (map->perm),
map->file?map->file:"?",
map->name);
}
fmtstr = dbg->bits& R_SYS_BITS_64?
"usr %04s 0x%016"PFMT64x" - 0x%016"PFMT64x" %c %x %s\n":
"usr %04s 0x%08"PFMT64x" - 0x%08"PFMT64x" %c %x %s\n";
"usr %04s 0x%016"PFMT64x" - 0x%016"PFMT64x" %c %x %s %s\n":
"usr %04s 0x%08"PFMT64x" - 0x%08"PFMT64x" %c %x %s %s\n";
r_list_foreach (dbg->maps_user, iter, map) {
r_num_units (buf, map->size);
dbg->cb_printf (fmtstr, buf, map->addr, map->addr_end,
map->user?'u':'s', map->perm, map->name);
map->user?'u':'s', (ut32)map->perm,
map->file?map->file:"?",
map->name);
}
break;
}
}
static void print_debug_map_ascii_art(RList *maps, ut64 addr,
int use_color, PrintfCallback cb_printf,
int bits) {
static void print_debug_map_ascii_art(RList *maps, ut64 addr, int use_color, PrintfCallback cb_printf, int bits) {
ut64 mul, min = -1, max = 0;
int width = r_cons_get_size (NULL) - 80;
RListIter *iter;
@ -127,17 +133,23 @@ static void print_debug_map_ascii_art(RList *maps, ut64 addr,
"| %s0x%08"PFMT64x"%s %s %s\n";
cb_printf (fmtstr, c, map->addr_end, c_end,
r_str_rwx_i (map->perm), map->name);
}
}
}
R_API void r_debug_map_list_visual(RDebug *dbg, ut64 addr, int use_color ) {
if (dbg && dbg->maps) print_debug_map_ascii_art (dbg->maps, addr,
use_color, dbg->cb_printf,
dbg->bits);
if (dbg && dbg->maps_user) print_debug_map_ascii_art (dbg->maps_user,
addr, use_color,
dbg->cb_printf, dbg->bits);
R_API void r_debug_map_list_visual(RDebug *dbg, ut64 addr, int use_color) {
if (dbg) {
if (dbg->maps) {
print_debug_map_ascii_art (dbg->maps, addr,
use_color, dbg->cb_printf,
dbg->bits);
}
if (dbg->maps_user) {
print_debug_map_ascii_art (dbg->maps_user,
addr, use_color,
dbg->cb_printf, dbg->bits);
}
}
}
R_API RDebugMap *r_debug_map_new(char *name, ut64 addr, ut64 addr_end, int perm, int user) {
@ -147,10 +159,9 @@ R_API RDebugMap *r_debug_map_new(char *name, ut64 addr, ut64 addr_end, int perm,
%"PFMT64x">=%"PFMT64x")\n", addr, addr_end);
return NULL;
}
map = R_NEW (RDebugMap);
map = R_NEW0 (RDebugMap);
if (!map) return NULL;
map->name = strdup (name);
map->file = NULL;
map->addr = addr;
map->addr_end = addr_end;
map->size = addr_end-addr;
@ -160,23 +171,21 @@ R_API RDebugMap *r_debug_map_new(char *name, ut64 addr, ut64 addr_end, int perm,
}
R_API RList *r_debug_modules_list(RDebug *dbg) {
if (dbg && dbg->h && dbg->h->modules_get) {
return dbg->h->modules_get (dbg);
}
return NULL;
return (dbg && dbg->h && dbg->h->modules_get)?
dbg->h->modules_get (dbg): NULL;
}
R_API int r_debug_map_sync(RDebug *dbg) {
int ret = R_FALSE;
bool ret = false;
if (dbg && dbg->h && dbg->h->map_get) {
RList *newmaps = dbg->h->map_get (dbg);
if (newmaps) {
r_list_free (dbg->maps);
dbg->maps = newmaps;
ret = R_TRUE;
ret = true;
}
}
return ret;
return (int)ret;
}
R_API RDebugMap* r_debug_map_alloc(RDebug *dbg, ut64 addr, int size) {
@ -188,14 +197,12 @@ R_API RDebugMap* r_debug_map_alloc(RDebug *dbg, ut64 addr, int size) {
}
R_API int r_debug_map_dealloc(RDebug *dbg, RDebugMap *map) {
int ret = R_FALSE;
bool ret = false;
ut64 addr = map->addr;
if (dbg && dbg->h && dbg->h->map_dealloc) {
if (dbg->h->map_dealloc (dbg, addr, map->size)) {
ret = R_TRUE;
}
}
return ret;
if (dbg && dbg->h && dbg->h->map_dealloc)
if (dbg->h->map_dealloc (dbg, addr, map->size))
ret = true;
return (int)ret;
}
R_API RDebugMap *r_debug_map_get(RDebug *dbg, ut64 addr) {
@ -221,4 +228,3 @@ R_API RList *r_debug_map_list_new() {
list->free = (RListFree)r_debug_map_free;
return list;
}

View File

@ -875,7 +875,7 @@ RList *xnu_dbg_maps(RDebug *dbg, int only_modules) {
} else contiguous = false;
//if (info.max_protection == oldprot && !contiguous) {
#endif
if (1) {
if (true) {
#define xwr2rwx(x) ((x&1)<<2) | (x&2) | ((x&4)>>2)
char maxperm[32];
char depthstr[32];
@ -907,7 +907,9 @@ RList *xnu_dbg_maps(RDebug *dbg, int only_modules) {
eprintf ("Cannot create r_debug_map_new\n");
break;
}
mr->file = strdup (module_name);
if (module_name && *module_name) {
mr->file = strdup (module_name);
}
i++;
r_list_append (list, mr);
}

View File

@ -1068,6 +1068,8 @@ R_API const char * r_print_color_op_type ( RPrint *p, ut64 anal_type) {
case R_ANAL_OP_TYPE_ROL:
case R_ANAL_OP_TYPE_ROR:
return p->cons->pal.bin;
case R_ANAL_OP_TYPE_IO:
return p->cons->pal.swi;
case R_ANAL_OP_TYPE_JMP:
case R_ANAL_OP_TYPE_UJMP:
return p->cons->pal.jmp;