加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

将托管DLL注入.net 4.0应用程序

发布时间:2020-12-14 04:35:36 所属栏目:Windows 来源:网络整理
导读:我已经成功地使用bootloader dll(在c中)将托管DLL注入到.net 3.5应用程序中,然后在(c#)中将我的“payload”dll注入. 当我尝试这样做.net 4.0应用程序总是崩溃. Bootloader C: #include "MSCorEE.h" void StartTheDotNetRuntime() { // Bind to the CLR runt
我已经成功地使用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.

代码可能类似于以下内容(没有错误检查):

ICLRMetaHost *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();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读