Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "clink/modules/minhook"]
path = clink/modules/minhook
url = git@github.com:RaMMicHaeL/minhook.git
8 changes: 8 additions & 0 deletions clink/dll/dll_hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "shared/hook.h"
#include "shared/vm.h"
#include "shared/pe.h"
#include "../modules/minhook/include/MinHook.h"

//------------------------------------------------------------------------------
static int (*g_hook_trap)() = NULL;
Expand Down Expand Up @@ -135,6 +136,13 @@ int apply_hooks(const hook_decl_t* hooks, int hook_count)
void* addr;
void* self;
int i;
MH_STATUS status;

status = MH_Initialize();
if (status != MH_OK)
{
return 0;
}

// Each hook needs fixing up, so we find the base address of our module.
self = get_alloc_base(apply_hooks);
Expand Down
3 changes: 3 additions & 0 deletions clink/dll/shell_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "shell.h"
#include "dll_hooks.h"
#include "shared/util.h"
#include "../modules/minhook/include/MinHook.h"

//------------------------------------------------------------------------------
int get_clink_setting_int(const char*);
Expand Down Expand Up @@ -459,6 +460,8 @@ static int cmd_initialise(void* base)
//------------------------------------------------------------------------------
static void cmd_shutdown()
{
MH_STATUS status;
status = MH_Uninitialize();
}

// vim: expandtab
1 change: 1 addition & 0 deletions clink/modules/minhook
Submodule minhook added at 080492
8 changes: 8 additions & 0 deletions clink/modules/minhook.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

// Just a cl wrapper for minhook Win32/Win64 files

#if defined(_WIN64)
#include "minhook/src/HDE/hde64.c"
#else
#include "minhook/src/HDE/hde32.c"
#endif
3 changes: 3 additions & 0 deletions clink/modules/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## minhook

* origin git@github.com:RaMMicHaeL/minhook.git
16 changes: 13 additions & 3 deletions clink/shared/hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "util.h"
#include "vm.h"
#include "pe.h"
#include "../modules/minhook/include/MinHook.h"

//------------------------------------------------------------------------------
static void* current_proc()
Expand Down Expand Up @@ -384,6 +385,7 @@ void* hook_jmp(const char* dll, const char* func_name, void* hook)
{
void* func_addr;
void* trampoline;
MH_STATUS status;

// Get the address of the function we're going to hook.
func_addr = get_proc_addr(dll, func_name);
Expand All @@ -397,10 +399,18 @@ void* hook_jmp(const char* dll, const char* func_name, void* hook)
LOG_INFO("Target is %s, %s @ %p", dll, func_name, func_addr);

// Install the hook.
trampoline = hook_jmp_impl(func_addr, hook);
if (trampoline == NULL)
//trampoline = hook_jmp_impl(func_addr, hook);
trampoline = NULL;
status = MH_CreateHook(func_addr, hook, &trampoline);
if ((status != MH_OK) || (trampoline == NULL))
{
LOG_INFO("MH_CreateHook failed.");
return NULL;
}
status = MH_EnableHook(func_addr);
if (status != MH_OK)
{
LOG_INFO("Jump hook failed.");
LOG_INFO("MH_EnableHook failed.");
return NULL;
}

Expand Down
9 changes: 9 additions & 0 deletions premake4.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ project("clink_dll")
links("lua")
links("readline")
links("clink_shared")
links("minhook")
includedirs("lua/src")
includedirs("clink")
defines("CLINK_DLL_BUILD")
Expand Down Expand Up @@ -235,6 +236,13 @@ project("clink_shared")
pchsource("clink/shared/pch.c")
pchheader("pch.h")

--------------------------------------------------------------------------------
project("minhook")
language("c")
kind("staticlib")
files("clink/modules/minhook/src/*")
files("clink/modules/minhook.c")

--------------------------------------------------------------------------------
project("clink_test")
language("c")
Expand All @@ -243,6 +251,7 @@ project("clink_test")
links("getopt")
links("readline")
links("clink_shared")
links("minhook")
defines("GETWCH_IMPL=getwch_automatic")
includedirs("getopt")
includedirs("lua/src")
Expand Down