refactor more

This commit is contained in:
Akash Mozumdar 2018-08-24 14:04:23 -04:00
parent 13c2bfed2f
commit 61fb3248fe
4 changed files with 14 additions and 13 deletions

View File

@ -6,6 +6,7 @@
#include "const.h"
#include "defs.h"
#include "../vnrhook/hijack/texthook.h"
#include <atlbase.h> // A2W
namespace
{
@ -21,7 +22,6 @@ namespace
ThreadEventCallback OnCreate, OnRemove;
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<DWORD, ProcessRecord> processRecordsByIds;
@ -201,22 +201,22 @@ namespace Host
return false;
}
bool DetachProcess(DWORD processId)
void DetachProcess(DWORD processId)
{
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);
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);
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)

View File

@ -14,11 +14,13 @@ namespace Host
{
void Start(ProcessEventCallback onAttach, ProcessEventCallback onDetach, ThreadEventCallback onCreate, ThreadEventCallback onRemove);
void Close();
bool InjectProcess(DWORD pid, DWORD timeout = 5000);
bool DetachProcess(DWORD pid);
bool InsertHook(DWORD pid, HookParam hp, std::string name = "");
bool RemoveHook(DWORD pid, unsigned __int64 addr);
bool InjectProcess(DWORD pid, DWORD timeout = 5000);
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(ThreadParam tp);
std::wstring GetHookName(DWORD pid, unsigned __int64 addr);

View File

@ -2,7 +2,6 @@
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <atlbase.h> // A2W
#include <string>
#include <vector>
#include <unordered_map>

View File

@ -30,7 +30,6 @@ struct HookParam
HANDLE readerHandle; // Artikash 8/4/2018: handle for reader thread
};
struct ThreadParam // From hook, used internally by host as well
{
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
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
{