1313
1414在C#中执行一个` .exe ` 文件可以使用` Process ` 类,
1515
16- ``` c#
16+ ``` Csharp
1717using System ;
1818using System .Diagnostics ;
1919
@@ -28,7 +28,7 @@ class Program
2828
2929而在C++中可以使用` CreateProcess ` 函数。
3030
31- ``` c++
31+ ``` Cpp
3232#include < windows.h>
3333
3434int main ()
@@ -64,7 +64,7 @@ int main()
6464
6565在C#中执行一个` .dll ` 文件通常涉及在应用程序中加载并调用该` .dll ` 中的函数。
6666
67- ``` c#
67+ ``` Csharp
6868using System ;
6969using System .Runtime .InteropServices ;
7070
@@ -82,7 +82,7 @@ class Program
8282
8383在C++中执行一个` .dll ` 文件通常是通过加载动态链接库并调用其中的函数。
8484
85- ``` c++
85+ ``` Cpp
8686#include < windows.h>
8787
8888typedef void (* YourFunction)(); // 假设要调用的函数没有返回值
@@ -193,7 +193,7 @@ namespace TestApplication
193193
194194**(3) 还原.exe的内容**
195195
196- ```C#
196+ ```Csharp
197197using System;
198198using System.Reflection;
199199namespace TestApplication
@@ -214,7 +214,7 @@ namespace TestApplication
214214
215215代码如下:
216216
217- ``` C#
217+ ``` Csharp
218218using System ;
219219using System .Reflection ;
220220namespace TestApplication
@@ -239,7 +239,7 @@ namespace TestApplication
239239
240240如果不需要指定需要调用的方法,调用main函数即可:
241241
242- ``` C#
242+ ``` Csharp
243243using System ;
244244using System .Reflection ;
245245namespace TestApplication
@@ -266,7 +266,7 @@ namespace TestApplication
266266
267267#### c#
268268
269- ``` C#
269+ ``` Csharp
270270using System ;
271271using System .IO ;
272272using System .Reflection ;
@@ -426,7 +426,7 @@ public void spawn(String var1) {
426426
427427** unmanaged.cpp**
428428
429- ``` C++
429+ ``` Cpp
430430#include < metahost.h>
431431#pragma comment(lib, "mscoree.lib")
432432
@@ -456,7 +456,7 @@ int main()
456456
457457执行的C#源码
458458
459- ``` C#
459+ ``` Csharp
460460using System ;
461461
462462namespace TEST
@@ -481,7 +481,7 @@ namespace TEST
481481
4824821.初始化CLR环境(同上)
483483
484- ``` c++
484+ ``` Cpp
485485 CLRCreateInstance (CLSID_CLRMetaHost, IID_ICLRMetaHost, (VOID** )&iMetaHost);
486486 iMetaHost->GetRuntime(L"v4.0.30319", IID_ICLRRuntimeInfo, (VOID** )&iRuntimeInfo);
487487 iRuntimeInfo->GetInterface(CLSID_CorRuntimeHost, IID_ICorRuntimeHost, (VOID** )&iRuntimeHost);
@@ -490,14 +490,14 @@ namespace TEST
490490
4914912.通过ICLRRuntimeHost获取AppDomain接口指针,然后通过AppDomain接口的QueryInterface方法来查询默认应用程序域的实例指针。
492492
493- ```c++
493+ ```Cpp
494494 iRuntimeHost->GetDefaultDomain(&pAppDomain);
495495 pAppDomain->QueryInterface(__uuidof(_AppDomain), (VOID**)&pDefaultAppDomain);
496496```
497497
4984983.通过默认应用程序域实例的Load_3方法加载安全.net程序集数组,并返回Assembly的实例对象指针,通过Assembly实例对象的get_EntryPoint方法获取描述入口点的MethodInfo实例对象。
499499
500- ``` c++
500+ ``` Cpp
501501 saBound[0 ].cElements = ASSEMBLY_LENGTH;
502502 saBound[0 ].lLbound = 0 ;
503503 SAFEARRAY* pSafeArray = SafeArrayCreate(VT_UI1, 1 , saBound);
@@ -512,7 +512,7 @@ namespace TEST
512512
5135134.创建参数安全数组
514514
515- ```c++
515+ ```Cpp
516516ZeroMemory(&vRet, sizeof(VARIANT));
517517 ZeroMemory(&vObj, sizeof(VARIANT));
518518 vObj.vt = VT_NULL;
@@ -535,13 +535,13 @@ ZeroMemory(&vRet, sizeof(VARIANT));
535535
5365365.通过描述入口点的MethodInfo实例对象的Invoke方法执行入口点。
537537
538- ``` c++
538+ ``` Cpp
539539HRESULT hr = pMethodInfo->Invoke_3 (vObj, args, &vRet);
540540```
541541
542542#### 示例代码
543543
544- ```C++
544+ ```Cpp
545545#include <stdio.h>
546546#include <tchar.h>
547547#include <metahost.h>
@@ -634,7 +634,7 @@ int _tmain(int argc, _TCHAR* argv[])
634634
635635执行的C#源码
636636
637- ``` C#
637+ ``` Csharp
638638using System ;
639639
640640namespace TEST
0 commit comments