Browse Source

修正dll和dmg文件检测的bug

懒得勤快 1 year ago
parent
commit
49d7d78005

+ 1 - 1
Directory.Build.props

@@ -1,6 +1,6 @@
 <Project>
  <PropertyGroup>
-   <Version>2024.5.4</Version>
+   <Version>2024.5.5</Version>
    <Deterministic>true</Deterministic>
  </PropertyGroup>
 </Project>

+ 6 - 1
Masuit.Tools.Abstractions/Files/FileDetector/Detectors/DLLDetector.cs

@@ -23,7 +23,12 @@ internal sealed class DLLDetector : IDetector
     {
         stream.Position = 60;
         using var reader = new BinaryReader(stream, Encoding.UTF8, true);
-        stream.Position = reader.ReadInt32() + 4 + 18;
+        var num = reader.ReadInt32();
+        if (num<0)
+        {
+            return false;
+        }
+        stream.Position = num + 4 + 18;
         short characteristics = reader.ReadInt16();
         return (characteristics & 0x2000) != 0;
     }

+ 2 - 5
Masuit.Tools.Abstractions/Files/FileDetector/Detectors/DMGDetector.cs

@@ -1,7 +1,4 @@
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Reflection;
+using System.Reflection;
 using Masuit.Tools.Mime;
 
 namespace Masuit.Tools.Files.FileDetector.Detectors;
@@ -10,7 +7,7 @@ namespace Masuit.Tools.Files.FileDetector.Detectors;
 internal sealed class DMGDetector : AbstractSignatureDetector
 {
     private static readonly SignatureInformation[] DmgSignatureInfo = {
-        new() { Position = 0, Signature = new byte [] { 0x78, 0x01, 0x73, 0x0D, 0x62, 0x62, 0x60 } },
+        new() { Position = 510, Signature = new byte [] { 0x55, 0xAA, 0x45, 0x46, 0x49, 0x20, 0x50,0x41,0x52,0x54 } },
     };
 
     public override string Extension => "dmg";

+ 1 - 4
Masuit.Tools.Abstractions/Files/FileDetector/Detectors/ZipDetector.cs

@@ -1,7 +1,4 @@
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Reflection;
+using System.Reflection;
 using Masuit.Tools.Mime;
 
 namespace Masuit.Tools.Files.FileDetector.Detectors;