IEnumerable <string> DoDirectoryInfo(SearchDir searchDir, DirectoryInfo di) { if (!di.Exists) { return(new List <string>()); } if (visitedDirectory.ContainsKey(di.FullName)) { return(new List <string>()); } visitedDirectory[di.FullName] = true; FileSystemInfo[] fsinfos; try { fsinfos = di.GetFileSystemInfos(); } catch (UnauthorizedAccessException) { return(new List <string>()); } catch (IOException) { return(new List <string>()); } catch (System.Security.SecurityException) { return(new List <string>()); } return(RecursiveAdd(searchDir, fsinfos)); }
IEnumerable <IObfuscatedFile> LoadFiles(SearchDir searchDir) { DirectoryInfo di = null; bool ok = false; try { di = new DirectoryInfo(searchDir.InputDirectory); if (di.Exists) { ok = true; } } catch (System.Security.SecurityException) { } catch (ArgumentException) { } if (ok) { foreach (var filename in DoDirectoryInfo(searchDir, di)) { var obfuscatedFile = CreateObfuscatedFile(searchDir, filename); if (obfuscatedFile != null) { yield return(obfuscatedFile); } } } }
IObfuscatedFile CreateObfuscatedFile(SearchDir searchDir, string filename) { var fileOptions = new ObfuscatedFile.Options { Filename = Utils.GetFullPath(filename), ControlFlowDeobfuscation = options.ControlFlowDeobfuscation, KeepObfuscatorTypes = options.KeepObfuscatorTypes, MetaDataFlags = options.MetaDataFlags, RenamerFlags = options.RenamerFlags, }; if (options.DefaultStringDecrypterType != null) { fileOptions.StringDecrypterType = options.DefaultStringDecrypterType.Value; } fileOptions.StringDecrypterMethods.AddRange(options.DefaultStringDecrypterMethods); if (!string.IsNullOrEmpty(searchDir.OutputDirectory)) { var inDir = Utils.GetFullPath(searchDir.InputDirectory); var outDir = Utils.GetFullPath(searchDir.OutputDirectory); if (!Utils.StartsWith(fileOptions.Filename, inDir, StringComparison.OrdinalIgnoreCase)) { throw new UserException(string.Format("Filename {0} does not start with inDir {1}", fileOptions.Filename, inDir)); } var subDirs = fileOptions.Filename.Substring(inDir.Length); if (subDirs.Length > 0 && subDirs[0] == Path.DirectorySeparatorChar) { subDirs = subDirs.Substring(1); } fileOptions.NewFilename = Utils.GetFullPath(Path.Combine(outDir, subDirs)); if (fileOptions.Filename.Equals(fileOptions.NewFilename, StringComparison.OrdinalIgnoreCase)) { throw new UserException(string.Format("Input and output filename is the same: {0}", fileOptions.Filename)); } } var obfuscatedFile = new ObfuscatedFile(fileOptions, options.ModuleContext, options.AssemblyClientFactory); if (Add(obfuscatedFile, searchDir.SkipUnknownObfuscators, false)) { return(obfuscatedFile); } obfuscatedFile.Dispose(); return(null); }
IEnumerable <string> RecursiveAdd(SearchDir searchDir, IEnumerable <FileSystemInfo> fileSystemInfos) { foreach (var fsi in fileSystemInfos) { if ((int)(fsi.Attributes & System.IO.FileAttributes.Directory) != 0) { foreach (var filename in DoDirectoryInfo(searchDir, (DirectoryInfo)fsi)) { yield return(filename); } } else { var fi = (FileInfo)fsi; if (fi.Exists) { yield return(fi.FullName); } } } }
IObfuscatedFile CreateObfuscatedFile(SearchDir searchDir, string filename) { var fileOptions = new ObfuscatedFile.Options { Filename = Utils.GetFullPath(filename), ControlFlowDeobfuscation = options.ControlFlowDeobfuscation, KeepObfuscatorTypes = options.KeepObfuscatorTypes, MetaDataFlags = options.MetaDataFlags, RenamerFlags = options.RenamerFlags, }; if (options.DefaultStringDecrypterType != null) fileOptions.StringDecrypterType = options.DefaultStringDecrypterType.Value; fileOptions.StringDecrypterMethods.AddRange(options.DefaultStringDecrypterMethods); if (!string.IsNullOrEmpty(searchDir.OutputDirectory)) { var inDir = Utils.GetFullPath(searchDir.InputDirectory); var outDir = Utils.GetFullPath(searchDir.OutputDirectory); if (!Utils.StartsWith(fileOptions.Filename, inDir, StringComparison.OrdinalIgnoreCase)) throw new UserException(string.Format("Filename {0} does not start with inDir {1}", fileOptions.Filename, inDir)); var subDirs = fileOptions.Filename.Substring(inDir.Length); if (subDirs.Length > 0 && subDirs[0] == Path.DirectorySeparatorChar) subDirs = subDirs.Substring(1); fileOptions.NewFilename = Utils.GetFullPath(Path.Combine(outDir, subDirs)); if (fileOptions.Filename.Equals(fileOptions.NewFilename, StringComparison.OrdinalIgnoreCase)) throw new UserException(string.Format("Input and output filename is the same: {0}", fileOptions.Filename)); } var obfuscatedFile = new ObfuscatedFile(fileOptions, options.ModuleContext, options.AssemblyClientFactory); if (Add(obfuscatedFile, searchDir.SkipUnknownObfuscators, false)) return obfuscatedFile; obfuscatedFile.Dispose(); return null; }
IEnumerable<string> DoDirectoryInfo(SearchDir searchDir, DirectoryInfo di) { if (!di.Exists) return new List<string>(); if (visitedDirectory.ContainsKey(di.FullName)) return new List<string>(); visitedDirectory[di.FullName] = true; FileSystemInfo[] fsinfos; try { fsinfos = di.GetFileSystemInfos(); } catch (UnauthorizedAccessException) { return new List<string>(); } catch (IOException) { return new List<string>(); } return RecursiveAdd(searchDir, fsinfos); }
IEnumerable<string> RecursiveAdd(SearchDir searchDir, IEnumerable<FileSystemInfo> fileSystemInfos) { foreach (var fsi in fileSystemInfos) { if ((int)(fsi.Attributes & System.IO.FileAttributes.Directory) != 0) { foreach (var filename in DoDirectoryInfo(searchDir, (DirectoryInfo)fsi)) yield return filename; } else { var fi = (FileInfo)fsi; if (fi.Exists) yield return fi.FullName; } } }
IEnumerable<IObfuscatedFile> LoadFiles(SearchDir searchDir) { DirectoryInfo di = null; bool ok = false; try { di = new DirectoryInfo(searchDir.InputDirectory); if (di.Exists) ok = true; } catch (System.Security.SecurityException) { } catch (ArgumentException) { } if (ok) { foreach (var filename in DoDirectoryInfo(searchDir, di)) { var obfuscatedFile = CreateObfuscatedFile(searchDir, filename); if (obfuscatedFile != null) yield return obfuscatedFile; } } }
public static string GetBasePhysicalPath(Repository repository) { return(Path.Combine(SearchDir.GetBasePhysicalPath(repository), PATH_NAME)); }
/// <summary> /// Attempts to migrate all sub-directories when the working directory is changed. /// Currently this only occurs in the GUI when a working directory has been changed. /// </summary> public void AttemptSubDirMigration(string newWDirAbs) { try { if (!newWDirAbs.EndsWith(DSStr)) { newWDirAbs += DS; } string tempPath; if (!InputDir.StartsWith(".." + DS)) { tempPath = newWDirAbs + InputDir; if (Directory.Exists(tempPath)) { iDir = tempPath; if (!DefaultSeedFileName.StartsWith(".." + DS)) { tempPath = iDir + DefaultSeedFileName; if (File.Exists(tempPath)) { defaultSeedFileName = tempPath; } } } } if (!OutputDir.StartsWith(".." + DS)) { tempPath = newWDirAbs + OutputDir; if (Directory.Exists(tempPath)) { oDir = tempPath; } } if (!RulesDir.StartsWith(".." + DS)) { tempPath = newWDirAbs + RulesDir; if (Directory.Exists(tempPath)) { rDir = tempPath; if (!CompiledRuleFunctions.StartsWith(".." + DS)) { tempPath = rDir + CustomShapesFile; if (File.Exists(tempPath)) { compiledRuleFunctions = tempPath; } } var relRuleSets = DefaultRuleSets.Split(','); for (var i = 0; i < relRuleSets.GetLength(0); i++) { if (!string.IsNullOrWhiteSpace(relRuleSets[i]) && !relRuleSets[i].StartsWith(".." + DS)) { tempPath = rDir + relRuleSets[i]; if (File.Exists(tempPath)) { defaultRSFileNames[i] = tempPath; } } } } } if (!SearchDir.StartsWith(".." + DS)) { tempPath = newWDirAbs + SearchDir; if (Directory.Exists(tempPath)) { sDir = tempPath; } } if (!GraphLayoutDir.StartsWith(".." + DS)) { tempPath = newWDirAbs + GraphLayoutDir; if (Directory.Exists(tempPath)) { glDir = tempPath; } } if (!CustomShapesFile.StartsWith(".." + DS)) { tempPath = newWDirAbs + CustomShapesFile; if (File.Exists(tempPath)) { customShapesFile = tempPath; } } } catch (Exception exc) { ErrorLogger.Catch(exc); } }
public GccMakefileParser(String MakeFile) { FileInfo fIfoMakeFile = new FileInfo(MakeFile); Root = fIfoMakeFile.Directory; Vars = new SortedList <string, string>(); SourceFiles = new SortedList <string, FileInfo>(); IncludePaths = new SortedList <string, DirectoryInfo>(); LibraryFiles = new SortedList <string, FileInfo>(); Defines = new List <string>(); String[] DataLines = File.ReadAllLines(MakeFile); // // Process all data-lines // foreach (String DataLine in DataLines) { // split makefile lines by spaces => results in words String[] DataItems = DataLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (DataItems.Length > 0) { // // sometimes +=: does not have spaces, so if first word contains +=: which should be in DataItems[1] // replace +=: with " += : " and split again // if (DataItems[0].Contains("+=:")) { String DataLineTmp = DataLine.Replace(DataItems[0], DataItems[0].Replace("+=:", " += :")); DataItems = DataLineTmp.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } // // sometimes += does not have spaces, so if first word contains += which should be in DataItems[1] // replace += with " += " and split again // if (DataItems[0].Contains("+=")) { String DataLineTmp = DataLine.Replace(DataItems[0], DataItems[0].Replace("+=", " += ")); DataItems = DataLineTmp.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } // // sometimes = does not have spaces, so if first word contains = which should be in DataItems[1] // replace = with " = " and split again // else if (DataItems[0].Contains("=")) { String DataLineTmp = DataLine.Replace(DataItems[0], DataItems[0].Replace("=", " = ")); DataItems = DataLineTmp.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); } } if (DataItems.Length > 2) { // // check second word is "=" which starts a new variable // if (DataItems[1].Equals("=")) { if (Vars.ContainsKey(DataItems[0])) { Vars.Remove(DataItems[0]); } String Val = DataLine.Substring(DataLine.IndexOf('=') + 1); Vars.Add(DataItems[0], Val.TrimStart()); } // // check second word is "+=" which appends a variable // else if (DataItems[1].Equals("+=")) { if (!Vars.ContainsKey(DataItems[0])) { Vars.Add(DataItems[0], ""); } String Val = DataLine.Substring(DataLine.IndexOf('=') + 1); Vars[DataItems[0]] += " " + Val.TrimStart(); } } } // // Search for source files in the specified VPATH variable // String[] VPATH = Vars["VPATH"].Replace(":", "").Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); String[] SRC = Vars["SRC"].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (String SourceFile in SRC) { foreach (String SearchDir in VPATH) { String absSearchDir = Path.Combine(Root.FullName, SearchDir.Replace("/", "\\")); absSearchDir = Path.GetFullPath((new Uri(absSearchDir)).LocalPath); String checkFilePath = Path.Combine(absSearchDir, SourceFile); if (File.Exists(checkFilePath)) { SourceFiles.Add(SourceFile, new FileInfo(checkFilePath)); break; } } } // // Process include paths // String[] INCLUDES = Vars["INCLUDES"].Split(new String[] { "-I" }, StringSplitOptions.RemoveEmptyEntries); Vars.Add("INCLUDESSTRING", ""); foreach (String Include in INCLUDES) { String IncludePath = Path.Combine(Root.FullName, Include.TrimStart().Replace("/", "\\")); IncludePath = Path.GetFullPath((new Uri(IncludePath)).LocalPath); IncludePaths.Add(Include.TrimStart(), new DirectoryInfo(IncludePath)); Vars["INCLUDESSTRING"] += Include.Trim() + ";"; } // // Process libraries // if (Vars.ContainsKey("LIBS")) { String[] LIBS = Vars["LIBS"].Split(new String[] { " " }, StringSplitOptions.RemoveEmptyEntries); Vars.Add("LIBSSTRING", ""); foreach (String Lib in LIBS) { String LibPath = Path.Combine(Root.FullName, Lib.TrimStart().Replace("/", "\\")); LibPath = Path.GetFullPath((new Uri(LibPath)).LocalPath); Vars["LIBSSTRING"] += Lib.Trim() + ";"; LibraryFiles.Add(Lib, new FileInfo(LibPath)); } } // // Generate defines string // String[] DEFINES = Vars["DEFINES"].Split(new String[] { "-D" }, StringSplitOptions.RemoveEmptyEntries); Vars.Add("DEFINESSTRING", ""); foreach (String Define in DEFINES) { if (!String.IsNullOrEmpty(Define.Trim())) { Defines.Add(ReplaceVars(Define.Trim())); String DefineVar = ReplaceVars(Define.Trim()); if (DefineVar.Contains("=")) { Vars["DEFINESSTRING"] += DefineVar + ";"; } else { Vars["DEFINESSTRING"] += DefineVar + "=1;"; } } } Vars.Add("CFLAGSSTRING", ReplaceVars(Vars["CFLAGS"])); }
public LastActionPath(Repository repository) { this.PhysicalPath = Path.Combine(SearchDir.GetBasePhysicalPath(repository), "LastActions.xml"); }
/// <summary> /// Error string for when something is not correct with the form. Displayed to user /// </summary> /// <param name="columnName"> Which control is producing the error</param> /// <returns></returns> public string this[string columnName] { get { string result = null; switch (columnName) { case "SearchName": if (string.IsNullOrWhiteSpace(SearchName)) { result = "The search name cannot be empty"; } break; case "SearchTag0": if (string.IsNullOrWhiteSpace(SearchTag0)) { result = "The first tag must have a value"; } if (SearchTag0.Contains(' ')) { result = "Tags Cannot contain spaces"; } break; case "SearchTag1": if (SearchTag1.Contains(' ')) { result = "Tags Cannot contain spaces"; } break; case "SearchTag2": if (SearchTag2.Contains(' ')) { result = "Tags Cannot contain spaces"; } break; case "SearchTag3": if (SearchTag3.Contains(' ')) { result = "Tags Cannot contain spaces"; } break; case "SearchTag4": if (SearchTag4.Contains(' ')) { result = "Tags Cannot contain spaces"; } break; case "SearchDir": if (SearchDir.EndsWith(@"\")) { result = @"Remove the last \"; } if (string.IsNullOrWhiteSpace(SearchDir)) { result = "Must have a value"; } break; default: break; } return(result); } }