reading a memory address using c++
-
How do you read the value from a memory address using c++ ? do you use pointer or something ?
What u want exactly? If u looking for actual memory address of your volatile memory then I dont think memory address is shown by your pointer is the actual one. Also u can manipuate data of the memory address of current process in windows at least. If you want actual physical memory address u please look for some windows memory management book.
-
How do you read the value from a memory address using c++ ? do you use pointer or something ?
You can use the * operator. But you have to tell C++ what sort of data to expect at the address, so it knows what type of variable to create, e.g.: int memoryAddressValue = *((int *)memoryAddress); if you know an int is at the address (which occupies 4 bytes, so this call reads the address and the next 3 addresses). Memory addresses are just bytes or data, so their meaning is open to interpretation ! This call casts the address to a pointer to an integer - (int*)memoryAddress - and then reads the value from memory - * operator. Note: if the process doesn't have access to the address (which usually means the address is not the address of one of its variables on the stack, or is not part of the heap space defined by calling new/malloc etc) then expect an access violation exception. Thanks, Neil Humphreys.
-
You can use the * operator. But you have to tell C++ what sort of data to expect at the address, so it knows what type of variable to create, e.g.: int memoryAddressValue = *((int *)memoryAddress); if you know an int is at the address (which occupies 4 bytes, so this call reads the address and the next 3 addresses). Memory addresses are just bytes or data, so their meaning is open to interpretation ! This call casts the address to a pointer to an integer - (int*)memoryAddress - and then reads the value from memory - * operator. Note: if the process doesn't have access to the address (which usually means the address is not the address of one of its variables on the stack, or is not part of the heap space defined by calling new/malloc etc) then expect an access violation exception. Thanks, Neil Humphreys.
thanks for the swift reply humps. I could understand your explaination better than any of those websites out there. Well you know the websites nowadays are providing more junks per piece of useful information. well i think i understand what you mean, and that exactly is what i am trying to do. I am trying to get a vaule from the address of another application. I suppose those address are not part of the heap space defined by my source code. So what am are the alternative now ? * define my source code to include those address ? well i am super confused stucked now i been bombing the internet all night with no avail... No last plea anyone could be kind enough to offer some help to write the souce code in c++ to get the value of a WORD from a memory address finder application -- memware -- the address is 12C71560 and probably 0x12C71560 in c++ ? well fragment of codes or even a clue as to which command would be kind enough.
-
thanks for the swift reply humps. I could understand your explaination better than any of those websites out there. Well you know the websites nowadays are providing more junks per piece of useful information. well i think i understand what you mean, and that exactly is what i am trying to do. I am trying to get a vaule from the address of another application. I suppose those address are not part of the heap space defined by my source code. So what am are the alternative now ? * define my source code to include those address ? well i am super confused stucked now i been bombing the internet all night with no avail... No last plea anyone could be kind enough to offer some help to write the souce code in c++ to get the value of a WORD from a memory address finder application -- memware -- the address is 12C71560 and probably 0x12C71560 in c++ ? well fragment of codes or even a clue as to which command would be kind enough.
Modern operating systems are designed to prevent exactly the type of access you are attempting. As a rule, each process runs in its own address space, and cannot access the address space of other processes. For example, suppose you have a variable in process A whose address is
12C71560
. That address has meaning only inside process A. That same address inside process B only refers to memory that may or may not be allocated to process B. If you are looking to establish communication between two processes, try here[^]. The topic you are looking for is inter-process communication.
Software Zen:
delete this;