/// <summary> /// /// </summary> /// <param name="packet"></param> /// <param name="start">Is used to quickly find packet start without calculations</param> /// <param name="offest"></param> /// <param name="length"></param> /// <returns></returns> public static bool RecreatePacket_StartSizeStopCompressSum(ref byte[] packet, out Int32 offest, out Int32 length, out byte compression) { offest = -1; length = -1; compression = 0; if (packet.IsNullOrEmpty()) { return(false); } byte start = TcpAsyncCommon.StartByte; byte end = TcpAsyncCommon.EndByte; int packet_length = packet.Length; Int32 _length, _offset; byte _compression; for (int i = 0; i < packet_length - 11; i++) { if (packet[i] != start) { continue; } _compression = packet[i + 1]; _length = Int32Ex.FromBytes(packet, i + 2); _offset = i + 10; if (_length <= 0 || //incorrect value test (_length + _offset) <= 0 || //overflow test packet_length <= (_length + _offset) || //invalid size test packet[_offset + _length] != end) { continue; } Int32 _checksum = Int32Ex.FromBytes(packet, i + 6); Int32 _checksum_test = packet.ChecksumInt32(_offset, _length); //(Int32)packet.SumValues(i + 1, 4); if (_checksum != _checksum_test || _length <= 0) { continue; } offest = _offset; length = _length; compression = _compression; return(true); } return(false); }
public static Bitmap[,] ToBitmap2D_16(this byte[] data, int offset) { if (data.IsCountLessOrEqual(24 + offset)) { return(null); } int xParts = Int16Ex.FromBytes(data); int yParts = Int16Ex.FromBytes(data, 2); if (1.IsGreaterThenAny(xParts, yParts)) { return(null); } Bitmap[,] result = new Bitmap[xParts, yParts]; int i = 4; for (; i < data.Length;) { int x = Int16Ex.FromBytes(data, i); int y = Int16Ex.FromBytes(data, i + 2); int l = Int32Ex.FromBytes(data, i + 4); if ( !x.InClosedInterval(0, xParts - 1) || !y.InClosedInterval(0, yParts - 1) || l <= 0) { return(null); } byte[] packet = data.SubArray(i + 8, l); result[x, y] = packet.ToBitmap(); i += (8 + l); } return(result); }