/// <summary> /// Compresses this instance. /// </summary> public void Compress() { var deflater = new Deflater(); byte[] packet = PacketData; deflater.SetInput(packet, 0, packet.Length); deflater.Finish(); var compBuffer = new byte[1024]; var ret = new List <byte>(); while (!deflater.IsFinished) { try { deflater.Deflate(compBuffer); ret.AddRange(compBuffer); Array.Clear(compBuffer, 0, compBuffer.Length); } catch (Exception ex) { Logging.WriteException(ex); return; } } deflater.Reset(); Seek((byte)_headerType, SeekOrigin.Begin); // Write the compressed bytes over whatever is there. Write(ret.ToArray()); // Set the stream length to the end of the actual packet data. // This makes sure we don't have any 'junk' packets at the end. OutStream.SetLength(BaseStream.Position); }
public void Init() { Proc = Process.GetCurrentProcess(); Id = Proc.Id; OutStream.Seek(0, SeekOrigin.Begin); OutStream.SetLength(0); }
public unsafe void TestRead() { int number = 30; IntPtr address = (IntPtr)(&number); OutStream.SetLength(4); Proc.Read(address, OutStream.GetBuffer(), 4); Assert.AreEqual(number, Reader.ReadInt32()); }
private void write(byte[] srcData, int index, int size) { if (DataBlockPosition + size <= DataBlock.SizeOccupied) { //** overwrite data in Stream Position.. Array.Copy(srcData, index, DataBlock.Data, DataBlockPosition, size); DataBlockPosition += size; } else if (DataBlock.SizeAvailable > 0) { int BytesToCopy = size; if (BytesToCopy <= DataBlock.SizeAvailable) { Array.Copy(srcData, index, DataBlock.Data, DataBlockPosition, BytesToCopy); DataBlockPosition += BytesToCopy; DataBlock.SizeOccupied += BytesToCopy; } else { // Write Data spanning multiple blocks int BytesToWrite = DataBlock.SizeAvailable; Array.Copy(srcData, index, DataBlock.Data, DataBlockPosition, BytesToWrite); DataBlockPosition = DataBlock.Data.Length; DataBlock.SizeOccupied = DataBlock.Data.Length; write(srcData, index + BytesToWrite, BytesToCopy - BytesToWrite); } } else { _dataBlock = DataBlock.Extend(); DataBlockPosition = 0; _logicalPosition += OutStream.Position; OutStream.SetLength(0); OutStream.Seek(0, SeekOrigin.Begin); do { if (_dataBlock.Data.Length < size) { Array.Copy(srcData, index, _dataBlock.Data, 0, _dataBlock.Data.Length); index += _dataBlock.Data.Length; _dataBlock.SizeOccupied = _dataBlock.Data.Length; size -= _dataBlock.Data.Length; _dataBlock.Extend(); _dataBlock = _dataBlock.Next; } else { Array.Copy(srcData, index, _dataBlock.Data, 0, size); _dataBlock.SizeOccupied = size; DataBlockPosition = size; break; } } while (size > 0); } }
public void Clear() { OutStream.SetLength(0); }