Textractor/texthook/hookman.h

71 lines
2.0 KiB
C
Raw Normal View History

#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"
#include <unordered_map>
#include <string>
2018-07-20 16:26:27 -04:00
#include "../vnrhook/include/types.h"
2018-07-19 01:43:31 -04:00
struct ProcessRecord
2018-07-19 00:46:52 -04:00
{
2018-07-19 01:43:31 -04:00
HANDLE process_handle;
HANDLE hookman_mutex;
HANDLE hookman_section;
LPVOID hookman_map;
HANDLE hostPipe;
};
2018-07-21 15:30:42 -07:00
typedef void(*ProcessEventCallback)(DWORD pid);
typedef void(*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-19 13:34:26 -04:00
// Artikash 7/19/2018: This should probably be broken up into 2-4 classes...
2018-07-19 00:46:52 -04:00
class __declspec(dllexport) HookManager
{
public:
2018-07-19 01:43:31 -04:00
HookManager();
~HookManager();
2018-07-19 00:46:52 -04:00
2018-07-22 18:10:00 -07:00
TextThread* FindSingle(DWORD number);
2018-07-21 11:09:07 -07:00
void AddConsoleOutput(std::wstring text);
2018-07-19 01:43:31 -04:00
void DispatchText(DWORD pid, DWORD hook, DWORD retn, DWORD split, const BYTE *text, int len);
2018-07-22 18:10:00 -07:00
void RemoveThreads(bool(*RemoveIf)(ThreadParameter, ThreadParameter), ThreadParameter cmp);
2018-07-19 01:43:31 -04:00
void RegisterProcess(DWORD pid, HANDLE hostPipe);
void UnRegisterProcess(DWORD pid);
2018-07-22 18:10:00 -07:00
HANDLE GetHostPipe(DWORD pid);
2018-07-19 01:43:31 -04:00
HookParam GetHookParam(DWORD pid, DWORD addr);
std::wstring GetHookName(DWORD pid, DWORD addr);
2018-07-19 01:43:31 -04:00
void RegisterThreadCreateCallback(ThreadEventCallback cf) { create = cf; }
void RegisterThreadRemoveCallback(ThreadEventCallback cf) { remove = cf; }
void RegisterProcessAttachCallback(ProcessEventCallback cf) { attach = cf; }
void RegisterProcessDetachCallback(ProcessEventCallback cf) { detach = cf; }
2018-07-19 01:43:31 -04:00
void SetSplitInterval(unsigned int splitDelay) { this->splitDelay = splitDelay; }
2018-07-17 17:01:56 -04:00
private:
std::unordered_map<ThreadParameter, TextThread*, ThreadParameterHasher> textThreadsByParams;
std::unordered_map<DWORD, ProcessRecord> processRecordsByIds;
2018-07-19 01:43:31 -04:00
CRITICAL_SECTION hmCs;
2018-07-21 14:16:26 -07:00
ThreadEventCallback create, remove;
2018-07-19 01:43:31 -04:00
ProcessEventCallback attach, detach;
2018-07-19 00:46:52 -04:00
2018-07-19 01:43:31 -04:00
WORD nextThreadNumber;
unsigned int splitDelay;
};
// EOF