Add cabinet finding

This commit is contained in:
Matt Nadareski
2022-07-07 12:11:23 -07:00
parent 5385de0f0a
commit 1517a66724
2 changed files with 21 additions and 0 deletions

View File

@@ -269,6 +269,18 @@ namespace BurnOutSharp.FileType
#region Public Functionality
/// <summary>
/// Find the start of an MS-CAB cabinet in a set of data, if possible
/// </summary>
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;
}
/// <summary>
/// Extract a single file from the archive to <paramref name="outputDirectory"/>
/// </summary>

View File

@@ -164,6 +164,15 @@ namespace BurnOutSharp.Tools
return positions;
}
/// <summary>
/// Find the first position of one array in another, if possible
/// </summary>
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);
}
/// <summary>
/// Find the first position of one array in another, if possible
/// </summary>