private void AddDuplicateToResultFolder(StorageFile file) { if (FileTypeChecker.IsImage(file.FileType)) { _images.Add(file); } else if (FileTypeChecker.IsVideo(file.FileType)) { _video.Add(file); } else if (FileTypeChecker.IsDocument(file.FileType)) { _documents.Add(file); } else if (FileTypeChecker.IsAudio(file.FileType)) { _audio.Add(file); } else if (FileTypeChecker.IsArchive(file.FileType)) { _archieves.Add(file); } else { _other.Add(file); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { switch (value) { case IFilesystemEntry filesystemEntry: if (filesystemEntry.IsDirectory) { return(IconManager.FindIconForFolder(parameter as string == "large", false)); } var isDDS = FileTypeChecker.IsExtensionDDS(filesystemEntry); if (isDDS) { return(IconManager.FindIconForFilename("file.dds", parameter as string == "large")); } //todo known types //menuItem.File.Filename // fallback return(IconManager.FindIconForFilename(filesystemEntry.Name, parameter as string == "large")); default: return(IconManager.FindIconForFilename("empty_file", parameter as string == "large")); // return empty file } }
public void SetUp() { bitmap = new MemoryStream(); // LAND.bmp is from http://www.fileformat.info/format/bmp/sample/ Resources.LAND.Save(bitmap, ImageFormat.Bmp); // http://boingboing.net/2015/03/23/free-pdf-advanced-quantum-the.html pdf = new MemoryStream(Resources.advancedquantumthermodynamics); checker = new FileTypeChecker(); }
public IAlgorithmDecided GetAlgorithm(Stream content) { SeekBegin(content); if (!FileTypeChecker.IsFileBinary(content)) { return(IocContainer.Container.ResolveKeyed <IAlgorithmDecided>("textAlgorithm")); } return(IocContainer.Container.ResolveKeyed <IAlgorithmDecided>("binaryAlgorithm")); }
public virtual JObject GetFormsInFolder(HttpContext context) { YZRequest request = new YZRequest(context); string path = request.GetString("path", null); string rsid = String.IsNullOrEmpty(path) ? WellKnownRSID.FormRoot : StoreZoneType.Form.ToString() + "://" + path; BPMPermision perm = request.GetEnum <BPMPermision>("perm"); BPMFileInfoCollection fileInfos = new BPMFileInfoCollection(); JObject rv = new JObject(); rv["dataVersion"] = new JObject(); rv["dataVersion"]["lastUpdateTime"] = DateTime.Now; //获得数据 using (BPMConnection cn = new BPMConnection()) { cn.WebOpen(); if (SecurityManager.CheckPermision(cn, rsid, perm)) { fileInfos = cn.GetFileInfoList(StoreZoneType.Form, path); } } //将数据转化为Json集合 rv[YZJsonProperty.total] = fileInfos.Count; JArray children = new JArray(); rv[YZJsonProperty.children] = children; foreach (BPMFileInfo fileInfo in fileInfos) { if (!FileTypeChecker.IsFormFile(fileInfo.FileName)) { continue; } string fullName = String.IsNullOrEmpty(path) ? fileInfo.FileName : path + "/" + fileInfo.FileName; JObject item = new JObject(); children.Add(item); item["FileName"] = fileInfo.FileName; item["FullName"] = fullName; item["Length"] = fileInfo.Length; item["CreationTime"] = fileInfo.CreationTime; item["LastWriteTime"] = fileInfo.LastWriteTime; } return(rv); }
public MainWindowViewModel() { OpenFileCommand = new SimpleCommand(OpenFileCommandExecute); OpenFolderCommand = new SimpleCommand(OpenFolderCommandExecute); FastScanCommand = new SimpleCommand(FastScanCommandExecute, FastScanCommandCanExecute); DeepScanCommand = new SimpleCommand(DeepScanCommandExecute, FastScanCommandCanExecute); Models = new ObservableCollection <SampleViewModel>(); ConfigGateway configGateway = new ConfigGateway(); _fileTypeChecker = new FileTypeChecker(); _scanner = new MalwareScanner(configGateway.YaraPath, configGateway.IndexRule, configGateway.CustomRule, configGateway.DbPath, configGateway.QuarantinePath, configGateway.ApiKey, configGateway.StringsPath); }
public void ItDoesntDetectBMPs() { checker = new FileTypeChecker(new List <FileType> { new FileType("Portable Network Graphic", ".png", new ExactFileTypeMatcher(new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A })), new FileType("JPEG", ".jpg", new FuzzyFileTypeMatcher(new byte?[] { 0xFF, 0xD, 0xFF, 0xE0, null, null, 0x4A, 0x46, 0x49, 0x46, 0x00 })), new FileType("Graphics Interchange Format 87a", ".gif", new ExactFileTypeMatcher(new byte[] { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61 })), new FileType("Graphics Interchange Format 89a", ".gif", new ExactFileTypeMatcher(new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 })), new FileType("Portable Document Format", ".pdf", new RangeFileTypeMatcher(new ExactFileTypeMatcher(new byte[] { 0x25, 0x50, 0x44, 0x46 }), 1019)) // ... Potentially more in future }); var fileTypes = checker.GetFileTypes(bitmap); Assert.AreEqual(0, fileTypes.Count()); }
public void ItDoesntDetectPDFs() { var pdf = LoadFile("Resources/pdf.pdf"); checker = new FileTypeChecker(new List <FileType> { new FileType("Bitmap", ".bmp", new ExactFileTypeMatcher(new byte[] { 0x42, 0x4d })), new FileType("Portable Network Graphic", ".png", new ExactFileTypeMatcher(new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A })), new FileType("JPEG", ".jpg", new FuzzyFileTypeMatcher(new byte?[] { 0xFF, 0xD, 0xFF, 0xE0, null, null, 0x4A, 0x46, 0x49, 0x46, 0x00 })), new FileType("Graphics Interchange Format 87a", ".gif", new ExactFileTypeMatcher(new byte[] { 0x47, 0x49, 0x46, 0x38, 0x37, 0x61 })), new FileType("Graphics Interchange Format 89a", ".gif", new ExactFileTypeMatcher(new byte[] { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 })) // ... Potentially more in future }); var fileTypes = checker.GetFileTypes(pdf); Assert.AreEqual(0, fileTypes.Count()); }
public void SetUp() { checker = new FileTypeChecker(); }
public async Task <IActionResult> Create(SourceCreateViewModel model, string authors, IFormFile coverFile, IFormFile sourceFile) { if (model.Name != null && sourceFile != null) { Source source = new Source { SourceTypeId = model.SourceTypeId, SourceStateId = model.SourceStateId, CategoryId = model.CategoryId, Name = model.Name, SourceDescription = model.SourceDescription, AdditionalInformation = model.AdditionalInformation, ISBN = model.ISBN, Edition = model.Edition, PhysicalPath = model.PhysicalPath, YearOfWriting = model.YearOfWriting, Keys = model.Keys }; if (coverFile != null) { if (FileTypeChecker.IsValidImage(coverFile)) { source.CoverPath = Load(model.Name, coverFile); } else { return(Json("falseCoverType")); } } else { source.CoverPath = "Files/Cover_missing.png"; } if (FileTypeChecker.IsValidDocument(sourceFile) || FileTypeChecker.IsValidImage(sourceFile) || FileTypeChecker.IsValidVideo(sourceFile) || FileTypeChecker.IsValidAudio(sourceFile)) { source.VirtualPath = Load(model.Name, sourceFile); } else { return(Json("falseBookType")); } await _db.Sources.AddAsync(source); await _db.SaveChangesAsync(); if (authors != null) { SaveSourceAuthors(authors, source); } if (model.BusinessProcesses != null) { SaveBusinessProcessesSource(model, source); } if (model.SourceId != 0) { SaveBookIdAndEnglishBookId(model, source); } return(Json(true)); } return(Json("falseData")); }