backtrip — .NET Decompiler & CIL Disassembler in Rust
backtrip is a .NET decompiler and CIL disassembler written in Rust. It
parses ECMA-335 PE/CLI metadata and CIL bytecode, then reconstructs readable
C# source code from compiled .NET assemblies (.dll / .exe). It also
provides IL disassembly, obfuscation detection, structural verification, and
JSON metadata export — all from a single fast native binary with zero runtime
dependencies.
Features
.NET Metadata & IL Parsing
- PE32 / PE32+ header parsing with RVA-to-offset resolution
- Full metadata stream parsing —
#~,#Strings,#US,#GUID,#Blob - All standard metadata tables via a generic, column-based schema with correct coded-index and heap-index sizing
- Type, method, field, and parameter signatures (ECMA-335 II.23)
- Complete CIL opcode table (ECMA-335 III) and bytecode decoder
- IL disassembler producing ildasm-style output
C# Decompilation
- Arithmetic, logic, comparison, and conversion operators
- String literals, numeric constants, arguments, and locals
- Instance/static field access, array element access,
newarr/ldlen - Method calls —
call/callvirt/newobjwith argument reconstruction - Type operations —
box/unbox.any/castclass/isinst(is/as) - Constructors with access modifiers,
static/virtual/override/abstract - Type kinds — class / struct / interface / enum / delegate detection
- Generic type parameters
- Properties and events with getter/setter rendering
- Custom attributes (
[Obsolete],[DllImport], etc.)
Structured Control Flow Recovery
if/else if/else— reconstructed from conditional brancheswhileanddo-whileloops — reconstructed from backward branchesforloops — detected from initializer + condition + incrementer patternsswitchstatements — case bodies inlined,gotolabels eliminatedswitchexpressions —V_0 = ...; gotopattern → cleanswitchwithbreaktry/catch/finally— reconstructed from exception handlersusingblocks — detected fromtry/finally+Dispose()patternforeachloops — detected fromGetEnumerator+MoveNext+Currentpattern- Collection initializers —
new List()+.Add()calls collapsed to{ ... } - Object initializers —
new Type()+ field assignments collapsed to{ ... }
Tooling & Analysis
- Recursive multi-assembly decompilation —
--recursivedecompiles all.dll/.exefiles in a directory - JSON metadata export —
--jsonoutputs a structured model of types, methods, and fields for machine consumption - Obfuscation detection —
--detect-obfuscationscans for non-printable names, control-flow flattening, and string encryption - Structural verification —
--verifychecks that all types/methods/fields from metadata appear in the decompiled output
Install
The resulting binary is at target/release/backtrip. No .NET runtime is
required to run backtrip — it parses PE files directly.
Usage
# Decompile to C# (one .cs file per type) into ./decompiled
# Choose an output directory
# Decompile a single type to stdout
# Emit CIL disassembly instead of C#
# List types in the assembly
# Recursively decompile all assemblies in a directory
# Export assembly metadata as JSON
# Detect obfuscation indicators
# Verify decompiled output against metadata
CLI Reference
| Flag | Description |
|---|---|
<assembly> |
Path to .NET .dll / .exe, or a directory with --recursive |
-o, --output <dir> |
Output directory (default decompiled) |
--il |
Emit IL disassembly instead of C# source |
--list |
List types in the assembly and exit |
--type <name> |
Decompile only the matching type |
--stdout |
Print matched type to stdout (requires --type) |
--recursive |
Decompile all .dll/.exe in a directory |
--json |
Export assembly metadata as JSON to stdout |
--detect-obfuscation |
Scan for obfuscation indicators and emit warnings |
--verify |
Verify decompiled output against metadata |
-h, --help |
Show help |
-V, --version |
Show version |
Project Layout
src/
pe.rs PE parsing + RVA resolution
metadata/
streams.rs metadata root + heaps (#Strings, #US, #GUID, #Blob)
tables.rs metadata table schemas + coded indexes + row parser
signatures.rs Type / MethodSig / FieldSig parsing
reader.rs high-level accessors tying everything together
cil/
opcodes.rs full CIL opcode table (ECMA-335 III)
decoder.rs bytecode → Instruction stream
disasm.rs Instruction → IL text
decompile/
csharp.rs C# decompiler (expression-stack machine)
json.rs JSON metadata export
obfuscation.rs obfuscation detection
verify.rs structural verification
output.rs per-type file writer
main.rs CLI (clap)
lib.rs library root (for integration tests)
tests/
integration.rs end-to-end tests against a sample .NET assembly
fixtures/ sample C# project used as a test fixture
Tests
The integration tests build a small C# fixture (tests/fixtures/Sample.cs)
using the .NET SDK (version 8+) and assert the decompiler reproduces expected
C# fragments — including control flow, switch statements, switch expressions,
try/catch, using blocks, foreach, properties, and more.
How It Works
backtrip works in three stages:
- PE parsing — Reads the portable executable headers and locates the .NET metadata root and CLI header.
- Metadata decoding — Parses the metadata streams and tables to extract type definitions, method signatures, field layouts, and custom attributes.
- CIL decompilation — Decodes the IL bytecode into an instruction stream,
then uses an expression-stack machine to reconstruct C# source. Post-
processing passes restructure control flow (
if/else,while,for,switch,try/catch), collapse patterns (using,foreach, collection initializers), and clean up compiler-generated names.
Comparison with Other Tools
| Feature | backtrip | ILSpy | dnSpy | dotPeek |
|---|---|---|---|---|
| Language | Rust | C# | C# | C# |
| CLI tool | Yes | Yes | No (GUI) | No (GUI) |
| IL disassembly | Yes | Yes | Yes | Yes |
| C# decompilation | Partial | Full | Full | Full |
| JSON export | Yes | No | No | No |
| Obfuscation detection | Yes | No | No | No |
| Structural verification | Yes | No | No | No |
| Recursive batch mode | Yes | Yes | No | No |
| .NET runtime required | No | Yes | Yes | Yes |
backtrip differentiates itself by being a lightweight, dependency-free native binary with unique analysis features (obfuscation detection, verification, JSON export) that complement traditional decompilers.
Limitations & Roadmap
See TODO.md for the full roadmap. Notable upcoming work:
async/awaitstate-machine recognition and reversalyielditerator state-machine reversal- Lambda / closure full inlining (display class → lambda expression)
- Switch expressions with type patterns and property patterns
- Full round-trip verification (recompile + IL diff)
License
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.