mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-25 16:51:30 +00:00
Optimize radiff2 -g off1,off2
- Less than one sec now versus more than 15 before - Code is cleaner (no more "r_core_cmdf") - Colours are now correct - Fix `radiff2 -C`
This commit is contained in:
parent
0be1fc041b
commit
9f18c219a6
@ -203,20 +203,21 @@ int main(int argc, char **argv) {
|
||||
if (mode == MODE_GRAPH) {
|
||||
const char* second = strstr (addr, ",");
|
||||
if (!second) {
|
||||
r_core_gdiff (c, c2);
|
||||
r_core_gdiff (c, c2, R_TRUE);
|
||||
r_core_cmdf (c, "agd %s", addr);
|
||||
} else {
|
||||
// define the same function at each offsets and diff them
|
||||
r_flag_set(c->flags, "diffing_offset",
|
||||
strtoull(addr, 0, 16), 1, R_FALSE);
|
||||
r_flag_set(c2->flags, "diffing_offset",
|
||||
strtoull(second, 0, 16), 1, R_FALSE);
|
||||
r_core_cmdf (c, "af @ diffing_offset");
|
||||
r_core_cmdf (c2, "af @ diffing_offset");
|
||||
r_core_gdiff (c, c2);
|
||||
r_core_cmdf (c, "agd diffing_offset");
|
||||
const ut64 off = strtoull(addr, 0, 16);
|
||||
// define the same function at each offsets
|
||||
r_core_anal_fcn (c, off, UT64_MAX, R_ANAL_REF_TYPE_NULL, 0);
|
||||
r_core_anal_fcn (c2, strtoull (second+1, 0, 16),
|
||||
UT64_MAX, R_ANAL_REF_TYPE_NULL, 0);
|
||||
r_core_gdiff (c, c2, R_FALSE); // Compute the diff
|
||||
r_core_anal_graph (c, off, R_CORE_ANAL_GRAPHBODY|R_CORE_ANAL_GRAPHDIFF);
|
||||
}
|
||||
} else r_core_diff_show (c, c2);
|
||||
} else {
|
||||
r_core_gdiff (c, c2, R_TRUE);
|
||||
r_core_diff_show (c, c2);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ R_API void r_anal_diff_setup_i(RAnal *anal, int doops, int thbb, int thfcn) {
|
||||
anal->diff_thfcn = (thfcn>=0)? ((double)thfcn)/100: R_ANAL_THRESHOLDFCN;
|
||||
}
|
||||
|
||||
// Fingerprint function basic block
|
||||
R_API int r_anal_diff_fingerprint_bb(RAnal *anal, RAnalBlock *bb) {
|
||||
RAnalOp *op;
|
||||
ut8 *buf;
|
||||
@ -52,16 +53,15 @@ R_API int r_anal_diff_fingerprint_bb(RAnal *anal, RAnalBlock *bb) {
|
||||
return R_FALSE;
|
||||
if (!(buf = malloc (1+bb->size))) {
|
||||
free (bb->fingerprint);
|
||||
return 0;
|
||||
return R_FALSE;
|
||||
}
|
||||
if (anal->iob.read_at (anal->iob.io, bb->addr, buf, bb->size) == bb->size) {
|
||||
memcpy (bb->fingerprint, buf, bb->size);
|
||||
/* diff using only the opcode */
|
||||
if (anal->diff_ops) {
|
||||
if (anal->diff_ops) { // diff using only the opcode
|
||||
if (!(op = r_anal_op_new ())) {
|
||||
free (bb->fingerprint);
|
||||
free (buf);
|
||||
return 0;
|
||||
return R_FALSE;
|
||||
}
|
||||
while (idx < bb->size) {
|
||||
if ((oplen = r_anal_op (anal, op, 0, buf+idx, bb->size-idx)) <1)
|
||||
|
@ -381,7 +381,7 @@ static int cmd_cmp(void *data, const char *input) {
|
||||
|
||||
r_core_bin_load (core2, file2,
|
||||
r_config_get_i (core->config, "bin.baddr"));
|
||||
r_core_gdiff (core, core2);
|
||||
r_core_gdiff (core, core2, 1);
|
||||
r_core_diff_show (core, core2);
|
||||
r_core_free (core2);
|
||||
}
|
||||
|
@ -7,7 +7,9 @@
|
||||
#include <r_util.h>
|
||||
#include <r_core.h>
|
||||
|
||||
R_API int r_core_gdiff(RCore *c, RCore *c2) {
|
||||
/* Fingerprint functions and blocs, then diff.
|
||||
* If `anal_all` is true, analyse the whole binary before */
|
||||
R_API int r_core_gdiff(RCore *c, RCore *c2, int anal_all) {
|
||||
RCore *cores[2] = {c, c2};
|
||||
RAnalFunction *fcn;
|
||||
RAnalBlock *bb;
|
||||
@ -15,8 +17,9 @@ R_API int r_core_gdiff(RCore *c, RCore *c2) {
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
r_core_anal_all (cores[i]);
|
||||
/* Fingerprint fcn bbs */
|
||||
if (anal_all)
|
||||
r_core_anal_all (cores[i]);
|
||||
/* Fingerprint fcn bbs (functions basic-blocs) */
|
||||
r_list_foreach (cores[i]->anal->fcns, iter, fcn) {
|
||||
r_list_foreach (fcn->bbs, iter2, bb) {
|
||||
r_anal_diff_fingerprint_bb (cores[i]->anal, bb);
|
||||
|
@ -336,7 +336,7 @@ R_API int r_core_bin_delete (RCore *core, ut32 binfile_idx, ut32 binobj_idx);
|
||||
R_API int r_core_bin_refresh_strings(RCore *core);
|
||||
|
||||
/* gdiff.c */
|
||||
R_API int r_core_gdiff(RCore *core1, RCore *core2);
|
||||
R_API int r_core_gdiff(RCore *core1, RCore *core2, int anal_all);
|
||||
|
||||
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…
x
Reference in New Issue
Block a user