Pointer Aliasing
So far we have understood that data can go from Register to Memory and back again through Pointer
Now we have a more important problem
Two different Pointers may point to the same part of Memory
For example:
int value = 100;
int *p = &value;
int *q = &value;
Here p and q are two different Pointers
But both point to the same Memory
value
|
0x5000
/ \
/ \
p q
So if we do this
*p = 200;
the value of value will change
And when we read this later
printf("%d", *q);
We see the value 200
Because p and q actually point to the same location
We call this situation
Pointer Aliasing
This is very important for Reverse Engineering
Because you might see inside a function
mov [rax], 200
And a few lines down
mov ecx, [rbx]
At first glance you might think these two instructions have nothing to do
But if
RAX = 0x5000
RBX = 0x5000
Well
They are both working with the same memory
RAX ─────┐
↓
0x5000
↑
|
RBX ─────┘
So a change through RAX can directly affect what is read through RBX
Here the Data Flow is not just between Registers
You should also follow the relationship between Pointers and Memory Addresses
A simpler example
int value = 10;
int *p = &value;
int *q = p;
*p = 50;
int x = *q;
Actual data path
value
↓
p
↓
q
↓
Memory
↓
50
↓
x
But in terms of Address
p ──┐
├──> value
q ──┘
So p and q are two different paths to reach the same data
In Reverse Engineering
When working with Pointers, don't just ask
Where is this Pointer?
You should ask
Where does this Pointer point to?
What other Pointers might point to the same Address?
Who changed the value of that Memory?
Who later read that value?
These questions help you find connections that are not obvious from normal Control Flow
Exercise:
Examine this code
int value = 10;
int *p = &value;
int *q = p;
*p = 100;
int result = *q;
Draw the Data Flow path
value
↓
p
↓
q
↓
*p = 100
↓
*q
↓
result
Then determine why result is equal to 100
Next, we will move on to a more important topic
Memory Aliasing
In different functions
There we no longer have two pointers inside a function
One function modifies the Memory and another function reads the same Memory through a different Pointer
And this is exactly where Data Flow analysis in real binaries starts to cause trouble
@reverseengine
Post #1867
80
ReverseEngineering Pointer Aliasing تا اینجا فهمیدیم داده میتونه از Register بره داخل Memory و دوباره از طریق Pointer برگرده حالا یک مشکل مهم تر داریم ممکنه دو Pointer مختلف به یک قسمت از Memory اشاره کنن مثلا: int value = 100; int *p = &value; int *q = &value; اینجا p…