You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.3 KiB

#include <iostream>
#include "hook.hpp"
using namespace std;
BOOL HookWriteFile(
HANDLE hFile,
LPCVOID lpBuffer,
DWORD nNumberOfBytesToWrite,
LPDWORD lpNumberOfBytesWritten,
LPOVERLAPPED lpOverlapped
)
{
//this will change the output to "shithooked!\n"
const char* shithooked = "shithooked!?";
hook::disable(&WriteFile);
BOOL result = WriteFile(
hFile,
shithooked,
nNumberOfBytesToWrite,
lpNumberOfBytesWritten,
lpOverlapped
);
hook::enable(&WriteFile);
return result;
}
int main()
{
//make hook
hook::make_hook(
&WriteFile,
&HookWriteFile,
false // you can choose not to install it yet
);
//make file
OFSTRUCT ofstruct{};
auto result = std::unique_ptr<std::remove_pointer_t<HANDLE>, decltype(&CloseHandle)>(
(HANDLE)(OpenFile(
"output.txt",
&ofstruct,
OF_READWRITE | OF_CREATE
)), &CloseHandle
);
if (reinterpret_cast<HFILE>(result.get()) != HFILE_ERROR)
{
// we can enable it after we open the file
hook::enable(&WriteFile);
//write to file
const char aString[] = "Hello world!\n";
WriteFile(result.get(), aString, sizeof(aString), NULL, NULL);
}
}