This commit is contained in:
Mino 2020-04-08 00:23:31 +09:00
parent b5f1084f73
commit 9965dc313a
14 changed files with 381 additions and 406 deletions

View file

@ -18,6 +18,11 @@ namespace Dalamud.Bootstrap
m_options = options;
}
public static void Test()
{
//
}
public void Launch(string exePath, string? commandLine)
{
commandLine = commandLine ?? "";
@ -126,6 +131,60 @@ namespace Dalamud.Bootstrap
throw new BootstrapException(exMessage, ex);
}
}
/// <summary>
/// Recovers a key used in encrypting process arguments.
/// </summary>
/// <returns>A key recovered from the time when the process was created.</returns>
/// <remarks>
/// This is possible because the key to encrypt arguments is just a high nibble value from GetTickCount() at the time when the process was created.
/// (Thanks Wintermute!)
/// </remarks>
private uint GetArgumentEncryptionKey()
{
var createdTime = m_process.GetCreationTime();
// Get current tick
var currentDt = DateTime.Now;
var currentTick = Environment.TickCount;
// We know that GetTickCount() is just a system uptime in milliseconds.
var delta = currentDt - createdTime;
var createdTick = (uint)currentTick - (uint)delta.TotalMilliseconds;
// only the high nibble is used.
return createdTick & 0xFFFF_0000;
}
/// <summary>
/// Reads command-line arguments from the game and decrypts them if necessary.
/// </summary>
/// <returns>
/// Command-line arguments that looks like this:
/// /DEV.TestSID =ABCD /UserPath =C:\Examples
/// </returns>
public string GetGameArguments()
{
var processArguments = m_process.GetProcessArguments();
// arg[0] is a path to exe(normally), arg[1] is actual stuff.
if (processArguments.Length < 2)
{
throw new ProcessException($"Process {m_process.GetProcessId()} only have {processArguments.Length} arguments. It must have atleast 2 arguments.");
}
// We're interested in argument that contains session id
var argument = processArguments[1];
// If it's encrypted, we need to decrypt it first
if (EncryptedArgument.TryParse(argument, out var encryptedArgument))
{
var key = GetArgumentEncryptionKey();
argument = encryptedArgument.Decrypt(key);
}
return argument;
}
}
internal sealed class PipePlatform : IPipePlatform