Added --one-file option to deobfuscate only one file at a time
This commit is contained in:
parent
6fec29daab
commit
2094990a93
|
@ -135,6 +135,9 @@ namespace de4dot {
|
||||||
miscOptions.Add(new NoArgOption(null, "keep-types", "Keep obfuscator types, fields, methods", () => {
|
miscOptions.Add(new NoArgOption(null, "keep-types", "Keep obfuscator types, fields, methods", () => {
|
||||||
filesOptions.KeepObfuscatorTypes = true;
|
filesOptions.KeepObfuscatorTypes = true;
|
||||||
}));
|
}));
|
||||||
|
miscOptions.Add(new NoArgOption(null, "one-file", "Deobfuscate one file at a time", () => {
|
||||||
|
filesOptions.OneFileAtATime = true;
|
||||||
|
}));
|
||||||
miscOptions.Add(new NoArgOption("v", null, "Verbose", () => {
|
miscOptions.Add(new NoArgOption("v", null, "Verbose", () => {
|
||||||
Log.logLevel = Log.LogLevel.verbose;
|
Log.logLevel = Log.LogLevel.verbose;
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -36,6 +36,7 @@ namespace de4dot {
|
||||||
public bool RenameSymbols { get; set; }
|
public bool RenameSymbols { get; set; }
|
||||||
public bool ControlFlowDeobfuscation { get; set; }
|
public bool ControlFlowDeobfuscation { get; set; }
|
||||||
public bool KeepObfuscatorTypes { get; set; }
|
public bool KeepObfuscatorTypes { get; set; }
|
||||||
|
public bool OneFileAtATime { get; set; }
|
||||||
public DecrypterType? DefaultStringDecrypterType { get; set; }
|
public DecrypterType? DefaultStringDecrypterType { get; set; }
|
||||||
public List<string> DefaultStringDecrypterMethods { get; private set; }
|
public List<string> DefaultStringDecrypterMethods { get; private set; }
|
||||||
public IAssemblyClientFactory AssemblyClientFactory { get; set; }
|
public IAssemblyClientFactory AssemblyClientFactory { get; set; }
|
||||||
|
@ -63,10 +64,36 @@ namespace de4dot {
|
||||||
public void doIt() {
|
public void doIt() {
|
||||||
if (options.DetectObfuscators)
|
if (options.DetectObfuscators)
|
||||||
loadAllFiles();
|
loadAllFiles();
|
||||||
|
else if (options.OneFileAtATime)
|
||||||
|
deobfuscateOneAtATime();
|
||||||
else
|
else
|
||||||
deobfuscateAll();
|
deobfuscateAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void deobfuscateOneAtATime() {
|
||||||
|
loadAllFiles();
|
||||||
|
|
||||||
|
foreach (var file in options.Files) {
|
||||||
|
try {
|
||||||
|
file.deobfuscateBegin();
|
||||||
|
file.deobfuscate();
|
||||||
|
file.deobfuscateEnd();
|
||||||
|
|
||||||
|
if (options.RenameSymbols)
|
||||||
|
new DefinitionsRenamer(new List<IObfuscatedFile> { file }).renameAll();
|
||||||
|
|
||||||
|
file.save();
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
Log.w("Could not deobfuscate {0}. Use -v to see stack trace", file.Filename);
|
||||||
|
Utils.printStackTrace(ex, Log.LogLevel.verbose);
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
file.deobfuscateCleanUp();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void deobfuscateAll() {
|
void deobfuscateAll() {
|
||||||
loadAllFiles();
|
loadAllFiles();
|
||||||
deobfuscateAllFiles();
|
deobfuscateAllFiles();
|
||||||
|
|
|
@ -44,7 +44,7 @@ namespace de4dot {
|
||||||
indentLevel--;
|
indentLevel--;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void log(LogLevel l, string format, params object[] args) {
|
public static void log(LogLevel l, string format, params object[] args) {
|
||||||
if (l > logLevel)
|
if (l > logLevel)
|
||||||
return;
|
return;
|
||||||
string indent = new string(' ', indentLevel * indentSize);
|
string indent = new string(' ', indentLevel * indentSize);
|
||||||
|
|
|
@ -55,13 +55,7 @@ namespace de4dot {
|
||||||
Log.e("ERROR: {0}", ex.Message);
|
Log.e("ERROR: {0}", ex.Message);
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
var line = new string('-', 78);
|
Utils.printStackTrace(ex);
|
||||||
Log.e("\n\nERROR: Caught an exception:\n\n");
|
|
||||||
Log.e(line);
|
|
||||||
Log.e("Message: {0}", ex.Message);
|
|
||||||
Log.e("Type: {0}", ex.GetType());
|
|
||||||
Log.e(line);
|
|
||||||
Log.e("\n\nStack trace:\n{0}", ex.StackTrace);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -173,5 +173,15 @@ namespace de4dot {
|
||||||
public static string getPathOfOurFile(string filename) {
|
public static string getPathOfOurFile(string filename) {
|
||||||
return Path.Combine(getOurBaseDir(), filename);
|
return Path.Combine(getOurBaseDir(), filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void printStackTrace(Exception ex, Log.LogLevel logLevel = Log.LogLevel.error) {
|
||||||
|
var line = new string('-', 78);
|
||||||
|
Log.log(logLevel, "\n\nERROR: Caught an exception:\n\n");
|
||||||
|
Log.log(logLevel, line);
|
||||||
|
Log.log(logLevel, "Message: {0}", ex.Message);
|
||||||
|
Log.log(logLevel, "Type: {0}", ex.GetType());
|
||||||
|
Log.log(logLevel, line);
|
||||||
|
Log.log(logLevel, "\n\nStack trace:\n{0}", ex.StackTrace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user