diff --git a/BurnOutSharp/FileType/MicrosoftCAB.cs b/BurnOutSharp/FileType/MicrosoftCAB.cs index 5fa8f504..14265d54 100644 --- a/BurnOutSharp/FileType/MicrosoftCAB.cs +++ b/BurnOutSharp/FileType/MicrosoftCAB.cs @@ -269,6 +269,18 @@ namespace BurnOutSharp.FileType #region Public Functionality + /// + /// Find the start of an MS-CAB cabinet in a set of data, if possible + /// + public int FindCabinet(byte[] data) + { + if (data == null || data.Length < CFHEADER.SignatureBytes.Length) + return -1; + + bool found = data.FirstPosition(CFHEADER.SignatureBytes, out int index); + return found ? index : -1; + } + /// /// Extract a single file from the archive to /// diff --git a/BurnOutSharp/Tools/Extensions.cs b/BurnOutSharp/Tools/Extensions.cs index 2323088f..ab8563c4 100644 --- a/BurnOutSharp/Tools/Extensions.cs +++ b/BurnOutSharp/Tools/Extensions.cs @@ -164,6 +164,15 @@ namespace BurnOutSharp.Tools return positions; } + /// + /// Find the first position of one array in another, if possible + /// + public static bool FirstPosition(this byte[] stack, byte[] needle, out int position, int start = 0, int end = -1) + { + byte?[] nullableNeedle = needle != null ? needle.Select(b => (byte?)b).ToArray() : null; + return stack.FirstPosition(nullableNeedle, out position, start, end); + } + /// /// Find the first position of one array in another, if possible ///