Move disposing of module to caller
The reason is that some deobfuscators require it to be non-disposed when their reload() method is called.
This commit is contained in:
parent
9a8218e68f
commit
2e61a8a757
|
@ -44,8 +44,6 @@ namespace de4dot.code {
|
||||||
}
|
}
|
||||||
|
|
||||||
ModuleDefMD setModule(ModuleDefMD newModule) {
|
ModuleDefMD setModule(ModuleDefMD newModule) {
|
||||||
if (module != null)
|
|
||||||
module.Dispose();
|
|
||||||
module = newModule;
|
module = newModule;
|
||||||
TheAssemblyResolver.Instance.addModule(module);
|
TheAssemblyResolver.Instance.addModule(module);
|
||||||
module.EnableTypeDefFindCache = true;
|
module.EnableTypeDefFindCache = true;
|
||||||
|
|
|
@ -171,6 +171,7 @@ namespace de4dot.code {
|
||||||
}
|
}
|
||||||
|
|
||||||
void loadModule(IEnumerable<IDeobfuscator> deobfuscators) {
|
void loadModule(IEnumerable<IDeobfuscator> deobfuscators) {
|
||||||
|
ModuleDefMD oldModule = module;
|
||||||
try {
|
try {
|
||||||
module = assemblyModule.load();
|
module = assemblyModule.load();
|
||||||
}
|
}
|
||||||
|
@ -179,6 +180,10 @@ namespace de4dot.code {
|
||||||
throw new BadImageFormatException();
|
throw new BadImageFormatException();
|
||||||
Logger.v("Unpacked native file");
|
Logger.v("Unpacked native file");
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
if (oldModule != null)
|
||||||
|
oldModule.Dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool unpackNativeImage(IEnumerable<IDeobfuscator> deobfuscators) {
|
bool unpackNativeImage(IEnumerable<IDeobfuscator> deobfuscators) {
|
||||||
|
@ -194,6 +199,7 @@ namespace de4dot.code {
|
||||||
if (unpackedData == null)
|
if (unpackedData == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
var oldModule = module;
|
||||||
try {
|
try {
|
||||||
module = assemblyModule.load(unpackedData);
|
module = assemblyModule.load(unpackedData);
|
||||||
}
|
}
|
||||||
|
@ -201,6 +207,10 @@ namespace de4dot.code {
|
||||||
Logger.w("Could not load unpacked data. File: {0}, deobfuscator: {0}", peImage.FileName ?? "(unknown filename)", deob.TypeLong);
|
Logger.w("Could not load unpacked data. File: {0}, deobfuscator: {0}", peImage.FileName ?? "(unknown filename)", deob.TypeLong);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
if (oldModule != null)
|
||||||
|
oldModule.Dispose();
|
||||||
|
}
|
||||||
this.deob = deob;
|
this.deob = deob;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -372,8 +382,10 @@ namespace de4dot.code {
|
||||||
void reloadModule(byte[] newModuleData, DumpedMethods dumpedMethods) {
|
void reloadModule(byte[] newModuleData, DumpedMethods dumpedMethods) {
|
||||||
Logger.v("Reloading decrypted assembly (original filename: {0})", Filename);
|
Logger.v("Reloading decrypted assembly (original filename: {0})", Filename);
|
||||||
simpleDeobfuscatorFlags.Clear();
|
simpleDeobfuscatorFlags.Clear();
|
||||||
|
using (var oldModule = module) {
|
||||||
module = assemblyModule.reload(newModuleData, createDumpedMethodsRestorer(dumpedMethods), deob as IStringDecrypter);
|
module = assemblyModule.reload(newModuleData, createDumpedMethodsRestorer(dumpedMethods), deob as IStringDecrypter);
|
||||||
deob = deob.moduleReloaded(module);
|
deob = deob.moduleReloaded(module);
|
||||||
|
}
|
||||||
initializeDeobfuscator();
|
initializeDeobfuscator();
|
||||||
deob.DeobfuscatedFile = this;
|
deob.DeobfuscatedFile = this;
|
||||||
updateDynamicStringInliner();
|
updateDynamicStringInliner();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user