<commit_before>
/*
 * WhatsApp protocol dissector
 * Written by <NAME> <<EMAIL>>
 * Based on WhatsAPI sources
 *
 */


#include <config.h>
#include <epan/packet.h>

#define WHATSAPP_PORT 5222
#define WHATSAPP_PORT_NEW 443

const char * global_imei_whatsapp_1 = 0;
const char * global_imei_whatsapp_2 = 0;
const char * global_imei_whatsapp_3 = 0;
const char * global_v2pw_whatsapp_1 = 0;
const char * global_v2pw_whatsapp_2 = 0;
const char * global_v2pw_whatsapp_3 = 0;
const gboolean global_enable_decoding;
int proto_whatsapp = -1;
int message_whatsapp = -1;
int userserver_string = -1;
int tree_whatsapp = -1;
static gint ett_whatsapp = -1;
int whatsapp_msg_crypted_payload = -1;
int whatsapp_msg_crypted_message = -1;

/* Variables for whatsapp packets */
int hf_whatsapp_message = -1;
int hf_whatsapp_node = -1;
int hf_whatsapp_nodesize16 = -1;
int hf_whatsapp_nodesize8 = -1;
int hf_whatsapp_attr_key_enc = -1;
int hf_whatsapp_attr_val_enc = -1;
int hf_whatsapp_attr_key_plain = -1;
int hf_whatsapp_attr_val_plain = -1;
int hf_whatsapp_attr_crypted = -1;
int hf_whatsapp_attr_flags = -1;
int hf_whatsapp_attribute = -1;
int hf_whatsapp_tag_enc = -1;
int hf_whatsapp_tag_plain = -1;
int hf_whatsapp_nvalue_enc = -1;
int hf_whatsapp_nvalue_plain = -1;
int hf_whatsapp_crypted_hmac_hash = -1;
int hf_whatsapp_userserver = -1;

const value_string strings_list[];

int whatsapp_msg = -1;

#define MIN_PAKCET_SIZE 5


static guint get_whatsapp_message_len(packet_info *pinfo, tvbuff_t *tvb, int offset)
{
  int length = tvb_length(tvb)-offset;
  guint8* buffer = tvb_memdup(tvb, offset, length);
  int wa_len = whatsapp_data_length(buffer, length);
  g_free(buffer);
  return wa_len;
}<commit_msg>Fixed the minimum pakcet length to 4. In theory it could be as low as 3, but that would not make any sense. That fixes the bug found when wireshark tried to dissect the first 5 bytes of the stream (only 4 could be successfully parsed) and it just forgot about the 5th byte (it takes the maximum between min_length and whatever you return).<commit_after>
/*
 * WhatsApp protocol dissector
 * Written by <NAME> <<EMAIL>>
 * Based on WhatsAPI sources
 *
 */


#include <config.h>
#include <epan/packet.h>

#define WHATSAPP_PORT 5222
#define WHATSAPP_PORT_NEW 443

const char * global_imei_whatsapp_1 = 0;
const char * global_imei_whatsapp_2 = 0;
const char * global_imei_whatsapp_3 = 0;
const char * global_v2pw_whatsapp_1 = 0;
const char * global_v2pw_whatsapp_2 = 0;
const char * global_v2pw_whatsapp_3 = 0;
const gboolean global_enable_decoding;
int proto_whatsapp = -1;
int message_whatsapp = -1;
int userserver_string = -1;
int tree_whatsapp = -1;
static gint ett_whatsapp = -1;
int whatsapp_msg_crypted_payload = -1;
int whatsapp_msg_crypted_message = -1;

/* Variables for whatsapp packets */
int hf_whatsapp_message = -1;
int hf_whatsapp_node = -1;
int hf_whatsapp_nodesize16 = -1;
int hf_whatsapp_nodesize8 = -1;
int hf_whatsapp_attr_key_enc = -1;
int hf_whatsapp_attr_val_enc = -1;
int hf_whatsapp_attr_key_plain = -1;
int hf_whatsapp_attr_val_plain = -1;
int hf_whatsapp_attr_crypted = -1;
int hf_whatsapp_attr_flags = -1;
int hf_whatsapp_attribute = -1;
int hf_whatsapp_tag_enc = -1;
int hf_whatsapp_tag_plain = -1;
int hf_whatsapp_nvalue_enc = -1;
int hf_whatsapp_nvalue_plain = -1;
int hf_whatsapp_crypted_hmac_hash = -1;
int hf_whatsapp_userserver = -1;

const value_string strings_list[];

int whatsapp_msg = -1;

#define MIN_PAKCET_SIZE 4


static guint get_whatsapp_message_len(packet_info *pinfo, tvbuff_t *tvb, int offset)
{
  int length = tvb_length(tvb)-offset;
  guint8* buffer = tvb_memdup(tvb, offset, length);
  int wa_len = whatsapp_data_length(buffer, length);
  g_free(buffer);
  return wa_len;
}
{'fraction_non_alphanumeric': 0.08768154922001076, 'fraction_numerical': 0.0293168370091447, 'mean_word_length': 5.2294807370184255, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6049096', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1504, 'n_words': 379}