37 for (
DWORD i = 0; i < Region->HooksCount; i++)
39 if (NULL != Region->Hooks[i])
46 ERROR(
"[ERROR] IntHookGvaRemoveHook failed: 0x%08x\n", status);
70 Region->Object->RegionsRemoved =
TRUE;
176 if (NULL == Callback)
183 ERROR(
"[ERROR] Trying to hook (%d) [%llx - %llx] with callback %p\n",
184 Type, Gla, Gla + Length, Callback);
210 if (NULL == pReg->
Hooks)
213 goto cleanup_and_exit;
216 for (
QWORD gva = Gla; gva < Gla + Length; )
218 QWORD left = Gla + Length - gva;
233 ERROR(
"[ERROR] IntHookGvaSetHook failed for GVA 0x%016llx: 0x%08x\n", gva, status);
234 goto cleanup_and_exit;
254 ERROR(
"[ERROR] IntHookObjectRemoveRegionInternal failed: 0x%08x\n", status2);
285 for (
DWORD i = 0; i < Region->HooksCount; i++)
287 if (NULL != Region->Hooks[i])
292 ERROR(
"[ERROR] IntHookGvaDeleteHook failed: 0x%08x\n", failStatus);
346 ERROR(
"[ERROR] IntHookObjectRemoveRegionInternal failed: 0x%08x\n", status);
395 list = (*Object)->Regions.
Flink;
396 while (list != &(*Object)->Regions)
405 ERROR(
"[ERROR] IntHookObjectRemoveRegionInternal failed: 0x%08x\n", status);
411 (*Object)->RegionsRemoved =
TRUE;
426 _In_ void *HookObject,
442 if (HookObject == NULL)
450 while (list != &pObject->
Regions)
494 LOG(
"[ERROR] There should be no hook objects remaining... Got one: (%llx, %d)!\n",
497 while (list2 != &pObj->
Regions)
501 list2 = list2->
Flink;
506 ERROR(
"[ERROR] IntHookObjectRemoveRegionInternal failed: 0x%08x\n", status);
559 list2 = list2->
Flink;
571 ERROR(
"[ERROR] IntHookObjectDeleteRegion failed: 0x%08x\n", status);
632 ERROR(
"[ERROR] IntHookObjectDestroyAll failed: 0x%08x\n", status);
LIST_HEAD RemovedRegions
All the removed regions are inserted here. The regions must be committed in the exact same order they...
INTSTATUS IntHookObjectCommit(void)
Commit removed hook objects and regions.
#define CONTAINING_RECORD(List, Type, Member)
BOOLEAN Dirty
Set whenever hooks are added or removed.
INTSTATUS IntHookObjectHookRegion(void *Object, QWORD Cr3, QWORD Gla, SIZE_T Length, BYTE Type, void *Callback, void *Context, DWORD Flags, HOOK_REGION_DESCRIPTOR **Region)
Hook a contiguous region of virtual memory inside the provided virtual address space.
void * Context
User-defined data that will be supplied to the callback.
static void InsertHeadList(LIST_ENTRY *ListHead, LIST_ENTRY *Entry)
void ** Hooks
Array of hooks. They will usually be HOOK_GVA objects.
#define INT_STATUS_SUCCESS
#define PAGE_REMAINING(addr)
INTSTATUS IntHookGvaDeleteHook(HOOK_GVA **Hook, DWORD Flags)
Completely delete a GVA hook.
void * IntHookObjectFindRegion(QWORD Gva, void *HookObject, BYTE HookType)
Searches for a region of hooked memory inside the provided hook object.
struct _LIST_ENTRY * Flink
static INTSTATUS IntHookObjectDestroyAll(DWORD Flags)
Destroy all existing hook objects.
#define INT_SUCCESS(Status)
#define HOOK_FLG_DISABLED
If flag is set, the hook is disabled, therefore ignored on EPT violations.
INTSTATUS IntHookObjectCreate(DWORD ObjectType, QWORD Cr3, void **Object)
Create a new hook object.
BYTE EptHookType
The type of the hook in EPT (see IG_EPT_HOOK_TYPE)
PHOOK_OBJECT_DESCRIPTOR Object
Parent object. Optional, but it is strongly recommended to link a region to an object.
DWORD ObjectType
One of the INTRO_OBJECT_TYPE values.
#define INT_STATUS_NOT_NEEDED_HINT
INTSTATUS IntHookObjectRemoveRegion(HOOK_REGION_DESCRIPTOR **Region, DWORD Flags)
Remove a hooked region of memory.
An entire hook region, consisting of multiple GVA hooks.
#define HpAllocWithTag(Len, Tag)
int INTSTATUS
The status data type.
HOOK_STATE * gHooks
Global hooks state.
BOOLEAN ObjectsRemoved
True whenever an object has been removed.
INTSTATUS IntHookObjectUninit(void)
Uninit the hook object system.
QWORD HookStart
Guest virtual address of the hooked region.
INTSTATUS IntHookGvaSetHook(QWORD Cr3, QWORD Gva, DWORD Length, BYTE Type, void *Callback, void *Context, void *ParentHook, DWORD Flags, HOOK_GVA **GvaHook)
Set a read, write, execute or swap hook on a guest virtual address.
BYTE HookType
The type of the hook structure (see _HOOK_TYPE)
#define HOOK_FLG_GLOBAL_MASK
Global flags must be defined here and must be handled by each hooks layer (even if it ignores them...
QWORD HookLength
Length of the hooked region. May span multiple pages.
static BOOLEAN RemoveEntryList(LIST_ENTRY *Entry)
BOOLEAN RegionsRemoved
True if regions have been removed from this object (used by the commit function). ...
void * ParentHook
The parent hook. For a GPA hook, for example, a GVA hook or a PagedHook will be the parent hook...
#define HOOK_FLG_CHAIN_DELETE
If flag is set, then we won't remove the hook on commit phase; we'll let the parent hook handle the d...
Measures the deletion of HOOK_REGION_DESCRIPTOR objects.
LIST_ENTRY Link
The list entry element.
#define IN_RANGE_LEN(x, start, len)
HOOK_HEADER Header
The hook header.
static INTSTATUS IntHookObjectDeleteRegion(HOOK_REGION_DESCRIPTOR *Region, DWORD Flags)
Permanently deletes the indicated region.
#define HpFreeAndNullWithTag(Add, Tag)
static void InsertTailList(LIST_ENTRY *ListHead, LIST_ENTRY *Entry)
INTSTATUS IntHookGvaRemoveHook(HOOK_GVA **Hook, DWORD Flags)
Remove a GVA hook.
static void InitializeListHead(LIST_ENTRY *ListHead)
#define UNREFERENCED_PARAMETER(P)
HOOK_OBJECT_STATE Objects
Object hooks state.
LIST_HEAD Objects
List of objects.
#define INT_STATUS_NOT_INITIALIZED_HINT
QWORD Cr3
The CR3 of the object. If this is a kernel object, Cr3 must be 0.
#define INT_STATUS_INVALID_PARAMETER_1
INTSTATUS IntHookObjectDestroy(HOOK_OBJECT_DESCRIPTOR **Object, DWORD Flags)
Destroy an entire hook object. All regions belonging to this object will be removed.
DWORD Flags
Generic flags. Check out EPT Hook flags.
static INTSTATUS IntHookObjectRemoveRegionInternal(HOOK_REGION_DESCRIPTOR *Region, DWORD Flags)
Remove a hooked region of memory.
LIST_ENTRY Link
The list entry element.
INTSTATUS IntHookObjectInit(void)
Initialize the hook object system.
DWORD HooksCount
Number of hooks set for this region of memory.
#define HOOK_FLG_REMOVE
If flag is set, the hook has been removed, and waits the next commit to be actually deleted...
#define INT_STATUS_INVALID_PARAMETER_7
#define INT_STATUS_INSUFFICIENT_RESOURCES
#define INT_STATUS_INVALID_PARAMETER_3