diff --git a/blocks/Block.cs b/blocks/Block.cs index 0d4c01c9..bf280366 100644 --- a/blocks/Block.cs +++ b/blocks/Block.cs @@ -82,9 +82,9 @@ namespace de4dot.blocks { if (!LastInstr.isBr()) return; - if (fallThrough != null || targets == null || targets.Count != 1) + if (fallThrough != null || (LastInstr.Operand != null && (targets == null || targets.Count != 1))) throw new ApplicationException("Invalid block state when last instr is a br/br.s"); - fallThrough = targets[0]; + fallThrough = LastInstr.Operand != null ? targets[0] : null; targets = null; instructions.RemoveAt(instructions.Count - 1); } diff --git a/blocks/InstructionListParser.cs b/blocks/InstructionListParser.cs index 75a1cd52..6ba1f3ef 100644 --- a/blocks/InstructionListParser.cs +++ b/blocks/InstructionListParser.cs @@ -78,7 +78,9 @@ namespace de4dot.blocks { switch (instr.OpCode.OperandType) { case OperandType.ShortInlineBrTarget: case OperandType.InlineBrTarget: - targets = new List { instrToIndex[(Instruction)instr.Operand] }; + var targetInstr = instr.Operand as Instruction; + if (targetInstr != null) + targets = new List { instrToIndex[targetInstr] }; break; case OperandType.InlineSwitch: @@ -138,7 +140,9 @@ namespace de4dot.blocks { switch (lastInstr.OpCode.OperandType) { case OperandType.ShortInlineBrTarget: case OperandType.InlineBrTarget: - block.Targets = new List { instrToBlock[instrToIndex[(Instruction)lastInstr.Operand]] }; + var targetInstr = lastInstr.Operand as Instruction; + if (targetInstr != null) + block.Targets = new List { instrToBlock[instrToIndex[targetInstr]] }; break; case OperandType.InlineSwitch: