mirror of
https://github.com/k1tbyte/Wand-Enhancer.git
synced 2026-08-28 22:01:17 +00:00
49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using System;
|
|
|
|
namespace WandEnhancer.Models
|
|
{
|
|
public sealed class Signature
|
|
{
|
|
public readonly byte[] OriginalBytes;
|
|
public readonly byte[] PatchBytes;
|
|
public readonly byte[] Sequence;
|
|
public readonly byte[] Mask;
|
|
public readonly int Offset;
|
|
|
|
public int Length => Sequence.Length;
|
|
|
|
public static implicit operator byte[](Signature signature) => signature.Sequence;
|
|
|
|
public Signature(string signature, int offset, byte[] patchBytes, byte[] originalBytes)
|
|
{
|
|
Parse(signature, out Sequence, out Mask);
|
|
PatchBytes = patchBytes;
|
|
OriginalBytes = originalBytes;
|
|
Offset = offset;
|
|
}
|
|
|
|
private static void Parse(string signatureStr, out byte[] pattern, out byte[] mask)
|
|
{
|
|
var parts = signatureStr.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
|
|
var length = parts.Length;
|
|
|
|
pattern = new byte[length];
|
|
mask = new byte[length];
|
|
|
|
for (var i = 0; i < length; i++)
|
|
{
|
|
if (parts[i] == "??" || parts[i] == "?")
|
|
{
|
|
pattern[i] = 0;
|
|
// wildcard byte
|
|
mask[i] = 0;
|
|
continue;
|
|
}
|
|
|
|
pattern[i] = Convert.ToByte(parts[i], 16);
|
|
mask[i] = 1;
|
|
}
|
|
}
|
|
}
|
|
}
|