dotnet-inspect-decompiler

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

dotnet-inspect: decompiler and IL

dotnet-inspect:反编译器与IL工具

Use this skill to understand how code actually works from the assembly you have. The decompiler runs locally against the acquired assembly, and the IL and annotated views can reveal more than the original source. Package and PDB acquisition can use the network; add
--offline
to prohibit network access. For authored original source, use the
sourcelink
skill and follow its checksum-verification boundaries before treating fetched content as authoritative.
bash
dnx dotnet-inspect -y -- <command>
使用此技能可以从你拥有的程序集中了解代码的实际运行机制。反编译器会针对获取到的程序集在本地运行,IL视图和注释视图能展示比原始源码更多的信息。包和PDB文件的获取可以使用网络;添加
--offline
参数可禁止网络访问。如果需要查看作者提供的原始源码,请使用
sourcelink
技能,并在将获取的内容视为权威内容之前遵循其校验和验证规则。
bash
dnx dotnet-inspect -y -- <command>

Decompiled source and IL

反编译源码与IL

A selected overload and bare
-S
both render its bounded
Signature
overview. Select
Decompiled Source
explicitly when implementation evidence is the question. Use
-S "Decompiled Source,Annotated Source,IL" --offline
for the full zero-network evidence set:
  • Decompiled Source
    — raised, lowered C# (readable best-effort); locals without PDB names use byte-preserving type/role-derived names by default.
  • Annotated Source
    — C# with hidden-fact comments and interleaved IL.
  • IL
    — raw IL, the highest-fidelity view.
Use
Annotated Source
or
IL
when exact opcodes, offsets, branches, tokens, or calls matter. Use
--bare
for a whole-type listing.
-S @Source
is broader and may fetch network
Original Source
content when SourceLink is available; that network body is not checksum-verified by default.
--project
reads existing restored assets; restore/build first if dependencies changed.
bash
dnx dotnet-inspect -y -- member JsonSerializer --platform System.Text.Json \
  Serialize:1 -S "Decompiled Source,Annotated Source,IL" --offline
dnx dotnet-inspect -y -- member JsonSerializer --platform System.Text.Json Serialize:1 -S "Annotated Source"
dnx dotnet-inspect -y -- type JsonSerializer --platform System.Text.Json -S "Decompiled Source" --bare
dnx dotnet-inspect -y -- member Command --project ./src/App Add:1 -S "Decompiled Source,Annotated Source,IL"
选择特定重载或仅使用
-S
参数都会生成其对应的
Signature
概览。当需要查看实现细节时,请明确选择
Decompiled Source
。使用
-S "Decompiled Source,Annotated Source,IL" --offline
可获取完整的无网络依赖证据集:
  • Decompiled Source
    ——经过转换的C#代码(尽可能保证可读性);默认情况下,没有PDB名称的局部变量会使用保留字节信息的类型/角色派生名称。
  • Annotated Source
    ——带有隐藏信息注释和交错IL代码的C#代码。
  • IL
    ——原始IL代码,是保真度最高的视图。
当需要关注精确的操作码、偏移量、分支、标记或调用时,请使用
Annotated Source
IL
视图。使用
--bare
参数可查看完整类型列表。
-S @Source
的范围更广,当SourceLink可用时可能会通过网络获取
Original Source
内容;默认情况下,该网络获取的内容不进行校验和验证。
--project
参数会读取已恢复的现有资源;如果依赖项发生变化,请先执行恢复/构建操作。
bash
dnx dotnet-inspect -y -- member JsonSerializer --platform System.Text.Json \
  Serialize:1 -S "Decompiled Source,Annotated Source,IL" --offline
dnx dotnet-inspect -y -- member JsonSerializer --platform System.Text.Json Serialize:1 -S "Annotated Source"
dnx dotnet-inspect -y -- type JsonSerializer --platform System.Text.Json -S "Decompiled Source" --bare
dnx dotnet-inspect -y -- member Command --project ./src/App Add:1 -S "Decompiled Source,Annotated Source,IL"

Readability and taste

可读性与风格偏好

--readable-names
replaces compiler-style local names such as
V_0
where the body provides a stable readable alternative. It is independent of C# taste options. A tool-owned
.dotnet-inspectconfig
, discovered by walking up from the working directory, selects configured spellings;
--taste
requests the full supported taste set for one invocation.
Applied Taste
reports which choices actually changed the rendered body.
bash
dnx dotnet-inspect -y -- member MyType Method:1 --library MyLib.dll \
  -S "Decompiled Source,Applied Taste" --taste --readable-names
--readable-names
参数会将编译器生成的局部变量名(如
V_0
)替换为代码中可用的稳定可读名称。它独立于C#风格选项。工具会从工作目录向上查找
.dotnet-inspectconfig
配置文件来选择预设的拼写方式;
--taste
参数会在单次调用中启用所有支持的风格选项。
Applied Taste
会报告哪些选项实际修改了生成的代码内容。
bash
dnx dotnet-inspect -y -- member MyType Method:1 --library MyLib.dll \
  -S "Decompiled Source,Applied Taste" --taste --readable-names

Focusing annotations

聚焦注释信息

By default every hidden fact renders as a trailing
//
comment. A fact with a long detail can push that comment far off the right edge.
--focus
promotes matching facts to a
^^^^
underline beneath the statement, wrapped into a readable block:
bash
dnx dotnet-inspect -y -- member Cache --project ./src/App Pump:1 -S "Annotated Source" --focus allocation
The value matches an annotation category, an exact id, or a dotted-id prefix on a segment boundary (
alloc
selects
alloc.box
, not
allocator.x
). It promotes, it never filters — facts that do not match keep the trailing form, so
--focus
narrows attention without hiding anything. A focus that matches nothing says so and names the families the member does have.
默认情况下,所有隐藏信息都会以尾部
//
注释的形式呈现。包含长细节的信息可能会导致注释被推到右侧很远的位置。
--focus
参数会将匹配的信息提升为语句下方的
^^^^
下划线注释,并整理为可读的块:
bash
dnx dotnet-inspect -y -- member Cache --project ./src/App Pump:1 -S "Annotated Source" --focus allocation
参数值可以匹配注释类别、精确ID或分段边界上的点分ID前缀(
alloc
会选中
alloc.box
,但不会选中
allocator.x
)。该参数仅提升显示优先级,不会过滤内容——不匹配的信息仍会保留尾部注释形式,因此
--focus
可以缩小关注范围但不会隐藏任何内容。如果没有匹配到任何信息,工具会提示这一点并列出该成员包含的信息类别。

Fidelity model

保真度模型

The decompiler degrades honestly: IL with no faithful C# spelling renders as a visible comment and lowers the result's fidelity level (
Full
->
Partial
->
StructuredOnly
->
IlOnly
->
Failed
) instead of emitting plausible-but-wrong source, with a stable
DEC####
diagnostic on every degradation.
Decompiled Source
is lowered C#; raw/annotated
IL
is highest fidelity.
If decompiled output looks wrong, capture
Decompiled Source
,
Annotated Source
,
Original Source
,
Source Diff
(via the
sourcelink
skill), and
IL
together; maintainers diagnose pipeline state with DecompilerHarness.
Select
Fidelity Causes
for the typed
DEC####
cause census behind that fidelity grade. It distinguishes a Full method (complete, no causes), a method without a body (absent), and a failed inspection.
bash
dnx dotnet-inspect -y -- member MyType MyMethod:1 --library MyLib.dll -S "Fidelity Causes"
反编译器会如实呈现降级情况:无法转换为可信C#代码的IL会显示为可见注释,并降低结果的保真度级别(
Full
Partial
StructuredOnly
IlOnly
Failed
),而不是生成看似合理但错误的源码,每次降级都会附带稳定的
DEC####
诊断信息。
Decompiled Source
是经过转换的C#代码;原始/注释版
IL
是保真度最高的视图。
如果反编译输出看起来有问题,请同时收集
Decompiled Source
Annotated Source
Original Source
Source Diff
(通过
sourcelink
技能获取)和
IL
内容;维护人员会使用DecompilerHarness诊断流水线状态。
选择
Fidelity Causes
可查看该保真度级别背后的
DEC####
类型原因统计。它会区分完整方法(无问题)、无方法体的方法(缺失)和检查失败的情况。
bash
dnx dotnet-inspect -y -- member MyType MyMethod:1 --library MyLib.dll -S "Fidelity Causes"

Locate code by IL offset

通过IL偏移量定位代码

bash
dnx dotnet-inspect -y -- library Foo --il-offset 0x06000001+0x5
Use
library Foo --il-offset 0x06000001+0x5
(MethodDef token plus IL offset) to compose its default source-location, member, instruction, exception, callsite, and return-address sections. Allocation, safety, and cost are opt-in; request them with
-S "Context: Allocation,Context: Safety,Context: Cost"
. Use
--il-offsets coordinates.txt
for a sparse batch. For call edges (what a method calls, who calls it), see the
relationships
skill.
bash
dnx dotnet-inspect -y -- library Foo --il-offset 0x06000001+0x5
使用
library Foo --il-offset 0x06000001+0x5
(MethodDef标记加IL偏移量)可生成默认的源码位置、成员、指令、异常、调用点和返回地址部分内容。分配、安全性和成本是可选内容;可通过
-S "Context: Allocation,Context: Safety,Context: Cost"
请求获取这些信息。使用
--il-offsets coordinates.txt
可进行批量查询。如需查看调用关系(方法调用的对象以及调用该方法的对象),请使用
relationships
技能。