From 19dcd23b134bb0be1d548a4c13b3e0f103cf53f0 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Tue, 10 Jul 2018 13:37:11 +0200 Subject: [PATCH] Disassembler: Fix bug ILStructure primitive loop detection. --- ICSharpCode.Decompiler/Disassembler/ILStructure.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ICSharpCode.Decompiler/Disassembler/ILStructure.cs b/ICSharpCode.Decompiler/Disassembler/ILStructure.cs index b5f904cc0..3a4057850 100644 --- a/ICSharpCode.Decompiler/Disassembler/ILStructure.cs +++ b/ICSharpCode.Decompiler/Disassembler/ILStructure.cs @@ -100,7 +100,7 @@ namespace ICSharpCode.Decompiler.Disassembler AddNestedStructure(new ILStructure(module, handle, genericContext, ILStructureType.Handler, eh.HandlerOffset, eh.HandlerOffset + eh.HandlerLength, eh)); } // Very simple loop detection: look for backward branches - (var allBranches, var isAfterConditionalBranch) = FindAllBranches(body.GetILReader()); + (var allBranches, var isAfterUnconditionalBranch) = FindAllBranches(body.GetILReader()); // We go through the branches in reverse so that we find the biggest possible loop boundary first (think loops with "continue;") for (int i = allBranches.Count - 1; i >= 0; i--) { int loopEnd = allBranches[i].Source.End; @@ -111,7 +111,7 @@ namespace ICSharpCode.Decompiler.Disassembler int entryPoint = -1; // entry point is first instruction in loop if prev inst isn't an unconditional branch - if (loopStart > 0 && !isAfterConditionalBranch[loopStart]) + if (loopStart > 0 && !isAfterUnconditionalBranch[loopStart]) entryPoint = allBranches[i].Target; bool multipleEntryPoints = false; @@ -221,7 +221,7 @@ namespace ICSharpCode.Decompiler.Disassembler while (body.RemainingBytes > 0) { var offset = body.Offset; int endOffset; - var thisOpCode = ILParser.DecodeOpCode(ref body); + var thisOpCode = body.DecodeOpCode(); switch (thisOpCode.GetOperandType()) { case OperandType.BrTarget: case OperandType.ShortBrTarget: @@ -254,6 +254,8 @@ namespace ICSharpCode.Decompiler.Disassembler case ILOpCode.Endfinally: case ILOpCode.Throw: case ILOpCode.Rethrow: + case ILOpCode.Leave: + case ILOpCode.Leave_s: return true; default: return false;