2018-08-23 11:53:23 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "const.h"
|
|
|
|
|
|
|
|
// jichi 3/7/2014: Add guessed comment
|
|
|
|
struct HookParam
|
|
|
|
{
|
|
|
|
// jichi 8/24/2013: For special hooks.
|
|
|
|
typedef void(*text_fun_t)(DWORD esp, HookParam *hp, BYTE index, DWORD *data, DWORD *split, DWORD *len);
|
|
|
|
typedef bool(*filter_fun_t)(LPVOID str, DWORD *len, HookParam *hp, BYTE index); // jichi 10/24/2014: Add filter function. Return true if skip the text
|
|
|
|
typedef bool(*hook_fun_t)(DWORD esp, HookParam *hp); // jichi 10/24/2014: Add generic hook function, return false if stop execution.
|
|
|
|
|
2018-10-11 12:58:30 -04:00
|
|
|
uint64_t insertion_address; // absolute address
|
|
|
|
uint64_t address; // absolute or relative address (not changed by TextHook)
|
2018-08-26 22:21:15 -04:00
|
|
|
int offset, // offset of the data in the memory
|
2018-08-23 11:53:23 -04:00
|
|
|
index, // deref_offset1
|
|
|
|
split, // offset of the split character
|
|
|
|
split_index; // deref_offset2
|
2018-10-11 12:58:30 -04:00
|
|
|
wchar_t module[MAX_MODULE_SIZE];
|
|
|
|
char function[MAX_MODULE_SIZE];
|
2018-08-23 11:53:23 -04:00
|
|
|
DWORD type; // flags
|
2018-10-30 20:50:50 -04:00
|
|
|
UINT codepage; // text encoding
|
2018-08-23 11:53:23 -04:00
|
|
|
WORD length_offset; // index of the string length
|
|
|
|
DWORD user_value; // 7/20/2014: jichi additional parameters for PSP games
|
|
|
|
|
|
|
|
text_fun_t text_fun;
|
|
|
|
filter_fun_t filter_fun;
|
|
|
|
hook_fun_t hook_fun;
|
|
|
|
};
|
|
|
|
|
2018-08-24 12:50:20 -04:00
|
|
|
struct ThreadParam // From hook, used internally by host as well
|
2018-08-23 11:53:23 -04:00
|
|
|
{
|
|
|
|
DWORD pid; // jichi: 5/11/2014: The process ID
|
2018-09-20 21:59:07 -04:00
|
|
|
uint64_t hook; // Artikash 6/6/2018: The insertion address of the hook
|
|
|
|
uint64_t retn; // jichi 5/11/2014: The return address of the hook
|
|
|
|
uint64_t spl; // jichi 5/11/2014: the processed split value of the hook paramete
|
2018-08-23 11:53:23 -04:00
|
|
|
};
|
2018-08-24 12:50:20 -04:00
|
|
|
// Artikash 5/31/2018: required for unordered_map to work with struct key
|
2018-09-20 21:59:07 -04:00
|
|
|
template <> struct std::hash<ThreadParam> { size_t operator()(const ThreadParam& tp) const { return std::hash<int64_t>()((tp.pid + tp.hook) ^ (tp.retn + tp.spl)); } };
|
2018-08-24 14:04:23 -04:00
|
|
|
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; }
|
2018-08-23 11:53:23 -04:00
|
|
|
|
2018-10-31 12:04:32 -04:00
|
|
|
class WinMutex
|
|
|
|
{
|
|
|
|
HANDLE mutex;
|
|
|
|
public:
|
|
|
|
WinMutex(std::wstring name) : mutex(CreateMutexW(nullptr, false, name.c_str())) {}
|
|
|
|
~WinMutex() { ReleaseMutex(mutex); CloseHandle(mutex); }
|
|
|
|
void lock() { WaitForSingleObject(mutex, 0); }
|
|
|
|
void unlock() { ReleaseMutex(mutex); }
|
|
|
|
};
|
|
|
|
|
2018-08-23 11:53:23 -04:00
|
|
|
struct InsertHookCmd // From host
|
|
|
|
{
|
2018-10-31 12:04:32 -04:00
|
|
|
InsertHookCmd(HookParam hp, std::string name = "") : hp(hp) { strcpy_s<HOOK_NAME_SIZE>(this->name, name.c_str()); };
|
2018-08-23 11:53:23 -04:00
|
|
|
int command = HOST_COMMAND_NEW_HOOK;
|
|
|
|
HookParam hp;
|
2018-10-31 12:04:32 -04:00
|
|
|
char name[HOOK_NAME_SIZE] = {};
|
2018-08-23 11:53:23 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct RemoveHookCmd // From host
|
|
|
|
{
|
2018-09-20 21:59:07 -04:00
|
|
|
RemoveHookCmd(uint64_t address) : address(address) {};
|
2018-08-23 11:53:23 -04:00
|
|
|
int command = HOST_COMMAND_REMOVE_HOOK;
|
2018-09-20 21:59:07 -04:00
|
|
|
uint64_t address;
|
2018-08-23 11:53:23 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ConsoleOutputNotif // From hook
|
|
|
|
{
|
2018-09-22 15:45:54 -04:00
|
|
|
ConsoleOutputNotif(std::string message = "") { strcpy_s<MESSAGE_SIZE>(this->message, message.c_str()); };
|
2018-08-23 11:53:23 -04:00
|
|
|
int command = HOST_NOTIFICATION_TEXT;
|
|
|
|
char message[MESSAGE_SIZE] = {};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct HookRemovedNotif // From hook
|
|
|
|
{
|
2018-09-20 21:59:07 -04:00
|
|
|
HookRemovedNotif(uint64_t address) : address(address) {};
|
2018-08-23 11:53:23 -04:00
|
|
|
int command = HOST_NOTIFICATION_RMVHOOK;
|
2018-09-20 21:59:07 -04:00
|
|
|
uint64_t address;
|
2018-08-23 11:53:23 -04:00
|
|
|
};
|
2018-08-24 12:50:20 -04:00
|
|
|
|
2018-10-31 12:04:32 -04:00
|
|
|
#define LOCK(mutex) std::lock_guard lock(mutex)
|