Fix #7108 - Implement anal.fcnprefix

This commit is contained in:
pancake 2017-03-24 10:46:13 +01:00
parent 4ceb55fa86
commit 55f1c0b4dd
7 changed files with 84 additions and 58 deletions

View File

@ -231,8 +231,12 @@ static void printBasicBlocks(AbbState *abb, ut64 fcnaddr, ut64 addr) {
}
}
static void printFunction(ut64 addr, const char *name) {
char *_name = name? (char *) name: r_str_newf ("fcn.%" PFMT64x, addr);
static void printFunction(RCore *core, ut64 addr, const char *name) {
const char *pfx = r_config_get (core->config, "anal.fcnprefix");
if (!pfx) {
pfx = "fcn";
}
char *_name = name? (char *) name: r_str_newf ("%s.%" PFMT64x, pfx, addr);
r_cons_printf ("af+ 0x%08" PFMT64x " %s\n", addr, _name);
if (!name) {
free (_name);
@ -247,7 +251,7 @@ static void findFunctions(RCore *core, AbbState *abb) {
AbbAddr *a;
eprintf ("Found %d functions\n", r_list_length (abb->fcnents));
r_list_foreach (abb->fcnents, iter, a) {
printFunction (a->addr, NULL); //a->name);
printFunction (core, a->addr, NULL); //a->name);
printBasicBlocks (abb, a->addr, a->addr);
}
RAnalBlock *bb;
@ -255,10 +259,10 @@ static void findFunctions(RCore *core, AbbState *abb) {
// if there's a flag, consider it a function
RFlagItem *fi = r_flag_get_i (core->flags, bb->addr);
if (fi) {
printFunction (bb->addr, fi->name);
printFunction (core, bb->addr, fi->name);
} else {
// eprintf ("# orphan bb 0x%08"PFMT64x"\n", bb->addr);
printFunction (bb->addr, NULL);
printFunction (core, bb->addr, NULL);
}
printBasicBlocks (abb, bb->addr, bb->addr);
// printFunction (a->addr, a->name);

View File

@ -458,6 +458,10 @@ static int core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int depth
ut64 *next = NULL;
int buflen, fcnlen;
RAnalFunction *fcn = r_anal_fcn_new ();
const char *fcnpfx = r_config_get (core->config, "anal.fcnprefix");
if (!fcnpfx) {
fcnpfx = "fcn";
}
if (!fcn) {
eprintf ("Error: new (fcn)\n");
return false;
@ -476,7 +480,7 @@ static int core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int depth
if (fi && fi->name && strncmp (fi->name, "sect", 4)) {
fcn->name = strdup (fi->name);
} else {
fcn->name = r_str_newf ("fcn.%08"PFMT64x, at);
fcn->name = r_str_newf ("%s.%08"PFMT64x, fcnpfx, at);
}
buf = malloc (core->anal->opt.bb_max_size);
if (!buf) {
@ -553,7 +557,8 @@ static int core_anal_fcn(RCore *core, ut64 at, ut64 from, int reftype, int depth
#endif
fcn->name = strdup (f->name);
} else {
fcn->name = r_str_newf ("fcn.%08"PFMT64x, fcn->addr);
fcn->name = r_str_newf ("%s.%08"PFMT64x, fcnpfx, fcn->addr);
}
}
if (fcnlen == R_ANAL_RET_ERROR ||

View File

@ -1721,6 +1721,7 @@ R_API int r_core_config_init(RCore *core) {
SETI("pdb.extract", 1, "Avoid extract of the pdb file, just download");
/* anal */
SETPREF("anal.fcnprefix", "fcn", "Prefix new function names with this");
SETPREF("anal.a2f", "false", "Use the new WIP analysis algorithm (core/p/a2f), anal.depth ignored atm");
SETICB("anal.gp", 0, (RConfigCallback)&cb_anal_gp, "Set the value of the GP register (MIPS)");
SETCB("anal.limits", "false", (RConfigCallback)&cb_anal_limits, "Restrict analysis to address range [anal.from:anal.to]");

View File

@ -1193,8 +1193,12 @@ static bool setFunctionName(RCore *core, ut64 off, const char *name, bool prefix
if (!core || !name) {
return false;
}
const char *fcnpfx = r_config_get (core->config, "anal.fcnprefix");
if (!fcnpfx) {
fcnpfx = "fcn";
}
if (r_reg_get (core->anal->reg, name, -1)) {
name = r_str_newf ("fcn.%s", name);
name = r_str_newf ("%s.%s", fcnpfx, name);
}
fcn = r_anal_get_fcn_in (core->anal, off,
R_ANAL_FCN_TYPE_FCN | R_ANAL_FCN_TYPE_SYM | R_ANAL_FCN_TYPE_LOC);
@ -1202,7 +1206,7 @@ static bool setFunctionName(RCore *core, ut64 off, const char *name, bool prefix
return false;
}
if (prefix && fcnNeedsPrefix (name)) {
nname = r_str_newf ("fcn.%s", name);
nname = r_str_newf ("%s.%s", fcnpfx, name);
} else {
nname = strdup (name);
}

View File

@ -8,37 +8,46 @@ R_API int r_core_log_list(RCore *core, int n, int nth, char fmt) {
RStrpool *sp = core->log->sp;
char *str = sp->str;
if (fmt=='j') r_cons_printf ("[");
for (i=idx=0; str && *str; i++, id++) {
if ((n&&n<=id)||!n) {
if (fmt == 'j') {
r_cons_printf ("[");
}
for (i = idx = 0; str && *str; i++, id++) {
if ((n && n <= id) || !n) {
switch (fmt) {
case 'j':r_cons_printf ("%s[%d,\"%s\"]",
printed?",":"",id, str); break;
case 't':r_cons_println (str); break;
case '*':r_cons_printf ("\"l %s\"\n", str); break;
case 'j': r_cons_printf ("%s[%d,\"%s\"]",
printed? ",": "", id, str); break;
case 't': r_cons_println (str); break;
case '*': r_cons_printf ("\"l %s\"\n", str); break;
default: r_cons_printf ("%d %s\n", id, str); break;
}
printed++;
if (nth && printed >= nth) break;
if (nth && printed >= nth) {
break;
}
}
str = r_strpool_next (sp, idx);
if (!str) break;
if (!str) {
break;
}
idx = r_strpool_get_index (sp, str);
count++;
}
if (fmt == 'j')
if (fmt == 'j') {
r_cons_printf ("]\n");
}
return count;
}
R_API RCoreLog *r_core_log_new () {
R_API RCoreLog *r_core_log_new() {
RCoreLog *log = R_NEW0 (RCoreLog);
if (!log) return NULL;
if (!log) {
return NULL;
}
r_core_log_init (log);
return log;
}
R_API void r_core_log_init (RCoreLog *log) {
R_API void r_core_log_init(RCoreLog *log) {
log->first = 1;
log->last = 1;
log->sp = r_strpool_new (0);
@ -56,12 +65,15 @@ R_API void r_core_log_add(RCore *core, const char *msg) {
R_API void r_core_log_del(RCore *core, int n) {
int idx;
if (n>0) {
if (n > core->log->last)
if (n > 0) {
if (n > core->log->last) {
n = core->log->last;
idx = n-core->log->first;
if (idx<0) return;
core->log->first += idx+1;
}
idx = n - core->log->first;
if (idx < 0) {
return;
}
core->log->first += idx + 1;
/* s= */ r_strpool_get_i (core->log->sp, idx);
r_strpool_slice (core->log->sp, idx);
} else {

View File

@ -106,15 +106,15 @@ static const char **menus_sub[] = {
// TODO: handle mouse wheel
static int curnode = 0;
#define G(x,y) r_cons_canvas_gotoxy (can, x, y)
#define G(x, y) r_cons_canvas_gotoxy (can, x, y)
#define W(x) r_cons_canvas_write (can, x)
#define B(x,y,w,h) r_cons_canvas_box (can, x,y,w,h,NULL)
#define B1(x,y,w,h) r_cons_canvas_box (can, x,y,w,h,Color_BLUE)
#define B2(x,y,w,h) r_cons_canvas_box (can, x,y,w,h,Color_MAGENTA)
#define L(x,y,x2,y2) r_cons_canvas_line (can, x,y,x2,y2,0)
#define L1(x,y,x2,y2) r_cons_canvas_line (can, x,y,x2,y2,1)
#define L2(x,y,x2,y2) r_cons_canvas_line (can, x,y,x2,y2,2)
#define F(x,y,x2,y2,c) r_cons_canvas_fill (can, x,y,x2,y2,c,0)
#define B(x, y, w, h) r_cons_canvas_box (can, x, y, w, h, NULL)
#define B1(x, y, w, h) r_cons_canvas_box (can, x, y, w, h, Color_BLUE)
#define B2(x, y, w, h) r_cons_canvas_box (can, x, y, w, h, Color_MAGENTA)
#define L(x, y, x2, y2) r_cons_canvas_line (can, x, y, x2, y2, 0)
#define L1(x, y, x2, y2) r_cons_canvas_line (can, x, y, x2, y2, 1)
#define L2(x, y, x2, y2) r_cons_canvas_line (can, x, y, x2, y2, 2)
#define F(x, y, x2, y2, c) r_cons_canvas_fill (can, x, y, x2, y2, c, 0)
static void Panel_print(RConsCanvas *can, Panel *n, int cur) {
char title[128];
@ -128,7 +128,7 @@ static void Panel_print(RConsCanvas *can, Panel *n, int cur) {
F (n->x, n->y, n->w, n->h, ' ');
if (n->type == PANEL_TYPE_FRAME) {
if (cur) {
//F (n->x,n->y, n->w, n->h, '.');
// F (n->x,n->y, n->w, n->h, '.');
snprintf (title, sizeof (title) - 1,
Color_BGREEN "[x] %s"Color_RESET, n->text);
} else {
@ -140,7 +140,7 @@ static void Panel_print(RConsCanvas *can, Panel *n, int cur) {
}
}
(void) G (n->x + 2, n->y + 2);
//if (
// if (
// TODO: only refresh if n->refresh is set
// TODO: temporary crop depending on out of screen offsets
if (n->cmd && *n->cmd) {
@ -150,7 +150,7 @@ static void Panel_print(RConsCanvas *can, Panel *n, int cur) {
delta_y = 0;
}
if (delta_x < 0) {
char white [128];
char white[128];
int idx = -delta_x;
memset (white, ' ', sizeof(white));
if (idx >= sizeof (white)) {
@ -339,7 +339,7 @@ static void addPanelFrame(const char *title, const char *cmd, ut64 addr) {
}
static int bbPanels(RCore *core, Panel **n) {
//panels = NULL;
// panels = NULL;
addPanelFrame ("Symbols", "isq", 0);
addPanelFrame ("Stack", "px 256@r:SP", 0);
addPanelFrame ("Registers", "dr=", 0);
@ -378,7 +378,7 @@ static void r_core_panels_refresh(RCore *core) {
}
panels[menu_pos].y = 1;
free (panels[menu_pos].text);
panels[menu_pos].text = calloc (1, 1024); //r_str_newf ("%d", menu_y);
panels[menu_pos].text = calloc (1, 1024); // r_str_newf ("%d", menu_y);
int maxsub = 0;
for (i = 0; menus_sub[i]; i++) {
maxsub = i;
@ -443,7 +443,7 @@ static void r_core_panels_refresh(RCore *core) {
}
static void reloadPanels(RCore *core) {
//W("HELLO WORLD");
// W("HELLO WORLD");
Layout_run (panels);
}
@ -501,9 +501,9 @@ static void panel_continue(RCore *core) {
}
R_API int r_core_visual_panels(RCore *core) {
#define OS_INIT() ostack.size = 0; ostack.panels[0] = 0;
#define OS_PUSH(x) if (ostack.size < LIMIT) {ostack.panels[++ostack.size] = x;}
#define OS_POP() ((ostack.size > 0)? ostack.panels[--ostack.size]: 0)
#define OS_INIT() ostack.size = 0; ostack.panels[0] = 0;
#define OS_PUSH(x) if (ostack.size < LIMIT) { ostack.panels[++ostack.size] = x; }
#define OS_POP() ((ostack.size > 0)? ostack.panels[--ostack.size]: 0)
int okey, key, wheel;
int w, h;
int asm_comments = 0;
@ -577,7 +577,7 @@ repeat:
case '.':
if (r_config_get_i (core->config, "cfg.debug")) {
r_core_cmd0 (core, "sr PC");
//r_core_seek (core, r_num_math (core->num, "entry0"), 1);
// r_core_seek (core, r_num_math (core->num, "entry0"), 1);
} else {
r_core_cmd0 (core, "s entry0; px");
}
@ -740,18 +740,18 @@ repeat:
} else if (strstr (action, "io.cache")) {
r_core_cmd0 (core, "e!io.cache");
} else if (strstr (action, "Fill")) {
r_cons_enable_mouse (false);
r_cons_enable_mouse (false);
char *s = r_cons_input ("Fill with: ");
r_core_cmdf (core, "wow %s", s);
free (s);
r_cons_enable_mouse (true);
r_cons_enable_mouse (true);
} else if (strstr (action, "References")) {
r_core_cmdf (core, "aar");
} else if (strstr (action, "FcnInfo")) {
addPanelFrame ("FcnInfo", "afi", 0);
} else if (strstr (action, "Graph")) {
r_core_visual_graph (core, NULL, NULL, true);
// addPanelFrame ("Graph", "agf", 0);
// addPanelFrame ("Graph", "agf", 0);
} else if (strstr (action, "System Shell")) {
r_cons_set_raw (0);
r_cons_flush ();
@ -811,14 +811,14 @@ repeat:
break;
case 's':
if (r_config_get_i (core->config, "cfg.debug")) {
r_core_cmd0 (core, "ds;.dr*"); //;sr PC");
r_core_cmd0 (core, "ds;.dr*"); // ;sr PC");
} else {
panel_single_step_in (core);
}
break;
case 'S':
if (r_config_get_i (core->config, "cfg.debug")) {
r_core_cmd0 (core, "dso;.dr*"); //;sr PC");
r_core_cmd0 (core, "dso;.dr*"); // ;sr PC");
} else {
panel_single_step_over (core);
}
@ -829,10 +829,10 @@ repeat:
core->vmode = true;
break;
case 'C':
can->color = !can->color; //WTF
//r_config_toggle (core->config, "scr.color");
can->color = !can->color; // WTF
// r_config_toggle (core->config, "scr.color");
// refresh graph
// reloadPanels (core);
// reloadPanels (core);
break;
case 'R':
if (r_config_get_i (core->config, "scr.randpal")) {
@ -1081,8 +1081,8 @@ repeat:
break;
#endif
default:
//eprintf ("Key %d\n", key);
//sleep (1);
// eprintf ("Key %d\n", key);
// sleep (1);
break;
}
goto repeat;

View File

@ -39,7 +39,7 @@ static int perform_mapped_file_yank(RCore *core, ut64 offset, ut64 len, const ch
// after our io op is done
RIODesc *yankfd = NULL;
ut64 fd = core->file? core->file->desc->fd: -1, yank_file_sz = 0,
loadaddr = 0, addr = offset;
loadaddr = 0, addr = offset;
int res = false;
if (filename && *filename) {
@ -106,7 +106,7 @@ static int perform_mapped_file_yank(RCore *core, ut64 offset, ut64 len, const ch
}
R_API int r_core_yank_set(RCore *core, ut64 addr, const ut8 *buf, ut32 len) {
//free (core->yank_buf);
// free (core->yank_buf);
if (buf && len) {
r_buf_set_bytes (core->yank_buf, buf, len);
core->yank_buf->base = addr;
@ -117,7 +117,7 @@ R_API int r_core_yank_set(RCore *core, ut64 addr, const ut8 *buf, ut32 len) {
// Call set and then null terminate the bytes.
R_API int r_core_yank_set_str(RCore *core, ut64 addr, const char *str, ut32 len) {
//free (core->yank_buf);
// free (core->yank_buf);
int res = r_core_yank_set (core, addr, (ut8 *) str, len);
if (res == true) {
core->yank_buf->buf[len - 1] = 0;