clean up hook manager a little (remove unused stuff)

This commit is contained in:
Akash Mozumdar 2018-05-31 04:44:33 -04:00
parent f8cb81ec59
commit ca6ec15ac8
4 changed files with 17 additions and 49 deletions

View File

@ -709,11 +709,6 @@ DWORD RemoveProcessList(DWORD pid)
return 0; return 0;
} }
DWORD RefreshProfileOnNewHook(DWORD pid)
{
return 0;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
switch (message) switch (message)
@ -750,7 +745,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
AddToCombo(*console, false); AddToCombo(*console, false);
man->RegisterProcessAttachCallback(RegisterProcessList); man->RegisterProcessAttachCallback(RegisterProcessList);
man->RegisterProcessDetachCallback(RemoveProcessList); man->RegisterProcessDetachCallback(RemoveProcessList);
man->RegisterProcessNewHookCallback(RefreshProfileOnNewHook); //man->RegisterProcessNewHookCallback(RefreshProfileOnNewHook); Artikash 5/30/2018 TODO: Finish implementing this.
man->RegisterAddRemoveLinkCallback(AddRemoveLink); man->RegisterAddRemoveLinkCallback(AddRemoveLink);
man->RegisterConsoleCallback(ConsoleOutput); man->RegisterConsoleCallback(ConsoleOutput);
StartHost(); StartHost();

View File

@ -208,20 +208,9 @@ HookManager::~HookManager()
//DeleteCriticalSection(&hmcs); //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<ThreadParameter *,DWORD> *node = Search(&tp);
return node ? thread_table->FindThread(node->data) : nullptr;
}
TextThread *HookManager::FindSingle(DWORD number) TextThread *HookManager::FindSingle(DWORD number)
{ return (number & 0x80008000) ? nullptr : thread_table->FindThread(number); } { return (number & 0x80008000) ? nullptr : thread_table->FindThread(number); }
void HookManager::DetachProcess(DWORD pid) {}
void HookManager::SetCurrent(TextThread *it) void HookManager::SetCurrent(TextThread *it)
{ {
if (current) if (current)
@ -707,8 +696,6 @@ ProcessRecord *HookManager::GetProcessRecord(DWORD pid)
//return pr; //return pr;
} }
DWORD HookManager::GetCurrentPID() { return current_pid; }
HANDLE HookManager::GetCmdHandleByPID(DWORD pid) HANDLE HookManager::GetCmdHandleByPID(DWORD pid)
{ {
HM_LOCK; HM_LOCK;
@ -734,8 +721,6 @@ MK_BASIC_TYPE(LPVOID)
// return hash; // return hash;
//} //}
DWORD GetCurrentPID() { return ::man->GetCurrentPID(); }
HANDLE GetCmdHandleByPID(DWORD pid) { return ::man->GetCmdHandleByPID(pid); } HANDLE GetCmdHandleByPID(DWORD pid) { return ::man->GetCmdHandleByPID(pid); }
//void AddLink(WORD from, WORD to) { ::man->AddLink(from, to); } //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) void HookManager::AddThreadsToProfile(Profile& pf, const ProcessRecord& pr, DWORD pid)
{ {
HM_LOCK; HM_LOCK;
ThreadTable* table = Table(); for (int i = 0; i < thread_table->Used(); ++i)
for (int i = 0; i < table->Used(); ++i)
{ {
TextThread* tt = table->FindThread(i); TextThread* tt = thread_table->FindThread(i);
if (tt == NULL || tt->GetThreadParameter()->pid != pid) if (tt == NULL || tt->GetThreadParameter()->pid != pid)
continue; continue;
//if (tt->Status() & CURRENT_SELECT || tt->Link() || tt->GetComment()) //if (tt->Status() & CURRENT_SELECT || tt->Link() || tt->GetComment())

View File

@ -7,6 +7,7 @@
#include "host/avl_p.h" #include "host/avl_p.h"
#include "host/textthread.h" #include "host/textthread.h"
#include "winmutex/winmutex.h" #include "winmutex/winmutex.h"
#include <unordered_map>
namespace pugi { namespace pugi {
class xml_node; class xml_node;
@ -40,16 +41,22 @@ struct IHFSERVICE TLen { int operator()(const ThreadParameter *t); };
typedef DWORD (*ProcessEventCallback)(DWORD pid); typedef DWORD (*ProcessEventCallback)(DWORD pid);
struct ThreadParameterHasher
{
size_t operator()(const ThreadParameter& tp)
{
return std::hash<DWORD>()(tp.pid << 6) + std::hash<DWORD>()(tp.hook) + std::hash<DWORD>()(tp.retn) + std::hash<DWORD>()(tp.spl);
}
};
class IHFSERVICE HookManager : public AVLTree<ThreadParameter, DWORD, TCmp, TCpy, TLen> class IHFSERVICE HookManager : public AVLTree<ThreadParameter, DWORD, TCmp, TCpy, TLen>
{ {
public: public:
HookManager(); HookManager();
~HookManager(); ~HookManager();
// jichi 12/26/2013: remove virtual modifiers // jichi 12/26/2013: remove virtual modifiers
TextThread *FindSingle(DWORD pid, DWORD hook, DWORD retn, DWORD split);
TextThread *FindSingle(DWORD number); TextThread *FindSingle(DWORD number);
ProcessRecord *GetProcessRecord(DWORD pid); ProcessRecord *GetProcessRecord(DWORD pid);
DWORD GetProcessIDByPath(LPCWSTR str); // private
void RemoveSingleThread(DWORD number); void RemoveSingleThread(DWORD number);
//void LockHookman(); //void LockHookman();
//void UnlockHookman(); //void UnlockHookman();
@ -59,7 +66,6 @@ public:
void UnLink(WORD from); void UnLink(WORD from);
void UnLinkAll(WORD from); void UnLinkAll(WORD from);
void SelectCurrent(DWORD num); void SelectCurrent(DWORD num);
void DetachProcess(DWORD pid);
void SetCurrent(TextThread *it); void SetCurrent(TextThread *it);
void AddConsoleOutput(LPCWSTR text); void AddConsoleOutput(LPCWSTR text);
@ -75,7 +81,6 @@ public:
void UnRegisterProcess(DWORD pid); void UnRegisterProcess(DWORD pid);
//void SetName(DWORD); //void SetName(DWORD);
DWORD GetCurrentPID(); // private
HANDLE GetCmdHandleByPID(DWORD pid); HANDLE GetCmdHandleByPID(DWORD pid);
ConsoleCallback RegisterConsoleCallback(ConsoleCallback cf) ConsoleCallback RegisterConsoleCallback(ConsoleCallback cf)
@ -102,25 +107,15 @@ public:
ProcessEventCallback RegisterProcessDetachCallback(ProcessEventCallback cf) ProcessEventCallback RegisterProcessDetachCallback(ProcessEventCallback cf)
{ return (ProcessEventCallback)_InterlockedExchange((long*)&detach,(long)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 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 OnThreadCreate(pugi::xml_node profile_node, TextThread* thread);
void GetProfile(DWORD pid, pugi::xml_node profile_node); void GetProfile(DWORD pid, pugi::xml_node profile_node);
private: private:
std::unordered_map<ThreadParameter, TextThread*, ThreadParameterHasher> threadTable;
std::unordered_map<DWORD, ProcessRecord*> processRecordsByIds;
typedef win_mutex<CRITICAL_SECTION> mutex_type; typedef win_mutex<CRITICAL_SECTION> mutex_type;
mutex_type hmcs; mutex_type hmcs;

View File

@ -131,13 +131,7 @@ DWORD WINAPI TextReceiver(LPVOID lpThreadParameter)
{ {
switch (commandType) switch (commandType)
{ {
case HOST_NOTIFICATION_NEWHOOK: case HOST_NOTIFICATION_NEWHOOK: // Artikash 5/30/2018: Useless for now, but could be handy to implement something later
{
static long lock;
while (InterlockedExchange(&lock, 1) == 1);
man->ProcessNewHook()(processId);
lock = 0;
}
break; break;
case HOST_NOTIFICATION_TEXT: case HOST_NOTIFICATION_TEXT:
USES_CONVERSION; USES_CONVERSION;