public RawJTEX(Stream input) { using (var br = new BinaryReaderX(input)) { Stream stream; if (br.ReadByte() == 0x11) { br.BaseStream.Position = 0; uint size = br.ReadUInt32() >> 8; br.BaseStream.Position = 0; lz11_compressed = true; byte[] decomp = LZ11.Decompress(br.BaseStream); stream = new MemoryStream(decomp); } else { br.BaseStream.Position = 0; stream = br.BaseStream; } //File.OpenWrite("test.decomp").Write(new BinaryReaderX(stream).ReadBytes((int)stream.Length), 0, (int)stream.Length); using (BinaryReaderX br2 = new BinaryReaderX(stream)) { JTEXRawHeader = br2.ReadStruct <RawHeader>(); br2.BaseStream.Position = JTEXRawHeader.dataStart; Settings = new ImageSettings { Width = JTEXRawHeader.width, Height = JTEXRawHeader.height, Format = JTEXRawHeader.format }; Image = Common.Load(br2.ReadBytes((int)(br2.BaseStream.Length - br2.BaseStream.Position)), Settings); } } }
public bool Identify(string filename) { using (var br = new BinaryReaderX(File.OpenRead(filename))) { if (br.BaseStream.Length < 4) { return(false); } //check for compression if (br.ReadByte() == 0x11) { br.BaseStream.Position = 0; uint size = br.ReadUInt32() >> 8; br.BaseStream.Position = 0; byte[] decomp = LZ11.Decompress(br.BaseStream); if (decomp.Length == size) { if (new BinaryReaderX(new MemoryStream(decomp)).ReadString(4) == "F3XT") { return(true); } } } br.BaseStream.Position = 0; return(br.ReadString(4) == "F3XT"); } }
private static byte[] DescomprimirComLZ11(LZ11 LZ11, byte[] arquivo) { MemoryStream output = new MemoryStream(); LZ11.Decompress(new MemoryStream(arquivo), arquivo.Length, output); return(output.ToArray()); }
static void Test(byte[] bytes, Method method) { byte[] bytes2 = new byte[bytes.Length]; switch (method) { case Method.LZ10: bytes2 = LZ10.Decompress(new MemoryStream(LZ10.Compress(new MemoryStream(bytes))), bytes.Length); Assert.IsTrue(bytes.SequenceEqual(bytes2)); break; case Method.LZ11: bytes2 = LZ11.Decompress(new MemoryStream(LZ11.Compress(new MemoryStream(bytes))), bytes.Length); Assert.IsTrue(bytes.SequenceEqual(bytes2)); break; case Method.LZ40: bytes2 = LZ40.Decompress(new MemoryStream(LZ40.Compress(new MemoryStream(bytes))), bytes.Length); Assert.IsTrue(bytes.SequenceEqual(bytes2)); break; case Method.LZ77: bytes2 = LZ77.Decompress(new MemoryStream(LZ77.Compress(new MemoryStream(bytes)))); Assert.IsTrue(bytes.SequenceEqual(bytes2)); break; case Method.RevLZ77: bytes2 = RevLZ77.Decompress(new MemoryStream(RevLZ77.Compress(new MemoryStream(bytes)))); Assert.IsTrue(bytes.SequenceEqual(bytes2)); break; case Method.LZ4: bytes2 = LZ4.Decompress(new MemoryStream(LZ4.Compress(new MemoryStream(bytes)))); Assert.IsTrue(bytes.SequenceEqual(bytes2)); break; case Method.LZECD: bytes2 = LZECD.Decompress(new MemoryStream(LZECD.Compress(new MemoryStream(bytes)))); Assert.IsTrue(bytes.SequenceEqual(bytes2)); break; case Method.LZOvl: bytes2 = LZOvl.Decompress(new MemoryStream(LZOvl.Compress(new MemoryStream(bytes)))); Assert.IsTrue(bytes.SequenceEqual(bytes2)); break; case Method.MIO0: bytes2 = MIO0.Decompress(new MemoryStream(MIO0.Compress(new MemoryStream(bytes), ByteOrder.LittleEndian)), ByteOrder.LittleEndian); Assert.IsTrue(bytes.SequenceEqual(bytes2)); break; } }
private static byte[] DecompressOrCompress(LZ11 LZ11, byte[] arquivo, bool compress) { MemoryStream output = new MemoryStream(); if (compress) { _ = LZ11.Compress(new MemoryStream(arquivo), arquivo.Length, output); } else { _ = LZ11.Decompress(new MemoryStream(arquivo), arquivo.Length, output); } return(output.ToArray()); }
private Task <LoadThemeResults> LoadNullTheme_Execute(bool start) { var busyLoadingTheme = MainResources.Busy_LoadingTheme; var task = new Task <LoadThemeResults>(() => { var result = new LoadThemeResults { Loaded = false, Path = null, }; BusyText = busyLoadingTheme; Stream fs; if (!File.Exists("default_body_lz.bin")) { var res = Extensions.GetResources("body_lz\\.bin"); fs = (Stream)res.Values.First(); } else { fs = File.OpenRead("default_body_lz.bin"); } using (fs) using (var ms = new MemoryStream()) { try { LZ11.Decompress(fs, fs.Length, ms); ms.Position = 0; result.Theme = Theme.Read(ms); result.Loaded = true; } catch { return(result); } } return(result); }); if (start) { task.Start(); } return(task); }
public F3XT(Stream input) { using (BinaryReaderX br = new BinaryReaderX(input)) { BinaryReaderX stream; //check for lz11 compression if (br.ReadByte() == 0x11) { br.BaseStream.Position = 0; byte[] decomp = LZ11.Decompress(br.BaseStream); br.BaseStream.Position = 0; uint size = br.ReadUInt32() >> 8; if (decomp.Length == size) { lz11_compressed = true; } stream = new BinaryReaderX(new MemoryStream(decomp, 0, decomp.Length)); } else { br.BaseStream.Position = 0; stream = new BinaryReaderX(input); } //map the file header = stream.ReadStruct <Header>(); settings = new ImageSettings { Width = header.width, Height = header.height, Format = ImageSettings.ConvertFormat(header.format), PadToPowerOf2 = false }; stream.BaseStream.Position = header.dataStart; //throw new Exception((stream.BaseStream.Length - stream.BaseStream.Position).ToString()); Image = Common.Load(stream.ReadBytes((int)(stream.BaseStream.Length - stream.BaseStream.Position)), settings); } }
public static void Decompress(object sender, EventArgs e) { var tsi = sender as ToolStripMenuItem; if (!PrepareFiles("Open a " + tsi.Tag.ToString() + " compressed file...", "Save your decompressed file...", ".decomp", out FileStream openFile, out FileStream saveFile)) { return; } try { using (openFile) using (var outFs = new BinaryWriterX(saveFile)) switch (tsi.Tag) { case Compression.Level5: outFs.Write(Level5.Decompress(openFile)); break; case Compression.GZip: outFs.Write(GZip.Decompress(openFile)); break; case Compression.Huff4: outFs.Write(Huffman.Decompress(openFile, 4)); break; case Compression.Huff8: outFs.Write(Huffman.Decompress(openFile, 8)); break; case Compression.LZ10: outFs.Write(LZ10.Decompress(openFile)); break; case Compression.LZ11: outFs.Write(LZ11.Decompress(openFile)); break; case Compression.LZ77: outFs.Write(LZ77.Decompress(openFile)); break; /*case Compression.LZSS: * outFs.Write(LZSS.Decompress(openFile, LZSS.GetDecompressedSize(openFile))); * break;*/ case Compression.RevLZ77: outFs.Write(RevLZ77.Decompress(openFile)); break; case Compression.RLE: outFs.Write(RLE.Decompress(openFile)); break; case Compression.ZLib: outFs.Write(ZLib.Decompress(openFile)); break; } } catch (Exception ex) { MessageBox.Show(ex.ToString(), tsi?.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } MessageBox.Show($"Successfully decompressed {Path.GetFileName(openFile.Name)}.", tsi?.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); }
private Task <LoadThemeResults> LoadTheme_Execute(string path, bool start) { var busyPickingFile = MainResources.Busy_PickingFile; var busyLoadingTheme = MainResources.Busy_LoadingTheme; var task = new Task <LoadThemeResults>(() => { var result = new LoadThemeResults { Loaded = false, Path = path, }; if (string.IsNullOrEmpty(result.Path)) { BusyText = busyPickingFile; var opfl = new OpenFileDialog { Filter = "3DS Theme File|*.bin", Multiselect = false }; var dlg = opfl.ShowDialog(); if (dlg.HasValue && dlg.Value) { result.Path = opfl.FileName; } } if (string.IsNullOrEmpty(result.Path)) { return(result); } var themeDir = Path.GetDirectoryName(result.Path) ?? "."; BusyText = busyLoadingTheme; using (var fs = File.OpenRead(result.Path)) using (var ms = new MemoryStream()) { try { LZ11.Decompress(fs, fs.Length, ms); ms.Position = 0; result.Theme = Theme.Read(ms); #if DEBUG ms.Seek(0, SeekOrigin.Begin); File.WriteAllBytes("dump.bin", ms.ToArray()); #endif result.Loaded = true; } catch { // Ignore } } var smdhPath = Path.Combine(themeDir, "info.smdh"); if (result.Loaded && File.Exists(smdhPath)) { using (var fs = File.OpenRead(smdhPath)) { try { result.Info = SMDH.Read(fs); } catch { result.Info = null; } } } return(result); }); if (start) { task.Start(); } return(task); }
private void openButton_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "Binary files (*.bin)|*.bin|All files (*.*)|*.*"; if (openFileDialog.ShowDialog() != DialogResult.OK) { return; } long length = (new FileInfo(openFileDialog.FileName)).Length; if (length > saveLength) { MessageBox.Show("Invalid save file", "Error"); return; } // Open a decompressed save file, for testing purpose if (length == saveLength) { Header = null; SaveData = File.ReadAllBytes(openFileDialog.FileName); enableButtons(); return; } Header = new byte[headerLength]; byte[] compressed = new byte[length - headerLength]; using (FileStream fs = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read)) { using (BinaryReader br = new BinaryReader(fs)) { br.BaseStream.Seek(headerLength, SeekOrigin.Begin); byte isLZ11 = br.ReadByte(); if (isLZ11 != 0x11) { MessageBox.Show("Invalid save file", "Error"); return; } br.BaseStream.Seek(0x00, SeekOrigin.Begin); br.Read(Header, 0x0, headerLength); br.Read(compressed, 0x0, (int)length - headerLength); } } // Decompress byte[] decompressed = null; LZ11 lz11 = new LZ11(); using (MemoryStream inStream = new MemoryStream(compressed)) { using (MemoryStream outStream = new MemoryStream()) { lz11.Decompress(inStream, compressed.Length, outStream); if (outStream != null) { decompressed = outStream.ToArray(); } else { MessageBox.Show("Invalid save file", "Error"); return; } } } // Check file validity and save loading if (decompressed.Length != saveLength) { MessageBox.Show("Invalid save file", "Error"); return; } SaveData = decompressed; enableButtons(); }