Now we have to implement custom Process.Start()

This commit is contained in:
Mino 2020-03-28 11:57:13 +09:00
parent e216227429
commit 3e6675adc0
3 changed files with 24 additions and 8 deletions

View file

@ -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);
}
/// <summary>

View file

@ -8,6 +8,13 @@ namespace Dalamud.Bootstrap.SqexArg
{
internal static class EncryptedArgumentExtensions
{
/// <summary>
///
/// </summary>
/// <param name="argument"></param>
/// <param name="key"></param>
/// <returns></returns>
/// <exception cref="SqexArgException">Thrown when the data property does not have a valid base64 string.</exception>
public static string Decrypt(this EncryptedArgument argument, uint key)
{
Span<byte> keyBytes = stackalloc byte[8];

View file

@ -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)
{