refactor more
This commit is contained in:
parent
13c2bfed2f
commit
61fb3248fe
14
host/host.cc
14
host/host.cc
@ -6,6 +6,7 @@
|
|||||||
#include "const.h"
|
#include "const.h"
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
#include "../vnrhook/hijack/texthook.h"
|
#include "../vnrhook/hijack/texthook.h"
|
||||||
|
#include <atlbase.h> // A2W
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@ -21,7 +22,6 @@ namespace
|
|||||||
ThreadEventCallback OnCreate, OnRemove;
|
ThreadEventCallback OnCreate, OnRemove;
|
||||||
ProcessEventCallback OnAttach, OnDetach;
|
ProcessEventCallback OnAttach, OnDetach;
|
||||||
|
|
||||||
bool operator==(const ThreadParam& one, const ThreadParam& two) { return one.pid == two.pid && one.hook == two.hook && one.retn == two.retn && one.spl == two.spl; }
|
|
||||||
std::unordered_map<ThreadParam, TextThread*> textThreadsByParams;
|
std::unordered_map<ThreadParam, TextThread*> textThreadsByParams;
|
||||||
std::unordered_map<DWORD, ProcessRecord> processRecordsByIds;
|
std::unordered_map<DWORD, ProcessRecord> processRecordsByIds;
|
||||||
|
|
||||||
@ -201,22 +201,22 @@ namespace Host
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DetachProcess(DWORD processId)
|
void DetachProcess(DWORD processId)
|
||||||
{
|
{
|
||||||
int command = HOST_COMMAND_DETACH;
|
int command = HOST_COMMAND_DETACH;
|
||||||
return WriteFile(processRecordsByIds[processId].hostPipe, &command, sizeof(command), DUMMY, nullptr);
|
WriteFile(processRecordsByIds[processId].hostPipe, &command, sizeof(command), DUMMY, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InsertHook(DWORD pid, HookParam hp, std::string name)
|
void InsertHook(DWORD pid, HookParam hp, std::string name)
|
||||||
{
|
{
|
||||||
auto info = InsertHookCmd(hp, name);
|
auto info = InsertHookCmd(hp, name);
|
||||||
return WriteFile(processRecordsByIds[pid].hostPipe, &info, sizeof(info), DUMMY, nullptr);
|
WriteFile(processRecordsByIds[pid].hostPipe, &info, sizeof(info), DUMMY, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RemoveHook(DWORD pid, unsigned __int64 addr)
|
void RemoveHook(DWORD pid, unsigned __int64 addr)
|
||||||
{
|
{
|
||||||
auto info = RemoveHookCmd(addr);
|
auto info = RemoveHookCmd(addr);
|
||||||
return WriteFile(processRecordsByIds[pid].hostPipe, &info, sizeof(info), DUMMY, nullptr);
|
WriteFile(processRecordsByIds[pid].hostPipe, &info, sizeof(info), DUMMY, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
HookParam GetHookParam(DWORD pid, unsigned __int64 addr)
|
HookParam GetHookParam(DWORD pid, unsigned __int64 addr)
|
||||||
|
10
host/host.h
10
host/host.h
@ -14,11 +14,13 @@ namespace Host
|
|||||||
{
|
{
|
||||||
void Start(ProcessEventCallback onAttach, ProcessEventCallback onDetach, ThreadEventCallback onCreate, ThreadEventCallback onRemove);
|
void Start(ProcessEventCallback onAttach, ProcessEventCallback onDetach, ThreadEventCallback onCreate, ThreadEventCallback onRemove);
|
||||||
void Close();
|
void Close();
|
||||||
bool InjectProcess(DWORD pid, DWORD timeout = 5000);
|
|
||||||
bool DetachProcess(DWORD pid);
|
|
||||||
|
|
||||||
bool InsertHook(DWORD pid, HookParam hp, std::string name = "");
|
bool InjectProcess(DWORD pid, DWORD timeout = 5000);
|
||||||
bool RemoveHook(DWORD pid, unsigned __int64 addr);
|
void DetachProcess(DWORD pid);
|
||||||
|
|
||||||
|
void InsertHook(DWORD pid, HookParam hp, std::string name = "");
|
||||||
|
void RemoveHook(DWORD pid, unsigned __int64 addr);
|
||||||
|
|
||||||
HookParam GetHookParam(DWORD pid, unsigned __int64 addr);
|
HookParam GetHookParam(DWORD pid, unsigned __int64 addr);
|
||||||
HookParam GetHookParam(ThreadParam tp);
|
HookParam GetHookParam(ThreadParam tp);
|
||||||
std::wstring GetHookName(DWORD pid, unsigned __int64 addr);
|
std::wstring GetHookName(DWORD pid, unsigned __int64 addr);
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <atlbase.h> // A2W
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
@ -30,7 +30,6 @@ struct HookParam
|
|||||||
HANDLE readerHandle; // Artikash 8/4/2018: handle for reader thread
|
HANDLE readerHandle; // Artikash 8/4/2018: handle for reader thread
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct ThreadParam // From hook, used internally by host as well
|
struct ThreadParam // From hook, used internally by host as well
|
||||||
{
|
{
|
||||||
DWORD pid; // jichi: 5/11/2014: The process ID
|
DWORD pid; // jichi: 5/11/2014: The process ID
|
||||||
@ -40,6 +39,7 @@ struct ThreadParam // From hook, used internally by host as well
|
|||||||
};
|
};
|
||||||
// Artikash 5/31/2018: required for unordered_map to work with struct key
|
// Artikash 5/31/2018: required for unordered_map to work with struct key
|
||||||
template <> struct std::hash<ThreadParam> { size_t operator()(const ThreadParam& tp) const { return std::hash<__int64>()((tp.pid + tp.hook) ^ (tp.retn + tp.spl)); } };
|
template <> struct std::hash<ThreadParam> { size_t operator()(const ThreadParam& tp) const { return std::hash<__int64>()((tp.pid + tp.hook) ^ (tp.retn + tp.spl)); } };
|
||||||
|
static bool operator==(const ThreadParam& one, const ThreadParam& two) { return one.pid == two.pid && one.hook == two.hook && one.retn == two.retn && one.spl == two.spl; }
|
||||||
|
|
||||||
struct InsertHookCmd // From host
|
struct InsertHookCmd // From host
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user