Fix false positive string ref spotted as write ##analysis

This commit is contained in:
pancake 2024-11-14 16:56:41 +01:00 committed by pancake
parent e6f1a82c56
commit 19ffa9b387
3 changed files with 23 additions and 29 deletions

View File

@ -340,9 +340,6 @@ static void r_anal_xrefs_list_table(RAnal *anal, RVecAnalRef *anal_refs, const c
RAnalRef *ref;
R_VEC_FOREACH (anal_refs, ref) {
int t = R_ANAL_REF_TYPE_MASK (ref->type);
if (!t) {
t = ' ';
}
char *fromname = anal->coreb.getNameDelta (anal->coreb.core, ref->addr);
char *toname = anal->coreb.getNameDelta (anal->coreb.core, ref->at);
r_table_add_rowf (table, "xxnssss",
@ -416,13 +413,9 @@ static void r_anal_xrefs_list_json(RAnal *anal, RVecAnalRef *anal_refs) {
static void r_anal_xrefs_list_hex(RAnal *anal, RVecAnalRef *anal_refs) {
RAnalRef *ref;
R_VEC_FOREACH (anal_refs, ref) {
int t = R_ANAL_REF_TYPE_MASK (ref->type);
if (!t) {
t = ' ';
}
const int t = R_ANAL_REF_TYPE_MASK (ref->type);
// TODO: export/import the read-write-exec information
anal->cb_printf ("ax%c 0x%"PFMT64x" 0x%"PFMT64x"\n", t, ref->addr, ref->at);
anal->cb_printf ("ax%c 0x%"PFMT64x" 0x%"PFMT64x"\n", t? t: ' ', ref->addr, ref->at);
}
}
@ -430,9 +423,6 @@ static void r_anal_xrefs_list_mapping(RAnal *anal, RVecAnalRef *anal_refs) {
RAnalRef *ref;
R_VEC_FOREACH (anal_refs, ref) {
RAnalRefType t = R_ANAL_REF_TYPE_MASK (ref->type);
if (!t) {
t = ' ';
}
anal->cb_printf ("0x%08"PFMT64x" -> 0x%08"PFMT64x" %s:%s\n", ref->at, ref->addr,
r_anal_ref_type_tostring (t), r_anal_ref_perm_tostring (ref));
}
@ -495,6 +485,7 @@ R_API void r_anal_xrefs_list(RAnal *anal, int rad, const char *arg) {
break;
case '\0':
r_anal_xrefs_list_plaintext (anal, anal_refs);
break;
default:
R_LOG_DEBUG ("Unsupported xrefs list format: %c", rad);
break;
@ -574,6 +565,8 @@ R_API char r_anal_ref_perm_tochar(RAnalRef *ref) {
return 'x';
}
switch (R_ANAL_REF_TYPE_MASK (ref->type)) {
case R_ANAL_REF_TYPE_STRN:
return 'r';
case R_ANAL_REF_TYPE_CODE:
case R_ANAL_REF_TYPE_CALL:
case R_ANAL_REF_TYPE_JUMP:
@ -583,7 +576,7 @@ R_API char r_anal_ref_perm_tochar(RAnalRef *ref) {
}
R_API const char *r_anal_ref_perm_tostring(RAnalRef *ref) {
int perm = R_ANAL_REF_TYPE_PERM (ref->type);
ut32 perm = R_ANAL_REF_TYPE_PERM (ref->type);
if (!perm) {
switch (R_ANAL_REF_TYPE_MASK (ref->type)) {
case R_ANAL_REF_TYPE_CODE:
@ -612,7 +605,6 @@ R_API int r_anal_ref_size(RAnalRef *ref) {
R_API const char *r_anal_ref_type_tostring(RAnalRefType type) {
switch (R_ANAL_REF_TYPE_MASK (type)) {
case ' ':
case R_ANAL_REF_TYPE_NULL:
return "NULL";
case R_ANAL_REF_TYPE_ICOD:
@ -628,11 +620,12 @@ R_API const char *r_anal_ref_type_tostring(RAnalRefType type) {
case R_ANAL_REF_TYPE_STRN:
return "STRN";
default:
// R_LOG_ERROR("Invalid unknown ref type %c", R_ANAL_REF_TYPE_MASK (type));
// R_LOG_ERROR ("Invalid unknown ref type %c", R_ANAL_REF_TYPE_MASK (type));
return "UNKN";
}
}
// UNUSED
R_API RAnalRefType r_anal_xrefs_type_from_string(const char *s) {
RAnalRefType rt = R_ANAL_REF_TYPE_NULL;
if (strchr (s, 'r')) {

View File

@ -727,18 +727,16 @@ static bool check_string_at(RCore *core, ut64 addr) {
static void r_anal_set_stringrefs(RCore *core, RAnalFunction *fcn) {
RVecAnalRef *refs = r_anal_function_get_refs (fcn);
if (!refs) {
return;
}
RAnalRef *ref;
R_VEC_FOREACH (refs, ref) {
const ut32 rt = R_ANAL_REF_TYPE_MASK (ref->type);
if (rt == R_ANAL_REF_TYPE_DATA && check_string_at (core, ref->addr)) {
r_anal_xrefs_set (core->anal, ref->at, ref->addr, R_ANAL_REF_TYPE_STRN | R_ANAL_REF_TYPE_READ);
if (refs) {
RAnalRef *ref;
R_VEC_FOREACH (refs, ref) {
const ut32 rt = R_ANAL_REF_TYPE_MASK (ref->type);
if (rt == R_ANAL_REF_TYPE_DATA && check_string_at (core, ref->addr)) {
r_anal_xrefs_set (core->anal, ref->at, ref->addr, R_ANAL_REF_TYPE_STRN | R_ANAL_REF_TYPE_READ);
}
}
RVecAnalRef_free (refs);
}
RVecAnalRef_free (refs);
}
static bool r_anal_try_get_fcn(RCore *core, RAnalRef *ref, int fcndepth, int refdepth) {
@ -4636,7 +4634,8 @@ static bool found_xref(RCore *core, ut64 at, ut64 xref_to, RAnalRefType type, PJ
return true;
}
ut64 r_anal_perm_to_reftype(int perm) {
static ut64 r_anal_perm_to_reftype(int perm) {
// XXX we have apis in anal/xrefs.c but nothing like this
ut64 refType = 0;
if (perm & 1) refType |= R_ANAL_REF_TYPE_READ;
if (perm & 2) refType |= R_ANAL_REF_TYPE_WRITE;
@ -6159,9 +6158,10 @@ R_API void r_core_anal_esil(RCore *core, const char *str /* len */, const char *
ut64 dst = ESIL->cur;
if ((target && dst == ntarget) || !target) {
if (CHECKREF (dst)) {
int type = core_type_by_addr (core, dst); // R_ANAL_REF_TYPE_DATA;
RAnalRefType ref_type = type == UT64_MAX ? R_ANAL_REF_TYPE_CODE : type;
r_anal_xrefs_set (core->anal, cur, dst, ref_type | R_ANAL_REF_TYPE_WRITE);
int type = core_type_by_addr (core, dst);
RAnalRefType ref_type = (type == -1)? R_ANAL_REF_TYPE_CODE : type;
ref_type |= R_ANAL_REF_TYPE_READ; // maybe ICOD instead of CODE
r_anal_xrefs_set (core->anal, cur, dst, ref_type);
}
}
if (cfg_anal_strings) {

View File

@ -8057,6 +8057,7 @@ R_IPI int core_type_by_addr(RCore *core, ut64 addr) {
}
}
if (!has_flag) {
// XXX assume TYPE_CODE Or TYPE_ICOD or mayb NULL if invalid address?
return -1;
}
return type;