Initial integartion of r_bin_dwarf into RCore

This commit is contained in:
pancake 2012-08-14 02:37:42 +02:00
parent 6b991786ab
commit ef8f41eafb
8 changed files with 101 additions and 25 deletions

View File

@ -256,10 +256,32 @@ static int rabin_do_operation(const char *op) {
return R_TRUE;
}
static int rabin_show_dwarf(RCore *core) {
//TODO RBinDwarfLine *lines =
static int rabin_show_dwarf(RCore *core, int rad) {
RBinDwarfRow *row;
RListIter *iter;
RList *list = r_list_new ();
r_bin_dwarf_parse_info (core->bin);
r_bin_dwarf_parse_line (core->bin);
list = r_bin_dwarf_parse_line (core->bin);
r_list_foreach (list, iter, row) {
if (rad) {
// TODO: use 'Cl' instead of CC
const char *path = row->file;
char *line = r_file_slurp_line (
path, row->line, 0);
if (line) {
r_str_filter (line, strlen (line));
r_str_replace (line, "@", ".", 1);
r_str_replace (line, "|", ".", 1);
r_str_replace (line, ";", ".", 1);
}
printf ("CC %s:%d %s @ 0x%"PFMT64x"\n",
row->file, row->line,
line?line:"", row->address);
} else
printf ("%s: %d\n", row->file, row->line);
}
r_list_destroy (list);
return R_TRUE;
}
@ -475,7 +497,7 @@ int main(int argc, char **argv) {
if (action&ACTION_RELOCS)
r_core_bin_info (&core, R_CORE_BIN_ACC_RELOCS, rad, va, NULL, 0);
if (action&ACTION_DWARF)
rabin_show_dwarf (&core);
r_core_bin_info (&core, R_CORE_BIN_ACC_DWARF, rad, va, NULL, 0);
if (action&ACTION_SRCLINE)
rabin_show_srcline (at);
if (action&ACTION_EXTRACT)

View File

@ -8,7 +8,5 @@ case "$1" in
[ ! -e plugins.cfg ] && ./configure-plugins $@
[ -e r2-bindings/configure-langs ] && \
r2-bindings/configure-langs $@
TIP=`git log HEAD^..HEAD|head -n1|cut -d ' ' -f2`
echo
;;
esac

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2012 pancake<nopcode.org> */
/* radare - LGPL - Copyright 2012 - pancake */
#define D0 if(0)
#define D1 if(1)
@ -12,13 +12,22 @@
#define READ(x,y) *((y *)x); x += sizeof (y)
R_API int r_bin_dwarf_parse_line(RBin *a);
R_API RList *r_bin_dwarf_parse_line(RBin *a);
// XXX wtf
R_API int r_bin_dwarf_parse(RBin *bin, int type) {
R_API RList *r_bin_dwarf_parse(RBin *bin, int type) {
return r_bin_dwarf_parse_line (bin);
}
R_API RBinDwarfRow *r_bin_dwarf_line_new (ut64 addr, const char *file, int line) {
RBinDwarfRow *bdl = R_NEW (RBinDwarfRow);
bdl->address = addr;
bdl->file = strdup (file); // use unique pointer
bdl->line = line;
bdl->column = 0;
return bdl;
}
struct Line_Table_File_Entry_s {
ut8 *lte_filename;
ut32 lte_directory_index;
@ -123,7 +132,7 @@ static const ut8 *r_bin_dwarf_parse_header (const ut8 *buf, RBinDwarfInfoHeader
return buf;
}
R_API int r_bin_dwarf_parse_line_raw(const ut8 *obuf) {
R_API int r_bin_dwarf_parse_line_raw(const ut8 *obuf, RList *list) {
RBinDwarfInfoHeader hdr;
ut64 address = 0;
int line = 1;
@ -173,7 +182,9 @@ R_API int r_bin_dwarf_parse_line_raw(const ut8 *obuf) {
address = (ut32) READ (buf, ut32);
}
D0 eprintf ("set address\n");
printf ("0x%08"PFMT64x"\t%s:%d\n", address, hdr.file[0], line);
//eprintf ("0x%08"PFMT64x"\t%s:%d\n", address, hdr.file[0], line);
if (list) r_list_append (list, r_bin_dwarf_line_new (
address, hdr.file[0], line));
break;
default:
eprintf ("Invalid extended opcode %d in dwarf's debug_line\n", opcode);
@ -216,7 +227,9 @@ R_API int r_bin_dwarf_parse_line_raw(const ut8 *obuf) {
address += addr;
line += delt;
eprintf ("0x%08"PFMT64x"\t%s:%d\n", address, hdr.file[0], line);
//eprintf ("0x%08"PFMT64x"\t%s:%d\n", address, hdr.file[0], line);
if (list) r_list_append (list, r_bin_dwarf_line_new (
address, hdr.file[0], line));
D0 {
eprintf ("LINE += %d ADDR += %d\n", delt, addr);
D0 eprintf ("opcode=%d ADJOP %d opadv=%d opidx=%d\n",
@ -308,17 +321,18 @@ R_API int r_bin_dwarf_parse_info(RBin *a) {
return R_FALSE;
}
R_API int r_bin_dwarf_parse_line(RBin *a) {
R_API RList *r_bin_dwarf_parse_line(RBin *a) {
ut8 *buf;
int len, ret;
RBinSection *section = getsection (a, "debug_line");
if (section) {
RList *list = r_list_new ();
len = section->size;
buf = malloc (len);
r_buf_read_at (a->cur.buf, section->offset, buf, len);
ret = r_bin_dwarf_parse_line_raw (buf);
ret = r_bin_dwarf_parse_line_raw (buf, list);
free (buf);
return ret;
return list;
}
return R_FALSE;
return NULL;
}

View File

@ -132,6 +132,41 @@ static int bin_info (RCore *r, int mode) {
return R_TRUE;
}
static int bin_dwarf (RCore *core, int mode) {
RBinDwarfRow *row;
RListIter *iter;
RList *list;
r_bin_dwarf_parse_info (core->bin);
list = r_bin_dwarf_parse_line (core->bin);
if (!list) return R_FALSE;
r_list_foreach (list, iter, row) {
if (mode) {
// TODO: use 'Cl' instead of CC
const char *path = row->file;
char *line = r_file_slurp_line (
path, row->line, 0);
if (line) {
r_str_filter (line, strlen (line));
r_str_replace (line, "@", ".", 1);
r_str_replace (line, "|", ".", 1);
r_str_replace (line, ";", ".", 1);
}
// TODO: implement internal : if ((mode & R_CORE_BIN_SET)) {
if ((mode & R_CORE_BIN_SET)) {
r_core_cmdf (core, "CC %s:%d %s@0x%"PFMT64x"\n",
row->file, row->line, line?line:"", row->address);
} else
r_cons_printf ("CC %s:%d %s@0x%"PFMT64x"\n",
row->file, row->line, line?line:"", row->address);
} else {
r_cons_printf ("%s: %d\n", row->file, row->line);
}
}
r_list_destroy (list);
return R_TRUE;
}
static int bin_main (RCore *r, int mode, ut64 baddr, int va) {
RBinAddr *binmain;
@ -145,7 +180,8 @@ static int bin_main (RCore *r, int mode, ut64 baddr, int va) {
} else {
if (mode) {
r_cons_printf ("fs symbols\n");
r_cons_printf ("f main @ 0x%08"PFMT64x"\n", va? baddr+binmain->rva: binmain->offset);
r_cons_printf ("f main @ 0x%08"PFMT64x"\n",
va? baddr+binmain->rva: binmain->offset);
} else {
r_cons_printf ("[Main]\n");
r_cons_printf ("addr=0x%08"PFMT64x" off=0x%08"PFMT64x"\n",
@ -181,7 +217,8 @@ static int bin_entry (RCore *r, int mode, ut64 baddr, int va) {
r_list_foreach (entries, iter, entry) {
if (mode) {
r_cons_printf ("f entry%i @ 0x%08"PFMT64x"\n", i, va?baddr+entry->rva:entry->offset);
r_cons_printf ("f entry%i @ 0x%08"PFMT64x"\n",
i, va?baddr+entry->rva:entry->offset);
r_cons_printf ("s entry%i\n", i);
} else r_cons_printf ("addr=0x%08"PFMT64x" off=0x%08"PFMT64x" baddr=0x%08"PFMT64x"\n",
baddr+entry->rva, entry->offset, baddr);
@ -555,6 +592,8 @@ R_API int r_core_bin_info (RCore *core, int action, int mode, int va, RCoreBinFi
ret &= bin_info (core, mode);
if ((action & R_CORE_BIN_ACC_MAIN))
ret &= bin_main (core, mode, baddr, va);
if ((action & R_CORE_BIN_ACC_DWARF))
ret &= bin_dwarf (core, mode);
if ((action & R_CORE_BIN_ACC_ENTRIES))
ret &= bin_entry (core, mode, baddr, va);
if ((action & R_CORE_BIN_ACC_RELOCS))

View File

@ -12,6 +12,9 @@ static int cmd_info(void *data, const char *input) {
case 's':
r_core_bin_info (core, R_CORE_BIN_ACC_SYMBOLS, mode, va, NULL, offset);
break;
case 'd':
r_core_bin_info (core, R_CORE_BIN_ACC_DWARF, mode, va, NULL, offset);
break;
case 'i':
r_core_bin_info (core, R_CORE_BIN_ACC_IMPORTS, mode, va, NULL, offset);
break;

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2008-2012 nibble<.ds@gmail.com>, pancake <nopcode.org> */
/* radare - LGPL - Copyright 2008-2012 nibble, pancake */
#ifndef _INCLUDE_R_BIN_H_
#define _INCLUDE_R_BIN_H_
@ -281,7 +281,7 @@ R_API ut64 r_bin_wr_scn_resize(RBin *bin, const char *name, ut64 size);
R_API int r_bin_wr_rpath_del(RBin *bin);
R_API int r_bin_wr_output(RBin *bin, const char *filename);
R_API int r_bin_dwarf_parse_info(RBin *a);
R_API int r_bin_dwarf_parse_line(RBin *a);
R_API RList *r_bin_dwarf_parse_line(RBin *a);
/* plugin pointers */
extern RBinPlugin r_bin_plugin_any;

View File

@ -143,5 +143,4 @@ typedef struct {
unsigned int column;
} RBinDwarfRow;
#endif

View File

@ -236,17 +236,18 @@ R_API void r_core_sysenv_help();
#define R_CORE_BIN_SET 0x002
#define R_CORE_BIN_ACC_STRINGS 0x001
#define R_CORE_BIN_ACC_INFO 0x002
#define R_CORE_BIN_ACC_MAIN 0x004
#define R_CORE_BIN_ACC_INFO 0x002
#define R_CORE_BIN_ACC_MAIN 0x004
#define R_CORE_BIN_ACC_ENTRIES 0x008
#define R_CORE_BIN_ACC_RELOCS 0x010
#define R_CORE_BIN_ACC_IMPORTS 0x020
#define R_CORE_BIN_ACC_SYMBOLS 0x040
#define R_CORE_BIN_ACC_SECTIONS 0x080
#define R_CORE_BIN_ACC_FIELDS 0x100
#define R_CORE_BIN_ACC_LIBS 0x200
#define R_CORE_BIN_ACC_LIBS 0x200
#define R_CORE_BIN_ACC_CLASSES 0x400
#define R_CORE_BIN_ACC_ALL 0xFFF
#define R_CORE_BIN_ACC_DWARF 0x800
#define R_CORE_BIN_ACC_ALL 0xFFF
typedef struct r_core_bin_filter_t {
ut64 offset;