Ok, so I’ve got an Open Source Java client/server program that uses packets to communicate. I’m trying to write a python client for said program, but the contents of the packet seem to be compressed. A quick perusal through the source code suggested gzip as the compression schema (since that was the only compression module imported in the code that I could find), but when I saved the data from one of the packets out of wireshark and tried to do
import gzip
f = gzip.open('compressed_file')
f.read()
It told me that this wasn’t a gzip file because the header was wrong. Can someone advise me what I’ve done wrong here? Did I change or mess up the format when I saved it out? Do I need to strip away some of the extraneous data from the packet before I try running this block on it?
if (zipped) {
// XML encode the data and GZIP it.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Writer zipOut = new BufferedWriter(new OutputStreamWriter(
new GZIPOutputStream(baos)));
PacketEncoder.encodeData(packet, zipOut);
zipOut.close();
// Base64 encode the commpressed data.
// Please note, I couldn't get anything other than a
// straight stream-to-stream encoding to work.
byte[] zipData = baos.toByteArray();
ByteArrayOutputStream base64 = new ByteArrayOutputStream(
(4 * zipData.length + 2) / 3);
Base64.encode(new ByteArrayInputStream(zipData), base64, false);
EDIT:
Ok, sorry I have the information requested here. This was gathered using Wireshark to listen in on communication between two running copies of the original program on different computers. To get the hex stream below, I used the “Copy -> Hex (Byte Stream)” option in Wireshark.
001321cdc68ff4ce46e4f00d0800450000832a85400080061e51ac102cceac102cb004f8092a9909b32c10e81cb25018f734823e00000100000000000000521f8b08000000000000005bf39681b59c85818121a0b4884138da272bb12c512f27312f5dcf3f292b35b9c47ac2b988f902c59a394c0c0c150540758c250c5c2ea5b9b9950a2e89258900aa4c201a3f000000
I know this will contain the string “Dummy Data” in it. I believe it should also contain “Jonathanb” (the player name I used to send the message) and the integer 80 (80 is the command # for “Chat” as far as I can gather from the code).
It would help enormously if you divulged:
(0) What leads you to the conclusion that “the contents of the packet seem to be compressed”
(1) The URLs for the (a) source and (b) documentation of the package that is writing the packets
(2) The contents of a sample packet
(a)
print repr(open('file_saved_from_wireshark', 'rb').read())(b) just in case the long trip around via wireshark is muddying the water, insert this in your Python client:
print repr(a_sample_packet)(3) the exact error message that you got (copy/paste)
Update after OP supplied the hex dump of a packet
This code:
produced this output (wrapped at col 80 by Windows’ “Command Prompt” terminal) when run with Python 2.6.4:
Comments/questions:
This packet is 145 bytes long; what happened to the idea that a packet was about 2900 bytes?
The packet is 63 bytes of as-yet-unanalysed data followed by an 82-byte gzip stream which decompresses(!) to 63 bytes. There is no data after the gzip stream — verified by comparing the last 8 bytes of the packet with calculated gzip values. It contains the expected “Dummy Data”, but userid “johnathonb” is not there (or obfuscated or encrypted).
The packet structure doesn’t match the code that we guessed was being used (no XML, no base64).
The gunzipped data contains the string “java.lang.Object” which is probably symptomatic of some java serialisation protocol. Lasciate ogni speranza, voi qu’entrate.