diff --git a/gui/window.cpp b/gui/window.cpp index ab349b1..b35b31c 100644 --- a/gui/window.cpp +++ b/gui/window.cpp @@ -709,11 +709,6 @@ DWORD RemoveProcessList(DWORD pid) return 0; } -DWORD RefreshProfileOnNewHook(DWORD pid) -{ - return 0; -} - LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) @@ -750,7 +745,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) AddToCombo(*console, false); man->RegisterProcessAttachCallback(RegisterProcessList); man->RegisterProcessDetachCallback(RemoveProcessList); - man->RegisterProcessNewHookCallback(RefreshProfileOnNewHook); + //man->RegisterProcessNewHookCallback(RefreshProfileOnNewHook); Artikash 5/30/2018 TODO: Finish implementing this. man->RegisterAddRemoveLinkCallback(AddRemoveLink); man->RegisterConsoleCallback(ConsoleOutput); StartHost(); diff --git a/vnr/texthook/host/hookman.cc b/vnr/texthook/host/hookman.cc index 97abda6..cd26bfe 100644 --- a/vnr/texthook/host/hookman.cc +++ b/vnr/texthook/host/hookman.cc @@ -208,20 +208,9 @@ HookManager::~HookManager() //DeleteCriticalSection(&hmcs); } -TextThread *HookManager::FindSingle(DWORD pid, DWORD hook, DWORD retn, DWORD split) -{ - if (pid == 0) - return thread_table->FindThread(0); - ThreadParameter tp = {pid, hook, retn, split}; - TreeNode *node = Search(&tp); - return node ? thread_table->FindThread(node->data) : nullptr; -} - TextThread *HookManager::FindSingle(DWORD number) { return (number & 0x80008000) ? nullptr : thread_table->FindThread(number); } -void HookManager::DetachProcess(DWORD pid) {} - void HookManager::SetCurrent(TextThread *it) { if (current) @@ -707,8 +696,6 @@ ProcessRecord *HookManager::GetProcessRecord(DWORD pid) //return pr; } -DWORD HookManager::GetCurrentPID() { return current_pid; } - HANDLE HookManager::GetCmdHandleByPID(DWORD pid) { HM_LOCK; @@ -734,8 +721,6 @@ MK_BASIC_TYPE(LPVOID) // return hash; //} -DWORD GetCurrentPID() { return ::man->GetCurrentPID(); } - HANDLE GetCmdHandleByPID(DWORD pid) { return ::man->GetCmdHandleByPID(pid); } //void AddLink(WORD from, WORD to) { ::man->AddLink(from, to); } @@ -869,10 +854,9 @@ void MakeHookRelative(const ProcessRecord& pr, HookParam& hp) void HookManager::AddThreadsToProfile(Profile& pf, const ProcessRecord& pr, DWORD pid) { HM_LOCK; - ThreadTable* table = Table(); - for (int i = 0; i < table->Used(); ++i) + for (int i = 0; i < thread_table->Used(); ++i) { - TextThread* tt = table->FindThread(i); + TextThread* tt = thread_table->FindThread(i); if (tt == NULL || tt->GetThreadParameter()->pid != pid) continue; //if (tt->Status() & CURRENT_SELECT || tt->Link() || tt->GetComment()) diff --git a/vnr/texthook/host/hookman.h b/vnr/texthook/host/hookman.h index b54abcf..9ee1d45 100644 --- a/vnr/texthook/host/hookman.h +++ b/vnr/texthook/host/hookman.h @@ -7,6 +7,7 @@ #include "host/avl_p.h" #include "host/textthread.h" #include "winmutex/winmutex.h" +#include namespace pugi { class xml_node; @@ -40,16 +41,22 @@ struct IHFSERVICE TLen { int operator()(const ThreadParameter *t); }; typedef DWORD (*ProcessEventCallback)(DWORD pid); +struct ThreadParameterHasher +{ + size_t operator()(const ThreadParameter& tp) + { + return std::hash()(tp.pid << 6) + std::hash()(tp.hook) + std::hash()(tp.retn) + std::hash()(tp.spl); + } +}; + class IHFSERVICE HookManager : public AVLTree { public: HookManager(); ~HookManager(); // jichi 12/26/2013: remove virtual modifiers - TextThread *FindSingle(DWORD pid, DWORD hook, DWORD retn, DWORD split); TextThread *FindSingle(DWORD number); ProcessRecord *GetProcessRecord(DWORD pid); - DWORD GetProcessIDByPath(LPCWSTR str); // private void RemoveSingleThread(DWORD number); //void LockHookman(); //void UnlockHookman(); @@ -59,7 +66,6 @@ public: void UnLink(WORD from); void UnLinkAll(WORD from); void SelectCurrent(DWORD num); - void DetachProcess(DWORD pid); void SetCurrent(TextThread *it); void AddConsoleOutput(LPCWSTR text); @@ -75,7 +81,6 @@ public: void UnRegisterProcess(DWORD pid); //void SetName(DWORD); - DWORD GetCurrentPID(); // private HANDLE GetCmdHandleByPID(DWORD pid); ConsoleCallback RegisterConsoleCallback(ConsoleCallback cf) @@ -102,25 +107,15 @@ public: ProcessEventCallback RegisterProcessDetachCallback(ProcessEventCallback cf) { return (ProcessEventCallback)_InterlockedExchange((long*)&detach,(long)cf); } - ProcessEventCallback RegisterProcessNewHookCallback(ProcessEventCallback cf) - { return (ProcessEventCallback)_InterlockedExchange((long*)&hook,(long)cf); } - - ProcessEventCallback ProcessNewHook() { return hook; } - TextThread *GetCurrentThread() { return current; } // private - ProcessRecord *Records() { return record; } // private ThreadTable *Table() { return thread_table; } // private - //DWORD& SplitTime() { return split_time; } - //DWORD& RepeatCount() { return repeat_count; } - //DWORD& CyclicRemove() { return cyclic_remove; } - //DWORD& GlobalFilter() { return global_filter; } - void ConsoleOutput(LPCSTR text) { if (console) console(text); } // not thread safe - void ConsoleOutputW(LPCWSTR text) { if (wconsole) wconsole(text); } // not thread safe - void OnThreadCreate(pugi::xml_node profile_node, TextThread* thread); void GetProfile(DWORD pid, pugi::xml_node profile_node); private: + std::unordered_map threadTable; + std::unordered_map processRecordsByIds; + typedef win_mutex mutex_type; mutex_type hmcs; diff --git a/vnr/texthook/host/pipe.cc b/vnr/texthook/host/pipe.cc index 271da2e..d2f5d8e 100644 --- a/vnr/texthook/host/pipe.cc +++ b/vnr/texthook/host/pipe.cc @@ -131,14 +131,8 @@ DWORD WINAPI TextReceiver(LPVOID lpThreadParameter) { switch (commandType) { - case HOST_NOTIFICATION_NEWHOOK: - { - static long lock; - while (InterlockedExchange(&lock, 1) == 1); - man->ProcessNewHook()(processId); - lock = 0; - } - break; + case HOST_NOTIFICATION_NEWHOOK: // Artikash 5/30/2018: Useless for now, but could be handy to implement something later + break; case HOST_NOTIFICATION_TEXT: USES_CONVERSION; man->AddConsoleOutput(A2W((LPCSTR)(buffer + 8)));