84 lines
2.3 KiB
C
Raw Normal View History

#pragma once
// hookman.h
// 8/23/2013 jichi
// Branch: ITH/HookManager.h, rev 133
#include "config.h"
2018-07-18 16:18:43 -04:00
#include "textthread.h"
#include "winmutex/winmutex.h"
#include <unordered_map>
#include <string>
#include "vnrhook/include/types.h"
struct ProcessRecord {
HANDLE process_handle;
HANDLE hookman_mutex;
HANDLE hookman_section;
LPVOID hookman_map;
HANDLE hostPipe;
};
2018-07-18 16:18:43 -04:00
typedef DWORD(*ProcessEventCallback)(DWORD pid);
typedef DWORD(*ThreadEventCallback)(TextThread*);
struct ThreadParameterHasher
{
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);
}
};
2018-07-17 17:01:56 -04:00
class DLLEXPORT HookManager
{
public:
HookManager();
~HookManager();
TextThread *FindSingle(DWORD number);
ProcessRecord *GetProcessRecord(DWORD pid);
void ClearCurrent();
void SelectCurrent(DWORD num);
void SetCurrent(TextThread *it);
void AddConsoleOutput(LPCWSTR text);
// jichi 10/27/2013: Add const; add space.
2018-06-17 21:04:04 -04:00
void DispatchText(DWORD pid, const BYTE *text, DWORD hook, DWORD retn, DWORD split, int len);
void RemoveProcessContext(DWORD pid); // private
void RemoveSingleHook(DWORD pid, DWORD addr);
void RegisterProcess(DWORD pid, HANDLE hostPipe);
void UnRegisterProcess(DWORD pid);
2018-07-18 23:40:44 -04:00
HookParam GetHookParam(DWORD pid, DWORD addr);
std::wstring GetHookName(DWORD pid, DWORD addr);
//void SetName(DWORD);
2018-07-17 17:01:56 -04:00
HANDLE GetHostPipe(DWORD pid);
2018-07-18 16:18:43 -04:00
void RegisterThreadCreateCallback(ThreadEventCallback cf) { create = cf; }
void RegisterThreadRemoveCallback(ThreadEventCallback cf) { remove = cf; }
void RegisterThreadResetCallback(ThreadEventCallback cf) { reset = cf; }
void RegisterProcessAttachCallback(ProcessEventCallback cf) { attach = cf; }
void RegisterProcessDetachCallback(ProcessEventCallback cf) { detach = cf; }
2018-07-17 17:01:56 -04:00
void SetSplitInterval(unsigned int splitDelay) { this->splitDelay = splitDelay; }
private:
std::unordered_map<ThreadParameter, TextThread*, ThreadParameterHasher> textThreadsByParams;
std::unordered_map<DWORD, ProcessRecord*> processRecordsByIds;
2018-06-12 17:31:24 -04:00
CRITICAL_SECTION hmcs;
TextThread *current;
ThreadEventCallback create,
2018-07-18 16:18:43 -04:00
remove,
reset;
ProcessEventCallback attach,
2018-07-18 16:18:43 -04:00
detach;
WORD register_count,
2018-07-18 16:18:43 -04:00
new_thread_number;
2018-07-17 17:01:56 -04:00
unsigned int splitDelay;
};
// EOF