execute_assembly ( [assembly bytes], [patch:true|not], [args])
| 569 | } |
| 570 | // execute_assembly ( [assembly bytes], [patch:true|not], [args]) |
| 571 | Napi::String ExecuteAssembly(const Napi::CallbackInfo& info) { |
| 572 | |
| 573 | Napi::Env env = info.Env(); |
| 574 | |
| 575 | // Check the number of arguments |
| 576 | if (info.Length() < 3) { |
| 577 | Napi::TypeError::New(env, "Expected three arguments").ThrowAsJavaScriptException(); |
| 578 | return Napi::String(); |
| 579 | } |
| 580 | |
| 581 | // Check the types of arguments |
| 582 | if (!info[0].IsBuffer() || !info[1].IsBoolean() || !info[2].IsArray()) { |
| 583 | Napi::TypeError::New(env, "Expected a byte buffer, a boolean, a string array").ThrowAsJavaScriptException(); |
| 584 | return Napi::String(); |
| 585 | } |
| 586 | |
| 587 | // Extract the byte array |
| 588 | Napi::Buffer<uint8_t> AsmBuf = info[0].As<Napi::Buffer<uint8_t>>(); |
| 589 | PBYTE AssemblyBytes = AsmBuf.Data(); |
| 590 | SIZE_T AssemblyLength = AsmBuf.ByteLength(); |
| 591 | DPRINT("AsmBuf 0x%llx\n", AssemblyBytes); |
| 592 | DPRINT("AsmLen 0x%llx\n", AssemblyLength); |
| 593 | |
| 594 | // Extract the boolean |
| 595 | Napi::Boolean doPatch = info[1].As<Napi::Boolean>(); |
| 596 | DPRINT("doPatch %d\n", doPatch.Value()); |
| 597 | |
| 598 | // Extract the string array |
| 599 | Napi::Array jsArray = info[2].As<Napi::Array>(); |
| 600 | uint32_t nArgs = jsArray.Length(); |
| 601 | PWCHAR* Args = new PWCHAR[nArgs]; |
| 602 | |
| 603 | for (uint32_t i = 0; i < nArgs; ++i) { |
| 604 | Napi::Value element = jsArray[i]; |
| 605 | if (!element.IsString()) { |
| 606 | Napi::TypeError::New(env, "Expected all elements in the array to be strings").ThrowAsJavaScriptException(); |
| 607 | delete[] Args; // Clean up previously allocated memory |
| 608 | return Napi::String(); |
| 609 | } |
| 610 | |
| 611 | // Convert Napi::String to UTF-16 std::u16string |
| 612 | std::u16string utf16str = element.As<Napi::String>().Utf16Value(); |
| 613 | |
| 614 | // Allocate memory for the wide character string and copy contents |
| 615 | wchar_t* wideBuffer = new wchar_t[utf16str.length() + 1]; |
| 616 | std::memcpy(wideBuffer, utf16str.c_str(), (utf16str.length() + 1) * sizeof(char16_t)); |
| 617 | |
| 618 | // Store the wide character string in the array |
| 619 | Args[i] = wideBuffer; |
| 620 | DPRINT("Arg %d: %S\n", i, Args[i]); |
| 621 | } |
| 622 | |
| 623 | // Extract the # of args |
| 624 | DPRINT("Argc: %d\n", nArgs); |
| 625 | |
| 626 | LPCWSTR NetVersion = NULL; |
| 627 | ICLRMetaHost* pClrMetaHost = NULL; |
| 628 | ICLRRuntimeInfo* pClrRuntimeInfo = NULL; |
nothing calls this directly
no test coverage detected