使用EasyHook,我设置了以下结构:
应用程序<->接口<-> DLL
当我按下应用程序中的一个按钮时,我试图在注入的DLL中运行一些代码。
我设法获得DLL,以便使用以下代码向外部发送消息:
((EntryPoint)HookRuntimeInfo.Callback).Interface.WriteLine("");但是如何使代码在注入的DLL中运行呢?
发布于 2017-06-09 02:24:29
您需要配置一个双向IPC接口。有多种不同的方法来实现这一点。下面是一个使用.NET远程处理的示例。
首先,将EasyHook 远程文件监视器教程作为创建接口的起点,以便将消息从DLL发送回APP,即应用程序<- interface <- DLL。
为了允许来自应用程序->接口-> DLL的消息,需要在DLL IEntryPoint构造函数中配置一个新的通道。
#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要从应用程序->接口-> DLL实现IPC,请看一下Direct3DHook项目、CaptureInterface.Disconnect、CaptureInterface.Disconnected和ClientCaptureInterfaceEventProxy.Disconnected的“客户端事件”中的Disconnect方法和Disconnected事件,它们都在CaptureInterface.cs中。除了接口类之外,此方法还使用从MarshalByRefObject继承的客户端事件代理类,并允许在调用方法的应用程序的响应下调用DLL中的其他地方的事件处理程序。您将需要仔细查看链接的代码,需要考虑其他一些需要考虑的方面(例如事件处理程序生存期),该接口在每个事件周围实现一个包装器,以“安全”的方式触发它。
最后,Disconnected事件的处理程序附加在DLL的IEntryPoint运行方法中:
_interface.Disconnected += _clientEventProxy.DisconnectedProxyHandler;
_clientEventProxy.Disconnected += () =>
{
// This code in the DLL will run when APP calls CaptureInterface.Disconnect
};https://stackoverflow.com/questions/44438799
复制相似问题