mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-27 15:10:53 +00:00
Minor Fixes for XRefs counting (#16546) ##anal
This commit is contained in:
parent
54617455de
commit
028db9cd62
@ -122,11 +122,13 @@ R_API int r_anal_xrefs_set(RAnal *anal, ut64 from, ut64 to, const RAnalRefType t
|
||||
if (!anal || from == to) {
|
||||
return false;
|
||||
}
|
||||
if (!anal->iob.is_valid_offset (anal->iob.io, from, 0)) {
|
||||
return false;
|
||||
}
|
||||
if (!anal->iob.is_valid_offset (anal->iob.io, to, 0)) {
|
||||
return false;
|
||||
if (anal->iob.is_valid_offset) {
|
||||
if (!anal->iob.is_valid_offset (anal->iob.io, from, 0)) {
|
||||
return false;
|
||||
}
|
||||
if (!anal->iob.is_valid_offset (anal->iob.io, to, 0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
setxref (anal->dict_xrefs, to, from, type);
|
||||
setxref (anal->dict_refs, from, to, type);
|
||||
@ -328,8 +330,15 @@ R_API bool r_anal_xrefs_init(RAnal *anal) {
|
||||
return true;
|
||||
}
|
||||
|
||||
R_API int r_anal_xrefs_count(RAnal *anal) {
|
||||
return anal->dict_xrefs->count;
|
||||
static bool count_cb(void *user, const ut64 k, const void *v) {
|
||||
(*(ut64 *)user) += ((HtUP *)v)->count;
|
||||
return true;
|
||||
}
|
||||
|
||||
R_API ut64 r_anal_xrefs_count(RAnal *anal) {
|
||||
ut64 ret = 0;
|
||||
ht_up_foreach (anal->dict_xrefs, count_cb, &ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static RList *fcn_get_refs(RAnalFunction *fcn, HtUP *ht) {
|
||||
|
@ -1575,7 +1575,7 @@ R_API bool r_anal_function_purity(RAnalFunction *fcn);
|
||||
|
||||
typedef bool (* RAnalRefCmp)(RAnalRef *ref, void *data);
|
||||
R_API RList *r_anal_ref_list_new(void);
|
||||
R_API int r_anal_xrefs_count(RAnal *anal);
|
||||
R_API ut64 r_anal_xrefs_count(RAnal *anal);
|
||||
R_API const char *r_anal_xrefs_type_tostring(RAnalRefType type);
|
||||
R_API RAnalRefType r_anal_xrefs_type(char ch);
|
||||
R_API RList *r_anal_xrefs_get(RAnal *anal, ut64 to);
|
||||
|
@ -5,6 +5,7 @@ if get_option('enable_tests')
|
||||
'anal_block',
|
||||
'anal_function',
|
||||
'anal_hints',
|
||||
'anal_xrefs',
|
||||
'base64',
|
||||
'bin',
|
||||
'bitmap',
|
||||
|
28
test/unit/test_anal_xrefs.c
Normal file
28
test/unit/test_anal_xrefs.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include <r_anal.h>
|
||||
#include "minunit.h"
|
||||
|
||||
bool test_r_anal_xrefs_count() {
|
||||
RAnal *anal = r_anal_new ();
|
||||
|
||||
mu_assert_eq (r_anal_xrefs_count (anal), 0, "xrefs count");
|
||||
|
||||
r_anal_xrefs_set (anal, 0x1337, 42, R_ANAL_REF_TYPE_NULL);
|
||||
r_anal_xrefs_set (anal, 0x1337, 43, R_ANAL_REF_TYPE_CODE);
|
||||
r_anal_xrefs_set (anal, 1234, 43, R_ANAL_REF_TYPE_CALL);
|
||||
r_anal_xrefs_set (anal, 12345, 43, R_ANAL_REF_TYPE_CALL);
|
||||
r_anal_xrefs_set (anal, 4321, 4242, R_ANAL_REF_TYPE_CALL);
|
||||
|
||||
mu_assert_eq (r_anal_xrefs_count (anal), 5, "xrefs count");
|
||||
|
||||
r_anal_free (anal);
|
||||
mu_end;
|
||||
}
|
||||
|
||||
int all_tests() {
|
||||
mu_run_test (test_r_anal_xrefs_count);
|
||||
return tests_passed != tests_run;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
return all_tests();
|
||||
}
|
Loading…
Reference in New Issue
Block a user