public virtual int sceZlibDecompress(TPointer outBufferAddr, int outBufferLength, TPointer inBufferAddr, TPointer32 crc32Addr) { sbyte[] inBuffer = new sbyte[4096]; sbyte[] outBuffer = new sbyte[4096]; int inBufferPtr = 0; IMemoryReader reader = MemoryReader.getMemoryReader(inBufferAddr.Address, 1); IMemoryWriter writer = MemoryWriter.getMemoryWriter(outBufferAddr.Address, outBufferLength, 1); CRC32 crc32 = new CRC32(); Inflater inflater = new Inflater(); while (!inflater.finished()) { if (inflater.needsInput()) { for (inBufferPtr = 0; inBufferPtr < inBuffer.Length; ++inBufferPtr) { inBuffer[inBufferPtr] = (sbyte)reader.readNext(); } inflater.Input = inBuffer; } try { int count = inflater.inflate(outBuffer); if (inflater.TotalOut > outBufferLength) { Console.WriteLine(string.Format("sceZlibDecompress : zlib decompress buffer too small inBuffer={0}, outLength={1:D}", inBufferAddr, outBufferLength)); return(SceKernelErrors.ERROR_INVALID_SIZE); } crc32.update(outBuffer, 0, count); for (int i = 0; i < count; ++i) { writer.writeNext(outBuffer[i] & 0xFF); } } catch (DataFormatException) { Console.WriteLine(string.Format("sceZlibDecompress : malformed zlib stream inBuffer={0}", inBufferAddr)); return(SceKernelErrors.ERROR_INVALID_FORMAT); } } writer.flush(); crc32Addr.setValue((int)crc32.Value); return(inflater.TotalOut); }