JpegDetector.cs 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Reflection;
  5. using Masuit.Tools.Mime;
  6. namespace Masuit.Tools.Files.FileDetector.Detectors;
  7. [FormatCategory(FormatCategory.Image)]
  8. internal class JpegDetector : AbstractSignatureDetector
  9. {
  10. private static readonly SignatureInformation[] JpegSignatureInfo = {
  11. new() { Position = 0, Signature = new byte [] { 0xFF, 0xD8, 0xFF, 0xFE, 0x00 } },
  12. new () { Position = 0, Signature = new byte [] { 0xFF, 0xD8, 0xFF, 0xDB } },
  13. new () { Position = 0, Signature = new byte [] { 0xFF, 0xD8, 0xFF, 0xE0 } },
  14. new () { Position = 0, Signature = new byte [] { 0xFF, 0xD8, 0xFF, 0xE1 } },
  15. new () { Position = 0, Signature = new byte [] { 0xFF, 0xD8, 0xFF, 0xE2 } },
  16. new () { Position = 0, Signature = new byte [] { 0xFF, 0xD8, 0xFF, 0xE3 } },
  17. new () { Position = 0, Signature = new byte [] { 0xFF, 0xD8, 0xFF, 0xE8 } },
  18. };
  19. public override string Extension => "jpg";
  20. protected override SignatureInformation[] SignatureInformations => JpegSignatureInfo;
  21. public override string MimeType => new MimeMapper().GetMimeFromExtension("." + Extension);
  22. public override List<FormatCategory> FormatCategories => GetType().GetCustomAttributes<FormatCategoryAttribute>().Select(a => a.Category).ToList();
  23. public override string ToString() => "JPEG Detector";
  24. }