Пример #1
0
        public static bool TryParsePacket(Kaitai.KaitaiStream stream, out TlsPacket packet)
        {
            try
            {
                var packetStartPos = stream.Pos;
                // first we check that this is really TlsRecord to be parsed
                // 1 byte  - content_type
                // 2 bytes - version
                // 2 bytes - record length
                if (stream.Size > 5 && CheckSignature(stream.ReadBytes(5)) == 0)
                {
                    packet = null;
                    return(false);
                }
                stream.Seek(packetStartPos);
                // Try to parse the record.
                packet = new TlsPacket(stream);

                // this code is necessary to properly handle change cipher + finished records in TLS1.2
                // the TLS1.3 does not necessary use finished record after change cipher
                if (packet.ContentType == TlsContentType.ChangeCipherSpec && stream.PeekByte() == (byte)TlsContentType.Handshake)
                {   // consume finished
                    var finished = new TlsPacket.TlsFinished(stream);
                }
                return(true);
            }
            catch (Exception e)
            {
                packet = null;
                return(false);
            }
        }
Пример #2
0
 private void _parse()
 {
     m_io.BaseStream.Seek(Contact.fOffset, SeekOrigin.Begin);
     _contacts = new List <Contact>((int)(1000));
     for (var i = 0; i < 1000; i++)
     {
         byte[] stuff             = m_io.ReadBytes(Contact.fSize);
         var    io___raw_contacts = new Kaitai.KaitaiStream(stuff);
         _contacts.Add(new Contact(io___raw_contacts, this, m_root));
     }
 }
Пример #3
0
 public Contact(Kaitai.KaitaiStream io, Codeplug parent = null, Codeplug root = null) : base(io)
 {
     m_parent = parent;
     m_root   = root;
     _parse();
 }