icsharpcode / ILSpy

.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
20.73k stars 3.29k forks source link

Assert at ICSharpCode.Decompiler.IL.ControlFlow.YieldReturnDecompiler.<ConvertBody> #3115

Open greenozon opened 7 months ago

greenozon commented 7 months ago

Input code

save project

Erroneous output

Error decompiling @06000170 -----
in assembly "C:\IL_errs\err139.dll"
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at ICSharpCode.Decompiler.IL.ControlFlow.YieldReturnDecompiler.<ConvertBody>g__ConvertBranchAfterYieldReturn|35_0(Block newBlock, Block oldBlock, Int32 pos, <>c__DisplayClass35_0&) in YieldReturnDecompiler.cs:line 1016
   at ICSharpCode.Decompiler.IL.ControlFlow.YieldReturnDecompiler.ConvertBody(BlockContainer oldBody, StateRangeAnalysis rangeAnalysis) in YieldReturnDecompiler.cs:line 894
   at ICSharpCode.Decompiler.IL.ControlFlow.YieldReturnDecompiler.AnalyzeMoveNext(ILFunction function) in YieldReturnDecompiler.cs:line 786
   at ICSharpCode.Decompiler.IL.ControlFlow.YieldReturnDecompiler.Run(ILFunction function, ILTransformContext context) in YieldReturnDecompiler.cs:line 152
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1737
-- continuing with outer exception (ICSharpCode.Decompiler.DecompilerException) --
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DecompileBody(IMethod method, EntityDeclaration entityDecl, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1773
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(IMethod method, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1622
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.<>c__DisplayClass74_0.<DoDecompile>g__DoDecompileMember|0(IEntity entity, RecordDecompiler recordDecompiler, PartialTypeInfo partialType) in CSharpDecompiler.cs:line 1497
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.DoDecompile(ITypeDefinition typeDef, DecompileRun decompileRun, ITypeResolveContext decompilationContext) in CSharpDecompiler.cs:line 1364
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.Decompile(IEnumerable`1 definitions) in CSharpDecompiler.cs:line 1033
   at ICSharpCode.Decompiler.CSharp.CSharpDecompiler.Decompile(EntityHandle[] definitions) in CSharpDecompiler.cs:line 1005
   at ICSharpCode.ILSpy.CSharpLanguage.DecompileType(ITypeDefinition type, ITextOutput output, DecompilationOptions options) in offset 93
   at ICSharpCode.ILSpy.TreeNodes.TypeTreeNode.Decompile(Language language, ITextOutput output, DecompilationOptions options) in offset 8
   at ICSharpCode.ILSpy.TextView.DecompilerTextView.DecompileNodes(DecompilationContext context, ITextOutput textOutput) in offset 122
   at ICSharpCode.ILSpy.TextView.DecompilerTextView.<>c__DisplayClass53_0.<DecompileAsync>b__0() in offset 20

Details

err139.zip

ElektroKill commented 7 months ago

This file is partially obfuscated with control flow obfuscation which interferes with the decompiler. image These methods all utilize an unassigned field in the class. This is typical obfuscation for the .NET Reactor obfuscator. image

For successful decompilation, you would need to remove this obfuscation. However, I think the decompiler should not completely crash when encountering this unexpected difference in the state machine code.

greenozon commented 3 months ago

Still reproducible on the following setup:

ILSpy version 9.0.0.7612-preview1
.NET version 8.0.3+9f4b1f5d664afdfc80e1508ab7ed099dff210fbd

@siegfriedpammer