From c6a9879498be79527b07d626814f40cf58fe9918 Mon Sep 17 00:00:00 2001 From: Mino <1381835+Minoost@users.noreply.github.com> Date: Thu, 12 Mar 2020 17:39:28 +0900 Subject: [PATCH] EncodedArg --- Dalamud.Bootstrap/Bootstrapper.cs | 7 ++- .../SqexArg/ArgumentContainer.cs | 40 ++++++++++++++++ Dalamud.Bootstrap/SqexArg/ArgumentDecoder.cs | 47 ------------------- 3 files changed, 46 insertions(+), 48 deletions(-) create mode 100644 Dalamud.Bootstrap/SqexArg/ArgumentContainer.cs delete mode 100644 Dalamud.Bootstrap/SqexArg/ArgumentDecoder.cs diff --git a/Dalamud.Bootstrap/Bootstrapper.cs b/Dalamud.Bootstrap/Bootstrapper.cs index 15c63d6d7..a307a51b3 100644 --- a/Dalamud.Bootstrap/Bootstrapper.cs +++ b/Dalamud.Bootstrap/Bootstrapper.cs @@ -46,7 +46,12 @@ namespace Dalamud.Bootstrap using var process = Process.Open(pid); var commandLine = process.ReadCommandLine(); - var argument = ArgumentDecoder.Decode(commandLine[1]); + if (!ArgumentContainer.Parse(commandLine[1], out var container)) + { + + } + + // TODO: // .... if arg1 exists // DecodeSqexArg(arguments[1]); diff --git a/Dalamud.Bootstrap/SqexArg/ArgumentContainer.cs b/Dalamud.Bootstrap/SqexArg/ArgumentContainer.cs new file mode 100644 index 000000000..c6e9216bb --- /dev/null +++ b/Dalamud.Bootstrap/SqexArg/ArgumentContainer.cs @@ -0,0 +1,40 @@ +using System; + +namespace Dalamud.Bootstrap.SqexArg +{ + internal sealed class ArgumentContainer + { + /// + /// + /// + /// + /// + /// + public static bool Parse(string argument, out ArgumentContainer? container) + { + if (argument.Length < 17) + { + // does not contain: //**sqex003 + payload + checksum + **// + container = null; + return false; + } + + if (!argument.StartsWith("//**sqex003") || !argument.EndsWith("**//")) + { + container = null; + return false; + } + + var checksum = argument[^5]; + var payload = argument[11..^5] + .Replace(; // encoded in url-safe variant of base64 + + // decode + + Convert.FromBase64String(); + container = new ArgumentContainer(payload, checksum); + + return true; + } + } +} diff --git a/Dalamud.Bootstrap/SqexArg/ArgumentDecoder.cs b/Dalamud.Bootstrap/SqexArg/ArgumentDecoder.cs deleted file mode 100644 index 0b162bbd8..000000000 --- a/Dalamud.Bootstrap/SqexArg/ArgumentDecoder.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; - -namespace Dalamud.Bootstrap.SqexArg -{ - internal static class ArgumentDecoder - { - public static ArgumentBuilder Decode(ReadOnlySpan argument, uint key) - { - // 1. strip //**sqex003 and **// - // 2. extract checksum - // 3. deduce upper nibble key - // 4. - - // //**c**// - if (argument.Length <= 9) - { - throw new ArgumentException(nameof(argument)); - } - - if (!argument.StartsWith("//**") || !argument.EndsWith("**//")) - { - throw new ArgumentException(nameof(argument)); - } - - var payload = argument[4..^5]; - var checksum = argument[^5]; - - // undo url safe - //payload.re - - - - // stuff - throw new NotImplementedException("TODO"); - } - - private static void DecodeUrlSafeBase64(ReadOnlySpan content) - { - var buffer = new byte[(content.Length / 3) * 4]; - if (!Convert.TryFromBase64Chars(payload, buffer, out var _)) - { - // TODO - } - } - - } -}