Skip to content

Commit

Permalink
Honor best name in 'afna' when flag starts with "sym." ##analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
radare authored Dec 24, 2024
1 parent 4c13cc9 commit 414f9c9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
20 changes: 18 additions & 2 deletions libr/core/canal.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,15 @@ static char *autoname_slow(RCore *core, RAnalFunction *fcn, int mode) {
pj = r_core_pj_new (core);
pj_a (pj);
}
char *bestname = NULL;
char *fd = r_core_cmd_str_at (core, fcn->addr, "fd");
if (r_str_startswith (fd, "sym.") && !r_str_startswith (fd, "sym.func.")) {
r_str_trim (fd);
r_list_append (names, fd);
bestname = strdup (fd);
} else {
free (fd);
}
// TODO: check if import, if its in plt, by name, by rbin...
int scr_color = r_config_get_i (core->config, "scr.color");
r_config_set_i (core->config, "scr.color", 0);
Expand Down Expand Up @@ -548,7 +557,6 @@ static char *autoname_slow(RCore *core, RAnalFunction *fcn, int mode) {
}
}
free (pdsfq);
char *bestname = NULL;
bool use_getopt = false;
r_list_uniq_inplace (names, cmpstrings);
r_list_foreach (names, iter, name) {
Expand Down Expand Up @@ -594,12 +602,20 @@ static char *autoname_slow(RCore *core, RAnalFunction *fcn, int mode) {
return strdup ("main_args");
}
if (bestname) {
if (r_str_startswith (bestname, "sym.")) {
return bestname;
}
if (r_str_startswith (bestname, "imp.")) {
char *bn = r_str_newf ("sym.%s", bestname);
free (bestname);
return bn;
}
char *ret = r_str_newf ("sub.%s_%"PFMT64x, bestname, fcn->addr);
char *ret;
if (r_str_startswith (bestname, "sub.")) {
ret = r_str_newf ("%s_%"PFMT64x, bestname, fcn->addr);
} else {
ret = r_str_newf ("sub.%s_%"PFMT64x, bestname, fcn->addr);
}
free (bestname);
return ret;
}
Expand Down
12 changes: 6 additions & 6 deletions test/db/anal/autoname
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ EXPECT=<<EOF
0x100003a1c 5 56 sub.strcoll_100003a1c
0x100003a54 5 60 sub.strcoll_100003a54
0x1000047a8 45 688 sub.fts_open_1000047a8
0x100004ab4 13 128 sub.sub.strcoll_100003830_100004ab4
0x100004ab4 13 128 sub.strcoll_100003830_100004ab4
0x100004b34 124 2220 sub.LS_COLWIDTHS_100004b34
0x1000053e0 3 20 sub.err_1000053e0
0x1000053f4 1 16 sym.func.1000053f4
Expand All @@ -148,13 +148,13 @@ EXPECT=<<EOF
0x100005d68 6 156 sub.humanize_number_100005d68
0x100005e04 34 740 sub.nl_langinfo_100005e04
0x100006184 3 32 sub.fcn.100006184_100006184
0x1000060e8 9 140 sub.sub.fcn.100006184_100006184_1000060e8
0x1000060e8 9 140 sub.fcn.100006184_100006184_1000060e8
0x1000061dc 7 180 sub.printf_1000061dc
0x100006290 14 160 sub.putchar_100006290
0x10000636c 13 232 sub.strlen_10000636c
0x100006454 39 828 sub.realloc_100006454
0x100006790 19 408 sub.strlen_100006790
0x100006928 3 72 sub.sub.printf_1000061dc_100006928
0x100006928 3 72 sub.printf_1000061dc_100006928
0x100006970 5 44 sub.nl_langinfo_100006970
0x10000699c 1 52 sub.write_10000699c
0x1000069d0 1 28 sub.putchar_1000069d0
Expand Down Expand Up @@ -283,7 +283,7 @@ EXPECT=<<EOF
0x100003a1c 5 56 sub.strcoll_100003a1c
0x100003a54 5 60 sub.strcoll_100003a54
0x1000047a8 45 688 sub.fts_open_1000047a8
0x100004ab4 13 128 sub.sub.strcoll_100003830_100004ab4
0x100004ab4 13 128 sub.strcoll_100003830_100004ab4
0x100004b34 124 2220 sub.LS_COLWIDTHS_100004b34
0x1000053e0 3 20 sub.err_1000053e0
0x1000053f4 1 16 sym.func.1000053f4
Expand All @@ -294,13 +294,13 @@ EXPECT=<<EOF
0x100005d68 6 156 sub.humanize_number_100005d68
0x100005e04 34 740 sub.nl_langinfo_100005e04
0x100006184 3 32 sub.fcn.100006184_100006184
0x1000060e8 9 140 sub.sub.fcn.100006184_100006184_1000060e8
0x1000060e8 9 140 sub.fcn.100006184_100006184_1000060e8
0x1000061dc 7 180 sub.printf_1000061dc
0x100006290 14 160 sub.putchar_100006290
0x10000636c 13 232 sub.strlen_10000636c
0x100006454 39 828 sub.realloc_100006454
0x100006790 19 408 sub.strlen_100006790
0x100006928 3 72 sub.sub.printf_1000061dc_100006928
0x100006928 3 72 sub.printf_1000061dc_100006928
0x100006970 5 44 sub.nl_langinfo_100006970
0x10000699c 1 52 sub.write_10000699c
0x1000069d0 1 28 sub.putchar_1000069d0
Expand Down

0 comments on commit 414f9c9

Please sign in to comment.