Get LoginData.Username by looking for it's prefix/header

This commit is contained in:
jvyden 2021-10-28 20:15:51 -04:00
commit 474556b8a6
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278

View file

@ -1,17 +1,9 @@
using System;
using System.IO;
using System.Text;
using LBPUnion.ProjectLighthouse.Helpers;
namespace LBPUnion.ProjectLighthouse.Types {
// This is all the information I can understand for now. More testing is required.
// Example data:
// - LBP2 digital, with the RPCN username `literally1984`
// POST /LITTLEBIGPLANETPS3_XML/login?applicationID=21414&languageID=1&lbp2=1&beta=0&titleID=NPUA80662&country=us
// !<21>0256333||x||<7C><>Y literally198bruUP9000-NPUA80662_008D
// - LBP2 digital, with the RPCN username `jvyden`
// POST /LITTLEBIGPLANETPS3_XML/login?applicationID=21414&languageID=1&lbp2=1&beta=0&titleID=NPUA80662&country=us
// !<21>0220333||/u||=0<> jvydebruUP9000-NPUA80662_008D
// Data is 251 bytes long.
/// <summary>
/// The data sent from POST /LOGIN.
/// </summary>
@ -20,15 +12,21 @@ namespace LBPUnion.ProjectLighthouse.Types {
// public string GameVersion { get; set; }
// public int UnknownNumber { get; set; } // Seems to increment by 1000 every login attempt
/// <summary>
/// Converts a X-I-5 Ticket into `LoginData`.
/// https://www.psdevwiki.com/ps3/X-I-5-Ticket
/// </summary>
public static LoginData CreateFromString(string str) {
str = str.Replace("\b", ""); // Remove backspace characters
using MemoryStream ms = new(Encoding.ASCII.GetBytes(str));
using BinaryReader reader = new(ms);
string usernamePrefix = Encoding.ASCII.GetString(new byte[] { 0x04, 0x00, 0x20 });
LoginData loginData = new();
reader.BaseStream.Position = 80;
reader.BaseStream.Position = str.IndexOf(usernamePrefix, StringComparison.Ordinal) + usernamePrefix.Length;
loginData.Username = BinaryHelper.ReadString(reader).Replace("\0", string.Empty);
return loginData;