mirror of
https://github.com/Artikash/Textractor.git
synced 2024-12-23 17:04:12 +08:00
start rewriting hookman with c++ 14 features
This commit is contained in:
parent
ca6ec15ac8
commit
97bca014e4
@ -149,6 +149,12 @@ void TCpy::operator()(ThreadParameter* t1, const ThreadParameter* t2)
|
||||
|
||||
int TLen::operator()(const ThreadParameter* t) { return 0; }
|
||||
|
||||
// Artikash 5/31/2018: required for unordered_map to work with struct key
|
||||
bool operator==(const ThreadParameter& one, const ThreadParameter& two)
|
||||
{
|
||||
return one.pid == two.pid && one.hook == two.hook && one.retn == two.retn && one.spl == two.spl;
|
||||
}
|
||||
|
||||
#define NAMED_PIPE_DISCONNECT 1
|
||||
//Class member of HookManger
|
||||
HookManager::HookManager() :
|
||||
@ -166,6 +172,8 @@ HookManager::HookManager() :
|
||||
, destroy_event(nullptr)
|
||||
, register_count(0)
|
||||
, new_thread_number(0)
|
||||
, threadTable()
|
||||
, processRecordsByIds()
|
||||
{
|
||||
// jichi 9/21/2013: zero memory
|
||||
::memset(record, 0, sizeof(record));
|
||||
@ -181,6 +189,10 @@ HookManager::HookManager() :
|
||||
head.data = 0;
|
||||
thread_table = new ThreadTable; // jichi 9/26/2013: zero memory in ThreadTable
|
||||
|
||||
TextThread* consoleTextThread = threadTable[{0, -1UL, -1UL, -1UL}] = new TextThread(0, -1, -1, -1, threadTable.size());
|
||||
consoleTextThread->Status() |= USING_UNICODE;
|
||||
SetCurrent(consoleTextThread);
|
||||
|
||||
TextThread *entry = new TextThread(0, -1,-1,-1, new_thread_number++); // jichi 9/26/2013: zero memory in TextThread
|
||||
thread_table->SetThread(0, entry);
|
||||
SetCurrent(entry);
|
||||
@ -197,19 +209,29 @@ HookManager::HookManager() :
|
||||
|
||||
HookManager::~HookManager()
|
||||
{
|
||||
// Artikash 5/31/2018: This is called when the program terminates, so Windows should automatically free all these resources.....right?
|
||||
//LARGE_INTEGER timeout={-1000*1000,-1};
|
||||
//IthBreak();
|
||||
NtWaitForSingleObject(destroy_event, 0, 0);
|
||||
NtClose(destroy_event);
|
||||
NtClose(cmd_pipes[0]);
|
||||
NtClose(recv_threads[0]);
|
||||
delete thread_table;
|
||||
delete head.key;
|
||||
//NtWaitForSingleObject(destroy_event, 0, 0);
|
||||
//NtClose(destroy_event);
|
||||
//NtClose(cmd_pipes[0]);
|
||||
//NtClose(recv_threads[0]);
|
||||
//delete thread_table;
|
||||
//delete head.key;
|
||||
//DeleteCriticalSection(&hmcs);
|
||||
}
|
||||
|
||||
TextThread *HookManager::FindSingle(DWORD number)
|
||||
{ return (number & 0x80008000) ? nullptr : thread_table->FindThread(number); }
|
||||
{
|
||||
for (auto i : threadTable)
|
||||
{
|
||||
if (i.second->Number() == number)
|
||||
{
|
||||
return i.second;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void HookManager::SetCurrent(TextThread *it)
|
||||
{
|
||||
@ -231,6 +253,19 @@ void HookManager::SelectCurrent(DWORD num)
|
||||
void HookManager::RemoveSingleHook(DWORD pid, DWORD addr)
|
||||
{
|
||||
HM_LOCK;
|
||||
for (auto i : threadTable)
|
||||
{
|
||||
if (i.second->PID() == pid && i.second->Addr() == addr)
|
||||
{
|
||||
if (remove)
|
||||
{
|
||||
remove(i.second);
|
||||
}
|
||||
delete i.second;
|
||||
threadTable[i.first] = nullptr;
|
||||
}
|
||||
}
|
||||
SetCurrent(0);
|
||||
//ConsoleOutput("vnrhost:RemoveSingleHook: lock");
|
||||
//EnterCriticalSection(&hmcs);
|
||||
DWORD max = thread_table->Used();
|
||||
|
@ -43,7 +43,7 @@ typedef DWORD (*ProcessEventCallback)(DWORD pid);
|
||||
|
||||
struct ThreadParameterHasher
|
||||
{
|
||||
size_t operator()(const ThreadParameter& tp)
|
||||
size_t operator()(const ThreadParameter& tp) const
|
||||
{
|
||||
return std::hash<DWORD>()(tp.pid << 6) + std::hash<DWORD>()(tp.hook) + std::hash<DWORD>()(tp.retn) + std::hash<DWORD>()(tp.spl);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user