Ejemplo n.º 1
0
        public int AddRawPacketeerLineAsBytes(string s)
        {
            /* Example:
             * // 1         2         3         4         5         6         7         8         9
             * // 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
             * // [C->S] Id: 001A | Size: 28
             * // 1A 0E ED 24 D5 10 10 01 D5 00 00 00 00 00 00 00  ..í$Õ...Õ.......
             */

            if (s.Length < 51)
            {
                // Doesn't look like a correct format
                return(0);
            }

            int c = 0;

            for (int i = 0; i <= 0xf; i++)
            {
                var h = s.Substring(11 + (i * 3), 2);
                // If this fails, we're probably at the end of the packet
                // Unlike windower, Packeteer doesn't add dashes for the blanks
                if ((h != "--") && (h != "  ") && (h != " "))
                {
                    if (!byte.TryParse("0x" + h, out byte b))
                    {
                        break;
                    }
                    RawBytes.Add(b);
                    c++;
                }
            }
            return(c);
        }
Ejemplo n.º 2
0
        public int AddRawHexDataAsBytes(string hexData)
        {
            int res = 0;

            try
            {
                RawBytes.Clear();
                string dataLine = hexData.Replace(" ", "").Replace("\r", "").Replace("\n", "").Replace("\t", "");
                for (int i = 0; i < (dataLine.Length - 1); i += 2)
                {
                    string num = dataLine.Substring(i, 2);
                    byte   b   = byte.Parse(num, System.Globalization.NumberStyles.HexNumber);
                    RawBytes.Add(b);
                    res++;
                }

                /*
                 * string[] nums = hexData.Split(' ');
                 * foreach(string num in nums)
                 * {
                 *  byte b = byte.Parse(num, System.Globalization.NumberStyles.HexNumber);
                 *  RawBytes.Add(b);
                 *  res++;
                 * }
                 */
            }
            catch
            {
                //
            }
            return(res);
        }
Ejemplo n.º 3
0
        public int AddRawLineAsBytes(string s)
        {
            /* Example:
             * //        1         2         3         4         5         6         7         8         9
             * //34567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
             *
             * [2018-05-16 18:11:35] Outgoing packet 0x015:
             |  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F      | 0123456789ABCDEF
             |  -----------------------------------------------------  ----------------------
             |    0 | 15 10 9E 00 CF 50 A0 C3 04 0E 1C C2 46 BF 33 43    0 | .....P......F.3C
             |    1 | 00 00 02 00 5D 00 00 00 49 97 B8 69 00 00 00 00    1 | ....]...I..i....
             |
             | // 1         2         3         4         5         6         7         8         9
             | // 123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890
             | // 5 | 00 00 00 00 -- -- -- -- -- -- -- -- -- -- -- --    5 | ....------------
             */

            // if (s.Length < 81)
            if (s.Length < 57)
            {
                // Doesn't look like a correct format
                return(0);
            }

            int c = 0;

            for (int i = 0; i <= 0xf; i++)
            {
                var h = s.Substring(10 + (i * 3), 2);
                if (h != "--")
                {
                    try
                    {
                        byte b = byte.Parse(h, System.Globalization.NumberStyles.HexNumber);
                        RawBytes.Add(b);
                    }
                    catch { }
                    c++;
                }
            }
            return(c);
        }