Ignore errors during method deobfuscation. A warning message is logged.
This commit is contained in:
parent
133ba79c80
commit
bb886f2bdb
|
@ -523,54 +523,63 @@ namespace de4dot.code {
|
||||||
Log.v("Deobfuscating {0} ({1:X8})", method, method.MetadataToken.ToUInt32());
|
Log.v("Deobfuscating {0} ({1:X8})", method, method.MetadataToken.ToUInt32());
|
||||||
Log.indent();
|
Log.indent();
|
||||||
|
|
||||||
if (hasNonEmptyBody(method)) {
|
try {
|
||||||
var blocks = new Blocks(method);
|
deobfuscate(method, cflowDeobfuscator, methodPrinter);
|
||||||
int numRemovedLocals = 0;
|
}
|
||||||
int oldNumInstructions = method.Body.Instructions.Count;
|
catch {
|
||||||
|
Log.w("Could not deobfuscate method {0:X8}", method.MetadataToken.ToInt32());
|
||||||
deob.deobfuscateMethodBegin(blocks);
|
|
||||||
if (options.ControlFlowDeobfuscation) {
|
|
||||||
cflowDeobfuscator.init(blocks);
|
|
||||||
cflowDeobfuscator.deobfuscate();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deob.deobfuscateOther(blocks) && options.ControlFlowDeobfuscation)
|
|
||||||
cflowDeobfuscator.deobfuscate();
|
|
||||||
|
|
||||||
if (options.ControlFlowDeobfuscation) {
|
|
||||||
numRemovedLocals = blocks.optimizeLocals();
|
|
||||||
blocks.repartitionBlocks();
|
|
||||||
}
|
|
||||||
|
|
||||||
deobfuscateStrings(blocks);
|
|
||||||
deob.deobfuscateMethodEnd(blocks);
|
|
||||||
|
|
||||||
IList<Instruction> allInstructions;
|
|
||||||
IList<ExceptionHandler> allExceptionHandlers;
|
|
||||||
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:");
|
|
||||||
Log.indent();
|
|
||||||
methodPrinter.print(dumpLogLevel, method, allInstructions, allExceptionHandlers);
|
|
||||||
Log.deIndent();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
removeNoInliningAttribute(method);
|
removeNoInliningAttribute(method);
|
||||||
|
|
||||||
Log.deIndent();
|
Log.deIndent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void deobfuscate(MethodDefinition method, BlocksCflowDeobfuscator cflowDeobfuscator, MethodPrinter methodPrinter) {
|
||||||
|
if (!hasNonEmptyBody(method))
|
||||||
|
return;
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deob.deobfuscateOther(blocks) && options.ControlFlowDeobfuscation)
|
||||||
|
cflowDeobfuscator.deobfuscate();
|
||||||
|
|
||||||
|
if (options.ControlFlowDeobfuscation) {
|
||||||
|
numRemovedLocals = blocks.optimizeLocals();
|
||||||
|
blocks.repartitionBlocks();
|
||||||
|
}
|
||||||
|
|
||||||
|
deobfuscateStrings(blocks);
|
||||||
|
deob.deobfuscateMethodEnd(blocks);
|
||||||
|
|
||||||
|
IList<Instruction> allInstructions;
|
||||||
|
IList<ExceptionHandler> allExceptionHandlers;
|
||||||
|
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:");
|
||||||
|
Log.indent();
|
||||||
|
methodPrinter.print(dumpLogLevel, method, allInstructions, allExceptionHandlers);
|
||||||
|
Log.deIndent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class MethodPrinter {
|
class MethodPrinter {
|
||||||
Log.LogLevel logLevel;
|
Log.LogLevel logLevel;
|
||||||
MethodReference method;
|
MethodReference method;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user