lundi 9 mars 2020

c++ get value from memory a process

I'm trying to get the int value of a processes' memory address.

I have been able to write to the memory address can't read the memory address value.

#include <iostream>
#include <windows.h>
#include <chrono>
#include <ctime>

using namespace std;


int main(void) {

    int nVal = 40000;

    HWND hWnd = FindWindowA(0, "Crusader");
    if(hWnd == 0){
        cerr << "Could not find window." << endl;
    } else {
        DWORD PID;
        GetWindowThreadProcessId(hWnd, &PID);
        HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, false, PID);

        if(!hProc) {
            cerr << "Cannot open process." << endl;
        } else {
            int buffer = 0;
            int stat = WriteProcessMemory(hProc, (LPVOID)0x0115FCF8, &nVal, (DWORD)sizeof(nVal), NULL);
            SIZE_T NumberOfBytesToRead = sizeof(buffer); //this is equal to 4
            SIZE_T NumberOfBytesActuallyRead;


            int stat2 = ReadProcessMemory(hProc, (LPVOID)0x0115FCF8, &buffer, NumberOfBytesToRead, &NumberOfBytesActuallyRead);
            std:cout<< *stat2;

           /* if(stat > 0){
                clog << "Memory written to process." << endl;
            } else {
                cerr << "Memory couldn't be written to process." << endl;
            }
*/
            CloseHandle(hProc);

            cin.get();

        }

    }

    return 0;
}

I can assign a value to the memory address, but reading the memory address returns 1. How can i get the value of the address

Aucun commentaire:

Enregistrer un commentaire