From 3e6675adc0515a5119608f3fe5a2a607ab2b89dd Mon Sep 17 00:00:00 2001 From: Mino Date: Sat, 28 Mar 2020 11:57:13 +0900 Subject: [PATCH] Now we have to implement custom Process.Start() --- Dalamud.Bootstrap/Bootstrapper.cs | 23 +++++++++++++------ .../SqexArg/EncryptedArgumentExtensions.cs | 7 ++++++ Dalamud.Bootstrap/Windows/Process.cs | 2 +- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Dalamud.Bootstrap/Bootstrapper.cs b/Dalamud.Bootstrap/Bootstrapper.cs index b604fb606..f6eec5abc 100644 --- a/Dalamud.Bootstrap/Bootstrapper.cs +++ b/Dalamud.Bootstrap/Bootstrapper.cs @@ -54,9 +54,18 @@ namespace Dalamud.Bootstrap // Acquire the process handle and read the command line using var process = Process.Open(pid); - var argument = ReadGameArgument(process); + var argument = ReadArgumentFromProcess(process); - argument.Remove("T"); + var newTick = Environment.TickCount; + var newKey = newTick & 0xFFFF_0000; // only the high nibble is used + + var newArgument = argument.Remove("T") + .Add("T", $"{newTick}") + .ToString(); + + // TODO: encode as a encrypted? + // TODO: launch it + //var newCommandLine = // TODO: // .... if arg1 exists @@ -85,24 +94,24 @@ namespace Dalamud.Bootstrap return createdTick & 0xFFFF_0000; } - private static ArgumentBuilder ReadGameArgument(Process process) + private static ArgumentBuilder ReadArgumentFromProcess(Process process) { var arguments = process.ReadArguments(); if (arguments.Length < 1) { - throw new BootstrapException($"Process id {process.Id} does not have any arguments to parse."); + throw new BootstrapException($"Process id {process.GetPid()} does not have any arguments to parse."); } var argument = arguments[0]; if (EncryptedArgument.TryParse(argument, out var encryptedArgument)) { - var key = RecoverKey(process); - // + var key = RecoverKey(process); + argument = encryptedArgument.Decrypt(key); } - + return ArgumentBuilder.TryParse(argument); } /// diff --git a/Dalamud.Bootstrap/SqexArg/EncryptedArgumentExtensions.cs b/Dalamud.Bootstrap/SqexArg/EncryptedArgumentExtensions.cs index 20c415bc1..8b580c7fc 100644 --- a/Dalamud.Bootstrap/SqexArg/EncryptedArgumentExtensions.cs +++ b/Dalamud.Bootstrap/SqexArg/EncryptedArgumentExtensions.cs @@ -8,6 +8,13 @@ namespace Dalamud.Bootstrap.SqexArg { internal static class EncryptedArgumentExtensions { + /// + /// + /// + /// + /// + /// + /// Thrown when the data property does not have a valid base64 string. public static string Decrypt(this EncryptedArgument argument, uint key) { Span keyBytes = stackalloc byte[8]; diff --git a/Dalamud.Bootstrap/Windows/Process.cs b/Dalamud.Bootstrap/Windows/Process.cs index 19426b74e..262a9bf5f 100644 --- a/Dalamud.Bootstrap/Windows/Process.cs +++ b/Dalamud.Bootstrap/Windows/Process.cs @@ -48,7 +48,7 @@ namespace Dalamud.Bootstrap return new Process(handle); } - private uint GetPid() => Win32.GetProcessId(m_handle); + public uint GetPid() => Win32.GetProcessId(m_handle); public void Terminate(uint exitCode = 0) {