////////////////////////////////////////////////////////////////////// // Asm_Code() // ------------------------------------------------------------------- // This is our assembler routine that we patch in to the game. Since // this code is relocateable, you can patch in anywhere in the game's // address-space. We chose to put it at game.exe+0x400 bytes. // // This code hi-jacks WinProc and loads/unloads our dll when it // receives WM_APP. ////////////////////////////////////////////////////////////////////// void _declspec(naked) AsmCode(void) { __asm { make_space // Make room for original code pushad call getaddress // Get our EIP getaddress: pop esi sub esi, 0x0c // We now have base address in esi add esi, DATA // Add offset to data mov eax, [esp+0x2c] // esp+0x2c = uMsg cmp eax, WM_APP // Check for our signal je do_our_stuff hack_exit: popad ret do_our_stuff: mov eax, esi add eax, MODULENAME push eax mov eax, [esi+PGETMODULEHANDLEA] call eax // Is our dll loaded ? cmp eax, 0 je load_dll // No, load it push eax // Yes, unload it mov eax, [esi+PFREELIBRARY] call eax jmp hack_exit load_dll: mov eax, esi add eax, FILENAME push eax mov eax, [esi+PLOADLIBRARYA] call eax jmp hack_exit } }