Allow invalid (null) targets
This commit is contained in:
parent
4692854bc8
commit
c6572aa75e
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user