Add option to radiff to suppress names

This commit is contained in:
Andrew McDonnell 2014-12-26 11:24:49 +10:30 committed by pancake
parent 581f20d654
commit 841a00e0d1
4 changed files with 23 additions and 4 deletions

View File

@ -15,6 +15,7 @@ static ut32 count = 0;
static int showcount = 0;
static int useva = R_TRUE;
static int delta = 0;
static int showbare = R_FALSE;
static int cb(RDiff *d, void *user, RDiffOp *op) {
int i, rad = (int)(size_t)user;
@ -77,6 +78,7 @@ static int show_help(int v) {
" -c count of changes\n"
" -C graphdiff code (columns: off-A, match-ratio, off-B)\n"
" -d use delta diffing\n"
" -f print bare addresses only (diff.bare=1)\n"
" -g [sym|off1,off2] graph diff of given symbol, or between two offsets\n"
" -O code diffing with opcode bytes only\n"
" -p use physical addressing (io.va=0)\n"
@ -136,7 +138,7 @@ int main(int argc, char **argv) {
int threshold = -1;
double sim;
while ((o = getopt (argc, argv, "a:b:Cpg:Orhcdsvxt:")) != -1) {
while ((o = getopt (argc, argv, "a:b:Cfpg:Orhcdsvxt:")) != -1) {
switch (o) {
case 'a':
arch = optarg;
@ -160,6 +162,9 @@ int main(int argc, char **argv) {
case 'C':
mode = MODE_CODE;
break;
case 'f':
showbare = R_TRUE;
break;
case 'O':
diffops = 1;
break;
@ -209,6 +214,10 @@ int main(int argc, char **argv) {
r_config_set_i (c->config, "asm.bits", bits);
r_config_set_i (c2->config, "asm.bits", bits);
}
if (showbare) {
r_config_set_i (c->config, "diff.bare", showbare);
r_config_set_i (c2->config, "diff.bare", showbare);
}
r_anal_diff_setup_i (c->anal, diffops, threshold, threshold);
r_anal_diff_setup_i (c2->anal, diffops, threshold, threshold);
if (mode == MODE_GRAPH) {

View File

@ -971,6 +971,7 @@ R_API int r_core_config_init(RCore *core) {
/* diff */
SETI("diff.from", 0, "Set source diffing address for px (uses cc command)");
SETI("diff.to", 0, "Set destination diffing address for px (uses cc command)");
SETPREF("diff.bare", "false", "Never show function names in diff output");
/* dir */
SETPREF("dir.magic", R_MAGIC_PATH, "Path to r_magic files");

View File

@ -55,7 +55,13 @@ R_API int r_core_gdiff(RCore *c, RCore *c2, int anal_all) {
}
/* copypasta from radiff2 */
static void diffrow(ut64 addr, const char *name, int maxnamelen, ut64 addr2, const char *name2, const char *match, double dist) {
static void diffrow(ut64 addr, const char *name, int maxnamelen, ut64 addr2, const char *name2, const char *match, double dist, int bare) {
if (bare) {
if (addr2 == UT64_MAX || name2 == NULL)
printf ("0x%016"PFMT64x" |%8s (%f)\n", addr, match, dist);
else printf ("0x%016"PFMT64x" |%8s (%f) | 0x%016"PFMT64x"\n", addr, match, dist, addr2);
return;
}
if (addr2 == UT64_MAX || name2 == NULL)
printf ("%*s 0x%"PFMT64x" |%8s (%f)\n",
maxnamelen, name, addr, match, dist);
@ -70,6 +76,7 @@ R_API void r_core_diff_show(RCore *c, RCore *c2) {
RList *fcns = r_anal_get_fcns (c->anal);
int maxnamelen = 0;
int len;
int bare = r_config_get_i (c->config, "diff.bare") || r_config_get_i (c2->config, "diff.bare");
r_list_foreach (fcns, iter, f) {
if (f->name && (len = strlen(f->name)) > maxnamelen)
maxnamelen = len;
@ -96,7 +103,7 @@ R_API void r_core_diff_show(RCore *c, RCore *c2) {
}
diffrow (f->addr, f->name, maxnamelen,
f->diff->addr, f->diff->name,
match, f->diff->dist);
match, f->diff->dist, bare);
break;
}
}
@ -108,7 +115,7 @@ R_API void r_core_diff_show(RCore *c, RCore *c2) {
if (f->diff->type == R_ANAL_DIFF_TYPE_NULL)
diffrow (f->addr, f->name, maxnamelen,
f->diff->addr, f->diff->name,
"NEW", f->diff->dist);
"NEW", f->diff->dist, bare);
}
}
}

View File

@ -22,6 +22,8 @@ Select register size bits for given arch
Count number of differences.
.It Fl C
Code diffing using graphdiff algorithm. Output columns are: file-a-address, percentatge of most similar function in B file | file-b-address.
.It Fl f
Suppress address names (show only addresses) when code diffing.
.It Fl d
Use delta diffing (slower).
.It Fl g Ar sym | off1,off2