mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-03 14:23:40 +01:00
WIP encoded arg
This commit is contained in:
parent
c1ed673f22
commit
6ce974caf7
4 changed files with 52 additions and 17 deletions
|
|
@ -8,7 +8,7 @@ using Dalamud.Bootstrap.SqexArg;
|
|||
|
||||
namespace Dalamud.Bootstrap
|
||||
{
|
||||
public sealed class Bootstrapper
|
||||
public class Bootstrapper
|
||||
{
|
||||
private readonly BootstrapperOptions m_options;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ using System.IO;
|
|||
|
||||
namespace Dalamud.Bootstrap
|
||||
{
|
||||
public sealed class BootstrapperOptions
|
||||
public class BootstrapperOptions
|
||||
{
|
||||
public static BootstrapperOptions Default => new BootstrapperOptions
|
||||
{
|
||||
|
|
|
|||
|
|
@ -15,12 +15,13 @@ namespace Dalamud.Bootstrap.SqexArg
|
|||
'5', 'C', 'A', 'P', '4', '_', 'V', 'L'
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Denotes that no checksum is encoded.
|
||||
/// </summary>
|
||||
private const char NoChecksumMarker = '!';
|
||||
|
||||
private readonly ReadOnlyMemory<byte> m_data;
|
||||
|
||||
private readonly uint m_key;
|
||||
|
||||
//private readonly Blowfish m_cachedBlowfish;
|
||||
|
||||
public EncodedArgument(ReadOnlyMemory<byte> data, uint key)
|
||||
{
|
||||
m_data = data;
|
||||
|
|
@ -51,23 +52,56 @@ namespace Dalamud.Bootstrap.SqexArg
|
|||
var checksum = argument[^5];
|
||||
var payload = DecodeUrlSafeBase64(argument.Substring(12, argument.Length - 1 - 12 - 4)); // //**sqex0003, checksum, **//
|
||||
|
||||
|
||||
// ...
|
||||
}
|
||||
|
||||
private static bool GetKeyFragmentFromChecksum(char checksum, out uint recoveredKey)
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="payload"></param>
|
||||
/// <param name="checksum"></param>
|
||||
/// <returns></returns>
|
||||
private static Blowfish RecoverKey(ReadOnlySpan<byte> payload, char checksum)
|
||||
{
|
||||
var index = MemoryExtensions.IndexOf(ChecksumTable, checksum);
|
||||
|
||||
if (index < 0)
|
||||
{
|
||||
recoveredKey = 0;
|
||||
return false;
|
||||
}
|
||||
var (keyFragment, step) = RecoverKeyFragmentFromChecksum(checksum);
|
||||
|
||||
recoveredKey = (uint) (index << 16);
|
||||
return true;
|
||||
var keyCandicate = keyFragment;
|
||||
while (true)
|
||||
{
|
||||
// try with keyCandicate
|
||||
|
||||
try
|
||||
{
|
||||
keyCandicate = checked(keyCandicate + step);
|
||||
}
|
||||
catch (OverflowException)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="keyFragment"></param>
|
||||
/// <param name="step"></param>
|
||||
/// <returns></returns>
|
||||
private static (uint keyFragment, uint step) RecoverKeyFragmentFromChecksum(char checksum)
|
||||
{
|
||||
if (checksum == NoChecksumMarker)
|
||||
{
|
||||
return (0x0001_0000, 0x0001_0000);
|
||||
}
|
||||
|
||||
return MemoryExtensions.IndexOf(ChecksumTable, checksum) switch
|
||||
{
|
||||
-1 => throw new SqexArgException($"{checksum} is not a valid checksum character."),
|
||||
var index => ((uint) (index << 16), 0x0010_0000)
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts url safe variant of base64 string to bytes.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Dalamud.Bootstrap.Windows
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue