From a290c36b521bc4122ec610c45ef2ab78ec20b32d Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Fri, 20 Jul 2018 17:21:35 -0400 Subject: [PATCH] remove extension code from host --- gui/window.cpp | 3 ++- vnr/extensions/Extensions.cpp | 36 --------------------------- vnr/extensions/Extensions.h | 6 ----- vnr/texthook/CMakeLists.txt | 4 +-- vnr/texthook/hookman.cc | 2 +- vnr/texthook/host.cc | 2 -- vnr/texthook/textthread.cc | 7 +++--- vnr/texthook/textthread.h | 2 +- vnr/{winmutex => texthook}/winmutex.h | 0 9 files changed, 8 insertions(+), 54 deletions(-) delete mode 100644 vnr/extensions/Extensions.cpp delete mode 100644 vnr/extensions/Extensions.h rename vnr/{winmutex => texthook}/winmutex.h (100%) diff --git a/gui/window.cpp b/gui/window.cpp index ba0c222..81d9a5e 100644 --- a/gui/window.cpp +++ b/gui/window.cpp @@ -347,9 +347,10 @@ void ClickButton(HWND hWnd, HWND h) } } -void ThreadOutput(TextThread* thread, std::wstring output) +std::wstring ThreadOutput(TextThread* thread, std::wstring output) { if (thread->Status() & CURRENT_SELECT) texts->AddText(output, false); + return output; } bool GetHookParam(DWORD pid, DWORD hook_addr, HookParam& hp) diff --git a/vnr/extensions/Extensions.cpp b/vnr/extensions/Extensions.cpp deleted file mode 100644 index aa22733..0000000 --- a/vnr/extensions/Extensions.cpp +++ /dev/null @@ -1,36 +0,0 @@ -#include "Extensions.h" -#include -#include -#include - -std::map extensionFunctions; - -void LoadExtensions() -{ - wchar_t path[MAX_PATH]; - wchar_t* end = path + GetModuleFileNameW(nullptr, path, MAX_PATH); - while (*(--end) != L'\\'); - *(end + 1) = L'*'; - *(end + 2) = L'\0'; - WIN32_FIND_DATAW fileData; - HANDLE file = FindFirstFileW(path, &fileData); - do - { - if (!(fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) - { - if (wcsstr(fileData.cFileName, L"_nexthooker_extension.dll")) - { - extensionFunctions[wcstoul(fileData.cFileName, nullptr, 10)] = (ExtensionFunction)GetProcAddress(LoadLibraryW(fileData.cFileName), "NewSentence"); - } - } - } while (FindNextFileW(file, &fileData) != 0); -} - -std::wstring DispatchSentenceToExtensions(std::wstring sentence, DWORD64 info) -{ - for (auto extension : extensionFunctions) - { - sentence = extension.second(sentence, info); - } - return sentence; -} \ No newline at end of file diff --git a/vnr/extensions/Extensions.h b/vnr/extensions/Extensions.h deleted file mode 100644 index 4a08691..0000000 --- a/vnr/extensions/Extensions.h +++ /dev/null @@ -1,6 +0,0 @@ -#include -#include - -typedef std::wstring (*ExtensionFunction)(std::wstring, DWORD64); -void LoadExtensions(); -std::wstring DispatchSentenceToExtensions(std::wstring sentence, DWORD64 info); \ No newline at end of file diff --git a/vnr/texthook/CMakeLists.txt b/vnr/texthook/CMakeLists.txt index d577ea8..ffeaeeb 100644 --- a/vnr/texthook/CMakeLists.txt +++ b/vnr/texthook/CMakeLists.txt @@ -11,13 +11,11 @@ set(vnrhost_src host.h pipe.h textthread.h + winmutex.h hookman.cc host.cc pipe.cc textthread.cc - ${PROJECT_SOURCE_DIR}/winmutex/winmutex.h - ${PROJECT_SOURCE_DIR}/extensions/Extensions.cpp - ${PROJECT_SOURCE_DIR}/extensions/Extensions.h ) add_library(vnrhost SHARED ${vnrhost_src}) diff --git a/vnr/texthook/hookman.cc b/vnr/texthook/hookman.cc index 53e71fd..7566695 100644 --- a/vnr/texthook/hookman.cc +++ b/vnr/texthook/hookman.cc @@ -12,7 +12,7 @@ #include "vnrhook/include/const.h" #include "vnrhook/include/defs.h" #include "vnrhook/include/types.h" -#include "winmutex/winmutex.h" +#include "winmutex.h" #include #define HM_LOCK CriticalSectionLocker hmLocker(hmCs) // Synchronized scope for accessing private data diff --git a/vnr/texthook/host.cc b/vnr/texthook/host.cc index 71c73fc..74e6cc1 100644 --- a/vnr/texthook/host.cc +++ b/vnr/texthook/host.cc @@ -7,7 +7,6 @@ #include "vnrhook/include/const.h" #include "vnrhook/include/defs.h" #include "vnrhook/include/types.h" -#include "extensions/Extensions.h" HANDLE preventDuplicationMutex; @@ -58,7 +57,6 @@ DLLEXPORT bool StartHost() } else { - LoadExtensions(); ::running = true; ::man = new HookManager; return true; diff --git a/vnr/texthook/textthread.cc b/vnr/texthook/textthread.cc index ed35928..7481d5c 100644 --- a/vnr/texthook/textthread.cc +++ b/vnr/texthook/textthread.cc @@ -8,8 +8,7 @@ #include "host.h" #include "textthread.h" #include "vnrhook/include/const.h" -#include "extensions/Extensions.h" -#include "winmutex/winmutex.h" +#include "winmutex.h" extern HookManager* man; extern HWND dummyWindow; @@ -54,7 +53,7 @@ void TextThread::AddSentence() sentence = std::wstring(converted, MultiByteToWideChar(932, 0, sentenceBuffer.data(), sentenceBuffer.size(), converted, sentenceBuffer.size())); delete[] converted; } - AddSentence(DispatchSentenceToExtensions(sentence, status)); + AddSentence(sentence); sentenceBuffer.clear(); } @@ -62,7 +61,7 @@ void TextThread::AddSentence(std::wstring sentence) { TT_LOCK; sentence.append(L"\r\n"); - if (output) output(this, sentence); + if (output) sentence = output(this, sentence); storage.append(sentence); } diff --git a/vnr/texthook/textthread.h b/vnr/texthook/textthread.h index 4409d7d..be7857e 100644 --- a/vnr/texthook/textthread.h +++ b/vnr/texthook/textthread.h @@ -25,7 +25,7 @@ struct ThreadParameter #define CURRENT_SELECT 0x1000 class TextThread; -typedef void(*ThreadOutputCallback)(TextThread*, std::wstring data); +typedef std::wstring(*ThreadOutputCallback)(TextThread*, std::wstring data); //extern DWORD split_time,repeat_count,global_filter,cyclic_remove; diff --git a/vnr/winmutex/winmutex.h b/vnr/texthook/winmutex.h similarity index 100% rename from vnr/winmutex/winmutex.h rename to vnr/texthook/winmutex.h