I am successfully parcing '.pcap' files using SharpPcap libary.
The goal is to retrieve XML data from the TCP/HTTP packets. In order to do this, I am using the code below (removed null checks to make it more readable):
Packet packet = Packet.ParsePacket(eventArguments.Packet.LinkLayerType, eventArguments.Packet.Data);
EthernetPacket ethernetPacket = ((EthernetPacket)packet);
IpPacket ipPacket = (IpPacket)packet.Extract(typeof(IpPacket));
TcpPacket tcpPacket = (TcpPacket)packet.Extract(typeof(TcpPacket));
string rawData = tcpPacket.PrintHex();
Moving, aside the hex values and the initial lines, I am able to extract the XML data from the rawData variable, along with an unexpected side-effect.
Instead of spaces, the .PrintHex()
returns '.' characters:
Instead of:
<xml>Only text here</xml>
I am getting this:
<xml>Only.text.here</xml>
I am not doing any weird replacements or byte conversions. The above behavior is exactly what .PrintHex()
returns.
- Is this by any chance the expected outcome?
- And more importantly... How can this be fixed or prevented? (having in mind that valid '.' from converted '.' cannot be distinguished)
Library versions:
.NET Framework: > 4.5.2
Pcapsharp: 4.2.0