public byte GetByte(int index) { if (index > 7) { throw new IndexOutOfRangeException("Max index for a getByte operation is 7"); } int pos = 22 + index; return(RawBytes.Skip(pos).Take(1).ToArray()[0]); }
public string GetByteString(int index) { if (index > 7) { throw new IndexOutOfRangeException("Max index for a GetByteString operation is 7"); } int pos = 22 + index; return(MyExtensions.ByteArrayToString(RawBytes.Skip(pos).Take(1).ToArray())); }
public float GetFloat(int index) { if (index > 1) { throw new IndexOutOfRangeException("Max index for a SetFloat operation is 1"); } int pos = 22 + (4 * index); return(BitConverter.ToSingle(EndianCorrectArray(RawBytes.Skip(pos).Take(4).ToArray()), 0)); }
private void parseRecords() { Records = new CompressedRecord[Header.SlotCnt]; int cnt = 0; foreach (short recordOffset in SlotArray) { Records[cnt++] = new CompressedRecord(ArrayHelper.SliceArray(RawBytes.ToArray(), recordOffset, RawBytes.Count - recordOffset), this); } }
public int GetInt16(int index) { if (index > 3) { throw new IndexOutOfRangeException("Max index for a GetInt16 operation is 3"); } int pos = 22 + (2 * index); return(BitConverter.ToInt16(EndianCorrectArray(RawBytes.Skip(pos).Take(2).ToArray()), 0)); }
public uint GetUint32(int index) { if (index > 1) { throw new IndexOutOfRangeException("Max index for a GetUInt32 operation is 1"); } int pos = 22 + (4 * index); return(BitConverter.ToUInt32(EndianCorrectArray(RawBytes.Skip(pos).Take(4).ToArray()), 0)); }
public uint GetUint8(int index) { if (index > 7) { throw new IndexOutOfRangeException("Max index for a setUInt8 operation is 7"); } int pos = 22 + index; return(CanUtilities.ByteToUInt8(RawBytes.Skip(pos).Take(1).ToArray())); }
public override int GetHashCode() { unchecked { var hashCode = Label.GetHashCode(); hashCode = (hashCode * 397) ^ Instr.GetHashCode(); hashCode = (hashCode * 397) ^ Pc.GetHashCode(); hashCode = (hashCode * 397) ^ RawBytes.GetHashCode(); hashCode = (hashCode * 397) ^ Ia.GetHashCode(); hashCode = (hashCode * 397) ^ RealComment.GetHashCode(); return(hashCode); } }
private void parseRecords() { Records = new ClusteredIndexRecord[Header.SlotCnt]; //var offsets = SlotArray.OrderBy(x => x).Select((o, i) => new {o, i}).ToArray(); //var joinedOffsets = from o1 in offsets // join o2 in offsets on o1.i equals o2.i-1 into ps // from p in ps.DefaultIfEmpty() // select new { o1.i,o1.o, length = p?.o - o1.o }; var idx = 0; foreach (var recordOffset in SlotArray) { Records[idx++] = new ClusteredIndexRecord(ArrayHelper.SliceArray(RawBytes.ToArray(), recordOffset, RawBytes.Count - recordOffset), this); } }
public List <string> ValidateXhtml() { var errors = new List <string>(); if (this.IsXhtmlPage) { try { RawBytes.ToXhtml(); } catch (Exception e) { errors.Add($"Chapter '{AbsolutePath}' has error: {e.Message}"); } } return(errors); }
protected override void OnLoad(SshDataWorker reader) { base.OnLoad(reader); if (MethodName != "publickey") { throw new ArgumentException(string.Format("Method name {0} is not valid.", MethodName)); } HasSignature = reader.ReadBoolean(); KeyAlgorithmName = reader.ReadString(Encoding.ASCII); PublicKey = reader.ReadBinary(); if (HasSignature) { Signature = reader.ReadBinary(); PayloadWithoutSignature = RawBytes.Take(RawBytes.Length - Signature.Length - 5).ToArray(); } }
public int AddRawLineAsBytes(string s) { /* Example: * // 1 2 3 4 5 6 7 8 9 * //34567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 * * [2018-05-16 18:11:35] Outgoing packet 0x015: | 0 1 2 3 4 5 6 7 8 9 A B C D E F | 0123456789ABCDEF | ----------------------------------------------------- ---------------------- | 0 | 15 10 9E 00 CF 50 A0 C3 04 0E 1C C2 46 BF 33 43 0 | .....P......F.3C | 1 | 00 00 02 00 5D 00 00 00 49 97 B8 69 00 00 00 00 1 | ....]...I..i.... | | // 1 2 3 4 5 6 7 8 9 | // 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 | // 5 | 00 00 00 00 -- -- -- -- -- -- -- -- -- -- -- -- 5 | ....------------ */ // if (s.Length < 81) if (s.Length < 57) { // Doesn't look like a correct format return(0); } int c = 0; for (int i = 0; i <= 0xf; i++) { var h = s.Substring(10 + (i * 3), 2); if (h != "--") { try { byte b = byte.Parse(h, System.Globalization.NumberStyles.HexNumber); RawBytes.Add(b); } catch { } c++; } } return(c); }
public void RemoveImageLink(string absolutePath) { string relativePath = ZipUtils.AbsolutePathToRelative(AbsolutePath.GetZipPath(), absolutePath); var doc = RawBytes.ToXhtml(); bool changed = false; foreach (var element in FindImageElements(doc)) { var href = element.GetImageHref(); if (relativePath == href) { doc.RemoveImage(element); changed = true; } } if (changed) { RawBytes = doc.ToSBytes(); } }
public Message(NetworkDataType type, byte[] payload = null) { DataType = type; switch (DataType) { case NetworkDataType.KeepAlive: RawBytes = BitConverter.GetBytes(0); return; case NetworkDataType.Choke: case NetworkDataType.Unchoke: case NetworkDataType.Interested: case NetworkDataType.NotInterested: RawBytes = BitConverter.GetBytes(1); RawBytes.Append(Convert.ToByte((int)DataType)); return; case NetworkDataType.Bitfield: case NetworkDataType.Have: case NetworkDataType.Request: default: return; } }
protected sealed override void setValue(object value) { var response = value as IRestResponse; if (Request != null) { Request.SetValue(response.Request); } if (ErrorMessage != null) { ErrorMessage.SetValue(response.ErrorMessage); } if (ResponseStatus != null) { ResponseStatus.SetValue(response.ResponseStatus); } if (Headers != null) { foreach (var header in Headers) { var headerValue = response.Headers.FirstOrDefault(h => h.Name == header.Key); if (headerValue != null) { header.Value.SetValue(headerValue.Value); } } } if (Cookies != null) { foreach (var cookie in Cookies) { var cookieValue = response.Cookies.FirstOrDefault(c => c.Name == cookie.Key); if (cookieValue != null) { cookie.Value.SetValue(cookieValue.Value); } } } if (Server != null) { Server.SetValue(response.Server); } if (ResponseUri != null) { ResponseUri.SetValue(response.ResponseUri); } if (ErrorException != null) { ErrorException.SetValue(response.ErrorException); } if (RawBytes != null) { RawBytes.SetValue(response.RawBytes); } if (IsSuccessful != null) { IsSuccessful.SetValue(response.IsSuccessful); } if (StatusCode != null) { StatusCode.SetValue(response.StatusCode); } if (Content != null) { Content.SetValue(response.Content); } if (ContentEncoding != null) { ContentEncoding.SetValue(response.ContentEncoding); } if (ContentLength != null) { ContentLength.SetValue(response.ContentLength); } if (ContentType != null) { ContentType.SetValue(response.ContentType); } if (StatusDescription != null) { StatusDescription.SetValue(response.StatusDescription); } if (ProtocolVersion != null) { ProtocolVersion.SetValue(response.ProtocolVersion); } setExtraValues(response); }
public int FindByte(byte aByte) { return(RawBytes.IndexOf(aByte)); }