Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass a hex address to a Pointer Variable

Tags:

c

pointers

I know how to work with pointers. But I don't know how do this:

I have an hex address that's of course it has a any value from any app.

I know to find the address that I want. I want to write a C Code to pass this address to a pointer variable, and then I could capture the value from that address and so on.

For example:

hex 0x00010010
int *pointer;

How can I pass this address to the pointer, what's the syntax for that?

like image 359
Jacklyin Avatar asked Apr 09 '26 18:04

Jacklyin


1 Answers

By using int* you are assuming the data you are point to is an int (4 bytes, on most OS's).

Shouldn't we use a void* instead? Later, if you want to access it's data using a particular type, all you need to do is cast.

void *addr = (void*)0x0023FF74; // valid memory address within my app

printf("Address: %p\n", addr);
getchar();

printf("Data (4bytes): %d\n", *(int*)addr); // print the first 4 bytes of data as int
getchar();

EDIT:

Help me understand what you are trying to do, because this statement confused me:

There is app using that address, I know the value in it, but the (int)pointer don't access the value.

Are you trying to write an application that will modify the memory of another application that is running your system? Your current approach won't work, and this is why: When the Operating System loads your application into a process, it reserves a memory region to be used by the process and assigns a range of virtual addresses to this region. These virtual addresses do not map directly to memory addresses in RAM, so the OS has to keep an internal table for that.

On Windows, each process loaded receives the same range of virtual addresses, but this area is only visible to the process that is running inside it. For instance, (on Windows) processes are loaded in memory address 0x00400000, which mean each process has it's own memory address 0x00400000, and therefore you can't assign X memory address to a pointer in your application and expect Windows to magically know that you are reffering to address X that is inside another application.

What you are trying to accomplish it's called Code Injection, and there's a lot of information on the web about it.

like image 122
karlphillip Avatar answered Apr 11 '26 13:04

karlphillip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!