From ce2bc766e46fcd99ee9b022e6bc47b0c27a196ef Mon Sep 17 00:00:00 2001 From: nilaoda Date: Thu, 17 Nov 2022 22:32:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81JPEG=E4=BC=AA=E8=A3=85?= =?UTF-8?q?=E7=9A=84TS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE/Util/ImageHeaderUtil.cs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/N_m3u8DL-RE/Util/ImageHeaderUtil.cs b/src/N_m3u8DL-RE/Util/ImageHeaderUtil.cs index c9d1ef7..81b7f7f 100644 --- a/src/N_m3u8DL-RE/Util/ImageHeaderUtil.cs +++ b/src/N_m3u8DL-RE/Util/ImageHeaderUtil.cs @@ -21,6 +21,9 @@ namespace N_m3u8DL_RE.Util //BMP HEADER检测 else if (size > 10 && 0x42 == bArr[0] && 0x4D == bArr[1] && 0x00 == bArr[5] && 0x00 == bArr[6] && 0x00 == bArr[7] && 0x00 == bArr[8]) return true; + //JPEG HEADER检测 + else if (size > 3 && 0xFF == bArr[0] && 0xD8 == bArr[1] && 0xFF == bArr[2]) + return true; return false; } @@ -41,7 +44,7 @@ namespace N_m3u8DL_RE.Util sourceData = sourceData[771..]; else { - //确定是PNG但是需要手动查询结尾标记 0x47 出现两次 + //手动查询结尾标记 0x47 出现两次 int skip = 0; for (int i = 4; i < sourceData.Length - 188 * 2 - 4; i++) { @@ -64,6 +67,21 @@ namespace N_m3u8DL_RE.Util { sourceData = sourceData[0x3E..]; } + //JPEG HEADER检测 + else if (0xFF == sourceData[0] && 0xD8 == sourceData[1] && 0xFF == sourceData[2]) + { + //手动查询结尾标记 0x47 出现两次 + int skip = 0; + for (int i = 4; i < sourceData.Length - 188 * 2 - 4; i++) + { + if (sourceData[i] == 0x47 && sourceData[i + 188] == 0x47 && sourceData[i + 188 + 188] == 0x47) + { + skip = i; + break; + } + } + sourceData = sourceData[skip..]; + } await File.WriteAllBytesAsync(sourcePath, sourceData); }