Make sure we don't get stuck in an infinite loop
This commit is contained in:
parent
4d5d1b9089
commit
d9012fbbd3
|
@ -23,15 +23,23 @@ using Mono.Cecil.Cil;
|
||||||
|
|
||||||
namespace de4dot.blocks.cflow {
|
namespace de4dot.blocks.cflow {
|
||||||
class MethodCallInliner {
|
class MethodCallInliner {
|
||||||
|
// We can't catch all infinite loops, so inline methods at most this many times
|
||||||
|
const int MAX_ITERATIONS = 10;
|
||||||
|
|
||||||
Blocks blocks;
|
Blocks blocks;
|
||||||
Block block;
|
Block block;
|
||||||
|
int iteration;
|
||||||
|
|
||||||
public void init(Blocks blocks, Block block) {
|
public void init(Blocks blocks, Block block) {
|
||||||
this.blocks = blocks;
|
this.blocks = blocks;
|
||||||
this.block = block;
|
this.block = block;
|
||||||
|
this.iteration = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool deobfuscate() {
|
public bool deobfuscate() {
|
||||||
|
if (iteration++ >= MAX_ITERATIONS)
|
||||||
|
return false;
|
||||||
|
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
var instructions = block.Instructions;
|
var instructions = block.Instructions;
|
||||||
for (int i = 0; i < instructions.Count; i++) {
|
for (int i = 0; i < instructions.Count; i++) {
|
||||||
|
@ -46,6 +54,8 @@ namespace de4dot.blocks.cflow {
|
||||||
var method = callInstr.Operand as MethodDefinition;
|
var method = callInstr.Operand as MethodDefinition;
|
||||||
if (method == null)
|
if (method == null)
|
||||||
return false;
|
return false;
|
||||||
|
if (MemberReferenceHelper.compareMethodReferenceAndDeclaringType(method, blocks.Method))
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!method.IsStatic)
|
if (!method.IsStatic)
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user