include stdio include windows include winspool include detours __decls

 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
91
92
93
94
95
96
97
98
#include <stdio.h>
#include <windows.h>
#include <winspool.h>
#include "detours.h"
__declspec(dllexport) BOOL(WINAPI * TrueWritePrinter)(_In_ HANDLE hPrinter,
_In_reads_bytes_(cbBuf)
LPVOID pBuf,
DWORD cbBuf,
_Out_ LPDWORD pcWritten) = WritePrinter;
BOOL WINAPI WritePrinterEx(_In_ HANDLE hPrinter,
_In_reads_bytes_(cbBuf)
LPVOID pBuf,
DWORD cbBuf,
_Out_ LPDWORD pcWritten)
{
HANDLE h = CreateFile("C:\\hoook.txt",
GENERIC_WRITE,
0,
0,
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0);
hPrinter;
printf("WritePrinterEx\n");
fflush(stdout);
BOOL ret = TrueWritePrinter(h, pBuf, cbBuf, pcWritten);
if (h)
{
CloseHandle(h);
}
return ret;
}
__declspec(dllexport) BOOL(WINAPI* TrueSetWindowTextW)(_In_ HWND hWnd,
_In_opt_ LPCWSTR lpString) = SetWindowTextW;
BOOL WINAPI MySetWindowTextW(_In_ HWND hWnd,
_In_opt_ LPCWSTR lpString)
{
lpString;
return TrueSetWindowTextW(hWnd, (LPCWSTR)L"HUITA");
}
BOOL WINAPI DllMain(HINSTANCE hinst, DWORD dwReason, LPVOID reserved)
{
LONG error;
(void)hinst;
(void)reserved;
printf("OHUET\n");
if (DetourIsHelperProcess()) {
printf("DetourIsHelperProcess\n");
return TRUE;
}
if (dwReason == DLL_PROCESS_ATTACH) {
DetourRestoreAfterWith();
printf("print" DETOURS_STRINGIFY(DETOURS_BITS) ".dll:"
" Starting.\n");
fflush(stdout);
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)TrueWritePrinter, WritePrinterEx);
DetourAttach(&(PVOID&)TrueSetWindowTextW, MySetWindowTextW);
error = DetourTransactionCommit();
if (error == NO_ERROR) {
printf("print" DETOURS_STRINGIFY(DETOURS_BITS) ".dll:"
" Detoured SleepEx().\n");
}
else {
printf("print" DETOURS_STRINGIFY(DETOURS_BITS) ".dll:"
" Error detouring SleepEx(): %d\n", error);
}
}
else if (dwReason == DLL_PROCESS_DETACH) {
printf("dwReason == DLL_PROCESS_DETACH\n");
DetourTransactionBegin();
DetourUpdateThread(GetCurrentThread());
DetourAttach(&(PVOID&)TrueWritePrinter, WritePrinterEx);
DetourDetach(&(PVOID&)TrueSetWindowTextW, MySetWindowTextW);
error = DetourTransactionCommit();
fflush(stdout);
}
return TRUE;
}
//
///////////////////////////////////////////////////////////////// End of File.