使用EasyHook我已經設置了以下結構:EasyHook和通信
APP < - >接口< - > DLL
我想,當我運行注入DLL裏面的一些代碼按APP中的按鈕。
我設法讓DLL外使用此代碼發送消息:
((EntryPoint)HookRuntimeInfo.Callback).Interface.WriteLine("");
但我怎麼能實際上使注入DLL中運行代碼?
使用EasyHook我已經設置了以下結構:EasyHook和通信
APP < - >接口< - > DLL
我想,當我運行注入DLL裏面的一些代碼按APP中的按鈕。
我設法讓DLL外使用此代碼發送消息:
((EntryPoint)HookRuntimeInfo.Callback).Interface.WriteLine("");
但我怎麼能實際上使注入DLL中運行代碼?
您需要配置一個雙向IPC接口。有多種不同的方式來實現這一點。以下是使用.NET Remoting的一個示例。
先來看看EasyHook remote file monitor tutorial作爲一個起點,創建你的接口發送從DLL消息回APP,即APP < - 接口< - DLL。
要允許來自的消息應用程序接口 - > DLL,需要在DLL 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實現IPC - >界面 - > DLL看一看的Disconnect
方法和Disconnected
事件的Direct3DHook project,CaptureInterface.Disconnect
,CaptureInterface.Disconnected
和ClientCaptureInterfaceEventProxy.Disconnected
「客戶端事件」 中,所有的在CaptureInterface.cs。除了接口類之外,這種方法還使用一個客戶端事件代理類,該類繼承自MarshalByRefObject
,並允許在您的DLL中的其他地方調用事件處理程序來響應APP調用方法。您需要仔細查看鏈接的代碼,還有一些需要考慮的其他興趣點(例如事件處理程序生存期),接口實現了每個事件的包裝以「安全」方式觸發它。
最後的Disconnected
事件處理程序的DLL的IEntryPoint
run方法中附:
_interface.Disconnected += _clientEventProxy.DisconnectedProxyHandler;
_clientEventProxy.Disconnected +=() =>
{
// This code in the DLL will run when APP calls CaptureInterface.Disconnect
};
哇,我一直在讀D3DHook項目幾天卻從未完全理解它,但多虧了你我剛剛開始工作!謝謝!!! – Eliza
@Eliza很高興幫助 –
您好 - 非常感謝您的回答。你能否詳細說明爲什麼ClientCaptureInferfaceEventProxy在那裏?簡單地使用這些事件處理程序的原始接口是否有任何困難? –