-
Notifications
You must be signed in to change notification settings - Fork 0
Pattern Class
Represents a pattern with an associated position and data.
Namespace: Rheo.Storage.Analyzing.Models
Assembly: Rheo.Storage.dll
[MessagePackObject]
public partial class Pattern| Property | Type | Description |
|---|---|---|
| Position | UInt16 | The offset position of the pattern in the file. |
| Data | Byte[] | Gets or sets the prefix pattern data. |
This class is used to store a pattern's offset position within a file and its corresponding data. Patterns are typically used to identify file types by matching byte sequences (magic numbers) at specific positions in the file header.
The offset position of the pattern in the file.
[Key(0)]
public ushort Position { get; set; }The zero-based offset from the beginning of the file where this pattern should match.
Position 0 represents the first byte of the file. Patterns at position 0 are weighted more heavily in the scoring algorithm as they typically represent the file's primary magic number.
The use of ushort limits the maximum position to 65,535 bytes, which is sufficient for file header identification.
Gets or sets the prefix pattern data.
[Key(1)]
public byte[] Data { get; set; }Byte[]
The byte sequence that should match at the specified position.
The data represents the exact byte sequence expected at the pattern's position. All bytes in the data array must match for the pattern to be considered valid.
Returns a string representation of the pattern.
public override string ToString()A string showing the ASCII representation of the data and its position.
var pattern = new Pattern
{
Position = 0,
Data = new byte[] { 0x50, 0x4B, 0x03, 0x04 }
};
Console.WriteLine(pattern.ToString());
// Output: "PK.." at 0The following example demonstrates how to create a pattern for the PNG file format:
using Rheo.Storage.Analyzing.Models;
var pngPattern = new Pattern
{
Position = 0,
Data = new byte[]
{
0x89, 0x50, 0x4E, 0x47, // PNG signature
0x0D, 0x0A, 0x1A, 0x0A // DOS line ending + EOF + Unix line ending
}
};The following example shows how to create patterns for a ZIP file:
using Rheo.Storage.Analyzing.Models;
// ZIP files start with "PK" signature
var zipHeaderPattern = new Pattern
{
Position = 0,
Data = new byte[] { 0x50, 0x4B, 0x03, 0x04 }
};
// Alternative ZIP signature for empty archives
var emptyZipPattern = new Pattern
{
Position = 0,
Data = new byte[] { 0x50, 0x4B, 0x05, 0x06 }
};The following example demonstrates how patterns are typically used within a signature:
using Rheo.Storage.Analyzing.Models;
var signature = new Signature
{
Patterns = new List<Pattern>
{
new Pattern
{
Position = 0,
Data = new byte[] { 0x1F, 0x8B } // GZIP magic number
},
new Pattern
{
Position = 2,
Data = new byte[] { 0x08 } // DEFLATE compression method
}
}
};The following example shows how to create patterns from text strings:
using System.Text;
using Rheo.Storage.Analyzing.Models;
// Create a pattern for XML files
var xmlPattern = new Pattern
{
Position = 0,
Data = Encoding.UTF8.GetBytes("<?xml")
};
// Create a pattern for HTML files
var htmlPattern = new Pattern
{
Position = 0,
Data = Encoding.ASCII.GetBytes("<!DOCTYPE html")
};This class is not thread-safe. When accessing instances from multiple threads, use appropriate synchronization mechanisms.
-
Storage Objects
-
Storage Information
-
Platform-Specific
-
Content-Type Analysis
-
Results
-
Models
-
-
Events & Progress