CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/HostingCLR_inject/HostingCLR/Executer.cpp
Views: 11778
1
// Author: B4rtik (@b4rtik)
2
// Project: Execute-dotnet-assembly (https://github.com/b4rtik/metasploit-execute-assembly)
3
// License: BSD 3-Clause
4
5
#include "stdafx.h"
6
#include "ReflectiveLoader.h"
7
#include "ReflectiveFree.h"
8
#include "HostingCLR.h"
9
10
extern HINSTANCE hAppInstance;
11
12
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD dwReason, LPVOID lpReserved)
13
{
14
BOOL bReturnValue = TRUE;
15
switch (dwReason)
16
{
17
case DLL_QUERY_HMODULE:
18
if (lpReserved != NULL)
19
*(HMODULE *)lpReserved = hAppInstance;
20
break;
21
case DLL_PROCESS_ATTACH:
22
hAppInstance = hinstDLL;
23
Execute(lpReserved);
24
fflush(stdout);
25
26
// Free the assembly and parameters
27
VirtualFree(lpReserved, 0, MEM_RELEASE);
28
29
ReflectiveFree(hinstDLL);
30
31
break;
32
case DLL_PROCESS_DETACH:
33
ReflectiveFree(hinstDLL);
34
break;
35
case DLL_THREAD_ATTACH:
36
case DLL_THREAD_DETACH:
37
break;
38
}
39
return bReturnValue;
40
}
41
42