Esempio n. 1
0
        //Loads a sniffed packet from a file
        public unsafe BasePacket(String path)
        {
            byte[] bytes = File.ReadAllBytes(path);

            if (bytes.Length < BASEPACKET_SIZE)
            {
                throw new OverflowException("Packet Error: Packet was too small");

                fixed(byte *pdata = &bytes[0])
                {
                    header = (BasePacketHeader)Marshal.PtrToStructure(new IntPtr(pdata), typeof(BasePacketHeader));
                }

                if (bytes.Length < header.packetSize)
                {
                    throw new OverflowException("Packet Error: Packet size didn't equal given size");
                }

                int packetSize = header.packetSize;

                if (packetSize - BASEPACKET_SIZE != 0)
                {
                    data = new byte[packetSize - BASEPACKET_SIZE];
                    Array.Copy(bytes, BASEPACKET_SIZE, data, 0, packetSize - BASEPACKET_SIZE);
                }
                else
                {
                    data = new byte[0];
                }
        }
Esempio n. 2
0
        public unsafe BasePacket(byte[] bytes, ref int offset)
        {
            if (bytes.Length < offset + BASEPACKET_SIZE)
                throw new OverflowException("Packet Error: Packet was too small");

            fixed(byte *pdata = &bytes[offset])
            {
                header = (BasePacketHeader)Marshal.PtrToStructure(new IntPtr(pdata), typeof(BasePacketHeader));
            }

            int packetSize = header.packetSize;

            if (bytes.Length < offset + header.packetSize)
                throw new OverflowException("Packet Error: Packet size didn't equal given size"); }