126 lines
No EOL
2.6 KiB
C++
126 lines
No EOL
2.6 KiB
C++
#include <Windows.h>
|
|
#include <mscoree.h>
|
|
#include <metahost.h>
|
|
#include <wchar.h>
|
|
#include <fstream>
|
|
|
|
#pragma comment(lib, "mscoree.lib")
|
|
|
|
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
|
|
|
|
static const LPCWSTR Assembly = L"\\ADProCrack.dll";
|
|
static const LPCWSTR Class = L"ADProCrack.Startup";
|
|
static const LPCWSTR Method = L"EntryPoint";
|
|
static const LPCWSTR Param = L"";
|
|
|
|
|
|
static DWORD WINAPI CreateDotNetRunTime(LPVOID lpParam)
|
|
{
|
|
ICLRRuntimeHost* lpRuntimeHost = NULL;
|
|
ICLRRuntimeInfo* lpRuntimeInfo = NULL;
|
|
ICLRMetaHost* lpMetaHost = NULL;
|
|
|
|
LPWSTR AppPath = new WCHAR[_MAX_PATH];
|
|
::GetModuleFileNameW((HINSTANCE)&__ImageBase, AppPath, _MAX_PATH);
|
|
|
|
std::wstring tempPath = AppPath;
|
|
size_t index = tempPath.rfind('\\');
|
|
tempPath.erase(index, tempPath.length() - index);
|
|
tempPath += Assembly;
|
|
|
|
HRESULT hr = CLRCreateInstance(
|
|
CLSID_CLRMetaHost,
|
|
IID_ICLRMetaHost,
|
|
(LPVOID*)&lpMetaHost
|
|
);
|
|
|
|
if (FAILED(hr))
|
|
{
|
|
MessageBoxA(NULL, "Failed to create CLR instance.", "Error", MB_ICONERROR);
|
|
return 1;
|
|
}
|
|
|
|
hr = lpMetaHost->GetRuntime(
|
|
L"v4.0.30319",
|
|
IID_PPV_ARGS(&lpRuntimeInfo)
|
|
);
|
|
|
|
if (FAILED(hr))
|
|
{
|
|
MessageBoxA(NULL, "Failed to acquire CLR runtime.", "Error", MB_ICONERROR);
|
|
|
|
lpMetaHost->Release();
|
|
}
|
|
|
|
BOOL fLoadable;
|
|
hr = lpRuntimeInfo->IsLoadable(&fLoadable);
|
|
|
|
if (FAILED(hr) || !fLoadable)
|
|
{
|
|
MessageBoxA(NULL, "Runtime is not loadable.", "Error", MB_ICONERROR);
|
|
|
|
lpRuntimeInfo->Release();
|
|
lpMetaHost->Release();
|
|
}
|
|
|
|
hr = lpRuntimeInfo->GetInterface(
|
|
CLSID_CLRRuntimeHost,
|
|
IID_PPV_ARGS(&lpRuntimeHost)
|
|
);
|
|
|
|
if (FAILED(hr))
|
|
{
|
|
MessageBoxA(NULL, "Failed to acquire runtime host.", "Error", MB_ICONERROR);
|
|
|
|
lpRuntimeInfo->Release();
|
|
lpMetaHost->Release();
|
|
}
|
|
|
|
hr = lpRuntimeHost->Start();
|
|
|
|
if (FAILED(hr))
|
|
{
|
|
MessageBoxA(NULL, "Failed to start runtime.", "Error", MB_ICONERROR);
|
|
|
|
lpRuntimeHost->Release();
|
|
lpRuntimeInfo->Release();
|
|
lpMetaHost->Release();
|
|
}
|
|
|
|
DWORD dwRetCode = 0;
|
|
|
|
hr = lpRuntimeHost->ExecuteInDefaultAppDomain(
|
|
(LPWSTR)tempPath.c_str(),
|
|
Class,
|
|
Method,
|
|
Param,
|
|
&dwRetCode
|
|
);
|
|
|
|
if (FAILED(hr))
|
|
{
|
|
MessageBoxA(NULL, "Failed to execute assembly.", "Error", MB_ICONERROR);
|
|
|
|
lpRuntimeHost->Stop();
|
|
lpRuntimeHost->Release();
|
|
lpRuntimeInfo->Release();
|
|
lpMetaHost->Release();
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
DWORD APIENTRY DllMain(HMODULE hModule, DWORD dwReason, LPVOID lpReserved)
|
|
{
|
|
switch (dwReason)
|
|
{
|
|
case DLL_PROCESS_ATTACH:
|
|
CreateThread(NULL, NULL, CreateDotNetRunTime, NULL, NULL, NULL);
|
|
case DLL_THREAD_ATTACH:
|
|
case DLL_THREAD_DETACH:
|
|
case DLL_PROCESS_DETACH:
|
|
default:
|
|
break;
|
|
}
|
|
return true;
|
|
} |