.NET / C# Reverse Engineering Operating Standard
ACTION REQUIRED (execute immediately after reading)
NOW: Use DIE/file/CLR header to confirm the target is .NET managed (otherwise SWITCH to ida-reverse/ / reverse-engineering/)
NOW: If obfuscation is suspected → first unpack with de4dot, producing *-clean.exe, keep the original sample
NEXT: dnSpyEx (or dnSpy MCP / ilspycmd) static: browse C# + use the IL view for key decision logic
ACT: Use dynamic debugging when plaintext/C2 is needed; when changing logic, prefer IL patch over C# recompilation
- At the end of a phase, give the user a 3–6 item next-step menu (including report export)
Scope
Prefer this skill when the task falls under these scenarios:
- Identifying and reverse engineering .NET / C# compiler output (managed PE / .exe / .dll)
- Analyzing red team Sharp* toolchains (Rubeus, SharpHound, SharpShell, etc.)
- Deobfuscating shells such as ConfuserEx / SmartAssembly / Babel / Eazfuscator / .NET Reactor
- Reverse engineering .NET loader / info-stealer / RAT decryption and C2 logic
- Patching C# programs (changing checks, changing constants, keygens)
- Analyzing the Mono/Unity managed layer prior to IL2CPP (note: IL2CPP output is native after compilation, use
reverse-engineering/ + seed-014)
If the target is a pure native binary (C/C++/Go/Rust compiled, no CLR), use reverse-engineering/, ida-reverse/, or radare2/ instead.
Core Principles
- Identify before acting: first confirm it is a .NET managed program (PE header CLR +
#~ / #Strings streams + mscoree _CorExeMain), then decide to go with dnSpy rather than IDA
- IL over C#: dnSpyEx's C# decompiler loses/distorts information (compiler-generated state machines, async/await, yield); for key logic and patches you must switch to the IL editor; the C# view is only for quick browsing
- de4dot first: when encountering an obfuscator, first run a
de4dot unpacking pass before static analysis, otherwise the strings/control flow are all garbled
- MCP integration: if a dnSpy MCP is registered in the environment (
dnspy_* tools), prefer the MCP surface for decompile / IL inspection to avoid switching back and forth to the GUI
- Evidence-based output: deobfuscated artifacts, extracted config/C2/keys, and patch diffs must all be saved to disk
Toolchain Mapping
| Capability |
First choice |
Notes |
| Decompile + debug + patch |
dnSpyEx |
The ace; the only GUI with an IL editor; the old dnSpy is unmaintained, use the Ex fork |
| Lightweight CLI / headless decompilation |
ILSpy (ilspycmd) |
Suited for batch, scripted, Linux/macOS |
| Deobfuscation |
de4dot |
The default solution for the whole ConfuserEx family, SmartAssembly, and other mainstream shells |
| Obfuscator identification |
Detect It Easy (DIE) / file |
Determine the shell type first, then decide de4dot arguments |
| Programmatic IL manipulation |
dnlib |
Write C# scripts to batch-edit metadata / string decryptors |
| Direct AI operation |
dnSpy MCP |
dnspy_decompile / dnspy_inspect_il tool surface |
Prerequisite: on a Windows host install dnSpyEx + de4dot (choco or release); on Linux/macOS use ilspycmd + dotnet runtime. See the installation matrix in references/sharp-tools.md.
Six-Phase Workflow
1. Identify (identify .NET)
Confirm the target is a managed program; do not analyze a native PE as .NET:
# Windows
file target.exe # "PE32 executable ... for MS Windows" is not enough
# Key: check for CLR
powershell -c "[System.Reflection.AssemblyName]::GetAssemblyName('target.exe')"
# Or
drag it straight into dnSpyEx —— if it opens, it is managed
# Generic
strings target.exe | grep -iE "mscoree|_CorExeMain|mscorlib|System\\."
.NET identification markers:
- PE header
Data Directory[14] (CLR Runtime Header) non-zero
mscoree.dll import / _CorExeMain entry point
#~, #Strings, #US, #GUID, #Blob metadata streams
mscorlib / System.Private.CoreLib strings
NativeAOT exception: compiled to native, no CLR header, but has System.Private.CoreLib strings and reconstructed type metadata —— route these to reverse-engineering/ (IDA/r2); this skill only provides identification hints.
2. Detect (detect the obfuscator)
# Quick identification with DIE
diec target.exe # Detect It Easy CLI
# Or drag into dnSpyEx and check for massive garbled class names / control flow deformation
Common obfuscators → unpacking strategy (see references/obfuscators.md for details):
| Obfuscator |
Signatures |
de4dot handling |
| ConfuserEx (1.0.0 / 2.x) |
<module> anti-tamper, control flow deformation, string encryption |
de4dot target.exe usually auto-detected |
| SmartAssembly |
circular/string encoding, resource compression |
de4dot target.exe |
| Babel.NET |
method body encryption, control flow |
de4dot target.exe |
| Eazfuscator.NET |
string/resource encryption |
de4dot, some versions need manual work |
| .NET Reactor |
anti-tamper + necrobit |
de4dot, newer versions may fail and need manual work |
3. Deobfuscate
# de4dot auto-identifies most shells by default
de4dot target.exe -o target-clean.exe
# Specify the type (when auto-detection fails)
de4dot --type cfze target.exe # ConfuserEx
de4dot --type sa target.exe # SmartAssembly
# Multi-layer obfuscation / de4dot reports unknown
de4dot --detect target.exe # see what it identifies it as
# You may need to patch anti-tamper first, then de4dot (see references/obfuscators.md)
Output: target-clean.exe; use it for subsequent analysis. Keep the original sample for comparison.
4. Static Analyze
Load the unpacked sample in dnSpyEx:
- C# view: quickly browse class structure, method signatures, strings (for orientation)
- IL view: key decision logic, encryption logic, and state machines must be inspected in IL (right-click → Edit IL or IL view)
- Find the entry point:
Main / Startup / module initializers (Module .cctor)
- Find key logic: search for
flag, password, verify, check, encrypt, http, Config
Locate a string → follow references back → find the method using it → inspect decision logic in IL view
5. Dynamic (dynamic debugging)
dnSpyEx debugger: attach to process / start debugging, set breakpoints on key methods, observe at runtime:
- Decrypted plaintext strings (many obfuscators only decrypt strings at runtime)
- C2 addresses, config decryption results
- Exception-driven control flow (anti-debug often hides the real path with
try/catch)
.NET dynamic debugging is far friendlier than native —— you can directly see object values and string contents. Prefer dynamic over grinding on static analysis.
6. Patch (modify as needed)
dnSpyEx → right-click method → Edit Method (C#) or Edit IL
- Change a check: ldc.i4.0 → ldc.i4.1 (false→true)
- Change a constant: edit the string/number directly
- Remove validation: nop out the whole block
File → Save Module → replace the original file
IL patch reliability > C# patch: C# recompilation may fail (missing references, bad syntax), while IL editing almost never distorts. See references/common-workflow.md.
Trigger Scenario Routing
Enter this skill when the user says:
- ".NET / C# binary reverse engineering" / "decompile a C# program"
- "analyze with dnSpy" / "patch with dnSpyEx"
- "ConfuserEx / SmartAssembly / Babel deobfuscation / unpacking"
- "analyze Sharp* tools" (Rubeus / SharpHound / SharpShell)
- "reverse a .NET malware / loader / info-stealer"
- "patch a C# program / keygen / modify a check"
When to Switch Out
- Unity games compiled with IL2CPP →
reverse-engineering/ + seed-014_unity-il2cpp-reverse.md (IL2CPP is native, not for dnSpy)
- NativeAOT output →
reverse-engineering/ (same as above, native)
- Pure native PE (no CLR) →
reverse-engineering/ / ida-reverse/
- Need to migrate symbols/functions in batch to another version →
binary-diff/
- Need to draw attack path / call chain diagrams →
diagram-generator/
Routing Context
Upstream entry points: skills/SKILL.md (master control), routing.md
Downstream exits:
- IL2CPP / NativeAOT (native) →
reverse-engineering/
- Deep analysis of native .so/.dll sections →
ida-reverse/ / radare2/
- Need the AI to operate dnSpy directly → register and integrate the dnSpy MCP (see
references/sharp-tools.md)
Peer related modules:
reverse-engineering/languages-compiled.md (the .NET intro points to this module)
apk-reverse/ (for Xamarin/MAUI Android reverse engineering you can switch back to this module to inspect the C# layer)
Reference Documents
- references/obfuscators.md — detailed ConfuserEx / SmartAssembly / Babel / Eazfuscator / .NET Reactor deobfuscation + anti-tamper bypass
- references/common-workflow.md — full workflow, IL patch reliability, string decryptor extraction, state machine identification
- references/sharp-tools.md — red team Sharp* tool analysis, tool installation matrix, dnSpy MCP integration, community resource index
Task Completion Self-Check
1---2name: router-reverse-skill-router-dotnet-reverse3description: .NET / C# binary reverse engineering. Use when the target is a .NET assembly (PE header containing CLR, .exe/.dll managed program), C# compiler output (including NativeAOT), red team Sharp* tools (Rubeus / SharpHound / etc.), .NET obfuscated programs (ConfuserEx / SmartAssembly / Babel / Eazfuscator), or .NET loaders / info-stealers / wrapped malware. Prefer dnSpyEx + de4dot; integrate with dnSpy MCP when the AI needs to operate directly. Not for pure native binaries (use reverse-engineering / ida-reverse).4license: MIT5---67# .NET / C# Reverse Engineering Operating Standard89## ACTION REQUIRED (execute immediately after reading)10111. `NOW`: Use DIE/`file`/CLR header to confirm the target is .NET managed (otherwise SWITCH to `ida-reverse/` / `reverse-engineering/`)122. `NOW`: If obfuscation is suspected → first unpack with `de4dot`, producing `*-clean.exe`, keep the original sample133. `NEXT`: dnSpyEx (or dnSpy MCP / `ilspycmd`) static: browse C# + use the **IL view** for key decision logic144. `ACT`: Use dynamic debugging when plaintext/C2 is needed; when changing logic, prefer **IL patch** over C# recompilation155. At the end of a phase, give the user a 3–6 item next-step menu (including report export)1617## Scope1819Prefer this skill when the task falls under these scenarios:2021- Identifying and reverse engineering .NET / C# compiler output (managed PE / .exe / .dll)22- Analyzing red team Sharp* toolchains (Rubeus, SharpHound, SharpShell, etc.)23- Deobfuscating shells such as ConfuserEx / SmartAssembly / Babel / Eazfuscator / .NET Reactor24- Reverse engineering .NET loader / info-stealer / RAT decryption and C2 logic25- Patching C# programs (changing checks, changing constants, keygens)26- Analyzing the Mono/Unity managed layer prior to IL2CPP (note: IL2CPP output is native after compilation, use `reverse-engineering/` + seed-014)2728If the target is a pure native binary (C/C++/Go/Rust compiled, no CLR), use `reverse-engineering/`, `ida-reverse/`, or `radare2/` instead.2930## Core Principles3132- **Identify before acting**: first confirm it is a .NET managed program (PE header CLR + `#~` / `#Strings` streams + mscoree `_CorExeMain`), then decide to go with dnSpy rather than IDA33- **IL over C#**: dnSpyEx's C# decompiler loses/distorts information (compiler-generated state machines, async/await, yield); for key logic and patches you must switch to the **IL editor**; the C# view is only for quick browsing34- **de4dot first**: when encountering an obfuscator, first run a `de4dot` unpacking pass before static analysis, otherwise the strings/control flow are all garbled35- **MCP integration**: if a dnSpy MCP is registered in the environment (`dnspy_*` tools), prefer the MCP surface for decompile / IL inspection to avoid switching back and forth to the GUI36- **Evidence-based output**: deobfuscated artifacts, extracted config/C2/keys, and patch diffs must all be saved to disk3738## Toolchain Mapping3940| Capability | First choice | Notes |41|------|------|------|42| Decompile + debug + patch | **dnSpyEx** | The ace; the only GUI with an IL editor; the old dnSpy is unmaintained, use the Ex fork |43| Lightweight CLI / headless decompilation | **ILSpy** (`ilspycmd`) | Suited for batch, scripted, Linux/macOS |44| Deobfuscation | **de4dot** | The default solution for the whole ConfuserEx family, SmartAssembly, and other mainstream shells |45| Obfuscator identification | **Detect It Easy (DIE)** / **file** | Determine the shell type first, then decide de4dot arguments |46| Programmatic IL manipulation | **dnlib** | Write C# scripts to batch-edit metadata / string decryptors |47| Direct AI operation | **dnSpy MCP** | `dnspy_decompile` / `dnspy_inspect_il` tool surface |4849> Prerequisite: on a Windows host install dnSpyEx + de4dot (choco or release); on Linux/macOS use `ilspycmd` + `dotnet runtime`. See the installation matrix in `references/sharp-tools.md`.5051## Six-Phase Workflow5253### 1. Identify (identify .NET)5455Confirm the target is a managed program; do not analyze a native PE as .NET:5657```powershell58# Windows59file target.exe # "PE32 executable ... for MS Windows" is not enough60# Key: check for CLR61powershell -c "[System.Reflection.AssemblyName]::GetAssemblyName('target.exe')"62# Or63drag it straight into dnSpyEx —— if it opens, it is managed6465# Generic66strings target.exe | grep -iE "mscoree|_CorExeMain|mscorlib|System\\."67```6869**.NET identification markers:**70- PE header `Data Directory[14]` (CLR Runtime Header) non-zero71- `mscoree.dll` import / `_CorExeMain` entry point72- `#~`, `#Strings`, `#US`, `#GUID`, `#Blob` metadata streams73- `mscorlib` / `System.Private.CoreLib` strings7475**NativeAOT exception:** compiled to native, no CLR header, but has `System.Private.CoreLib` strings and reconstructed type metadata —— route these to `reverse-engineering/` (IDA/r2); this skill only provides identification hints.7677### 2. Detect (detect the obfuscator)7879```powershell80# Quick identification with DIE81diec target.exe # Detect It Easy CLI82# Or drag into dnSpyEx and check for massive garbled class names / control flow deformation83```8485Common obfuscators → unpacking strategy (see `references/obfuscators.md` for details):8687| Obfuscator | Signatures | de4dot handling |88|--------|------|------------|89| ConfuserEx (1.0.0 / 2.x) | `<module>` anti-tamper, control flow deformation, string encryption | `de4dot target.exe` usually auto-detected |90| SmartAssembly | `circular`/`string encoding`, resource compression | `de4dot target.exe` |91| Babel.NET | method body encryption, control flow | `de4dot target.exe` |92| Eazfuscator.NET | string/resource encryption | `de4dot`, some versions need manual work |93| .NET Reactor | anti-tamper + necrobit | `de4dot`, newer versions may fail and need manual work |9495### 3. Deobfuscate9697```powershell98# de4dot auto-identifies most shells by default99de4dot target.exe -o target-clean.exe100101# Specify the type (when auto-detection fails)102de4dot --type cfze target.exe # ConfuserEx103de4dot --type sa target.exe # SmartAssembly104105# Multi-layer obfuscation / de4dot reports unknown106de4dot --detect target.exe # see what it identifies it as107# You may need to patch anti-tamper first, then de4dot (see references/obfuscators.md)108```109110Output: `target-clean.exe`; use it for subsequent analysis. **Keep the original sample** for comparison.111112### 4. Static Analyze113114Load the unpacked sample in dnSpyEx:115116- **C# view**: quickly browse class structure, method signatures, strings (for orientation)117- **IL view**: key decision logic, encryption logic, and state machines must be inspected in IL (right-click → Edit IL or IL view)118- Find the entry point: `Main` / `Startup` / module initializers (`Module .cctor`)119- Find key logic: search for `flag`, `password`, `verify`, `check`, `encrypt`, `http`, `Config`120121```text122Locate a string → follow references back → find the method using it → inspect decision logic in IL view123```124125### 5. Dynamic (dynamic debugging)126127dnSpyEx debugger: attach to process / start debugging, set breakpoints on key methods, observe at runtime:128- Decrypted plaintext strings (many obfuscators only decrypt strings at runtime)129- C2 addresses, config decryption results130- Exception-driven control flow (anti-debug often hides the real path with `try/catch`)131132> .NET dynamic debugging is far friendlier than native —— you can directly see object values and string contents. Prefer dynamic over grinding on static analysis.133134### 6. Patch (modify as needed)135136```text137dnSpyEx → right-click method → Edit Method (C#) or Edit IL138 - Change a check: ldc.i4.0 → ldc.i4.1 (false→true)139 - Change a constant: edit the string/number directly140 - Remove validation: nop out the whole block141File → Save Module → replace the original file142```143144**IL patch reliability > C# patch**: C# recompilation may fail (missing references, bad syntax), while IL editing almost never distorts. See `references/common-workflow.md`.145146## Trigger Scenario Routing147148Enter this skill when the user says:149- ".NET / C# binary reverse engineering" / "decompile a C# program"150- "analyze with dnSpy" / "patch with dnSpyEx"151- "ConfuserEx / SmartAssembly / Babel deobfuscation / unpacking"152- "analyze Sharp* tools" (Rubeus / SharpHound / SharpShell)153- "reverse a .NET malware / loader / info-stealer"154- "patch a C# program / keygen / modify a check"155156## When to Switch Out157158- Unity games compiled with IL2CPP → `reverse-engineering/` + `seed-014_unity-il2cpp-reverse.md` (IL2CPP is native, not for dnSpy)159- NativeAOT output → `reverse-engineering/` (same as above, native)160- Pure native PE (no CLR) → `reverse-engineering/` / `ida-reverse/`161- Need to migrate symbols/functions in batch to another version → `binary-diff/`162- Need to draw attack path / call chain diagrams → `diagram-generator/`163164## Routing Context165166**Upstream entry points**: `skills/SKILL.md` (master control), `routing.md`167**Downstream exits**:168- IL2CPP / NativeAOT (native) → `reverse-engineering/`169- Deep analysis of native .so/.dll sections → `ida-reverse/` / `radare2/`170- Need the AI to operate dnSpy directly → register and integrate the dnSpy MCP (see `references/sharp-tools.md`)171172**Peer related modules**:173- `reverse-engineering/languages-compiled.md` (the .NET intro points to this module)174- `apk-reverse/` (for Xamarin/MAUI Android reverse engineering you can switch back to this module to inspect the C# layer)175176## Reference Documents177178- [references/obfuscators.md](references/obfuscators.md) — detailed ConfuserEx / SmartAssembly / Babel / Eazfuscator / .NET Reactor deobfuscation + anti-tamper bypass179- [references/common-workflow.md](references/common-workflow.md) — full workflow, IL patch reliability, string decryptor extraction, state machine identification180- [references/sharp-tools.md](references/sharp-tools.md) — red team Sharp* tool analysis, tool installation matrix, dnSpy MCP integration, community resource index181182## Task Completion Self-Check183184- [ ] Was CLR / managed identity confirmed (or was this skill SWITCHED out of)?185- [ ] For obfuscated samples, was de4dot / equivalent unpacking done before deep analysis?186- [ ] Was key logic verified in the IL view (rather than only reading C# pseudocode)?187- [ ] Were artifacts (clean sample / config / patch diff) saved to disk and reproducible?188- [ ] Was a next-step menu or report exit provided?