diff --git a/gui/ProcessWindow.cpp b/gui/ProcessWindow.cpp index 4845dd5..306cf55 100644 --- a/gui/ProcessWindow.cpp +++ b/gui/ProcessWindow.cpp @@ -1,7 +1,7 @@ #include "ProcessWindow.h" #include "resource.h" -#include "host/host.h" -#include "host/hookman.h" +#include "host.h" +#include "hookman.h" #include "ProfileManager.h" #include "profile/Profile.h" diff --git a/gui/ProfileManager.cpp b/gui/ProfileManager.cpp index 2a86b08..191a153 100644 --- a/gui/ProfileManager.cpp +++ b/gui/ProfileManager.cpp @@ -1,7 +1,7 @@ #include "ProfileManager.h" #include "profile/Profile.h" -#include "host/host.h" -#include "host/hookman.h" +#include "host.h" +#include "hookman.h" #include "vnrhook/include/types.h" #include "vnrhook/include/const.h" #include "utility.h" diff --git a/gui/command.cpp b/gui/command.cpp index cdf077a..3b791f8 100644 --- a/gui/command.cpp +++ b/gui/command.cpp @@ -16,7 +16,7 @@ */ #include "ITH.h" -#include "host/host.h" +#include "host.h" #include "vnrhook/include/const.h" #include "vnrhook/include/types.h" #include "language.h" diff --git a/gui/main.cpp b/gui/main.cpp index 040e505..a884736 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -16,8 +16,8 @@ */ #include "ITH.h" -#include "host/host.h" -#include "host/hookman.h" +#include "host.h" +#include "hookman.h" #include "profile/Profile.h" #include "ProfileManager.h" diff --git a/gui/utility.cpp b/gui/utility.cpp index f58c70d..2017091 100644 --- a/gui/utility.cpp +++ b/gui/utility.cpp @@ -16,8 +16,8 @@ */ #include "utility.h" -#include "host/host.h" -#include "host/hookman.h" +#include "host.h" +#include "hookman.h" #include "vnrhook/include/types.h" #include "vnrhook/include/const.h" #include "profile/misc.h" diff --git a/gui/utility.h b/gui/utility.h index 74ba36f..47c3c13 100644 --- a/gui/utility.h +++ b/gui/utility.h @@ -1,7 +1,7 @@ #pragma once #include "ITH.h" -#include "texthook/host/textthread.h" +#include "textthread.h" struct HookParam; struct ProcessRecord; diff --git a/gui/window.cpp b/gui/window.cpp index 9c68379..0f57bcc 100644 --- a/gui/window.cpp +++ b/gui/window.cpp @@ -18,8 +18,8 @@ #include "ProcessWindow.h" #include "resource.h" #include "language.h" -#include "host/host.h" -#include "host/hookman.h" +#include "host.h" +#include "hookman.h" #include "vnrhook/include/const.h" #include "version.h" #include "ProfileManager.h" diff --git a/vnr/CMakeLists.txt b/vnr/CMakeLists.txt index 00dd0a5..ca0cdf5 100644 --- a/vnr/CMakeLists.txt +++ b/vnr/CMakeLists.txt @@ -24,5 +24,5 @@ include_directories( ) add_subdirectory(vnrhook) -add_subdirectory(texthook/host) +add_subdirectory(texthook) add_subdirectory(profile) diff --git a/vnr/profile/Profile.cpp b/vnr/profile/Profile.cpp index 7dd1fc2..b973545 100644 --- a/vnr/profile/Profile.cpp +++ b/vnr/profile/Profile.cpp @@ -16,8 +16,8 @@ */ -#include "host/host.h" -#include "host/hookman.h" +#include "host.h" +#include "hookman.h" #include "vnrhook/include/types.h" #include "vnrhook/include/const.h" #include "Profile.h" diff --git a/vnr/profile/misc.cpp b/vnr/profile/misc.cpp index effb5cf..6be4827 100644 --- a/vnr/profile/misc.cpp +++ b/vnr/profile/misc.cpp @@ -1,7 +1,7 @@ #include "misc.h" #include #include -#include "host/host.h" +#include "host.h" #include "vnrhook/include/const.h" #include "vnrhook/include/types.h" diff --git a/vnr/texthook/host/CMakeLists.txt b/vnr/texthook/CMakeLists.txt similarity index 100% rename from vnr/texthook/host/CMakeLists.txt rename to vnr/texthook/CMakeLists.txt diff --git a/vnr/texthook/host/config.h b/vnr/texthook/config.h similarity index 100% rename from vnr/texthook/host/config.h rename to vnr/texthook/config.h diff --git a/vnr/texthook/growl.h b/vnr/texthook/growl.h deleted file mode 100644 index a99b5b2..0000000 --- a/vnr/texthook/growl.h +++ /dev/null @@ -1,85 +0,0 @@ -#pragma once - -// growl.h -// 9/17/2013 jichi - -//#ifdef GROWL_HAS_GROWL - -#include -#include - -#define GROWL_MSG_A(_msg) MessageBoxA(nullptr, _msg, "VNR Message", MB_OK) -#define GROWL_MSG(_msg) MessageBoxW(nullptr, _msg, L"VNR Message", MB_OK) -#define GROWL_WARN(_msg) MessageBoxW(nullptr, _msg, L"VNR Warning", MB_OK) -#define GROWL_ERROR(_msg) MessageBoxW(nullptr, _msg, L"VNR Error", MB_OK) - -inline void GROWL_DWORD(DWORD value) -{ - WCHAR buf[100]; - swprintf(buf, L"DWORD: %x", value); - GROWL_MSG(buf); -} - -inline void GROWL_DWORD2(DWORD v, DWORD v2) -{ - WCHAR buf[100]; - swprintf(buf, L"DWORD2: %x,%x", v, v2); - GROWL_MSG(buf); -} - -inline void GROWL_DWORD3(DWORD v, DWORD v2, DWORD v3) -{ - WCHAR buf[100]; - swprintf(buf, L"DWORD3: %x,%x,%x", v, v2, v3); - GROWL_MSG(buf); -} - -inline void GROWL_DWORD4(DWORD v, DWORD v2, DWORD v3, DWORD v4) -{ - WCHAR buf[100]; - swprintf(buf, L"DWORD4: %x,%x,%x,%x", v, v2, v3, v4); - GROWL_MSG(buf); -} - -inline void GROWL_DWORD5(DWORD v, DWORD v2, DWORD v3, DWORD v4, DWORD v5) -{ - WCHAR buf[100]; - swprintf(buf, L"DWORD5: %x,%x,%x,%x,%x", v, v2, v3, v4, v5); - GROWL_MSG(buf); -} - -inline void GROWL_DWORD6(DWORD v, DWORD v2, DWORD v3, DWORD v4, DWORD v5, DWORD v6) -{ - WCHAR buf[100]; - swprintf(buf, L"DWORD6: %x,%x,%x,%x,%x,%x", v, v2, v3, v4, v5, v6); - GROWL_MSG(buf); -} - -inline void GROWL_DWORD7(DWORD v, DWORD v2, DWORD v3, DWORD v4, DWORD v5, DWORD v6, DWORD v7) -{ - WCHAR buf[100]; - swprintf(buf, L"DWORD7: %x,%x,%x,%x,%x,%x,%x", v, v2, v3, v4, v5, v6, v7); - GROWL_MSG(buf); -} - -inline void GROWL_DWORD8(DWORD v, DWORD v2, DWORD v3, DWORD v4, DWORD v5, DWORD v6, DWORD v7, DWORD v8) -{ - WCHAR buf[100]; - swprintf(buf, L"DWORD8: %x,%x,%x,%x,%x,%x,%x,%x", v, v2, v3, v4, v5, v6, v7, v8); - GROWL_MSG(buf); -} - -inline void GROWL_DWORD9(DWORD v, DWORD v2, DWORD v3, DWORD v4, DWORD v5, DWORD v6, DWORD v7, DWORD v8, DWORD v9) -{ - WCHAR buf[100]; - swprintf(buf, L"DWORD9: %x,%x,%x,%x,%x,%x,%x,%x,%x", v, v2, v3, v4, v5, v6, v7, v8, v9); - GROWL_MSG(buf); -} - -inline void GROWL(DWORD v) { GROWL_DWORD(v); } -inline void GROWL(LPCWSTR v) { GROWL_MSG(v); } -inline void GROWL(LPCSTR v) { GROWL_MSG_A(v); } - -//#endif // GROWL_HAS_GROWL - -// EOF diff --git a/vnr/texthook/host/hookman.cc b/vnr/texthook/hookman.cc similarity index 100% rename from vnr/texthook/host/hookman.cc rename to vnr/texthook/hookman.cc diff --git a/vnr/texthook/host/hookman.h b/vnr/texthook/hookman.h similarity index 100% rename from vnr/texthook/host/hookman.h rename to vnr/texthook/hookman.h diff --git a/vnr/texthook/host/host.cc b/vnr/texthook/host.cc similarity index 73% rename from vnr/texthook/host/host.cc rename to vnr/texthook/host.cc index 14ecb57..2f3ecf3 100644 --- a/vnr/texthook/host/host.cc +++ b/vnr/texthook/host.cc @@ -6,7 +6,6 @@ #include "vnrhook/include/const.h" #include "vnrhook/include/defs.h" #include "vnrhook/include/types.h" -#include #include "extensions/Extensions.h" HANDLE preventDuplicationMutex; @@ -15,11 +14,10 @@ HookManager* man; HWND dummyWindow; bool running; -namespace +namespace { // unnamed - - void GetDebugPrivileges() - { // Artikash 5/19/2018: Is it just me or is this function 100% superfluous? + void GetDebugPrivileges() // Artikash 5/19/2018: Is it just me or is this function 100% superfluous? + { HANDLE processToken; TOKEN_PRIVILEGES Privileges = { 1, {0x14, 0, SE_PRIVILEGE_ENABLED} }; @@ -27,7 +25,6 @@ namespace AdjustTokenPrivileges(processToken, FALSE, &Privileges, 0, nullptr, nullptr); CloseHandle(processToken); } - } // unnamed namespace void CreateNewPipe(); @@ -39,14 +36,11 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID unused) case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls(hinstDLL); GetDebugPrivileges(); - // jichi 12/20/2013: Since I already have a GUI, I don't have to InitCommonControls() - // Used by timers. - // InitCommonControls(); // jichi 8/24/2013: Create hidden window so that ITH can access timer and events dummyWindow = CreateWindowW(L"Button", L"InternalWindow", 0, 0, 0, 0, 0, 0, 0, hinstDLL, 0); break; case DLL_PROCESS_DETACH: - if (::running) CloseHost(); + CloseHost(); DestroyWindow(dummyWindow); break; default: @@ -60,7 +54,7 @@ DLLEXPORT bool StartHost() preventDuplicationMutex = CreateMutexW(nullptr, TRUE, ITH_SERVER_MUTEX); if (GetLastError() == ERROR_ALREADY_EXISTS || ::running) { - GROWL_WARN(L"I am sorry that this game is attached by some other VNR ><\nPlease restart the game and try again!"); + MessageBoxW(nullptr, L"I am sorry that this game is attached by some other VNR ><\nPlease restart the game and try again!", L"Error", MB_ICONERROR); return false; } else @@ -114,7 +108,7 @@ DLLEXPORT bool InjectProcessById(DWORD processId, DWORD timeout) CloseHandle(processHandle); return true; } - + man->AddConsoleOutput(L"couldn't inject dll"); return false; } @@ -128,44 +122,41 @@ DLLEXPORT bool DetachProcessById(DWORD processId) DLLEXPORT void GetHostHookManager(HookManager** hookman) { - if (::running) - { - *hookman = man; - } + *hookman = man; } -DLLEXPORT DWORD InsertHook(DWORD pid, const HookParam *hp, std::string name) -{ - HANDLE commandPipe = man->GetHostPipe(pid); - if (commandPipe == nullptr) - return -1; - - BYTE buffer[PIPE_BUFFER_SIZE] = {}; - *(DWORD*)buffer = HOST_COMMAND_NEW_HOOK; - *(HookParam*)(buffer + sizeof(DWORD)) = *hp; - if (name.size()) strcpy((char*)buffer + sizeof(DWORD) + sizeof(HookParam), name.c_str()); - - DWORD unused; - WriteFile(commandPipe, buffer, sizeof(DWORD) + sizeof(HookParam) + name.size(), &unused, nullptr); - return 0; -} - -DLLEXPORT DWORD RemoveHook(DWORD pid, DWORD addr) +DLLEXPORT bool InsertHook(DWORD pid, const HookParam *hp, std::string name) { HANDLE commandPipe = man->GetHostPipe(pid); - if (commandPipe == nullptr) return -1; - + if (commandPipe == nullptr) return false; + + BYTE buffer[PIPE_BUFFER_SIZE] = {}; + *(DWORD*)buffer = HOST_COMMAND_NEW_HOOK; + *(HookParam*)(buffer + sizeof(DWORD)) = *hp; + if (name.size()) strcpy((char*)buffer + sizeof(DWORD) + sizeof(HookParam), name.c_str()); + DWORD unused; + WriteFile(commandPipe, buffer, sizeof(DWORD) + sizeof(HookParam) + name.size(), &unused, nullptr); + return true; +} + +DLLEXPORT bool RemoveHook(DWORD pid, DWORD addr) +{ + HANDLE commandPipe = man->GetHostPipe(pid); + if (commandPipe == nullptr) return false; + HANDLE hookRemovalEvent = CreateEventW(nullptr, TRUE, FALSE, ITH_REMOVEHOOK_EVENT); + BYTE buffer[sizeof(DWORD) * 2] = {}; *(DWORD*)buffer = HOST_COMMAND_REMOVE_HOOK; *(DWORD*)(buffer + sizeof(DWORD)) = addr; - DWORD unused; - WriteFile(commandPipe, buffer, sizeof(DWORD) * 2, &unused, nullptr); - WaitForSingleObject(hookRemovalEvent, 1000); - CloseHandle(hookRemovalEvent); - man->RemoveSingleHook(pid, addr); - return 0; + WriteFile(commandPipe, buffer, sizeof(DWORD) * 2, &unused, nullptr); + + WaitForSingleObject(hookRemovalEvent, 1000); + CloseHandle(hookRemovalEvent); + + man->RemoveSingleHook(pid, addr); + return true; } // EOF diff --git a/vnr/texthook/host/host.h b/vnr/texthook/host.h similarity index 72% rename from vnr/texthook/host/host.h rename to vnr/texthook/host.h index d47879f..0aa3c58 100644 --- a/vnr/texthook/host/host.h +++ b/vnr/texthook/host.h @@ -6,7 +6,7 @@ //#include "host/settings.h" #include "config.h" -#include "host/hookman.h" +#include "hookman.h" #include struct HookParam; @@ -17,7 +17,7 @@ DLLEXPORT void CloseHost(); DLLEXPORT void GetHostHookManager(HookManager **hookman); DLLEXPORT bool InjectProcessById(DWORD pid, DWORD timeout = 5000); DLLEXPORT bool DetachProcessById(DWORD pid); -DLLEXPORT DWORD InsertHook(DWORD pid, const HookParam *hp, std::string name = ""); -DLLEXPORT DWORD RemoveHook(DWORD pid, DWORD addr); +DLLEXPORT bool InsertHook(DWORD pid, const HookParam *hp, std::string name = ""); +DLLEXPORT bool RemoveHook(DWORD pid, DWORD addr); // EOF diff --git a/vnr/texthook/host/pipe.cc b/vnr/texthook/pipe.cc similarity index 91% rename from vnr/texthook/host/pipe.cc rename to vnr/texthook/pipe.cc index 65a4ab1..7556558 100644 --- a/vnr/texthook/host/pipe.cc +++ b/vnr/texthook/pipe.cc @@ -7,8 +7,6 @@ #include "hookman.h" #include "vnrhook/include/defs.h" #include "vnrhook/include/const.h" -#include -#include "growl.h" #include extern HookManager* man; @@ -38,13 +36,6 @@ DWORD WINAPI TextReceiver(LPVOID lpThreadParameter) BYTE buffer[PIPE_BUFFER_SIZE] = {}; DWORD bytesRead, processId; - - // Artikash 5/20/2018: Shouldn't Windows automatically close the handles when the host process stops running? - //if (!::running) { - // NtClose(hookPipe); - // return 0; - //} - ReadFile(pipes->hookPipe, &processId, sizeof(processId), &bytesRead, nullptr); man->RegisterProcess(processId, pipes->hostPipe); @@ -91,9 +82,7 @@ DWORD WINAPI TextReceiver(LPVOID lpThreadParameter) man->UnRegisterProcess(processId); CloseHandle(pipes->hookPipe); CloseHandle(pipes->hostPipe); - delete pipes; - return 0; } diff --git a/vnr/texthook/host/textthread.cc b/vnr/texthook/textthread.cc similarity index 90% rename from vnr/texthook/host/textthread.cc rename to vnr/texthook/textthread.cc index e48cbe4..b25043f 100644 --- a/vnr/texthook/host/textthread.cc +++ b/vnr/texthook/textthread.cc @@ -69,9 +69,9 @@ void TextThread::AddSentence(std::wstring sentence) void TextThread::AddText(const BYTE *con, int len) { TT_LOCK; - sentenceBuffer.insert(sentenceBuffer.end(), con, con+len); - SetTimer(dummyWindow, (UINT_PTR)this, splitDelay, - [](HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) + sentenceBuffer.insert(sentenceBuffer.end(), con, con + len); + SetTimer(dummyWindow, (UINT_PTR)this, splitDelay, + [](HWND hWnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { KillTimer(hWnd, idEvent); ((TextThread*)idEvent)->AddSentence(); diff --git a/vnr/texthook/host/textthread.h b/vnr/texthook/textthread.h similarity index 100% rename from vnr/texthook/host/textthread.h rename to vnr/texthook/textthread.h