Skip to content

Commit 473664b

Browse files
radaretrufae
authored andcommitted
Little radiff api changes and updated man/help
1 parent 7c550d4 commit 473664b

File tree

5 files changed

+41
-67
lines changed

5 files changed

+41
-67
lines changed

Diff for: libr/anal/diff.c

+4-8
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,16 @@ R_API void r_anal_diff_free(RAnalDiff *diff) {
2323
}
2424
}
2525

26-
R_API void r_anal_diff_setup(RAnal *anal, int doops, double thbb, double thfcn) {
26+
R_API void r_anal_diff_setup(RAnal *anal, bool doops, double thbb, double thfcn) {
2727
R_RETURN_IF_FAIL (anal);
28-
if (doops >= 0) {
29-
anal->diff_ops = doops;
30-
}
28+
anal->diff_ops = doops;
3129
anal->diff_thbb = (thbb >= 0)? thbb: R_ANAL_THRESHOLDBB;
3230
anal->diff_thfcn = (thfcn >= 0)? thfcn: R_ANAL_THRESHOLDFCN;
3331
}
3432

35-
R_API void r_anal_diff_setup_i(RAnal *anal, int doops, int thbb, int thfcn) {
33+
R_API void r_anal_diff_setup_i(RAnal *anal, bool doops, int thbb, int thfcn) {
3634
R_RETURN_IF_FAIL (anal);
37-
if (doops >= 0) {
38-
anal->diff_ops = doops;
39-
}
35+
anal->diff_ops = doops;
4036
anal->diff_thbb = (thbb >= 0)? ((double)thbb) / 100: R_ANAL_THRESHOLDBB;
4137
anal->diff_thfcn = (thfcn >= 0)? ((double)thfcn) / 100: R_ANAL_THRESHOLDFCN;
4238
}

Diff for: libr/include/r_anal.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ typedef struct r_anal_t {
432432
ut8 *last_disasm_reg;
433433
int last_disasm_reg_size;
434434
RSyscall *syscall;
435-
int diff_ops;
435+
bool diff_ops;
436436
double diff_thbb;
437437
double diff_thfcn;
438438
RIOBind iob;
@@ -1202,8 +1202,8 @@ R_API char *r_anal_function_format_sig(R_NONNULL RAnal *anal, R_NONNULL RAnalFun
12021202

12031203
/* diff.c */
12041204
R_API RAnalDiff *r_anal_diff_new(void);
1205-
R_API void r_anal_diff_setup(RAnal *anal, int doops, double thbb, double thfcn);
1206-
R_API void r_anal_diff_setup_i(RAnal *anal, int doops, int thbb, int thfcn);
1205+
R_API void r_anal_diff_setup(RAnal *anal, bool doops, double thbb, double thfcn);
1206+
R_API void r_anal_diff_setup_i(RAnal *anal, bool doops, int thbb, int thfcn);
12071207
R_API void r_anal_diff_free(RAnalDiff *diff);
12081208
R_API int r_anal_diff_fingerprint_bb(RAnal *anal, RAnalBlock *bb);
12091209
R_API size_t r_anal_diff_fingerprint_fcn(RAnal *anal, RAnalFunction *fcn);

Diff for: libr/main/radiff2.c

+27-41
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ typedef struct {
5151
int delta;
5252
bool json_started;
5353
int diffmode;
54-
int diffops;
54+
bool diffops;
5555
int mode;
5656
int gmode;
5757
bool disasm;
@@ -147,7 +147,7 @@ static void readstr(char *s, int sz, const ut8 *buf, int len) {
147147

148148
static int cb(RDiff *d, void *user, RDiffOp *op) {
149149
int i;
150-
RadiffOptions *ro = user;
150+
RadiffOptions *ro = (RadiffOptions*)user;
151151
char s[256] = {0};
152152
if (ro->showcount) {
153153
ro->count++;
@@ -455,9 +455,9 @@ static int show_help(int v) {
455455
" -d use delta diffing\n"
456456
" -D show disasm instead of hexpairs\n"
457457
" -e [k=v] set eval config var value for all RCore instances\n"
458-
" -f [ofmt] select output format (see '-f help' for details)\n"
458+
" -f [help] select output format (see '-f help' for details)\n"
459459
" -g [arg] graph diff of [sym] or functions in [off1,off2]\n"
460-
" -i [what] compare bin information (symbols, strings, classes, ..)\n"
460+
" -i [help] compare bin information (symbols, strings, classes, ..)\n"
461461
" -j output in json format (see -f json)\n"
462462
" -m [mode] choose the graph output mode (aditsjJ)\n"
463463
" -n count of changes\n"
@@ -471,13 +471,10 @@ static int show_help(int v) {
471471
" -t [0-100] set threshold for code diff (default is 70%%)\n"
472472
" -T analyze files in threads (EXPERIMENTAL, 30%% faster and crashy)\n"
473473
" -x show two column hexdump diffing\n"
474-
" -X show two column hexII diffing\n"
475474
" -u unified output (---+++)\n"
476475
" -U unified output using system 'diff'\n"
477476
" -v show version information\n"
478477
" -V be verbose (current only for -s)\n"
479-
" -z diff on extracted strings (see -i)\n"
480-
" -Z diff code comparing zignatures (see -i)\n\n"
481478
);
482479
}
483480
return 1;
@@ -1091,8 +1088,6 @@ static bool select_input_data(RadiffOptions *ro, const char *arg) {
10911088
ch0 = 'i';
10921089
} else if (!strcmp (arg, "classes")) {
10931090
ch0 = 'c';
1094-
} else if (!strcmp (arg, "symbols")) {
1095-
ch0 = 's';
10961091
} else if (!strcmp (arg, "fields")) {
10971092
ch0 = 'f';
10981093
} else if (!strcmp (arg, "methods")) {
@@ -1155,7 +1150,6 @@ static bool select_input_data(RadiffOptions *ro, const char *arg) {
11551150
default:
11561151
return false;
11571152
}
1158-
ro->diffmode = 'U';
11591153
return true;
11601154
}
11611155

@@ -1315,7 +1309,7 @@ R_API int r_main_radiff2(int argc, const char **argv) {
13151309

13161310
radiff_options_init (&ro);
13171311

1318-
r_getopt_init (&opt, argc, argv, "Aa:b:B:CDe:f:npg:m:G:Oi:jrhcdsS:uUvVxXt:TzqZ");
1312+
r_getopt_init (&opt, argc, argv, "Aa:b:B:c:CdDe:f:g:hi:jm:nOprst:TxuUqvV");
13191313
while ((o = r_getopt_next (&opt)) != -1) {
13201314
switch (o) {
13211315
case 'a':
@@ -1361,6 +1355,13 @@ R_API int r_main_radiff2(int argc, const char **argv) {
13611355
return 1;
13621356
}
13631357
break;
1358+
case 'g':
1359+
ro.mode = MODE_GRAPH;
1360+
// ro.pdc = true;
1361+
addr = opt.arg;
1362+
break;
1363+
case 'h':
1364+
return show_help (1);
13641365
case 'i':
13651366
if (!select_input_data (&ro, opt.arg)) {
13661367
R_LOG_ERROR ("Invalid input data selected (see -i help)");
@@ -1371,17 +1372,6 @@ R_API int r_main_radiff2(int argc, const char **argv) {
13711372
ro.diffmode = 'j';
13721373
ro.pj = pj_new ();
13731374
break;
1374-
case 'p':
1375-
ro.useva = false;
1376-
break;
1377-
case 'r':
1378-
ro.diffmode = 'r';
1379-
break;
1380-
case 'g':
1381-
ro.mode = MODE_GRAPH;
1382-
// ro.pdc = true;
1383-
addr = opt.arg;
1384-
break;
13851375
case 'm':
13861376
if (!select_graph_type (&ro, opt.arg)) {
13871377
R_LOG_ERROR ("Invalid input data selected (see -i help)");
@@ -1391,33 +1381,35 @@ R_API int r_main_radiff2(int argc, const char **argv) {
13911381
case 'n':
13921382
ro.showcount = true;
13931383
break;
1394-
case 'O':
1395-
ro.diffops = 1;
1384+
case 'O': // move to options
1385+
ro.diffops = true;
13961386
break;
1397-
case 'T': // imho `t <=> T`
1398-
ro.thready = true;
1399-
// printf ("%s\n", opt.arg);
1387+
case 'p':
1388+
ro.useva = false;
14001389
break;
1401-
case 't':
1402-
ro.threshold = atoi (opt.arg);
1403-
// printf ("%s\n", opt.arg);
1390+
case 'r':
1391+
ro.diffmode = 'r';
14041392
break;
1405-
case 'h':
1406-
return show_help (1);
14071393
case 's':
1394+
// TODO: maybe use -a to select algorithm?
14081395
ro.mode = (ro.mode == MODE_DIST_MYERS)
14091396
? MODE_DIST_LEVENSHTEIN
14101397
: MODE_DIST_MYERS;
14111398
break;
14121399
case 'S':
14131400
columnSort = opt.arg;
14141401
break;
1402+
case 't':
1403+
ro.threshold = atoi (opt.arg);
1404+
// printf ("%s\n", opt.arg);
1405+
break;
1406+
case 'T': // imho `t <=> T`
1407+
ro.thready = true;
1408+
// printf ("%s\n", opt.arg);
1409+
break;
14151410
case 'x':
14161411
ro.mode = MODE_COLS;
14171412
break;
1418-
case 'X':
1419-
ro.mode = MODE_COLSII;
1420-
break;
14211413
case 'u':
14221414
ro.diffmode = 'u';
14231415
break;
@@ -1432,12 +1424,6 @@ R_API int r_main_radiff2(int argc, const char **argv) {
14321424
case 'V':
14331425
ro.verbose = true;
14341426
break;
1435-
case 'z':
1436-
ro.mode = MODE_DIFF_STRS;
1437-
break;
1438-
case 'Z':
1439-
ro.zignatures = true;
1440-
break;
14411427
default:
14421428
return show_help (0);
14431429
}

Diff for: man/radiff2.1

-8
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,6 @@ Be verbose (current only for -s).
9696
.B -x
9797
Show two-column hexdump diffing.
9898
.TP
99-
.B -X
100-
Show two-column hexII diffing.
101-
.TP
102-
.B -z
103-
Diff on extracted strings.
104-
.TP
105-
.B -Z
106-
Diff code comparing zignatures.
10799

108100
.SH "GRAPH OUTPUT FORMATS (-m [mode])"
109101
.TP

Diff for: test/db/tools/radiff2

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
NAME=radiff2 -c
1+
NAME=radiff2 -n
22
FILE=-
3-
CMDS=!radiff2 -c bins/other/radiff2/radiff2_c_1 bins/other/radiff2/radiff2_c_2
3+
CMDS=!radiff2 -n bins/other/radiff2/radiff2_c_1 bins/other/radiff2/radiff2_c_2
44
EXPECT=<<EOF
55
1
66
EOF
@@ -48,15 +48,15 @@ RUN
4848

4949
NAME=radiff2 string comparison
5050
FILE=-
51-
CMDS=!!radiff2 -z bins/elf/elf_one_symbol_shdr bins/elf/elf_one_symbol_shdr1
51+
CMDS=!!radiff2 -iz bins/elf/elf_one_symbol_shdr bins/elf/elf_one_symbol_shdr1
5252
EXPECT=<<EOF
5353
0x00000000 48656c6c => 41414141 0x00000000
5454
EOF
5555
RUN
5656

5757
NAME=radiff2 unified string comparison
5858
FILE=-
59-
CMDS=!!radiff2 -quz bins/elf/elf_one_symbol_shdr bins/elf/elf_one_symbol_shdr1
59+
CMDS=!!radiff2 -qu -iz bins/elf/elf_one_symbol_shdr bins/elf/elf_one_symbol_shdr1
6060
EXPECT=<<EOF
6161
-0x00000000:48 65 6c 6c
6262
+0x00000000:41 41 41 41
@@ -65,7 +65,7 @@ RUN
6565

6666
NAME=radiff2 gnu unified string comparison
6767
FILE=-
68-
CMDS=!!radiff2 -Uz bins/elf/elf_one_symbol_shdr bins/elf/elf_one_symbol_shdr1 | tail -n 2
68+
CMDS=!!radiff2 -U -iz bins/elf/elf_one_symbol_shdr bins/elf/elf_one_symbol_shdr1 | tail -n 2
6969
EXPECT=<<EOF
7070
-Hello world!
7171
+AAAAo world!
@@ -96,9 +96,9 @@ EXPECT=<<EOF
9696
EOF
9797
RUN
9898

99-
NAME=radiff2 -1 (GDIFF support) #1
99+
NAME=radiff2 -f1 (GDIFF support) #1
100100
FILE=-
101-
CMDS=!!radiff2 -1 bins/other/radiff2/radiff2_c_1 bins/other/radiff2/radiff2_c_2 | rax2 -S
101+
CMDS=!!radiff2 -f1 bins/other/radiff2/radiff2_c_1 bins/other/radiff2/radiff2_c_2 | rax2 -S
102102
EXPECT=<<EOF
103103
d1ffd1ff04019000
104104
EOF

0 commit comments

Comments
 (0)