Hello, i have been a member for quite a while but i havent written that much in here, so i guess a little introduction would be in place.
my name is Dan-Levi, i am 30 years old. I started out with server side web development about 12 years ago just until 4 years ago when i started learning c# and all that .NET shizzle, and now i am interested in learning about c++.
So im working in a simple dll injection which loads the CLR and (eventually) a managed dll. i am able to inject the unmanaged dll into the process (notepad in this case) , but i struggle getting CLR to start.
This is what i got so far:
So all HRESULT hr returns S_OK until i actually try to start CLR
Since im coming over from c# and have little to no experience writing c++, i understand the syntax and can make a understanding of the code, but i dont know exactly how to do errorhandling in the right manner in every situation.
I was hoping that some of you could have a look and give me some pointers so i can learn from this and eventually give back to the community with full source once it all is in place.
I want to know how i can debug my code once it is injected into the other process. I have tried to use try catch blocks but no exceptions is thrown from clr and the even inside the try block it crashes.
I want to add that after i inject this dll the clr.dll is in the list of loaded dll's (Process Explorer) but it seems that it fails to start.
I am running this on a Windows 10 X64 setup.
Cheers and thanks for the great community with alot of cool content.
my name is Dan-Levi, i am 30 years old. I started out with server side web development about 12 years ago just until 4 years ago when i started learning c# and all that .NET shizzle, and now i am interested in learning about c++.
So im working in a simple dll injection which loads the CLR and (eventually) a managed dll. i am able to inject the unmanaged dll into the process (notepad in this case) , but i struggle getting CLR to start.
This is what i got so far:
Code:
#include "stdafx.h"
#include <Windows.h>
#include <metahost.h>
#pragma comment(lib, "mscoree.lib")
#import "mscorlib.tlb" raw_interfaces_only \
high_property_prefixes("_get","_put","_putref") \
rename("ReportEvent", "InteropServices_ReportEvent")
void LoadDotNet()
{
HRESULT hr;
ICLRMetaHost *pMetaHost = NULL;
ICLRRuntimeInfo *pRuntimeInfo = NULL;
ICLRRuntimeHost *pClrRuntimeHost = NULL;
hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_PPV_ARGS(&pMetaHost));
hr = pMetaHost->GetRuntime(L"v4.0.30319", IID_PPV_ARGS(&pRuntimeInfo));
hr = pRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost,
IID_PPV_ARGS(&pClrRuntimeHost));
MessageBox(NULL, L"Runs up to here...", L"DEBUG", NULL);
// start runtime
hr = pClrRuntimeHost->Start();
pMetaHost->Release();
pRuntimeInfo->Release();
pClrRuntimeHost->Release();
}
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
//printf("DLL Loaded!");
LoadDotNet();
}
return TRUE;
}
Code:
hr = pClrRuntimeHost->Start();
I was hoping that some of you could have a look and give me some pointers so i can learn from this and eventually give back to the community with full source once it all is in place.
I want to know how i can debug my code once it is injected into the other process. I have tried to use try catch blocks but no exceptions is thrown from clr and the even inside the try block it crashes.
I want to add that after i inject this dll the clr.dll is in the list of loaded dll's (Process Explorer) but it seems that it fails to start.
I am running this on a Windows 10 X64 setup.
Cheers and thanks for the great community with alot of cool content.