diff --git a/hook/meson.build b/hook/meson.build index 019c6fe..c3ed5fd 100644 --- a/hook/meson.build +++ b/hook/meson.build @@ -3,6 +3,8 @@ hook_lib = static_library( include_directories : inc, c_pch : '../precompiled.h', sources : [ + 'peb.c', + 'peb.h', ], ) diff --git a/hook/peb.c b/hook/peb.c new file mode 100644 index 0000000..7c05353 --- /dev/null +++ b/hook/peb.c @@ -0,0 +1,50 @@ +#include +#include + +#include + +#include "hook/peb.h" + +static const PEB *peb_get(void) +{ +#ifdef __amd64 + return (const PEB *) __readgsqword(0x60); +#else + return (const PEB *) __readfsdword(0x30); +#endif +} + +const peb_dll_t *peb_dll_get_first(void) +{ + const PEB *peb; + const LIST_ENTRY *node; + + peb = peb_get(); + node = peb->Ldr->InMemoryOrderModuleList.Flink; + + return CONTAINING_RECORD(node, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks); +} + +const peb_dll_t *peb_dll_get_next(const peb_dll_t *dll) +{ + const PEB *peb; + const LIST_ENTRY *node; + + assert(dll != NULL); + + peb = peb_get(); + node = dll->InMemoryOrderLinks.Flink; + + if (node == peb->Ldr->InMemoryOrderModuleList.Flink) { + return NULL; + } + + return CONTAINING_RECORD(node, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks); +} + +HMODULE peb_dll_get_base(const peb_dll_t *dll) +{ + assert(dll != NULL); + + return dll->DllBase; +} diff --git a/hook/peb.h b/hook/peb.h new file mode 100644 index 0000000..6c10cf8 --- /dev/null +++ b/hook/peb.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +typedef LDR_DATA_TABLE_ENTRY peb_dll_t; + +const peb_dll_t *peb_dll_get_first(void); +const peb_dll_t *peb_dll_get_next(const peb_dll_t *dll); +HMODULE peb_dll_get_base(const peb_dll_t *dll); +char *peb_dll_dup_name(const peb_dll_t *dll);