* Some optimizations in r_anal
- bb's are included in fcn struct - analyze bb's and fcn's all together * Update some vapis * Fix build
This commit is contained in:
parent
9c8aa28a9a
commit
1d83a7ba25
|
@ -1,5 +1,5 @@
|
|||
BIN=rafind2
|
||||
BINDEPS=r_search r_io r_print r_lib r_asm r_anal r_reg r_cons r_util
|
||||
BINDEPS=r_search r_io r_print r_lib r_asm r_anal r_reg r_cons r_util r_syscall
|
||||
BINDEPS+=r_socket
|
||||
|
||||
include ../binr.mk
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
BIN=ranal2
|
||||
BINDEPS=r_anal r_lib r_reg r_util
|
||||
BINDEPS=r_anal r_lib r_reg r_util r_syscall
|
||||
|
||||
include ../binr.mk
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
include ../../config.mk
|
||||
|
||||
CFLAGS+=-I ../arch -I../../include -D__UNIX__=1
|
||||
LDFLAGS=-L../../util -lr_util -L../../anal -lr_anal -L../../reg -lr_reg
|
||||
LDFLAGS=-L../../util -lr_util -L../../anal -lr_anal -L../../reg -lr_reg -L../../syscall -lr_syscall
|
||||
|
||||
all: test_meta${EXT_EXE} test_x86im${EXT_EXE}
|
||||
|
||||
|
|
|
@ -63,56 +63,49 @@ static char *r_core_anal_graph_label(RCore *core, struct r_anal_bb_t *bb, int op
|
|||
return str;
|
||||
}
|
||||
|
||||
static void r_core_anal_graph_nodes(RCore *core, RList *pbb, ut64 addr, int opts) {
|
||||
struct r_anal_bb_t *bbi, *bbc;
|
||||
RListIter *iter;
|
||||
static void r_core_anal_graph_nodes(RCore *core, RAnalFcn *fcn, RList *pbb, int opts) {
|
||||
struct r_anal_bb_t *bbi, *bbi2, *bbc;
|
||||
RListIter *iter, *iter2;
|
||||
char *str;
|
||||
|
||||
/* In partial graphs test if the bb is already printed */
|
||||
if (pbb)
|
||||
r_list_foreach (pbb, iter, bbi)
|
||||
if (addr == bbi->addr)
|
||||
return;
|
||||
r_list_foreach (fcn->bbs, iter, bbi) {
|
||||
/* In partial graphs test if the bb is already printed */
|
||||
r_list_foreach (pbb, iter2, bbi2)
|
||||
if (bbi2->addr == bbi->addr)
|
||||
continue;
|
||||
bbc = R_NEW (RAnalBlock);
|
||||
if (bbc) {
|
||||
memcpy (bbc, bbi, sizeof (RAnalBlock));
|
||||
/* We don't want to free this refs when the temporary list is destroyed */
|
||||
bbc->aops = NULL;
|
||||
bbc->cond = NULL;
|
||||
bbc->diff = NULL;
|
||||
bbc->fingerprint = NULL;
|
||||
r_list_append (pbb, bbc);
|
||||
}
|
||||
|
||||
r_list_foreach (core->anal->bbs, iter, bbi) {
|
||||
if (addr == 0 || addr == bbi->addr) {
|
||||
if (pbb) { /* Copy BB and append to the list of printed bbs */
|
||||
bbc = R_NEW (RAnalBlock);
|
||||
if (bbc) {
|
||||
memcpy (bbc, bbi, sizeof (RAnalBlock));
|
||||
/* We don't want to free this refs when the temporary list is destroyed */
|
||||
bbc->aops = NULL;
|
||||
bbc->cond = NULL;
|
||||
bbc->diff = NULL;
|
||||
bbc->fingerprint = NULL;
|
||||
r_list_append (pbb, bbc);
|
||||
}
|
||||
}
|
||||
if (bbi->jump != -1) {
|
||||
r_cons_printf ("\t\"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x"\" "
|
||||
"[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, opts);
|
||||
}
|
||||
if (bbi->fail != -1) {
|
||||
r_cons_printf ("\t\"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x"\" "
|
||||
"[color=\"red\"];\n", bbi->addr, bbi->fail);
|
||||
r_cons_flush ();
|
||||
if (addr != 0) r_core_anal_graph_nodes (core, pbb, bbi->fail, opts);
|
||||
}
|
||||
if ((str = r_core_anal_graph_label (core, bbi, opts))) {
|
||||
if (opts & R_CORE_ANAL_GRAPHDIFF) {
|
||||
r_cons_printf (" \"0x%08"PFMT64x"\" [color=\"%s\", label=\"%s\"]\n", bbi->addr,
|
||||
bbi->diff->type==R_ANAL_DIFF_TYPE_MATCH?"lightgray":
|
||||
bbi->diff->type==R_ANAL_DIFF_TYPE_UNMATCH?"yellow":"red",str);
|
||||
} else {
|
||||
r_cons_printf (" \"0x%08"PFMT64x"\" [color=\"%s\", label=\"%s\"]\n", bbi->addr,
|
||||
bbi->traced?"yellow":"lightgray",str);
|
||||
}
|
||||
r_cons_flush ();
|
||||
free (str);
|
||||
if (bbi->jump != -1) {
|
||||
r_cons_printf ("\t\"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x"\" "
|
||||
"[color=\"%s\"];\n", bbi->addr, bbi->jump,
|
||||
bbi->fail != -1 ? "green" : "blue");
|
||||
r_cons_flush ();
|
||||
}
|
||||
if (bbi->fail != -1) {
|
||||
r_cons_printf ("\t\"0x%08"PFMT64x"\" -> \"0x%08"PFMT64x"\" "
|
||||
"[color=\"red\"];\n", bbi->addr, bbi->fail);
|
||||
r_cons_flush ();
|
||||
}
|
||||
if ((str = r_core_anal_graph_label (core, bbi, opts))) {
|
||||
if (opts & R_CORE_ANAL_GRAPHDIFF) {
|
||||
r_cons_printf (" \"0x%08"PFMT64x"\" [color=\"%s\", label=\"%s\"]\n", bbi->addr,
|
||||
bbi->diff->type==R_ANAL_DIFF_TYPE_MATCH?"lightgray":
|
||||
bbi->diff->type==R_ANAL_DIFF_TYPE_UNMATCH?"yellow":"red",str);
|
||||
} else {
|
||||
r_cons_printf (" \"0x%08"PFMT64x"\" [color=\"%s\", label=\"%s\"]\n", bbi->addr,
|
||||
bbi->traced?"yellow":"lightgray",str);
|
||||
}
|
||||
r_cons_flush ();
|
||||
free (str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -467,6 +460,8 @@ R_API int r_core_anal_fcn_list(RCore *core, const char *input, int rad) {
|
|||
}
|
||||
|
||||
R_API int r_core_anal_graph(RCore *core, ut64 addr, int opts) {
|
||||
RAnalFcn *fcni;
|
||||
RListIter *iter;
|
||||
RList *pbb = NULL;
|
||||
int reflines = r_config_get_i (core->config, "asm.lines");
|
||||
int bytes = r_config_get_i (core->config, "asm.bytes");
|
||||
|
@ -480,9 +475,12 @@ R_API int r_core_anal_graph(RCore *core, ut64 addr, int opts) {
|
|||
"\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, opts);
|
||||
if (pbb) r_list_free (pbb);
|
||||
if (!(pbb = r_anal_bb_list_new ()))
|
||||
return R_FALSE;
|
||||
r_list_foreach (core->anal->fcns, iter, fcni)
|
||||
if (addr == 0 || addr == fcni->addr)
|
||||
r_core_anal_graph_nodes (core, fcni, pbb, opts);
|
||||
r_list_free (pbb);
|
||||
r_cons_printf ("}\n");
|
||||
r_cons_flush ();
|
||||
r_config_set_i (core->config, "asm.lines", reflines);
|
||||
|
@ -634,10 +632,12 @@ R_API int r_core_anal_all(RCore *core) {
|
|||
if (!strncmp (symbol->type,"FUNC", 4))
|
||||
r_core_anal_fcn (core, va?baddr+symbol->rva:symbol->offset, -1,
|
||||
R_ANAL_REF_TYPE_NULL, depth);
|
||||
#if 0 /* Done during fcn analysis */
|
||||
/* Analyze Basic blocks */
|
||||
r_list_foreach (core->anal->fcns, iter, fcn)
|
||||
if (fcn->type == R_ANAL_FCN_TYPE_FCN)
|
||||
r_core_anal_bb (core, core->anal->bbs, fcn->addr, depth, R_TRUE);
|
||||
#endif
|
||||
|
||||
return R_TRUE;
|
||||
}
|
||||
|
|
|
@ -2019,7 +2019,7 @@ static int cmd_anal(void *data, const char *input) {
|
|||
} else {
|
||||
int ret, idx;
|
||||
ut8 *buf = core->block;
|
||||
RAnalAop aop;
|
||||
RAnalOp aop;
|
||||
|
||||
for (idx=ret=0; idx<len; idx+=ret) {
|
||||
ret = r_anal_aop (core->anal, &aop,
|
||||
|
|
|
@ -56,6 +56,7 @@ static void gdiff_diff_bb(RAnalFcn *mfcn, RAnalFcn *mfcn2) {
|
|||
RListIter *iter, *iter2;
|
||||
double t, ot;
|
||||
|
||||
mfcn->diff->type = mfcn2->diff->type = R_ANAL_DIFF_TYPE_MATCH;
|
||||
iter = r_list_iterator (mfcn->bbs);
|
||||
while (r_list_iter_next (iter)) {
|
||||
bb = r_list_iter_get (iter);
|
||||
|
@ -84,13 +85,16 @@ static void gdiff_diff_bb(RAnalFcn *mfcn, RAnalFcn *mfcn2) {
|
|||
if (mbb != NULL && mbb2 != NULL) {
|
||||
if (ot == 1)
|
||||
mbb->diff->type = mbb2->diff->type = R_ANAL_DIFF_TYPE_MATCH;
|
||||
else
|
||||
else {
|
||||
mbb->diff->type = mbb2->diff->type = R_ANAL_DIFF_TYPE_UNMATCH;
|
||||
mfcn->diff->type = mfcn2->diff->type = R_ANAL_DIFF_TYPE_UNMATCH;
|
||||
}
|
||||
R_FREE (mbb->fingerprint);
|
||||
R_FREE (mbb2->fingerprint);
|
||||
mbb->diff->addr = mbb2->addr;
|
||||
mbb2->diff->addr = mbb->addr;
|
||||
}
|
||||
} else
|
||||
mfcn->diff->type = mfcn2->diff->type = R_ANAL_DIFF_TYPE_UNMATCH;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,7 +123,7 @@ static void gdiff_diff_fcn(RList *fcns, RList *fcns2) {
|
|||
r_diff_buffers_distance (NULL, fcn->fingerprint, fcn->size,
|
||||
fcn2->fingerprint, fcn2->size, NULL, &t);
|
||||
#if 1
|
||||
eprintf ("FCN NAME: %s - %s => %lli - %lli => %f\n", fcn->name, fcn2->name,
|
||||
eprintf ("FCN NAME (NAME): %s - %s => %lli - %lli => %f\n", fcn->name, fcn2->name,
|
||||
fcn->size, fcn2->size, t);
|
||||
#endif
|
||||
/* Set flag in matched functions */
|
||||
|
@ -231,7 +235,6 @@ R_API int r_core_gdiff(RCore *c, RCore *c2) {
|
|||
fcn->size = concat_fcn_fp (cores[i], fcn);
|
||||
}
|
||||
}
|
||||
|
||||
/* Diff functions */
|
||||
gdiff_diff_fcn (cores[0]->anal->fcns, cores[1]->anal->fcns);
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ include ../../config.mk
|
|||
|
||||
OBJ=main.o
|
||||
BIN=main
|
||||
BINDEPS=r_lib r_debug r_bp r_io r_reg r_cons r_util r_anal r_socket
|
||||
BINDEPS=r_lib r_debug r_bp r_io r_reg r_cons r_util r_anal r_socket r_syscall
|
||||
LIBS+=${DL_LIBS}
|
||||
|
||||
include ../../rules.mk
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
OBJ=rasign2.o
|
||||
BIN=rasign2
|
||||
BINDEPS=r_sign r_util r_anal r_reg
|
||||
BINDEPS=r_sign r_util r_anal r_reg r_syscall
|
||||
|
||||
include ../../rules.mk
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
r_util
|
|
@ -1,6 +1,6 @@
|
|||
/* radare - LGPL - Copyright 2010 pancake<@nopcode.org> */
|
||||
|
||||
[CCode (cheader_filename="r_flags.h", cprefix="r_flag_", lower_case_cprefix="r_flag_")]
|
||||
[CCode (cheader_filename="r_flags.h,r_list.h,r_types_base.h", cprefix="r_flag_", lower_case_cprefix="r_flag_")]
|
||||
namespace Radare {
|
||||
[Compact]
|
||||
[CCode (cname="struct r_flag_item_t", free_function="free")]
|
||||
|
|
Loading…
Reference in New Issue