Convert Assembly from Cheat Engine to C++

Convert Assembly from Cheat Engine to C++

I want to write an auto for gaming. I use Cheat Engine and found the following Assembly code:

push 014656DC
call 00633940
add esp,04
ret

I inject this code into the app using Cheat Engine and it always worked.

Now, I want to use C++ code so I wrote a DLL:

  • header file:
#ifdef DIVLIB_EXPORTS
#define DIVLIB_API __declspec(dllexport)
#else
#define DIVLIB_API __declspec(dllimport)
#endif

extern "C" {
    DIVLIB_API void ClickID();
}
  • source file:
void ClickID()
{
    _asm {
        push esi;
        push eax;
        mov esi, 0x014656DC;
        mov eax, 0x00633940;
        push esi;
        call eax;
        add esp, 0x04;
    }
}

And I have the Main.exe to call this DLL

auto h_process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
char dll[] = "D:\\project\\DivHook\\divhook\\Debug\\divlib.dll";
HMODULE hinstDLL = LoadLibraryA(dll);
LPVOID LoadLibAddress = (LPVOID)GetProcAddress(hinstDLL, "ClickID");
LPVOID MemAlloc = (LPVOID)VirtualAllocEx(h_process, NULL, strlen(dll)+1, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
WriteProcessMemory(h_process, (LPVOID)MemAlloc, dll, strlen(dll) + 1, NULL);
CreateRemoteThread(h_process, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibAddress, (LPVOID)MemAlloc, NULL, NULL);
CloseHandle(h_process);
VirtualFreeEx(h_process, (LPVOID)MemAlloc, 0, MEM_RELEASE | MEM_DECOMMIT);

However, my game always crashes when Main.exe is run.

I have tried the above Assembly over and over with the Cheat Engine and made sure it works perfectly, but C++ code always crashes.

9

1 Answer

Well, Its not that easy to convert assembly to C++, Its actually impossible, Unless you can de-compile the main executable then yes you can do it, But for converting the Assembly code used by cheat engine that is impossible.

You can try to get it working by executing the assembly code using a DLL injected into the games process, But you will need to manage its memory and give it certain instructions.

Try and de-compile the main Executable first and see where that gets you. Once you find out what piece of source code the instruction is called from then you can try to Reverse Engineer the instruction by using again DLL Injection but at least you will know what to do, But just straight assembly into C++ won't be happening.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller
Author

David Miller

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.