Compare commits
24 Commits
clr-fix-at
...
2.0.2.81-D
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
172288c755 | ||
|
|
1c17be53d0 | ||
| 68b4863f52 | |||
|
|
e8f598e695 | ||
|
|
861a337029 | ||
| 06f89955d3 | |||
|
|
c7a2b679f2 | ||
|
|
bec69074a5 | ||
|
|
ac711d9a43 | ||
|
|
b875e0c3a1 | ||
|
|
46e76bbfe6 | ||
|
|
3654365f2a | ||
|
|
9b256dd185 | ||
|
|
223ade39cb | ||
|
|
5aca9e70b2 | ||
|
|
92772cf334 | ||
|
|
0395e81a9f | ||
|
|
7734a7bf7e | ||
|
|
db2d19bb1e | ||
|
|
ab305a249c | ||
|
|
9d104a9dd8 | ||
|
|
bcd3bd5ca2 | ||
|
|
c1829a9837 | ||
|
|
cca23f6e05 |
@@ -3,7 +3,7 @@
|
|||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Authors></Authors>
|
<Authors></Authors>
|
||||||
<Company></Company>
|
<Company></Company>
|
||||||
<Version>2.0.3</Version>
|
<Version>2.0.2.81</Version>
|
||||||
<Description></Description>
|
<Description></Description>
|
||||||
<Copyright></Copyright>
|
<Copyright></Copyright>
|
||||||
<PackageProjectUrl>https://github.com/Light-Public-Syncshells/LightlessClient</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/Light-Public-Syncshells/LightlessClient</PackageProjectUrl>
|
||||||
|
|||||||
@@ -127,7 +127,7 @@ public class PlayerDataFactory
|
|||||||
{
|
{
|
||||||
nint basePtr = playerPointer;
|
nint basePtr = playerPointer;
|
||||||
|
|
||||||
if (!PtrGuard.LooksLikePtr(basePtr, _dalamudUtil.IsWine))
|
if (!PtrGuard.LooksLikePtr(basePtr))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
nint drawObjAddr = basePtr + _drawObjectOffset;
|
nint drawObjAddr = basePtr + _drawObjectOffset;
|
||||||
@@ -135,10 +135,10 @@ public class PlayerDataFactory
|
|||||||
if (!PtrGuard.IsReadable(drawObjAddr, (nuint)IntPtr.Size))
|
if (!PtrGuard.IsReadable(drawObjAddr, (nuint)IntPtr.Size))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (!PtrGuard.TryReadIntPtr(drawObjAddr, _dalamudUtil.IsWine, out var drawObj))
|
if (!PtrGuard.TryReadIntPtr(drawObjAddr, out var drawObj))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (drawObj != 0 && !PtrGuard.LooksLikePtr(drawObj, _dalamudUtil.IsWine))
|
if (drawObj != 0 && !PtrGuard.LooksLikePtr(drawObj))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return drawObj == 0;
|
return drawObj == 0;
|
||||||
|
|||||||
@@ -180,14 +180,16 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
|
|||||||
|
|
||||||
var nextAddr = _getAddress();
|
var nextAddr = _getAddress();
|
||||||
|
|
||||||
if (nextAddr != IntPtr.Zero && !PtrGuard.LooksLikePtr(nextAddr, _dalamudUtil.IsWine))
|
if (nextAddr != IntPtr.Zero && !PtrGuard.LooksLikePtr(nextAddr))
|
||||||
{
|
{
|
||||||
|
Logger.LogWarning("[{this}] _getAddress returned non-pointer: 0x{addr:X}", this, (ulong)nextAddr);
|
||||||
nextAddr = IntPtr.Zero;
|
nextAddr = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextAddr != IntPtr.Zero &&
|
if (nextAddr != IntPtr.Zero &&
|
||||||
!PtrGuard.IsReadable(nextAddr, (nuint)sizeof(FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject)))
|
!PtrGuard.IsReadable(nextAddr, (nuint)sizeof(FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject)))
|
||||||
{
|
{
|
||||||
|
Logger.LogWarning("[{this}] Address not readable: 0x{addr:X}", this, (ulong)nextAddr);
|
||||||
nextAddr = IntPtr.Zero;
|
nextAddr = IntPtr.Zero;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +201,7 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
|
|||||||
|
|
||||||
var draw = (nint)gameObject->DrawObject;
|
var draw = (nint)gameObject->DrawObject;
|
||||||
|
|
||||||
if (!PtrGuard.LooksLikePtr(draw, _dalamudUtil.IsWine) || !PtrGuard.IsReadable(draw, (nuint)sizeof(DrawObject)))
|
if (!PtrGuard.LooksLikePtr(draw) || !PtrGuard.IsReadable(draw, (nuint)sizeof(DrawObject)))
|
||||||
draw = 0;
|
draw = 0;
|
||||||
|
|
||||||
DrawObjectAddress = draw;
|
DrawObjectAddress = draw;
|
||||||
@@ -361,7 +363,7 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
|
|||||||
private unsafe bool CompareAndUpdateMainHand(Weapon* weapon)
|
private unsafe bool CompareAndUpdateMainHand(Weapon* weapon)
|
||||||
{
|
{
|
||||||
var p = (nint)weapon;
|
var p = (nint)weapon;
|
||||||
if (!PtrGuard.LooksLikePtr(p, _dalamudUtil.IsWine) || !PtrGuard.IsReadable(p, (nuint)sizeof(Weapon)))
|
if (!PtrGuard.LooksLikePtr(p) || !PtrGuard.IsReadable(p, (nuint)sizeof(Weapon)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool hasChanges = false;
|
bool hasChanges = false;
|
||||||
@@ -377,7 +379,7 @@ public sealed class GameObjectHandler : DisposableMediatorSubscriberBase, IHighP
|
|||||||
private unsafe bool CompareAndUpdateOffHand(Weapon* weapon)
|
private unsafe bool CompareAndUpdateOffHand(Weapon* weapon)
|
||||||
{
|
{
|
||||||
var p = (nint)weapon;
|
var p = (nint)weapon;
|
||||||
if (!PtrGuard.LooksLikePtr(p, _dalamudUtil.IsWine) || !PtrGuard.IsReadable(p, (nuint)sizeof(Weapon)))
|
if (!PtrGuard.LooksLikePtr(p) || !PtrGuard.IsReadable(p, (nuint)sizeof(Weapon)))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool hasChanges = false;
|
bool hasChanges = false;
|
||||||
|
|||||||
@@ -5,41 +5,24 @@ namespace LightlessSync.Utils
|
|||||||
{
|
{
|
||||||
public static partial class PtrGuard
|
public static partial class PtrGuard
|
||||||
{
|
{
|
||||||
private static readonly nuint _hardMinWindows =
|
private const ulong _minLikelyPtr = 0x0000_0001_0000_0000UL;
|
||||||
(nuint)(IntPtr.Size == 8 ? 0x0000000100000000UL : 0x0000000000010000UL);
|
private const ulong _maxUserPtr = 0x0000_7FFF_FFFF_FFFFUL;
|
||||||
private static readonly nuint _hardMaxWindows =
|
private const ulong _aligmentPtr = 0x7UL;
|
||||||
(nuint)(IntPtr.Size == 8 ? 0x00007FFFFFFFFFFFUL : 0x7FFFFFFFUL);
|
|
||||||
private const nuint _alignmentPtr = 0x7;
|
|
||||||
|
|
||||||
private static readonly (nuint min, nuint max) _sysRange = GetSysRange();
|
public static bool LooksLikePtr(nint p)
|
||||||
|
|
||||||
private static (nuint min, nuint max) GetSysRange()
|
|
||||||
{
|
|
||||||
GetSystemInfo(out var si);
|
|
||||||
return ((nuint)si.lpMinimumApplicationAddress, (nuint)si.lpMaximumApplicationAddress);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static nuint GetMinAppAddr(bool isWine) => isWine ? _sysRange.min : _hardMinWindows;
|
|
||||||
private static nuint GetMaxAppAddr(bool isWine) => isWine ? _sysRange.max : _hardMaxWindows;
|
|
||||||
|
|
||||||
public static bool LooksLikePtr(nint p, bool isWine = false)
|
|
||||||
{
|
{
|
||||||
if (p == 0) return false;
|
if (p == 0) return false;
|
||||||
nuint u = (nuint)p;
|
var u = (ulong)p;
|
||||||
|
if (u < _minLikelyPtr) return false;
|
||||||
if (u < GetMinAppAddr(isWine)) return false;
|
if (u > _maxUserPtr) return false;
|
||||||
if (u > GetMaxAppAddr(isWine)) return false;
|
if ((u & _aligmentPtr) != 0) return false;
|
||||||
if ((u & _alignmentPtr) != 0) return false;
|
|
||||||
if ((uint)u == 0x12345679u) return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
public static bool TryReadIntPtr(nint addr, out nint value)
|
||||||
public static bool TryReadIntPtr(nint addr, bool isWine, out nint value)
|
|
||||||
{
|
{
|
||||||
value = 0;
|
value = 0;
|
||||||
|
|
||||||
if (!LooksLikePtr(addr, isWine))
|
if (!LooksLikePtr(addr))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return ReadProcessMemory(GetCurrentProcess(), addr, out value, (nuint)IntPtr.Size, out nuint bytesRead)
|
return ReadProcessMemory(GetCurrentProcess(), addr, out value, (nuint)IntPtr.Size, out nuint bytesRead)
|
||||||
|
|||||||
@@ -32,24 +32,5 @@ namespace LightlessSync.Utils
|
|||||||
|
|
||||||
[DllImport("kernel32.dll")]
|
[DllImport("kernel32.dll")]
|
||||||
internal static extern nint GetCurrentProcess();
|
internal static extern nint GetCurrentProcess();
|
||||||
|
|
||||||
[DllImport("kernel32.dll")]
|
|
||||||
internal static extern void GetSystemInfo(out SystemInfo lpSystemInfo);
|
|
||||||
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
internal struct SystemInfo
|
|
||||||
{
|
|
||||||
public ushort wProcessorArchitecture;
|
|
||||||
public ushort wReserved;
|
|
||||||
public uint dwPageSize;
|
|
||||||
public nint lpMinimumApplicationAddress;
|
|
||||||
public nint lpMaximumApplicationAddress;
|
|
||||||
public nint dwActiveProcessorMask;
|
|
||||||
public uint dwNumberOfProcessors;
|
|
||||||
public uint dwProcessorType;
|
|
||||||
public uint dwAllocationGranularity;
|
|
||||||
public ushort wProcessorLevel;
|
|
||||||
public ushort wProcessorRevision;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user