From e14c5436c2e14ad182e613e99bb7a80c3ff9fbbe Mon Sep 17 00:00:00 2001 From: Tau Date: Thu, 8 Nov 2018 16:02:03 -0500 Subject: [PATCH] minihook: Add security override hook --- meson.build | 2 ++ minihook/dllmain.c | 39 +++++++++++++++++++++++++++++++++++++++ minihook/meson.build | 18 ++++++++++++++++++ minihook/minihook.def | 4 ++++ 4 files changed, 63 insertions(+) create mode 100644 minihook/dllmain.c create mode 100644 minihook/meson.build create mode 100644 minihook/minihook.def diff --git a/meson.build b/meson.build index 499c09e..989637a 100644 --- a/meson.build +++ b/meson.build @@ -21,3 +21,5 @@ subdir('board') subdir('jvs') subdir('nu') subdir('util') + +subdir('minihook') diff --git a/minihook/dllmain.c b/minihook/dllmain.c new file mode 100644 index 0000000..7865bfc --- /dev/null +++ b/minihook/dllmain.c @@ -0,0 +1,39 @@ +#include + +#include "hook/process.h" + +#include "nu/ds.h" +#include "nu/nusec.h" + +#include "util/dprintf.h" + +static process_entry_t app_startup; + +static DWORD CALLBACK app_pre_startup(void) +{ + dprintf("--- Begin %s ---\n", __func__); + + ds_hook_init(); + nusec_hook_init(); + + dprintf("--- End %s ---\n", __func__); + + return app_startup(); +} + +BOOL WINAPI DllMain(HMODULE mod, DWORD cause, void *ctx) +{ + HRESULT hr; + + if (cause != DLL_PROCESS_ATTACH) { + return TRUE; + } + + hr = process_hijack_startup(app_pre_startup, &app_startup); + + if (!SUCCEEDED(hr)) { + dprintf("Failed to hijack process startup: %x\n", (int) hr); + } + + return SUCCEEDED(hr); +} diff --git a/minihook/meson.build b/minihook/meson.build new file mode 100644 index 0000000..5dd71a1 --- /dev/null +++ b/minihook/meson.build @@ -0,0 +1,18 @@ +shared_library( + 'minihook', + name_prefix : '', + include_directories: inc, + implicit_include_directories : false, + vs_module_defs : 'minihook.def', + c_pch : '../precompiled.h', + dependencies : [ + capnhook.get_variable('hook_dep'), + ], + link_with : [ + nu_lib, + util_lib, + ], + sources : [ + 'dllmain.c', + ], +) diff --git a/minihook/minihook.def b/minihook/minihook.def new file mode 100644 index 0000000..d9cbc6d --- /dev/null +++ b/minihook/minihook.def @@ -0,0 +1,4 @@ +LIBRARY minihook + +EXPORTS + DllMain@12 @1 NONAME