Add bbsum metric for zignatures ##sign

This commit is contained in:
pancake 2019-01-10 15:23:16 +01:00 committed by radare
parent ae1b3feb3f
commit d7ff7a97ea
3 changed files with 21 additions and 6 deletions

View File

@ -717,14 +717,14 @@ static void listGraph(RAnal *a, RSignItem *it, int format) {
RSignGraph *graph = it->graph;
if (format == '*') {
a->cb_printf ("za %s g cc=%d nbbs=%d edges=%d ebbs=%d\n",
it->name, graph->cc, graph->nbbs, graph->edges, graph->ebbs);
a->cb_printf ("za %s g cc=%d nbbs=%d edges=%d ebbs=%d bbsum=%d\n",
it->name, graph->cc, graph->nbbs, graph->edges, graph->ebbs, graph->bbsum);
} else if (format == 'j') {
a->cb_printf ("\"graph\":{\"cc\":\"%d\",\"nbbs\":\"%d\",\"edges\":\"%d\",\"ebbs\":\"%d\"},",
graph->cc, graph->nbbs, graph->edges, graph->ebbs);
a->cb_printf ("\"graph\":{\"cc\":%d,\"nbbs\":%d,\"edges\":%d,\"ebbs\":%d,\"bbsum\":%d},",
graph->cc, graph->nbbs, graph->edges, graph->ebbs, graph->bbsum);
} else {
a->cb_printf (" graph: cc=%d nbbs=%d edges=%d ebbs=%d\n",
graph->cc, graph->nbbs, graph->edges, graph->ebbs);
a->cb_printf (" graph: cc=%d nbbs=%d edges=%d ebbs=%d bbsum=%d\n",
graph->cc, graph->nbbs, graph->edges, graph->ebbs, graph->bbsum);
}
}
@ -1227,6 +1227,13 @@ R_API int r_sign_search_update(RAnal *a, RSignSearch *ss, ut64 *at, const ut8 *b
return r_search_update (ss->search, *at, buf, len);
}
// allow ~10% of margin error
static int matchCount(int a, int b) {
int c = a - b;
int m = a / 10;
return R_ABS (c) < m;
}
static bool fcnMetricsCmp(RSignItem *it, RAnalFunction *fcn) {
RSignGraph *graph = it->graph;
int ebbs = -1;
@ -1243,6 +1250,9 @@ static bool fcnMetricsCmp(RSignItem *it, RAnalFunction *fcn) {
if (graph->ebbs != -1 && graph->ebbs != ebbs) {
return false;
}
if (graph->bbsum > 0 && matchCount (graph->bbsum, r_anal_fcn_size (fcn))) {
return false;
}
return true;
}

View File

@ -122,6 +122,7 @@ static bool addFcnGraph(RCore *core, RAnalFunction *fcn, const char *name) {
};
// XXX ebbs doesnt gets initialized if calling this from inside the struct
graph.edges = r_anal_fcn_count_edges (fcn, &graph.ebbs);
graph.bbsum = r_anal_fcn_size (fcn);
return r_sign_add_graph (core->anal, name, graph);
}
@ -176,6 +177,7 @@ static bool parseGraphMetrics(const char *args0, int nargs, RSignGraph *graph) {
graph->nbbs = -1;
graph->edges = -1;
graph->ebbs = -1;
graph->bbsum = 0;
for (i = 0; i < nargs; i++) {
ptr = r_str_word_get0 (args0, i);
@ -187,6 +189,8 @@ static bool parseGraphMetrics(const char *args0, int nargs, RSignGraph *graph) {
graph->edges = atoi (ptr + 6);
} else if (r_str_startswith (ptr, "ebbs=")) {
graph->ebbs = atoi (ptr + 5);
} else if (r_str_startswith (ptr, "bbsum=")) {
graph->bbsum = atoi (ptr + 6);
} else {
return false;
}

View File

@ -32,6 +32,7 @@ typedef struct r_sign_graph_t {
int nbbs;
int edges;
int ebbs;
int bbsum;
} RSignGraph;
typedef struct r_sign_bytes_t {