Skip to content

Instantly share code, notes, and snippets.

@lunasorcery
Created September 10, 2014 15:04
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 lunasorcery/6971bdc0a9a305809c60 to your computer and use it in GitHub Desktop.
Save lunasorcery/6971bdc0a9a305809c60 to your computer and use it in GitHub Desktop.
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
namespace SaboteurExtractor
{
class Program
{
static void Main(string[] args)
{
Extract(
@"E:\Users\Will\Downloads\Start0.kiloPack",
@"E:\Users\Will\Downloads\Start0"
);
Extract(
@"E:\Users\Will\Downloads\Mega2.megaPack",
@"E:\Users\Will\Downloads\Mega2"
);
}
static void Extract(string p_filePath, string p_outputDir)
{
using (BinaryReader br = new BinaryReader(File.OpenRead(p_filePath)))
{
string magic = Encoding.ASCII.GetString(br.ReadBytes(4));
Debug.Assert(magic == "00PM");
int numFiles = br.ReadInt32();
file_header_t[] headers = new file_header_t[numFiles];
ulong[] hashes = new ulong[numFiles];
for (int i = 0; i < numFiles; i++)
{
headers[i] = new file_header_t(br);
}
for (int i = 0; i < numFiles; i++)
{
hashes[i] = br.ReadUInt64();
}
for (int i = 0; i < numFiles; i++)
{
Debug.Assert(headers[i].hash == hashes[i]);
}
if (Directory.Exists(p_outputDir) == false)
{
Directory.CreateDirectory(p_outputDir);
}
for (int i = 0; i < numFiles; i++)
{
FileInfo outputFile = new FileInfo(
Path.Combine(
p_outputDir,
string.Format("{0}_{1:X16}.bin", i, headers[i].hash)
)
);
br.BaseStream.Position = headers[i].offset;
using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(outputFile.FullName)))
{
Console.WriteLine(outputFile.Name);
bw.Write(br.ReadBytes(headers[i].length));
}
}
}
}
struct file_header_t
{
public ulong hash;
public int length;
public int offset;
public uint unknown;
public file_header_t(BinaryReader p_reader)
{
hash = p_reader.ReadUInt64();
length = p_reader.ReadInt32();
offset = p_reader.ReadInt32();
unknown = p_reader.ReadUInt32();
Debug.Assert(unknown == 0);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment