So, I have an unsigned int
variable with a decimal value address stored on it, let's say unsigned int var = 1232342
, what I am trying to do is, without knowing the type of the variable but knowing the size of it and the address where it is stored, get the values as a byte array
. For example, let's say I have an int var = 20
with its address and bytesize. I want to be able to go to that address and return a byte array, in this case [00001100]
and the same for char
variables and data members of a struct.
A little bit of pseudocode would be something like:
for var.address until var.address = var.address + bytesize
do
byte_array = *var.address
var.address++
I am encountering some problems though, I am kind of new to C so I don't know how to treat an unsigned int as an address/pointer. Second, I don't know how to get the actual bytes out of the address, whenever I dereference the address what I get is the actual value of it, but that is if I know the type for the variable.
A little bit of background: I am working on a tool called Pin which gives me the option to hook into a running process, then I am using the DWARF and ELF info. So I do have access to the virtual memory space I am trying to access