ilspy-decompile
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinese.NET Assembly Decompilation with ILSpy
使用ILSpy进行.NET程序集反编译
Use this skill to understand how .NET code works internally by decompiling compiled assemblies.
使用此技能,你可以通过反编译已编译的程序集来了解.NET代码的内部工作原理。
Prerequisites
前置条件
- .NET SDK installed
- ILSpy command-line tool available via one of the following:
- (if available in your SDK or runtime)
dnx ilspycmd dotnet tool install --global ilspycmd
Both forms are shown below. Use the one that works in your environment.
Note: ILSpyCmd options may vary slightly by version.
Always verify supported flags with.ilspycmd -h
- 已安装.NET SDK
- 可通过以下方式之一获取ILSpy命令行工具:
- (若你的SDK或运行时中提供此命令)
dnx ilspycmd dotnet tool install --global ilspycmd
以下展示了两种使用形式,请选择适配你环境的方式。
注意:ILSpyCmd的选项可能会因版本略有不同。 请始终通过验证支持的参数。ilspycmd -h
Quick start
快速开始
bash
undefinedbash
undefinedDecompile an assembly to stdout
将程序集反编译后输出到标准输出
ilspycmd MyLibrary.dll
ilspycmd MyLibrary.dll
or
或者
dnx ilspycmd MyLibrary.dll
dnx ilspycmd MyLibrary.dll
Decompile to an output folder
将反编译结果输出到指定文件夹
ilspycmd -o output-folder MyLibrary.dll
undefinedilspycmd -o output-folder MyLibrary.dll
undefinedCommon .NET Assembly Locations
.NET程序集常见位置
NuGet packages
NuGet包
bash
~/.nuget/packages/<package-name>/<version>/lib/<tfm>/bash
~/.nuget/packages/<package-name>/<version>/lib/<tfm>/.NET runtime libraries
.NET运行时库
bash
dotnet --list-runtimesbash
dotnet --list-runtimes.NET SDK reference assemblies
.NET SDK引用程序集
bash
dotnet --list-sdksReference assemblies do not contain implementations.
bash
dotnet --list-sdks引用程序集不包含实现代码。
Project build output
项目构建输出
bash
./bin/Debug/net8.0/<AssemblyName>.dll
./bin/Release/net8.0/publish/<AssemblyName>.dllbash
./bin/Debug/net8.0/<AssemblyName>.dll
./bin/Release/net8.0/publish/<AssemblyName>.dllCore workflow
核心工作流程
- Identify what you want to understand
- Locate the assembly
- List types
- Decompile the target
- 确定你想要了解的目标内容
- 定位程序集位置
- 列出类型
- 反编译目标内容
Commands
命令说明
Basic decompilation
基础反编译
bash
ilspycmd MyLibrary.dll
ilspycmd -o ./decompiled MyLibrary.dll
ilspycmd -p -o ./project MyLibrary.dllbash
ilspycmd MyLibrary.dll
ilspycmd -o ./decompiled MyLibrary.dll
ilspycmd -p -o ./project MyLibrary.dllTargeted decompilation
定向反编译
bash
ilspycmd -t Namespace.ClassName MyLibrary.dll
ilspycmd -lv CSharp12_0 MyLibrary.dllbash
ilspycmd -t Namespace.ClassName MyLibrary.dll
ilspycmd -lv CSharp12_0 MyLibrary.dllView IL code
查看IL代码
bash
ilspycmd -il MyLibrary.dllbash
ilspycmd -il MyLibrary.dllNotes on modern .NET builds
现代.NET构建相关说明
- ReadyToRun images may reduce readability
- Trimmed or AOT builds may omit code
- Prefer non-trimmed builds
- ReadyToRun镜像可能会降低代码可读性
- 经过裁剪或AOT构建的程序集可能会省略部分代码
- 优先选择未裁剪的构建版本
Legal note
法律说明
Decompiling assemblies may be subject to license restrictions.
反编译程序集可能会受到许可证限制。