BitmapDetector.cs 993 B

12345678910111213141516171819202122232425
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Reflection;
  4. using Masuit.Tools.Mime;
  5. namespace Masuit.Tools.Files.FileDetector.Detectors;
  6. [FormatCategory(FormatCategory.Image)]
  7. internal class BitmapDetector : AbstractSignatureDetector
  8. {
  9. private static readonly SignatureInformation[] BmpSignatureInfo = {
  10. new() { Position = 0, Signature = new byte [] { 0x42, 0x4D } },
  11. new() { Position = 6, Signature = new byte [] { 0x00, 0x00, 0x00, 0x00 }, Presignature = new byte [] { 0x42, 0x4D } },
  12. };
  13. public override string Extension => "bmp";
  14. protected override SignatureInformation[] SignatureInformations => BmpSignatureInfo;
  15. public override string MimeType => new MimeMapper().GetMimeFromExtension("." + Extension);
  16. public override List<FormatCategory> FormatCategories => GetType().GetCustomAttributes<FormatCategoryAttribute>().Select(a => a.Category).ToList();
  17. public override string ToString() => "Bitmap(BMP) Detector";
  18. }