mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-02-19 14:27:45 +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
|
namespace Dalamud.Bootstrap
|
||||||
{
|
{
|
||||||
public sealed class Bootstrapper
|
public class Bootstrapper
|
||||||
{
|
{
|
||||||
private readonly BootstrapperOptions m_options;
|
private readonly BootstrapperOptions m_options;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ using System.IO;
|
||||||
|
|
||||||
namespace Dalamud.Bootstrap
|
namespace Dalamud.Bootstrap
|
||||||
{
|
{
|
||||||
public sealed class BootstrapperOptions
|
public class BootstrapperOptions
|
||||||
{
|
{
|
||||||
public static BootstrapperOptions Default => new BootstrapperOptions
|
public static BootstrapperOptions Default => new BootstrapperOptions
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,13 @@ namespace Dalamud.Bootstrap.SqexArg
|
||||||
'5', 'C', 'A', 'P', '4', '_', 'V', 'L'
|
'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 ReadOnlyMemory<byte> m_data;
|
||||||
|
|
||||||
private readonly uint m_key;
|
|
||||||
|
|
||||||
//private readonly Blowfish m_cachedBlowfish;
|
|
||||||
|
|
||||||
public EncodedArgument(ReadOnlyMemory<byte> data, uint key)
|
public EncodedArgument(ReadOnlyMemory<byte> data, uint key)
|
||||||
{
|
{
|
||||||
m_data = data;
|
m_data = data;
|
||||||
|
|
@ -51,21 +52,54 @@ namespace Dalamud.Bootstrap.SqexArg
|
||||||
var checksum = argument[^5];
|
var checksum = argument[^5];
|
||||||
var payload = DecodeUrlSafeBase64(argument.Substring(12, argument.Length - 1 - 12 - 4)); // //**sqex0003, checksum, **//
|
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);
|
var (keyFragment, step) = RecoverKeyFragmentFromChecksum(checksum);
|
||||||
|
|
||||||
if (index < 0)
|
var keyCandicate = keyFragment;
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
recoveredKey = 0;
|
// try with keyCandicate
|
||||||
return false;
|
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
recoveredKey = (uint) (index << 16);
|
return MemoryExtensions.IndexOf(ChecksumTable, checksum) switch
|
||||||
return true;
|
{
|
||||||
|
-1 => throw new SqexArgException($"{checksum} is not a valid checksum character."),
|
||||||
|
var index => ((uint) (index << 16), 0x0010_0000)
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
namespace Dalamud.Bootstrap.Windows
|
namespace Dalamud.Bootstrap.Windows
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue