Skip to content

Commit af4fd6a

Browse files
authored
Merge pull request #10 from mitchcapper/option_to_allow_exception_onload_pr
Add -re option to handle exceptions when loading files gracefully
2 parents 6023387 + 80fed4d commit af4fd6a

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

de4dot.cui/CommandLineParser.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ void AddAllOptions() {
107107
ExitError("Missing -r option");
108108
searchDir.SkipUnknownObfuscators = true;
109109
}));
110+
miscOptions.Add(new NoArgOption("re", null, "Skip recursively found files that throw an exception on load", () => {
111+
if (searchDir == null)
112+
ExitError("Missing -r option");
113+
searchDir.AllowFileLoadError = true;
114+
}));
115+
110116
miscOptions.Add(new NoArgOption("d", null, "Detect obfuscators and exit", () => {
111117
filesOptions.DetectObfuscators = true;
112118
}));

de4dot.cui/FilesDeobfuscator.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public class SearchDir {
7575
public string InputDirectory { get; set; }
7676
public string OutputDirectory { get; set; }
7777
public bool SkipUnknownObfuscators { get; set; }
78+
public bool AllowFileLoadError { get; set; }
7879
}
7980

8081
public FilesDeobfuscator(Options options) => this.options = options;
@@ -262,7 +263,15 @@ IEnumerable<IObfuscatedFile> LoadFiles(SearchDir searchDir) {
262263
}
263264
if (ok) {
264265
foreach (var filename in DoDirectoryInfo(searchDir, di)) {
265-
var obfuscatedFile = CreateObfuscatedFile(searchDir, filename);
266+
IObfuscatedFile obfuscatedFile = null;
267+
try {
268+
obfuscatedFile = CreateObfuscatedFile(searchDir, filename);
269+
}catch (Exception ex){
270+
if (!searchDir.AllowFileLoadError)
271+
throw;
272+
Logger.Instance.Log(false, null, LoggerEvent.Warning, "Could not load file {0} Use -v to see stack trace", filename);
273+
Program.PrintStackTrace(ex, LoggerEvent.Verbose);
274+
}
266275
if (obfuscatedFile != null)
267276
yield return obfuscatedFile;
268277
}

0 commit comments

Comments
 (0)