EasyHook 不适用于其他线程
EasyHook does not work for other threads
我目前正在尝试使用 EasyHook 挂钩 user32.dll 中的 "MessageBeep" 函数。 If im 运行 [this example][1] 似乎一切正常。但是,如果我将第 52 行和第 60 行中的线程 ID 替换为我的测试应用程序的线程 ID,则该挂钩不适用于其他程序。
为什么 SetExclusiveACL-Method 不接受任何其他线程 ID?例如
hook.ThreadACL.SetExclusiveACL(new int[] { 8788 });
我正在使用以下代码检索我的测试应用程序的线程 ID 并验证挂钩是否适用于 MessageBeep 函数:
Sub Main()
While True
Console.WriteLine(GetCurrentThreadId().ToString)
MessageBeep(&H40)
If Console.ReadKey().KeyChar = "c"c Then
Console.Clear()
End If
End While
End Sub
如果你想挂接到目标进程,你需要将你的DLL注入目标进程,EasyHook已经提供了这样做的方法。在注入的 DLL 中,您可以为 MessageBeep 设置 LocalHook。下面是使用 RemoteHooking.Inject
进行注入的示例代码
//create channel to send text data and log
RemoteHooking.IpcCreateServer<LogChannel>(ref _logChannelName, WellKnownObjectMode.Singleton);
RemoteHooking.IpcCreateServer<TextDataChannel>(
ref _textDataChannelName, WellKnownObjectMode.Singleton);
CommandChannel = new Common.IPC.CommandChannel();
string filePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\" + INJECT_DLL_NAME;
RemoteHooking.Inject(processID,InjectionOptions.DoNotRequireStrongName,
filePath,
filePath,
_logChannelName, _textDataChannelName, CommandChannel.PipeName, _pendingMsgType);
更新:可以参考这个linkhttps://www.codeproject.com/Articles/27637/EasyHook-The-reinvention-of-Windows-API-hooking
我目前正在尝试使用 EasyHook 挂钩 user32.dll 中的 "MessageBeep" 函数。 If im 运行 [this example][1] 似乎一切正常。但是,如果我将第 52 行和第 60 行中的线程 ID 替换为我的测试应用程序的线程 ID,则该挂钩不适用于其他程序。
为什么 SetExclusiveACL-Method 不接受任何其他线程 ID?例如
hook.ThreadACL.SetExclusiveACL(new int[] { 8788 });
我正在使用以下代码检索我的测试应用程序的线程 ID 并验证挂钩是否适用于 MessageBeep 函数:
Sub Main()
While True
Console.WriteLine(GetCurrentThreadId().ToString)
MessageBeep(&H40)
If Console.ReadKey().KeyChar = "c"c Then
Console.Clear()
End If
End While
End Sub
如果你想挂接到目标进程,你需要将你的DLL注入目标进程,EasyHook已经提供了这样做的方法。在注入的 DLL 中,您可以为 MessageBeep 设置 LocalHook。下面是使用 RemoteHooking.Inject
//create channel to send text data and log
RemoteHooking.IpcCreateServer<LogChannel>(ref _logChannelName, WellKnownObjectMode.Singleton);
RemoteHooking.IpcCreateServer<TextDataChannel>(
ref _textDataChannelName, WellKnownObjectMode.Singleton);
CommandChannel = new Common.IPC.CommandChannel();
string filePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\" + INJECT_DLL_NAME;
RemoteHooking.Inject(processID,InjectionOptions.DoNotRequireStrongName,
filePath,
filePath,
_logChannelName, _textDataChannelName, CommandChannel.PipeName, _pendingMsgType);
更新:可以参考这个linkhttps://www.codeproject.com/Articles/27637/EasyHook-The-reinvention-of-Windows-API-hooking