Textractor_test/include/types.h

118 lines
4.3 KiB
C
Raw Permalink Normal View History

2018-08-23 23:53:23 +08:00
#pragma once
#include "const.h"
class WinMutex // Like CMutex but works with scoped_lock
{
public:
WinMutex(std::wstring name = L"", LPSECURITY_ATTRIBUTES sa = nullptr) : m(CreateMutexW(sa, FALSE, name.empty() ? NULL : name.c_str())) {}
void lock() { if (m) WaitForSingleObject(m, INFINITE); }
void unlock() { if (m) ReleaseMutex(m); }
private:
AutoHandle<> m;
};
2019-02-19 12:12:12 +08:00
inline SECURITY_ATTRIBUTES allAccess = std::invoke([] // allows non-admin processes to access kernel objects made by admin processes
{
static SECURITY_DESCRIPTOR sd = {};
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
return SECURITY_ATTRIBUTES{ sizeof(SECURITY_ATTRIBUTES), &sd, FALSE };
});
2018-08-23 23:53:23 +08:00
// jichi 3/7/2014: Add guessed comment
2018-12-31 11:11:23 +08:00
struct HookParam
2018-08-23 23:53:23 +08:00
{
uint64_t address; // absolute or relative address
2018-08-27 10:21:15 +08:00
int offset, // offset of the data in the memory
2018-08-23 23:53:23 +08:00
index, // deref_offset1
split, // offset of the split character
2019-03-28 11:35:22 +08:00
split_index, // deref_offset2
null_length;
wchar_t module[MAX_MODULE_SIZE];
char function[MAX_MODULE_SIZE];
2018-08-23 23:53:23 +08:00
DWORD type; // flags
2018-10-31 08:50:50 +08:00
UINT codepage; // text encoding
2018-12-21 23:10:51 +08:00
short length_offset; // index of the string length
2019-06-18 16:48:48 +08:00
uintptr_t padding; // padding before string
2018-08-23 23:53:23 +08:00
DWORD user_value; // 7/20/2014: jichi additional parameters for PSP games
2019-02-03 05:54:13 +08:00
void(*text_fun)(DWORD stack, HookParam* hp, BYTE obsoleteAlwaysZero, DWORD* data, DWORD* split, DWORD* len);
2019-11-24 01:44:26 +08:00
bool(*filter_fun)(void* data, DWORD* len, HookParam* hp, BYTE obsoleteAlwaysZero); // jichi 10/24/2014: Add filter function. Return false to skip the text
2019-02-03 05:54:13 +08:00
bool(*hook_fun)(DWORD stack, HookParam* hp); // jichi 10/24/2014: Add generic hook function, return false if stop execution.
2019-06-18 16:48:48 +08:00
int(*length_fun)(uintptr_t stack, uintptr_t data); // data after padding added
2018-12-02 04:52:12 +08:00
char name[HOOK_NAME_SIZE];
2018-08-23 23:53:23 +08:00
};
2018-11-05 09:48:46 +08:00
struct ThreadParam
2018-08-23 23:53:23 +08:00
{
2019-01-10 11:35:01 +08:00
bool operator==(ThreadParam other) const { return processId == other.processId && addr == other.addr && ctx == other.ctx && ctx2 == other.ctx2; }
2018-11-05 09:48:46 +08:00
DWORD processId;
uint64_t addr;
uint64_t ctx; // The context of the hook: by default the first value on stack, usually the return address
uint64_t ctx2; // The subcontext of the hook: 0 by default, generated in a method specific to the hook
2018-08-23 23:53:23 +08:00
};
2019-06-02 14:09:17 +08:00
struct SearchParam
{
BYTE pattern[PATTERN_SIZE] = { x64 ? 0xcc : 0x55, x64 ? 0xcc : 0x8b, x64 ? 0x48 : 0xec, 0x89 }; // pattern in memory to search for
int length = x64 ? 4 : 3, // length of pattern (zero means this SearchParam is invalid and the default should be used)
offset = x64 ? 2 : 0, // offset from start of pattern to add hook
2021-03-08 23:41:34 +08:00
searchTime = 30000, // ms
maxRecords = 100000,
codepage = SHIFT_JIS;
uintptr_t padding = 0, // same as hook param padding
minAddress = 0, maxAddress = (uintptr_t)-1; // hook all functions between these addresses (used only if both modules empty)
wchar_t boundaryModule[MAX_MODULE_SIZE] = {}; // hook all functions within this module (middle priority)
wchar_t exportModule[MAX_MODULE_SIZE] = {}; // hook the exports of this module (highest priority)
wchar_t text[PATTERN_SIZE] = {}; // text to search for
void(*hookPostProcessor)(HookParam&) = nullptr;
2019-06-02 14:09:17 +08:00
};
2018-08-23 23:53:23 +08:00
struct InsertHookCmd // From host
{
2018-12-31 11:11:23 +08:00
InsertHookCmd(HookParam hp) : hp(hp) {}
2019-02-22 02:09:44 +08:00
HostCommandType command = HOST_COMMAND_NEW_HOOK;
2018-08-23 23:53:23 +08:00
HookParam hp;
};
2019-06-10 13:49:11 +08:00
struct RemoveHookCmd // From host
{
RemoveHookCmd(uint64_t address) : address(address) {}
HostCommandType command = HOST_COMMAND_REMOVE_HOOK;
uint64_t address;
};
2019-06-02 14:09:17 +08:00
struct FindHookCmd // From host
{
FindHookCmd(SearchParam sp) : sp(sp) {}
HostCommandType command = HOST_COMMAND_FIND_HOOK;
SearchParam sp;
};
struct ConsoleOutputNotif // From dll
2018-08-23 23:53:23 +08:00
{
ConsoleOutputNotif(std::string message = "") { strncpy_s(this->message, message.c_str(), MESSAGE_SIZE - 1); }
2019-02-22 02:09:44 +08:00
HostNotificationType command = HOST_NOTIFICATION_TEXT;
2018-08-23 23:53:23 +08:00
char message[MESSAGE_SIZE] = {};
};
2019-06-02 14:09:17 +08:00
struct HookFoundNotif // From dll
{
HookFoundNotif(HookParam hp, wchar_t* text) : hp(hp) { wcsncpy_s(this->text, text, MESSAGE_SIZE - 1); }
HostNotificationType command = HOST_NOTIFICATION_FOUND_HOOK;
HookParam hp;
wchar_t text[MESSAGE_SIZE] = {}; // though type is wchar_t, may not be encoded in UTF-16 (it's just convenient to use wcs* functions)
};
struct HookRemovedNotif // From dll
2018-08-23 23:53:23 +08:00
{
2018-09-21 09:59:07 +08:00
HookRemovedNotif(uint64_t address) : address(address) {};
2019-02-22 02:09:44 +08:00
HostNotificationType command = HOST_NOTIFICATION_RMVHOOK;
2018-09-21 09:59:07 +08:00
uint64_t address;
2018-08-23 23:53:23 +08:00
};