示例#1
0
        //For Easy debugging and enable to see the payload we override toString
        public string BufferToText()
        {
            //TODO: add try catch return buffer index safe

            string s = "Packet Dump: " + Environment.NewLine;
            int    CurrentBufferIndex = mBufferIndex; // Keep the current index and restore later

            mBufferIndex = 4;
            s           += "Len = " + GetDataLen() + Environment.NewLine;
            ReadPayloadType();
            s += "PayloadType = " + PaylodType.ToString() + Environment.NewLine;
            s += ",Name = " + ReadString() + Environment.NewLine;

            byte ValueType = mBuffer[mBufferIndex];
            int  idx       = 0;

            while (ValueType != LastByteMarker)
            {
                idx++;
                s += ", [" + idx + "] ";
                switch (ValueType)
                {
                case 1:
                    string s1 = GetValueString();
                    s += "String = " + s1 + Environment.NewLine;
                    break;

                case 2:
                    int i = GetValueInt();
                    s += "Int = " + i + Environment.NewLine;
                    break;

                case 3:
                    string e1 = GetValueEnum();
                    s += "Enum = " + e1 + Environment.NewLine;
                    break;

                case 4:
                    string s16 = GetStringUTF16();
                    s += "StringUTF16 = " + s16 + Environment.NewLine;
                    break;

                case ListStringType:
                    List <string> list  = GetListString();
                    string        sList = "";
                    for (int iCount = 0; iCount < list.Count(); iCount++)
                    {
                        sList = sList + "::" + list[iCount];
                    }
                    s += "List= " + sList + Environment.NewLine;
                    break;

                case 6:
                    // List of Payloads
                    List <NewPayLoad> PLs     = GetListPayLoad();
                    string            sPLList = "List of Payloads, len=" + PLs.Count + Environment.NewLine;
                    int PLi = 0;
                    for (PLi = 0; PLi < PLs.Count; PLi++)
                    {
                        string PLDump = PLs[PLi].BufferInfo;
                        sPLList += "Payload #" + PLi + Environment.NewLine + PLDump + Environment.NewLine;
                    }
                    s += "List of Payloads= " + sPLList + Environment.NewLine;
                    break;

                case 7:
                    byte[] b = GetBytes();
                    //Bytes - for screen shot or any binary
                    s += "Bytes(Binary), Len=" + b.Length + Environment.NewLine;
                    break;

                case 8:     // Guid
                    Guid g = GetGuid();
                    s += "GUID= " + g.ToString() + Environment.NewLine;
                    break;

                case 9:     // bool false
                    s += "bool=false " + Environment.NewLine;
                    break;

                case 10:     // bool true
                    s += "bool=true " + Environment.NewLine;
                    break;

                case Struct:
                    mBufferIndex++;
                    //    // TODO: Create display for struct!?
                    int structlen = ReadInt();
                    mBufferIndex += structlen;
                    s            += "struct binary len=" + structlen + Environment.NewLine;
                    break;

                case JSONStruct:
                    mBufferIndex++;
                    string json = ReadString();
                    s += "jsonstruct= " + json + Environment.NewLine;
                    break;

                case PayLoadType:
                    NewPayLoad payloadInPayload     = ReadPayload();
                    string     payload              = "PayloadInPayload, package len=" + payloadInPayload.PackageLen() + Environment.NewLine;
                    string     PayloadInPayloadDump = payloadInPayload.BufferInfo;
                    payload += "Payload data" + Environment.NewLine + PayloadInPayloadDump + Environment.NewLine;
                    s       += payload;
                    break;

                default:
                    mBufferIndex = CurrentBufferIndex;
                    throw new InvalidOperationException("Payload.ToString() Error - Unknown ValueType: " + ValueType);
                }

                ValueType = mBuffer[mBufferIndex];
            }
            mBufferIndex = CurrentBufferIndex;

            return(s);
        }
示例#2
0
 internal static void Send(System.Net.Sockets.NetworkStream ns, NewPayLoad pl)
 {
     byte[] b = pl.GetPackage();
     ns.Write(b, 0, b.Length);
     ns.Flush();
 }
示例#3
0
 // 13 Add Payload
 public void AddPayload(NewPayLoad item)
 {
     CheckBuffer(1 + item.PackageLen() + 4);
     WriteValueType(PayLoadType);
     WriteBytes(item.GetPackage());
 }