Example #1
0
        public static void ParseHdr(byte[] hdr, ref UInt32 major, ref UInt32 minor, ref UInt32 type, ref UInt64 id, ref UInt32 size)
        {
            BinaryReader r = new BinaryReader(new MemoryStream(hdr));

            major = Base.ntoh(r.ReadUInt32());
            minor = Base.ntoh(r.ReadUInt32());
            type  = Base.ntoh(r.ReadUInt32());
            id    = Base.ntoh(r.ReadUInt64());
            size  = Base.ntoh(r.ReadUInt32());
        }
Example #2
0
        public static List <Element> ParsePayload(byte[] payload)
        {
            List <Element> a = new List <Element>();
            MemoryStream   s = new MemoryStream(payload);
            BinaryReader   r = new BinaryReader(s, Encoding.GetEncoding("iso-8859-1"));

            while (s.Position != s.Length)
            {
                Element e = null;

                // To whoever wants to fix this code: beware that old KWMs
                // send incorrectly formatted application packets. It is
                // probably preferrable to ignore type 0 elements.

                // Evil.
                AnpType t = (AnpType)r.ReadByte();

                switch (t)
                {
                case AnpType.UInt32:
                    e = new Element(Base.ntoh(r.ReadUInt32()));
                    break;

                case AnpType.UInt64:
                    e = new Element(Base.ntoh(r.ReadUInt64()));
                    break;

                case AnpType.String:
                    e = new Element(new String(r.ReadChars((Int32)Base.ntoh((UInt32)r.ReadUInt32()))));
                    break;

                case AnpType.Bin:
                    e = new Element(r.ReadBytes((Int32)Base.ntoh((UInt32)r.ReadUInt32())));
                    break;
                }
                a.Add(e);
            }

            return(a);
        }