mirror of
https://github.com/T3nb3w/ComDotNetExploit
synced 2026-06-06 16:54:26 +00:00
31 lines
1.1 KiB
C++
31 lines
1.1 KiB
C++
// dotnet_interop.h
|
|
#pragma once
|
|
#include <comdef.h>
|
|
#include <vector>
|
|
#include <iostream>
|
|
#import "C:\\Windows\\Microsoft.NET\\Framework64\\v4.0.30319\\mscorlib.tlb" \
|
|
rename("ReportEvent", "_ReportEvent") \
|
|
rename("or", "_or")
|
|
|
|
class DotNetInterop {
|
|
public:
|
|
static mscorlib::_MethodInfoPtr GetStaticMethod(mscorlib::_TypePtr type, LPCWSTR methodName, int paramCount);
|
|
static mscorlib::_MethodInfoPtr GetStaticMethodLoad(mscorlib::_TypePtr type, LPCWSTR methodName, int pcount);
|
|
|
|
template<typename T>
|
|
static T ExecuteMethod(mscorlib::_MethodInfoPtr method, std::vector<variant_t>& args) {
|
|
SAFEARRAY* psa = SafeArrayCreateVector(VT_VARIANT, 0, static_cast<ULONG>(args.size()));
|
|
for (LONG i = 0; i < static_cast<LONG>(args.size()); ++i) {
|
|
SafeArrayPutElement(psa, &i, &args[i]);
|
|
}
|
|
|
|
variant_t ret = method->Invoke_3(variant_t(), psa);
|
|
T retObj = (ret.vt == VT_UNKNOWN || ret.vt == VT_DISPATCH) ? ret.punkVal : nullptr;
|
|
|
|
SafeArrayDestroy(psa);
|
|
return retObj;
|
|
}
|
|
|
|
|
|
};
|