Fix for instructions with invalid targets

This commit is contained in:
de4dot 2011-10-05 03:36:01 +02:00
parent 182dc10ffc
commit 15c715e312
2 changed files with 8 additions and 4 deletions

View File

@ -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);
}

View File

@ -78,7 +78,9 @@ namespace de4dot.blocks {
switch (instr.OpCode.OperandType) {
case OperandType.ShortInlineBrTarget:
case OperandType.InlineBrTarget:
targets = new List<int> { instrToIndex[(Instruction)instr.Operand] };
var targetInstr = instr.Operand as Instruction;
if (targetInstr != null)
targets = new List<int> { 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<Block> { instrToBlock[instrToIndex[(Instruction)lastInstr.Operand]] };
var targetInstr = lastInstr.Operand as Instruction;
if (targetInstr != null)
block.Targets = new List<Block> { instrToBlock[instrToIndex[targetInstr]] };
break;
case OperandType.InlineSwitch: