Question

ive been reading around the website and googling to try and find a conclusive answer to what im trying to do, but i didnt find one that answers all my questions.

i have two processes. one has an integer variable which i want to change by a second process. i know how to read/write to specific memory locations, but i only know how to do it on the native process addresses.

i dont understand createremotethread. is it possible i get the cleanest, simplest example of manipulating memory of a process not native to the running program? assuming both programs are running, of course.

thanks in advance

EDIT: i got some answers about my question from other sources. i just want to understand how do i write a vairable to a memory location, say:

WriteProcessMemory(phandle,(void*)address,val,sizeof(val),NULL);

this seems to have no effect, assuming the val is a bool:

while(true){
    key=getch();
    if(key=='1'){
        if(val)val=false;
        else val=true;
        WriteProcessMemory(phandle,(void*)address,&val,sizeof(val),NULL);
    }
    bool val2;
    ReadProcessMemory(phandle, (void*)address, &val2, sizeof(val2), NULL);
    cout<<val2<<endl;
}

always shows 0. why?

Was it helpful?

Solution 2

issue solved, i had to use HANDLE phandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid)

instead of HANDLE phandle = OpenProcess(PROCESS_VM_READ, 0, pid)

OTHER TIPS

try to read about shared memory, and mutex to make sure not two processes manipulating same memory spot at the same time.

BOOL WINAPI WriteProcessMemory(
  _In_   HANDLE hProcess,
  _In_   LPVOID lpBaseAddress,
  _In_   LPCVOID lpBuffer,
  _In_   SIZE_T nSize,
  _Out_  SIZE_T *lpNumberOfBytesWritten
);

did you pass the correct parameters as above, you will have to have at least the first 4 parameters to work

do the follow

WriteProcessMemory(phandle,(void*)address,&val,sizeof(val),NULL); 

notice the val pass the address of the val

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top