feat: port aelrynth 2026.9.27.2 snapshot onto GitHub history

Overlay upstream/main (9b5e276) onto BlankenshipG main without rewriting
history. Keep origin-only Decal/plugin/docs trees. Re-apply aelrynth.com
and sibling-fork URL fixes that aelrynth git still has as tombohar links.

Co-authored-by: BlankenshipG <BlankenshipG@users.noreply.github.com>
This commit is contained in:
Cursor Agent 2026-10-04 15:43:50 +00:00
commit 4ddbb52eb2
No known key found for this signature in database
244 changed files with 59710 additions and 3067 deletions

View file

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0-windows</TargetFramework>
<PlatformTarget>AnyCPU</PlatformTarget>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>RynthCore.HookManifest</RootNamespace>
<AssemblyName>RynthCore.HookManifest</AssemblyName>
<LangVersion>latest</LangVersion>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,28 @@
namespace RynthCore.HookManifest.Scanning;
public sealed class AcClientImageView
{
public AcClientImageView(
int imageBase, int imageSize,
int textRva, byte[] textBytes,
int rdataRva = 0, byte[]? rdataBytes = null)
{
ImageBase = imageBase;
ImageSize = imageSize;
TextRva = textRva;
TextBytes = textBytes;
RdataRva = rdataRva;
RdataBytes = rdataBytes ?? [];
}
public int ImageBase { get; }
public int ImageSize { get; }
public int TextRva { get; }
public int TextBaseVa => ImageBase + TextRva;
public byte[] TextBytes { get; }
public int RdataRva { get; }
public int RdataBaseVa => ImageBase + RdataRva;
public byte[] RdataBytes { get; }
public bool HasRdata => RdataBytes.Length > 0;
}

View file

@ -0,0 +1,105 @@
using System;
namespace RynthCore.HookManifest.Scanning;
public static class PatternScanner
{
public static int FindPattern(byte[] data, byte[] pattern)
=> FindPatternInRegion(data, pattern, 0, data.Length);
public static int FindPattern(byte[] data, byte?[] pattern)
=> FindPatternInRegion(data, pattern, 0, data.Length);
public static int FindPatternInRegion(byte[] data, byte[] pattern, int start, int end)
{
int limit = Math.Min(end, data.Length) - pattern.Length;
for (int i = Math.Max(0, start); i <= limit; i++)
{
bool match = true;
for (int j = 0; j < pattern.Length; j++)
{
if (data[i + j] == pattern[j])
continue;
match = false;
break;
}
if (match)
return i;
}
return -1;
}
public static int FindPatternInRegion(byte[] data, byte?[] pattern, int start, int end)
{
int limit = Math.Min(end, data.Length) - pattern.Length;
for (int i = Math.Max(0, start); i <= limit; i++)
{
bool match = true;
for (int j = 0; j < pattern.Length; j++)
{
byte? expected = pattern[j];
if (expected.HasValue && data[i + j] != expected.Value)
{
match = false;
break;
}
}
if (match)
return i;
}
return -1;
}
public static int FindPrologueBefore(byte[] data, int opcodeOffset, byte[] prologue, int maxDistance = 300)
{
for (int back = 1; back < maxDistance; back++)
{
int pos = opcodeOffset - back;
if (pos < 1 || pos + prologue.Length > data.Length)
continue;
if (!VerifyBytes(data, pos, prologue))
continue;
byte prev = data[pos - 1];
if (prev == 0xCC || prev == 0x90 || prev == 0xC3)
return pos;
}
return -1;
}
public static bool VerifyBytes(byte[] data, int offset, byte[] expected)
{
if (offset < 0 || offset + expected.Length > data.Length)
return false;
for (int i = 0; i < expected.Length; i++)
{
if (data[offset + i] != expected[i])
return false;
}
return true;
}
public static bool VerifyPattern(byte[] data, int offset, byte?[] expected)
{
if (offset < 0 || offset + expected.Length > data.Length)
return false;
for (int i = 0; i < expected.Length; i++)
{
byte? value = expected[i];
if (value.HasValue && data[offset + i] != value.Value)
return false;
}
return true;
}
}

View file

@ -0,0 +1,170 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace RynthCore.HookManifest.Scanning;
/// <summary>
/// MSVC 32-bit RTTI walker. Given a class name like "gmRadarUI", walks:
/// 1. Type descriptor (.rdata: ".?AV<Class>@@" string, header lives 8 bytes before)
/// 2. Complete Object Locator(s) that reference the type descriptor (+0xC field)
/// 3. vtables that the COL precedes (vtable starts at COL_ref_addr + 4)
/// 4. virtual method slots (4-byte code pointers into .text)
/// </summary>
public static class RttiVtableScanner
{
public readonly record struct Vtable(int VtableVa, int ColVa);
public readonly record struct VtableMethod(int SlotIndex, int Va);
public sealed record VtableEnumeration(
string ClassName,
int? TypeDescriptorVa,
IReadOnlyList<int> ColVas,
IReadOnlyList<Vtable> Vtables,
IReadOnlyList<VtableMethod> Methods);
/// <summary>
/// Returns the VA of the type descriptor for <paramref name="className"/>,
/// or 0 if not present in the image.
/// The descriptor name string in .rdata is preceded by an 8-byte header
/// (vftable ptr + spare); the descriptor's VA is string_va - 8.
/// </summary>
public static int FindTypeDescriptorVa(AcClientImageView image, string className)
{
string mangled = $".?AV{className}@@";
int stringVa = StringRefScanner.FindStringVa(image, mangled);
if (stringVa == 0) return 0;
return stringVa - 8;
}
/// <summary>
/// Find every 32-bit little-endian occurrence of <paramref name="targetVa"/>
/// in .rdata. Returns the VA of each occurrence.
/// </summary>
public static List<int> FindPointersTo(AcClientImageView image, int targetVa)
{
var hits = new List<int>();
if (!image.HasRdata) return hits;
byte[] data = image.RdataBytes;
byte b0 = (byte)(targetVa & 0xFF);
byte b1 = (byte)((targetVa >> 8) & 0xFF);
byte b2 = (byte)((targetVa >> 16) & 0xFF);
byte b3 = (byte)((targetVa >> 24) & 0xFF);
int max = data.Length - 4;
// Pointer fields are 4-byte aligned in MSVC-emitted RTTI tables.
for (int i = 0; i <= max; i += 4)
{
if (data[i] == b0 && data[i + 1] == b1 && data[i + 2] == b2 && data[i + 3] == b3)
hits.Add(image.RdataBaseVa + i);
}
return hits;
}
/// <summary>
/// Locate every Complete Object Locator that references
/// <paramref name="typeDescriptorVa"/>. The COL's pTypeDescriptor field
/// is at COL+0xC, so the COL starts 0xC bytes before each reference.
/// Validates signature == 0 (32-bit).
/// </summary>
public static List<int> FindColsForTypeDescriptor(AcClientImageView image, int typeDescriptorVa)
{
var cols = new List<int>();
if (!image.HasRdata) return cols;
foreach (int refVa in FindPointersTo(image, typeDescriptorVa))
{
int colVa = refVa - 0xC;
if (!TryReadInt32(image, colVa, out int signature)) continue;
if (signature != 0) continue; // 32-bit COL signature
if (!TryReadInt32(image, colVa + 0x10, out int classHierarchyVa)) continue;
if (!IsInRdata(image, classHierarchyVa)) continue;
cols.Add(colVa);
}
return cols;
}
/// <summary>
/// Find every vtable preceded by a pointer to the given COL.
/// The COL pointer slot lives 4 bytes before the vtable proper.
/// </summary>
public static List<Vtable> FindVtablesForCol(AcClientImageView image, int colVa)
{
var tables = new List<Vtable>();
foreach (int refVa in FindPointersTo(image, colVa))
{
int vtableVa = refVa + 4;
tables.Add(new Vtable(vtableVa, colVa));
}
return tables;
}
/// <summary>
/// Read consecutive 4-byte code pointers from a vtable. Stops at the first
/// entry that is not a valid .text pointer (or after <paramref name="maxSlots"/>).
/// </summary>
public static List<VtableMethod> EnumerateVtable(AcClientImageView image, int vtableVa, int maxSlots = 256)
{
var methods = new List<VtableMethod>();
for (int slot = 0; slot < maxSlots; slot++)
{
int entryVa = vtableVa + slot * 4;
if (!TryReadInt32(image, entryVa, out int ptr)) break;
if (!IsInText(image, ptr)) break;
methods.Add(new VtableMethod(slot, ptr));
}
return methods;
}
/// <summary>
/// End-to-end: class name → every method address across every vtable.
/// </summary>
public static VtableEnumeration EnumerateClass(AcClientImageView image, string className)
{
int tdVa = FindTypeDescriptorVa(image, className);
if (tdVa == 0)
return new VtableEnumeration(className, null, [], [], []);
var cols = FindColsForTypeDescriptor(image, tdVa);
var allTables = new List<Vtable>();
var allMethods = new List<VtableMethod>();
var seen = new HashSet<int>();
foreach (int colVa in cols)
{
foreach (var vt in FindVtablesForCol(image, colVa))
{
allTables.Add(vt);
foreach (var m in EnumerateVtable(image, vt.VtableVa))
{
if (seen.Add(m.Va))
allMethods.Add(m);
}
}
}
return new VtableEnumeration(className, tdVa, cols, allTables, allMethods);
}
private static bool TryReadInt32(AcClientImageView image, int va, out int value)
{
value = 0;
if (image.HasRdata && va >= image.RdataBaseVa && va + 4 <= image.RdataBaseVa + image.RdataBytes.Length)
{
int off = va - image.RdataBaseVa;
value = image.RdataBytes[off]
| (image.RdataBytes[off + 1] << 8)
| (image.RdataBytes[off + 2] << 16)
| (image.RdataBytes[off + 3] << 24);
return true;
}
return false;
}
private static bool IsInRdata(AcClientImageView image, int va)
=> image.HasRdata
&& va >= image.RdataBaseVa
&& va < image.RdataBaseVa + image.RdataBytes.Length;
private static bool IsInText(AcClientImageView image, int va)
=> va >= image.TextBaseVa
&& va < image.TextBaseVa + image.TextBytes.Length;
}

View file

@ -0,0 +1,171 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace RynthCore.HookManifest.Scanning;
/// <summary>
/// Locate AC-client functions by anchoring on string literals they push to
/// the stack (debug/trace/error messages). String refs are far more
/// discriminating than the generic 6-byte prologues that match dozens of
/// functions.
/// </summary>
public static class StringRefScanner
{
/// <summary>
/// Returns the absolute VA of the first NUL-terminated occurrence of
/// <paramref name="literal"/> in .rdata (and as a fallback, .text), or 0
/// if not present.
/// </summary>
public static int FindStringVa(AcClientImageView image, string literal, bool requireNul = true)
{
if (string.IsNullOrEmpty(literal)) return 0;
byte[] needle = Encoding.ASCII.GetBytes(literal);
if (image.HasRdata)
{
int rd = FindAscii(image.RdataBytes, needle, requireNul);
if (rd >= 0) return image.RdataBaseVa + rd;
}
int tx = FindAscii(image.TextBytes, needle, requireNul);
if (tx >= 0) return image.TextBaseVa + tx;
return 0;
}
/// <summary>
/// Find every <c>push imm32</c> in .text whose immediate equals
/// <paramref name="targetVa"/>. Returns offsets into TextBytes.
/// </summary>
public static List<int> FindPushImm32Sites(AcClientImageView image, int targetVa)
{
var sites = new List<int>();
byte b0 = (byte)(targetVa & 0xFF);
byte b1 = (byte)((targetVa >> 8) & 0xFF);
byte b2 = (byte)((targetVa >> 16) & 0xFF);
byte b3 = (byte)((targetVa >> 24) & 0xFF);
byte[] bytes = image.TextBytes;
int max = bytes.Length - 5;
for (int i = 0; i < max; i++)
{
if (bytes[i] != 0x68) continue;
if (bytes[i + 1] != b0) continue;
if (bytes[i + 2] != b1) continue;
if (bytes[i + 3] != b2) continue;
if (bytes[i + 4] != b3) continue;
sites.Add(i);
}
return sites;
}
/// <summary>
/// Find every 4-byte little-endian occurrence of <paramref name="targetVa"/>
/// anywhere in .text — catches mov reg,imm32 / lea / cmp / push-mem etc.,
/// not just `push imm32`. Returns .text offsets of the immediate (the
/// instruction starts 1-2 bytes earlier, but walk-back-to-prologue does
/// not need exact instruction boundaries).
/// </summary>
public static List<int> FindImm32SitesInText(AcClientImageView image, int targetVa)
{
var sites = new List<int>();
byte b0 = (byte)(targetVa & 0xFF);
byte b1 = (byte)((targetVa >> 8) & 0xFF);
byte b2 = (byte)((targetVa >> 16) & 0xFF);
byte b3 = (byte)((targetVa >> 24) & 0xFF);
byte[] bytes = image.TextBytes;
int max = bytes.Length - 4;
for (int i = 0; i <= max; i++)
{
if (bytes[i] == b0 && bytes[i + 1] == b1 && bytes[i + 2] == b2 && bytes[i + 3] == b3)
sites.Add(i);
}
return sites;
}
/// <summary>
/// Find every 4-byte little-endian occurrence of <paramref name="targetVa"/>
/// in .rdata — i.e. the string used as a data-table pointer. Returns the
/// VA of each pointer slot. There is no enclosing function to walk back to;
/// this just reports that the string is table-referenced.
/// </summary>
public static List<int> FindDataPointerSites(AcClientImageView image, int targetVa)
{
var sites = new List<int>();
if (!image.HasRdata) return sites;
byte[] data = image.RdataBytes;
byte b0 = (byte)(targetVa & 0xFF);
byte b1 = (byte)((targetVa >> 8) & 0xFF);
byte b2 = (byte)((targetVa >> 16) & 0xFF);
byte b3 = (byte)((targetVa >> 24) & 0xFF);
int max = data.Length - 4;
for (int i = 0; i <= max; i += 4)
{
if (data[i] == b0 && data[i + 1] == b1 && data[i + 2] == b2 && data[i + 3] == b3)
sites.Add(image.RdataBaseVa + i);
}
return sites;
}
/// <summary>
/// Walk backward from <paramref name="textOffset"/> in TextBytes for the
/// nearest occurrence of <paramref name="prologue"/>. Returns the offset
/// of the matched prologue, or -1.
/// </summary>
public static int FindFunctionEntryBefore(
AcClientImageView image, int textOffset, byte[] prologue, int maxBackward = 0x2000)
{
if (prologue.Length == 0) return -1;
byte[] bytes = image.TextBytes;
int floor = Math.Max(0, textOffset - maxBackward);
for (int i = textOffset; i >= floor; i--)
{
if (i + prologue.Length > bytes.Length) continue;
bool match = true;
for (int j = 0; j < prologue.Length; j++)
{
if (bytes[i + j] != prologue[j]) { match = false; break; }
}
if (match) return i;
}
return -1;
}
/// <summary>
/// End-to-end: find every function that pushes <paramref name="literal"/>
/// and walk back to a prologue. Single hit = strong anchor; multi-hit =
/// needs disambiguation; zero = string isn't in the image.
/// </summary>
public static List<int> FindFunctionsByStringRef(
AcClientImageView image, string literal, byte[] prologue,
int maxBackward = 0x2000, bool requireNul = true)
{
var hits = new HashSet<int>();
int stringVa = FindStringVa(image, literal, requireNul);
if (stringVa == 0) return [];
foreach (int site in FindPushImm32Sites(image, stringVa))
{
int funcOff = FindFunctionEntryBefore(image, site, prologue, maxBackward);
if (funcOff >= 0) hits.Add(image.TextBaseVa + funcOff);
}
return new List<int>(hits);
}
private static int FindAscii(byte[] haystack, byte[] needle, bool requireNul)
{
int max = haystack.Length - needle.Length - (requireNul ? 1 : 0);
for (int i = 0; i <= max; i++)
{
bool match = true;
for (int j = 0; j < needle.Length; j++)
{
if (haystack[i + j] != needle[j]) { match = false; break; }
}
if (!match) continue;
if (requireNul && haystack[i + needle.Length] != 0) continue;
return i;
}
return -1;
}
}

View file

@ -0,0 +1,17 @@
using System.Collections.Generic;
namespace RynthCore.HookManifest.Schema;
public sealed record CallTarget(int Va, int Offset);
public sealed record FunctionSnapshot
{
public required int Rva { get; init; }
public required int Va { get; init; }
public required int LengthBytes { get; init; }
public required int InstructionCount { get; init; }
public required bool EndsAtReturn { get; init; }
public required string PrologueHex { get; init; }
public IReadOnlyList<CallTarget> CallTargets { get; init; } = [];
public string? Note { get; init; }
}

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
namespace RynthCore.HookManifest.Schema;
public sealed record ManifestInput
{
public required string Path { get; init; }
public required long FileSizeBytes { get; init; }
public required string Sha256 { get; init; }
public required int ImageBase { get; init; }
public required int ImageSizeRva { get; init; }
public required int TextRva { get; init; }
public required string Machine { get; init; }
}
public sealed record HookManifest
{
public int SchemaVersion { get; init; } = 1;
public required string Generator { get; init; }
public required DateTime GeneratedAtUtc { get; init; }
public required ManifestInput Input { get; init; }
public IReadOnlyDictionary<string, string> Labels { get; init; } =
new Dictionary<string, string>();
public IReadOnlyDictionary<string, HookManifestEntry> Symbols { get; init; } =
new Dictionary<string, HookManifestEntry>();
}

View file

@ -0,0 +1,25 @@
using System.Collections.Generic;
namespace RynthCore.HookManifest.Schema;
public enum ResolutionStatus
{
Resolved,
Ambiguous,
Unresolved,
NotApplicable
}
public sealed record HookManifestEntry
{
public required string SymbolId { get; init; }
public required ResolutionStatus Status { get; init; }
public ResolvedAddress? Address { get; init; }
public string? PatternId { get; init; }
public int MatchedCandidates { get; init; }
public string? ChosenCandidateReason { get; init; }
public IReadOnlyList<ValidationRecord> Validations { get; init; } = [];
public IReadOnlyList<ValidationRecord> Warnings { get; init; } = [];
public string? Reason { get; init; }
public FunctionSnapshot? Snapshot { get; init; }
}

View file

@ -0,0 +1,20 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace RynthCore.HookManifest.Schema;
[JsonSourceGenerationOptions(
WriteIndented = true,
PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase,
UseStringEnumConverter = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(HookManifest))]
[JsonSerializable(typeof(HookManifestEntry))]
[JsonSerializable(typeof(ResolvedAddress))]
[JsonSerializable(typeof(ValidationRecord))]
[JsonSerializable(typeof(ManifestInput))]
[JsonSerializable(typeof(FunctionSnapshot))]
[JsonSerializable(typeof(CallTarget))]
[JsonSerializable(typeof(Dictionary<string, HookManifestEntry>))]
[JsonSerializable(typeof(Dictionary<string, string>))]
public partial class HookManifestJsonContext : JsonSerializerContext;

View file

@ -0,0 +1,6 @@
namespace RynthCore.HookManifest.Schema;
public sealed record ResolvedAddress(int Va, int Rva)
{
public string Hex => $"0x{Va:X8}";
}

View file

@ -0,0 +1,3 @@
namespace RynthCore.HookManifest.Schema;
public sealed record ValidationRecord(string RuleId, bool Passed, string Detail);