mirror of
https://github.com/radareorg/radare2.git
synced 2025-02-21 14:50:49 +00:00
Make duplicated zignatures optional via zign.dups + tests ##zignatures
This commit is contained in:
parent
8b0b92ad29
commit
6923af97ef
@ -948,8 +948,10 @@ R_API int r_sign_all_functions(RAnal *a, bool merge) {
|
||||
const RSpace *sp = r_spaces_current (&a->zign_spaces);
|
||||
char *prev_name = NULL;
|
||||
r_cons_break_push (NULL, NULL);
|
||||
RCore *core = a->coreb.core;
|
||||
bool do_mangled = a->coreb.cfggeti (core, "zign.mangled");
|
||||
RCoreBind cb = a->coreb;
|
||||
RCore *core = cb.core;
|
||||
bool do_mangled = cb.cfggeti (core, "zign.mangled");
|
||||
bool zign_dups = cb.cfggeti (core, "zign.dups");
|
||||
r_list_foreach_prev (a->fcns, iter, fcn) {
|
||||
if (r_cons_is_breaked ()) {
|
||||
break;
|
||||
@ -958,14 +960,14 @@ R_API int r_sign_all_functions(RAnal *a, bool merge) {
|
||||
RSignItem *it = NULL;
|
||||
if (merge || !name_exists (a->sdb_zigns, realname, sp)) {
|
||||
it = item_from_func (a, fcn, realname);
|
||||
} else {
|
||||
} else if (zign_dups) {
|
||||
char *name = get_unique_name (a->sdb_zigns, fcn->name, sp);
|
||||
if (name) {
|
||||
it = item_from_func (a, fcn, name);
|
||||
}
|
||||
free (name);
|
||||
free (realname);
|
||||
}
|
||||
free (realname);
|
||||
if (it) {
|
||||
if (prev_name) {
|
||||
it->next = prev_name;
|
||||
|
@ -3869,6 +3869,7 @@ R_API int r_core_config_init(RCore *core) {
|
||||
SETI ("zign.maxsz", 500, "maximum zignature length");
|
||||
SETI ("zign.minsz", 16, "minimum zignature length for matching");
|
||||
SETI ("zign.mincc", 10, "minimum cyclomatic complexity for matching");
|
||||
SETBPREF ("zign.dups", "false", "allow duplicate zignatures");
|
||||
SETBPREF ("zign.graph", "true", "use graph metrics for matching");
|
||||
SETBPREF ("zign.bytes", "true", "use bytes patterns for matching");
|
||||
SETBPREF ("zign.offset", "false", "use original offset for matching");
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <r_core.h>
|
||||
#include <r_anal.h>
|
||||
#include <r_sign.h>
|
||||
|
||||
@ -116,8 +117,32 @@ static bool test_anal_sign_get_set(void) {
|
||||
mu_end;
|
||||
}
|
||||
|
||||
bool test_anal_sign_avoid_dup_functions(void) {
|
||||
RCore *core = r_core_new ();
|
||||
|
||||
RAnalFunction *fcn1 = r_anal_create_function (core->anal, "fcn1", 0x2137, 0, NULL);
|
||||
RAnalBlock *first_block = r_anal_create_block (core->anal, 0x2137, 13);
|
||||
r_anal_function_add_block (fcn1, first_block);
|
||||
|
||||
RAnalFunction *fcn2 = r_anal_create_function (core->anal, "fcn2", 0xdeadbeef, 0, NULL);
|
||||
RAnalBlock *second_block = r_anal_create_block (core->anal, 0xdeadbeef, 31);
|
||||
r_anal_function_add_block (fcn2, second_block);
|
||||
|
||||
r_core_cmd0 (core, "aF"); // find functions
|
||||
|
||||
int count = r_sign_all_functions (core->anal, false); // "zg"
|
||||
mu_assert_eq (count, 2, "Should create 2 new zignatures for the unseen functions");
|
||||
|
||||
count = r_sign_all_functions (core->anal, false);
|
||||
mu_assert_eq (count, 0, "Should not create new zignatures for the same functions");
|
||||
|
||||
r_core_free (core);
|
||||
mu_end;
|
||||
}
|
||||
|
||||
int all_tests(void) {
|
||||
mu_run_test (test_anal_sign_get_set);
|
||||
mu_run_test (test_anal_sign_avoid_dup_functions);
|
||||
return tests_passed != tests_run;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user