2018-08-23 23:53:23 +08:00
|
|
|
// pipe.cc
|
|
|
|
// 8/24/2013 jichi
|
|
|
|
// Branch: ITH_DLL/pipe.cpp, rev 66
|
|
|
|
// 8/24/2013 TODO: Clean up this file
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
# pragma warning (disable:4100) // C4100: unreference formal parameter
|
|
|
|
#endif // _MSC_VER
|
|
|
|
|
2018-08-26 03:45:25 +08:00
|
|
|
#include "pipe.h"
|
2018-08-23 23:53:23 +08:00
|
|
|
#include "main.h"
|
|
|
|
#include "hijack/texthook.h"
|
|
|
|
#include "engine/match.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "const.h"
|
|
|
|
#include "growl.h"
|
|
|
|
|
|
|
|
HANDLE hookPipe;
|
|
|
|
|
|
|
|
DWORD DUMMY[100];
|
|
|
|
|
|
|
|
void CreatePipe()
|
|
|
|
{
|
2018-09-21 10:42:15 +08:00
|
|
|
CreateThread(nullptr, 0, [](LPVOID)
|
2018-08-23 23:53:23 +08:00
|
|
|
{
|
|
|
|
while (::running)
|
|
|
|
{
|
|
|
|
DWORD count = 0;
|
|
|
|
BYTE buffer[PIPE_BUFFER_SIZE] = {};
|
2018-08-29 03:18:05 +08:00
|
|
|
HANDLE hostPipe = ::hookPipe = INVALID_HANDLE_VALUE;
|
2018-08-23 23:53:23 +08:00
|
|
|
|
|
|
|
while (::hookPipe == INVALID_HANDLE_VALUE || hostPipe == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
|
|
|
if (::hookPipe == INVALID_HANDLE_VALUE)
|
|
|
|
{
|
2018-11-01 08:09:29 +08:00
|
|
|
::hookPipe = CreateFileW(HOOK_PIPE, GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
|
2018-08-23 23:53:23 +08:00
|
|
|
}
|
2018-09-10 10:37:48 +08:00
|
|
|
if (::hookPipe != INVALID_HANDLE_VALUE && hostPipe == INVALID_HANDLE_VALUE)
|
2018-08-23 23:53:23 +08:00
|
|
|
{
|
2018-11-01 08:09:29 +08:00
|
|
|
hostPipe = CreateFileW(HOST_PIPE, GENERIC_READ | FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
|
2018-08-23 23:53:23 +08:00
|
|
|
DWORD mode = PIPE_READMODE_MESSAGE;
|
|
|
|
SetNamedPipeHandleState(hostPipe, &mode, NULL, NULL);
|
2018-11-01 08:09:29 +08:00
|
|
|
continue;
|
2018-08-23 23:53:23 +08:00
|
|
|
}
|
2018-11-01 08:09:29 +08:00
|
|
|
Sleep(50);
|
2018-08-23 23:53:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
*(DWORD*)buffer = GetCurrentProcessId();
|
|
|
|
WriteFile(::hookPipe, buffer, sizeof(DWORD), &count, nullptr);
|
|
|
|
|
2018-09-30 04:05:08 +08:00
|
|
|
ConsoleOutput("Textractor: pipe connected");
|
2018-08-23 23:53:23 +08:00
|
|
|
#ifdef _WIN64
|
|
|
|
ConsoleOutput("Hooks don't work on x64, only read codes work. Engine disabled.");
|
|
|
|
#else
|
|
|
|
Engine::Hijack();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
while (::running && ReadFile(hostPipe, buffer, PIPE_BUFFER_SIZE, &count, nullptr))
|
|
|
|
switch (*(int*)buffer)
|
|
|
|
{
|
|
|
|
case HOST_COMMAND_NEW_HOOK:
|
|
|
|
{
|
|
|
|
auto info = *(InsertHookCmd*)buffer;
|
2018-08-24 03:25:33 +08:00
|
|
|
NewHook(info.hp, info.name, 0);
|
2018-08-23 23:53:23 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case HOST_COMMAND_REMOVE_HOOK:
|
|
|
|
{
|
|
|
|
auto info = *(RemoveHookCmd*)buffer;
|
2018-08-26 03:45:25 +08:00
|
|
|
RemoveHook(info.address);
|
2018-08-23 23:53:23 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case HOST_COMMAND_DETACH:
|
|
|
|
{
|
|
|
|
::running = false;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(hostPipe);
|
2018-11-01 08:09:29 +08:00
|
|
|
CloseHandle(::hookPipe);
|
2018-08-23 23:53:23 +08:00
|
|
|
}
|
|
|
|
FreeLibraryAndExitThread(GetModuleHandleW(ITH_DLL), 0);
|
2018-08-24 00:18:03 +08:00
|
|
|
return (DWORD)0;
|
|
|
|
}, nullptr, 0, nullptr);
|
2018-08-23 23:53:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConsoleOutput(LPCSTR text)
|
|
|
|
{
|
|
|
|
auto info = ConsoleOutputNotif(text);
|
|
|
|
WriteFile(::hookPipe, &info, strlen(text) + sizeof(info), DUMMY, nullptr);
|
|
|
|
}
|
|
|
|
|
2018-09-21 09:59:07 +08:00
|
|
|
void NotifyHookRemove(uint64_t addr)
|
2018-08-23 23:53:23 +08:00
|
|
|
{
|
|
|
|
auto info = HookRemovedNotif(addr);
|
|
|
|
WriteFile(::hookPipe, &info, sizeof(info), DUMMY, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// EOF
|