Skip to content

Commit 8d6988d

Browse files
committed
12.3备份
1 parent cadbef3 commit 8d6988d

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/develop/CSharp/PELoader.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
在C#中执行一个`.exe`文件可以使用`Process`类,
1515

16-
```Csharp
16+
```C#
1717
using System;
1818
using System.Diagnostics;
1919

@@ -28,7 +28,7 @@ class Program
2828

2929
而在C++中可以使用`CreateProcess`函数。
3030

31-
```Cpp
31+
```C++
3232
#include <windows.h>
3333

3434
int main()
@@ -64,7 +64,7 @@ int main()
6464

6565
在C#中执行一个`.dll`文件通常涉及在应用程序中加载并调用该`.dll`中的函数。
6666

67-
```Csharp
67+
```C#
6868
using System;
6969
using System.Runtime.InteropServices;
7070

@@ -82,7 +82,7 @@ class Program
8282

8383
在C++中执行一个`.dll`文件通常是通过加载动态链接库并调用其中的函数。
8484

85-
```Cpp
85+
```C++
8686
#include <windows.h>
8787

8888
typedef void (*YourFunction)(); // 假设要调用的函数没有返回值
@@ -138,7 +138,7 @@ int main()
138138
139139
测试程序的代码如下:
140140
141-
```
141+
```c#
142142
using System;
143143
namespace TestApplication
144144
{
@@ -173,7 +173,7 @@ C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe /out:testcalc.exe test.c
173173

174174
代码如下:
175175

176-
```
176+
```C#
177177
using System;
178178
using System.Reflection;
179179
namespace TestApplication
@@ -193,7 +193,7 @@ namespace TestApplication
193193

194194
**(3) 还原.exe的内容**
195195

196-
```Csharp
196+
```C#
197197
using System;
198198
using System.Reflection;
199199
namespace TestApplication
@@ -214,7 +214,7 @@ namespace TestApplication
214214

215215
代码如下:
216216

217-
```Csharp
217+
```C#
218218
using System;
219219
using System.Reflection;
220220
namespace TestApplication
@@ -239,7 +239,7 @@ namespace TestApplication
239239

240240
如果不需要指定需要调用的方法,调用main函数即可:
241241

242-
```Csharp
242+
```C#
243243
using System;
244244
using System.Reflection;
245245
namespace TestApplication
@@ -266,7 +266,7 @@ namespace TestApplication
266266

267267
#### c#
268268

269-
```Csharp
269+
```C#
270270
using System;
271271
using System.IO;
272272
using System.Reflection;
@@ -426,7 +426,7 @@ public void spawn(String var1) {
426426

427427
**unmanaged.cpp**
428428

429-
```Cpp
429+
```C++
430430
#include <metahost.h>
431431
#pragma comment(lib, "mscoree.lib")
432432

@@ -456,7 +456,7 @@ int main()
456456

457457
执行的C#源码
458458

459-
```Csharp
459+
```C#
460460
using System;
461461

462462
namespace TEST
@@ -481,7 +481,7 @@ namespace TEST
481481

482482
1.初始化CLR环境(同上)
483483

484-
```Cpp
484+
```C++
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

491491
2.通过ICLRRuntimeHost获取AppDomain接口指针,然后通过AppDomain接口的QueryInterface方法来查询默认应用程序域的实例指针。
492492

493-
```Cpp
493+
```C++
494494
iRuntimeHost->GetDefaultDomain(&pAppDomain);
495495
pAppDomain->QueryInterface(__uuidof(_AppDomain), (VOID**)&pDefaultAppDomain);
496496
```
497497

498498
3.通过默认应用程序域实例的Load_3方法加载安全.net程序集数组,并返回Assembly的实例对象指针,通过Assembly实例对象的get_EntryPoint方法获取描述入口点的MethodInfo实例对象。
499499

500-
```Cpp
500+
```C++
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

513513
4.创建参数安全数组
514514

515-
```Cpp
515+
```C++
516516
ZeroMemory(&vRet, sizeof(VARIANT));
517517
ZeroMemory(&vObj, sizeof(VARIANT));
518518
vObj.vt = VT_NULL;
@@ -535,13 +535,13 @@ ZeroMemory(&vRet, sizeof(VARIANT));
535535

536536
5.通过描述入口点的MethodInfo实例对象的Invoke方法执行入口点。
537537

538-
```Cpp
538+
```C++
539539
HRESULT hr = pMethodInfo->Invoke_3(vObj, args, &vRet);
540540
```
541541

542542
#### 示例代码
543543

544-
```Cpp
544+
```C++
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-
```Csharp
637+
```C#
638638
using System;
639639

640640
namespace TEST

0 commit comments

Comments
 (0)