Beispiel #1
0
        public void _PrintPacketDetailHandler(PPacket ppacket)
        {
            //try
            //{
                //------------------------------------------------------------------------------------------------------------------------------
                //| packet no 5                      | relative time 0.745022                                            | packet length 55    |
                //-------------------------------------------------------[ethernet frame]-------------------------------------------------------
                //| 0x0000 | 00 07 CB C1 35 5D       | destination MAC address         00:07:CB:C1:35:5D                 | header length 14    |
                //| 0x0006 | 48 5B 39 C0 45 48       | source MAC address              48:5B:39:C0:45:48                 | data length   41    |
                //| 0x000C | 08 00                   | ether type                      0x0800  IPv4                      |                     |
                //---------------------------------------------------------[ipv4 frame]---------------------------------------------------------
                //| 0x000E | 45                      | version                         4                                 | header length 20    |
                //|        |                         | internet header length (ihl)    5                                 | data length   21    |
                //| 0x000F | 00                      | dscp                            0x00                              |                     |
                //|        |                         | ecn                                                               |                     |
                //| 0x0010 | 00 29                   | total length                    41                                |                     |
                //| 0x0012 | 4F F9                   | identification                  0x4FF9                            |                     |
                //| 0x0014 | 40 00                   | flags                                                             |                     |
                //|        |                         | fragment offset                 0x0000                            |                     |
                //| 0x0016 | 80                      | time to live                    0x80                              |                     |
                //| 0x0017 | 06                      | protocol                        0x06 TCP                          |                     |
                //| 0x0018 | 1A 47                   | header checksum                 0x1A47                            |                     |
                //| 0x001A | C0 A8 00 01             | source ip address               192.168.0.1                       |                     |
                //| 0x001E | AD C2 22 23             | destination ip address          173.194.34.35                     |                     |
                //|        |                         | options (if ihl > 5)                                              |                     |
                //| 0x0022 | CD 67 01 BB E9 DF 53 5D | data                                                              |                     |
                //| 0x002A | 91 1F 42 06 50 10 40 3D |                                                                   |                     |
                //| 0x0032 | FF 81 00 00 00          |                                                                   |                     |
                //------------------------------------------------------------------------------------------------------------------------------

                //if (ip.Tcp != null && ip.Tcp.Http.Version == null)
                //    return;

                PrintPacketInfos(ppacket);
                _dataLength = (ushort)ppacket.Packet.Count;
                _dataEnum = ppacket.Packet.zAsEnumerableWithCounter();
                PrintEthernet(ppacket);

                EthernetDatagram ethernet = ppacket.Packet.Ethernet;
                if (ethernet.EtherType == EthernetType.IpV4)
                {
                    PrintIpV4(ppacket);
                    IpV4Datagram ip = ethernet.IpV4;
                    if (ip.Protocol == IpV4Protocol.Tcp)
                    {
                        PrintTcp(ppacket);
                        if (ip.Tcp.Http.Version != null)
                            PrintHttp(ppacket);
                    }
                }
                WriteSeparation();
                Trace.WriteLine();


            //}
            //finally
            //{
            //    WriteSeparation();
            //    Trace.WriteLine();
            //}
        }
Beispiel #2
0
        private void WritePayloadData(int nb, EnumerableWithCounter<byte> dataEnum = null)
        {
            //|        |                         | data                                                              |                     |
            //| 0x0022 | CD 67 01 BB E9 DF 53 5D | data                                                              |                     |
            //| 0x002A | 91 1F 42 06 50 10 40 3D |                                                                   |                     |
            //| 0x0032 | FF 81 00 00 00          |                                                                   |                     |


            //| 0x000E | 00 01 08 00 06 04 00 02 00 01 08 00 06 04 00 02 | "................"                        | data length    48   |
            //| 0x000E | 00 01 08 00 06 04 00 02 00 01 08 00 06 04 00 02 | "................"                        |                     |
            //| 0x000E | 00 01 08 00 06 04 00 02 00 01 08 00 06 04 00 02 | "................"                        |                     |


            if (dataEnum == null)
                dataEnum = _dataEnum;

            StringBuilder sb = new StringBuilder();
            bool firstLine = true;

            while (nb > 0)
            {
                int n = Math.Min(_maxDataPerLine2, nb);
                int i = 0;
                sb.Append("\"");
                while (dataEnum.MoveNext())
                {
                    if (i == 0)
                        _sb.AppendFormat("| 0x{0} |", ((ushort)dataEnum.Index).zToHex());
                    byte b = dataEnum.Current;
                    _sb.AppendFormat(" {0}", b.zToHex());
                    if (b >= 32)
                        sb.Append((char)b);
                    else
                        sb.Append(".");
                    if (++i == n)
                        break;
                }
                sb.Append("\"");
                if (i == 0)
                {
                    _sb.AppendFormat("|        |");
                    sb.Clear();
                    sb.Append("  ");
                }
                while (i < _maxDataPerLine2)
                {
                    _sb.Append("   ");
                    sb.Append(" ");
                    i++;
                }
                _sb.Append(" | ");
                //if (firstLine)
                //    _sb.Append("data  ");
                //else
                //    _sb.Append("      ");
                _sb.Append(sb.ToString());
                //_sb.Append("                                                  |                     |");




                //_sb.Append("                        |                     |");
                _sb.Append("                        ");
                //_sb.Append("|                     |");


                if (firstLine)
                {
                    _sb.Append("| ");
                    _sb.Append("data length".PadRight(15));
                    _sb.Append(_dataLength.ToString().PadRight(5));
                    _sb.Append("|");
                }
                else
                    _sb.Append("|                     |");





                WriteLine();
                sb.Clear();
                nb -= n;
                firstLine = false;
                if (dataEnum.EndOfData)
                    break;
            }
        }