I made myself a little challenge: to make a simply memory tool that can read and write a value to an address, in C++. I have it working, but only for memory inside the program. I get an 'access violation' when I try to read/write memory outside the program(Which is definitely there)
The way I'm doing this is writing a value in one of the programs, and I'm trying to change it with another, but I get the access violation.
You can't do it purely from within the process. You need support from the OS to access the memory space of another process. There are two main reasons for this:
1. The OS configures the CPU to perform a memory mapping of pages between virtual addresses and physical addresses. The virtual address is the address that the program sees, and the physical address is the address that the hardware sees. What this means is that two different processes can own two virtual pages that start at the same location and map to different physical memory regions, and therefore contain different data. So, even if the access doesn't crash the program, you will still not be able to see the other process' memory.
2. The OS enforces memory protection between processes to prevent accidental or malicious access to the memory of other processes. This is a basic security feature of all modern OSs.
If you're on Windows, you can use ReadProcessMemory() and related functions.
Note that even with OS support, there will still be things you won't be able to do:
* Normal users' processes can generally not access the processes of other users. Processes with administrative privileges may not have this limitation.
* Normal processes, including those with administrative privileges, are never able to access memory owned by the kernel. The only way to access this memory is to load a driver.