mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-23 17:04:12 +08:00
clean up hook manager a little (remove unused stuff)
This commit is contained in:
parent
f8cb81ec59
commit
ca6ec15ac8
@ -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();
|
||||
|
@ -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<ThreadParameter *,DWORD> *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())
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "host/avl_p.h"
|
||||
#include "host/textthread.h"
|
||||
#include "winmutex/winmutex.h"
|
||||
#include <unordered_map>
|
||||
|
||||
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<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>
|
||||
{
|
||||
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<ThreadParameter, TextThread*, ThreadParameterHasher> threadTable;
|
||||
std::unordered_map<DWORD, ProcessRecord*> processRecordsByIds;
|
||||
|
||||
typedef win_mutex<CRITICAL_SECTION> mutex_type;
|
||||
mutex_type hmcs;
|
||||
|
||||
|
@ -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)));
|
||||
|
Loading…
x
Reference in New Issue
Block a user