dewolf
dewolf copied to clipboard
[Array access detection] Consider address-of operation as a valid base candidate
Proposal
Currently, we consider expressions *(base+offset)
as an array element access base[offset/type_size]
if the base
variable has type Pointer
and offset
satisfies valid offset requirements.
For instance, here:
void func(long * arr, size_t size){
for (int i=0; i<size; ++i)
*(arr + 8*i) = ...;
...
}
we recognize *(arr+8*i)
as arr[i]
.
However, we do not recognize &STUDENTS[var_2]
here:
gradebook.zip
$ python decompile.py gradebook add_student
extern void STUDENTS = 0;
...
*(var_2 * 8 + &STUDENTS) = var_4;
...
Here address
-operation (or reference) (&STUDENTS
) is not recognized as valid base (pointer to the first element), as it is not a variable of type Pointer
.
Since reference to a variable and a pointer to that variable are semantically equivalent, we should consider address
operation as a valid base candidate.
Approach
Update and rename _is_pointer_variable
function in ArrayAccessDetection
to not only return True
, if an expression is a variable of type Pointer
but also if it is address
UnaryOperation
.
Also update getting array type -> in case as above type of unary operation operand can be used.
The expression &STUDENTS
in *(var_2 * 8 + &STUDENTS)
is the result of the bug during liffing of Binary Ninja DataVariable
. The correctly lifted expression should be *(var_2 * 8 + STUDENTS)
. #106 should deal first with the bug.
Blocked by #106
The change proposed by the issue is not correct, since it is based on incorrect lifting (see comment above). The lifting was fixed and this change is not required and does not make sense. Closing.