gpt4 book ai didi

c# - EasyHook 和通信

转载 作者:行者123 更新时间:2023-11-30 23:11:55 28 4
gpt4 key购买 nike

使用 EasyHook 我设置了以下结构:

APP <--> 接口(interface) <--> DLL

当我按下应用程序中的按钮时,我试图在注入(inject)的 DLL 中运行一些代码。

我设法让 DLL 使用此代码向外部发送消息:

((EntryPoint)HookRuntimeInfo.Callback).Interface.WriteLine("");

但是我怎样才能真正让代码在注入(inject)的 DLL 中运行呢?

最佳答案

您需要配置一个双向IPC接口(interface)。有多种不同的方法可以实现这一点。以下是一个使用 .NET Remoting 的示例。

先看看EasyHook remote file monitor tutorial作为创建接口(interface)以将消息从 DLL 发送回 APP 的起点,即 APP <- interface <- DLL

要允许来自APP -> interface -> DLL 的消息,需要在DLL 中配置一个新 channel IEntryPoint constructor :例如

    #region Allow client event handlers (bi-directional IPC)
// Attempt to create a IpcServerChannel so that any event handlers on the client will function correctly
System.Collections.IDictionary properties = new System.Collections.Hashtable();
properties["name"] = channelName;
properties["portName"] = channelName + Guid.NewGuid().ToString("N"); // random portName so no conflict with existing channels of channelName

System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider binaryProv = new System.Runtime.Remoting.Channels.BinaryServerFormatterSinkProvider();
binaryProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

System.Runtime.Remoting.Channels.Ipc.IpcServerChannel _clientServerChannel = new System.Runtime.Remoting.Channels.Ipc.IpcServerChannel(properties, binaryProv);
System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(_clientServerChannel, false);
#endregion

要从 APP -> interface -> DLL 实现 IPC,请查看“Client”中的 Disconnect 方法和 Disconnected 事件-边事件”的Direct3DHook projectCaptureInterface.DisconnectCaptureInterface.DisconnectedClientCaptureInterfaceEventProxy.Disconnected,全部在 CaptureInterface.cs 中.除了接口(interface)类之外,这种方法还使用了一个继承自 MarshalByRefObject 的客户端事件代理类,并允许在 DLL 的其他地方调用事件处理程序以响应 APP 调用方法。您需要仔细查看链接的代码,还有一些额外的兴趣点需要考虑(例如事件处理程序生命周期),该接口(interface)实现了每个事件的包装器以“安全”方式触发它.

最后,Disconnected 事件的处理程序附加到 DLL 的 IEntryPoint Run 方法中:

    _interface.Disconnected += _clientEventProxy.DisconnectedProxyHandler;

_clientEventProxy.Disconnected += () =>
{
// This code in the DLL will run when APP calls CaptureInterface.Disconnect
};

关于c# - EasyHook 和通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44438799/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com