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:
parent
ac0d743e16
commit
4ddbb52eb2
244 changed files with 59710 additions and 3067 deletions
18
tools/HookResolver.Core/Validation/IValidationRule.cs
Normal file
18
tools/HookResolver.Core/Validation/IValidationRule.cs
Normal 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);
|
||||
}
|
||||
51
tools/HookResolver.Core/Validation/Rules/CallTargetsRule.cs
Normal file
51
tools/HookResolver.Core/Validation/Rules/CallTargetsRule.cs
Normal 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}");
|
||||
}
|
||||
}
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue