diff --git a/src/Prospect.Launcher/Invoke/Kernel32.cs b/src/Prospect.Launcher/Invoke/Kernel32.cs index e2268be..02cca13 100644 --- a/src/Prospect.Launcher/Invoke/Kernel32.cs +++ b/src/Prospect.Launcher/Invoke/Kernel32.cs @@ -23,14 +23,6 @@ namespace Prospect.Launcher.Invoke out ProcessInformation lpProcessInformation) => CreateProcess(lpApplicationName, lpCommandLine, IntPtr.Zero, IntPtr.Zero, false, dwCreationFlags, IntPtr.Zero, null, ref lpStartupInfo, out lpProcessInformation); - [DllImport("kernel32.dll", SetLastError = true)] - public static extern bool ReadProcessMemory( - IntPtr hProcess, - IntPtr lpBaseAddress, - byte[] lpBuffer, - Int32 nSize, - out IntPtr lpNumberOfBytesRead); - [DllImport("kernel32.dll", SetLastError = true)] public static extern unsafe bool WriteProcessMemory( IntPtr hProcess, @@ -40,9 +32,6 @@ namespace Prospect.Launcher.Invoke out IntPtr lpNumberOfBytesWritten ); - [DllImport("kernel32.dll", SetLastError = true)] - public static extern bool VirtualProtectEx(IntPtr hProcess, IntPtr lpAddress, int dwSize, uint flNewProtect, out uint lpflOldProtect); - [DllImport("kernel32.dll", CharSet = CharSet.Auto)] public static extern IntPtr GetModuleHandle(string lpModuleName); diff --git a/src/Prospect.Launcher/Invoke/PSAPI.cs b/src/Prospect.Launcher/Invoke/PSAPI.cs deleted file mode 100644 index cf46eeb..0000000 --- a/src/Prospect.Launcher/Invoke/PSAPI.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Text; -using Prospect.Launcher.Invoke.Structs; - -namespace Prospect.Launcher.Invoke -{ - public class PSAPI - { - [DllImport("psapi.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)] - public static extern int EnumProcessModules(IntPtr hProcess, [Out] IntPtr lphModule, uint cb, out uint lpcbNeeded); - - [DllImport("psapi.dll", CallingConvention = CallingConvention.StdCall, SetLastError = true)] - public static extern bool GetModuleInformation(IntPtr hProcess, IntPtr hModule, out ModuleInfo lpModInfo, int cb); - - [DllImport("psapi.dll")] - public static extern uint GetModuleFileNameEx(IntPtr hProcess, IntPtr hModule, [Out] StringBuilder lpBaseName, [In] [MarshalAs(UnmanagedType.U4)] int nSize); - } -} \ No newline at end of file diff --git a/src/Prospect.Launcher/Invoke/Structs/ModuleInfo.cs b/src/Prospect.Launcher/Invoke/Structs/ModuleInfo.cs deleted file mode 100644 index 47b603f..0000000 --- a/src/Prospect.Launcher/Invoke/Structs/ModuleInfo.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace Prospect.Launcher.Invoke.Structs -{ - [StructLayout(LayoutKind.Sequential)] - public struct ModuleInfo - { - public IntPtr lpBaseOfDll; - public uint SizeOfImage; - public IntPtr EntryPoint; - } -} \ No newline at end of file diff --git a/src/Prospect.Launcher/MemoryHelper.cs b/src/Prospect.Launcher/MemoryHelper.cs deleted file mode 100644 index cd503dd..0000000 --- a/src/Prospect.Launcher/MemoryHelper.cs +++ /dev/null @@ -1,133 +0,0 @@ -using System; -using System.Buffers.Binary; -using System.IO; -using System.Runtime.InteropServices; -using System.Text; -using Prospect.Launcher.Invoke; -using Prospect.Launcher.Invoke.Structs; - -namespace Prospect.Launcher -{ - public class MemoryHelper - { - private readonly IntPtr _handle; - private readonly IntPtr _baseAddress; - - private MemoryHelper(IntPtr handle, IntPtr baseAddress) - { - _handle = handle; - _baseAddress = baseAddress; - } - - public void WriteU32(int offset, uint value) - { - Span data = stackalloc byte[sizeof(int)]; - BinaryPrimitives.WriteUInt32LittleEndian(data, value); - Write(offset, data); - } - - public void WriteASCII(int offset, string value) - { - // + 1 for NULL character - var dataCount = Encoding.ASCII.GetByteCount(value); - Span data = stackalloc byte[dataCount + 1]; - Encoding.ASCII.GetBytes(value, data); - Write(offset, data); - } - - public void WriteUnicode(int offset, string value) - { - // + 2 for NULL character - var dataCount = Encoding.Unicode.GetByteCount(value); - Span data = stackalloc byte[dataCount + 2]; - Encoding.Unicode.GetBytes(value, data); - Write(offset, data); - } - - public unsafe void Write(int offset, ReadOnlySpan data) - { - Write(_baseAddress + offset, data); - } - - public unsafe void Write(IntPtr addr, ReadOnlySpan data) - { - // Modify protection. - if (!Kernel32.VirtualProtectEx(_handle, addr, data.Length, 0x40, out var oldProtect)) - { - throw new Exception($"Unable to change protection {Marshal.GetLastWin32Error()}."); - } - - fixed (byte* pData = data) - { - var write = Kernel32.WriteProcessMemory(_handle, addr, pData, data.Length, out _); - - // Restore protection. - Kernel32.VirtualProtectEx(_handle, addr, data.Length, oldProtect, out _); - - if (!write) - { - throw new Exception($"Unable to write process memory {Marshal.GetLastWin32Error()}."); - } - } - } - - public byte[] Read(int offset, int count) - { - var buffer = new byte[count]; - - if (!Kernel32.ReadProcessMemory(_handle, _baseAddress + offset, buffer, count, out _)) - { - throw new Exception("Unable to read process memory."); - } - - return buffer; - } - - public static MemoryHelper CreateForHandle(IntPtr handle, string gameBinary) - { - var gameBinaryName = Path.GetFileName(gameBinary); - - var hMods = new IntPtr[512]; - var hModsHandle = GCHandle.Alloc(hMods, GCHandleType.Pinned); - - try - { - var hModsPtr = hModsHandle.AddrOfPinnedObject(); - var hModsSize = (uint)(Marshal.SizeOf(typeof(IntPtr)) * (hMods.Length)); - - if (PSAPI.EnumProcessModules(handle, hModsPtr, hModsSize, out var cbNeeded) == 1) - { - var moduleCount = (int)(cbNeeded / Marshal.SizeOf(typeof(IntPtr))); - - for (var i = 0; i < moduleCount; i++) - { - var stringBuilder = new StringBuilder(1024); - - if (PSAPI.GetModuleFileNameEx(handle, hMods[i], stringBuilder, stringBuilder.Capacity) == 0) - { - continue; - } - - if (!gameBinaryName.Equals(Path.GetFileName(stringBuilder.ToString()))) - { - continue; - } - - if (!PSAPI.GetModuleInformation(handle, hMods[i], out var modInfo, Marshal.SizeOf())) - { - continue; - } - - return new MemoryHelper(handle, modInfo.lpBaseOfDll); - } - } - } - finally - { - hModsHandle.Free(); - } - - return null; - } - } -} \ No newline at end of file diff --git a/src/Prospect.Launcher/Patches.cs b/src/Prospect.Launcher/Patches.cs deleted file mode 100644 index b89e614..0000000 --- a/src/Prospect.Launcher/Patches.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace Prospect.Launcher -{ - public static class Patches - { - private const string DefaultPlayFabUrl = ".playfabapi.com"; - - public static bool ChangePlayFabUrl(MemoryHelper memory, string value) - { - if (value.Length > DefaultPlayFabUrl.Length) - { - return false; - } - - var lengthWithNull = (uint)(value.Length + 1); - - // Modify wide string. - memory.WriteU32(0xCA45A9 + 2, lengthWithNull * 2); // mov r8d, 20h - memory.WriteUnicode(0x4431860, value); // text "UTF-16LE", '.playfabapi.com',0 - - // Modify normal string. - memory.WriteU32(0x605F44 + 1, lengthWithNull); // mov edx, 10h - memory.WriteU32(0x605F86 + 2, lengthWithNull); // mov r9d, 10h - memory.WriteASCII(0x4431588, value); // '.playfabapi.com',0 - - return true; - } - } -} \ No newline at end of file diff --git a/src/Prospect.Launcher/Prospect.Launcher.csproj b/src/Prospect.Launcher/Prospect.Launcher.csproj index 93260f1..e77d873 100644 --- a/src/Prospect.Launcher/Prospect.Launcher.csproj +++ b/src/Prospect.Launcher/Prospect.Launcher.csproj @@ -23,7 +23,7 @@ PreserveNewest PreserveNewest - false + true