113 lines
3.1 KiB
C
113 lines
3.1 KiB
C
#ifndef HOOKS_H
|
|
#define HOOKS_H
|
|
|
|
////////////////////////////////
|
|
// Hooks
|
|
|
|
//// HOOK_POINT ////
|
|
|
|
typedef struct HookPoint{
|
|
String8 name;
|
|
} HookPoint;
|
|
|
|
#define SYMBOL_SET_DEFINE HOOK_POINT
|
|
#define HOOK_POINT_Type HookPoint
|
|
#define HOOK_POINT_elf_section ".sy.hookpoint"
|
|
#define HOOK_POINT_coff_a_section ".sy$hookpoint_a"
|
|
#define HOOK_POINT_coff_m_section ".sy$hookpoint_m"
|
|
#define HOOK_POINT_coff_z_section ".sy$hookpoint_z"
|
|
#define HOOK_POINT_marker hookpoint
|
|
#include "symbol_set.define.h"
|
|
|
|
#define HOOK_POINT_STRUCT(N) \
|
|
SyDefine(HOOK_POINT, N) = { .name = str8_const(#N) }; \
|
|
typedef struct HookPointType_##N HookPointType_##N; struct HookPointType_##N
|
|
|
|
#define HOOK_POINT_TYPE_DEF(N,T) \
|
|
SyDefine(HOOK_POINT, N) = { .name = str8_const(#N) }; \
|
|
typedef T HookPointType_##N
|
|
|
|
#define HOOK_POINT_TYPE(N) HookPointType_##N
|
|
|
|
//// PROCESS_TYPE ////
|
|
|
|
typedef struct ProcessType{
|
|
String8 name;
|
|
} ProcessType;
|
|
|
|
#define SYMBOL_SET_DEFINE PROCESS_TYPE
|
|
#define PROCESS_TYPE_Type ProcessType
|
|
#define PROCESS_TYPE_elf_section ".sy.processtype"
|
|
#define PROCESS_TYPE_coff_a_section ".sy$processtype_a"
|
|
#define PROCESS_TYPE_coff_m_section ".sy$processtype_m"
|
|
#define PROCESS_TYPE_coff_z_section ".sy$processtype_z"
|
|
#define PROCESS_TYPE_marker processtype
|
|
#include "symbol_set.define.h"
|
|
|
|
#define PROCESS_TYPE(N) SyDefine(PROCESS_TYPE, N) = { .name = str8_const(#N) }
|
|
|
|
//// PROCESS-HOOK ////
|
|
|
|
typedef struct Ctx Ctx;
|
|
typedef void HookFunc(Ctx *ctx, void *params);
|
|
|
|
typedef struct ProcessHook{
|
|
SY__UAddr process_type_id;
|
|
SY__UAddr hook_point_id;
|
|
HookFunc *func;
|
|
} ProcessHook;
|
|
|
|
#define SYMBOL_SET_DEFINE PROCESS_HOOK
|
|
#define PROCESS_HOOK_Type ProcessHook
|
|
#define PROCESS_HOOK_elf_section ".sy.processhook"
|
|
#define PROCESS_HOOK_coff_a_section ".sy$processhook_a"
|
|
#define PROCESS_HOOK_coff_m_section ".sy$processhook_m"
|
|
#define PROCESS_HOOK_coff_z_section ".sy$processhook_z"
|
|
#define PROCESS_HOOK_marker processhook
|
|
#include "symbol_set.define.h"
|
|
|
|
#define PROCESS_HOOK(PR,HP) \
|
|
static void processhook__##PR##_##HP(Ctx *ctx, HookPointType_##HP *params); \
|
|
SyDefineUnnamed(PROCESS_HOOK) = { \
|
|
.process_type_id = SyRaw(PROCESS_TYPE, PR), \
|
|
.hook_point_id = SyRaw(HOOK_POINT, HP), \
|
|
.func = (HookFunc*)processhook__##PR##_##HP }; \
|
|
static void processhook__##PR##_##HP(Ctx *ctx, HookPointType_##HP *params)
|
|
|
|
#if SY__MAIN
|
|
SY_INIT(PROCESS_HOOK){
|
|
for (SyEach(PROCESS_HOOK, link)){
|
|
link->process_type_id = SyIDFromRaw(PROCESS_TYPE, link->process_type_id);
|
|
link->hook_point_id = SyIDFromRaw(HOOK_POINT, link->hook_point_id);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
//// Rules ////
|
|
|
|
typedef struct Rules{
|
|
U32 hook_point_count;
|
|
U32 process_type_count;
|
|
HookPoint *hook_points;
|
|
ProcessType *process_types;
|
|
|
|
HookFunc **func__process_hook; // [process_type][hook_point]->func
|
|
} Rules;
|
|
|
|
static Rules rules_from_symbol_sets(Arena *arena);
|
|
static HookFunc* rules_func_from_process_hook(Rules *rules, U32 process_type_id, U32 hook_point_id);
|
|
|
|
//// CTX ////
|
|
|
|
struct Ctx{
|
|
Rules *rules;
|
|
|
|
U32 process_type_id[100];
|
|
U32 process_count;
|
|
};
|
|
|
|
static void ctx_new_process(Ctx *ctx, U32 process_type_id);
|
|
static void ctx_hook_all_processes(Ctx *ctx, U32 hook_id, void *params);
|
|
|
|
#endif //HOOKS_H
|