mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-23 16:27:44 +01:00
Compare commits
9 commits
0d533c18f8
...
a2add0369e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a2add0369e | ||
|
|
a56d2cf40b | ||
|
|
3eb65c85c0 | ||
|
|
1b76aec89f | ||
|
|
b52024d927 | ||
|
|
56b0ae80b6 | ||
|
|
0b1a697d4d | ||
|
|
05beea003c | ||
|
|
3c8cef06dd |
8 changed files with 180 additions and 23 deletions
|
|
@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||||
using Dalamud.Common;
|
using Dalamud.Common;
|
||||||
using Dalamud.Configuration.Internal;
|
using Dalamud.Configuration.Internal;
|
||||||
using Dalamud.Game;
|
using Dalamud.Game;
|
||||||
|
using Dalamud.Hooking.Internal.Verification;
|
||||||
using Dalamud.Plugin.Internal;
|
using Dalamud.Plugin.Internal;
|
||||||
using Dalamud.Storage;
|
using Dalamud.Storage;
|
||||||
using Dalamud.Utility;
|
using Dalamud.Utility;
|
||||||
|
|
@ -73,6 +74,11 @@ internal sealed unsafe class Dalamud : IServiceType
|
||||||
scanner,
|
scanner,
|
||||||
Localization.FromAssets(info.AssetDirectory!, configuration.LanguageOverride));
|
Localization.FromAssets(info.AssetDirectory!, configuration.LanguageOverride));
|
||||||
|
|
||||||
|
using (Timings.Start("HookVerifier Init"))
|
||||||
|
{
|
||||||
|
HookVerifier.Initialize(scanner);
|
||||||
|
}
|
||||||
|
|
||||||
// Set up FFXIVClientStructs
|
// Set up FFXIVClientStructs
|
||||||
this.SetupClientStructsResolver(cacheDir);
|
this.SetupClientStructsResolver(cacheDir);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ using System.Runtime.InteropServices;
|
||||||
|
|
||||||
using Dalamud.Configuration.Internal;
|
using Dalamud.Configuration.Internal;
|
||||||
using Dalamud.Hooking.Internal;
|
using Dalamud.Hooking.Internal;
|
||||||
|
using Dalamud.Hooking.Internal.Verification;
|
||||||
|
|
||||||
namespace Dalamud.Hooking;
|
namespace Dalamud.Hooking;
|
||||||
|
|
||||||
|
|
@ -230,6 +231,8 @@ public abstract class Hook<T> : IDalamudHook where T : Delegate
|
||||||
if (EnvironmentConfiguration.DalamudForceMinHook)
|
if (EnvironmentConfiguration.DalamudForceMinHook)
|
||||||
useMinHook = true;
|
useMinHook = true;
|
||||||
|
|
||||||
|
HookVerifier.Verify<T>(procAddress);
|
||||||
|
|
||||||
procAddress = HookManager.FollowJmp(procAddress);
|
procAddress = HookManager.FollowJmp(procAddress);
|
||||||
if (useMinHook)
|
if (useMinHook)
|
||||||
return new MinHookHook<T>(procAddress, detour, Assembly.GetCallingAssembly());
|
return new MinHookHook<T>(procAddress, detour, Assembly.GetCallingAssembly());
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Dalamud.Hooking.Internal.Verification;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Exception thrown when a provided delegate for a hook does not match a known delegate.
|
||||||
|
/// </summary>
|
||||||
|
public class HookVerificationException : Exception
|
||||||
|
{
|
||||||
|
private HookVerificationException(string message)
|
||||||
|
: base(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Create a new <see cref="HookVerificationException"/> exception.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="address">The address of the function that is being hooked.</param>
|
||||||
|
/// <param name="passed">The delegate passed by the user.</param>
|
||||||
|
/// <param name="enforced">The delegate we think is correct.</param>
|
||||||
|
/// <param name="message">Additional context to show to the user.</param>
|
||||||
|
/// <returns>The created exception.</returns>
|
||||||
|
internal static HookVerificationException Create(IntPtr address, Type passed, Type enforced, string message)
|
||||||
|
{
|
||||||
|
return new HookVerificationException(
|
||||||
|
$"Hook verification failed for address 0x{address.ToInt64():X}\n\n" +
|
||||||
|
$"Why: {message}\n" +
|
||||||
|
$"Passed Delegate: {GetSignature(passed)}\n" +
|
||||||
|
$"Correct Delegate: {GetSignature(enforced)}\n\n" +
|
||||||
|
"The hook delegate must exactly match the provided signature to prevent memory corruption and wrong data passed to originals.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string GetSignature(Type delegateType)
|
||||||
|
{
|
||||||
|
var method = delegateType.GetMethod("Invoke");
|
||||||
|
if (method == null) return delegateType.Name;
|
||||||
|
|
||||||
|
var parameters = string.Join(", ", method.GetParameters().Select(p => p.ParameterType.Name));
|
||||||
|
return $"{method.ReturnType.Name} ({parameters})";
|
||||||
|
}
|
||||||
|
}
|
||||||
107
Dalamud/Hooking/Internal/Verification/HookVerifier.cs
Normal file
107
Dalamud/Hooking/Internal/Verification/HookVerifier.cs
Normal file
|
|
@ -0,0 +1,107 @@
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
using Dalamud.Game;
|
||||||
|
using Dalamud.Logging.Internal;
|
||||||
|
|
||||||
|
namespace Dalamud.Hooking.Internal.Verification;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Global utility that can verify whether hook delegates are correctly declared.
|
||||||
|
/// Initialized out-of-band, since Hook is instantiated all over the place without a service, so this cannot be
|
||||||
|
/// a service either.
|
||||||
|
/// </summary>
|
||||||
|
internal static class HookVerifier
|
||||||
|
{
|
||||||
|
private static readonly ModuleLog Log = new("HookVerifier");
|
||||||
|
|
||||||
|
private static readonly VerificationEntry[] ToVerify =
|
||||||
|
[
|
||||||
|
new(
|
||||||
|
"ActorControlSelf",
|
||||||
|
"E8 ?? ?? ?? ?? 0F B7 0B 83 E9 64",
|
||||||
|
typeof(ActorControlSelfDelegate),
|
||||||
|
"Signature changed in Patch 7.4") // 7.4 (new parameters)
|
||||||
|
];
|
||||||
|
|
||||||
|
private delegate void ActorControlSelfDelegate(uint category, uint eventId, uint param1, uint param2, uint param3, uint param4, uint param5, uint param6, uint param7, uint param8, ulong targetId, byte param9);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="HookVerifier"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="scanner">Process to scan in.</param>
|
||||||
|
public static void Initialize(TargetSigScanner scanner)
|
||||||
|
{
|
||||||
|
foreach (var entry in ToVerify)
|
||||||
|
{
|
||||||
|
if (!scanner.TryScanText(entry.Signature, out var address))
|
||||||
|
{
|
||||||
|
Log.Error("Could not resolve signature for hook {Name} ({Sig})", entry.Name, entry.Signature);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.Address = address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Verify the hook with the provided address and exception.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="address">The address of the function we are hooking.</param>
|
||||||
|
/// <typeparam name="T">The delegate type passed by the creator of the hook.</typeparam>
|
||||||
|
/// <exception cref="HookVerificationException">Exception thrown when we think the hook is not correctly declared.</exception>
|
||||||
|
public static void Verify<T>(IntPtr address) where T : Delegate
|
||||||
|
{
|
||||||
|
var entry = ToVerify.FirstOrDefault(x => x.Address == address);
|
||||||
|
|
||||||
|
// Nothing to verify for this hook?
|
||||||
|
if (entry == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var passedType = typeof(T);
|
||||||
|
|
||||||
|
// Directly compare delegates
|
||||||
|
if (passedType == entry.TargetDelegateType)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var passedInvoke = passedType.GetMethod("Invoke")!;
|
||||||
|
var enforcedInvoke = entry.TargetDelegateType.GetMethod("Invoke")!;
|
||||||
|
|
||||||
|
// Compare Return Type
|
||||||
|
var mismatch = passedInvoke.ReturnType != enforcedInvoke.ReturnType;
|
||||||
|
|
||||||
|
// Compare Parameter Count
|
||||||
|
var passedParams = passedInvoke.GetParameters();
|
||||||
|
var enforcedParams = enforcedInvoke.GetParameters();
|
||||||
|
|
||||||
|
if (passedParams.Length != enforcedParams.Length)
|
||||||
|
{
|
||||||
|
mismatch = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Compare Parameter Types
|
||||||
|
for (var i = 0; i < passedParams.Length; i++)
|
||||||
|
{
|
||||||
|
if (passedParams[i].ParameterType != enforcedParams[i].ParameterType)
|
||||||
|
{
|
||||||
|
mismatch = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mismatch)
|
||||||
|
{
|
||||||
|
throw HookVerificationException.Create(address, passedType, entry.TargetDelegateType, entry.Message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private record VerificationEntry(string Name, string Signature, Type TargetDelegateType, string Message)
|
||||||
|
{
|
||||||
|
public nint Address { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -420,13 +420,13 @@ internal unsafe class UiDebug
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
Service<SeStringRenderer>.Get().Draw(textInputComponent->AtkComponentInputBase.RawString);
|
Service<SeStringRenderer>.Get().Draw(textInputComponent->AtkComponentInputBase.RawString);
|
||||||
|
|
||||||
ImGui.Text("Text1: "u8);
|
// ImGui.Text("Text1: "u8);
|
||||||
ImGui.SameLine();
|
// ImGui.SameLine();
|
||||||
Service<SeStringRenderer>.Get().Draw(textInputComponent->UnkText01);
|
// Service<SeStringRenderer>.Get().Draw(textInputComponent->UnkText01);
|
||||||
|
//
|
||||||
ImGui.Text("Text2: "u8);
|
// ImGui.Text("Text2: "u8);
|
||||||
ImGui.SameLine();
|
// ImGui.SameLine();
|
||||||
Service<SeStringRenderer>.Get().Draw(textInputComponent->UnkText02);
|
// Service<SeStringRenderer>.Get().Draw(textInputComponent->UnkText02);
|
||||||
|
|
||||||
ImGui.Text("AvailableLines: "u8);
|
ImGui.Text("AvailableLines: "u8);
|
||||||
ImGui.SameLine();
|
ImGui.SameLine();
|
||||||
|
|
|
||||||
|
|
@ -89,20 +89,14 @@ internal unsafe class ComponentNodeTree : ResNodeTree
|
||||||
{
|
{
|
||||||
case TextInput:
|
case TextInput:
|
||||||
var textInputComponent = (AtkComponentTextInput*)this.Component;
|
var textInputComponent = (AtkComponentTextInput*)this.Component;
|
||||||
ImGui.Text(
|
ImGui.Text($"InputBase Text1: {Marshal.PtrToStringAnsi(new(textInputComponent->AtkComponentInputBase.EvaluatedString.StringPtr))}");
|
||||||
$"InputBase Text1: {Marshal.PtrToStringAnsi(new(textInputComponent->AtkComponentInputBase.EvaluatedString.StringPtr))}");
|
ImGui.Text($"InputBase Text2: {Marshal.PtrToStringAnsi(new(textInputComponent->AtkComponentInputBase.RawString.StringPtr))}");
|
||||||
ImGui.Text(
|
// TODO: Reenable when unknowns have been unprivated / named
|
||||||
$"InputBase Text2: {Marshal.PtrToStringAnsi(new(textInputComponent->AtkComponentInputBase.RawString.StringPtr))}");
|
// ImGui.Text($"Text1: {Marshal.PtrToStringAnsi(new(textInputComponent->UnkText01.StringPtr))}");
|
||||||
ImGui.Text(
|
// ImGui.Text($"Text2: {Marshal.PtrToStringAnsi(new(textInputComponent->UnkText02.StringPtr))}");
|
||||||
$"Text1: {Marshal.PtrToStringAnsi(new(textInputComponent->UnkText01.StringPtr))}");
|
ImGui.Text($"AvailableLines: {Marshal.PtrToStringAnsi(new(textInputComponent->AvailableLines.StringPtr))}");
|
||||||
ImGui.Text(
|
ImGui.Text($"HighlightedAutoTranslateOptionColorPrefix: {Marshal.PtrToStringAnsi(new(textInputComponent->HighlightedAutoTranslateOptionColorPrefix.StringPtr))}");
|
||||||
$"Text2: {Marshal.PtrToStringAnsi(new(textInputComponent->UnkText02.StringPtr))}");
|
ImGui.Text($"HighlightedAutoTranslateOptionColorSuffix: {Marshal.PtrToStringAnsi(new(textInputComponent->HighlightedAutoTranslateOptionColorSuffix.StringPtr))}");
|
||||||
ImGui.Text(
|
|
||||||
$"AvailableLines: {Marshal.PtrToStringAnsi(new(textInputComponent->AvailableLines.StringPtr))}");
|
|
||||||
ImGui.Text(
|
|
||||||
$"HighlightedAutoTranslateOptionColorPrefix: {Marshal.PtrToStringAnsi(new(textInputComponent->HighlightedAutoTranslateOptionColorPrefix.StringPtr))}");
|
|
||||||
ImGui.Text(
|
|
||||||
$"HighlightedAutoTranslateOptionColorSuffix: {Marshal.PtrToStringAnsi(new(textInputComponent->HighlightedAutoTranslateOptionColorSuffix.StringPtr))}");
|
|
||||||
break;
|
break;
|
||||||
case List:
|
case List:
|
||||||
case TreeList:
|
case TreeList:
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using System.Runtime.CompilerServices;
|
||||||
using Dalamud.Data;
|
using Dalamud.Data;
|
||||||
using Dalamud.Game;
|
using Dalamud.Game;
|
||||||
using Dalamud.Game.Text;
|
using Dalamud.Game.Text;
|
||||||
|
|
||||||
using Lumina.Excel.Sheets;
|
using Lumina.Excel.Sheets;
|
||||||
using Lumina.Text;
|
using Lumina.Text;
|
||||||
using Lumina.Text.ReadOnly;
|
using Lumina.Text.ReadOnly;
|
||||||
|
|
@ -125,10 +126,15 @@ public static class ItemUtil
|
||||||
|
|
||||||
if (IsEventItem(itemId))
|
if (IsEventItem(itemId))
|
||||||
{
|
{
|
||||||
|
// Only English, German, and French have a Name field.
|
||||||
|
// For other languages, the Name is an empty string, and the Singular field should be used instead.
|
||||||
|
language ??= dataManager.Language;
|
||||||
|
var useSingular = language is not (ClientLanguage.English or ClientLanguage.German or ClientLanguage.French);
|
||||||
|
|
||||||
return dataManager
|
return dataManager
|
||||||
.GetExcelSheet<EventItem>(language)
|
.GetExcelSheet<EventItem>(language)
|
||||||
.TryGetRow(itemId, out var eventItem)
|
.TryGetRow(itemId, out var eventItem)
|
||||||
? eventItem.Name
|
? (useSingular ? eventItem.Singular : eventItem.Name)
|
||||||
: default;
|
: default;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit df206b5f61855e3ba73f93fd57bc07056698ac4a
|
Subproject commit b309d1ee1f5445678a9ffffc51555a3a089f72d8
|
||||||
Loading…
Add table
Add a link
Reference in a new issue