0

現在、EasyHook を使用して user32.dll の「MessageBeep」関数をフックしようとしています。[この例][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
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);

更新: このリンクを参照できます https://www.codeproject.com/Articles/27637/EasyHook-The-reinvention-of-Windows-API-hooking

于 2016-12-21T08:21:46.480 に答える