Skip to content

Instantly share code, notes, and snippets.

@maxton
Last active May 24, 2018 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxton/88d65c22b1ef57e877a226b4d2555b2d to your computer and use it in GitHub Desktop.
Save maxton/88d65c22b1ef57e877a226b4d2555b2d to your computer and use it in GitHub Desktop.
Decrypt xma/fsb.e.2 files from Power Gig
using System;
using System.IO;
using GameArchives.Seven45;
namespace PowerGigDecryptor
{
class Program
{
static void Main(string[] args)
{
var directory = args[0];
foreach (var f in Directory.EnumerateFiles(directory, "*.e.2", SearchOption.AllDirectories))
{
if (f.Contains(".xma"))
DecryptXMA(f);
else if (f.Contains(".fsb"))
DecryptFSB(f);
else
continue;
}
}
static void DecryptXMA(string file)
{
var outfile = file.EndsWith(".e.2") ? file.Substring(0, file.Length - 4) : (file + ".dec");
var IV = new byte[16];
using (var i = File.OpenRead(file))
using (var o = File.OpenWrite(outfile))
{
using (var d = new PowerChordCryptStream(i, iv: IV))
{
d.Position = 0x400;
d.Read(IV, 0, 16);
}
IV = Array.ConvertAll(IV, x => (byte)(~x));
using (var d = new PowerChordCryptStream(i, iv: IV))
{
d.CopyTo(o);
}
}
}
static byte[] header = {
0x46, 0x53, 0x42, 0x34,
0x01, 0x00, 0x00, 0x00,
0x50, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00
};
static void DecryptFSB(string file)
{
var outfile = file.EndsWith(".e.2") ? file.Substring(0, file.Length - 4) : (file + ".dec");
var IV = new byte[16];
using (var i = File.OpenRead(file))
using (var o = File.OpenWrite(outfile))
{
using (var d = new PowerChordCryptStream(i, iv: IV))
{
d.Position = 0;
d.Read(IV, 0, 16);
var length = d.Length - 0x80;
header[12] = (byte)(length & 0xFF);
header[13] = (byte)(length >> 8 & 0xFF);
header[14] = (byte)(length >> 16 & 0xFF);
header[15] = (byte)(length >> 24 & 0xFF);
for (var x = 0; x < header.Length; x++)
{
IV[x] ^= header[x];
}
}
using (var d = new PowerChordCryptStream(i, iv: IV))
{
d.CopyTo(o);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment