Print number of removed instructions

This commit is contained in:
de4dot 2011-10-21 21:35:35 +02:00
parent 2ff8a0ea7a
commit 88f7a31ff1
2 changed files with 10 additions and 15 deletions

View File

@ -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() {

View File

@ -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:");