I am having trouble understanding this code and would like a good explanation.
The following function takes in a hex file and modifies the address without overwriting everything else.
Can someone explain to me how its doing that?
unsafe void WriteUint32(void* p, int Offset, uint value)
{
*(uint*)((byte*)p + Offset) = value;
}
If we ignore Offset
, you have
*(uint*)((byte*)p) = value;
which is just assigning value
to what p
points to, interpreted as a uint
.
Adding Offset
just changes the pointer to where value
is being assigned.