Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Reflection;
- using System.Security.Cryptography; // HashAlgorithm
- using Ionic.Zlib;
- namespace DeflateTest
- {
- class Program
- {
- static void Main(string[] args)
- {
- Byte[] compressed;
- BinaryReader reader = new BinaryReader(File.Open("D:\\TITLE_MENU.TPK", FileMode.Open));
- BinaryWriter write = new BinaryWriter(File.Open("D:\\testout.bin", FileMode.Create));
- UInt32 magicNumber = reader.ReadUInt32();
- UInt32 uncompressedSize = reader.ReadUInt32();
- UInt32 unknown = reader.ReadUInt32();
- compressed = reader.ReadBytes((int)(reader.BaseStream.Length - 0x0C));
- Byte[] output = new Byte[uncompressedSize];
- ZlibCodec compressor = new ZlibCodec();
- compressor.InitializeInflate(true);
- compressor.InputBuffer = compressed;
- compressor.AvailableBytesIn = compressed.Length;
- compressor.NextIn = 0;
- compressor.OutputBuffer = output;
- foreach (var f in new FlushType[] { FlushType.None, FlushType.Finish })
- {
- int bytesToWrite = 0;
- do
- {
- compressor.AvailableBytesOut = (int)uncompressedSize;
- compressor.NextOut = 0;
- compressor.Inflate(f);
- bytesToWrite = (int)(uncompressedSize - compressor.AvailableBytesOut);
- if (bytesToWrite > 0)
- write.Write(output, 0, bytesToWrite);
- }
- while ((f == FlushType.None && (compressor.AvailableBytesIn != 0 || compressor.AvailableBytesOut == 0)) ||
- (f == FlushType.Finish && bytesToWrite != 0));
- }
- compressor.EndInflate();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement