#include <windows.h>
#include <iostream>
#include "minhook/include/MinHook.h"
void create_console()
{
if (!AllocConsole()) {
return;
}
FILE* fDummy;
freopen_s(&fDummy, "CONOUT$", "w", stdout);
freopen_s(&fDummy, "CONOUT$", "w", stderr);
freopen_s(&fDummy, "CONIN$", "r", stdin);
};
using system_t = int(__cdecl*)(const char* _Command);
system_t system_;
int __cdecl SystemHooked(const char* _Command) {
std::cout << "hook:" << _Command << std::endl;
return system_(_Command);
}
BOOL APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
if (dwReason == DLL_PROCESS_ATTACH)
create_console();
HMODULE kernel = GetModuleHandleA("msvcrt.dll");
if (kernel != NULL) {
LPVOID system_lp = GetProcAddress(kernel, "system");
if (system_lp != NULL) {
MH_Initialize();
MH_CreateHook(system_lp, &SystemHooked, reinterpret_cast<void**>(&system));
MH_EnableHook(system_lp);
}
}
return TRUE;
}