Advertisement
rlane187

Untitled

Jan 13th, 2012
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.20 KB | None | 0 0
  1. C++ code:
  2. #include <Windows.h>
  3. #include "MSCorEE.h"
  4. #include <metahost.h>
  5. //#include "main.h"
  6. #pragma unmanaged
  7.  
  8. void __cdecl StartDotNet(void);
  9.  
  10. BOOL APIENTRY DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReeserved)
  11. {
  12.     switch (ul_reason_for_call)
  13.     {
  14.         case DLL_PROCESS_ATTACH:
  15.             CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&StartDotNet, 0, 0, NULL);
  16.             break;
  17.         case DLL_THREAD_ATTACH:
  18.         case DLL_THREAD_DETACH:
  19.         case DLL_PROCESS_DETACH:
  20.             break;
  21.     }
  22.     return TRUE;
  23. }
  24.  
  25. void StartDotNet()
  26. {
  27.     HRESULT hr;
  28.     ICLRRuntimeHost *pClrHost = NULL;
  29.     ICLRMetaHost *pMetaHost = NULL;
  30.     hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*)&pMetaHost);
  31.     //MessageBox(NULL, L"CLRCreateInstance Done.", NULL, NULL);
  32.  
  33.     ICLRRuntimeInfo * lpRuntimeInfo = NULL;
  34.  
  35.     hr = pMetaHost->GetRuntime(L"v4.0.30319", IID_ICLRRuntimeInfo, (LPVOID*)&lpRuntimeInfo);
  36.     //MessageBox(NULL, L"pMetaHost->GetRuntime Done.", NULL, NULL);
  37.  
  38.     ICLRRuntimeHost * lpRuntimeHost = NULL;
  39.    
  40.     hr = lpRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (LPVOID *)&lpRuntimeHost);
  41.     //MessageBox(NULL, L"lpRuntimeInfo->GetInterface Done.", NULL, NULL);
  42.  
  43.     hr = lpRuntimeHost->Start();
  44.     //MessageBox(NULL, L"lpRuntimeHost->Start() Done.", NULL, NULL);
  45.  
  46.     DWORD dwRet = 0;
  47.  
  48.     hr = lpRuntimeHost->ExecuteInDefaultAppDomain(
  49.         L"C:\\AOInject.dll",
  50.         L"Namespace.Program", L"DllMain", L"Injection Worked", &dwRet);
  51.  
  52.     lpRuntimeHost->Release();
  53.  
  54. }
  55.  
  56. C# Code
  57. using System;
  58. using System.Collections.Generic;
  59. using System.Diagnostics;
  60. using System.Linq;
  61. using System.Runtime.InteropServices;
  62. using System.Text;
  63. using System.Windows.Forms;
  64.  
  65. namespace Namespace
  66. {
  67.     public class Program
  68.     {
  69.         [DllImport("User32", EntryPoint = "MessageBoxA")]
  70.         static extern int MessageBox(IntPtr hWnd, string text, string title, int type);
  71.         public static int DllMain(string args)
  72.         {
  73.             Process currentProcess = Process.GetCurrentProcess();
  74.             string text = string.Format("Process: {0}\nMessage: {1}", currentProcess.ProcessName, args);
  75.             MessageBox(IntPtr.Zero, text, "", 0);
  76.             return 0;
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement