Make sure we don't get stuck in an infinite loop

This commit is contained in:
de4dot 2011-10-24 15:12:32 +02:00
parent 4d5d1b9089
commit d9012fbbd3

View File

@ -23,15 +23,23 @@ using Mono.Cecil.Cil;
namespace de4dot.blocks.cflow {
class MethodCallInliner {
// We can't catch all infinite loops, so inline methods at most this many times
const int MAX_ITERATIONS = 10;
Blocks blocks;
Block block;
int iteration;
public void init(Blocks blocks, Block block) {
this.blocks = blocks;
this.block = block;
this.iteration = 0;
}
public bool deobfuscate() {
if (iteration++ >= MAX_ITERATIONS)
return false;
bool changed = false;
var instructions = block.Instructions;
for (int i = 0; i < instructions.Count; i++) {
@ -46,6 +54,8 @@ namespace de4dot.blocks.cflow {
var method = callInstr.Operand as MethodDefinition;
if (method == null)
return false;
if (MemberReferenceHelper.compareMethodReferenceAndDeclaringType(method, blocks.Method))
return false;
if (!method.IsStatic)
return false;