I don't even know what I'm doing

This commit is contained in:
Mino 2020-04-01 20:00:15 +09:00
parent 117d1dfbb2
commit 79fb6c5104
3 changed files with 55 additions and 35 deletions

View file

@ -1,17 +1,13 @@
using System;
using Dalamud.Bootstrap.SqexArg;
using Dalamud.Bootstrap.Windows;
using Microsoft.Win32.SafeHandles;
namespace Dalamud.Bootstrap
{
internal sealed class GameProcess : IDisposable
internal sealed class GameProcess : Process
{
private Process m_process;
public GameProcess(Process process)
{
m_process = process;
}
public GameProcess(SafeProcessHandle handle) : base(handle) { }
public static GameProcess Open(uint pid)
{
@ -25,15 +21,9 @@ namespace Dalamud.Bootstrap
// TODO: unfuck VM_WRITE
var process = Process.Open(pid, access);
var handle = Process.OpenHandle(pid, access);
return new GameProcess(process);
}
public void Dispose()
{
m_process?.Dispose();
m_process = null!;
return new GameProcess(handle);
}
/// <summary>
@ -60,24 +50,34 @@ namespace Dalamud.Bootstrap
return createdTick & 0xFFFF_0000;
}
public ArgumentBuilder ReadArguments()
/// <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 ReadArguments()
{
var arguments = m_process.ReadArguments();
var processArguments = m_process.GetArguments();
if (arguments.Length < 2)
// arg[0] is a path to exe(normally), arg[1] is actual stuff.
if (processArguments.Length < 2)
{
throw new BootstrapException($"Process id {m_process.GetPid()} have no arguments to parse.");
}
var argument = arguments[1];
// 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 ArgumentBuilder.Parse(argument);
return argument;
}
}
}