Fix problem with dup, and don't include nops
This commit is contained in:
parent
d7c61c65fe
commit
28f95d386e
|
@ -321,7 +321,7 @@ namespace de4dot.blocks.cflow {
|
||||||
|
|
||||||
var startInstr = block.Instructions[index];
|
var startInstr = block.Instructions[index];
|
||||||
int startInstrPushes, startInstrPops;
|
int startInstrPushes, startInstrPops;
|
||||||
DotNetUtils.calculateStackUsage(startInstr.Instruction, false, out startInstrPushes, out startInstrPops);
|
calculateStackUsage(startInstr.Instruction, false, out startInstrPushes, out startInstrPops);
|
||||||
|
|
||||||
if (startInstrPops == 0)
|
if (startInstrPops == 0)
|
||||||
return true;
|
return true;
|
||||||
|
@ -335,7 +335,7 @@ namespace de4dot.blocks.cflow {
|
||||||
index--;
|
index--;
|
||||||
|
|
||||||
int pushes, pops;
|
int pushes, pops;
|
||||||
DotNetUtils.calculateStackUsage(instr.Instruction, methodHasReturnValue, out pushes, out pops);
|
calculateStackUsage(instr.Instruction, methodHasReturnValue, out pushes, out pops);
|
||||||
if (pops < 0)
|
if (pops < 0)
|
||||||
return false; // eg. leave
|
return false; // eg. leave
|
||||||
|
|
||||||
|
@ -344,7 +344,7 @@ namespace de4dot.blocks.cflow {
|
||||||
if (!find(ref index, addIt && !otherExpr))
|
if (!find(ref index, addIt && !otherExpr))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else {
|
else if (pushes != 0 || pops != 0) {
|
||||||
if (addIt)
|
if (addIt)
|
||||||
addIndex(index);
|
addIndex(index);
|
||||||
}
|
}
|
||||||
|
@ -362,5 +362,14 @@ namespace de4dot.blocks.cflow {
|
||||||
deadInstructions.Add(index);
|
deadInstructions.Add(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void calculateStackUsage(Instruction instr, bool methodHasReturnValue, out int pushes, out int pops) {
|
||||||
|
if (instr.OpCode.Code == Code.Dup) {
|
||||||
|
pushes = 1;
|
||||||
|
pops = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
DotNetUtils.calculateStackUsage(instr, false, out pushes, out pops);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user