This repository has been archived by the owner on Mar 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
192 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "native/minhook/src"] | ||
path = native/minhook/src | ||
url = https://github.com/Summpot/minhook | ||
url = https://github.com/TsudaKageyu/minhook |
Submodule src
updated
8 files
+1 −1 | CMakeLists.txt | |
+0 −10 | README.md | |
+1 −8 | dll_resources/MinHook.def | |
+17 −85 | include/MinHook.h | |
+1 −1 | src/buffer.h | |
+344 −647 | src/hook.c | |
+20 −26 | src/trampoline.c | |
+6 −12 | src/trampoline.h |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
using System.Text; | ||
|
||
namespace MinHook; | ||
public class LibraryLoadingMonitor | ||
{ | ||
[UnmanagedFunctionPointer(CallingConvention.StdCall, BestFitMapping = true, CharSet = CharSet.Ansi)] | ||
public delegate IntPtr LoadLibraryADelegate(string lpLibFileName); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.StdCall, BestFitMapping = true, CharSet = CharSet.Unicode)] | ||
public delegate IntPtr LoadLibraryWDelegate(string lpLibFileName); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.StdCall, BestFitMapping = true, CharSet = CharSet.Ansi)] | ||
public delegate IntPtr LoadLibraryExADelegate(string lpLibFileName, IntPtr hFile, uint dwFlags); | ||
|
||
[UnmanagedFunctionPointer(CallingConvention.StdCall, BestFitMapping = true, CharSet = CharSet.Unicode)] | ||
public delegate IntPtr LoadLibraryExWDelegate(string lpLibFileName, IntPtr hFile, uint dwFlags); | ||
|
||
|
||
private static Hook<LoadLibraryADelegate> s_hook1 = Hook.Create<LoadLibraryADelegate>("kernel32", "LoadLibraryA", Hook_LoadLibraryA); | ||
private static Hook<LoadLibraryWDelegate> s_hook2 = Hook.Create<LoadLibraryWDelegate>("kernel32", "LoadLibraryW", Hook_LoadLibraryW); | ||
private static Hook<LoadLibraryExADelegate> s_hook3 = Hook.Create<LoadLibraryExADelegate>("kernel32", "LoadLibraryExA", Hook_LoadLibraryExA); | ||
private static Hook<LoadLibraryExWDelegate> s_hook4 = Hook.Create<LoadLibraryExWDelegate>("kernel32", "LoadLibraryExW", Hook_LoadLibraryExW); | ||
|
||
public static bool Enabled { get; private set; } | ||
|
||
private static IntPtr Hook_LoadLibraryA(string lpLibFileName) | ||
{ | ||
OnLibraryLoading(lpLibFileName); | ||
var handle = s_hook1.Original(lpLibFileName); | ||
OnLibraryLoaded(handle); | ||
return handle; | ||
} | ||
|
||
private static IntPtr Hook_LoadLibraryW(string lpLibFileName) | ||
{ | ||
OnLibraryLoading(lpLibFileName); | ||
var handle = s_hook2.Original(lpLibFileName); | ||
OnLibraryLoaded(handle); | ||
return handle; | ||
} | ||
private static IntPtr Hook_LoadLibraryExA(string lpLibFileName, IntPtr hFile, uint dwFlags) | ||
{ | ||
OnLibraryLoading(lpLibFileName); | ||
var handle = s_hook3.Original(lpLibFileName, hFile, dwFlags); | ||
OnLibraryLoaded(handle); | ||
return handle; | ||
} | ||
private static IntPtr Hook_LoadLibraryExW(string lpLibFileName, IntPtr hFile, uint dwFlags) | ||
{ | ||
OnLibraryLoading(lpLibFileName); | ||
var handle = s_hook4.Original(lpLibFileName, hFile, dwFlags); | ||
OnLibraryLoaded(handle); | ||
return handle; | ||
} | ||
|
||
public static void Enable() | ||
{ | ||
s_hook1.Enable(); | ||
s_hook2.Enable(); | ||
s_hook3.Enable(); | ||
s_hook4.Enable(); | ||
} | ||
|
||
public static void Disable() | ||
{ | ||
s_hook1.Disable(); | ||
s_hook2.Disable(); | ||
s_hook3.Disable(); | ||
s_hook4.Disable(); | ||
} | ||
|
||
private static void OnLibraryLoading(string libraryName) | ||
{ | ||
LibraryLoading?.Invoke(null, new LibraryLoadingEventArgs(libraryName)); | ||
} | ||
|
||
private static void OnLibraryLoaded(IntPtr handle) | ||
{ | ||
LibraryLoaded?.Invoke(null, new LibraryLoadedEventArgs(handle)); | ||
} | ||
|
||
public static event EventHandler<LibraryLoadingEventArgs>? LibraryLoading; | ||
public static event EventHandler<LibraryLoadedEventArgs>? LibraryLoaded; | ||
|
||
public record struct LibraryLoadingEventArgs(string LibraryName); | ||
public record struct LibraryLoadedEventArgs(IntPtr Handle); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,21 @@ | ||
using System.Diagnostics; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace MinHook.Tests; | ||
|
||
public class UnitTest1 | ||
{ | ||
|
||
[DllImport("Kernel32.dll")] | ||
[DllImport("kernel32.dll")] | ||
public static extern uint GetTickCount(); | ||
|
||
|
||
[Fact] | ||
public void Test1() | ||
{ | ||
StaticLazyHookManager.Enable(); | ||
Assert.Equal(0u, GetTickCount()); | ||
StaticLazyHookManager.Disable(alsoDisableAllEnabledHooks: true); | ||
Assert.NotEqual(0u, GetTickCount()); | ||
TestLazyHook.Enable(); | ||
Assert.Equal(0u,GetTickCount()); | ||
TestLazyHook.Disable(); | ||
Assert.NotEqual(0u,GetTickCount()); | ||
} | ||
} |