From 88f7a31ff10f5de94687901f8f3e602cfa9e367c Mon Sep 17 00:00:00 2001 From: de4dot Date: Fri, 21 Oct 2011 21:35:35 +0200 Subject: [PATCH] Print number of removed instructions --- blocks/cflow/BlocksCflowDeobfuscator.cs | 10 +--------- de4dot.code/ObfuscatedFile.cs | 15 +++++++++------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/blocks/cflow/BlocksCflowDeobfuscator.cs b/blocks/cflow/BlocksCflowDeobfuscator.cs index d05936c1..963b8d3a 100644 --- a/blocks/cflow/BlocksCflowDeobfuscator.cs +++ b/blocks/cflow/BlocksCflowDeobfuscator.cs @@ -29,15 +29,9 @@ namespace de4dot.blocks.cflow { DeadCodeRemover deadCodeRemover = new DeadCodeRemover(); DeadStoreRemover deadStoreRemover = new DeadStoreRemover(); StLdlocFixer stLdlocFixer = new StLdlocFixer(); - int numRemovedDeadBlocks; - - public int NumberOfRemovedDeadBlocks { - get { return numRemovedDeadBlocks; } - } public void init(Blocks blocks) { this.blocks = blocks; - numRemovedDeadBlocks = 0; } public void deobfuscate() { @@ -127,9 +121,7 @@ namespace de4dot.blocks.cflow { } bool removeDeadBlocks() { - int count = new DeadBlocksRemover(blocks.MethodBlocks).remove(); - numRemovedDeadBlocks += count; - return count > 0; + return new DeadBlocksRemover(blocks.MethodBlocks).remove() > 0; } bool mergeBlocks() { diff --git a/de4dot.code/ObfuscatedFile.cs b/de4dot.code/ObfuscatedFile.cs index 64e5ea64..c783af78 100644 --- a/de4dot.code/ObfuscatedFile.cs +++ b/de4dot.code/ObfuscatedFile.cs @@ -449,17 +449,14 @@ namespace de4dot { if (hasNonEmptyBody(method)) { var blocks = new Blocks(method); + int numRemovedLocals = 0; + int oldNumInstructions = method.Body.Instructions.Count; deob.deobfuscateMethodBegin(blocks); if (options.ControlFlowDeobfuscation) { cflowDeobfuscator.init(blocks); cflowDeobfuscator.deobfuscate(); - int numDeadBlocks = cflowDeobfuscator.NumberOfRemovedDeadBlocks; - if (numDeadBlocks > 0) - Log.v("Removed {0} dead block(s)", numDeadBlocks); - int numRemovedLocals = blocks.optimizeLocals(); - if (numRemovedLocals > 0) - Log.v("Removed {0} unused local(s)", numRemovedLocals); + numRemovedLocals = blocks.optimizeLocals(); blocks.repartitionBlocks(); } deobfuscateStrings(blocks); @@ -470,6 +467,12 @@ namespace de4dot { blocks.getCode(out allInstructions, out allExceptionHandlers); DotNetUtils.restoreBody(method, allInstructions, allExceptionHandlers); + if (numRemovedLocals > 0) + Log.v("Removed {0} unused local(s)", numRemovedLocals); + int numRemovedInstructions = oldNumInstructions - method.Body.Instructions.Count; + if (numRemovedInstructions > 0) + Log.v("Removed {0} dead instruction(s)", numRemovedInstructions); + const Log.LogLevel dumpLogLevel = Log.LogLevel.veryverbose; if (Log.isAtLeast(dumpLogLevel)) { Log.log(dumpLogLevel, "Deobfuscated code:");