You cannot do this with your code: on x86-64 systems, you will receive an access violation for every address that does not belong to your executable address space.
The OS is responsible for deciding which addresses belong to this process (they undergo the MMU translation process, which ultimately decides whether the address belongs to the process or not) if it is not notified about the processor and according to the OS you can get an access violation or segmentation error .
On a linux system, you usually edit another process memory with something like ptrace to debug another process. Another option is to edit / dev / mem . For both, you need root access.
On a Windows system, you can instead use ReadProcessMemory and WriteProcessMemory or directly paste your code into the target whose address you created (CreateRemoteThread).
In any case, remember why you cannot execute it using your current code: modern operating systems run your application in a paged environment, that is, they provide a virtual address space that is optional (and usually not) to map physical addresses. What you are trying to do is wrong because these addresses will not be mapped to physical locations . If you really want to go this way, you will have to disable or bypass segmentation mechanisms, ring3 / 0 protection, paging, MMU transfers and probably solve a ton of other problems related to reserved addresses and registered MMIO intervals.
source share