From d9012fbbd32c1a81707a4929772e6e2187c9eba3 Mon Sep 17 00:00:00 2001 From: de4dot Date: Mon, 24 Oct 2011 15:12:32 +0200 Subject: [PATCH] Make sure we don't get stuck in an infinite loop --- blocks/cflow/MethodCallInliner.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/blocks/cflow/MethodCallInliner.cs b/blocks/cflow/MethodCallInliner.cs index 1b8d1f3b..cb64656b 100644 --- a/blocks/cflow/MethodCallInliner.cs +++ b/blocks/cflow/MethodCallInliner.cs @@ -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;