mirror of
https://github.com/xivdev/Penumbra.git
synced 2025-12-15 05:04:15 +01:00
Cleanup.
This commit is contained in:
parent
528e3226b5
commit
df33557477
2 changed files with 11 additions and 13 deletions
|
|
@ -1 +1 @@
|
||||||
Subproject commit f4c6144ca2012b279e6d8aa52b2bef6cc2ba32d9
|
Subproject commit 86249598afb71601b247f9629d9c29dbecfe6eb1
|
||||||
|
|
@ -11,10 +11,10 @@ public sealed class PapRewriter(PapRewriter.PapResourceHandlerPrototype papResou
|
||||||
{
|
{
|
||||||
public unsafe delegate int PapResourceHandlerPrototype(void* self, byte* path, int length);
|
public unsafe delegate int PapResourceHandlerPrototype(void* self, byte* path, int length);
|
||||||
|
|
||||||
private readonly PeSigScanner _scanner = new();
|
private readonly PeSigScanner _scanner = new();
|
||||||
private readonly Dictionary<nint, AsmHook> _hooks = [];
|
private readonly Dictionary<nint, AsmHook> _hooks = [];
|
||||||
private readonly Dictionary<(nint, Register, ulong), nint> _nativeAllocPaths = [];
|
private readonly Dictionary<(nint, Register, ulong), nint> _nativeAllocPaths = [];
|
||||||
private readonly List<nint> _nativeAllocCaves = [];
|
private readonly List<nint> _nativeAllocCaves = [];
|
||||||
|
|
||||||
public void Rewrite(string sig, string name)
|
public void Rewrite(string sig, string name)
|
||||||
{
|
{
|
||||||
|
|
@ -26,13 +26,13 @@ public sealed class PapRewriter(PapRewriter.PapResourceHandlerPrototype papResou
|
||||||
|
|
||||||
foreach (var hookPoint in hookPoints)
|
foreach (var hookPoint in hookPoints)
|
||||||
{
|
{
|
||||||
var stackAccesses = ScanStackAccesses(funcInstructions, hookPoint).ToList();
|
var stackAccesses = ScanStackAccesses(funcInstructions, hookPoint).ToList();
|
||||||
var stringAllocation = NativeAllocPath(
|
var stringAllocation = NativeAllocPath(
|
||||||
address, hookPoint.MemoryBase, hookPoint.MemoryDisplacement64,
|
address, hookPoint.MemoryBase, hookPoint.MemoryDisplacement64,
|
||||||
Utf8GamePath.MaxGamePathLength
|
Utf8GamePath.MaxGamePathLength
|
||||||
);
|
);
|
||||||
WriteToAlloc(stringAllocation, Utf8GamePath.MaxGamePathLength, name);
|
WriteToAlloc(stringAllocation, Utf8GamePath.MaxGamePathLength, name);
|
||||||
|
|
||||||
// We'll need to grab our true hook point; the location where we can change the path at our leisure.
|
// We'll need to grab our true hook point; the location where we can change the path at our leisure.
|
||||||
// This is going to be the first call instruction after our 'hookPoint', so, we'll find that.
|
// This is going to be the first call instruction after our 'hookPoint', so, we'll find that.
|
||||||
// Pretty scuffed, this might need a refactoring at some point.
|
// Pretty scuffed, this might need a refactoring at some point.
|
||||||
|
|
@ -150,7 +150,7 @@ public sealed class PapRewriter(PapRewriter.PapResourceHandlerPrototype papResou
|
||||||
|
|
||||||
return caveLoc;
|
return caveLoc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is a bit conked but, if we identify a path by:
|
// This is a bit conked but, if we identify a path by:
|
||||||
// 1) The function it belongs to (starting address, 'funcAddress')
|
// 1) The function it belongs to (starting address, 'funcAddress')
|
||||||
// 2) The stack register (not strictly necessary - should always be rbp - but abundance of caution, so I don't hit myself in the future)
|
// 2) The stack register (not strictly necessary - should always be rbp - but abundance of caution, so I don't hit myself in the future)
|
||||||
|
|
@ -158,9 +158,7 @@ public sealed class PapRewriter(PapRewriter.PapResourceHandlerPrototype papResou
|
||||||
// Then we ensure we have a unique identifier for the specific variable location of that specific function
|
// Then we ensure we have a unique identifier for the specific variable location of that specific function
|
||||||
// This is useful because sometimes the stack address is reused within the same function for different GetResourceAsync calls
|
// This is useful because sometimes the stack address is reused within the same function for different GetResourceAsync calls
|
||||||
private unsafe nint NativeAllocPath(nint funcAddress, Register stackRegister, ulong stackDisplacement, nuint size)
|
private unsafe nint NativeAllocPath(nint funcAddress, Register stackRegister, ulong stackDisplacement, nuint size)
|
||||||
{
|
=> _nativeAllocPaths.GetOrAdd((funcAddress, stackRegister, stackDisplacement), _ => (nint)NativeMemory.Alloc(size));
|
||||||
return _nativeAllocPaths.GetOrAdd((funcAddress, stackRegister, stackDisplacement), _ => (nint)NativeMemory.Alloc(size));
|
|
||||||
}
|
|
||||||
|
|
||||||
private static unsafe void NativeFree(nint mem)
|
private static unsafe void NativeFree(nint mem)
|
||||||
=> NativeMemory.Free((void*)mem);
|
=> NativeMemory.Free((void*)mem);
|
||||||
|
|
@ -181,7 +179,7 @@ public sealed class PapRewriter(PapRewriter.PapResourceHandlerPrototype papResou
|
||||||
NativeFree(mem);
|
NativeFree(mem);
|
||||||
|
|
||||||
_nativeAllocCaves.Clear();
|
_nativeAllocCaves.Clear();
|
||||||
|
|
||||||
foreach (var mem in _nativeAllocPaths.Values)
|
foreach (var mem in _nativeAllocPaths.Values)
|
||||||
NativeFree(mem);
|
NativeFree(mem);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue