示例#1
0
        //REQUEST_CHANNEL_LIST:
        public byte[] CreatePacket(string password, PACKET_TYPES type)
        {
            try
            {
                byte[] hdrBytes = null;
                byte[] packet   = null;
                switch (type)
                {
                case PACKET_TYPES.REQUEST_CHANNEL_LIST:
                {
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();

                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)0;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdrBytes            = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];
                    string seqNumS = ((byte)hdr.SEQUENCE_NUMBER).ToString();
                    hdr.PasswordHash    = EncyptGetHostPassword(password + "," + seqNumS);
                    hdr.START_OF_PACKET = 0xaa55aa55;

                    packet = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];

                    GCHandle handle = GCHandle.Alloc(packet, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);
                    handle.Free();
                }
                break;

                case PACKET_TYPES.REQUEST_STATS:
                {
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();

                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)0;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdrBytes            = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];
                    string seqNumS = ((byte)hdr.SEQUENCE_NUMBER).ToString();
                    hdr.PasswordHash    = EncyptGetHostPassword(password + "," + seqNumS);
                    hdr.START_OF_PACKET = 0xaa55aa55;

                    packet = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];

                    GCHandle handle = GCHandle.Alloc(packet, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);
                    handle.Free();
                }
                break;
                }
                return(packet);
            }
            catch (Exception ex)
            {
                m_Log.Log("CreatePacket: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL);
                return(null);
            }
        }
示例#2
0
        public byte[] CreatePacket(PACKET_TYPES type)
        {
            try
            {
                byte[] hdrBytes = null;

                switch (type)
                {
                case PACKET_TYPES.REPLY_VALID_ADMIN_PASSWORD:
                {
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();


                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)0;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdr.START_OF_PACKET = 0xaa55aa55;

                    hdrBytes = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];

                    GCHandle handle = GCHandle.Alloc(hdrBytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);
                    handle.Free();
                }
                break;

                case PACKET_TYPES.REPLY_VALID_VIEWER_PASSWORD:
                {
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();


                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)0;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdr.START_OF_PACKET = 0xaa55aa55;
                    hdrBytes            = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];

                    GCHandle handle = GCHandle.Alloc(hdrBytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);
                    handle.Free();
                }
                break;
                }
                return(hdrBytes);
            }
            catch (Exception ex)
            {
                m_Log.Log("CreatePacket: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL);
                return(null);
            }
        }
示例#3
0
        public byte[] CreatePacket(PACKET_TYPES type, string data)
        {
            try
            {
                byte[] hdrBytes = null;
                byte[] packet   = null;
                switch (type)
                {
                case PACKET_TYPES.REQUEST_CHECK_VIEWER_PASSWORD:
                case PACKET_TYPES.REQUEST_CHECK_ADMIN_PASSWORD:
                {
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();

                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)0;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdrBytes            = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];
                    string seqNumS = ((byte)hdr.SEQUENCE_NUMBER).ToString();
                    hdr.PasswordHash    = EncyptGetHostPassword(data + "," + seqNumS);
                    hdr.START_OF_PACKET = 0xaa55aa55;

                    packet = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];

                    GCHandle handle = GCHandle.Alloc(packet, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);
                    handle.Free();
                }
                break;

                case PACKET_TYPES.SEND_HOST_NAME:
                case PACKET_TYPES.SEND_STATS:
                {
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();

                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)data.Length;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdrBytes            = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];
                    hdr.START_OF_PACKET = 0xaa55aa55;

                    GCHandle handle = GCHandle.Alloc(hdrBytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);
                    handle.Free();

                    if (data == null)
                    {
                        data = "0";
                    }

                    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                    byte[] dataBytes = encoding.GetBytes(data);

                    packet = new byte[hdrBytes.Length + dataBytes.Length];


                    for (int i = 0; i < hdrBytes.Length; i++)
                    {
                        packet[i] = hdrBytes[i];
                    }
                    for (int i = hdrBytes.Length; i < hdrBytes.Length + dataBytes.Length; i++)
                    {
                        packet[i] = dataBytes[i - hdrBytes.Length];
                    }
                }
                break;

                case PACKET_TYPES.REPLY_INVALID_ADMIN_PASSWORD_ERROR:
                case PACKET_TYPES.REPLY_INVALID_VIEWER_PASSWORD_ERROR:
                case PACKET_TYPES.REPLY_INVALID_HOSTNAME_PASSWORD_ERROR:
                {
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();

                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)data.Length;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdrBytes            = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];
                    hdr.START_OF_PACKET = 0xaa55aa55;

                    GCHandle handle = GCHandle.Alloc(hdrBytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);

                    if (data == null)
                    {
                        data = "0";
                    }

                    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                    byte[] dataBytes = encoding.GetBytes(data);

                    packet = new byte[hdrBytes.Length + dataBytes.Length];

                    for (int i = 0; i < hdrBytes.Length; i++)
                    {
                        packet[i] = hdrBytes[i];
                    }
                    for (int i = hdrBytes.Length; i < hdrBytes.Length + dataBytes.Length; i++)
                    {
                        packet[i] = dataBytes[i - hdrBytes.Length];
                    }
                }
                break;
                }
                return(packet);
            }
            catch (Exception ex)
            {
                m_Log.Log("CreatePacket: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL);
                return(null);
            }
        }
示例#4
0
        public byte[] CreatePacket(string password, PACKET_TYPES type, string[] data)
        {
            try
            {
                byte[] hdrBytes = null;
                byte[] packet   = null;
                switch (type)
                {
                case PACKET_TYPES.REPLY_CHANNEL_LIST:
                {
                    // count the number of bytes needed for the payload

                    int count = 0;
                    foreach (string s in data)
                    {
                        count += (s.Length + 1);        // add one for the null terminator
                    }


                    // header
                    PACKET_HEADER_STRUCT hdr = new PACKET_HEADER_STRUCT();
                    hdr.PACKET_TYPE     = (uint)type;
                    hdr.PACKET_LEN      = (uint)count;
                    hdr.SEQUENCE_NUMBER = (uint)m_OutBoundSequenceNumber++;
                    hdrBytes            = new byte[Marshal.SizeOf(typeof(PACKET_HEADER_STRUCT))];
                    string seqNumS = ((byte)hdr.SEQUENCE_NUMBER).ToString();
                    hdr.PasswordHash = EncyptGetHostPassword(password + "," + seqNumS);

                    hdr.START_OF_PACKET = 0xaa55aa55;

                    hdrBytes = new byte[hdrBytes.Length];

                    GCHandle handle = GCHandle.Alloc(hdrBytes, GCHandleType.Pinned);
                    Marshal.StructureToPtr(hdr, handle.AddrOfPinnedObject(), true);
                    handle.Free();



                    packet = new byte[hdrBytes.Length + count];

                    // now build the packet

                    int i   = 0;
                    int cnt = 0;
                    for (i = 0; i < hdrBytes.Length; i++)
                    {
                        packet[i] = hdrBytes[i];
                    }

                    foreach (string s in data)
                    {
                        System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                        byte[] dataBytes = encoding.GetBytes(s);

                        int end = s.Length + i;
                        cnt = 0;
                        for ( ; i < end; i++)
                        {
                            packet[i] = dataBytes[cnt];

                            cnt++;
                        }
                        packet[i++] = 0;        // null terminator for each string
                    }
                }
                break;
                }
                return(packet);
            }
            catch (Exception ex)
            {
                m_Log.Log("CreatePacket: " + ex.Message, ErrorLog.LOG_TYPE.INFORMATIONAL);
                return(null);
            }
        }