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)) {
|
if (getShortBranch(instruction, out opcode)) {
|
||||||
const int instrSize = 5; // It's a long branch instruction
|
const int instrSize = 5; // It's a long branch instruction
|
||||||
var target = (Instruction)instruction.Operand;
|
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) {
|
if (-0x80 <= distance && distance <= 0x7F) {
|
||||||
instruction.OpCode = opcode;
|
instruction.OpCode = opcode;
|
||||||
changed = true;
|
changed = true;
|
||||||
|
|
|
@ -86,8 +86,12 @@ namespace de4dot.blocks {
|
||||||
case OperandType.InlineSwitch:
|
case OperandType.InlineSwitch:
|
||||||
var switchTargets = (Instruction[])instr.Operand;
|
var switchTargets = (Instruction[])instr.Operand;
|
||||||
targets = new List<int>(switchTargets.Length);
|
targets = new List<int>(switchTargets.Length);
|
||||||
for (int j = 0; j < switchTargets.Length; j++)
|
for (int j = 0; j < switchTargets.Length; j++) {
|
||||||
targets.Add(instrToIndex[switchTargets[j]]);
|
var target = switchTargets[j];
|
||||||
|
if (target == null)
|
||||||
|
continue;
|
||||||
|
targets.Add(instrToIndex[target]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -149,8 +153,10 @@ namespace de4dot.blocks {
|
||||||
var switchTargets = (Instruction[])lastInstr.Operand;
|
var switchTargets = (Instruction[])lastInstr.Operand;
|
||||||
var newSwitchTargets = new List<Block>();
|
var newSwitchTargets = new List<Block>();
|
||||||
block.Targets = newSwitchTargets;
|
block.Targets = newSwitchTargets;
|
||||||
foreach (var target in switchTargets)
|
foreach (var target in switchTargets) {
|
||||||
|
if (target != null)
|
||||||
newSwitchTargets.Add(instrToBlock[instrToIndex[target]]);
|
newSwitchTargets.Add(instrToBlock[instrToIndex[target]]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user