mirror of
https://github.com/radareorg/radare2.git
synced 2024-12-02 10:16:21 +00:00
* r_anal
- Fix aop->addr asignment in plugins * r_core - Add commands 'agl' and 'agfl' that output graphs with meta-data
This commit is contained in:
parent
99533607a0
commit
e834fc9c9b
@ -53,6 +53,7 @@ static int aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr, const ut8 *data, i
|
||||
return 0;
|
||||
|
||||
memset (aop, '\0', sizeof(RAnalysisAop));
|
||||
aop->addr = addr;
|
||||
aop->type = R_ANAL_OP_TYPE_UNK;
|
||||
|
||||
|
||||
|
@ -18,6 +18,7 @@ int aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr, const ut8 *bytes, int len
|
||||
// baddr = -baddr;
|
||||
|
||||
memset (aop, '\0', sizeof (RAnalysisAop));
|
||||
aop->addr = addr;
|
||||
aop->type = R_ANAL_OP_TYPE_NOP;
|
||||
aop->length = 4;
|
||||
|
||||
@ -69,7 +70,6 @@ int aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr, const ut8 *bytes, int len
|
||||
aop->eob = 1;
|
||||
break;
|
||||
}
|
||||
aop->addr = addr;
|
||||
aop->length = 4;
|
||||
return aop->length;
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ static int aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr, const ut8 *data, i
|
||||
ut8 *buf = (ut8*)data;
|
||||
memset(aop, '\0', sizeof(RAnalysisAop));
|
||||
aop->type = R_ANAL_OP_TYPE_UNK;
|
||||
aop->addr = addr;
|
||||
|
||||
switch(buf[0]) {
|
||||
case 0x8a:
|
||||
@ -138,7 +139,6 @@ static int aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr, const ut8 *data, i
|
||||
aop->type = R_ANAL_OP_TYPE_MOV;
|
||||
aop->eob = 0;
|
||||
aop->length = 4;
|
||||
aop->addr = addr;
|
||||
return 4;
|
||||
}
|
||||
break;
|
||||
@ -384,7 +384,6 @@ static int aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr, const ut8 *data, i
|
||||
aop->jump = addr+bo+2; //(unsigned long)((buf+1)+5);
|
||||
aop->fail = addr+2;
|
||||
aop->eob = 1;
|
||||
//aop->addr = addr;
|
||||
//return 2;
|
||||
}
|
||||
break;
|
||||
@ -394,7 +393,6 @@ static int aop(RAnalysis *anal, RAnalysisAop *aop, ut64 addr, const ut8 *data, i
|
||||
|
||||
//if (aop->length == 0)
|
||||
aop->length = dislen((unsigned char *)buf, 64); //instLength(buf, 16, 0);
|
||||
aop->addr = addr;
|
||||
//aop->length = instLength(buf, 16, 0);
|
||||
if (!(aop->jump>>33))
|
||||
aop->jump &= 0xFFFFFFFF; // XXX may break on 64 bits here
|
||||
|
@ -5,12 +5,33 @@
|
||||
#include <r_flags.h>
|
||||
#include <r_core.h>
|
||||
|
||||
static char *r_core_anal_graph_label(struct r_core_t *core, ut64 addr, ut64 size) {
|
||||
char cmd[1024], *cmdstr = NULL, *str = NULL;
|
||||
int i, j;
|
||||
static char *r_core_anal_graph_label(struct r_core_t *core, struct r_anal_bb_t *bb, int lines) {
|
||||
struct r_anal_aop_t *aopi;
|
||||
RListIter *iter;
|
||||
char cmd[1024], file[1024], *cmdstr = NULL, *filestr = NULL, *str = NULL;
|
||||
int i, j, line = 0, oline = 0, idx = 0;
|
||||
|
||||
snprintf (cmd, 1023, "pD %lli @ 0x%08llx", size, addr);
|
||||
if ((cmdstr = r_core_cmd_str(core, cmd))) {
|
||||
if (lines) {
|
||||
r_list_foreach (bb->aops, iter, aopi) {
|
||||
r_bin_meta_get_line (&core->bin, aopi->addr, file, 1023, &line);
|
||||
if (line != 0 && line != oline && strcmp (file, "??")) {
|
||||
filestr = r_file_slurp_line (file, line, 0);
|
||||
if (filestr) {
|
||||
cmdstr = realloc (cmdstr, idx + strlen (filestr) + 3);
|
||||
cmdstr[idx] = 0;
|
||||
strcat (cmdstr, filestr);
|
||||
strcat (cmdstr, "\\l");
|
||||
idx+=strlen (filestr);
|
||||
free (filestr);
|
||||
}
|
||||
}
|
||||
oline = line;
|
||||
}
|
||||
} else {
|
||||
snprintf (cmd, 1023, "pD %lli @ 0x%08llx", bb->size, bb->addr);
|
||||
cmdstr = r_core_cmd_str(core, cmd);
|
||||
}
|
||||
if (cmdstr) {
|
||||
if (!(str = malloc(strlen(cmdstr)*2)))
|
||||
return NULL;
|
||||
for(i=j=0;cmdstr[i];i++,j++) {
|
||||
@ -20,6 +41,10 @@ static char *r_core_anal_graph_label(struct r_core_t *core, ut64 addr, ut64 size
|
||||
for(i++;cmdstr[i]&&cmdstr[i]!='m'&&cmdstr[i]!='H'&&cmdstr[i]!='J';i++);
|
||||
j--;
|
||||
break;
|
||||
case '"':
|
||||
str[j]='\\';
|
||||
str[++j]='"';
|
||||
break;
|
||||
case '\n':
|
||||
case '\r':
|
||||
str[j]='\\';
|
||||
@ -35,7 +60,7 @@ static char *r_core_anal_graph_label(struct r_core_t *core, ut64 addr, ut64 size
|
||||
return str;
|
||||
}
|
||||
|
||||
static void r_core_anal_graph_nodes(struct r_core_t *core, RList *pbb, ut64 addr) {
|
||||
static void r_core_anal_graph_nodes(struct r_core_t *core, RList *pbb, ut64 addr, int lines) {
|
||||
struct r_anal_bb_t *bbi, *bbc;
|
||||
RListIter *iter;
|
||||
char *str;
|
||||
@ -59,14 +84,14 @@ static void r_core_anal_graph_nodes(struct r_core_t *core, RList *pbb, ut64 addr
|
||||
r_cons_printf ("\t\"0x%08llx\" -> \"0x%08llx\" [color=\"%s\"];\n", bbi->addr, bbi->jump,
|
||||
bbi->fail != -1 ? "green" : "blue");
|
||||
r_cons_flush ();
|
||||
if (addr != 0) r_core_anal_graph_nodes (core, pbb, bbi->jump);
|
||||
if (addr != 0) r_core_anal_graph_nodes (core, pbb, bbi->jump, lines);
|
||||
}
|
||||
if (bbi->fail != -1) {
|
||||
r_cons_printf ("\t\"0x%08llx\" -> \"0x%08llx\" [color=\"red\"];\n", bbi->addr, bbi->fail);
|
||||
r_cons_flush ();
|
||||
if (addr != 0) r_core_anal_graph_nodes (core, pbb, bbi->fail);
|
||||
if (addr != 0) r_core_anal_graph_nodes (core, pbb, bbi->fail, lines);
|
||||
}
|
||||
if ((str = r_core_anal_graph_label (core, bbi->addr, bbi->size))) {
|
||||
if ((str = r_core_anal_graph_label (core, bbi, lines))) {
|
||||
r_cons_printf (" \"0x%08llx\" [label=\"%s\"]\n", bbi->addr, str);
|
||||
r_cons_flush ();
|
||||
free(str);
|
||||
@ -318,7 +343,7 @@ R_API int r_core_anal_fcn_list(struct r_core_t *core, int rad) {
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
R_API int r_core_anal_graph(struct r_core_t *core, ut64 addr) {
|
||||
R_API int r_core_anal_graph(struct r_core_t *core, ut64 addr, int lines) {
|
||||
RList *pbb = NULL;
|
||||
int reflines = r_config_get_i(&core->config, "asm.reflines");
|
||||
int bytes = r_config_get_i(&core->config, "asm.bytes");
|
||||
@ -330,7 +355,7 @@ R_API int r_core_anal_graph(struct r_core_t *core, ut64 addr) {
|
||||
r_cons_printf ("\tnode [color=lightgray, style=filled shape=box fontname=\"Courier\" fontsize=\"8\"];\n");
|
||||
r_cons_flush ();
|
||||
if (addr != 0) pbb = r_anal_bb_list_new (); /* In partial graphs define printed bb list */
|
||||
r_core_anal_graph_nodes (core, pbb, addr);
|
||||
r_core_anal_graph_nodes (core, pbb, addr, lines);
|
||||
if (pbb) r_list_destroy (pbb);
|
||||
r_cons_printf ("}\n");
|
||||
r_cons_flush ();
|
||||
@ -339,12 +364,12 @@ R_API int r_core_anal_graph(struct r_core_t *core, ut64 addr) {
|
||||
return R_TRUE;
|
||||
}
|
||||
|
||||
R_API int r_core_anal_graph_fcn(struct r_core_t *core, char *fname) {
|
||||
R_API int r_core_anal_graph_fcn(struct r_core_t *core, char *fname, int lines) {
|
||||
struct r_anal_fcn_t *fcni;
|
||||
RListIter *iter;
|
||||
|
||||
r_list_foreach (core->anal.fcns, iter, fcni)
|
||||
if (!strcmp (fname, fcni->name))
|
||||
return r_core_anal_graph (core, fcni->addr);
|
||||
return r_core_anal_graph (core, fcni->addr, lines);
|
||||
return R_FALSE;
|
||||
}
|
||||
|
@ -1100,10 +1100,13 @@ static int cmd_anal(void *data, const char *input) {
|
||||
break;
|
||||
case 'g':
|
||||
switch (input[1]) {
|
||||
case 'l':
|
||||
r_core_anal_graph (core, r_num_math (&core->num, input+2), R_TRUE);
|
||||
break;
|
||||
case 'f':
|
||||
{
|
||||
char *fname = r_str_word_get_first (input+2);
|
||||
r_core_anal_graph_fcn (core, fname);
|
||||
char *fname = r_str_word_get_first (input+(input[2]=='l'?3:2));
|
||||
r_core_anal_graph_fcn (core, fname, input[2]=='l');
|
||||
free (fname);
|
||||
}
|
||||
break;
|
||||
@ -1111,10 +1114,12 @@ static int cmd_anal(void *data, const char *input) {
|
||||
r_cons_printf (
|
||||
"Usage: ag[?f]\n"
|
||||
" ag [addr] ; Output graphviz code (bb at addr and childs)\n"
|
||||
" agf [fcn name] ; Output graphviz code of function\n");
|
||||
" agl [fcn name] ; Output graphviz code using meta-data\n"
|
||||
" agf [fcn name] ; Output graphviz code of function\n"
|
||||
" agfl [fcn name] ; Output graphviz code of function using meta-data\n");
|
||||
break;
|
||||
default:
|
||||
r_core_anal_graph (core, r_num_math (&core->num, input+2));
|
||||
r_core_anal_graph (core, r_num_math (&core->num, input+2), R_FALSE);
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
|
@ -118,8 +118,8 @@ R_API int r_core_anal_fcn(struct r_core_t *core, ut64 at, ut64 from, int depth);
|
||||
R_API int r_core_anal_fcn_add(struct r_core_t *core, ut64 addr, ut64 size, const char *name);
|
||||
R_API int r_core_anal_fcn_list(struct r_core_t *core, int rad);
|
||||
R_API int r_core_anal_fcn_clean(struct r_core_t *core, ut64 addr);
|
||||
R_API int r_core_anal_graph(struct r_core_t *core, ut64 addr);
|
||||
R_API int r_core_anal_graph_fcn(struct r_core_t *core, char *input);
|
||||
R_API int r_core_anal_graph(struct r_core_t *core, ut64 addr, int lines);
|
||||
R_API int r_core_anal_graph_fcn(struct r_core_t *core, char *input, int lines);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user