From deda2d5d60f13b2721a2265a6c907cdd7d1a9eae Mon Sep 17 00:00:00 2001 From: de4dot Date: Fri, 28 Oct 2011 01:27:00 +0200 Subject: [PATCH] Handle case where try handler block is before try block --- blocks/CodeGenerator.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/blocks/CodeGenerator.cs b/blocks/CodeGenerator.cs index 40bea79e..aec95b14 100644 --- a/blocks/CodeGenerator.cs +++ b/blocks/CodeGenerator.cs @@ -29,6 +29,7 @@ namespace de4dot.blocks { Stack stateStack = new Stack(); List exceptions = new List(); Dictionary visited = new Dictionary(); + List notProcessedYet = new List(); class BlockState { public ScopeBlock scopeBlock; @@ -264,6 +265,13 @@ namespace de4dot.blocks { }); stateStack.Pop(); + + foreach (var bb in notProcessedYet) { + bool wasVisited; + visited.TryGetValue(bb, out wasVisited); + if (!wasVisited) + throw new ApplicationException("A block wasn't processed"); + } } void processBaseBlocks(List lb, Func placeLast) { @@ -318,6 +326,12 @@ namespace de4dot.blocks { doFilterHandlerBlock(bb as FilterHandlerBlock); else if (bb is HandlerBlock) doHandlerBlock(bb as HandlerBlock); + else if (bb is TryHandlerBlock) { + // The try handler block is usually after the try block, but sometimes it isn't... + // Handle that case here. + visited.Remove(bb); + notProcessedYet.Add(bb); + } else throw new ApplicationException("Invalid block found"); }