Ethereal-dev: Re: [Ethereal-dev] SoulSeek Dissector
Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.
From: Kendy Kutzner <kutzner@xxxxxxxxx>
Date: Wed, 11 Feb 2004 14:43:12 +0100
On 2003-12-20T18:30:36+0100, Joerg Mayer wrote: > Two more things (the first one can be found in doc/README.developer > section 1.1.1). And here comes the diff... --
--- packet-slsk.c 2003-12-10 16:06:26.000000000 +0100
+++ packet-slsk.c.3 2004-02-11 14:23:14.000000000 +0100
@@ -40,7 +40,10 @@
#include <string.h>
#include <glib.h>
+
+#ifdef HAVE_LIBZ
#include <zlib.h>
+#endif
#include <epan/packet.h>
#include "packet-tcp.h"
@@ -121,7 +124,11 @@
/* desegmentation of SoulSeek Message over TCP */
static gboolean slsk_desegment = TRUE;
+#ifdef HAVE_LIBZ
static gboolean slsk_decompress = TRUE;
+#else
+static gboolean slsk_decompress = FALSE;
+#endif
static const value_string slsk_tcp_msgs[] = {
{ 1, "Login"},
@@ -233,11 +240,6 @@
* * - can be used at the end of a format to ignore any following bytes
*/
- char remaining_format[strlen(format)-1];
- int i =0;
- while (i < (int)strlen(format)){remaining_format[i] = format[i+1]; i++;}
-
-
switch ( format[0] ) {
case 'i':
if (tvb_length_remaining(tvb, offset) < 4) return FALSE;
@@ -260,11 +262,11 @@
break;
}
- if (remaining_format[0] == '\0' ) {
+ if (format[1] == '\0' ) {
if (tvb_length_remaining(tvb, offset) != 0) return FALSE; /* Checks for additional bytes at the end */
return TRUE;
}
- return check_slsk_format(tvb, offset, remaining_format);
+ return check_slsk_format(tvb, offset, &format[1]);
}
@@ -282,30 +284,18 @@
if (check_slsk_format(tvb, 4, "bi")) message_type = "Pierce Fw";
}
return message_type;
-};
+}
static guint get_slsk_pdu_len(tvbuff_t *tvb, int offset)
{
guint32 msg_len;
-
- /*
- * Checks if the Message Type is known.
- * If it's not known, we cannot trust the first 4 bytes to be the
- * message length flag, so we just say the length is
- * 'what remains in the packet'.
- */
-// if (strcmp(get_message_type(tvb), "Unknown") != 0) {
- /* Get the length of the SoulSeek TCP packet. */
- msg_len = tvb_get_letohl(tvb, offset);
-
- /* That length doesn't include the length field itself; add that in. */
- msg_len += 4;
- return msg_len;
-// } else return tvb_length_remaining(tvb, offset);
-
-
+ msg_len = tvb_get_letohl(tvb, offset);
+ /* That length doesn't include the length field itself; add that in. */
+ msg_len += 4;
+ return msg_len;
}
+#ifdef HAVE_LIBZ
static tvbuff_t* uncompress_packet(tvbuff_t *tvb, int offset, int comprlen){
/*
@@ -316,18 +306,25 @@
char compr[comprlen];
int i = 0;
- while (i < comprlen) { compr[i] = tvb_get_guint8(tvb, offset+i); i++;}
long uncomprlen = (comprlen*10);
char uncompr[uncomprlen];
-
- int err = uncompress((Bytef *)uncompr, &uncomprlen, (Bytef *)compr, comprlen);
-
+ int err = 0;
tvbuff_t *uncompr_tvb;
- uncompr_tvb = tvb_new_real_data((guint8*) uncompr, uncomprlen, uncomprlen);
-
+
+ while (i < comprlen) { compr[i] = tvb_get_guint8(tvb, offset+i); i++;}
+
+ err = uncompress((Bytef *)uncompr, &uncomprlen, (Bytef *)compr, comprlen);
if (err != 0) return NULL;
+
+ uncompr_tvb = tvb_new_real_data((guint8*) uncompr, uncomprlen, uncomprlen);
return uncompr_tvb;
}
+#else
+static tvbuff_t* uncompress_packet(tvbuff_t *tvb, int offset, int comprlen){
+ return NULL;
+}
+#endif
+
/* Code to actually dissect the packets */
@@ -343,6 +340,14 @@
guint32 msg_len, msg_code;
gchar *message_type;
+ int comprlen = 0;
+ int uncomprlen = 0;
+ int uncompr_tvb_offset = 0;
+ int i2 = 0;
+ int j2 = 0;
+ int i3 = 0;
+ int j3 = 0;
+
offset = 0;
msg_len = tvb_get_letohl(tvb, offset);
@@ -493,7 +498,7 @@
offset += 4;
/* [zlib compressed] */
- int comprlen = tvb_length_remaining(tvb, offset);
+ comprlen = tvb_length_remaining(tvb, offset);
if (slsk_decompress == TRUE){
@@ -512,12 +517,12 @@
proto_tree_add_uint_format(slsk_tree, hf_slsk_integer, tvb, offset, tvb_length_remaining(tvb, offset), 0,
"( compressed packet length: %d)", comprlen);
- int uncomprlen = tvb_length_remaining(uncompr_tvb, 0);
+ uncomprlen = tvb_length_remaining(uncompr_tvb, 0);
proto_tree_add_uint_format(slsk_tree, hf_slsk_integer, tvb, offset, tvb_length_remaining(tvb, offset), 0,
"(uncompressed packet length: %d)", uncomprlen);
/* Dissects the uncompressed tvbuffer */
- int uncompr_tvb_offset = 0;
+ uncompr_tvb_offset = 0;
if (check_slsk_format(uncompr_tvb, uncompr_tvb_offset, "i*")) {
i=0; j = tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
proto_tree_add_uint_format(slsk_compr_packet_tree, hf_slsk_integer, uncompr_tvb, 0, 0, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset),
@@ -530,7 +535,8 @@
proto_tree_add_uint_format(slsk_compr_packet_tree, hf_slsk_string_length, uncompr_tvb, 0, 0, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset),
"Directory #%d Name: %s", i+1, tvb_get_string(uncompr_tvb, uncompr_tvb_offset+4, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset)));
uncompr_tvb_offset += 4+tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
- int i2=0; int j2 = tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
+ i2=0;
+ j2 = tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
proto_tree_add_uint_format(slsk_compr_packet_tree, hf_slsk_integer, uncompr_tvb, 0, 0, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset),
"Directory #%d Number of files: %d", i+1, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset));
uncompr_tvb_offset += 4;
@@ -555,7 +561,8 @@
proto_tree_add_uint_format(slsk_compr_packet_tree, hf_slsk_string_length, uncompr_tvb, 0, 0, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset),
"Dir #%d File #%d ext: %s", i+1, i2+1, tvb_get_string(uncompr_tvb, uncompr_tvb_offset+4, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset)));
uncompr_tvb_offset += 4+tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
- int i3=0; int j3 = tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
+ i3=0;
+ j3 = tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
proto_tree_add_uint_format(slsk_compr_packet_tree, hf_slsk_integer, uncompr_tvb, 0, 0, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset),
"Dir #%d File #%d Number of attributes: %d", i+1, i2+1, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset));
uncompr_tvb_offset += 4;
@@ -623,7 +630,7 @@
offset += 4;
/* [zlib compressed] */
- int comprlen = tvb_length_remaining(tvb, offset);
+ comprlen = tvb_length_remaining(tvb, offset);
if (slsk_decompress == TRUE){
@@ -642,12 +649,12 @@
proto_tree_add_uint_format(slsk_tree, hf_slsk_integer, tvb, offset, tvb_length_remaining(tvb, offset), 0,
"( compressed packet length: %d)", comprlen);
- int uncomprlen = tvb_length_remaining(uncompr_tvb, 0);
+ uncomprlen = tvb_length_remaining(uncompr_tvb, 0);
proto_tree_add_uint_format(slsk_tree, hf_slsk_integer, tvb, offset, tvb_length_remaining(tvb, offset), 0,
"(uncompressed packet length: %d)", uncomprlen);
/* Dissects the uncompressed tvbuffer */
- int uncompr_tvb_offset = 0;
+ uncompr_tvb_offset = 0;
if (check_slsk_format(uncompr_tvb, uncompr_tvb_offset, "sii*")) {
proto_tree_add_uint(slsk_compr_packet_tree, hf_slsk_string_length, uncompr_tvb, 0, 0, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset));
proto_tree_add_uint_format(slsk_compr_packet_tree, hf_slsk_string_length, uncompr_tvb, 0, 0, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset),
@@ -680,7 +687,8 @@
proto_tree_add_uint_format(slsk_compr_packet_tree, hf_slsk_string_length, uncompr_tvb, 0, 0, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset),
"File #%d ext: %s", i+1, tvb_get_string(uncompr_tvb, uncompr_tvb_offset+4, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset)));
uncompr_tvb_offset += 4+tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
- int i2=0; int j2 = tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
+ i2=0;
+ j2 = tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
proto_tree_add_uint_format(slsk_compr_packet_tree, hf_slsk_integer, uncompr_tvb, 0, 0, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset),
"File #%d Number of attributes: %d", i+1, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset));
uncompr_tvb_offset += 4;
@@ -1137,7 +1145,7 @@
offset += 4;
/* [zlib compressed] */
- int comprlen = tvb_length_remaining(tvb, offset);
+ comprlen = tvb_length_remaining(tvb, offset);
if (slsk_decompress == TRUE){
@@ -1156,12 +1164,12 @@
proto_tree_add_uint_format(slsk_tree, hf_slsk_integer, tvb, offset, tvb_length_remaining(tvb, offset), 0,
"( compressed packet length: %d)", comprlen);
- int uncomprlen = tvb_length_remaining(uncompr_tvb, 0);
+ uncomprlen = tvb_length_remaining(uncompr_tvb, 0);
proto_tree_add_uint_format(slsk_tree, hf_slsk_integer, tvb, offset, tvb_length_remaining(tvb, offset), 0,
"(uncompressed packet length: %d)", uncomprlen);
/* Dissects the uncompressed tvbuffer */
- int uncompr_tvb_offset = 0;
+ uncompr_tvb_offset = 0;
if (check_slsk_format(uncompr_tvb, uncompr_tvb_offset, "isi*")) {
proto_tree_add_uint_format(slsk_compr_packet_tree, hf_slsk_integer, uncompr_tvb, 0, 0, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset),
"Token: %d", tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset));
@@ -1179,7 +1187,8 @@
proto_tree_add_uint_format(slsk_compr_packet_tree, hf_slsk_string_length, uncompr_tvb, 0, 0, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset),
"Directory #%d Name: %s", i+1, tvb_get_string(uncompr_tvb, uncompr_tvb_offset+4, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset)));
uncompr_tvb_offset += 4+tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
- int i2=0; int j2 = tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
+ i2 = 0;
+ j2 = tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
proto_tree_add_uint_format(slsk_compr_packet_tree, hf_slsk_integer, uncompr_tvb, 0, 0, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset),
"Directory #%d Number of files: %d", i+1, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset));
uncompr_tvb_offset += 4;
@@ -1204,7 +1213,8 @@
proto_tree_add_uint_format(slsk_compr_packet_tree, hf_slsk_string_length, uncompr_tvb, 0, 0, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset),
"Dir #%d File #%d ext: %s", i+1, i2+1, tvb_get_string(uncompr_tvb, uncompr_tvb_offset+4, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset)));
uncompr_tvb_offset += 4+tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
- int i3=0; int j3 = tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
+ i3 = 0;
+ j3 = tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset);
proto_tree_add_uint_format(slsk_compr_packet_tree, hf_slsk_integer, uncompr_tvb, 0, 0, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset),
"Dir #%d File #%d Number of attributes: %d", i+1, i2+1, tvb_get_letohl(uncompr_tvb, uncompr_tvb_offset));
uncompr_tvb_offset += 4;
@@ -2482,11 +2492,12 @@
"Desegment all SoulSeek messages spanning multiple TCP segments",
"Whether the SoulSeek dissector should desegment all messages spanning multiple TCP segments",
&slsk_desegment);
-
+#ifdef HAVE_LIBZ
prefs_register_bool_preference(slsk_module, "decompress",
"Decompress zlib compressed packets inside SoulSeek messages",
"Whether the SoulSeek dissector should decompress all zlib compressed packets inside messages",
&slsk_decompress);
+#endif
}
Attachment:
pgp0H0MrJ3RYL.pgp
Description: PGP signature
- Prev by Date: Re: [Ethereal-dev] SoulSeek Dissector
- Next by Date: [Ethereal-dev] patch for wiretap lib: read EyeSDN USB S0 format
- Previous by thread: Re: [Ethereal-dev] SoulSeek Dissector
- Next by thread: [Ethereal-dev] patch for wiretap lib: read EyeSDN USB S0 format
- Index(es):





