-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdllmain.cpp
More file actions
90 lines (72 loc) · 1.96 KB
/
dllmain.cpp
File metadata and controls
90 lines (72 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <Windows.h>
#include <iostream>
#include <stdio.h>
#include "detours.h"
#include <excpt.h>
DWORD addrPrintf = 0;
DWORD addrNopPrint= 0;
void myInvalidParameterHandler(const wchar_t* expression,
const wchar_t* function,
const wchar_t* file,
unsigned int line,
uintptr_t pReserved)
{
//PASS...
//Yes, this is gross.
}
int hookNopPrint(const char *format, ...) {
return 0;
}
int hookPrintf(const char *format, ...)
{
char buffer[256];
memset(&buffer, 0x00, sizeof(buffer));
int ret = -1;
va_list args;
va_start(args, format);
ret = _vsnprintf_s(buffer, sizeof(buffer), format, args);
if (ret > 0) {
if (WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), buffer, ret, NULL, NULL) == FALSE)
{
if (AllocConsole() == TRUE)
{
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE), buffer, ret, NULL, NULL);
}
}
}
va_end(args);
return 0;
}
BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
{
_invalid_parameter_handler oldHandler, newHandler;
newHandler = myInvalidParameterHandler;
oldHandler = _set_invalid_parameter_handler(newHandler);
// Disable the message box for assertions.
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_DEBUG);
// create console window for printing debug lines
AllocConsole();
if (dwReason == DLL_PROCESS_ATTACH)
{
// address to the functions we are hooking
DWORD addrPrintf = 0x006FA180;
DWORD addrJunkPrint = 0x008E0280;
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
// hook the null debug printf
DetourAttach(&(LPVOID&)addrPrintf, &hookPrintf);
// NOP "print:" message that appears to be kanji or ...?
DetourAttach(&(LPVOID&)addrJunkPrint, &hookNopPrint);
DetourTransactionCommit();
}
else if (dwReason == DLL_PROCESS_DETACH)
{
// unhook
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourDetach(&(LPVOID&)addrPrintf, &hookPrintf);
DetourDetach(&(LPVOID&)addrNopPrint, &hookNopPrint);
DetourTransactionCommit();
}
return TRUE;
}