Skip to content

Instantly share code, notes, and snippets.

@misodengaku
Created September 25, 2014 17:39
Show Gist options
  • Save misodengaku/1eb41774ddee2ebd61ab to your computer and use it in GitHub Desktop.
Save misodengaku/1eb41774ddee2ebd61ab to your computer and use it in GitHub Desktop.
weissman extract
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
int i = 0, count = 1;
var hashmap = new Dictionary<byte[], byte[]>();
FileStream fs = new FileStream(args[0], FileMode.Open);
var data = new byte[fs.Length];
var bytelist = new List<byte>();
fs.Read(data, 0, (int)fs.Length);
var crc16 = new Crc16(Crc16Mode.CcittKermit);
while(i < data.Length)
{
if (data[i] < 0x12)
{
var blocksize = data[i] / 2;
var rel_addr = data[i + 1];
var unknown_value = data[i + 2];
var copyblock = new byte[blocksize];
if (rel_addr == 0xFF)
{
for (int j = 1; j < blocksize + 1; j++)
bytelist.Add(bytelist[bytelist.Count - 9 + j]);
}
else
{
for (int j = 1; j < blocksize + 1; j++)
bytelist.Add(data[i - rel_addr + j]);
}
i += 3;
}
else if(data[i] == 0x12)
{
/*i++;
bytelist.Add(data[i]);
i++;
bytelist.Add(data[i]);
i++;*/
i++;
byte[] queryhash = new byte[] {data[i], data[i + 1]};
bytelist.AddRange(hashmap[queryhash]);
i += 2;
}else if (data[i] == 0x13)
{
Console.Write("Count " + Convert.ToString(count, 16) + " ");
count++;
i++;
byte[] crcinput = new byte[9];
int sum = 0;
for (int j = 0; j < 9; j++)
{
bytelist.Add(data[i + j]);
crcinput[j] = data[i + j];
sum += data[i + j];
Console.Write(Convert.ToChar(data[i + j]));
}
var checksum = crc16.ComputeChecksumBytes(crcinput);
//checksum[0] = (byte)(~(int)checksum[0]);
//checksum[1] = (byte)(~(int)checksum[1]);
hashmap.Add(checksum, crcinput);
/*
sum = (sum % 4096);
var sumarr = new byte[] { (byte)((sum & 0xFF00) >> 16), (byte)(sum & 0x00FF) };
hashmap.Add(sumarr, crcinput);
*/
Console.WriteLine();
i += 9;
}
}
FileStream nfs = new FileStream("inflated_file", FileMode.Create);
nfs.Write(bytelist.ToArray(), 0, bytelist.Count);
nfs.Close();
fs.Close();
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment