public CollectionFileType GetMatchingFileTypes() { CollectionFileType AllFT_Matches = new CollectionFileType(); foreach (FileType FT in FilteredFileTypeTargets) { if (FT.Matches(MinimumTargetFileSequence)) { AllFT_Matches.AddFileType(FT); } } return(AllFT_Matches.Count == 0 ? new CollectionFileType(new[] { FileType.Unknown }) : AllFT_Matches); }
public FileTypeTeller() { List <FileTypeSpecifications> JSONFileSpecs = JsonSerializer.Deserialize <List <FileTypeSpecifications> >(Resources.FILESIGNATURES_JSON); foreach (var spec in JSONFileSpecs) { List <MatchByteSegment> OneFileByteSegments = new List <MatchByteSegment>(); foreach (SegmentAndOffset SegByteOff in spec.SegmentBytesAndOffset) { OneFileByteSegments.Add(new MatchByteSegment( Array.ConvertAll(SegByteOff.SegmentStringByte.Trim().Split(' '), byteAsString => Convert.ToByte(byteAsString, 16)), SegByteOff.Offset) ); } KnownFileSignatures.AddFileType(new FileType(string.Join(",", spec.FileTypeDescriptions), string.Join(",", spec.Extensions), new FuzzyFileTypeMatcher(OneFileByteSegments))); } //KnownFileSignatures.SortListBySegmentBytesLengthDescendently(); }
public CollectionFileType GetFileExtension(byte[] rawContent) { CollectionFileType FileTypeTargets = new CollectionFileType(); int MaximumLengthForMatch = 0; foreach (FileType CurrFileType in KnownFileSignatures) { int CurrFileSignatureLength = CurrFileType.GetMaxSignatureLength(); int MinResult = Math.Min(CurrFileSignatureLength, rawContent.Length); if (MinResult == CurrFileSignatureLength) { FileTypeTargets.AddFileType(CurrFileType); MaximumLengthForMatch = Math.Max(MaximumLengthForMatch, CurrFileSignatureLength); } } MSTF = new MinimumStreamTargetFile(rawContent, MaximumLengthForMatch, FileTypeTargets); return(MSTF.GetMatchingFileTypes()); }