2024-03-23 10:11:57 +08:00
|
|
|
/**
|
|
|
|
veh_hook Vectored Exception Handler hooking library
|
|
|
|
Version: 24-March-2008
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef LIST_T_H_INCLUDED
|
|
|
|
#define LIST_T_H_INCLUDED
|
|
|
|
#include <windows.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include<functional>
|
|
|
|
// VEH Hooking types
|
|
|
|
#define VEH_HK_INT3 0
|
|
|
|
#define VEH_HK_MEM 1
|
|
|
|
#define VEH_HK_HW 2
|
|
|
|
// -
|
|
|
|
|
|
|
|
#define OPCODE_INT3 "\xCC"
|
|
|
|
|
|
|
|
|
|
|
|
//typedef void (*pfvoid)();
|
|
|
|
//typedef void (*newFuncType)(PCONTEXT);
|
2024-03-31 19:00:26 +08:00
|
|
|
using newFuncType = std::function<bool(PCONTEXT)>;
|
2024-03-23 10:11:57 +08:00
|
|
|
|
|
|
|
typedef struct veh_node
|
|
|
|
{
|
2024-03-31 19:00:26 +08:00
|
|
|
struct veh_node* last;
|
|
|
|
struct veh_node* next;
|
2024-03-23 10:11:57 +08:00
|
|
|
void* origFunc;
|
|
|
|
newFuncType newFunc;
|
|
|
|
void* handle;
|
|
|
|
DWORD hooktype;
|
|
|
|
void* baseAddr; // Address of the page in which origFunc resides.
|
|
|
|
BYTE origBaseByte;
|
|
|
|
DWORD OldProtect;
|
|
|
|
} veh_node_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
veh_node_t* head;
|
|
|
|
veh_node_t* tail;
|
|
|
|
} veh_list_t;
|
|
|
|
|
|
|
|
// VEH hook interface functions for creating and removing hooks.
|
2024-03-31 19:00:26 +08:00
|
|
|
bool add_veh_hook(void* origFunc, newFuncType newFunc, DWORD hook_type=VEH_HK_INT3);
|
2024-03-23 10:11:57 +08:00
|
|
|
bool remove_veh_hook(void* origFunc);
|
|
|
|
|
|
|
|
// The VEH dispathing function is called by Windows every time an exception is encountered.
|
|
|
|
// the function dispatches calls to the correct inctercept function.
|
|
|
|
LONG CALLBACK veh_dispatch(PEXCEPTION_POINTERS ExceptionInfo);
|
|
|
|
|
|
|
|
// Functions used internally by the library.
|
|
|
|
veh_list_t* new_veh_list();
|
2024-03-31 19:00:26 +08:00
|
|
|
veh_node_t* create_veh_node(void* origFunc, newFuncType newFunc, void* handle, DWORD hook_type);
|
|
|
|
void insert_veh_node(veh_list_t* list, veh_node_t*);
|
2024-04-02 02:25:13 +08:00
|
|
|
void remove_veh_node(veh_list_t* list, void* origFunc);
|
2024-03-24 16:50:41 +08:00
|
|
|
veh_node_t* get_veh_node(veh_list_t* list, void* origFunc, int range=0);
|
2024-03-23 10:11:57 +08:00
|
|
|
|
|
|
|
#endif // LIST_T_H_INCLUDED
|