コード例 #1
0
        //Loads a sniffed packet from a file
        public unsafe BasePacket(string path)
        {
            var 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];
                }
        }
コード例 #2
0
        public static BasePacket CreatePacket(SubPacket subpacket, bool isAuthed, bool isCompressed)
        {
            //Create Header
            var header = new BasePacketHeader();

            byte[] data = null;

            header.isAuthenticated = isAuthed ? (byte)1 : (byte)0;
            header.isCompressed    = isCompressed ? (byte)1 : (byte)0;
            header.numSubpackets   = 1;
            header.packetSize      = BASEPACKET_SIZE;
            header.timestamp       = Utils.MilisUnixTimeStampUTC();

            //Get packet size
            header.packetSize += subpacket.header.subpacketSize;

            data = new byte[header.packetSize - 0x10];

            //Add Subpackets
            var subpacketData = subpacket.GetBytes();

            Array.Copy(subpacketData, 0, data, 0, subpacketData.Length);

            Debug.Assert(data != null);

            var packet = new BasePacket(header, data);

            return(packet);
        }
コード例 #3
0
        public static unsafe BasePacketHeader GetHeader(byte[] bytes)
        {
            BasePacketHeader header;

            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));
            }

            return(header);
        }
コード例 #4
0
        public static BasePacket CreatePacket(byte[] data, bool isAuthed, bool isCompressed)
        {
            Debug.Assert(data != null);

            //Create Header
            var header = new BasePacketHeader();

            header.isAuthenticated = isAuthed ? (byte)1 : (byte)0;
            header.isCompressed    = isCompressed ? (byte)1 : (byte)0;
            header.numSubpackets   = 1;
            header.packetSize      = BASEPACKET_SIZE;
            header.timestamp       = Utils.MilisUnixTimeStampUTC();

            //Get packet size
            header.packetSize += (ushort)data.Length;

            var packet = new BasePacket(header, data);

            return(packet);
        }
コード例 #5
0
        //Loads a sniffed packet from a byte array
        public unsafe BasePacket(byte[] bytes)
        {
            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;

                data = new byte[packetSize - BASEPACKET_SIZE];
                Array.Copy(bytes, BASEPACKET_SIZE, data, 0, packetSize - BASEPACKET_SIZE);
        }
コード例 #6
0
        public static BasePacket CreatePacket(List <SubPacket> subpackets, bool isAuthed, bool isCompressed)
        {
            //Create Header
            var header = new BasePacketHeader();

            byte[] data = null;

            header.isAuthenticated = isAuthed ? (byte)1 : (byte)0;
            header.isCompressed    = isCompressed ? (byte)1 : (byte)0;
            header.numSubpackets   = (ushort)subpackets.Count;
            header.packetSize      = BASEPACKET_SIZE;
            header.timestamp       = Utils.MilisUnixTimeStampUTC();

            //Get packet size
            foreach (var subpacket in subpackets)
            {
                header.packetSize += subpacket.header.subpacketSize;
            }

            data = new byte[header.packetSize - 0x10];

            //Add Subpackets
            var offset = 0;

            foreach (var subpacket in subpackets)
            {
                var subpacketData = subpacket.GetBytes();
                Array.Copy(subpacketData, 0, data, offset, subpacketData.Length);
                offset += (ushort)subpacketData.Length;
            }

            Debug.Assert(data != null && offset == data.Length && header.packetSize == 0x10 + offset);

            var packet = new BasePacket(header, data);

            return(packet);
        }
コード例 #7
0
 public BasePacket(BasePacketHeader header, byte[] data)
 {
     this.header = header;
     this.data   = data;
 }