Allow invalid (null) targets

This commit is contained in:
de4dot 2011-12-28 13:21:21 +01:00
parent 4692854bc8
commit c6572aa75e
2 changed files with 11 additions and 5 deletions

View File

@ -137,7 +137,7 @@ namespace de4dot.blocks {
if (getShortBranch(instruction, out opcode)) {
const int instrSize = 5; // It's a long branch instruction
var target = (Instruction)instruction.Operand;
int distance = target.Offset - (instruction.Offset + instrSize);
int distance = target == null ? int.MaxValue : target.Offset - (instruction.Offset + instrSize);
if (-0x80 <= distance && distance <= 0x7F) {
instruction.OpCode = opcode;
changed = true;

View File

@ -86,8 +86,12 @@ namespace de4dot.blocks {
case OperandType.InlineSwitch:
var switchTargets = (Instruction[])instr.Operand;
targets = new List<int>(switchTargets.Length);
for (int j = 0; j < switchTargets.Length; j++)
targets.Add(instrToIndex[switchTargets[j]]);
for (int j = 0; j < switchTargets.Length; j++) {
var target = switchTargets[j];
if (target == null)
continue;
targets.Add(instrToIndex[target]);
}
break;
default:
@ -149,8 +153,10 @@ namespace de4dot.blocks {
var switchTargets = (Instruction[])lastInstr.Operand;
var newSwitchTargets = new List<Block>();
block.Targets = newSwitchTargets;
foreach (var target in switchTargets)
newSwitchTargets.Add(instrToBlock[instrToIndex[target]]);
foreach (var target in switchTargets) {
if (target != null)
newSwitchTargets.Add(instrToBlock[instrToIndex[target]]);
}
break;
}