From 07183f2acaf740c5f8fe21deea210f036ea202ce Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 28 Nov 2017 16:50:26 +0100 Subject: [PATCH] #993: Check if code size is == 0 and cancel decompilation in that case. --- ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs index b56c43342..e924319fe 100644 --- a/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs +++ b/ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs @@ -737,6 +737,15 @@ namespace ICSharpCode.Decompiler.CSharp void DecompileBody(MethodDefinition methodDefinition, IMethod method, EntityDeclaration entityDecl, ITypeResolveContext decompilationContext) { + // Special case: code size is 0 + // This might be a reference assembly: + if (methodDefinition.Body.CodeSize == 0) { + var dummy = new BlockStatement(); + dummy.InsertChildAfter(null, new EmptyStatement(), BlockStatement.StatementRole); + dummy.InsertChildAfter(null, new Comment(" Empty body found. Decompiled assembly might be a reference assembly."), Roles.Comment); + entityDecl.AddChild(dummy, Roles.Body); + return; + } var specializingTypeSystem = typeSystem.GetSpecializingTypeSystem(decompilationContext); var ilReader = new ILReader(specializingTypeSystem); ilReader.UseDebugSymbols = settings.UseDebugSymbols;