2016-01-06 00:01:17 +09:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// hookman.h
|
|
|
|
// 8/23/2013 jichi
|
|
|
|
// Branch: ITH/HookManager.h, rev 133
|
|
|
|
|
2018-07-19 00:46:52 -04:00
|
|
|
#include <Windows.h>
|
2018-07-18 16:18:43 -04:00
|
|
|
#include "textthread.h"
|
2018-05-31 04:44:33 -04:00
|
|
|
#include <unordered_map>
|
2018-07-17 19:18:36 -04:00
|
|
|
#include <string>
|
|
|
|
#include "vnrhook/include/types.h"
|
2016-01-06 00:01:17 +09:00
|
|
|
|
2018-07-19 00:46:52 -04:00
|
|
|
struct ProcessRecord
|
|
|
|
{
|
2016-01-06 00:01:17 +09:00
|
|
|
HANDLE process_handle;
|
|
|
|
HANDLE hookman_mutex;
|
|
|
|
HANDLE hookman_section;
|
|
|
|
LPVOID hookman_map;
|
2018-06-01 02:36:51 -04:00
|
|
|
HANDLE hostPipe;
|
2018-07-17 19:18:36 -04:00
|
|
|
};
|
|
|
|
|
2018-07-18 16:18:43 -04:00
|
|
|
typedef DWORD(*ProcessEventCallback)(DWORD pid);
|
|
|
|
typedef DWORD(*ThreadEventCallback)(TextThread*);
|
2016-01-06 00:01:17 +09:00
|
|
|
|
2018-05-31 04:44:33 -04:00
|
|
|
struct ThreadParameterHasher
|
|
|
|
{
|
2018-05-31 05:40:00 -04:00
|
|
|
size_t operator()(const ThreadParameter& tp) const
|
2018-05-31 04:44:33 -04:00
|
|
|
{
|
|
|
|
return std::hash<DWORD>()(tp.pid << 6) + std::hash<DWORD>()(tp.hook) + std::hash<DWORD>()(tp.retn) + std::hash<DWORD>()(tp.spl);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-19 00:46:52 -04:00
|
|
|
class __declspec(dllexport) HookManager
|
2016-01-06 00:01:17 +09:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
HookManager();
|
|
|
|
~HookManager();
|
2018-07-19 00:46:52 -04:00
|
|
|
|
2016-01-06 00:01:17 +09:00
|
|
|
TextThread *FindSingle(DWORD number);
|
|
|
|
ProcessRecord *GetProcessRecord(DWORD pid);
|
2018-07-19 00:46:52 -04:00
|
|
|
HANDLE GetHostPipe(DWORD pid);
|
2016-01-06 00:01:17 +09:00
|
|
|
void ClearCurrent();
|
|
|
|
void SelectCurrent(DWORD num);
|
|
|
|
void SetCurrent(TextThread *it);
|
|
|
|
void AddConsoleOutput(LPCWSTR text);
|
2018-07-19 00:46:52 -04:00
|
|
|
void DispatchText(DWORD pid, DWORD hook, DWORD retn, DWORD split, const BYTE *text, int len);
|
2016-01-06 00:01:17 +09:00
|
|
|
void RemoveProcessContext(DWORD pid); // private
|
|
|
|
void RemoveSingleHook(DWORD pid, DWORD addr);
|
2018-06-01 02:36:51 -04:00
|
|
|
void RegisterProcess(DWORD pid, HANDLE hostPipe);
|
2016-01-06 00:01:17 +09:00
|
|
|
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);
|
2016-01-06 00:01:17 +09:00
|
|
|
|
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; }
|
2016-01-06 00:01:17 +09:00
|
|
|
|
2018-07-17 17:01:56 -04:00
|
|
|
void SetSplitInterval(unsigned int splitDelay) { this->splitDelay = splitDelay; }
|
|
|
|
|
2016-01-06 00:01:17 +09:00
|
|
|
private:
|
2018-07-17 19:18:36 -04:00
|
|
|
std::unordered_map<ThreadParameter, TextThread*, ThreadParameterHasher> textThreadsByParams;
|
2018-05-31 04:44:33 -04:00
|
|
|
std::unordered_map<DWORD, ProcessRecord*> processRecordsByIds;
|
|
|
|
|
2018-06-12 17:31:24 -04:00
|
|
|
CRITICAL_SECTION hmcs;
|
2016-01-06 00:01:17 +09:00
|
|
|
|
|
|
|
TextThread *current;
|
|
|
|
|
2018-07-19 00:46:52 -04:00
|
|
|
ThreadEventCallback create, remove, reset;
|
|
|
|
ProcessEventCallback attach, detach;
|
|
|
|
|
|
|
|
WORD nextThreadNumber;
|
2018-07-17 17:01:56 -04:00
|
|
|
unsigned int splitDelay;
|
2016-01-06 00:01:17 +09:00
|
|
|
};
|
|
|
|
|
|
|
|
// EOF
|