public async Task <IEnumerable <IntegrityReport> > GetIntegrityReports() { var hashes = new HashSet <string>(); var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies() .Select(a => { if (hashes.Contains(a.FullName)) { return(null); } hashes.Add(a.FullName); return(new IntegrityReport(a)); }) .Where(a => a != null) .Where(r => r.IsAuthJanitorExtensionLibrary || r.IsAuthJanitorNamedLibrary) .ToList(); await Task.WhenAll(loadedAssemblies.Select(async asm => { if (string.IsNullOrEmpty(asm.LibraryFile)) { return; } asm.LibraryFileHash = BitConverter.ToString(await _cryptographicImplementation.HashFile(asm.LibraryFile)); var inspector = new FileInspector(asm.LibraryFile); var signatureCheckResult = inspector.Validate(); asm.SignatureCheckResult = Enum.Parse <IntegrityReport.IntegritySignatureCheckResult>(signatureCheckResult.ToString()); if (signatureCheckResult != SignatureCheckResult.NoSignature && signatureCheckResult != SignatureCheckResult.BadDigest) { asm.Signatures = inspector.GetSignatures().Select(s => { return(new IntegrityReportSignature() { Thumbprint = s.SigningCertificate.Thumbprint, Subject = s.SigningCertificate.Subject, FriendlyName = s.SigningCertificate.FriendlyName, Issuer = s.SigningCertificate.Issuer, IssuerName = s.SigningCertificate.IssuerName?.Name, NotAfter = s.SigningCertificate.NotAfter, NotBefore = s.SigningCertificate.NotBefore, SerialNumber = s.SigningCertificate.SerialNumber, SubjectName = s.SigningCertificate.SubjectName?.Name, Version = s.SigningCertificate.Version.ToString(), PublisherDescription = s.PublisherInformation?.Description, PublisherUrl = s.PublisherInformation?.UrlLink }); }).ToList(); } })); return(loadedAssemblies); }
private void SetupDisablerButtonText() { if (SelectedTarget != null) { var d3d9Path = Path.Combine(MEDirectories.ExecutableDirectory(SelectedTarget), @"d3d9.dll"); if (File.Exists(d3d9Path)) { // See if it ME3Tweaks disabler or some other tool var fi = new FileInspector(d3d9Path); foreach (var sig in fi.GetSignatures()) { foreach (var signChain in sig.AdditionalCertificates) { try { var outStr = signChain.Subject.Substring(3); //remove CN= outStr = outStr.Substring(0, outStr.IndexOf(',')); if (outStr == @"Michael Perez") //My signing cert name { D3D9Status = M3L.GetString(M3L.string_overlayDisablerInstalled); DisablerButtonText = M3L.GetString(M3L.string_uninstallDisabler); DisablerButtonEnabled = true; return; } } catch { } } } D3D9Status = M3L.GetString(M3L.string_otherD3d9dllInstalledOverlayDisabled); DisablerButtonText = M3L.GetString(M3L.string_cannotUninstallOtherD3d9File); DisablerButtonEnabled = false; return; } DisablerButtonEnabled = true; D3D9Status = M3L.GetString(M3L.string_overlayDisablerNotInstalled); DisablerButtonText = M3L.GetString(M3L.string_installDisabler); } else { DisablerButtonEnabled = false; DisablerButtonText = M3L.GetString(M3L.string_installDisabler); if (Targets.Any()) { D3D9Status = M3L.GetString(M3L.string_noTargetSelected); } else { D3D9Status = M3L.GetString(M3L.string_noOriginBasedGameTargets); } } }
public List <Dictionary <string, string> > Run(List <string> arguments, List <Dictionary <string, string> > list) { Directory.CreateDirectory(destinationFolder); foreach (var file in arguments) { if (!File.Exists(file)) { list.Add(new Dictionary <string, string>() { { "token", "File" }, { "err", file + " does not exist" }, }); continue; } var encoding = new ASCIIEncoding(); var destFileName = FileInspector.GetHash(file) + " - " + Convert.ToBase64String(encoding.GetBytes(file)); var destFilePath = destinationFolder + @"\" + destFileName; if (File.Exists(destFilePath)) { File.Delete(file); list.Add(new Dictionary <string, string>() { { "token", "File" }, { "success", "Moved (by deletion) " + file }, }); continue; } try { File.Move(file, destFilePath); } catch { list.Add(new Dictionary <string, string>() { { "token", "File" }, { "err", "Failed to move " + file }, }); continue; } list.Add(new Dictionary <string, string>() { { "token", "File" }, { "success", "Successfully moved " + file }, }); } return(list); }
internal string ImportProject(string importFrom) { using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Title = TextHelper.GetString("Title.ImportProject"); dialog.Filter = TextHelper.GetString("Info.ImportProjectFilter"); if (importFrom == "hxml") { dialog.FilterIndex = 3; } if (dialog.ShowDialog() == DialogResult.OK && File.Exists(dialog.FileName)) { string fileName = dialog.FileName; string currentDirectory = Directory.GetCurrentDirectory(); try { if (FileInspector.IsHxml(Path.GetExtension(fileName).ToLower())) { var project = HaxeProject.Load(fileName); var path = Path.GetDirectoryName(project.ProjectPath); var name = Path.GetFileNameWithoutExtension(project.OutputPath); var newPath = Path.Combine(path, $"{name}.hxproj"); PatchProject(project); PatchHxmlProject(project); project.SaveAs(newPath); return(newPath); } if (FileInspector.IsFlexBuilderPackagedProject(fileName)) { fileName = ExtractPackagedProject(fileName); } if (FileInspector.IsFlexBuilderProject(fileName)) { AS3Project imported = AS3Project.Load(fileName); string path = Path.GetDirectoryName(imported.ProjectPath); string name = Path.GetFileNameWithoutExtension(imported.OutputPath); string newPath = Path.Combine(path, name + ".as3proj"); PatchProject(imported); PatchFbProject(imported); imported.SaveAs(newPath); return(newPath); } ErrorManager.ShowInfo(TextHelper.GetString("Info.NotValidFlashBuilderProject")); } catch (Exception exception) { Directory.SetCurrentDirectory(currentDirectory); string msg = TextHelper.GetString("Info.CouldNotOpenProject"); ErrorManager.ShowInfo(msg + " " + exception.Message); } } } return(null); }
public override LibraryAsset GetAsset(string path) { if (!FileInspector.IsSwc(path)) { return(base.GetAsset(path)); } else { return(SwcLibraries[GetRelativePath(path)]); } }
public override bool IsLibraryAsset(string path) { if (!FileInspector.IsSwc(path)) { return(base.IsLibraryAsset(path)); } else { return(SwcLibraries.Contains(path) || SwcLibraries.Contains(GetRelativePath(path))); } }
public SwfFileNode(string filePath) : base(filePath) { string ext = Path.GetExtension(filePath).ToLower(); explorable = FileInspector.IsSwf(filePath, ext) || ext == ".swc" || ext == ".ane"; if (explorable) { isRefreshable = true; Nodes.Add(new WorkingNode(filePath)); } }
static async Task Run(ILogger logger, FileInspector fileInspector) { while (true) { // input bool isDir, isFile, found; string path; do { logger.LogInformation("input file/folder path or [Enter] to exit"); path = Console.ReadLine(); // exit if (string.IsNullOrEmpty(path)) { goto exit; } // check isDir = Directory.Exists(path); isFile = File.Exists(path); found = isDir || isFile; if (!found) { logger.LogWarning("not found path '{path}'", path); } } while (!found); // collect files var paths = new[] { path }; if (isDir) { paths = Directory.GetFiles(path, "*.cs", SearchOption.AllDirectories); if (paths.Length > 0) { logger.LogInformation("found {count} cs file(s) in '{path}'", paths.Length, path); } else { logger.LogWarning("found no cs file in '{path}'", path); continue; } } // inspect files foreach (var filePath in paths) { await fileInspector.Inspect(filePath); } } exit: logger.LogInformation("exiting..."); }
public RuleResult Validate(string file, SignatureLogger verboseWriter, CheckConfiguration configuration) { var inspector = new FileInspector(file); var result = inspector.Validate(configuration.RevocationMode); if (result == SignatureCheckResult.Valid) { return(RuleResult.Pass); } verboseWriter.LogMessage($"Authenticode signature validation failed with '{result}'."); return(RuleResult.Fail); }
public static void AddMxmlMapping(FileMappingRequest request) { foreach (string file in request.Files) { if (FileInspector.IsMxml(file, Path.GetExtension(file).ToLower())) { foreach (string includedFile in GetIncludedFiles(file)) { request.Mapping.Map(includedFile, file); } } } }
private void init(string fileName) { Package = ""; Module = ""; FileName = fileName ?? ""; haXe = (FileName.Length > 3) ? FileInspector.IsHaxeFile(FileName, Path.GetExtension(FileName)) : false; // Namespaces = new Dictionary <string, Visibility>(); // Imports = new MemberList(); Classes = new List <ClassModel>(); Members = new MemberList(); Regions = new MemberList(); }
public void Execute(List <FileDetails> fileDetails) { foreach (var fileDetail in fileDetails) { var extractor = new FileInspector(fileDetail.Filename); fileDetail.IsSigned = extractor.Validate() == SignatureCheckResult.Valid; if (fileDetail.IsSigned) { fileDetail.SignatureVersion = extractor.GetSignatures().FirstOrDefault()?.SigningCertificate.Version.ToString(); fileDetail.SignatureDate = extractor.GetSignatures().FirstOrDefault()?.TimestampSignatures.FirstOrDefault()?.TimestampDateTime?.UtcDateTime.ToString(); } } }
public override void ChangeAssetPath(string fromPath, string toPath) { if (!FileInspector.IsSwc(fromPath)) { base.ChangeAssetPath(fromPath, toPath); } else { LibraryAsset asset = SwcLibraries[GetRelativePath(fromPath)]; SwcLibraries.Remove(asset); asset.Path = GetRelativePath(toPath); SwcLibraries.Add(asset); } }
public void ThrowsExceptionIfMissingFileName() { //Arrange var fileInspector = new FileInspector(mockFileDetails.Object); var options = new Options() { ShowSize = true }; //Act Action act = () => fileInspector.InspectFile(options); //Assert act.Should().Throw <ArgumentException>().WithMessage("FileName"); }
public override LibraryAsset GetAsset(string path) { if (!FileInspector.IsSwc(path) && !base.IsDirectory(path)) { return(base.GetAsset(path)); } else if (SwcLibraries.Contains(path)) { return(SwcLibraries[path]); } else { return(SwcLibraries[GetRelativePath(path)]); } }
public void Run(ref Report report, List <Dictionary <string, string> > list) { foreach (var directory in directories) { if (!Directory.Exists(directory)) { continue; } foreach (var file in SafeFileEnumerator.EnumerateFiles(directory, "*.exe", SearchOption.AllDirectories)) { if (file.Length > 248) { continue; } var fileDate = FileInspector.GetDate(file); if ((fileDate - DateTime.Now).TotalDays > 14) { continue; } try { list.Add(new Dictionary <string, string> { { "token", "File" }, { "hash", "[" + FileInspector.GetHash(file) }, { "date", fileDate.ToString("MM-dd-yyyy") + "]" }, { "publisher", "(" + FileInspector.GetPublisher(file) + ")" }, { "path", file } }); } catch (IOException) { list.Add(new Dictionary <string, string> { { "token", "File" }, { "date", "[" + fileDate.ToString("MM-dd-yyyy") + "]" }, { "path", file } }); } } } report.Add(list); }
public override CompileTargetType AllowCompileTarget(string path, bool isDirectory) { if (isDirectory || !FileInspector.IsHaxeFile(path, Path.GetExtension(path))) { return(CompileTargetType.None); } foreach (string cp in AbsoluteClasspaths) { if (path.StartsWith(cp, StringComparison.OrdinalIgnoreCase)) { return(CompileTargetType.AlwaysCompile | CompileTargetType.DocumentClass); } } return(CompileTargetType.None); }
public void ReturnsNothingIfNoAction() { //Arrange var fileInspector = new FileInspector(mockFileDetails.Object); var options = new Options() { FileName = "file1.txt" }; //Act var result = fileInspector.InspectFile(options); //Assert result.Version.Should().BeNull(); result.Size.Should().BeNull(); }
public void OpenFile(string path) { if (FileInspector.ShouldUseShellExecute(path)) { ShellOpenFile(path); } else if (path.IndexOf("::") > 0) { DataEvent de = new DataEvent(EventType.Command, ProjectManagerEvents.OpenVirtualFile, path); EventManager.DispatchEvent(this, de); } else { MainForm.OpenEditableDocument(path); } }
public List <Dictionary <string, string> > Run(List <string> arguments, List <Dictionary <string, string> > list) { Directory.CreateDirectory(destinationFolder); foreach (var file in arguments) { if (!File.Exists(file) && !Directory.Exists(file)) { list.Add(new Dictionary <string, string> { { "token", "File" }, { "err", file + " does not exist" } }); continue; } var encoding = new ASCIIEncoding(); string destFileName; if (!Directory.Exists(file)) { destFileName = FileInspector.GetHash(file) + " - " + Convert.ToBase64String(encoding.GetBytes(file)); } else { destFileName = "Directory - " + Convert.ToBase64String(encoding.GetBytes(file)); } var destFilePath = destinationFolder + @"\" + destFileName; if (File.Exists(destFilePath)) { File.Delete(file); list.Add(new Dictionary <string, string> { { "token", "File" }, { "success", "Moved (by deletion) " + file } }); continue; } MoveFile(ref list, file, destFilePath); } return(list); }
public string ImportProject() { OpenFileDialog dialog = new OpenFileDialog(); dialog.Title = TextHelper.GetString("Title.ImportProject"); dialog.Filter = TextHelper.GetString("Info.ImportProjectFilter"); if (dialog.ShowDialog() == DialogResult.OK && File.Exists(dialog.FileName)) { string fbProject = dialog.FileName; string currentDirectory = Directory.GetCurrentDirectory(); try { if (FileInspector.IsFlexBuilderPackagedProject(fbProject)) { fbProject = ExtractPackagedProject(fbProject); } if (FileInspector.IsFlexBuilderProject(fbProject)) { AS3Project imported = AS3Project.Load(fbProject); string path = Path.GetDirectoryName(imported.ProjectPath); string name = Path.GetFileNameWithoutExtension(imported.OutputPath); string newPath = Path.Combine(path, name + ".as3proj"); PatchProject(imported); PatchFbProject(imported); imported.SaveAs(newPath); return(newPath); } else { ErrorManager.ShowInfo(TextHelper.GetString("Info.NotValidFlashBuilderProject")); } } catch (Exception exception) { Directory.SetCurrentDirectory(currentDirectory); string msg = TextHelper.GetString("Info.CouldNotOpenProject"); ErrorManager.ShowInfo(msg + " " + exception.Message); } } return(null); }
public void GetsVersion() { //Arrange mockFileDetails.Setup(x => x.Version(It.IsAny <string>())).Returns("1.2.3"); var fileInspector = new FileInspector(mockFileDetails.Object); var options = new Options() { ShowVersion = true, FileName = "file1.txt" }; //Act var result = fileInspector.InspectFile(options); //Assert mockFileDetails.Verify(x => x.Version("file1.txt"), Times.Once); result.Version.Should().Be("1.2.3"); result.Size.Should().BeNull(); }
public void Run(ref Report report, List <Dictionary <string, string> > list) { var processes = Process.GetProcesses(); var sortedProcesses = processes.OrderBy(process => process.Id).ToList(); foreach (var process in sortedProcesses) { if (process.Id == 0) { continue; } string path; string publisher = ""; bool error = false; try { path = process.MainModule.FileName; publisher = FileInspector.GetPublisher(path); } catch (Win32Exception) { continue; } catch (InvalidOperationException) { path = ""; error = true; } list.Add(new Dictionary <string, string> { { "token", "Proc" }, { "publisher", !error ? "(" + publisher + ")" : "" }, { "path", !error ? path : "(could not get path)" }, { "pid", "[" + process.Id + "]" }, }); } report.Add(list); }
public void AddLibraryAsset(Project project, string inDirectory) { using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Title = TextHelper.GetString("Label.AddLibraryAsset"); dialog.Filter = TextHelper.GetString("Info.FileFilter"); dialog.Multiselect = false; if (dialog.ShowDialog() == DialogResult.OK) { string filePath = CopyFile(dialog.FileName, inDirectory); // null means the user cancelled if (filePath == null) { return; } // add as an asset project.SetLibraryAsset(filePath, true); if (!FileInspector.IsSwc(filePath)) { // ask if you want to keep this file updated string caption = TextHelper.GetString("FlashDevelop.Title.ConfirmDialog"); string message = TextHelper.GetString("Info.ConfirmFileUpdate"); DialogResult result = MessageBox.Show(mainForm, message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { LibraryAsset asset = project.GetAsset(filePath); asset.UpdatePath = project.GetRelativePath(dialog.FileName); } } project.Save(); OnProjectModified(new string[] { filePath }); } } }
public override string GetInsertFileText(string inFile, string path, string export, string nodeType) { if (nodeType == "ProjectManager.Controls.TreeView.ClassExportNode") { return(export); } string pre = ""; string post = ""; string ext = Path.GetExtension(inFile).ToLower(); if (ext == ".as") { pre = "["; post = "]"; } string relPath = ProjectPaths.GetRelativePath(Path.GetDirectoryName(inFile), path).Replace('\\', '/'); string fileExt = Path.GetExtension(path).ToLower(); if (export != null) { if (export.IndexOf('(') > 0) { string fontName = export.Substring(0, export.IndexOf('(')).Trim(); return(String.Format("{0}Embed(source=\"{1}\", fontFamily=\"{2}\"){3}", pre, relPath, fontName, post)); } else { return(String.Format("{0}Embed(source=\"{1}\", symbol=\"{2}\"){3}", pre, relPath, export, post)); } } else if (FileInspector.IsImage(relPath, fileExt) || IsText(fileExt) || FileInspector.IsFont(relPath, fileExt) || FileInspector.IsSound(relPath, fileExt)) { return(String.Format("{0}Embed(source=\"{1}\"){2}", pre, relPath, post)); } else { return(String.Format("{0}Embed(source=\"{1}\", mimeType=\"application/octet-stream\"){2}", pre, relPath, post)); } }
private bool IsBuildable(String path) { String ext = Path.GetExtension(path).ToLower(); if (FileInspector.IsAS2Project(path, ext)) { return(true); } else if (FileInspector.IsAS3Project(path, ext)) { return(true); } else if (FileInspector.IsHaxeProject(path, ext)) { return(true); } else { return(false); } }
public override string GetInsertFileText(string inFile, string path, string export, string nodeType) { bool isInjectionTarget = (UsesInjection && path == GetAbsolutePath(InputPath)); if (export != null) { return(export); } if (IsLibraryAsset(path) && !isInjectionTarget) { return(GetAsset(path).ID); } else if (!NoOutput && FileInspector.IsActionScript(inFile, Path.GetExtension(inFile).ToLower())) { return(ProjectPaths.GetRelativePath(Path.GetDirectoryName(ProjectPath), path).Replace('\\', '/')); } else { return(ProjectPaths.GetRelativePath(Path.GetDirectoryName(inFile), path).Replace('\\', '/')); } }
private static bool IsMicrosoftFile(PackageFile file) { IReadOnlyList <AuthenticodeSignature> sigs; SignatureCheckResult isValidSig; using (var str = file.GetStream()) using (var tempFile = new TemporaryFile(str, Path.GetExtension(file.Name))) { var extractor = new FileInspector(tempFile.FileName); sigs = extractor.GetSignatures().ToList(); isValidSig = extractor.Validate(); if (isValidSig == SignatureCheckResult.Valid && sigs.Count > 0) { return(sigs[0].SigningCertificate.Subject.EndsWith(", O=Microsoft Corporation, L=Redmond, S=Washington, C=US", StringComparison.OrdinalIgnoreCase)); } } return(false); }
static int Main(string[] args) { Console.Write("Type a program path: "); var path = Console.ReadLine(); if (!File.Exists(path)) { Console.WriteLine("File doesn't exist."); return(1); } var extractor = new FileInspector(path); var validationResult = extractor.Validate(); switch (validationResult) { case SignatureCheckResult.Valid: Console.WriteLine("The file is valid."); break; case SignatureCheckResult.NoSignature: Console.WriteLine("The file is not signed."); return(1); case SignatureCheckResult.BadDigest: Console.WriteLine("The file's signature is not valid."); return(1); default: Console.WriteLine($"The file is not valid: {validationResult}"); return(1); } var signatures = extractor.GetSignatures(); foreach (var signature in signatures) { DumpSignatureDetails(signature); } return(0); }
public override string GetInsertFileText(string inFile, string path, string export, string nodeType) { bool isInjectionTarget = (UsesInjection && path == GetAbsolutePath(InputPath)); if (export != null) { return(export); } if (IsLibraryAsset(path) && !isInjectionTarget) { return(GetAsset(path).ID); } String dirName = inFile; if (FileInspector.IsHaxeFile(inFile, Path.GetExtension(inFile).ToLower())) { dirName = ProjectPath; } return('"' + ProjectPaths.GetRelativePath(Path.GetDirectoryName(dirName), path).Replace('\\', '/') + '"'); }