Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

access an array from known address

Tags:

arrays

c

I have a code that I passed a certain place in the memory. This place in the memory is pointing to an array

uint32_t *ps2 = NULL;
uint32_t src_address = 0x1ffffc3;

How can I read the value of the array from this address? I tried to cast it as follows

*ps2 = (void *)src_address;

but it gives me an error: invalid conversion from ‘void*’ to ‘uint32_t

Regards,

like image 525
asd Avatar asked Apr 04 '19 08:04

asd


1 Answers

You have two problems:

  1. First of all, the pointer ps2 is a null pointer, it doesn't point anywhere. That means you can't dereference it.

  2. src_address is not a pointer, when it really should be.

All in all there's seems to be some mixup in your understanding of pointers and how they are used.

For it to work, first define ps2 as not a pointer:

uint32_t ps2;

then define src_address as a pointer:

uint32_t *src_address = (uint32_t *) 0x1ffffc3;

and finally dereference src_address like a normal pointer:

ps2 = *src_address;

There is a possible third problem: The address of src_address is not aligned for an uint32_t. On some systems unaligned access is invalid and will lead to hardware exceptions.

like image 200
Some programmer dude Avatar answered Oct 22 '22 21:10

Some programmer dude