Parent: #46
Depends on: #48
Custom Roslyn Analyzers for ConfuserEx
Domain-specific analyzers that catch the exact bugs we've been fixing at compile time, preventing regressions.
Analyzer Rules
| ID |
Pattern |
Severity |
Violations |
Prevents |
| CX001 |
typeof(X).GetMethod() with module.Import() — imports from host runtime |
Error |
3 |
Wrong mscorlib version (#7) |
| CX002 |
ResolveTypeDef()/ResolveMethodDef() without null check before use |
Warning |
6 (2-3 real bugs) |
Crashes on external assemblies (#13, #27) |
| CX003 |
ResolveThrow/ResolveTypeDefThrow usage audit |
Info |
~34 (most intentional) |
Awareness — flags spots to evaluate |
| CX004 |
Assembly.GetTypes() without ReflectionTypeLoadException catch |
Warning |
2 |
Packer startup crashes (#24) |
Scope
This issue covers:
- Create
Confuser.Analyzers project (netstandard2.0)
- Implement all 4 analyzers (CX001-CX004)
- Wire into build via ConfuserEx.Common.targets
- Fix all existing violations found by the analyzers
- Add analyzer tests
Implementation Order
- CX003 (easy, ~120 LOC) — set up project infrastructure, simple method name match
- CX001 (medium, ~170 LOC) — nested invocation detection + fix 3 violations
- CX004 (medium, ~230 LOC) — type discrimination + try-catch walk + fix 2 violations
- CX002 (hard, ~300 LOC) — data flow analysis + fix VTableAnalyzer.cs:355-356
Technical Requirements
- Target:
netstandard2.0 (required for Roslyn analyzers)
- Dependencies:
Microsoft.CodeAnalysis.CSharp ≥ 3.3.1, Microsoft.CodeAnalysis.Analyzers ≥ 3.3.4
- Testing:
Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnit
- Integration:
ProjectReference with OutputItemType=Analyzer in shared targets
Known Violations to Fix
CX001 (3 files):
Confuser.Protections/Resources/InjectPhase.cs:139
Confuser.Protections/Constants/EncodePhase.cs:124
Confuser.Protections/Compress/Compressor.cs:199
CX002 (2 files):
Confuser.Renamer/Analyzers/VTableAnalyzer.cs:355-356 (2 unguarded calls)
CX004 (2 files):
Confuser.Core/PluginDiscovery.cs:58
ConfuserEx/ComponentDiscovery.cs:15
Estimated Effort
~1,050 lines total (820 analyzer + 230 tests). Implementation order above allows incremental delivery.
Parent: #46
Depends on: #48
Custom Roslyn Analyzers for ConfuserEx
Domain-specific analyzers that catch the exact bugs we've been fixing at compile time, preventing regressions.
Analyzer Rules
typeof(X).GetMethod()withmodule.Import()— imports from host runtimeResolveTypeDef()/ResolveMethodDef()without null check before useResolveThrow/ResolveTypeDefThrowusage auditAssembly.GetTypes()withoutReflectionTypeLoadExceptioncatchScope
This issue covers:
Confuser.Analyzersproject (netstandard2.0)Implementation Order
Technical Requirements
netstandard2.0(required for Roslyn analyzers)Microsoft.CodeAnalysis.CSharp≥ 3.3.1,Microsoft.CodeAnalysis.Analyzers≥ 3.3.4Microsoft.CodeAnalysis.CSharp.Analyzer.Testing.XUnitProjectReferencewithOutputItemType=Analyzerin shared targetsKnown Violations to Fix
CX001 (3 files):
Confuser.Protections/Resources/InjectPhase.cs:139Confuser.Protections/Constants/EncodePhase.cs:124Confuser.Protections/Compress/Compressor.cs:199CX002 (2 files):
Confuser.Renamer/Analyzers/VTableAnalyzer.cs:355-356(2 unguarded calls)CX004 (2 files):
Confuser.Core/PluginDiscovery.cs:58ConfuserEx/ComponentDiscovery.cs:15Estimated Effort
~1,050 lines total (820 analyzer + 230 tests). Implementation order above allows incremental delivery.