0

我目前正在尝试使用 EasyHook 在 user32.dll 中挂钩“MessageBeep”函数。如果我正在运行 [this example][1] 一切似乎都正常。但是,如果我将第 52 行和第 60 行中的线程 ID 替换为我的测试应用程序的线程 ID,则该钩子不适用于 ohter 程序。

为什么 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
4

1 回答 1

1

如果你想挂接到目标进程,你需要将你的 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);

Updated: you can refer to this link https://www.codeproject.com/Articles/27637/EasyHook-The-reinvention-of-Windows-API-hooking

于 2016-12-21T08:21:46.480 回答