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,113 @@
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace RynthCore.HookResolver.Core.Diff;
public enum EngineResolutionKind
{
PatternResolved,
FallbackResolved,
Unavailable
}
public sealed record EngineResolution(
string SymbolId,
int? Va,
EngineResolutionKind Kind,
string Detail);
public static class EngineLogParser
{
public const string LogDirectory = @"C:\Games\RynthCore\Logs";
public const string DefaultLogPath = LogDirectory + @"\RynthCore.log";
/// <summary>
/// HookResolver lines are engine-origin, so since the per-client log split
/// they land in RynthCore.&lt;pid&gt;.log, not the shared RynthCore.log. Pick the
/// newest per-PID session log if any exist; otherwise fall back to the shared
/// file (and legacy single-file layouts).
/// </summary>
public static string ResolveDefaultLogPath()
{
try
{
if (Directory.Exists(LogDirectory))
{
string? newest = null;
System.DateTime newestTime = System.DateTime.MinValue;
foreach (string f in Directory.GetFiles(LogDirectory, "RynthCore.*.log"))
{
var t = File.GetLastWriteTime(f);
if (t > newestTime) { newestTime = t; newest = f; }
}
if (newest != null) return newest;
}
}
catch { /* fall through to the shared path */ }
return DefaultLogPath;
}
private static readonly Regex Resolved = new(
@"HookResolver\[(?<sym>[^\]]+)\]:\s+RESOLVED\s+via\s+(?<detail>\S+)\s+@\s+0x(?<addr>[0-9A-Fa-f]+)",
RegexOptions.Compiled);
private static readonly Regex Fallback = new(
@"HookResolver\[(?<sym>[^\]]+)\]:\s+PATTERN MISS.*?VA\s+0x(?<addr>[0-9A-Fa-f]+)",
RegexOptions.Compiled);
private static readonly Regex Unavailable = new(
@"HookResolver\[(?<sym>[^\]]+)\]:\s+UNAVAILABLE\b",
RegexOptions.Compiled);
public static async Task<IReadOnlyDictionary<string, EngineResolution>> ParseAsync(
string? path = null, CancellationToken ct = default)
{
path ??= ResolveDefaultLogPath();
var result = new Dictionary<string, EngineResolution>();
if (!File.Exists(path)) return result;
await using var stream = new FileStream(
path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete);
using var reader = new StreamReader(stream);
while (await reader.ReadLineAsync(ct).ConfigureAwait(false) is { } line)
{
if (TryMatch(Resolved, line, out var sym, out var addr, out var detail))
{
result[sym] = new EngineResolution(sym, addr, EngineResolutionKind.PatternResolved, detail);
continue;
}
if (TryMatch(Fallback, line, out sym, out addr, out _))
{
result[sym] = new EngineResolution(sym, addr, EngineResolutionKind.FallbackResolved, "fallback-va");
continue;
}
var unavailableMatch = Unavailable.Match(line);
if (unavailableMatch.Success)
{
string s = unavailableMatch.Groups["sym"].Value;
result[s] = new EngineResolution(s, null, EngineResolutionKind.Unavailable, "unavailable");
}
}
return result;
}
private static bool TryMatch(Regex rx, string line, out string symbol, out int va, out string detail)
{
symbol = string.Empty;
detail = string.Empty;
va = 0;
var m = rx.Match(line);
if (!m.Success) return false;
symbol = m.Groups["sym"].Value;
va = int.Parse(m.Groups["addr"].Value, System.Globalization.NumberStyles.HexNumber);
if (m.Groups["detail"].Success) detail = m.Groups["detail"].Value;
return true;
}
}

View file

@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using Iced.Intel;
using RynthCore.HookManifest.Scanning;
using RynthCore.HookManifest.Schema;
namespace RynthCore.HookResolver.Core.Disassembly;
public static class IcedDisassembler
{
private const int DefaultMaxBytes = 0x1000;
private const int DefaultMaxInstructions = 4096;
public static FunctionSnapshot Snapshot(
AcClientImageView image,
int rva,
int maxBytes = DefaultMaxBytes,
int maxInstructions = DefaultMaxInstructions,
int maxCallsToCapture = 8)
{
int textRva = image.TextRva;
int textOffset = rva - textRva;
if (textOffset < 0 || textOffset >= image.TextBytes.Length)
{
return new FunctionSnapshot
{
Rva = rva,
Va = image.ImageBase + rva,
LengthBytes = 0,
InstructionCount = 0,
EndsAtReturn = false,
PrologueHex = "",
Note = "RVA outside .text"
};
}
int available = image.TextBytes.Length - textOffset;
int scanLen = Math.Min(maxBytes, available);
byte[] slice = new byte[scanLen];
Array.Copy(image.TextBytes, textOffset, slice, 0, scanLen);
var reader = new ByteArrayCodeReader(slice);
var decoder = Decoder.Create(32, reader);
decoder.IP = (ulong)(uint)(image.ImageBase + rva);
int firstVa = image.ImageBase + rva;
ulong endIp = (ulong)(uint)(firstVa + scanLen);
int instructionCount = 0;
bool endsAtReturn = false;
var calls = new List<CallTarget>();
while (decoder.IP < endIp && instructionCount < maxInstructions)
{
decoder.Decode(out var instr);
if (instr.IsInvalid)
break;
instructionCount++;
if (instr.Mnemonic == Mnemonic.Call &&
instr.OpCount > 0 &&
instr.Op0Kind == OpKind.NearBranch32 &&
calls.Count < maxCallsToCapture)
{
int targetVa = (int)(uint)instr.NearBranch32;
int offset = (int)(instr.IP - (ulong)(uint)firstVa);
calls.Add(new CallTarget(targetVa, offset));
}
if (instr.FlowControl == FlowControl.Return)
{
endsAtReturn = true;
break;
}
if (instr.FlowControl == FlowControl.UnconditionalBranch && instructionCount > 2)
{
break;
}
}
int finalLength = (int)((long)decoder.IP - firstVa);
int prologueLen = Math.Min(8, scanLen);
string prologueHex = Convert.ToHexString(image.TextBytes.AsSpan(textOffset, prologueLen));
return new FunctionSnapshot
{
Rva = rva,
Va = firstVa,
LengthBytes = finalLength,
InstructionCount = instructionCount,
EndsAtReturn = endsAtReturn,
PrologueHex = prologueHex,
CallTargets = calls
};
}
}

View file

@ -0,0 +1,123 @@
using System.Collections.Generic;
using System.Linq;
using RynthCore.HookManifest.Scanning;
using RynthCore.HookManifest.Schema;
using RynthCore.HookResolver.Core.Disassembly;
using RynthCore.HookResolver.Core.Offline;
namespace RynthCore.HookResolver.Core.Discovery;
public enum StringReferenceMode
{
PushImm32, // 0x68 + va (printf-style string arg; precise)
AnyImm32InText, // any mov/lea/cmp immediate in .text (broad)
DataPointer // va appears as a pointer in .rdata table (no function)
}
public sealed record StringDiscoveryRequest(
string Literal,
byte[] Prologue,
int MaxBackward = 0x2000,
bool LooseMatch = false,
StringReferenceMode ReferenceMode = StringReferenceMode.PushImm32);
public sealed record StringDiscoveryCandidate(
int Va,
int Rva,
int PushSiteVa,
FunctionSnapshot Snapshot);
public sealed record StringDiscoveryResult(
string Literal,
int? StringVa,
int PushSiteCount,
IReadOnlyList<StringDiscoveryCandidate> Candidates,
string Summary);
public static class StringDiscoveryService
{
public static StringDiscoveryResult Discover(AcClientImage image, StringDiscoveryRequest req)
{
bool requireNul = !req.LooseMatch;
int stringVa = StringRefScanner.FindStringVa(image.View, req.Literal, requireNul);
if (stringVa == 0)
{
string hint = requireNul
? " (try Loose match — it may be embedded in a longer string)"
: "";
return new StringDiscoveryResult(req.Literal, null, 0, [],
$"'{req.Literal}' not present in image{hint}.");
}
// DataPointer mode: the string is a table entry, not a code reference.
// We can report where the table is but there's no function to walk to.
if (req.ReferenceMode == StringReferenceMode.DataPointer)
{
var ptrs = StringRefScanner.FindDataPointerSites(image.View, stringVa);
string msg = ptrs.Count == 0
? $"'{req.Literal}' @ 0x{stringVa:X8} — not referenced as a .rdata data pointer either."
: $"'{req.Literal}' @ 0x{stringVa:X8} — referenced by {ptrs.Count} data-table " +
$"pointer(s): {string.Join(", ", ptrs.ConvertAll(p => $"0x{p:X8}"))}. " +
"Table-driven — no function to walk back to (inspect the table layout manually).";
return new StringDiscoveryResult(req.Literal, stringVa, ptrs.Count, [], msg);
}
var sites = req.ReferenceMode == StringReferenceMode.AnyImm32InText
? StringRefScanner.FindImm32SitesInText(image.View, stringVa)
: StringRefScanner.FindPushImm32Sites(image.View, stringVa);
string refKind = req.ReferenceMode == StringReferenceMode.AnyImm32InText
? "imm32" : "push imm32";
if (sites.Count == 0)
{
return new StringDiscoveryResult(req.Literal, stringVa, 0, [],
$"'{req.Literal}' @ 0x{stringVa:X8} — no `{refKind}` site references it " +
"(try AnyImm32 or DataPointer reference mode).");
}
var byFunc = new Dictionary<int, int>();
foreach (int site in sites)
{
int funcOff = StringRefScanner.FindFunctionEntryBefore(
image.View, site, req.Prologue, req.MaxBackward);
if (funcOff < 0) continue;
int funcVa = image.View.TextBaseVa + funcOff;
int siteVa = image.View.TextBaseVa + site;
if (!byFunc.ContainsKey(funcVa))
byFunc[funcVa] = siteVa;
}
var candidates = byFunc
.OrderBy(kv => kv.Key)
.Select(kv =>
{
int funcVa = kv.Key;
int rva = funcVa - image.View.ImageBase;
var snap = IcedDisassembler.Snapshot(image.View, rva);
return new StringDiscoveryCandidate(funcVa, rva, kv.Value, snap);
})
.ToList();
string summary = candidates.Count switch
{
0 => $"'{req.Literal}' @ 0x{stringVa:X8} — {sites.Count} {refKind} site(s), " +
"but no enclosing prologue match (try a different prologue or larger walk-back).",
1 => $"'{req.Literal}' @ 0x{stringVa:X8} — single function candidate via {refKind} (strong anchor).",
_ => $"'{req.Literal}' @ 0x{stringVa:X8} — {candidates.Count} candidates via {refKind} " +
$"({sites.Count} site(s); disambiguate with the snapshot)."
};
return new StringDiscoveryResult(req.Literal, stringVa, sites.Count, candidates, summary);
}
public static IReadOnlyList<ProloguePreset> Presets { get; } =
[
new("thiscall (push esi; mov esi, ecx)", [0x56, 0x8B, 0xF1]),
new("cdecl (push ebp; mov ebp, esp)", [0x55, 0x8B, 0xEC]),
new("combat-action (sub esp,0xC; push regs; call)", [0x83, 0xEC, 0x0C, 0x53, 0x56, 0x57, 0xE8]),
new("static (sub esp,N)", [0x83, 0xEC]),
];
}
public sealed record ProloguePreset(string Name, byte[] Bytes);

View file

@ -0,0 +1,69 @@
using System.Collections.Generic;
using System.Linq;
using RynthCore.HookManifest.Scanning;
using RynthCore.HookManifest.Schema;
using RynthCore.HookResolver.Core.Disassembly;
using RynthCore.HookResolver.Core.Offline;
namespace RynthCore.HookResolver.Core.Discovery;
public sealed record VtableMethodCandidate(
int SlotIndex,
int Va,
int VtableVa,
FunctionSnapshot Snapshot);
public sealed record VtableDiscoveryResult(
string ClassName,
int? TypeDescriptorVa,
int ColCount,
int VtableCount,
IReadOnlyList<VtableMethodCandidate> Methods,
string Summary);
public static class VtableDiscoveryService
{
public static VtableDiscoveryResult Discover(AcClientImage image, string className)
{
var view = image.View;
var enumeration = RttiVtableScanner.EnumerateClass(view, className);
if (enumeration.TypeDescriptorVa is null)
{
return new VtableDiscoveryResult(className, null, 0, 0, [],
$"Type descriptor '.?AV{className}@@' not present in .rdata.");
}
if (enumeration.Vtables.Count == 0)
{
return new VtableDiscoveryResult(className,
enumeration.TypeDescriptorVa, enumeration.ColVas.Count, 0, [],
$"Type descriptor found @ 0x{enumeration.TypeDescriptorVa:X8} with " +
$"{enumeration.ColVas.Count} COL(s) but no vtable preceded by a COL pointer.");
}
var methods = enumeration.Methods
.OrderBy(m => m.SlotIndex)
.Select(m =>
{
int rva = m.Va - view.ImageBase;
var snap = IcedDisassembler.Snapshot(view, rva);
int vtableVa = enumeration.Vtables[0].VtableVa;
return new VtableMethodCandidate(m.SlotIndex, m.Va, vtableVa, snap);
})
.ToList();
string summary =
$"'{className}' → TypeDesc 0x{enumeration.TypeDescriptorVa:X8}, " +
$"{enumeration.ColVas.Count} COL(s), {enumeration.Vtables.Count} vtable(s), " +
$"{methods.Count} unique method(s).";
return new VtableDiscoveryResult(
className,
enumeration.TypeDescriptorVa,
enumeration.ColVas.Count,
enumeration.Vtables.Count,
methods,
summary);
}
}

View file

@ -0,0 +1,6 @@
using RynthCore.HookManifest.Scanning;
using RynthCore.HookManifest.Schema;
namespace RynthCore.HookResolver.Core.Offline;
public sealed record AcClientImage(AcClientImageView View, ManifestInput Input);

View file

@ -0,0 +1,147 @@
using System;
using System.IO;
using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
using RynthCore.HookManifest.Scanning;
using RynthCore.HookManifest.Schema;
namespace RynthCore.HookResolver.Core.Offline;
public static class AcClientImageLoader
{
private const ushort DosSignature = 0x5A4D;
private const uint NtSignature = 0x00004550;
private const int DosPeOffset = 0x3C;
private const int FileHeaderMachineOffset = 0x0;
private const int FileHeaderNumSectionsOffset = 0x2;
private const int FileHeaderOptionalSizeOffset = 0x10;
private const int OptionalHeaderImageBaseOffset = 0x1C;
private const int OptionalHeaderSizeOfImageOffset = 0x38;
private const int SectionHeaderSize = 0x28;
private const int SectionNameLength = 8;
public static async Task<AcClientImage> LoadAsync(string path, CancellationToken ct = default)
{
if (string.IsNullOrWhiteSpace(path))
throw new ArgumentException("Path is required.", nameof(path));
if (!File.Exists(path))
throw new FileNotFoundException("acclient.exe not found.", path);
byte[] fileBytes = await File.ReadAllBytesAsync(path, ct).ConfigureAwait(false);
if (fileBytes.Length < 0x200)
throw new InvalidDataException("File is too small to be a valid PE.");
if (BitConverter.ToUInt16(fileBytes, 0) != DosSignature)
throw new InvalidDataException("Missing MZ DOS signature.");
int peOffset = BitConverter.ToInt32(fileBytes, DosPeOffset);
if (peOffset <= 0 || peOffset + 0x18 > fileBytes.Length)
throw new InvalidDataException("Invalid PE header offset.");
if (BitConverter.ToUInt32(fileBytes, peOffset) != NtSignature)
throw new InvalidDataException("Missing PE NT signature.");
int fileHeaderOffset = peOffset + 4;
ushort machine = BitConverter.ToUInt16(fileBytes, fileHeaderOffset + FileHeaderMachineOffset);
ushort numSections = BitConverter.ToUInt16(fileBytes, fileHeaderOffset + FileHeaderNumSectionsOffset);
ushort optionalHeaderSize = BitConverter.ToUInt16(fileBytes, fileHeaderOffset + FileHeaderOptionalSizeOffset);
int optionalHeaderOffset = fileHeaderOffset + 0x14; // FILE_HEADER is 20 bytes
int imageBase = BitConverter.ToInt32(fileBytes, optionalHeaderOffset + OptionalHeaderImageBaseOffset);
int imageSize = BitConverter.ToInt32(fileBytes, optionalHeaderOffset + OptionalHeaderSizeOfImageOffset);
int sectionTableOffset = optionalHeaderOffset + optionalHeaderSize;
if (!TryFindSection(fileBytes, sectionTableOffset, numSections, ".text",
out int textRva, out int textRawOffset, out int textRawSize, out int textVirtualSize))
{
throw new InvalidDataException(".text section not found.");
}
int textBytesLength = Math.Max(textVirtualSize, textRawSize);
textBytesLength = Math.Min(textBytesLength, fileBytes.Length - textRawOffset);
if (textBytesLength <= 0)
throw new InvalidDataException(".text section is empty or truncated.");
byte[] textBytes = new byte[textBytesLength];
Array.Copy(fileBytes, textRawOffset, textBytes, 0, Math.Min(textRawSize, textBytesLength));
int rdataRva = 0;
byte[] rdataBytes = [];
if (TryFindSection(fileBytes, sectionTableOffset, numSections, ".rdata",
out int rRva, out int rRawOffset, out int rRawSize, out int rVirtualSize))
{
int rdataLen = Math.Max(rVirtualSize, rRawSize);
rdataLen = Math.Min(rdataLen, fileBytes.Length - rRawOffset);
if (rdataLen > 0)
{
rdataRva = rRva;
rdataBytes = new byte[rdataLen];
Array.Copy(fileBytes, rRawOffset, rdataBytes, 0, Math.Min(rRawSize, rdataLen));
}
}
string sha256 = ComputeSha256(fileBytes);
var view = new AcClientImageView(imageBase, imageSize, textRva, textBytes, rdataRva, rdataBytes);
var input = new ManifestInput
{
Path = path,
FileSizeBytes = fileBytes.Length,
Sha256 = sha256,
ImageBase = imageBase,
ImageSizeRva = imageSize,
TextRva = textRva,
Machine = MachineName(machine)
};
return new AcClientImage(view, input);
}
private static bool TryFindSection(
byte[] fileBytes, int sectionTableOffset, int numSections, string name,
out int rva, out int rawOffset, out int rawSize, out int virtualSize)
{
rva = rawOffset = rawSize = virtualSize = 0;
for (int i = 0; i < numSections; i++)
{
int sectionOffset = sectionTableOffset + i * SectionHeaderSize;
if (sectionOffset + SectionHeaderSize > fileBytes.Length)
return false;
string sectionName = ReadAsciiNullPadded(fileBytes, sectionOffset, SectionNameLength);
if (!string.Equals(sectionName, name, StringComparison.Ordinal))
continue;
virtualSize = BitConverter.ToInt32(fileBytes, sectionOffset + 0x08);
rva = BitConverter.ToInt32(fileBytes, sectionOffset + 0x0C);
rawSize = BitConverter.ToInt32(fileBytes, sectionOffset + 0x10);
rawOffset = BitConverter.ToInt32(fileBytes, sectionOffset + 0x14);
return true;
}
return false;
}
private static string ReadAsciiNullPadded(byte[] data, int offset, int length)
{
int end = offset;
while (end < offset + length && data[end] != 0) end++;
return System.Text.Encoding.ASCII.GetString(data, offset, end - offset);
}
private static string ComputeSha256(byte[] data)
{
byte[] hash = SHA256.HashData(data);
return Convert.ToHexString(hash);
}
private static string MachineName(ushort machine) => machine switch
{
0x014C => "x86",
0x8664 => "x64",
0x01C4 => "arm",
0xAA64 => "arm64",
_ => $"unknown(0x{machine:X4})"
};
}

View file

@ -0,0 +1,170 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using RynthCore.HookManifest.Scanning;
using RynthCore.HookManifest.Schema;
using RynthCore.HookResolver.Core.Disassembly;
using RynthCore.HookResolver.Core.Offline;
using RynthCore.HookResolver.Core.Symbols;
using RynthCore.HookResolver.Core.Validation;
namespace RynthCore.HookResolver.Core.Resolution;
public static class HookResolveOrchestrator
{
public static async IAsyncEnumerable<HookManifestEntry> ResolveAsync(
AcClientImage image,
IReadOnlyList<HookSymbol> symbols,
[EnumeratorCancellation] CancellationToken ct = default)
{
foreach (var symbol in symbols)
{
ct.ThrowIfCancellationRequested();
var entry = ResolveSymbol(image.View, symbol);
await Task.Yield();
yield return entry;
}
}
private static HookManifestEntry ResolveSymbol(AcClientImageView image, HookSymbol symbol)
{
var candidates = FindCandidates(image, symbol).ToList();
if (candidates.Count == 0)
{
return new HookManifestEntry
{
SymbolId = symbol.Id,
Status = ResolutionStatus.Unresolved,
PatternId = symbol.PatternId,
MatchedCandidates = 0,
Reason = "no pattern matches in .text"
};
}
var passingCandidates = new List<(int Rva, int Va, List<ValidationRecord> Validations, List<ValidationRecord> Warnings)>();
var rejectedCandidates = new List<(int Rva, int Va, List<ValidationRecord> Validations)>();
foreach (var (rva, va) in candidates)
{
var ctx = new ValidationContext(image, rva, va, symbol);
var validations = new List<ValidationRecord>();
var warnings = new List<ValidationRecord>();
bool requiredPassed = true;
foreach (var rule in symbol.RequiredRules)
{
var outcome = rule.Evaluate(ctx);
validations.Add(new ValidationRecord(outcome.RuleId, outcome.Passed, outcome.Detail));
if (!outcome.Passed) requiredPassed = false;
}
foreach (var rule in symbol.AdvisoryRules)
{
var outcome = rule.Evaluate(ctx);
var rec = new ValidationRecord(outcome.RuleId, outcome.Passed, outcome.Detail);
validations.Add(rec);
if (!outcome.Passed) warnings.Add(rec);
}
if (requiredPassed)
passingCandidates.Add((rva, va, validations, warnings));
else
rejectedCandidates.Add((rva, va, validations));
}
if (passingCandidates.Count == 1)
{
var c = passingCandidates[0];
return new HookManifestEntry
{
SymbolId = symbol.Id,
Status = ResolutionStatus.Resolved,
Address = new ResolvedAddress(c.Va, c.Rva),
PatternId = symbol.PatternId,
MatchedCandidates = candidates.Count,
ChosenCandidateReason = candidates.Count == 1 ? "single-match" : "single-passing",
Validations = c.Validations,
Warnings = c.Warnings,
Snapshot = IcedDisassembler.Snapshot(image, c.Rva)
};
}
if (passingCandidates.Count > 1)
{
if (symbol.FallbackVa is { } fb)
{
var chosen = passingCandidates.OrderBy(c => Math.Abs(c.Va - fb)).First();
return new HookManifestEntry
{
SymbolId = symbol.Id,
Status = ResolutionStatus.Resolved,
Address = new ResolvedAddress(chosen.Va, chosen.Rva),
PatternId = symbol.PatternId,
MatchedCandidates = candidates.Count,
ChosenCandidateReason = $"multi-match nearest-fallback (of {passingCandidates.Count} passing)",
Validations = chosen.Validations,
Warnings = chosen.Warnings,
Snapshot = IcedDisassembler.Snapshot(image, chosen.Rva)
};
}
var first = passingCandidates[0];
return new HookManifestEntry
{
SymbolId = symbol.Id,
Status = ResolutionStatus.Ambiguous,
Address = new ResolvedAddress(first.Va, first.Rva),
PatternId = symbol.PatternId,
MatchedCandidates = candidates.Count,
ChosenCandidateReason = "first-passing (no fallback)",
Validations = first.Validations,
Warnings = first.Warnings,
Reason = $"{passingCandidates.Count} candidates passed; no fallback VA to disambiguate",
Snapshot = IcedDisassembler.Snapshot(image, first.Rva)
};
}
var firstReject = rejectedCandidates[0];
return new HookManifestEntry
{
SymbolId = symbol.Id,
Status = ResolutionStatus.Unresolved,
PatternId = symbol.PatternId,
MatchedCandidates = candidates.Count,
Validations = firstReject.Validations,
Reason = $"{candidates.Count} pattern hits, none passed required rules"
};
}
private static IEnumerable<(int Rva, int Va)> FindCandidates(AcClientImageView image, HookSymbol symbol)
{
byte[] text = image.TextBytes;
int start = 0;
while (start < text.Length)
{
int hit = PatternScanner.FindPatternInRegion(text, symbol.Pattern, start, text.Length);
if (hit < 0) yield break;
int resolvedOff = hit;
if (symbol.WalkBack is { } walk)
{
int prologueOff = PatternScanner.FindPrologueBefore(text, hit, walk.Prologue, walk.MaxDistance);
if (prologueOff < 0)
{
start = hit + 1;
continue;
}
resolvedOff = prologueOff;
}
int rva = image.TextRva + resolvedOff;
int va = image.ImageBase + rva;
yield return (rva, va);
start = hit + 1;
}
}
}

View file

@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using RynthCore.HookManifest.Schema;
using Manifest = RynthCore.HookManifest.Schema.HookManifest;
namespace RynthCore.HookResolver.Core.Resolution;
public static class ManifestBuilder
{
public const string GeneratorName = "RynthCore.HookResolver 0.1.0";
public static Manifest Compose(
ManifestInput input,
IEnumerable<HookManifestEntry> entries,
IReadOnlyDictionary<string, string>? labels = null)
{
var dict = new Dictionary<string, HookManifestEntry>();
foreach (var e in entries)
dict[e.SymbolId] = e;
return new Manifest
{
Generator = GeneratorName,
GeneratedAtUtc = DateTime.UtcNow,
Input = input,
Labels = labels ?? new Dictionary<string, string>(),
Symbols = dict
};
}
public static async Task WriteAsync(Manifest manifest, string path, CancellationToken ct = default)
{
string? dir = Path.GetDirectoryName(path);
if (!string.IsNullOrEmpty(dir))
Directory.CreateDirectory(dir);
byte[] bytes = JsonSerializer.SerializeToUtf8Bytes(
manifest, HookManifestJsonContext.Default.HookManifest);
await File.WriteAllBytesAsync(path, bytes, ct).ConfigureAwait(false);
}
}

View file

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0-windows</TargetFramework>
<PlatformTarget>AnyCPU</PlatformTarget>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>RynthCore.HookResolver.Core</RootNamespace>
<AssemblyName>RynthCore.HookResolver.Core</AssemblyName>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Iced" Version="1.21.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\RynthCore.HookManifest\RynthCore.HookManifest.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,554 @@
using System.Collections.Generic;
using RynthCore.HookResolver.Core.Validation;
using RynthCore.HookResolver.Core.Validation.Rules;
namespace RynthCore.HookResolver.Core.Symbols;
public static class AllSymbols
{
// Shared prologue used by all CombatActionHooks dispatch wrappers
// (small functions: sub esp,0xC; push ebx; push esi; push edi; call rel32).
private static readonly byte[] CombatActionPrologue = [0x83, 0xEC, 0x0C, 0x53, 0x56, 0x57, 0xE8];
// The three helper functions every CombatActionHooks wrapper CALLs,
// verified empirically across all 7 siblings (incl. CastSpell @0x006A3E60)
// in the SHA-keyed manifest. A candidate that doesn't call all three is
// NOT a combat-action wrapper — this is what rejects a bad walk-back.
private static readonly int[] CombatDispatchers = [0x005473A0, 0x005DF0F0, 0x006B4010];
private static IReadOnlyList<IValidationRule> CombatCallCheck { get; } =
[new CallTargetsRule(CombatDispatchers, minMatches: 3)];
public static IReadOnlyList<HookSymbol> Default { get; } =
[
new HookSymbol
{
Id = "MultiClientHooks.Client::IsAlreadyRunning",
PatternId = "iar-v1",
FallbackVa = 0x004122A0,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x56, 0x68, 0x30, 0x58, 0x79, 0x00, 0x6A, 0x01,
0x6A, 0x00, 0x6A, 0x00, 0x8B, 0xF1, 0xFF, 0x15
]
},
new HookSymbol
{
Id = "MultiClientHooks.CLBlockAllocator::OpenDataFile",
PatternId = "openDataFile-v1",
FallbackVa = 0x00675920,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x8B, 0x44, 0x24, 0x10, 0x53, 0x55, 0x8B, 0x6C,
0x24, 0x0C, 0x56, 0x57, 0x8B, 0xF1, 0x50, 0x8B,
0xC8, 0x8B, 0x44, 0x24, 0x20, 0x6A, 0x00, 0x80,
0xE1, 0x02, 0x80, 0xF9, 0x02, 0x50, 0x6A, 0x00
]
},
new HookSymbol
{
Id = "BusyCountHooks.IncrementBusyCount",
PatternId = "busy-inc-v1",
FallbackVa = 0x00565610,
Anchor = SymbolAnchor.AnchorOnBody,
Pattern =
[
0x8B, 0x51, 0x14, 0x42, 0x8B, 0xC2, 0x83, 0xF8,
0x01, 0x89, 0x51, 0x14, 0x75, 0x05, 0xE9, null,
null, null, null, 0xC3
]
},
new HookSymbol
{
Id = "BusyCountHooks.DecrementBusyCount",
PatternId = "busy-dec-v1",
FallbackVa = 0x00565630,
Anchor = SymbolAnchor.AnchorOnBody,
Pattern =
[
0xFF, 0x49, 0x14, 0x75, 0x05, 0xE9, null, null,
null, null, 0xC3
]
},
new HookSymbol
{
Id = "BusyCountHooks.UpdateCursorState",
PatternId = "busy-cursor-v1",
FallbackVa = 0x005653D0,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x83, 0xEC, 0x08, 0x53, 0x55, 0x56, 0x57, 0x89,
0x4C, 0x24, 0x10, 0xE8, null, null, null, null,
0x85, 0xC0, 0x0F, 0x95, 0xC3, 0x33, 0xC0, 0x84, 0xDB
]
},
new HookSymbol
{
Id = "CombatModeHooks.SetCombatMode",
PatternId = "combatmode-v1",
FallbackVa = 0x0056CB80,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x51, 0x53, 0x56, 0x8B, 0xF1, 0x8B, 0x46, 0x1C,
0x57, 0x8B, 0x7C, 0x24, 0x14, 0x3B, 0xF8, 0x8B,
0xD8, 0x0F, 0x84, 0xEA, 0x01, 0x00, 0x00, 0x8A,
0x44, 0x24, 0x18, 0x84, 0xC0
]
},
new HookSymbol
{
Id = "LogoutLifecycle.ExecuteLogOff",
PatternId = "logout-exec-v1",
FallbackVa = 0x0055E4A0,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x53, 0x56, 0x8B, 0xF1, 0x33, 0xDB, 0x88, 0x9E,
0x13, 0x02, 0x00, 0x00, 0x88, 0x9E, 0x21, 0x02,
0x00, 0x00, 0x8B, 0x0D, null, null, null, null,
0xA1, null, null, null, null, 0x89, 0x86, 0x00,
0x02, 0x00, 0x00
]
},
new HookSymbol
{
Id = "LogoutLifecycle.RecvNotice_Logoff",
PatternId = "logout-recv-v1",
FallbackVa = 0x004ECBA0,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x81, 0xEC, 0x90, 0x00, 0x00, 0x00, 0x56, 0x8B,
0xF1, 0xB0, 0x01, 0x8D, 0x4C, 0x24, 0x04, 0x88,
0x46, 0x2D, 0x88, 0x46, 0x2E, 0xE8, null, null,
null, null, 0xA1, null, null, null, null, 0x68,
0x01, 0x00, 0x00, 0x10
]
},
new HookSymbol
{
Id = "DoMotionHooks.DoMotion",
PatternId = "domotion-v1",
FallbackVa = 0x00510AF0,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x83, 0xEC, 0x64, 0x56, 0x8B, 0xF1, 0x8B, 0x8E,
0xC4, 0x00, 0x00, 0x00, 0x33, 0xC0, 0x3B, 0xC8,
0xC7, 0x86, 0xCC, 0x00, 0x00, 0x00, 0x01, 0x00,
0x00, 0x00, 0x75, 0x0C
]
},
new HookSymbol
{
Id = "AccountHooks.SendNotice_WorldName",
PatternId = "account-worldname-v1",
FallbackVa = 0x00693A60,
Anchor = SymbolAnchor.AnchorOnBody,
Pattern =
[
0xE8, null, null, null, null, 0x8B, 0x10, 0x68,
0xA2, 0x86, 0x01, 0x00, 0x8B, 0xC8, 0xFF, 0x52,
0x10, 0x85, 0xC0, 0x74, 0x22, 0x56, 0x8B, 0x70, 0x04
]
},
new HookSymbol
{
Id = "PowerbarHooks.UIElement::SetVisible",
PatternId = "uielement-setvisible-v1",
FallbackVa = 0x00462390,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x51, 0x53, 0x56, 0x57, 0x8B, 0x3D, null, null,
null, null, 0x8B, 0xF1, 0xE8, null, null, null,
null, 0x8B, 0x9E, 0xA4, 0x00, 0x00, 0x00, 0x88,
0x44, 0x24, 0x0F
]
},
new HookSymbol
{
Id = "PowerbarHooks.Begin",
PatternId = "powerbar-begin-v1",
FallbackVa = 0x004DB390,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x83, 0xEC, 0x10, 0x55, 0x8B, 0x6C, 0x24, 0x18,
0x56, 0x8D, 0x45, 0xFF, 0x83, 0xF8, 0x03, 0x57,
0x8B, 0xF1, 0x0F, 0x87, 0xBC, 0x00, 0x00, 0x00,
0xFF, 0x24, 0x85, null, null, null, null
]
},
new HookSymbol
{
Id = "PowerbarHooks.Level",
PatternId = "powerbar-level-v1",
FallbackVa = 0x004DB1B0,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x8B, 0x44, 0x24, 0x04, 0x3B, 0x41, 0x04, 0x75,
0x23, 0x68, 0x34, 0x00, 0x00, 0x10, 0x81, 0xC1,
0x08, 0xFA, 0xFF, 0xFF, 0xE8, null, null, null,
null, 0x85, 0xC0, 0x74, 0x0F
]
},
new HookSymbol
{
Id = "PowerbarHooks.Finish",
PatternId = "powerbar-finish-v1",
FallbackVa = 0x004DB1E0,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x8B, 0x44, 0x24, 0x04, 0x3B, 0x41, 0x04, 0x75,
0x33, 0x56, 0x8D, 0xB1, 0x08, 0xFA, 0xFF, 0xFF,
0xC7, 0x41, 0x04, 0x00, 0x00, 0x00, 0x00, 0x68,
0x34, 0x00, 0x00, 0x10, 0x8B, 0xCE, 0xE8, null,
null, null, null
]
},
new HookSymbol
{
Id = "ChatHooks.UIElement::SetVisible",
PatternId = "uielement-setvisible-v1",
FallbackVa = 0x00462390,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x51, 0x53, 0x56, 0x57, 0x8B, 0x3D, null, null,
null, null, 0x8B, 0xF1, 0xE8, null, null, null,
null, 0x8B, 0x9E, 0xA4, 0x00, 0x00, 0x00, 0x88,
0x44, 0x24, 0x0F
]
},
new HookSymbol
{
Id = "ChatHooks.ListenToElementMessage",
PatternId = "chat-listen-v1",
FallbackVa = 0x004CE6F0,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x56, 0x8B, 0x74, 0x24, 0x08, 0x8B, 0x46, 0x08,
0x48, 0x57, 0x8B, 0xF9, 0x74, 0x72, 0x83, 0xE8,
0x06, 0x75, 0x7D, 0x8B, 0x4E, 0x04, 0x8B, 0x01,
0x6A, 0x06, 0xFF, 0x90, 0x94, 0x00, 0x00, 0x00
]
},
new HookSymbol
{
Id = "RadarHooks.UIElement::SetVisible",
PatternId = "uielement-setvisible-v1",
FallbackVa = 0x00462390,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x51, 0x53, 0x56, 0x57, 0x8B, 0x3D, null, null,
null, null, 0x8B, 0xF1, 0xE8, null, null, null,
null, 0x8B, 0x9E, 0xA4, 0x00, 0x00, 0x00, 0x88,
0x44, 0x24, 0x0F
]
},
new HookSymbol
{
Id = "RadarHooks.UIElement::GetSurfaceBox",
PatternId = "uielement-surfacebox-v1",
FallbackVa = 0x00462220,
Anchor = SymbolAnchor.AnchorOnBody,
Pattern =
[
0xF6, 0x81, 0x56, 0x05, 0x00, 0x00, 0x01, 0x74,
0x11, 0x56, 0x8B, 0x74, 0x24, 0x08, 0x56, 0xE8,
null, null, null, null, 0x8B, 0xC6, 0x5E, 0xC2,
0x04, 0x00
]
},
new HookSymbol
{
Id = "RadarHooks.DrawObjects",
PatternId = "radar-drawobjects-v1",
FallbackVa = 0x004D9FE0,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x81, 0xEC, 0xDC, 0x00, 0x00, 0x00, 0x53, 0x55,
0x56, 0x8B, 0xF1, 0xD9, 0x86, 0x00, 0x06, 0x00,
0x00, 0x8B, 0x86, 0x0C, 0x06, 0x00, 0x00, 0xD8,
0x25, null, null, null, null, 0x33, 0xDB, 0x3B, 0xC3
]
},
new HookSymbol
{
Id = "RadarHooks.DrawChildren",
PatternId = "radar-drawchildren-v1",
FallbackVa = 0x004DA380,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x8B, 0x44, 0x24, 0x0C, 0x8B, 0x54, 0x24, 0x04,
0x53, 0x55, 0x56, 0x8B, 0x74, 0x24, 0x1C, 0x57,
0x56, 0x8B, 0xF9, 0x8B, 0x4C, 0x24, 0x1C, 0x50,
0x51, 0x52, 0x8B, 0xCF, 0xE8, null, null, null,
null, 0x56
]
},
// ── Hooks NOT routed through HookResolver.Resolve. The engine still finds
// these via PatternScanner.FindPattern + FindPrologueBefore (or
// pattern-or-fixed-VA verify). Engine VA column will show "—" for all
// of these because they don't emit HookResolver[...] log lines.
new HookSymbol
{
Id = "LoginLifecycle.SendLoginCompleteNotification",
PatternId = "loginComplete-v1",
Anchor = SymbolAnchor.AnchorOnCallSite,
Pattern =
[
0x6A, 0x01, 0xC6, 0x86, null, null, null, null,
0x01, 0xE8, null, null, null, null, 0x8B, 0x0D,
null, null, null, null, 0x83, 0xC4, 0x04, 0x6A,
0x00, 0x6A, 0x0B, 0xE8
],
WalkBack = new PrologueWalkBack([0x56, 0x8B, 0xF1], MaxDistance: 0x100)
},
new HookSymbol
{
Id = "SmartBoxHooks.DispatchSmartBoxEvent",
PatternId = "smartbox-dispatch-v1",
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x83, 0xEC, 0x08, 0x53, 0x8B, 0x5C, 0x24, 0x10,
0x8B, 0x53, 0x30, 0x83, 0xFA, 0x04, 0x8B, 0x43,
0x2C, 0x56, 0x8B, 0xF1, 0x89, 0x44, 0x24, 0x14,
0x89, 0x54, 0x24, 0x08, 0x72, null, 0x8B, 0x08
]
},
new HookSymbol
{
Id = "SmartBoxHooks.DispatchGameEvent",
PatternId = "smartbox-dispatch-v1",
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x83, 0xEC, 0x08, 0x53, 0x8B, 0x5C, 0x24, 0x10,
0x8B, 0x53, 0x30, 0x83, 0xFA, 0x04, 0x8B, 0x43,
0x2C, 0x56, 0x8B, 0xF1, 0x89, 0x44, 0x24, 0x14,
0x89, 0x54, 0x24, 0x08, 0x72, null, 0x8B, 0x08
]
},
new HookSymbol
{
Id = "UiLifecycleHooks.SetUIReady",
PatternId = "setUIReady-v1",
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x56, 0x8B, 0x74, 0x24, 0x08, 0x85, 0xF6, 0x75,
0x16, 0x8B, 0x0D, null, null, null, null, 0x85,
0xC9, 0x74, 0x0C, 0x8B, 0x41, 0x04, 0x85, 0xC0,
0x74, 0x05, 0xE8, null, null, null, null, 0x89,
0x35, null, null, null, null, 0x5E, 0xC3
]
},
// ── MovementActionHooks: tiny `mov [edx], ACTION_CODE` wrappers. Each
// pattern is the unique action-code write; walk back to the shared
// 7-byte combat-family prologue (sub esp,0xC; push regs; call).
new HookSymbol
{
Id = "MovementActionHooks.StopMovement",
PatternId = "movement-stop-v1",
Anchor = SymbolAnchor.AnchorOnBody,
Pattern = [0xC7, 0x02, 0x61, 0xF6, 0x00, 0x00],
WalkBack = new PrologueWalkBack(CombatActionPrologue, MaxDistance: 300)
},
new HookSymbol
{
Id = "MovementActionHooks.DoMovement",
PatternId = "movement-do-v1",
Anchor = SymbolAnchor.AnchorOnBody,
Pattern = [0xC7, 0x02, 0x1E, 0xF6, 0x00, 0x00],
WalkBack = new PrologueWalkBack(CombatActionPrologue, MaxDistance: 300)
},
new HookSymbol
{
Id = "MovementActionHooks.JumpNonAutonomous",
PatternId = "movement-jump-v1",
Anchor = SymbolAnchor.AnchorOnBody,
Pattern = [0xC7, 0x02, 0xC9, 0xF7, 0x00, 0x00],
WalkBack = new PrologueWalkBack(CombatActionPrologue, MaxDistance: 300)
},
new HookSymbol
{
Id = "MovementActionHooks.SetAutonomyLevel",
PatternId = "movement-autonomy-v1",
Anchor = SymbolAnchor.AnchorOnBody,
Pattern = [0xC7, 0x02, 0x52, 0xF7, 0x00, 0x00],
WalkBack = new PrologueWalkBack(CombatActionPrologue, MaxDistance: 300)
},
// ── CombatActionHooks: same wrapper shape as Movement. CastSpell is
// known-fragile (engine has it disabled); the snapshot will tell us
// if the walk-back lands on a sane function.
new HookSymbol
{
Id = "CombatActionHooks.CancelAttack",
PatternId = "combat-cancel-v1",
Anchor = SymbolAnchor.AnchorOnBody,
Pattern = [0xC7, 0x02, 0xB7, 0x01, 0x00, 0x00],
WalkBack = new PrologueWalkBack(CombatActionPrologue, MaxDistance: 300),
AdvisoryRules = CombatCallCheck
},
new HookSymbol
{
Id = "CombatActionHooks.ChangeCombatMode",
PatternId = "combat-change-v1",
Anchor = SymbolAnchor.AnchorOnBody,
Pattern = [0xC7, 0x02, 0x53, 0x00, 0x00, 0x00],
WalkBack = new PrologueWalkBack(CombatActionPrologue, MaxDistance: 300),
AdvisoryRules = CombatCallCheck
},
new HookSymbol
{
Id = "CombatActionHooks.QueryHealth",
PatternId = "combat-queryhealth-v1",
Anchor = SymbolAnchor.AnchorOnBody,
Pattern = [0xC7, 0x02, 0xBF, 0x01, 0x00, 0x00],
WalkBack = new PrologueWalkBack(CombatActionPrologue, MaxDistance: 300),
AdvisoryRules = CombatCallCheck
},
new HookSymbol
{
Id = "CombatActionHooks.MeleeAttack",
PatternId = "combat-melee-v1",
Anchor = SymbolAnchor.AnchorOnBody,
Pattern = [0xC7, 0x02, 0x08, 0x00, 0x00, 0x00],
WalkBack = new PrologueWalkBack(CombatActionPrologue, MaxDistance: 300),
AdvisoryRules = CombatCallCheck
},
new HookSymbol
{
Id = "CombatActionHooks.MissileAttack",
PatternId = "combat-missile-v1",
Anchor = SymbolAnchor.AnchorOnBody,
Pattern = [0xC7, 0x02, 0x0A, 0x00, 0x00, 0x00],
WalkBack = new PrologueWalkBack(CombatActionPrologue, MaxDistance: 300),
AdvisoryRules = CombatCallCheck
},
new HookSymbol
{
Id = "CombatActionHooks.RequestId",
PatternId = "combat-requestid-v1",
Anchor = SymbolAnchor.AnchorOnBody,
Pattern = [0xC7, 0x02, 0xC8, 0x00, 0x00, 0x00],
WalkBack = new PrologueWalkBack(CombatActionPrologue, MaxDistance: 300),
AdvisoryRules = CombatCallCheck
},
new HookSymbol
{
Id = "CombatActionHooks.CastSpell",
PatternId = "combat-castspell-v1",
Anchor = SymbolAnchor.AnchorOnBody,
Pattern = [0xC7, 0x02, 0x4A, 0x00, 0x00, 0x00],
WalkBack = new PrologueWalkBack(CombatActionPrologue, MaxDistance: 300),
// Required (not advisory): if the walk-back ever lands on a
// non-combat function, this flips CastSpell to Unresolved instead
// of silently emitting a wrong VA — the whole point of the tool.
RequiredRules = CombatCallCheck
},
// ── ChatCallbackHooks: hardcoded VA + signature verify in the engine.
// Tool just pattern-scans; if it resolves to the same VA the engine
// uses, the pattern is sound.
new HookSymbol
{
Id = "ChatCallbackHooks.IncomingChatAddTextToScroll",
PatternId = "chat-incoming-scroll-v1",
FallbackVa = 0x005649F0,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x81, 0xEC, 0x48, 0x09, 0x00, 0x00, 0x8A, 0x84,
0x24, 0x54, 0x09, 0x00, 0x00, 0x53, 0x55, 0x56,
0x33, 0xF6, 0x84, 0xC0, 0x57, 0x8B, 0xBC, 0x24,
0x5C, 0x09, 0x00, 0x00, 0x89, 0x4C, 0x24, 0x24
]
},
new HookSymbol
{
Id = "ChatCallbackHooks.IncomingChatWrapper",
PatternId = "chat-incoming-wrapper-v1",
FallbackVa = 0x0058A000,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0xA1, 0xE4, 0x0B, 0x87, 0x00, 0x85, 0xC0, 0x75,
0x06, 0xB8, 0x01, 0x00, 0x00, 0x00, 0xC3, 0x56,
0x8B, 0x74, 0x24, 0x10, 0x83, 0xFE, 0x01, 0x74, 0x0F
]
},
new HookSymbol
{
Id = "ChatCallbackHooks.OutgoingChat",
PatternId = "chat-outgoing-v1",
FallbackVa = 0x005821A0,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x83, 0xEC, 0x0C, 0x53, 0x55, 0x56, 0x57, 0x8B,
0xF9, 0xE8, null, null, null, null, 0x85, 0xC0,
0x8B, 0x74, 0x24, 0x20, 0x74, 0x30, 0x8B, 0x06,
0x50, 0xFF, 0x15, null, null, null, null, 0x8B,
0xD8, 0xC7, 0x44, 0x24, 0x20, 0x00, 0x00, 0x00,
0x00, 0xE8, null, null, null, null, 0x8B, 0x08,
0x8D, 0x54, 0x24, 0x20, 0x52, 0x53, 0x50, 0xFF,
0x51, 0x20, 0x8B, 0x44, 0x24, 0x20, 0x85, 0xC0,
0x0F, 0x85, null, null, null, null, 0x8B, 0x44,
0x24, 0x24, 0x6A, 0x00
]
},
new HookSymbol
{
Id = "UpdateObjectInventoryHooks.UpdateObjectInventory",
PatternId = "updateInv-v1",
FallbackVa = 0x0055A190,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x8B, 0x44, 0x24, 0x04, 0x50, 0xE8, 0x96, 0xE7,
0xFA, 0xFF, 0x8B, 0x4C, 0x24, 0x08, 0x51, 0x8D,
0x48, 0x3C, 0xE8, 0x69, 0xFF, 0xFF, 0xFF, 0xC2,
0x08, 0x00
]
},
new HookSymbol
{
Id = "SalvageHooks.OpenSalvagePanel",
PatternId = "salvage-open-v1",
FallbackVa = 0x004CBF70,
Anchor = SymbolAnchor.AnchorOnPrologue,
Pattern =
[
0x8B, 0x44, 0x24, 0x04, 0x56, 0x8B, 0xF1, 0x8B,
0x8E, 0x00, 0x06, 0x00, 0x00, 0x51, 0x8B, 0xCE,
0x89, 0x86, 0x08, 0x06, 0x00, 0x00, 0xE8, null,
null, null, null, 0x8B, 0x8E, 0x00, 0x06, 0x00,
0x00, 0xE8, null, null, null, null
]
}
];
}

View file

@ -0,0 +1,26 @@
using System.Collections.Generic;
using RynthCore.HookResolver.Core.Validation;
namespace RynthCore.HookResolver.Core.Symbols;
public enum SymbolAnchor
{
AnchorOnPrologue,
AnchorOnBody,
AnchorOnCallSite,
AnchorOnStringRef
}
public sealed record PrologueWalkBack(byte[] Prologue, int MaxDistance = 0x100);
public sealed record HookSymbol
{
public required string Id { get; init; }
public required string PatternId { get; init; }
public required byte?[] Pattern { get; init; }
public int? FallbackVa { get; init; }
public required SymbolAnchor Anchor { get; init; }
public PrologueWalkBack? WalkBack { get; init; }
public IReadOnlyList<IValidationRule> RequiredRules { get; init; } = [];
public IReadOnlyList<IValidationRule> AdvisoryRules { get; init; } = [];
}

View file

@ -0,0 +1,18 @@
using RynthCore.HookManifest.Scanning;
using RynthCore.HookResolver.Core.Symbols;
namespace RynthCore.HookResolver.Core.Validation;
public readonly record struct ValidationContext(
AcClientImageView Image,
int CandidateRva,
int CandidateVa,
HookSymbol Symbol);
public readonly record struct ValidationOutcome(bool Passed, string RuleId, string Detail);
public interface IValidationRule
{
string RuleId { get; }
ValidationOutcome Evaluate(in ValidationContext ctx);
}

View file

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RynthCore.HookResolver.Core.Disassembly;
namespace RynthCore.HookResolver.Core.Validation.Rules;
/// <summary>
/// Decodes the candidate function with Iced and asserts that at least
/// <see cref="_minMatches"/> of the <see cref="_expectedTargets"/> VAs appear
/// as CALL targets in its body. This is the rule that distinguishes a real
/// combat-action wrapper (which calls the shared dispatcher trio) from a
/// look-alike the bare pattern happened to match.
/// </summary>
public sealed class CallTargetsRule : IValidationRule
{
private readonly int[] _expectedTargets;
private readonly int _minMatches;
private readonly int _scanBytes;
public CallTargetsRule(int[] expectedTargets, int minMatches, int scanBytes = 0x400)
{
_expectedTargets = expectedTargets;
_minMatches = minMatches;
_scanBytes = scanBytes;
RuleId = "calltargets:[" +
string.Join(",", expectedTargets.Select(v => $"0x{v:X8}")) +
$"]>={minMatches}";
}
public string RuleId { get; }
public ValidationOutcome Evaluate(in ValidationContext ctx)
{
var snap = IcedDisassembler.Snapshot(ctx.Image, ctx.CandidateRva, maxBytes: _scanBytes);
var present = new HashSet<int>(snap.CallTargets.Select(c => c.Va));
var matched = _expectedTargets.Where(present.Contains).ToArray();
bool pass = matched.Length >= _minMatches;
string matchedHex = matched.Length == 0
? "none"
: string.Join(",", matched.Select(v => $"0x{v:X8}"));
return new ValidationOutcome(
pass,
RuleId,
$"{matched.Length}/{_expectedTargets.Length} expected dispatchers present " +
$"({matchedHex}); needed >= {_minMatches}");
}
}

View file

@ -0,0 +1,44 @@
using System;
using RynthCore.HookManifest.Scanning;
namespace RynthCore.HookResolver.Core.Validation.Rules;
public sealed class PrologueBytesRule : IValidationRule
{
private readonly byte?[] _expected;
public PrologueBytesRule(byte?[] expected)
{
_expected = expected;
RuleId = "prologue:" + FormatPattern(expected);
}
public string RuleId { get; }
public ValidationOutcome Evaluate(in ValidationContext ctx)
{
int offset = ctx.CandidateRva - ctx.Image.TextRva;
bool ok = PatternScanner.VerifyPattern(ctx.Image.TextBytes, offset, _expected);
if (ok)
return new ValidationOutcome(true, RuleId, "prologue matches");
int len = Math.Min(_expected.Length, ctx.Image.TextBytes.Length - offset);
string actual = "";
if (offset >= 0 && len > 0)
{
Span<byte> slice = ctx.Image.TextBytes.AsSpan(offset, len);
actual = Convert.ToHexString(slice);
}
return new ValidationOutcome(false, RuleId,
$"prologue mismatch (saw {actual}, expected {FormatPattern(_expected)})");
}
private static string FormatPattern(byte?[] pattern)
{
var sb = new System.Text.StringBuilder(pattern.Length * 2);
foreach (var b in pattern)
sb.Append(b.HasValue ? b.Value.ToString("X2") : "??");
return sb.ToString();
}
}