Skip to content

Instantly share code, notes, and snippets.

@NotAdam
Last active January 22, 2018 08:22
Show Gist options
  • Save NotAdam/279579dae85527e4b6350093c7ddc9ea to your computer and use it in GitHub Desktop.
Save NotAdam/279579dae85527e4b6350093c7ddc9ea to your computer and use it in GitHub Desktop.
using System;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Net;
using Newtonsoft.Json;
using System.IO;
using System.IO.Compression;
namespace eorzeadb_noncegen
{
class Program
{
static void Main( string[] args )
{
var dt = DateTimeOffset.Now.ToUnixTimeSeconds();
var nonce = new byte[] { 48, 102, 54, 51, 54, 50, 98, 52, 53, 48, 49, 52, 101, 53, 99, 55, 49, 98, 100, 57, 48, 48, 98, 57, 98, 57, 98, 52, 48, 52, 50, 55, 98, 57, 49, 55, 101, 98, 97, 49 };
var apikey = "858dd61895a851c365513a27e9ac80cf143957c6";
var ba = Encoding.ASCII.GetBytes( apikey + dt ).Concat( nonce ).ToArray();
string response = string.Empty;
using ( var sha1 = new SHA1Managed() )
{
var hash = sha1.ComputeHash( ba );
var sb = new StringBuilder( hash.Length * 2 );
foreach ( byte b in hash )
sb.Append( b.ToString( "x2" ) );
var url = $"https://login.finalfantasyxiv.com/lodestone/api/data/app_data?apikey={apikey}&timestamp={dt}&nonce={sb.ToString()}&type=android";
using ( var wc = new WebClient() )
{
response = wc.DownloadString( url );
}
}
dynamic respData = JsonConvert.DeserializeObject( response );
Console.WriteLine( $"got response url: {respData.data.uri}" );
Console.WriteLine( $"downloading file..." );
byte[] fileBytes;
using ( var wc = new WebClient() )
{
fileBytes = wc.DownloadData( respData.data.uri.ToString() );
}
Console.WriteLine( "decrypting..." );
var IV = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
var key = "1c9e4e3aac2e4327825ac30694333db9";
using ( var rm = new RijndaelManaged() )
{
rm.Key = Encoding.ASCII.GetBytes( key );
rm.IV = IV;
var decryptor = rm.CreateDecryptor();
using ( var ms = new MemoryStream( fileBytes ) )
using ( var cs = new CryptoStream( ms, decryptor, CryptoStreamMode.Read ) )
{
using ( var za = new ZipArchive( cs ) )
{
foreach ( var e in za.Entries )
{
Console.WriteLine( $"writing file {e.FullName}" );
using ( var fs = File.Create( e.FullName ) )
using ( var s = e.Open() )
{
int data;
while ( ( data = s.ReadByte() ) != -1 )
fs.WriteByte( ( byte )data );
}
}
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment