Pass a hex address to a Pointer Variable

后端 未结 2 1756
南笙
南笙 2021-01-03 10:55

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

相关标签:
2条回答
  • 2021-01-03 11:32

    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.

    0 讨论(0)
  • 2021-01-03 11:48

    In typical modern operating systems, you cannot access another process' (app's) address space. The addresses are virtual, so the same numerical value means different things to different processes.

    If you are on a system with a true "flat" address space (where processes directly work with actual physical memory addresses) such as Amiga OS on the 680x0, you can do something like:

    int *pointer = (int *) 0x00010010;
    
    0 讨论(0)
提交回复
热议问题