#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.