mandiant / mandiant/capa

dotnet: detect large switch statements towards identifying flattened .NET code

Open
#1,455 3 comments 2 reactions 0 assignees View on GitHub
dotnet enhancement
Dominant language
Python
Stars
6.2k
Forks
726
Avg merge
11d 11h
Merged PRs (30d)
7

Description

The CIL [`Switch` instruction](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.emit.opcodes.switch?view=net-8.0#remarks) encodes the number of cases directly in the instruction so we can detect large switch statements. We often see large switch statements used for control flow flattening (CFF) so this could be a way for capa to detect obfuscated .NET code.

Tasks:
- [ ] research common .NET CFF techniques to determine prevalence of large switch statements (vs. large `if-else` statements, etc.) and to determine a reliable switch case count threshold that indicates flattened .NET code
- [ ] add a new `characteristic` feature e.g. `characteristic('contains flattened code')`

Contributor guide

Open the contributing guide

Research direction

Start with the linked CIL Switch instruction documentation and research common .NET control-flow-flattening techniques. Determine whether large switch statements are prevalent and establish a reliable case-count threshold; done means adding the proposed characteristic feature for flattened code.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
reverse-engineering
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.