Refactored dynamically linking ntdll
This commit is contained in:
parent
9f011ff103
commit
35cd117ffc
@ -27,10 +27,32 @@ typedef union _LDR_DLL_NOTIFICATION_DATA {
|
|||||||
|
|
||||||
typedef void (*LdrDllNotification_t)(ULONG reason, const PLDR_DLL_NOTIFICATION_DATA data, void *context);
|
typedef void (*LdrDllNotification_t)(ULONG reason, const PLDR_DLL_NOTIFICATION_DATA data, void *context);
|
||||||
|
|
||||||
typedef NTSTATUS (*LdrRegisterDllNotification_t)(ULONG flags, LdrDllNotification_t notificationFunction, void *context, void **cookie);
|
#define DYNAMIC_FN_TYPE(ret, name, args) typedef ret (*name##_t)args
|
||||||
typedef NTSTATUS (*LdrUnregisterDllNotification_t)(void *cookie);
|
|
||||||
|
|
||||||
extern LdrRegisterDllNotification_t LdrRegisterDllNotification;
|
#ifdef NTDLL_DYNAMIC_LINK_IMPL
|
||||||
extern LdrUnregisterDllNotification_t LdrUnregisterDllNotification;
|
#define DYNAMIC_FN_VAR(name) extern name##_t name; name##_t name
|
||||||
|
#else
|
||||||
|
#define DYNAMIC_FN_VAR(name) extern name##_t name
|
||||||
|
#endif
|
||||||
|
|
||||||
void ntdll_link();
|
#define DYNAMIC_FN_DEF(ret, name, args) DYNAMIC_FN_TYPE(ret, name, args); DYNAMIC_FN_VAR(name)
|
||||||
|
|
||||||
|
DYNAMIC_FN_DEF(NTSTATUS, LdrRegisterDllNotification, (ULONG flags, LdrDllNotification_t notification, void *context, void **cookie));
|
||||||
|
DYNAMIC_FN_DEF(NTSTATUS, LdrUnregisterDllNotification, (void *cookie));
|
||||||
|
|
||||||
|
#ifdef NTDLL_DYNAMIC_LINK_IMPL
|
||||||
|
#define DYNAMIC_FN_LINK(module, name) name = (name##_t)GetProcAddress(module, #name)
|
||||||
|
|
||||||
|
static void _ntdll_link() {
|
||||||
|
HMODULE ntdll = GetModuleHandleA("ntdll.dll");
|
||||||
|
|
||||||
|
DYNAMIC_FN_LINK(ntdll, LdrRegisterDllNotification);
|
||||||
|
DYNAMIC_FN_LINK(ntdll, LdrUnregisterDllNotification);
|
||||||
|
}
|
||||||
|
|
||||||
|
#undef DYNAMIC_FN_LINK
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#undef DYNAMIC_FN_TYPE
|
||||||
|
#undef DYNAMIC_FN_VAR
|
||||||
|
#undef DYNAMIC_FN_DEF
|
||||||
|
@ -5,7 +5,6 @@ include_dir = include_directories('include')
|
|||||||
# Input files
|
# Input files
|
||||||
sources = [
|
sources = [
|
||||||
'src/main.c',
|
'src/main.c',
|
||||||
'src/ntdll.c',
|
|
||||||
'src/ace.c',
|
'src/ace.c',
|
||||||
'src/pe.c',
|
'src/pe.c',
|
||||||
'src/game.c',
|
'src/game.c',
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
|
|
||||||
#include <ntdll.h>
|
|
||||||
#include <ace.h>
|
#include <ace.h>
|
||||||
#include <game.h>
|
#include <game.h>
|
||||||
#include <core.h>
|
#include <core.h>
|
||||||
@ -8,6 +7,9 @@
|
|||||||
#include <msg.h>
|
#include <msg.h>
|
||||||
#include <tx.h>
|
#include <tx.h>
|
||||||
|
|
||||||
|
#define NTDLL_DYNAMIC_LINK_IMPL
|
||||||
|
#include <ntdll.h>
|
||||||
|
|
||||||
#include <main.h>
|
#include <main.h>
|
||||||
|
|
||||||
HMODULE this_module;
|
HMODULE this_module;
|
||||||
@ -76,7 +78,7 @@ BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved) {
|
|||||||
this_module = instance;
|
this_module = instance;
|
||||||
|
|
||||||
// Dynamically link functions from ntdll
|
// Dynamically link functions from ntdll
|
||||||
ntdll_link();
|
_ntdll_link();
|
||||||
|
|
||||||
// Detect which game the user is trying to run
|
// Detect which game the user is trying to run
|
||||||
struct game_data game;
|
struct game_data game;
|
||||||
|
@ -1,11 +0,0 @@
|
|||||||
#include <ntdll.h>
|
|
||||||
|
|
||||||
LdrRegisterDllNotification_t LdrRegisterDllNotification;
|
|
||||||
LdrUnregisterDllNotification_t LdrUnregisterDllNotification;
|
|
||||||
|
|
||||||
void ntdll_link() {
|
|
||||||
HMODULE ntdll = GetModuleHandleA("ntdll.dll");
|
|
||||||
|
|
||||||
LdrRegisterDllNotification = (LdrRegisterDllNotification_t)GetProcAddress(ntdll, "LdrRegisterDllNotification");
|
|
||||||
LdrUnregisterDllNotification = (LdrUnregisterDllNotification_t)GetProcAddress(ntdll, "LdrUnregisterDllNotification");
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user