首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >EasyHook与通信

EasyHook与通信
EN

Stack Overflow用户
提问于 2017-06-08 14:42:02
回答 1查看 952关注 0票数 2

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

应用程序<->接口<-> DLL

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

我设法获得DLL,以便使用以下代码向外部发送消息:

代码语言:javascript
复制
((EntryPoint)HookRuntimeInfo.Callback).Interface.WriteLine("");

但是如何使代码在注入的DLL中运行呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-06-09 02:24:29

您需要配置一个双向IPC接口。有多种不同的方法来实现这一点。下面是一个使用.NET远程处理的示例。

首先,将EasyHook 远程文件监视器教程作为创建接口的起点,以便将消息从DLL发送回APP,即应用程序<- interface <- DLL

为了允许来自应用程序->接口-> DLL的消息,需要在DLL IEntryPoint构造函数中配置一个新的通道。

代码语言:javascript
复制
    #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.DisconnectCaptureInterface.DisconnectedClientCaptureInterfaceEventProxy.Disconnected的“客户端事件”中的Disconnect方法和Disconnected事件,它们都在CaptureInterface.cs中。除了接口类之外,此方法还使用从MarshalByRefObject继承的客户端事件代理类,并允许在调用方法的应用程序的响应下调用DLL中的其他地方的事件处理程序。您将需要仔细查看链接的代码,需要考虑其他一些需要考虑的方面(例如事件处理程序生存期),该接口在每个事件周围实现一个包装器,以“安全”的方式触发它。

最后,Disconnected事件的处理程序附加在DLL的IEntryPoint运行方法中:

代码语言:javascript
复制
    _interface.Disconnected += _clientEventProxy.DisconnectedProxyHandler;

    _clientEventProxy.Disconnected += () =>
            {
                // This code in the DLL will run when APP calls CaptureInterface.Disconnect
            };
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44438799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档