-
Notifications
You must be signed in to change notification settings - Fork 0
Signature Class
Represents a signature that contains collections of patterns and string data in byte array format.
Namespace: Rheo.Storage.Analyzing.Models
Assembly: Rheo.Storage.dll
[MessagePackObject]
public partial class Signature| Property | Type | Description |
|---|---|---|
| Patterns | List<Pattern> | Gets or sets the collection of patterns used for processing or validation. |
| Strings | List<Byte[]> | Gets or sets the collection of byte arrays representing string data. |
This class provides properties to manage patterns for processing or validation, as well as string data stored in byte array format. Ensure proper encoding and decoding when working with the Strings property.
Signatures are used by the file analyzer to identify file types based on binary patterns (magic numbers) at specific positions within a file, and optional string sequences that may appear anywhere in the file.
Gets or sets the collection of patterns used for processing or validation.
[Key(0)]
public List<Pattern> Patterns { get; set; }A list of Pattern objects representing byte sequences at specific file positions.
Patterns are typically used to identify file headers (magic numbers). Each pattern specifies a byte sequence and its expected position within the file. All patterns in a signature must match for a file to be identified as that type.
Gets or sets the collection of byte arrays representing string data.
[Key(1)]
public List<byte[]> Strings { get; set; }A list of byte arrays representing text or binary sequences that may appear anywhere in the file.
This property can be used to store and retrieve string data in its byte array representation. Ensure proper encoding and decoding when converting between strings and byte arrays.
String signatures are optional and provide additional confidence when identifying files. They can match anywhere within the scanned portion of the file.
Returns a string representation of the signature.
public override string ToString()A string describing the number of patterns and strings in the signature.
var signature = new Signature
{
Patterns = new List<Pattern>
{
new Pattern { Position = 0, Data = new byte[] { 0x50, 0x4B } }
},
Strings = new List<byte[]>()
};
Console.WriteLine(signature.ToString());
// Output: Signature: 1 patterns, 0 stringsThe following example demonstrates how to create a signature for PNG files:
using Rheo.Storage.Analyzing.Models;
var pngSignature = new Signature
{
Patterns = new List<Pattern>
{
new Pattern
{
Position = 0,
Data = new byte[] { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A }
}
},
Strings = new List<byte[]>()
};The following example shows a signature with multiple patterns and string checks:
using System.Text;
using Rheo.Storage.Analyzing.Models;
var xmlSignature = new Signature
{
Patterns = new List<Pattern>
{
new Pattern
{
Position = 0,
Data = Encoding.UTF8.GetBytes("<?xml")
}
},
Strings = new List<byte[]>
{
Encoding.UTF8.GetBytes("version=\"1.0\""),
Encoding.UTF8.GetBytes("encoding=\"UTF-8\"")
}
};The following example demonstrates how signatures are used internally by the analyzer:
using Rheo.Storage.Analyzing.Models;
// This is typically done internally by the FileAnalyzer
bool MatchesSignature(byte[] fileHeader, Signature signature)
{
// Check all patterns
foreach (var pattern in signature.Patterns)
{
if (pattern.Position + pattern.Data.Length > fileHeader.Length)
return false;
for (int i = 0; i < pattern.Data.Length; i++)
{
if (fileHeader[pattern.Position + i] != pattern.Data[i])
return false;
}
}
return true;
}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