Search code examples
c++arraysbytereverse-engineeringcheat-engine

How would I go about modifying an AOB from Cheat Engine to C++?


I've been attempting to modify an array of bytes that I found inside of Cheat Engine inside of C++, but I've reached an Access Violation crash when I attempt to read or write from it.

    // Writes pillarbox removal into memory ("33 83 4C 02" to "33 83 4C 00").
    *(BYTE*)(*((intptr_t*)((intptr_t)baseModule + 0x1E14850)) + 0x3) = 00;

I'm wondering what I'm doing wrong, as using something similar for the float values that I modified worked fine once I unprotected the main module handle.


Solution

  • Try this :

    void WriteToMemory(uintptr_t addressToWrite, char* valueToWrite, int byteNum)
    {
        //used to change our file access type, stores the old
        //access type and restores it after memory is written
        unsigned long OldProtection;
        //give that address read and write permissions and store the old permissions at oldProtection
        VirtualProtect((LPVOID)(addressToWrite), byteNum, PAGE_EXECUTE_READWRITE, &OldProtection);
    
        //write the memory into the program and overwrite previous value
        memcpy((LPVOID)addressToWrite, valueToWrite, byteNum);
    
        //reset the permissions of the address back to oldProtection after writting memory
        VirtualProtect((LPVOID)(addressToWrite), byteNum, OldProtection, NULL);
    }
    

    and call it as such :

    MODULEINFO mInfo = GetModuleInfo("name.exe");
    
    //Assign our base and module size
    DWORD baseModule = (DWORD)mInfo.lpBaseOfDll;
    uintptr_t addressToWrite = (uintptr_t)baseModule + 0x1E14850;
    char writeThis[] = "\x33\x83\x4c\x00";
    WriteToMemory(addressToWrite, writeThis, 4);
    

    Please let me know if it worked