* Change gdiff API so it takes 2 core's as args
* Don't output diff info and vars in 'afl' for loc's * More refactoring of gdiff
This commit is contained in:
parent
ea73472ee6
commit
28d0a62430
|
@ -124,21 +124,39 @@ int main(int argc, char **argv) {
|
|||
// break;
|
||||
case MODE_GRAPH:
|
||||
{
|
||||
RCore *core;
|
||||
if (!(core = r_core_new ()))
|
||||
return 1;
|
||||
r_config_set_i (core->config, "io.va", va);
|
||||
if (!r_core_file_open (core, file, 0)) {
|
||||
fprintf (stderr, "Cannot open file '%s'\n", file);
|
||||
RCore *core, *core2;
|
||||
if (!(core = r_core_new ())) {
|
||||
eprintf ("Cannot init main core\n");
|
||||
return 1;
|
||||
}
|
||||
r_core_gdiff (core, file, file2, va);
|
||||
core->anal->split = R_FALSE;
|
||||
core->io->va = va;
|
||||
if (!r_core_file_open (core, file, 0)) {
|
||||
eprintf ("Cannot open main file '%s'\n", file);
|
||||
r_core_free (core);
|
||||
return 1;
|
||||
}
|
||||
if (!(core2 = r_core_new ())) {
|
||||
eprintf ("Cannot init diff core\n");
|
||||
r_core_free (core);
|
||||
return 1;
|
||||
}
|
||||
core2->anal->split = R_FALSE;
|
||||
core2->io->va = va;
|
||||
if (!r_core_file_open (core2, file2, 0)) {
|
||||
eprintf ("Cannot open diff file '%s'\n", file2);
|
||||
r_core_free (core);
|
||||
r_core_free (core2);
|
||||
return 1;
|
||||
}
|
||||
r_core_gdiff (core, core2);
|
||||
if (rad) {
|
||||
r_core_anal_bb_list (core, R_TRUE);
|
||||
r_core_anal_fcn_list (core, NULL, R_TRUE);
|
||||
} else
|
||||
r_core_anal_graph (core, 0, R_CORE_ANAL_GRAPHBODY|R_CORE_ANAL_GRAPHDIFF);
|
||||
r_core_free (core);
|
||||
r_core_free (core2);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -409,9 +409,10 @@ R_API int r_core_anal_fcn_list(RCore *core, const char *input, int rad) {
|
|||
fcni->addr, fcni->size, fcni->name);
|
||||
r_cons_printf (" type=%s",
|
||||
fcni->type==R_ANAL_FCN_TYPE_LOC?"loc":"fcn");
|
||||
r_cons_printf (" [%s]",
|
||||
fcni->diff->type==R_ANAL_DIFF_TYPE_MATCH?"MATCH":
|
||||
fcni->diff->type==R_ANAL_DIFF_TYPE_UNMATCH?"UNMATCH":"NEW");
|
||||
if (fcni->type==R_ANAL_FCN_TYPE_FCN)
|
||||
r_cons_printf (" [%s]",
|
||||
fcni->diff->type==R_ANAL_DIFF_TYPE_MATCH?"MATCH":
|
||||
fcni->diff->type==R_ANAL_DIFF_TYPE_UNMATCH?"UNMATCH":"NEW");
|
||||
|
||||
r_cons_printf ("\n CODE refs: ");
|
||||
r_list_foreach (fcni->refs, iter2, refi)
|
||||
|
@ -437,18 +438,20 @@ R_API int r_core_anal_fcn_list(RCore *core, const char *input, int rad) {
|
|||
if (refi->type == R_ANAL_REF_TYPE_DATA)
|
||||
r_cons_printf ("0x%08"PFMT64x" ", refi->addr);
|
||||
|
||||
r_cons_printf ("\n vars:");
|
||||
r_list_foreach (fcni->vars, iter2, vari)
|
||||
r_cons_printf ("\n %-10s delta=0x%02x type=%s", vari->name,
|
||||
vari->delta, r_anal_var_type_to_str (core->anal, vari->type));
|
||||
r_cons_printf ("\n diff: type=%s",
|
||||
fcni->diff->type==R_ANAL_DIFF_TYPE_MATCH?"match":
|
||||
fcni->diff->type==R_ANAL_DIFF_TYPE_UNMATCH?"unmatch":"new");
|
||||
if (fcni->diff->addr != -1)
|
||||
r_cons_printf (" addr=0x%"PFMT64x, fcni->diff->addr);
|
||||
if (fcni->diff->name != NULL)
|
||||
r_cons_printf (" function=%s",
|
||||
fcni->diff->name);
|
||||
if (fcni->type==R_ANAL_FCN_TYPE_FCN) {
|
||||
r_cons_printf ("\n vars:");
|
||||
r_list_foreach (fcni->vars, iter2, vari)
|
||||
r_cons_printf ("\n %-10s delta=0x%02x type=%s", vari->name,
|
||||
vari->delta, r_anal_var_type_to_str (core->anal, vari->type));
|
||||
r_cons_printf ("\n diff: type=%s",
|
||||
fcni->diff->type==R_ANAL_DIFF_TYPE_MATCH?"match":
|
||||
fcni->diff->type==R_ANAL_DIFF_TYPE_UNMATCH?"unmatch":"new");
|
||||
if (fcni->diff->addr != -1)
|
||||
r_cons_printf (" addr=0x%"PFMT64x, fcni->diff->addr);
|
||||
if (fcni->diff->name != NULL)
|
||||
r_cons_printf (" function=%s",
|
||||
fcni->diff->name);
|
||||
}
|
||||
r_cons_newline ();
|
||||
} else r_cons_printf ("af+ 0x%08"PFMT64x" %"PFMT64d" %s %c %c\n",
|
||||
fcni->addr, fcni->size, fcni->name,
|
||||
|
|
|
@ -1450,7 +1450,24 @@ static int cmd_cmp(void *data, const char *input) {
|
|||
break;
|
||||
#endif
|
||||
case 'g':
|
||||
r_core_gdiff (core, core->file->filename, (char*)r_str_chop_ro (input+1), core->io->va);
|
||||
{
|
||||
RCore *core2;
|
||||
char *file2 = (char*)r_str_chop_ro (input+1);
|
||||
|
||||
if (!(core2 = r_core_new ())) {
|
||||
eprintf ("Cannot init diff core\n");
|
||||
return R_FALSE;
|
||||
}
|
||||
core2->io->va = core->io->va;
|
||||
core2->anal->split = core->anal->split;
|
||||
if (!r_core_file_open (core2, file2, 0)) {
|
||||
eprintf ("Cannot open diff file '%s'\n", file2);
|
||||
r_core_free (core2);
|
||||
return R_FALSE;
|
||||
}
|
||||
r_core_gdiff (core, core2);
|
||||
r_core_free (core2);
|
||||
}
|
||||
break;
|
||||
case '?':
|
||||
r_cons_strcat (
|
||||
|
|
|
@ -71,9 +71,10 @@ static void gdiff_diff_bb(RAnalFcn *mfcn, RAnalFcn *mfcn2, RList *bbs, RList *bb
|
|||
mbb->diff->type = mbb2->diff->type = R_ANAL_DIFF_TYPE_MATCH;
|
||||
else
|
||||
mbb->diff->type = mbb2->diff->type = R_ANAL_DIFF_TYPE_UNMATCH;
|
||||
mbb->diff->addr = mbb2->addr;
|
||||
R_FREE (mbb->fingerprint);
|
||||
R_FREE (mbb2->fingerprint);
|
||||
mbb->diff->addr = mbb2->addr;
|
||||
mbb2->diff->addr = mbb->addr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,86 +131,52 @@ static void gdiff_diff_fcn(RList *fcns, RList *fcns2, RList *bbs, RList *bbs2) {
|
|||
R_FREE (mfcn->fingerprint);
|
||||
R_FREE (mfcn2->fingerprint);
|
||||
mfcn->diff->addr = mfcn2->addr;
|
||||
mfcn2->diff->addr = mfcn->addr;
|
||||
R_FREE (mfcn->diff->name);
|
||||
if (mfcn2->name)
|
||||
mfcn->diff->name = strdup (mfcn2->name);
|
||||
R_FREE (mfcn2->diff->name);
|
||||
if (mfcn->name)
|
||||
mfcn2->diff->name = strdup (mfcn->name);
|
||||
gdiff_diff_bb (mfcn, mfcn2, bbs, bbs2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
R_API int r_core_gdiff(RCore *c, const char *file1, const char *file2, int va) {
|
||||
RCore *core2;
|
||||
R_API int r_core_gdiff(RCore *c, RCore *c2) {
|
||||
RCore *cores[2] = {c, c2};
|
||||
RAnalFcn *fcn;
|
||||
RAnalBlock *bb;
|
||||
RList *fcns[2], *bbs[2];
|
||||
RListIter *iter;
|
||||
ut8 *buf;
|
||||
const char *files[2] = {file1, file2};
|
||||
int i;
|
||||
|
||||
/* Init resources */
|
||||
core2 = r_core_new ();
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
/* Load and analyze bin*/
|
||||
r_config_set_i (core2->config, "io.va", va);
|
||||
if (!r_core_file_open (core2, files[i], 0)) {
|
||||
eprintf ("Cannot open file '%s'\n", files[i]);
|
||||
return R_FALSE;
|
||||
}
|
||||
r_config_set_i (core2->config, "anal.split", 0);
|
||||
r_core_cmd0 (core2, "aa");
|
||||
/* Copy fcn's */
|
||||
fcns[i] = r_list_new ();
|
||||
fcns[i]->free = &r_anal_fcn_free;
|
||||
iter = r_list_iterator (core2->anal->fcns);
|
||||
r_core_anal_all (cores[i]);
|
||||
/* Fingerprint fcn's */
|
||||
iter = r_list_iterator (cores[i]->anal->fcns);
|
||||
while (r_list_iter_next (iter)) {
|
||||
fcn = r_list_iter_get (iter);
|
||||
/* Fingerprint fcn */
|
||||
if ((buf = malloc (fcn->size))) {
|
||||
if (r_io_read_at (core2->io, fcn->addr, buf, fcn->size) == fcn->size)
|
||||
fcn->fingerprint = gdiff_fingerprint (core2->anal, buf, fcn->size);
|
||||
if (r_io_read_at (cores[i]->io, fcn->addr, buf, fcn->size) == fcn->size)
|
||||
fcn->fingerprint = gdiff_fingerprint (cores[i]->anal, buf, fcn->size);
|
||||
free (buf);
|
||||
}
|
||||
r_list_split (core2->anal->fcns, fcn);
|
||||
r_list_append (fcns[i], fcn);
|
||||
}
|
||||
/* Copy bb's */
|
||||
bbs[i] = r_list_new ();
|
||||
bbs[i]->free = &r_anal_bb_free;
|
||||
iter = r_list_iterator (core2->anal->bbs);
|
||||
/* Fingerprint bb's */
|
||||
iter = r_list_iterator (cores[i]->anal->bbs);
|
||||
while (r_list_iter_next (iter)) {
|
||||
bb = r_list_iter_get (iter);
|
||||
/* Fingerprint bb */
|
||||
if ((buf = malloc (bb->size))) {
|
||||
if (r_io_read_at (core2->io, bb->addr, buf, bb->size) == bb->size)
|
||||
bb->fingerprint = gdiff_fingerprint (core2->anal, buf, bb->size);
|
||||
if (r_io_read_at (cores[i]->io, bb->addr, buf, bb->size) == bb->size)
|
||||
bb->fingerprint = gdiff_fingerprint (cores[i]->anal, buf, bb->size);
|
||||
free (buf);
|
||||
}
|
||||
r_list_split (core2->anal->bbs, bb);
|
||||
r_list_append (bbs[i], bb);
|
||||
}
|
||||
/* Remove flags and analysis info */
|
||||
r_core_cmd0 (core2, "af-");
|
||||
r_core_cmd0 (core2, "ab-");
|
||||
r_core_cmd0 (core2, "f-*");
|
||||
}
|
||||
|
||||
/* Diff functions */
|
||||
gdiff_diff_fcn (fcns[0], fcns[1], bbs[0], bbs[1]);
|
||||
|
||||
/* Fill analysis info in core */
|
||||
r_list_foreach (bbs[0], iter, bb)
|
||||
r_anal_bb_add (c->anal, bb->addr, bb->size, bb->jump, bb->fail, bb->type, bb->diff);
|
||||
r_list_foreach (fcns[0], iter, fcn)
|
||||
r_anal_fcn_add (c->anal, fcn->addr, fcn->size, fcn->name, fcn->type, fcn->diff);
|
||||
|
||||
/* Free resources */
|
||||
r_core_free (core2);
|
||||
for (i=0;i<2;i++) {
|
||||
r_list_free (bbs[i]);
|
||||
r_list_free (fcns[i]);
|
||||
}
|
||||
gdiff_diff_fcn (cores[0]->anal->fcns, cores[1]->anal->fcns, cores[0]->anal->bbs, cores[1]->anal->bbs);
|
||||
|
||||
return R_TRUE;
|
||||
}
|
||||
|
|
|
@ -181,7 +181,7 @@ R_API RList *r_core_asm_strsearch(RCore *core, const char *input, ut64 from, ut6
|
|||
R_API RList *r_core_asm_bwdisassemble (RCore *core, ut64 addr, int n, int len);
|
||||
|
||||
/* gdiff.c */
|
||||
R_API int r_core_gdiff(struct r_core_t *core, const char *file1, const char *file2, int va);
|
||||
R_API int r_core_gdiff(RCore *c, RCore *c2);
|
||||
|
||||
R_API int r_core_project_open(RCore *core, const char *file);
|
||||
R_API int r_core_project_save(RCore *core, const char *file);
|
||||
|
|
Loading…
Reference in New Issue