Created
January 19, 2019 05:19
-
-
Save maxton/ea954216e8eea92634714b9117f72e15 to your computer and use it in GitHub Desktop.
c# script for some app
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Security.Cryptography; | |
using System.IO; | |
byte[][] LoadKeys(string fn) | |
{ | |
var blobKey = new byte[] { 0xE4, 0xC5, 0x1B, 0x30, 0xDB, 0x7E, 0xE, 0x20, 0x15, 0xB5, 0xD8, 0x2E, 0x1A, 0xF6, 0x3F, 0x6E }; | |
var decrypted = new MemoryStream(); | |
using(var f = File.OpenRead(fn)) | |
{ | |
var iv = new byte[16]; | |
f.Read(iv, 0, 16); | |
using (var aes = new AesCryptoServiceProvider() { Key = blobKey, IV = iv, Mode = CipherMode.CBC }) | |
using (var dec = aes.CreateDecryptor(blobKey, iv)) | |
using (var x = new CryptoStream(f, dec, CryptoStreamMode.Read)) | |
{ | |
x.CopyTo(decrypted); | |
} | |
} | |
decrypted.Seek(-144, SeekOrigin.End); | |
var ret = new byte[9][]; | |
for(var i = 0; i < 9; i++) | |
{ | |
ret[i] = new byte[16]; | |
decrypted.Read(ret[i], 0, 16); | |
} | |
decrypted.Dispose(); | |
return ret; | |
} | |
enum InstrumentType { Guitar = 0, Bass, Drums, Vox }; | |
int GetSoloKey(InstrumentType t){ | |
switch(t) | |
{ | |
case InstrumentType.Guitar: return 5; | |
case InstrumentType.Bass: return 1; | |
case InstrumentType.Drums: return 3; | |
case InstrumentType.Vox: return 7; | |
default: return 0; | |
} | |
} | |
int GetTrksKey(InstrumentType t){ | |
switch (t) | |
{ | |
case InstrumentType.Guitar: return 6; | |
case InstrumentType.Bass: return 2; | |
case InstrumentType.Drums: return 4; | |
case InstrumentType.Vox: return 8; | |
default: return 1; | |
} | |
} | |
string GetFileName(string blobName, InstrumentType t, bool trks) | |
{ | |
var fn = blobName.Replace(".blob", ""); | |
string txt = ""; | |
switch(t) | |
{ | |
case InstrumentType.Guitar: txt = "gtr"; break; | |
case InstrumentType.Bass: txt = "bass"; break; | |
case InstrumentType.Drums: txt = "drums"; break; | |
case InstrumentType.Vox: txt = "vox"; break; | |
default: throw new Exception("AAAAAAHHHH!!!!"); | |
} | |
return fn + "_" + txt + "_" + (trks ? "trks" : "solo") + ".dat"; | |
} | |
void DecryptOgg(string fn, byte[] key){ | |
using (var f = File.OpenRead(fn)) | |
using (var o = File.OpenWrite(fn.Replace(".dat",".ogg"))) | |
{ | |
var iv = new byte[16]; | |
f.Read(iv, 0, 16); | |
using (var aes = new AesCryptoServiceProvider() { Key = key, IV = iv, Mode = CipherMode.CBC }) | |
using (var dec = aes.CreateDecryptor(key, iv)) | |
using (var x = new CryptoStream(f, dec, CryptoStreamMode.Read)) | |
{ | |
x.CopyTo(o); | |
} | |
} | |
} | |
void DecryptAll(string baseName, int howMany){ | |
for(int songNum = 0; songNum < howMany; songNum++) | |
{ | |
var blobName = $"{baseName}{songNum}.blob"; | |
var keys = LoadKeys(blobName); | |
for(var i = 0; i < 4; i++){ | |
DecryptOgg(GetFileName(blobName, (InstrumentType)i, false), keys[GetSoloKey((InstrumentType) i)]); | |
DecryptOgg(GetFileName(blobName, (InstrumentType)i, true), keys[GetTrksKey((InstrumentType) i)]); | |
} | |
} | |
} | |
// DecryptAll(@"G:\Dumps\game.app\a", 15); // decrypt all the songs in the app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment