.Net 反编译与编译

本文通过 C# 程序举例

示例代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test1
{
internal class Program
{
static void Main(string[] args)
{
MessageBox.Show("hello,world");
}
}
}

编译后的程序,我们可以通过 ildasm.exe 进行反编译,如下图:

然后在菜单 File-> Dump, 如下图:

然后就可以得到文件:

然后我们打开: tttt.il, 然后找到字符串 hello,world 修改成:okddddddddd, 如下图:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// =============== CLASS MEMBERS DECLARATION ===================

.class private auto ansi beforefieldinit test2.Program
extends [mscorlib]System.Object
{
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
// Code size 13 (0xd)
.maxstack 8
IL_0000: nop
IL_0001: ldstr "okddddddddd"
IL_0006: call valuetype [System.Windows.Forms]System.Windows.Forms.DialogResult [System.Windows.Forms]System.Windows.Forms.MessageBox::Show(string)
IL_000b: pop
IL_000c: ret
} // end of method Program::Main

.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method Program::.ctor

} // end of class test2.Program

然后通过 ilasm.exe 把代码编译成程序, 如下命令:

1
ilasm.exe /resource=tttt.res tttt.il

如下图:

完成后,得到程序:tttt.exe, 然后运行,我们可以看到:


.Net 反编译与编译
https://xxxxnnxxxx.github.io/2023/08/17/dotNet编译与反编译/
作者
xxxxnnxxxx
发布于
2023年8月17日
许可协议