我已经成功地使用bootloader dll(在c中)将托管DLL注入到.net 3.5应用程序中,然后在(c#)中将我的“payload”dll注入.
当我尝试这样做.net 4.0应用程序总是崩溃.
Bootloader C:
#include "MscoreE.h" void StartTheDotNetRuntime() { // Bind to the CLR runtime.. ICLRRuntimeHost *pClrHost = NULL; HRESULT hr = CorBindToRuntimeEx( NULL,L"wks",CLSID_CLRRuntimeHost,IID_ICLRRuntimeHost,(PVOID*)&pClrHost); hr = pClrHost->Start(); // Okay,the CLR is up and running in this (prevIoUsly native) process. // Now call a method on our managed C# class library. DWORD dwRet = 0; hr = pClrHost->ExecuteInDefaultAppDomain( L"payload.dll",L"MyNamespace.MyClass",L"MyMethod",L"MyParameter",&dwRet); // Optionally stop the CLR runtime (we could also leave it running) hr = pClrHost->Stop(); // Don't forget to clean up. pClrHost->Release(); }
有效载荷C#:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows.Forms; namespace MyNamespace { public class MyClass { // This method will be called by native code inside the target process... public static int MyMethod(String pwzArgument) { MessageBox.Show("Hello World"); return 0; } } }
我试过使用下面的修复程序,但没有用,有什么想法吗?
固定??:
hr = pMetaHost->GetRuntime(L"v4.0.30319",IID_ICLRRuntimeInfo,(LPVOID*)&lpRuntimeInfo);
接口随.NET 4.0改变.您应该使用新的ICLRMetaHost
interface,而不是使用CorBindToRuntimeEx.
原文链接:https://www.f2er.com/windows/364194.htmlICLRMetaHost *pMetaHost = NULL; CLRCreateInstance(CLSID_CLRMetaHost,IID_ICLRMetaHost,(LPVOID*)&pMetaHost); ICLRRuntimeInfo *pRuntimeInfo = NULL; pMetaHost->GetRuntime(L"v4.0.30319",(LPVOID*)&pRuntimeInfo); ICLRRuntimeHost *pClrRuntimeHost = NULL; pRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost,(LPVOID*)&pClrRuntimeHost); pClrRuntimeHost->Start();