diff --git a/de4dot.code/AssemblyModule.cs b/de4dot.code/AssemblyModule.cs index e0f0b455..3baafd55 100644 --- a/de4dot.code/AssemblyModule.cs +++ b/de4dot.code/AssemblyModule.cs @@ -52,7 +52,7 @@ namespace de4dot { } void readMethodsFile() { - if (new FileInfo(methodsFilename).Exists) { + if (Utils.fileExists(methodsFilename)) { using (var reader = new BinaryReader(File.Open(methodsFilename, FileMode.Open, FileAccess.Read, FileShare.Read))) { dumpedMethods = new DumpedMethodsReader(reader).read(); } diff --git a/de4dot.code/AssemblyResolver.cs b/de4dot.code/AssemblyResolver.cs index 64b763fd..25926172 100644 --- a/de4dot.code/AssemblyResolver.cs +++ b/de4dot.code/AssemblyResolver.cs @@ -72,22 +72,13 @@ namespace de4dot { static void addIfExists(string basePath, string extraPath) { try { var path = Path.Combine(basePath, extraPath); - if (pathExists(path)) + if (Utils.pathExists(path)) Instance.addSearchDirectory(path); } catch (Exception) { } } - static bool pathExists(string path) { - try { - return new DirectoryInfo(path).Exists; - } - catch (Exception) { - return false; - } - } - public void addSearchDirectory(string dir) { if (!addedDirectories.ContainsKey(dir)) { addedDirectories[dir] = true; diff --git a/de4dot.code/CommandLineParser.cs b/de4dot.code/CommandLineParser.cs index 882fa418..1ab149b3 100644 --- a/de4dot.code/CommandLineParser.cs +++ b/de4dot.code/CommandLineParser.cs @@ -95,7 +95,7 @@ namespace de4dot { miscOptions.Add(new OneArgOption("r", null, "Scan for .NET files in all subdirs", "dir", (val) => { addSearchDir(); searchDir = new FilesDeobfuscator.SearchDir(); - if (!new DirectoryInfo(val).Exists) + if (!Utils.pathExists(val)) exitError(string.Format("Directory {0} does not exist", val)); searchDir.InputDirectory = val; })); @@ -152,7 +152,7 @@ namespace de4dot { defaultOption = new OneArgOption("f", null, "Name of .NET file", "file", (val) => { addFile(); - if (!new FileInfo(val).Exists) + if (!Utils.fileExists(val)) exitError(string.Format("File \"{0}\" does not exist.", val)); newFileOptions = new ObfuscatedFile.Options { Filename = val, @@ -168,7 +168,7 @@ namespace de4dot { fileOptions.Add(new OneArgOption("m", null, "Name of .methods file", "file", (val) => { if (newFileOptions == null) exitError("Missing input file"); - if (!new FileInfo(val).Exists) + if (!Utils.fileExists(val)) exitError(string.Format("File \"{0}\" does not exist.", val)); newFileOptions.MethodsFilename = val; })); diff --git a/de4dot.code/FilesDeobfuscator.cs b/de4dot.code/FilesDeobfuscator.cs index 7f67135d..e97419a4 100644 --- a/de4dot.code/FilesDeobfuscator.cs +++ b/de4dot.code/FilesDeobfuscator.cs @@ -300,9 +300,15 @@ namespace de4dot { void createDirectories(string path) { if (string.IsNullOrEmpty(path)) return; - var di = new DirectoryInfo(path); - if (!di.Exists) - di.Create(); + try { + var di = new DirectoryInfo(path); + if (!di.Exists) + di.Create(); + } + catch (System.Security.SecurityException) { + } + catch (ArgumentException) { + } } } diff --git a/de4dot.code/Utils.cs b/de4dot.code/Utils.cs index ed1f492e..0c974db6 100644 --- a/de4dot.code/Utils.cs +++ b/de4dot.code/Utils.cs @@ -198,5 +198,23 @@ namespace de4dot { return name; return name.Substring(0, i); } + + public static bool pathExists(string path) { + try { + return new DirectoryInfo(path).Exists; + } + catch (Exception) { + return false; + } + } + + public static bool fileExists(string path) { + try { + return new FileInfo(path).Exists; + } + catch (Exception) { + return false; + } + } } }