maniackplanet/Observer/dllmain.cpp

79 lines
1.7 KiB
C++

// dllmain.cpp : Définit le point d'entrée pour l'application DLL.
#include "stdafx.h"
#include <iostream>
#include <fstream>
/*
void __stdcall LogMessageWrapperHook() {
std::cout << "Message wrapped called" << std::endl;
}
__declspec(naked) void TrampolineLogMessageWrapperHook()
{
__asm
{
// Overwrited instructions by the patch
PUSH esi
PUSH [esp+0xC] // push [esp + 4 + messageLength]
// Save registers
PUSHAD
// Call our hook
CALL LogMessageWrapperHook
// Restore registers
POPAD
// Not really sure...
RET
}
}*/
void initDll() {
AllocConsole();
SetConsoleTitleA("Maniaplanet Observer");
FILE* console;
freopen_s(&console, "CONIN$", "r", stdin);
freopen_s(&console, "CONOUT$", "w", stdout);
freopen_s(&console, "CONOUT$", "w", stderr);
std::cout << "Observer.dll was successfully injected, time to patch now..." << std::endl;
return;
/*
unsigned int* addressToPatch = (unsigned int*)0x403b70;
DWORD oldProtection = 0;
// Enable writing in memory
if (!VirtualProtect(addressToPatch, 5, PAGE_EXECUTE_READWRITE, &oldProtection)) {
std::cout << "Failed to change VirtualProtect status while attempting to patch your binary" << std::endl;
return;
}
// Change the instruction by JMP Trampoline
*addressToPatch = 0xE9; // JMP INT32
*(addressToPatch + 1) = (unsigned int)TrampolineLogMessageWrapperHook - ((unsigned int)addressToPatch + 5);
*/
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
initDll();
break;
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}