static byte[] Decompress(byte[] data) { if (!QuickLZ.IsCompressed(data)) { return(data); } return(QuickLZ.Decompress(data)); }
public IPacket ReadPacket() { byte[] packetBytes = QuickLZ.Decompress(ReadData()); using (var ms = new MemoryStream(packetBytes)) { PacketReceived?.Invoke(this, EventArgs.Empty); return((IPacket)serializer.Deserialize(ms)); } }
public EmbeddedResource MergeResources() { if (encryptedResource.Resource == null) { return(null); } DeobUtils.DecryptAndAddResources(module, encryptedResource.Resource.Name.String, () => { return(QuickLZ.Decompress(encryptedResource.Decrypt())); }); return(encryptedResource.Resource); }
public AsmNet(byte[] data) { byte[] payload = new byte[data.Length]; Array.Copy(data, payload, payload.Length); payload = QuickLZ.Decompress(payload, 0); int ReadOffset = 0; byte[] DataSectionBytes = new byte[BitConverter.ToInt32(payload, ReadOffset)]; ReadOffset += 4; Array.Copy(payload, 4, DataSectionBytes, 0, DataSectionBytes.Length); ReadOffset += DataSectionBytes.Length; byte[] CodeSectionBytes = new byte[BitConverter.ToInt32(payload, ReadOffset)]; ReadOffset += 4; Array.Copy(payload, ReadOffset, CodeSectionBytes, 0, CodeSectionBytes.Length); ReadOffset += CodeSectionBytes.Length; byte[] ApiSectionBytes = new byte[BitConverter.ToInt32(payload, ReadOffset)]; ReadOffset += 4; Array.Copy(payload, ReadOffset, ApiSectionBytes, 0, ApiSectionBytes.Length); ReadOffset += ApiSectionBytes.Length; byte[] DataSectionChecksum = new byte[16]; byte[] CodeSectionChecksum = new byte[16]; byte[] ApiSectionChecksum = new byte[16]; Array.Copy(payload, ReadOffset, DataSectionChecksum, 0, 16); Array.Copy(payload, ReadOffset + 16, CodeSectionChecksum, 0, 16); Array.Copy(payload, ReadOffset + 32, ApiSectionChecksum, 0, 16); for (int i = 0; i < DataSectionBytes.Length; i++) { DataSectionBytes[i] ^= DataSectionChecksum[i % DataSectionChecksum.Length]; } for (int i = 0; i < CodeSectionBytes.Length; i++) { CodeSectionBytes[i] ^= CodeSectionChecksum[i % CodeSectionChecksum.Length]; } for (int i = 0; i < ApiSectionBytes.Length; i++) { ApiSectionBytes[i] ^= ApiSectionChecksum[i % ApiSectionChecksum.Length]; } ApiSection = new src.Sections.ApiSection(ApiSectionBytes); DataSection = new DataSection(DataSectionBytes); this.CodeSectionReader = new OpcodeReader(CodeSectionBytes, DataSection, ApiSection); this.DataSectionReader = new OpcodeReader(DataSectionBytes, DataSection, ApiSection); Instructions = CodeSectionReader.ReadAllInstructions(); }
private static void RunGeneralTest(int level) { byte[] original = File.ReadAllBytes("./Flower.bmp"); var qlz = new QuickLZ(level); int sizeC = qlz.SizeCompressed(original); var compressedBytes = new byte[sizeC]; qlz.Compress(original, compressedBytes, original.Length); var result = new byte[original.Length]; qlz.Decompress(compressedBytes, result); for (int i = 0; i < original.Length; i++) { Assert.AreEqual(original[i], result[i]); } }
public EmbeddedResource MergeResources() { if (encryptedResource.Resource == null) { return(null); } DeobUtils.DecryptAndAddResources(module, encryptedResource.Resource.Name.String, () => { try { return(QuickLZ.Decompress(encryptedResource.Decrypt())); } catch { try { return(DeobUtils.Inflate(encryptedResource.Decrypt(), true)); } catch { return(null); } } }); return(encryptedResource.Resource); }
public override int Read(byte[] destBuffer, int offset, int count) { //lastChecksum = md5.ComputeHash(destBuffer); //if(count == 0) return 0; tempBuffer = new byte[count]; //internalOffset = offset; /*while(internalOffset < compressorBufferSize || (read = inputStream.Read(tempBuffer, offset+internalOffset, count-read)) > 0){ * internalOffset += read; * }*/ int read = inputStream.Read(tempBuffer, offset, count); //if(read < minBlockSize){ //} //else destBuffer = QuickLZ.Decompress(tempBuffer); //QuickLZ. //if(read == 0) return 0; //Console.WriteLine("CompressorStream : read "+read+", compressed to "+destBuffer.Length); return(QuickLZ.sizeDecompressed(tempBuffer)); }
static int SPICES_QCLZ_SIG = 0x3952534E; // "9RSN" public static byte[] Decompress(byte[] data) { if (Read32(data, 0) == SPICES_QCLZ_SIG) { return(QuickLZ.Decompress(data, SPICES_QCLZ_SIG)); } int headerLength, decompressedLength, compressedLength; if ((data[0] & 2) != 0) { headerLength = 9; compressedLength = (int)Read32(data, 1); decompressedLength = (int)Read32(data, 5); } else { headerLength = 3; compressedLength = data[1]; decompressedLength = data[2]; } bool isCompressed = (data[0] & 1) != 0; byte[] decompressed = new byte[decompressedLength]; if (isCompressed) { Decompress(data, headerLength, decompressed); } else { Copy(data, headerLength, decompressed, 0, decompressed.Length); } return(decompressed); }
private static bool TryFetchPacket(RingQueue <IncomingPacket> packetQueue, out IncomingPacket packet) { if (packetQueue.Count <= 0) { packet = null; return(false); } int take = 0; int takeLen = 0; bool hasStart = false; bool hasEnd = false; for (int i = 0; i < packetQueue.Count; i++) { IncomingPacket peekPacket; if (packetQueue.TryPeekStart(i, out peekPacket)) { take++; takeLen += peekPacket.Size; if (peekPacket.FragmentedFlag) { if (!hasStart) { hasStart = true; } else if (!hasEnd) { hasEnd = true; break; } } else { if (!hasStart) { hasStart = true; hasEnd = true; break; } } } else { break; } } if (!hasStart || !hasEnd) { packet = null; return(false); } // GET if (!packetQueue.TryDequeue(out packet)) { throw new InvalidOperationException("Packet in queue got missing (?)"); } if (take > 1) // MERGE { var preFinalArray = new byte[takeLen]; // for loop at 0th element int curCopyPos = packet.Size; Array.Copy(packet.Data, 0, preFinalArray, 0, packet.Size); for (int i = 1; i < take; i++) { IncomingPacket nextPacket = null; if (!packetQueue.TryDequeue(out nextPacket)) { throw new InvalidOperationException("Packet in queue got missing (?)"); } Array.Copy(nextPacket.Data, 0, preFinalArray, curCopyPos, nextPacket.Size); curCopyPos += nextPacket.Size; } packet.Data = preFinalArray; } // DECOMPRESS if (packet.CompressedFlag) { if (QuickLZ.SizeDecompressed(packet.Data) > MaxDecompressedSize) { throw new InvalidOperationException("Compressed packet is too large"); } packet.Data = QuickLZ.Decompress(packet.Data); } return(true); }