Preserve tokens if necessary
This commit is contained in:
parent
c9f1f8073e
commit
2aedcc730c
|
@ -51,10 +51,12 @@ namespace de4dot.code {
|
||||||
return module;
|
return module;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(string newFilename, bool updateMaxStack, IModuleWriterListener writerListener) {
|
public void save(string newFilename, bool preserveTokens, bool updateMaxStack, IModuleWriterListener writerListener) {
|
||||||
var writerOptions = new ModuleWriterOptions(module, writerListener);
|
var writerOptions = new ModuleWriterOptions(module, writerListener);
|
||||||
if (!updateMaxStack)
|
if (!updateMaxStack)
|
||||||
writerOptions.MetaDataOptions.Flags |= MetaDataFlags.KeepOldMaxStack;
|
writerOptions.MetaDataOptions.Flags |= MetaDataFlags.KeepOldMaxStack;
|
||||||
|
if (preserveTokens)
|
||||||
|
writerOptions.MetaDataOptions.Flags |= MetaDataFlags.PreserveTokens | MetaDataFlags.PreserveUSOffsets | MetaDataFlags.PreserveExtraSignatureData;
|
||||||
module.Write(newFilename, writerOptions);
|
module.Write(newFilename, writerOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -304,9 +304,13 @@ namespace de4dot.code {
|
||||||
return detected;
|
return detected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ShouldPreserveTokens() {
|
||||||
|
return options.KeepObfuscatorTypes || deob.Type == "un";
|
||||||
|
}
|
||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
Log.n("Saving {0}", options.NewFilename);
|
Log.n("Saving {0}", options.NewFilename);
|
||||||
assemblyModule.save(options.NewFilename, options.ControlFlowDeobfuscation, deob as IModuleWriterListener);
|
assemblyModule.save(options.NewFilename, ShouldPreserveTokens(), options.ControlFlowDeobfuscation, deob as IModuleWriterListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
IList<MethodDef> getAllMethods() {
|
IList<MethodDef> getAllMethods() {
|
||||||
|
@ -524,7 +528,7 @@ namespace de4dot.code {
|
||||||
if (!options.ControlFlowDeobfuscation) {
|
if (!options.ControlFlowDeobfuscation) {
|
||||||
// If it's the unknown type, we don't remove any types that could cause Mono.Cecil
|
// If it's the unknown type, we don't remove any types that could cause Mono.Cecil
|
||||||
// to throw an exception.
|
// to throw an exception.
|
||||||
if (deob.Type == "un" || options.KeepObfuscatorTypes)
|
if (ShouldPreserveTokens())
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -590,7 +594,10 @@ namespace de4dot.code {
|
||||||
cflowDeobfuscator.deobfuscate();
|
cflowDeobfuscator.deobfuscate();
|
||||||
|
|
||||||
if (options.ControlFlowDeobfuscation) {
|
if (options.ControlFlowDeobfuscation) {
|
||||||
numRemovedLocals = blocks.optimizeLocals();
|
// Don't remove any locals if we should preserve tokens or we won't be able
|
||||||
|
// to always preserve StandAloneSig tokens.
|
||||||
|
if (!ShouldPreserveTokens())
|
||||||
|
numRemovedLocals = blocks.optimizeLocals();
|
||||||
blocks.repartitionBlocks();
|
blocks.repartitionBlocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user