0

I've been trying to make some modding tools for quake live by reverse engineering, and I have this function. I rebased my program to 0x0, and did pretty much everything to set me up. However, when I call virtualprotect it doesn't work. I still get access violations when I inject the DLL. All helps appreciated!

comprintf

Above, I have the address for the value. Heres how I'm calling virtualprotect:

typedef void(__cdecl* Com_printf)(const char* msg, ...);

namespace QLIVESDK 
{
    void Com_Printf(const char* a1, ...)
    {
        DWORD old;
        VirtualProtect((PVOID)(GetModuleHandle("quakelive_steam.exe") + 0x000C9860), sizeof(a1), PAGE_EXECUTE_READWRITE, &old);
        Com_printf com_print = (Com_printf)0x000C9860;
        return com_print(a1);
    }
}

https://github.com/id-Software/Quake-III-Arena/blob/dbe4ddb10315479fc00086f08e25d968b4b43c49/code/qcommon/common.c#L143 Heres the function I'm trying to reverse. And heres how I'm calling it:

void Init()
{
    QLIVESDK::Com_Printf("hello, world!\n"); //test this shit
}

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
{
    switch (fdwReason)
    {
    case DLL_PROCESS_ATTACH:
        CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Init, 0, 0, 0);
        break;
    }
    return 1;
}

As you can see, its not working. I still get access violations. Thanks! All helps appreciated! :)

3
  • 1
    This isn't an issue with VirtualProtect. You're VirtualProtect-ing quakelive_steam.exe+0x000C9860 but then using just 0x000C9860 for the function pointer that you call. I would assume VirtualProtect worked to make the code writable and then the access violation is because address 0xc9860 isn't executable. Additionally in general you should check the return value and GetLastError codes for functions you think aren't working.
    – Fewmitz
    Jan 1 '17 at 6:43
  • So @Fewmitz , is it because its possible the wrong address?
    – Verideth
    Jan 1 '17 at 19:17
  • Yes. On Windows GetModuleHandle() doesn't return a handle; it returns an address to the module. So you used VirtualProtect on offset 0x000C9860 into quakelive_steam.exe but your com_print variable is JUST address 0x000C9860, which isn't what you VirtualProtect'd and probably not code (if it's there at all)
    – Fewmitz
    Jan 3 '17 at 1:53
-1

Thanks to @Fewmitz I managed to fix the problem.

Turns out com_print should = (Com_Printf)GetModuleHandle("quakelive_steam.exe") + 0x000C9860;

Thanks so much!

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.