remove extension code from host

This commit is contained in:
Akash Mozumdar 2018-07-20 17:21:35 -04:00
parent f4980d6eb6
commit a290c36b52
9 changed files with 8 additions and 54 deletions

View File

@ -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); if (thread->Status() & CURRENT_SELECT) texts->AddText(output, false);
return output;
} }
bool GetHookParam(DWORD pid, DWORD hook_addr, HookParam& hp) bool GetHookParam(DWORD pid, DWORD hook_addr, HookParam& hp)

View File

@ -1,36 +0,0 @@
#include "Extensions.h"
#include <Windows.h>
#include <map>
#include <vector>
std::map<DWORD, ExtensionFunction> 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;
}

View File

@ -1,6 +0,0 @@
#include <Windows.h>
#include <string>
typedef std::wstring (*ExtensionFunction)(std::wstring, DWORD64);
void LoadExtensions();
std::wstring DispatchSentenceToExtensions(std::wstring sentence, DWORD64 info);

View File

@ -11,13 +11,11 @@ set(vnrhost_src
host.h host.h
pipe.h pipe.h
textthread.h textthread.h
winmutex.h
hookman.cc hookman.cc
host.cc host.cc
pipe.cc pipe.cc
textthread.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}) add_library(vnrhost SHARED ${vnrhost_src})

View File

@ -12,7 +12,7 @@
#include "vnrhook/include/const.h" #include "vnrhook/include/const.h"
#include "vnrhook/include/defs.h" #include "vnrhook/include/defs.h"
#include "vnrhook/include/types.h" #include "vnrhook/include/types.h"
#include "winmutex/winmutex.h" #include "winmutex.h"
#include <atlbase.h> #include <atlbase.h>
#define HM_LOCK CriticalSectionLocker hmLocker(hmCs) // Synchronized scope for accessing private data #define HM_LOCK CriticalSectionLocker hmLocker(hmCs) // Synchronized scope for accessing private data

View File

@ -7,7 +7,6 @@
#include "vnrhook/include/const.h" #include "vnrhook/include/const.h"
#include "vnrhook/include/defs.h" #include "vnrhook/include/defs.h"
#include "vnrhook/include/types.h" #include "vnrhook/include/types.h"
#include "extensions/Extensions.h"
HANDLE preventDuplicationMutex; HANDLE preventDuplicationMutex;
@ -58,7 +57,6 @@ DLLEXPORT bool StartHost()
} }
else else
{ {
LoadExtensions();
::running = true; ::running = true;
::man = new HookManager; ::man = new HookManager;
return true; return true;

View File

@ -8,8 +8,7 @@
#include "host.h" #include "host.h"
#include "textthread.h" #include "textthread.h"
#include "vnrhook/include/const.h" #include "vnrhook/include/const.h"
#include "extensions/Extensions.h" #include "winmutex.h"
#include "winmutex/winmutex.h"
extern HookManager* man; extern HookManager* man;
extern HWND dummyWindow; extern HWND dummyWindow;
@ -54,7 +53,7 @@ void TextThread::AddSentence()
sentence = std::wstring(converted, MultiByteToWideChar(932, 0, sentenceBuffer.data(), sentenceBuffer.size(), converted, sentenceBuffer.size())); sentence = std::wstring(converted, MultiByteToWideChar(932, 0, sentenceBuffer.data(), sentenceBuffer.size(), converted, sentenceBuffer.size()));
delete[] converted; delete[] converted;
} }
AddSentence(DispatchSentenceToExtensions(sentence, status)); AddSentence(sentence);
sentenceBuffer.clear(); sentenceBuffer.clear();
} }
@ -62,7 +61,7 @@ void TextThread::AddSentence(std::wstring sentence)
{ {
TT_LOCK; TT_LOCK;
sentence.append(L"\r\n"); sentence.append(L"\r\n");
if (output) output(this, sentence); if (output) sentence = output(this, sentence);
storage.append(sentence); storage.append(sentence);
} }

View File

@ -25,7 +25,7 @@ struct ThreadParameter
#define CURRENT_SELECT 0x1000 #define CURRENT_SELECT 0x1000
class TextThread; 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; //extern DWORD split_time,repeat_count,global_filter,cyclic_remove;