From 75a4371f36bfaee8d88ee8faa0fc1debbd140f1c Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sat, 31 Dec 2022 11:21:29 -0800 Subject: [PATCH] Handle MS-CAB compression type masking better --- BurnOutSharp.Builders/MicrosoftCabinet.cs | 2 +- BurnOutSharp.Wrappers/MicrosoftCabinet.cs | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/BurnOutSharp.Builders/MicrosoftCabinet.cs b/BurnOutSharp.Builders/MicrosoftCabinet.cs index 2d340005..9739db1b 100644 --- a/BurnOutSharp.Builders/MicrosoftCabinet.cs +++ b/BurnOutSharp.Builders/MicrosoftCabinet.cs @@ -183,7 +183,7 @@ namespace BurnOutSharp.Builders folder.CabStartOffset = data.ReadUInt32(); folder.DataCount = data.ReadUInt16(); - folder.CompressionType = (CompressionType)(data.ReadUInt16() & (ushort)CompressionType.MASK_TYPE); + folder.CompressionType = (CompressionType)data.ReadUInt16(); if (header.FolderReservedSize > 0) folder.ReservedData = data.ReadBytes(header.FolderReservedSize); diff --git a/BurnOutSharp.Wrappers/MicrosoftCabinet.cs b/BurnOutSharp.Wrappers/MicrosoftCabinet.cs index afde3e27..65786dd5 100644 --- a/BurnOutSharp.Wrappers/MicrosoftCabinet.cs +++ b/BurnOutSharp.Wrappers/MicrosoftCabinet.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; namespace BurnOutSharp.Wrappers { @@ -190,7 +189,7 @@ namespace BurnOutSharp.Wrappers else // if (x >= 4) return a[n - x + b] ^ S(a, b, x - 4); } - + #endregion #region Folders @@ -224,7 +223,7 @@ namespace BurnOutSharp.Wrappers foreach (var dataBlock in folder.DataBlocks) { byte[] decompressed = null; - switch (folder.CompressionType) + switch (folder.CompressionType & Models.MicrosoftCabinet.CompressionType.MASK_TYPE) { case Models.MicrosoftCabinet.CompressionType.TYPE_NONE: decompressed = dataBlock.CompressedData; @@ -469,7 +468,7 @@ namespace BurnOutSharp.Wrappers Console.WriteLine($" Folder {i}"); Console.WriteLine($" Cab start offset = {entry.CabStartOffset}"); Console.WriteLine($" Data count = {entry.DataCount}"); - Console.WriteLine($" Compression type = {entry.CompressionType}"); + Console.WriteLine($" Compression type = {entry.CompressionType} ({entry.CompressionType & Models.MicrosoftCabinet.CompressionType.MASK_TYPE})"); if (entry.ReservedData == null) Console.WriteLine($" Reserved data = [NULL]"); else