Skip to content

Signature Class

Naveen Dharmathunga edited this page Jan 19, 2026 · 1 revision

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

Definition

[MessagePackObject]
public partial class Signature

Properties

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.

Remarks

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.


Property Details

Patterns

Gets or sets the collection of patterns used for processing or validation.

[Key(0)]
public List<Pattern> Patterns { get; set; }

Property Value

List<Pattern>

A list of Pattern objects representing byte sequences at specific file positions.

Remarks

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.


Strings

Gets or sets the collection of byte arrays representing string data.

[Key(1)]
public List<byte[]> Strings { get; set; }

Property Value

List<Byte[]>

A list of byte arrays representing text or binary sequences that may appear anywhere in the file.

Remarks

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.


Methods

ToString()

Returns a string representation of the signature.

public override string ToString()

Returns

String

A string describing the number of patterns and strings in the signature.

Examples

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 strings

Examples

Creating a Simple Signature

The 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[]>()
};

Creating a Signature with Multiple Patterns

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\"")
    }
};

Using Signatures in File Analysis

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;
}

Thread Safety

This class is not thread-safe. When accessing instances from multiple threads, use appropriate synchronization mechanisms.

See Also

Clone this wiki locally