public static byte[] UnZlib(byte[] bytes) { try { MemoryStream ms = new MemoryStream(bytes); ZInputStream zs = new ZInputStream(ms); MemoryStream mz = new MemoryStream(); byte[] buffer = new byte[BUFFER_SIZE]; int read; do { read = zs.read(buffer, 0, BUFFER_SIZE); if (read > 0) { mz.Write(buffer, 0, read); } }while (read > 0); ms.Close(); zs.Close(); byte[] retVal = mz.ToArray(); mz.Close(); return(retVal); } catch { return(null); } }
private void PrepareNextPacket() { byte b = (byte)this.baseStream.ReadByte(); byte b2 = (byte)this.baseStream.ReadByte(); byte b3 = (byte)this.baseStream.ReadByte(); int num = (int)b + ((int)b2 << 8) + ((int)b3 << 16); this.baseStream.ReadByte(); int num2 = this.baseStream.ReadByte() + (this.baseStream.ReadByte() << 8) + (this.baseStream.ReadByte() << 16); if (num2 == 0) { num2 = num; this.zInStream = null; } else { this.ReadNextPacket(num); MemoryStream in_Renamed = new MemoryStream(this.inBuffer); this.zInStream = new ZInputStream(in_Renamed); this.zInStream.maxInput = (long)num; } this.inPos = 0; this.maxInPos = num2; }
public static void Uncompress(Stream input, Stream output, int uncompressedSize, byte[] buff, CancellationToken cancelationToken, Action <long> uncompressed = null) { Exceptions.CheckArgumentNull(input, "input"); Exceptions.CheckArgumentNull(output, "output"); Exceptions.CheckArgumentOutOfRangeException(uncompressedSize, "uncompressedSize", 0, int.MaxValue); ZInputStream reader = new ZInputStream(input); int readed; while (uncompressedSize > 0 && (readed = reader.read(buff, 0, Math.Min(buff.Length, uncompressedSize))) > 0) { if (cancelationToken.IsCancellationRequested) { return; } uncompressedSize -= readed; output.Write(buff, 0, readed); uncompressed.NullSafeInvoke(readed); } if (uncompressedSize != 0) { throw new Exception("Неожиданный конец потока."); } }
private byte[] GetContentHelperFunc(FileStream fStream) { var buffer = new byte[FileSize]; //Will contain compressed data fStream.Seek(FileOffset, SeekOrigin.Begin); fStream.Read(buffer, 0, (int)FileSize); try { var mStream = new MemoryStream(buffer); var zinput = new ZInputStream(mStream); var dBuffer = new List <byte>(); //decompressed buffer, arraylist to my knowledge... //This could be optimized in the future by reading a block and adding it to our arraylist.. //which would be much faster, obviously int data; while ((data = zinput.Read()) != -1) { dBuffer.Add((byte)data); } return(dBuffer.ToArray()); } catch { //it's not compressed, just return original content return(buffer); } }
private void PrepareNextPacket() { byte num = (byte)this.baseStream.ReadByte(); byte num2 = (byte)this.baseStream.ReadByte(); byte num3 = (byte)this.baseStream.ReadByte(); int len = (num + (num2 << 8)) + (num3 << 0x10); this.baseStream.ReadByte(); int num5 = (this.baseStream.ReadByte() + (this.baseStream.ReadByte() << 8)) + (this.baseStream.ReadByte() << 0x10); if (num5 == 0) { num5 = len; this.zInStream = null; } else { this.ReadNextPacket(len); MemoryStream stream = new MemoryStream(this.inBuffer); this.zInStream = new ZInputStream(stream); this.zInStream.maxInput = len; } this.inPos = 0; this.maxInPos = num5; }
public static byte[] LoadDLL(Stream stream) { if (stream == null) { return(null); } byte[] lenBytes = new byte[4]; stream.Read(lenBytes, 0, 4); int len = System.Net.IPAddress.NetworkToHostOrder((int)BitConverter.ToUInt32(lenBytes, 0)); stream.Read(lenBytes, 0, 4); int decryLen = System.Net.IPAddress.NetworkToHostOrder((int)BitConverter.ToUInt32(lenBytes, 0)); var trans = m_netCrypte.GetCryptoTransform(); byte[] srcBytes = new byte[len]; byte[] dbytes = new byte[len]; stream.Read(srcBytes, 0, (int)stream.Length - 8); trans.TransformBlock(srcBytes, 0, (int)stream.Length - 8, dbytes, 0); MemoryStream ms = new MemoryStream(dbytes, 0, decryLen, false); var zos = new ZInputStream(ms); MemoryStream output = new MemoryStream(srcBytes, true); int tlen = 0; while ((tlen = zos.read(m_tempBuffer, 0, m_tempBuffer.Length)) > 0) { output.Write(m_tempBuffer, 0, tlen); } ; zos.Close(); return(srcBytes); }
private void PrepareNextPacket() { // read off the uncompressed and compressed lengths byte b1 = (byte)baseStream.ReadByte(); byte b2 = (byte)baseStream.ReadByte(); byte b3 = (byte)baseStream.ReadByte(); int compressedLength = b1 + (b2 << 8) + (b3 << 16); baseStream.ReadByte(); // seq int unCompressedLength = baseStream.ReadByte() + (baseStream.ReadByte() << 8) + (baseStream.ReadByte() << 16); if (unCompressedLength == 0) { unCompressedLength = compressedLength; zInStream = null; } else { ReadNextPacket(compressedLength); MemoryStream ms = new MemoryStream(inBuffer); zInStream = new ZInputStream(ms); zInStream.maxInput = compressedLength; } inPos = 0; maxInPos = unCompressedLength; }
/// <summary> /// Returns the content of the actual file (extracts from raf archive) /// </summary> public byte[] GetContent() { if (inMemory) { throw new Exception("Invalid call to GetContent, this entry is only in memory, and has not been linked to the DAT file yet."); } byte[] buffer = new byte[this.FileSize]; //Will contain compressed data //lock (this.raf) //No longer necessary { //Todo: Since we are no longer modifying the data file content stream, // it would be valid to create the stream more than once. // We could then work WHILE reading. FileStream fStream = new FileStream(archive.DatFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //this.raf.GetDataFileContentStream(); fStream.Seek(this.FileOffset, SeekOrigin.Begin); fStream.Read(buffer, 0, (int)this.FileSize); fStream.Close(); } try { // using (var outputMs = new MemoryStream()) { // // var deflate = new DeflateStream(new MemoryStream(buffer, 2, buffer.Length - 2), CompressionMode.Decompress); // deflate.CopyTo(outputMs); // return outputMs.ToArray(); // } ZInputStream zinput = new ZInputStream(new MemoryStream(buffer)); MemoryStream ms = new MemoryStream(); int data = 0; while ((data = zinput.Read()) != -1) { ms.WriteByte((byte)data); } return(ms.ToArray()); // new DeflateStream() // // //List<byte> dBuffer = new List<byte>(); //decompressed buffer, arraylist to my knowledge... // // MemoryStream ms = new MemoryStream(); // // //This could be optimized in the future by reading a block and adding it to our arraylist.. // //which would be much faster, obviously // int data = 0; // while ((data = zinput.Read()) != -1) // ms.WriteByte((byte)data); // //dBuffer.Add((byte)data); // //ComponentAce.Compression.Libs.zlib.ZStream a = new ComponentAce.Compression.Libs.zlib.ZStream(); // // //File.WriteAllBytes((dumpDir + entry.FileName).Replace("/", "\\"), dBuffer.ToArray()); // return ms.ToArray(); } catch (Exception e) { Console.WriteLine(e); //it's not compressed, just return original content return(buffer); } }
public static byte[] Uncompress(Stream input, int uncompressedSize) { byte[] buff = new byte[uncompressedSize]; ZInputStream reader = new ZInputStream(input); reader.EnsureRead(buff, 0, uncompressedSize); return(buff); }
public static byte[] Decompress(byte[] data) { using (var input = new MemoryStream(data)) using (var decompressor = new ZInputStream(input)) { decompressor.CopyTo(input); return(input.ToArray()); } }
public static byte[] ZLibDecompress(byte[] CompData, int Offset, int DecompLength) { byte[] buffer = new byte[CompData.Length - Offset]; Array.Copy((Array)CompData, Offset, (Array)buffer, 0, buffer.Length); ZInputStream zinputStream = new ZInputStream((Stream) new MemoryStream(buffer)); byte[] b = new byte[DecompLength]; zinputStream.read(b, 0, DecompLength); zinputStream.Close(); return(b); }
internal static void DecompressData(byte[] inData, out byte[] outData) { try { using (Stream inMemoryStream = new MemoryStream(inData)) using (ZInputStream outZStream = new ZInputStream(inMemoryStream)) { MemoryStream outMemoryStream = new MemoryStream(); CopyStream(outZStream, outMemoryStream); outData = outMemoryStream.ToArray(); } } catch { outData = new byte[0]; } }
static private void ReadStrings(ZInputStream Inflater, int count, string[] target) { byte[] byte2 = new byte[2]; for (int i = 0; i < count; ++i) { if (Inflater.Read(byte2) == 0) { throw new Exception("Error: byte = 0"); } int length = ByteConverter.getShort(byte2, 0); byte[] message = new byte[length]; Inflater.Read(message); target[i] = Encoding.UTF8.GetString(message); } }
private static byte[] Decompress(byte[] input, int ilen = 0) { MemoryStream ms = new MemoryStream(input, 0, ilen == 0 ? input.Length : ilen, false); var zos = new ZInputStream(ms); MemoryStream output = new MemoryStream(input.Length * 5); int len = 0; while ((len = zos.read(m_tempBuffer, 0, m_tempBuffer.Length)) > 0) { output.Write(m_tempBuffer, 0, len); } ; zos.Close(); return(output.ToArray()); }
public byte[] GetContent(int limit) { CompressedData instance = CompressedData.GetInstance(contentInfo.Content); ContentInfo encapContentInfo = instance.EncapContentInfo; Asn1OctetString asn1OctetString = (Asn1OctetString)encapContentInfo.Content; ZInputStream inStream = new ZInputStream(new MemoryStream(asn1OctetString.GetOctets(), writable: false)); try { return(CmsUtilities.StreamToByteArray(inStream, limit)); } catch (IOException e) { throw new CmsException("exception reading compressed stream.", e); } }
public static void DecompressFile(string inFile, string outFile) { int data; const int stopByte = -1; var outFileStream = new FileStream(outFile, FileMode.Create); var inZStream = new ZInputStream(File.Open(inFile, FileMode.Open, FileAccess.Read)); while (stopByte != (data = inZStream.Read())) { var databyte = (byte)data; outFileStream.WriteByte(databyte); } inZStream.Close(); outFileStream.Close(); }
/// <summary> /// Unpacks zipped data. /// </summary> /// <param name="str">In Stream.</param> /// <param name="outStream">Out stream.</param> /// <param name = "plainLen">Data size after decompress.</param> /// <param name = "rewind">Manual control for stream seek position.</param> public static void Unzip(Stream str, Stream outStream, bool rewind = true) { int len; var buffer = new byte[65536]; var zOutputStream = new ZInputStream(str); while ((len = zOutputStream.read(buffer, 0, buffer.Length)) > 0) { outStream.Write(buffer, 0, len); } zOutputStream.Close(); buffer = null; if (rewind) { outStream.Position = 0; outStream.Flush(); } }
public static OSD ZDecompressBytesToOsd(byte[] input) { OSD osd = null; using (MemoryStream msSinkUnCompressed = new MemoryStream()) { using (ZInputStream zOut = new ZInputStream(msSinkUnCompressed)) { zOut.Read(input, 0, input.Length); msSinkUnCompressed.Seek(0L, SeekOrigin.Begin); osd = OSDParser.DeserializeLLSDBinary(msSinkUnCompressed.ToArray()); zOut.Close(); } } return(osd); }
public override int Read(byte[] buffer, int offset, int count) { if (buffer == null) { throw new ArgumentNullException("buffer", Resources.BufferCannotBeNull); } if (offset < 0 || offset >= buffer.Length) { throw new ArgumentOutOfRangeException("offset", Resources.OffsetMustBeValid); } if ((offset + count) > buffer.Length) { throw new ArgumentException(Resources.BufferNotLargeEnough, "buffer"); } if (inPos == maxInPos) { PrepareNextPacket(); } int countToRead = Math.Min(count, maxInPos - inPos); int countRead; if (zInStream != null) { countRead = zInStream.read(buffer, offset, countToRead); } else { countRead = baseStream.Read(buffer, offset, countToRead); } inPos += countRead; // release the weak reference if (inPos == maxInPos) { zInStream = null; if (!Platform.IsMono()) { inBufferRef = new WeakReference(inBuffer, false); inBuffer = null; } } return(countRead); }
private static void UncompressFile(string inFile, string outFile) { // Do it slow way because calling CopyStream sometimes causes an inflated exception on LoL comrpessed files int stopByte = -1; System.IO.FileStream outFileStream = new System.IO.FileStream(outFile, System.IO.FileMode.Create); ZInputStream inZStream = new ZInputStream(System.IO.File.Open(inFile, System.IO.FileMode.Open, System.IO.FileAccess.Read)); int data; while (stopByte != (data = inZStream.Read())) { byte _dataByte = (byte)data; outFileStream.WriteByte(_dataByte); } inZStream.Close(); outFileStream.Close(); }
public static void uncompressFile(string inFile, string outFile) { int data = 0; int stopByte = -1; System.IO.FileStream outFileStream = new System.IO.FileStream(outFile, System.IO.FileMode.Create); ZInputStream inZStream = new ZInputStream(System.IO.File.Open(inFile, System.IO.FileMode.Open, System.IO.FileAccess.Read)); while (stopByte != (data = inZStream.Read())) { byte _dataByte = (byte)data; outFileStream.WriteByte(_dataByte); } inZStream.Close(); outFileStream.Close(); }
private void DecryptEncryptedDataStream(Stream outputPlaintextStream, ICryptoTransform decryptor, AxCryptDataStream encryptedDataStream, ProgressContext progress) { Exception savedExceptionIfCloseCausesCryptographicException = null; try { if (DocumentHeaders.IsCompressed) { using (CryptoStream deflatedPlaintextStream = new CryptoStream(encryptedDataStream, decryptor, CryptoStreamMode.Read)) { using (ZInputStream inflatedPlaintextStream = new ZInputStream(deflatedPlaintextStream)) { try { CopyToWithCount(inflatedPlaintextStream, outputPlaintextStream, encryptedDataStream, progress); } catch (Exception ex) { savedExceptionIfCloseCausesCryptographicException = ex; throw; } } } } else { using (Stream plainStream = new CryptoStream(encryptedDataStream, decryptor, CryptoStreamMode.Read)) { try { CopyToWithCount(plainStream, outputPlaintextStream, encryptedDataStream, progress); } catch (Exception ex) { savedExceptionIfCloseCausesCryptographicException = ex; throw; } } } } catch (CryptographicException) { throw savedExceptionIfCloseCausesCryptographicException; } }
/** * Return the uncompressed content, throwing an exception if the data size * is greater than the passed in limit. If the content is exceeded getCause() * on the CMSException will contain a StreamOverflowException * * @param limit maximum number of bytes to read * @return the content read * @throws CMSException if there is an exception uncompressing the data. */ public byte[] GetContent(int limit) { CompressedData comData = CompressedData.GetInstance(contentInfo.Content); ContentInfo content = comData.EncapContentInfo; Asn1OctetString bytes = (Asn1OctetString)content.Content; ZInputStream zIn = new ZInputStream(new MemoryStream(bytes.GetOctets(), false)); try { return(CmsUtilities.StreamToByteArray(zIn, limit)); } catch (IOException e) { throw new CmsException("exception reading compressed stream.", e); } }
public static byte[] Decompress(byte[] input) { MemoryStream ms = new MemoryStream(input); var zos = new ZInputStream(ms); MemoryStream output = new MemoryStream(); byte[] temp = new byte[4096]; int len = 0; while ((len = zos.read(temp, 0, temp.Length)) > 0) { output.Write(temp, 0, len); } ; zos.Close(); return(output.ToArray()); }
public static byte[] Decompress(byte[] compressed, int decompressedSize, byte compressionFlags, bool chunked = false) { switch ((CompressionMethod)(compressionFlags & 0x0F)) { case CompressionMethod.None: return(compressed); case CompressionMethod.Zlib: { using (var compressedStream = new MemoryStream(compressed)) using (var decompressedStream = new MemoryStream()) using (var stream = new ZInputStream(compressedStream)) { byte[] buf = new byte[0x10000]; int length = 0; while ((length = stream.read(buf, 0, buf.Length)) > 0) { decompressedStream.Write(buf, 0, length); } return(decompressedStream.ToArray()); } } case CompressionMethod.LZ4: if (chunked) { var decompressed = Native.LZ4FrameCompressor.Decompress(compressed); return(decompressed); } else { var decompressed = new byte[decompressedSize]; LZ4Codec.Decode(compressed, 0, compressed.Length, decompressed, 0, decompressedSize, true); return(decompressed); } default: { var msg = String.Format("No decompressor found for this format: {0}", compressionFlags); throw new InvalidDataException(msg); } } }
/** * Return the uncompressed content. * * @return the uncompressed content * @throws CmsException if there is an exception uncompressing the data. */ public byte[] GetContent() { CompressedData comData = CompressedData.GetInstance(ContentInfoInternal.Content); ContentInfo content = comData.EncapContentInfo; var bytes = (Asn1OctetString)content.Content; using (var zIn = new ZInputStream(bytes.GetOctetStream())) { try { return(CmsUtilities.StreamToByteArray(zIn)); } catch (IOException e) { throw new CmsException("exception reading compressed stream.", e); } } }
public override int Read(byte[] buffer, int offset, int count) { if (buffer == null) { throw new ArgumentNullException("buffer", System.Data.MySqlClient.Properties.Resources.BufferCannotBeNull); } if (offset < 0 || offset >= buffer.Length) { throw new ArgumentOutOfRangeException("offset", System.Data.MySqlClient.Properties.Resources.OffsetMustBeValid); } if ((offset + count) > buffer.Length) { throw new ArgumentException(System.Data.MySqlClient.Properties.Resources.BufferNotLargeEnough, "buffer"); } if (inPos == maxInPos) { PrepareNextPacket(); } int countToRead = Math.Min(count, maxInPos - inPos); int countRead; if (zInStream != null) { countRead = zInStream.read(buffer, offset, countToRead); } else { countRead = baseStream.Read(buffer, offset, countToRead); } inPos += countRead; // release the weak reference if (inPos == maxInPos) { zInStream = null; inBufferRef.Target = inBuffer; inBuffer = null; } return(countRead); }
private byte[] DecompressBytes(ARZFile arzFile) { // Read in the compressed data and decompress it, storing the results in a memorystream FileStream arzStream = new FileStream(arzFile.m_filename, FileMode.Open, FileAccess.Read, FileShare.Read); try { arzStream.Seek(m_offset, SeekOrigin.Begin); // Create a decompression stream ZInputStream zinput = new ZInputStream(arzStream); // Create a memorystream to hold the decompressed data MemoryStream outStream = new MemoryStream(); try { // Now decompress byte[] buffer = new byte[1024]; int len; while ((len = zinput.read(buffer, 0, 1024)) > 0) { outStream.Write(buffer, 0, len); } // Now create a final Byte array to hold the answer byte[] ans = new byte[(int)zinput.TotalOut]; // Copy the data into it Array.Copy(outStream.GetBuffer(), ans, (int)zinput.TotalOut); // Return the decompressed data return(ans); } finally { outStream.Close(); } } finally { arzStream.Close(); } }
public byte[] DecompressPacket(byte[] Payload, int Offset) { MemoryStream ms = new MemoryStream(Payload.GetUpperBound(0) - Offset); ms.Write(Payload, Offset, Payload.GetUpperBound(0) - Offset); ms.Seek(0, System.IO.SeekOrigin.Begin); ZInputStream zs = new ZInputStream(ms); int UncompressedSize; byte[] Uncompressed = new byte[4096]; try { UncompressedSize = zs.read(Uncompressed, 0, 4096); } catch { if (DEBUG) { Debug("DECOMPRESSION FAILURE"); } Array.Copy(Payload, Offset - 1, Uncompressed, 0, Payload.Length - (Offset - 1)); UncompressedSize = Payload.Length - (Offset - 1); } zs.Close(); zs.Dispose(); ms.Close(); ms.Dispose(); Array.Resize(ref Uncompressed, UncompressedSize); return(Uncompressed); }
public byte[] GetContent(int limit) { //IL_002b: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Expected O, but got Unknown //IL_0043: Expected O, but got Unknown CompressedData instance = CompressedData.GetInstance(contentInfo.Content); ContentInfo encapContentInfo = instance.EncapContentInfo; Asn1OctetString asn1OctetString = (Asn1OctetString)encapContentInfo.Content; ZInputStream inStream = new ZInputStream((Stream) new MemoryStream(asn1OctetString.GetOctets(), false)); try { return(CmsUtilities.StreamToByteArray((Stream)(object)inStream, limit)); } catch (IOException val) { IOException e = val; throw new CmsException("exception reading compressed stream.", (global::System.Exception)(object) e); } }
public static void main(String[] args) { try { java.io.ByteArrayOutputStream outJ = new java.io.ByteArrayOutputStream(); ZOutputStream zOut = new ZOutputStream(outJ, JZlib.Z_BEST_COMPRESSION); String hello = "Hello World!"; //java.io.ObjectOutputStream objOut = new java.io.ObjectOutputStream(zOut); //objOut.writeObject(hello); outJ.write(hello.getBytes()); zOut.close(); java.io.ByteArrayInputStream inJ = new java.io.ByteArrayInputStream(outJ.toByteArray()); ZInputStream zIn = new ZInputStream(inJ); //java.io.ObjectInputStream objIn=new java.io.ObjectInputStream(zIn); byte[] buffer = new byte[hello.length()]; inJ.read(buffer); java.lang.SystemJ.outJ.println(new java.lang.StringJ(buffer).ToString() /*objIn.readObject()*/); } catch (java.lang.Exception e) { e.printStackTrace(); } }