decompiled_code:
int __fastcall xdg_helper_init(__int64 a1, const char **a2)
{
const char *v2; // rbx
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax

v2 = *a2;
v3 = strrchr(*a2, 47);
if ( v3 )
v2 = v3 + 1;
appname = (__int64)v2;
v4 = getenv("XDG_CONFIG_HOME");
determine_path(paths, v4, ".config", "config");
v5 = getenv("XDG_DATA_HOME");
determine_path(s, v5, ".local/share", "data");
v6 = getenv("XDG_CACHE_HOME");
return determine_path(byte_4060A0, v6, ".cache", "cache");
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, const char **a2)
{
const char *v2; // rbx
char *v3; // rax
char *v4; // rax
char *v5; // rax
char *v6; // rax

v2 = *a2;
v3 = strrchr(*a2, 47);
if ( v3 )
v2 = v3 + 1;
appname = (__int64)v2;
v4 = getenv("XDG_CONFIG_HOME");
func7(paths, v4, ".config", "config");
v5 = getenv("XDG_DATA_HOME");
func7(s, v5, ".local/share", "data");
v6 = getenv("XDG_CACHE_HOME");
return func7(byte_4060A0, v6, ".cache", "cache");
}

original_code:
void xdg_helper_init(int argc, char **argv)
{
    const char *slash = strrchr(argv[0], '/');
    appname = slash ? (slash + 1) : argv[0];
    determine_path(paths[0], getenv("XDG_CONFIG_HOME"), ".config", "config");
    determine_path(paths[1], getenv("XDG_DATA_HOME"), ".local/share", "data");
    determine_path(paths[2], getenv("XDG_CACHE_HOME"), ".cache", "cache");
}

canonical_original_code:
void xdg_helper_init(int argc, char **argv)
{
    char *slash = strrchr(argv[0], '/');
    appname = slash ? (slash + 1) : argv[0];
    determine_path(paths[0], getenv("XDG_CONFIG_HOME"), ".config", "config");
    determine_path(paths[1], getenv("XDG_DATA_HOME"), ".local/share", "data");
    determine_path(paths[2], getenv("XDG_CACHE_HOME"), ".cache", "cache");
}

variable_types: argc int

variable_types:
slash
char *


repo: sailfish-sdk/xdg-helper

decompiled_code:
char *__fastcall xdg_helper_get(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 2 )
result = &paths[4096 * (unsigned __int64)a1];
return result;
}

canonical_decompiled_code:
char *__fastcall func9(unsigned int a1)
{
char *result; // rax

result = 0LL;
if ( a1 <= 2 )
result = &paths[4096 * (unsigned __int64)a1];
return result;
}

original_code:
const char *xdg_helper_get(enum xdg_helper_path_t which)
{
    return (which < 0 || which > XDG_HELPER_CACHE_PATH) ? 0 : paths[which];
}

variable_types: enum xdg_helper_path_t { XDG_HELPER_CONFIG_PATH=0, XDG_HELPER_DATA_PATH=1, XDG_HELPER_CACHE_PATH=2 }

return_type: char *


repo: saintkepha/airtraf

decompiled_code:
void *initialize_p802_11b_parser()
{
void *result; // rax

result = calloc(0x48uLL, 1uLL);
info = (__int64)result;
if ( !result )
{
perror("malloc: initialize_p802_11b_parser()");
exit(-1);
}
return result;
}

canonical_decompiled_code:
void *func0()
{
void *result; // rax

result = calloc(0x48uLL, 1uLL);
info = (__int64)result;
if ( !result )
{
perror("malloc: initialize_p802_11b_parser()");
exit(-1);
}
return result;
}

original_code:
void initialize_p802_11b_parser()
{
  if (((void *)0) == (info = malloc(sizeof(struct p802_11b_info)))){
    perror("malloc: initialize_p802_11b_parser()");
    exit(-1);
  }
  memset(info, 0, sizeof(struct p802_11b_info));
}

return_type: void

user_defined_types: struct p802_11b_info { unsigned char type; unsigned short subtype; unsigned char datatype; unsigned char wep; unsigned char status; unsigned char *bssid; unsigned char *da; unsigned char *sa; unsigned char channel; unsigned char ssid[32]; }


decompiled_code:
int __fastcall parse_ap_info(__int64 a1, int a2)
{
int i; // er12
int v3; // ebx
__int64 v4; // rax
unsigned int v5; // er13

for ( i = 6; i; --i )
{
v3 = a2 + 2;
v4 = a2 + 1;
v5 = *(unsigned __int8 *)(a1 + v4);
if ( v5 > 0x20 )
break;
if ( *(_BYTE *)(a1 + a2) )
{
if ( *(_BYTE *)(a1 + a2) == 3 )
{
LODWORD(v4) = info;
*(_BYTE *)(info + 32) = *(_BYTE *)(a1 + v3);
return v4;
}
}
else
{
LODWORD(v4) = snprintf((char *)(info + 33), (unsigned __int8)(v5 + 1), "%s", (const char *)(a1 + v3));
}
a2 = v5 + v3;
}
return v4;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2)
{
int i; // er12
int v3; // ebx
__int64 v4; // rax
unsigned int v5; // er13

for ( i = 6; i; --i )
{
v3 = a2 + 2;
v4 = a2 + 1;
v5 = *(unsigned __int8 *)(a1 + v4);
if ( v5 > 0x20 )
break;
if ( *(_BYTE *)(a1 + a2) )
{
if ( *(_BYTE *)(a1 + a2) == 3 )
{
LODWORD(v4) = info;
*(_BYTE *)(info + 32) = *(_BYTE *)(a1 + v3);
return v4;
}
}
else
{
LODWORD(v4) = snprintf((char *)(info + 33), (unsigned __int8)(v5 + 1), "%s", (const char *)(a1 + v3));
}
a2 = v5 + v3;
}
return v4;
}

original_code:
void parse_ap_info(wlan_hdr_t *hdr, int offset)
{
  __u8 temp_num;
  __u8 *packet;
  int info_ptr, tag_number, tag_length, loop_count;
  tag_number = 0;
  tag_length = 0;
  loop_count = 0;
  info_ptr = offset;
  packet = (__u8*)hdr;
  if (0) printf("parse_ap_info(): processing access point data\n");
  while(tag_number != 3){
    loop_count++;
    if (loop_count > 6){
      return;
    }
    tag_number = packet[info_ptr];
    info_ptr++;
    tag_length = packet[info_ptr];
    info_ptr++;
    if(tag_length > 32){
      return;
    }
    if (0) printf("tag_number = %d, tag_length = %d\n",tag_number,tag_length);
    if(tag_number == 0){
      temp_num = (tag_length & 0xff)+1;
      snprintf(info->ssid,temp_num,"%s",&packet[info_ptr]);
    }
    if(tag_number == 3){
   info->channel = packet[info_ptr];
    }
    info_ptr += tag_length;
  }
  if (0) printf("parse_ap_info(): channel=%d\n",info->channel);
}

canonical_original_code:
void parse_ap_info(struct wlan_hdr_t *hdr, int offset)
{
  unsigned char temp_num;
  unsigned char *packet;
  int info_ptr; int tag_number; int tag_length; int loop_count;
  tag_number = 0;
  tag_length = 0;
  loop_count = 0;
  info_ptr = offset;
  packet = (unsigned char *)hdr;
  if (0) printf("parse_ap_info(): processing access point data\n");
  while(tag_number != 3){
    loop_count++;
    if (loop_count > 6){
      return;
    }
    tag_number = packet[info_ptr];
    info_ptr++;
    tag_length = packet[info_ptr];
    info_ptr++;
    if(tag_length > 32){
      return;
    }
    if (0) printf("tag_number = %d, tag_length = %d\n",tag_number,tag_length);
    if(tag_number == 0){
      temp_num = (tag_length & 0xff)+1;
      snprintf(info->ssid,temp_num,"%s",&packet[info_ptr]);
    }
    if(tag_number == 3){
   info->channel = packet[info_ptr];
    }
    info_ptr += tag_length;
  }
  if (0) printf("parse_ap_info(): channel=%d\n",info->channel);
}

variable_types: struct wlan_hdr_t { unsigned short frame_control; unsigned short duration_id; unsigned char mac1[6]; unsigned char mac2[6]; unsigned char mac3[6]; unsigned short sequence; unsigned char mac4[6]; } *

variable_types: offset int

variable_types:
packet
unsigned char *


decompiled_code:
__int64 __fastcall parse_mgmt(__int64 a1)
{
__int64 result; // rax

result = info;
*(_QWORD *)(info + 16) = a1 + 4;
*(_QWORD *)(result + 24) = a1 + 10;
*(_QWORD *)(result + 8) = a1 + 16;
*(_BYTE *)(result + 6) = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 result; // rax

result = info;
*(_QWORD *)(info + 16) = a1 + 4;
*(_QWORD *)(result + 24) = a1 + 10;
*(_QWORD *)(result + 8) = a1 + 16;
*(_BYTE *)(result + 6) = 1;
return result;
}

original_code:
void parse_mgmt(wlan_hdr_t *packet)
{
  if (0) printf("parse_mgmt(): processing mgmt frame\n");
  info->da=(__u8 *)&packet->mac1;
  info->sa=(__u8 *)&packet->mac2;
  info->bssid=(__u8 *)&packet->mac3;
  if (0) printf("da: %s   sa: %s   bssid: %s\n",
      hexdump((__u8*)info->da, 6),
      hexdump((__u8*)info->sa, 6),
      hexdump((__u8*)info->bssid, 6));
  info->status = 1;
  if (0) printf("parse_mgmt(): exiting...\n");
  return;
}

canonical_original_code:
void parse_mgmt(struct wlan_hdr_t *packet)
{
  if (0) printf("parse_mgmt(): processing mgmt frame\n");
  info->da=(unsigned char *)&packet->mac1;
  info->sa=(unsigned char *)&packet->mac2;
  info->bssid=(unsigned char *)&packet->mac3;
  if (0) printf("da: %s   sa: %s   bssid: %s\n",
      hexdump((unsigned char *)info->da, 6),
      hexdump((unsigned char *)info->sa, 6),
      hexdump((unsigned char *)info->bssid, 6));
  info->status = 1;
  if (0) printf("parse_mgmt(): exiting...\n");
  return;
}

user_defined_types: struct wlan_hdr_t { unsigned short frame_control; unsigned short duration_id; unsigned char mac1[6]; unsigned char mac2[6]; unsigned char mac3[6]; unsigned short sequence; unsigned char mac4[6]; }


decompiled_code:
__int64 __fastcall parse_ctrl(__int64 a1)
{
__int64 result; // rax

result = info;
*(_QWORD *)(info + 16) = a1 + 4;
*(_BYTE *)(result + 6) = 1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
__int64 result; // rax

result = info;
*(_QWORD *)(info + 16) = a1 + 4;
*(_BYTE *)(result + 6) = 1;
return result;
}

original_code:
void parse_ctrl(wlan_hdr_t *packet)
{
  if (0) printf("parse_ctrl(): processing control frame\n");
  info->da=(__u8 *)&packet->mac1;
  info->status = 1;
  if (0) printf("handlecontrol: exiting...\n");
  return;
}

canonical_original_code:
void parse_ctrl(struct wlan_hdr_t *packet)
{
  if (0) printf("parse_ctrl(): processing control frame\n");
  info->da=(unsigned char *)&packet->mac1;
  info->status = 1;
  if (0) printf("handlecontrol: exiting...\n");
  return;
}


original_code:
void parse_data(wlan_hdr_t *hdr)
{
  frame_control_t *fc;
  __u8 tofrom;
  if (0) printf("parse_data(): processing data packet\n");
  fc = (frame_control_t *) &hdr->frame_control;
  tofrom = (fc->toDS << 1) | fc->fromDS;
  switch (tofrom)
    {
    case 0:
      info->datatype = 1;
      info->da=(__u8 *)&hdr->mac1;
      info->sa=(__u8 *)&hdr->mac2;
      info->bssid=(__u8 *)&hdr->mac3;
      break;
    case 1:
      info->datatype = 2;
      info->da=(__u8 *)&hdr->mac1;
      info->sa=(__u8 *)&hdr->mac3;
      info->bssid=(__u8 *)&hdr->mac2;
      break;
    case 2:
      info->datatype = 3;
      info->da=(__u8 *)&hdr->mac3;
      info->sa=(__u8 *)&hdr->mac2;
      info->bssid=(__u8 *)&hdr->mac1;
      break;
    case 3:
      info->datatype = 4;
      break;
    }
  info->status = 1;
  if (0) printf("parse_data(): exiting...\n");
  return;
}

canonical_original_code:
void parse_data(struct wlan_hdr_t *hdr)
{
  struct frame_control_t *fc;
  unsigned char tofrom;
  if (0) printf("parse_data(): processing data packet\n");
  fc = (struct frame_control_t *) &hdr->frame_control;
  tofrom = (fc->toDS << 1) | fc->fromDS;
  switch (tofrom)
    {
    case 0:
      info->datatype = 1;
      info->da=(unsigned char *)&hdr->mac1;
      info->sa=(unsigned char *)&hdr->mac2;
      info->bssid=(unsigned char *)&hdr->mac3;
      break;
    case 1:
      info->datatype = 2;
      info->da=(unsigned char *)&hdr->mac1;
      info->sa=(unsigned char *)&hdr->mac3;
      info->bssid=(unsigned char *)&hdr->mac2;
      break;
    case 2:
      info->datatype = 3;
      info->da=(unsigned char *)&hdr->mac3;
      info->sa=(unsigned char *)&hdr->mac2;
      info->bssid=(unsigned char *)&hdr->mac1;
      break;
    case 3:
      info->datatype = 4;
      break;
    }
  info->status = 1;
  if (0) printf("parse_data(): exiting...\n");
  return;
}

variable_types: struct frame_control_t { unsigned char version; unsigned char type; unsigned char subtype; unsigned char toDS; unsigned char fromDS; unsigned char morefrag; unsigned char retry; unsigned char pwr; unsigned char moredata; unsigned char wep; unsigned char rsvd; } *

variable_types:
tofrom
unsigned char


decompiled_code:
__int64 parse_other()
{
__int64 result; // rax

result = info;
*(_BYTE *)(info + 6) = 0;
return result;
}

canonical_decompiled_code:
__int64 func5()
{
__int64 result; // rax

result = info;
*(_BYTE *)(info + 6) = 0;
return result;
}

original_code:
void parse_other(wlan_hdr_t *packet)
{
  info->status = 0;
}

canonical_original_code:
void parse_other(struct wlan_hdr_t *packet)
{
  info->status = 0;
}


decompiled_code:
__int64 __fastcall parse_p802_11b_hdr(_BYTE *a1)
{
__int64 v1; // rax
__int64 v2; // rsi
char v3; // al
unsigned __int8 v4; // cl
__int64 result; // rax

v1 = info;
*(_OWORD *)info = 0LL;
v2 = info;
*(_QWORD *)(v1 + 64) = 0LL;
*(_OWORD *)(v1 + 16) = 0LL;
*(_OWORD *)(v1 + 32) = 0LL;
*(_OWORD *)(v1 + 48) = 0LL;
v3 = (*a1 >> 2) & 3;
*(_BYTE *)v2 = v3;
v4 = *a1 >> 4;
*(_WORD *)(v2 + 2) = v4;
*(_BYTE *)(v2 + 5) = (a1[1] & 0x40) != 0;
if ( v3 == 1 )
{
parse_ctrl((__int64)a1);
result = info;
}
else if ( v3 == 2 )
{
parse_data((__int64)a1);
result = info;
}
else if ( v3 )
{
parse_other();
result = info;
}
else
{
if ( v4 == 5 || v4 == 8 )
parse_ap_info((__int64)a1, 36);
parse_mgmt((__int64)a1);
result = info;
}
return result;
}

original_code:
struct p802_11b_info *parse_p802_11b_hdr(wlan_hdr_t *hdr)
{
  frame_control_t *fc;
  memset(info, 0, sizeof(struct p802_11b_info));
  fc = (frame_control_t *)&hdr->frame_control;
  if (0) printf("parse_p802_11b_hdr():entering\n");
  info->type = fc->type;
  info->subtype = fc->subtype;
  info->wep = fc->wep;
  switch(fc->type)
    {
    case 0:
      switch(fc->subtype)
 {
 case 8:
 case 5:
   parse_ap_info(hdr, sizeof(wlan_hdr_t) + 6);
   break;
 }
      parse_mgmt(hdr);
      break;
    case 1:
      parse_ctrl(hdr);
      break;
    case 2:
      parse_data(hdr);
      break;
    default:
      parse_other(hdr);
      break;
    }
  return (info);
}

canonical_original_code:
struct p802_11b_info *parse_p802_11b_hdr(struct wlan_hdr_t *hdr)
{
  struct frame_control_t *fc;
  memset(info, 0, sizeof(struct p802_11b_info));
  fc = (struct frame_control_t *)&hdr->frame_control;
  if (0) printf("parse_p802_11b_hdr():entering\n");
  info->type = fc->type;
  info->subtype = fc->subtype;
  info->wep = fc->wep;
  switch(fc->type)
    {
    case 0:
      switch(fc->subtype)
 {
 case 8:
 case 5:
   parse_ap_info(hdr, sizeof(wlan_hdr_t) + 6);
   break;
 }
      parse_mgmt(hdr);
      break;
    case 1:
      parse_ctrl(hdr);
      break;
    case 2:
      parse_data(hdr);
      break;
    default:
      parse_other(hdr);
      break;
    }
  return (info);
}

return_type: struct p802_11b_info { unsigned char type; unsigned short subtype; unsigned char datatype; unsigned char wep; unsigned char status; unsigned char *bssid; unsigned char *da; unsigned char *sa; unsigned char channel; unsigned char ssid[32]; } *

user_defined_types: struct frame_control_t { unsigned char version; unsigned char type; unsigned char subtype; unsigned char toDS; unsigned char fromDS; unsigned char morefrag; unsigned char retry; unsigned char pwr; unsigned char moredata; unsigned char wep; unsigned char rsvd; }


original_code:
struct p802_11b_info *parse_hfa384x_hdr(prism2_hdr_t *hdr)
{
  frame_control_t *fc;
  int descript_size = sizeof(hfa384x_descript_t);
  void *wlan_hdr;
  wlan_hdr = (void *)((char *)hdr + descript_size);
  if (0) printf("parse_hfa384x_hdr(): entering...\n");
  memset(info, 0, sizeof(struct p802_11b_info));
  fc = (frame_control_t *)&hdr->frame_control;
  info->type = fc->type;
  info->subtype = fc->subtype;
  info->wep = fc->wep;
  switch(fc->type)
    {
    case 0:
      switch(fc->subtype)
 {
 case 8:
 case 5:
   parse_ap_info(wlan_hdr, sizeof(prism2_hdr_t) - descript_size + 6);
   break;
 }
      parse_mgmt((wlan_hdr_t *)wlan_hdr);
      break;
    case 1:
      parse_ctrl((wlan_hdr_t *)wlan_hdr);
      break;
    case 2:
      parse_data((wlan_hdr_t *)wlan_hdr);
      break;
    default:
      parse_other((wlan_hdr_t *)wlan_hdr);
      break;
    }
  return (info);
}

canonical_original_code:
struct p802_11b_info *parse_hfa384x_hdr(struct prism2_hdr_t *hdr)
{
  struct frame_control_t *fc;
  int descript_size = sizeof(hfa384x_descript_t);
  void *wlan_hdr;
  wlan_hdr = (void *)((char *)hdr + descript_size);
  if (0) printf("parse_hfa384x_hdr(): entering...\n");
  memset(info, 0, sizeof(struct p802_11b_info));
  fc = (struct frame_control_t *)&hdr->frame_control;
  info->type = fc->type;
  info->subtype = fc->subtype;
  info->wep = fc->wep;
  switch(fc->type)
    {
    case 0:
      switch(fc->subtype)
 {
 case 8:
 case 5:
   parse_ap_info(wlan_hdr, sizeof(prism2_hdr_t) - descript_size + 6);
   break;
 }
      parse_mgmt((struct wlan_hdr_t *)wlan_hdr);
      break;
    case 1:
      parse_ctrl((struct wlan_hdr_t *)wlan_hdr);
      break;
    case 2:
      parse_data((struct wlan_hdr_t *)wlan_hdr);
      break;
    default:
      parse_other((struct wlan_hdr_t *)wlan_hdr);
      break;
    }
  return (info);
}

variable_types: struct prism2_hdr_t { struct hfa384x_descript_t { unsigned short status; unsigned int time; unsigned char silence; unsigned char signal; unsigned char rate; unsigned char rxflow; unsigned int reserved; } frame_descriptor; unsigned short frame_control; unsigned short duration_id; unsigned char mac1[6]; unsigned char mac2[6]; unsigned char mac3[6]; unsigned short sequence; unsigned char mac4[6]; unsigned short data_len; unsigned char dst_addr[6]; unsigned char src_addr[6]; unsigned short len; unsigned char crap[6]; } *

user_defined_types: struct prism2_hdr_t { struct hfa384x_descript_t frame_descriptor; unsigned short frame_control; unsigned short duration_id; unsigned char mac1[6]; unsigned char mac2[6]; unsigned char mac3[6]; unsigned short sequence; unsigned char mac4[6]; unsigned short data_len; unsigned char dst_addr[6]; unsigned char src_addr[6]; unsigned short len; unsigned char crap[6]; }


original_code:
struct p802_11b_info *parse_wlanngp2_hdr(wlan_ng_hdr_t *hdr)
{
  frame_control_t *fc;
  wlan_hdr_t *whdr;
  int descript_size = sizeof(wlan_ng_hdr_t);
  void *wlan_hdr;
  wlan_hdr = (void *)((char *)hdr + descript_size);
  whdr = (wlan_hdr_t *)wlan_hdr;
  if (0) printf("parse_wlanngp2_hdr(): entering...\n");
  memset(info, 0, sizeof(struct p802_11b_info));
  fc = (frame_control_t *)&whdr->frame_control;
  info->type = fc->type;
  info->subtype = fc->subtype;
  info->wep = fc->wep;
  switch(fc->type)
    {
    case 0:
      switch(fc->subtype)
 {
 case 8:
 case 5:
   parse_ap_info(wlan_hdr, sizeof(wlan_hdr_t) + 6);
   break;
 }
      parse_mgmt((wlan_hdr_t *)wlan_hdr);
      break;
    case 1:
      parse_ctrl((wlan_hdr_t *)wlan_hdr);
      break;
    case 2:
      parse_data((wlan_hdr_t *)wlan_hdr);
      break;
    default:
      parse_other((wlan_hdr_t *)wlan_hdr);
      break;
    }
  return (info);
}

canonical_original_code:
struct p802_11b_info *parse_wlanngp2_hdr(struct wlan_ng_hdr_t *hdr)
{
  struct frame_control_t *fc;
  struct wlan_hdr_t *whdr;
  int descript_size = sizeof(wlan_ng_hdr_t);
  void *wlan_hdr;
  wlan_hdr = (void *)((char *)hdr + descript_size);
  whdr = (struct wlan_hdr_t *)wlan_hdr;
  if (0) printf("parse_wlanngp2_hdr(): entering...\n");
  memset(info, 0, sizeof(struct p802_11b_info));
  fc = (struct frame_control_t *)&whdr->frame_control;
  info->type = fc->type;
  info->subtype = fc->subtype;
  info->wep = fc->wep;
  switch(fc->type)
    {
    case 0:
      switch(fc->subtype)
 {
 case 8:
 case 5:
   parse_ap_info(wlan_hdr, sizeof(wlan_hdr_t) + 6);
   break;
 }
      parse_mgmt((struct wlan_hdr_t *)wlan_hdr);
      break;
    case 1:
      parse_ctrl((struct wlan_hdr_t *)wlan_hdr);
      break;
    case 2:
      parse_data((struct wlan_hdr_t *)wlan_hdr);
      break;
    default:
      parse_other((struct wlan_hdr_t *)wlan_hdr);
      break;
    }
  return (info);
}

variable_types: struct wlan_ng_hdr_t { unsigned int msgcode; unsigned int msglen; unsigned char devname[16]; struct p80211item_t { unsigned int did; unsigned short status; unsigned short len; unsigned int data; } hosttime; struct p80211item_t mactime; struct p80211item_t channel; struct p80211item_t rssi; struct p80211item_t sq; struct p80211item_t signal; struct p80211item_t noise; struct p80211item_t rate; struct p80211item_t istx; struct p80211item_t frmlen; } *

user_defined_types: struct wlan_ng_hdr_t { unsigned int msgcode; unsigned int msglen; unsigned char devname[16]; struct p80211item_t hosttime; struct p80211item_t mactime; struct p80211item_t channel; struct p80211item_t rssi; struct p80211item_t sq; struct p80211item_t signal; struct p80211item_t noise; struct p80211item_t rate; struct p80211item_t istx; struct p80211item_t frmlen; }


decompiled_code:
int __fastcall airtraf_init(void *arg)
{
int v1; // eax
const char *v2; // rdx

if ( *((_DWORD *)arg + 8) != 1 )
{
if ( *((_DWORD *)arg + 5) != 2 )
goto LABEL_3;
LABEL_7:
pthread_cond_init(&start_cond, 0LL);
pthread_mutex_init(&start_lock, 0LL);
pthread_mutex_lock(&start_lock);
pthread_create(&thread, 0LL, (void *(*)(void *))&server, arg);
pthread_cond_wait(&start_cond, &start_lock);
fwrite("airtraf_init: [success] server started\n", 1uLL, 0x27uLL, stderr);
if ( *((_DWORD *)arg + 15) != 1 )
goto LABEL_4;
goto LABEL_8;
}
init_log(1LL, *((_QWORD *)arg + 3));
fwrite("airtraf_init: [success] logging enabled\n", 1uLL, 0x28uLL, stderr);
if ( *((_DWORD *)arg + 5) == 2 )
goto LABEL_7;
LABEL_3:
if ( *((_DWORD *)arg + 15) != 1 )
goto LABEL_4;
LABEL_8:
fwrite("airtraf_init: [info] starting capture mode\n", 1uLL, 0x2BuLL, stderr);
if ( !(unsigned int)init_capture(arg) )
fwrite("airtraf_init: [error] initializing capture mode failed\n", 1uLL, 0x37uLL, stderr);
LABEL_4:
*((_DWORD *)arg + 10) = pkt_card_sock_open(arg);
v1 = pkt_card_ifup(arg);
v2 = (const char *)*((_QWORD *)arg + 1);
if ( !v1 )
{
fprintf(stderr, "airtraf_init: [error] (%s) failed to bring the interface's configuration status up!\n", v2);
exit(-1);
}
fprintf(stderr, "airtraf_init: [success] (%s) flags updated to reflect UP & RUNNING.\n", v2);
initialize_packet_abstraction();
fwrite("airtraf_init: [success] initialized packet_abstraction engine.\n", 1uLL, 0x3FuLL, stderr);
initialize_p802_11b_parser();
fwrite("airtraf_init: [success] initialized 802.11b parser.\n", 1uLL, 0x34uLL, stderr);
fwrite("airtraf_init: [success] AirTraf initialization complete\n\n", 1uLL, 0x39uLL, stderr);
return gettimeofday(&t_start, 0LL);
}

canonical_decompiled_code:
int __fastcall func0(void *arg)
{
int v1; // eax
const char *v2; // rdx

if ( *((_DWORD *)arg + 8) != 1 )
{
if ( *((_DWORD *)arg + 5) != 2 )
goto LABEL_3;
LABEL_7:
pthread_cond_init(&start_cond, 0LL);
pthread_mutex_init(&start_lock, 0LL);
pthread_mutex_lock(&start_lock);
pthread_create(&thread, 0LL, (void *(*)(void *))&server, arg);
pthread_cond_wait(&start_cond, &start_lock);
fwrite("airtraf_init: [success] server started\n", 1uLL, 0x27uLL, stderr);
if ( *((_DWORD *)arg + 15) != 1 )
goto LABEL_4;
goto LABEL_8;
}
init_log(1LL, *((_QWORD *)arg + 3));
fwrite("airtraf_init: [success] logging enabled\n", 1uLL, 0x28uLL, stderr);
if ( *((_DWORD *)arg + 5) == 2 )
goto LABEL_7;
LABEL_3:
if ( *((_DWORD *)arg + 15) != 1 )
goto LABEL_4;
LABEL_8:
fwrite("airtraf_init: [info] starting capture mode\n", 1uLL, 0x2BuLL, stderr);
if ( !(unsigned int)init_capture(arg) )
fwrite("airtraf_init: [error] initializing capture mode failed\n", 1uLL, 0x37uLL, stderr);
LABEL_4:
*((_DWORD *)arg + 10) = pkt_card_sock_open(arg);
v1 = pkt_card_ifup(arg);
v2 = (const char *)*((_QWORD *)arg + 1);
if ( !v1 )
{
fprintf(stderr, "airtraf_init: [error] (%s) failed to bring the interface's configuration status up!\n", v2);
exit(-1);
}
fprintf(stderr, "airtraf_init: [success] (%s) flags updated to reflect UP & RUNNING.\n", v2);
initialize_packet_abstraction();
fwrite("airtraf_init: [success] initialized packet_abstraction engine.\n", 1uLL, 0x3FuLL, stderr);
initialize_p802_11b_parser();
fwrite("airtraf_init: [success] initialized 802.11b parser.\n", 1uLL, 0x34uLL, stderr);
fwrite("airtraf_init: [success] AirTraf initialization complete\n\n", 1uLL, 0x39uLL, stderr);
return gettimeofday(&t_start, 0LL);
}

original_code:
void airtraf_init(struct SETTINGS *mySettings)
{
  if (mySettings->logging_mode == 1){
    init_log(1,mySettings->logfile);
    fprintf(stderr, "airtraf_init: [success] logging enabled\n");
  }
  if (mySettings->conn_mode == 2){
    pthread_cond_init(&start_cond, ((void *)0));
    pthread_mutex_init(&start_lock, ((void *)0));
    pthread_mutex_lock(&start_lock);
    pthread_create(&thread, ((void *)0), server, (void *)mySettings);
    pthread_cond_wait(&start_cond, &start_lock);
    fprintf(stderr, "airtraf_init: [success] server started\n");
  }
  if (mySettings->capture_mode == 1){
    fprintf(stderr, "airtraf_init: [info] starting capture mode\n");
    if (!init_capture(mySettings)){
      fprintf(stderr, "airtraf_init: [error] initializing capture mode failed\n");
    }
  }
  (mySettings->sniff_socket) = pkt_card_sock_open(mySettings);
  if (!pkt_card_ifup(mySettings)){
    fprintf(stderr, "airtraf_init: [error] (%s) failed to bring the interface's configuration status up!\n", mySettings->interface);
    exit(-1);
  }
  else
    fprintf(stderr, "airtraf_init: [success] (%s) flags updated to reflect UP & RUNNING.\n", mySettings->interface);
  initialize_packet_abstraction();
  fprintf(stderr, "airtraf_init: [success] initialized packet_abstraction engine.\n");
  initialize_p802_11b_parser();
  fprintf(stderr, "airtraf_init: [success] initialized 802.11b parser.\n");
  fprintf(stderr, "airtraf_init: [success] AirTraf initialization complete\n\n");
  gettimeofday(&t_start,((void *)0));
}

variable_types: struct SETTINGS { int card_type; char *interface; int runtime_mode; int conn_mode; char *logfile; int logging_mode; int signal_support; int sniff_socket; int scan_mode; void *chosen_ap; int capture_version; int capture_mode; char *capture_file; unsigned int capture_size; unsigned int capture_seq; long *capture_timestamp; float capture_interval; float capture_duration; int capture_overwrite; int capture_command; int capture_status; } *


decompiled_code:
size_t __fastcall airtraf_start(__int64 a1)
{
int v1; // eax

fwrite("Entering AirTraf Execution...\n", 1uLL, 0x1EuLL, stderr);
v1 = *(_DWORD *)(a1 + 16);
if ( v1 == 1 )
{
initscr();
if ( LINES <= 44 || COLS <= 119 )
{
endwin();
fwrite("\nThis program requires a screen size of at least 120 columns by 45 lines\n", 1uLL, 0x49uLL, stderr);
fwrite("Please resize your window\n\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
start_color();
standardcolors(1LL);
noecho();
nonl();
cbreak();
program_interface(a1);
endwin();
}
else if ( !v1 )
{
*(_DWORD *)(a1 + 44) = 1;
initialize_detailed_scan();
init_potential_structs();
start_sniffer_engine(a1);
while ( (unsigned int)get_engine_status() == 1 )
{
pkt_card_ifup(a1);
sleep(1u);
}
free_potential_structs();
free_detailed_scan();
}
return fwrite("Leaving AirTraf Execution...\n\n", 1uLL, 0x1EuLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func1(__int64 a1)
{
int v1; // eax

fwrite("Entering AirTraf Execution...\n", 1uLL, 0x1EuLL, stderr);
v1 = *(_DWORD *)(a1 + 16);
if ( v1 == 1 )
{
initscr();
if ( LINES <= 44 || COLS <= 119 )
{
endwin();
fwrite("\nThis program requires a screen size of at least 120 columns by 45 lines\n", 1uLL, 0x49uLL, stderr);
fwrite("Please resize your window\n\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
start_color();
standardcolors(1LL);
noecho();
nonl();
cbreak();
program_interface(a1);
endwin();
}
else if ( !v1 )
{
*(_DWORD *)(a1 + 44) = 1;
initialize_detailed_scan();
init_potential_structs();
start_sniffer_engine(a1);
while ( (unsigned int)get_engine_status() == 1 )
{
pkt_card_ifup(a1);
sleep(1u);
}
free_potential_structs();
free_detailed_scan();
}
return fwrite("Leaving AirTraf Execution...\n\n", 1uLL, 0x1EuLL, stderr);
}

original_code:
void airtraf_start(struct SETTINGS *mySettings)
{
  fprintf(stderr, "Entering AirTraf Execution...\n");
  if (mySettings->runtime_mode == 1){
    initscr();
    if ((LINES < 45) || (COLS < 120)) {
      endwin();
      fprintf(stderr,
       "\nThis program requires a screen size of at least 120 columns by 45 lines\n");
      fprintf(stderr, "Please resize your window\n\n");
      exit(1);
    }
    start_color();
    standardcolors(1);
    noecho();
    nonl();
    cbreak();
    program_interface(mySettings);
    endwin();
  }
  else if (mySettings->runtime_mode == 0){
    mySettings->scan_mode = 1;
    initialize_detailed_scan();
    init_potential_structs();
    start_sniffer_engine(mySettings);
    while (get_engine_status() == 1){
      if (mySettings->capture_mode == 1){
      }
      pkt_card_ifup(mySettings);
      sleep(1);
    }
    free_potential_structs();
    free_detailed_scan();
  }
  fprintf(stderr, "Leaving AirTraf Execution...\n\n");
}

user_defined_types: struct SETTINGS { int card_type; char *interface; int runtime_mode; int conn_mode; char *logfile; int logging_mode; int signal_support; int sniff_socket; int scan_mode; void *chosen_ap; int capture_version; int capture_mode; char *capture_file; unsigned int capture_size; unsigned int capture_seq; long *capture_timestamp; float capture_interval; float capture_duration; int capture_overwrite; int capture_command; int capture_status; }


decompiled_code:
size_t __fastcall airtraf_end(__int64 a1)
{
__int64 v1; // rcx
__int128 v3[2]; // [rsp+0h] [rbp-108h] BYREF
int v4[56]; // [rsp+20h] [rbp-E8h] BYREF

if ( *(_DWORD *)(a1 + 32) == 1 )
{
memset(v4, 0, sizeof(v4));
v4[0] = 168438314;
v3[0] = (__int128)_mm_load_si128((const __m128i *)&LC15);
v3[1] = (__int128)_mm_load_si128((const __m128i *)&LC16);
write_log(1LL, v3);
close_log(1LL);
if ( *(_DWORD *)(a1 + 60) != 1 )
goto LABEL_3;
LABEL_5:
free_capture();
goto LABEL_3;
}
if ( *(_DWORD *)(a1 + 60) == 1 )
goto LABEL_5;
LABEL_3:
pkt_card_sock_close(a1);
gettimeofday(&t_end, 0LL);
hour = (LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) / 3600;
v1 = (unsigned int)((LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) / 60
- 60 * ((LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) / 3600));
min = v1;
sec = (LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) % 3600 - 60 * v1;
fprintf(
stderr,
"airtraf_end: [info] Elapsed Time: %02d:%02d:%02d\n",
(unsigned int)((LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) / 3600),
v1,
(unsigned int)sec);
return fwrite("airtraf_end: [info] Exiting gracefully...\n\n", 1uLL, 0x2BuLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func2(__int64 a1)
{
__int64 v1; // rcx
__int128 v3[2]; // [rsp+0h] [rbp-108h] BYREF
int v4[56]; // [rsp+20h] [rbp-E8h] BYREF

if ( *(_DWORD *)(a1 + 32) == 1 )
{
memset(v4, 0, sizeof(v4));
v4[0] = 168438314;
v3[0] = (__int128)_mm_load_si128((const __m128i *)&LC15);
v3[1] = (__int128)_mm_load_si128((const __m128i *)&LC16);
write_log(1LL, v3);
close_log(1LL);
if ( *(_DWORD *)(a1 + 60) != 1 )
goto LABEL_3;
LABEL_5:
free_capture();
goto LABEL_3;
}
if ( *(_DWORD *)(a1 + 60) == 1 )
goto LABEL_5;
LABEL_3:
pkt_card_sock_close(a1);
gettimeofday(&t_end, 0LL);
hour = (LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) / 3600;
v1 = (unsigned int)((LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) / 60
- 60 * ((LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) / 3600));
min = v1;
sec = (LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) % 3600 - 60 * v1;
fprintf(
stderr,
"airtraf_end: [info] Elapsed Time: %02d:%02d:%02d\n",
(unsigned int)((LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) / 3600),
v1,
(unsigned int)sec);
return fwrite("airtraf_end: [info] Exiting gracefully...\n\n", 1uLL, 0x2BuLL, stderr);
}

original_code:
void airtraf_end(struct SETTINGS *mySettings)
{
  unsigned char logmsg[256];
  if (mySettings->logging_mode == 1){
    bzero(logmsg,sizeof(logmsg));
    sprintf(logmsg,"** AirTraf Server Shutting Down **\n\n");
    write_log(1,logmsg);
    close_log(1);
  }
  if (mySettings->capture_mode == 1){
    free_capture();
  }
  pkt_card_sock_close(mySettings);
  if (1 == 1) {
    gettimeofday(&t_end,((void *)0));
    hour = ((t_end.tv_sec - t_start.tv_sec) / 3600);
    min = (((t_end.tv_sec - t_start.tv_sec) / 60)-(hour * 60));
    sec = ((t_end.tv_sec - t_start.tv_sec) - (hour *3600) - (min * 60));
    fprintf(stderr,"airtraf_end: [info] Elapsed Time: %02d:%02d:%02d\n",hour,min,sec);
    fprintf(stderr,"airtraf_end: [info] Exiting gracefully...\n\n");
  }
  else if (1 == 0) {
    fprintf(stderr,"airtraf_end: [info] Exiting gracefully...\n");
  }
}

variable_types:
logmsg
unsigned char [256]


decompiled_code:
void __fastcall __noreturn term_signal_handler(unsigned int a1)
{
unsigned int v1; // eax

if ( a1 != 1 )
{
v1 = getpid();
fprintf(stderr, "AirTraf process %u exiting on signal %d\n\n", v1, a1);
}
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(unsigned int a1)
{
unsigned int v1; // eax

if ( a1 != 1 )
{
v1 = getpid();
fprintf(stderr, "AirTraf process %u exiting on signal %d\n\n", v1, a1);
}
exit(1);
}

original_code:
void term_signal_handler(int signo)
{
    if (signo != 1)
 fprintf(stderr, "AirTraf process %u exiting on signal %d\n\n",
  getpid(), signo);
    exit(1);
}

variable_types: signo int


usage

decompiled_code:
void __fastcall __noreturn usage(const char *a1)
{
fwrite("--------------------------------------------------------------------------\n", 1uLL, 0x4BuLL, stderr);
fwrite(
"AirTraf: a wireless (802.11) network performance analyzer. by Peter K. Lee (Elixar, Inc.)\n",
1uLL,
0x5AuLL,
stderr);
fprintf(
stderr,
"\nUsage:\n\t%s [-l -f] [-C <cardtype>] [-I <interface>] [-D] [-x] [-A <capture>] [-L <logfile>]\n",
a1);
fwrite("\n-l : list available wireless devices in the system (& exits)\n", 1uLL, 0x3EuLL, stderr);
fwrite("-f : force monitor mode, manual override, etc. (w/o prompting for sanity check)\n", 1uLL, 0x50uLL, stderr);
fwrite("-C : card type, either prism2, hermes or aironet (manual override)\n", 1uLL, 0x43uLL, stderr);
fwrite("-I : interface to listen on eth0. eth1, wlan0, etc. (manual override)\n", 1uLL, 0x46uLL, stderr);
fwrite("-D : runs the program in daemonized background *default:OFF* \n", 1uLL, 0x3EuLL, stderr);
fwrite("-A : runs the program in capture mode (filename arg allowed) \n", 1uLL, 0x3EuLL, stderr);
fwrite(
"-L : enable logging mode *default:OFF (argument allows specification of log file name) \n",
1uLL,
0x58uLL,
stderr);
fwrite("-x : enable signal strength *default:OFF (using patched aironet driver) \n", 1uLL, 0x49uLL, stderr);
fwrite("-h : view this usage message\n\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func1(const char *a1)
{
fwrite("--------------------------------------------------------------------------\n", 1uLL, 0x4BuLL, stderr);
fwrite(
"AirTraf: a wireless (802.11) network performance analyzer. by Peter K. Lee (Elixar, Inc.)\n",
1uLL,
0x5AuLL,
stderr);
fprintf(
stderr,
"\nUsage:\n\t%s [-l -f] [-C <cardtype>] [-I <interface>] [-D] [-x] [-A <capture>] [-L <logfile>]\n",
a1);
fwrite("\n-l : list available wireless devices in the system (& exits)\n", 1uLL, 0x3EuLL, stderr);
fwrite("-f : force monitor mode, manual override, etc. (w/o prompting for sanity check)\n", 1uLL, 0x50uLL, stderr);
fwrite("-C : card type, either prism2, hermes or aironet (manual override)\n", 1uLL, 0x43uLL, stderr);
fwrite("-I : interface to listen on eth0. eth1, wlan0, etc. (manual override)\n", 1uLL, 0x46uLL, stderr);
fwrite("-D : runs the program in daemonized background *default:OFF* \n", 1uLL, 0x3EuLL, stderr);
fwrite("-A : runs the program in capture mode (filename arg allowed) \n", 1uLL, 0x3EuLL, stderr);
fwrite(
"-L : enable logging mode *default:OFF (argument allows specification of log file name) \n",
1uLL,
0x58uLL,
stderr);
fwrite("-x : enable signal strength *default:OFF (using patched aironet driver) \n", 1uLL, 0x49uLL, stderr);
fwrite("-h : view this usage message\n\n", 1uLL, 0x1EuLL, stderr);
exit(1);
}

original_code:
static void usage (const char *pname)
{
  fprintf(stderr, "--------------------------------------------------------------------------\n");
  fprintf(stderr, "AirTraf: a wireless (802.11) network performance analyzer. by Peter K. Lee (Elixar, Inc.)\n");
  fprintf(stderr, "\nUsage:\n\t%s [-l -f] [-C <cardtype>] [-I <interface>] [-D] [-x] [-A <capture>] [-L <logfile>]\n", pname);
  fprintf(stderr, "\n-l : list available wireless devices in the system (& exits)\n");
  fprintf(stderr, "-f : force monitor mode, manual override, etc. (w/o prompting for sanity check)\n");
  fprintf(stderr, "-C : card type, either prism2, hermes or aironet (manual override)\n");
  fprintf(stderr, "-I : interface to listen on eth0. eth1, wlan0, etc. (manual override)\n");
  fprintf(stderr, "-D : runs the program in daemonized background *default:OFF* \n");
  fprintf(stderr, "-A : runs the program in capture mode (filename arg allowed) \n");
  fprintf(stderr, "-L : enable logging mode *default:OFF (argument allows specification of log file name) \n");
  fprintf(stderr, "-x : enable signal strength *default:OFF (using patched aironet driver) \n");
  fprintf(stderr, "-h : view this usage message\n\n");
  exit(1);
}

canonical_original_code:
static void usage(char *pname)
{
  fprintf(stderr, "--------------------------------------------------------------------------\n");
  fprintf(stderr, "AirTraf: a wireless (802.11) network performance analyzer. by Peter K. Lee (Elixar, Inc.)\n");
  fprintf(stderr, "\nUsage:\n\t%s [-l -f] [-C <cardtype>] [-I <interface>] [-D] [-x] [-A <capture>] [-L <logfile>]\n", pname);
  fprintf(stderr, "\n-l : list available wireless devices in the system (& exits)\n");
  fprintf(stderr, "-f : force monitor mode, manual override, etc. (w/o prompting for sanity check)\n");
  fprintf(stderr, "-C : card type, either prism2, hermes or aironet (manual override)\n");
  fprintf(stderr, "-I : interface to listen on eth0. eth1, wlan0, etc. (manual override)\n");
  fprintf(stderr, "-D : runs the program in daemonized background *default:OFF* \n");
  fprintf(stderr, "-A : runs the program in capture mode (filename arg allowed) \n");
  fprintf(stderr, "-L : enable logging mode *default:OFF (argument allows specification of log file name) \n");
  fprintf(stderr, "-x : enable signal strength *default:OFF (using patched aironet driver) \n");
  fprintf(stderr, "-h : view this usage message\n\n");
  exit(1);
}

variable_types:
pname
char *


decompiled_code:
size_t dump_trace()
{
__int64 v0; // r13
__int64 v1; // r12
unsigned int *v2; // rbp
__int64 v3; // rbx
__int64 v4; // r13
__int64 v5; // r12
__int64 v6; // rbp
__int64 v7; // rbx

v0 = get_p_nodes();
v1 = get_p_aps();
v2 = (unsigned int *)get_channel_snapshot();
v3 = get_detailed_snapshot();
fwrite("\n--------------- TRACE DUMP --------------------\n", 1uLL, 0x33uLL, stderr);
fwrite("SETTINGS:\n", 1uLL, 0xAuLL, stderr);
fprintf(
stderr,
"card_type=%d \tinterface=%s \truntime_mode=%d \tconn_mode=%d\n",
*(unsigned int *)myset_ptr,
*(const char **)(myset_ptr + 8),
*(unsigned int *)(myset_ptr + 16),
*(unsigned int *)(myset_ptr + 20));
fprintf(
stderr,
"signal_support=%d \tsniff_socket=%d \tscan_mode=%d ",
*(unsigned int *)(myset_ptr + 36),
*(unsigned int *)(myset_ptr + 40),
*(unsigned int *)(myset_ptr + 44));
if ( *(_QWORD *)(myset_ptr + 48) )
fwrite("\tchosen_ap= OK\n\n", 1uLL, 0x10uLL, stderr);
else
fwrite("\tchosen_ap= NULL\n\n", 1uLL, 0x12uLL, stderr);
fwrite("DATA STRUCTURES:\n", 1uLL, 0x11uLL, stderr);
if ( v0 )
fprintf(stderr, "potential_nodes= OK \tnum=%d\n", *(unsigned __int8 *)(v0 + 2000));
else
fwrite("potential_nodes= NULL\n", 1uLL, 0x16uLL, stderr);
if ( v1 )
fprintf(stderr, "potential_aps= OK \tnum=%d\n", *(unsigned __int8 *)(v1 + 8800));
else
fwrite("potential_aps= NULL\n", 1uLL, 0x14uLL, stderr);
if ( v2 )
fprintf(stderr, "channel_overview= OK \tnum_det_aps=%d\n", *v2);
else
fwrite("channel_overview= NULL\n", 1uLL, 0x17uLL, stderr);
if ( v3 )
{
fprintf(
stderr,
"detailed_overview_t= OK \ttot_ap=%d \ttot_nodes=%d\n",
*(unsigned __int8 *)(v3 + 48),
*(unsigned __int16 *)(v3 + 50));
v4 = *(_QWORD *)(v3 + 56);
if ( v4 )
{
do
{
while ( 1 )
{
fprintf(stderr, "bss_t= OK \tnum nodes=%d\n", *(unsigned __int8 *)(v4 + 1256));
v5 = *(_QWORD *)(v4 + 1264);
if ( v5 )
break;
fwrite("bss_node_t= NULL\n", 1uLL, 0x11uLL, stderr);
v4 = *(_QWORD *)(v4 + 1280);
if ( !v4 )
return fwrite(
"\n-----------------------------------------------------------------\n\n",
1uLL,
0x44uLL,
stderr);
}
do
{
while ( 1 )
{
fprintf(
stderr,
"bss_node_t= OK \tstatus=%d \ttot_packet=%d \ttcp_conns=%d\n",
*(unsigned __int8 *)(v5 + 80),
*(unsigned int *)(v5 + 28),
*(unsigned __int16 *)(v5 + 116));
v6 = *(_QWORD *)(v5 + 120);
if ( v6 )
break;
fwrite("tcptable_t= NULL\n", 1uLL, 0x11uLL, stderr);
v5 = *(_QWORD *)(v5 + 136);
if ( !v5 )
goto LABEL_17;
}
do
{
while ( 1 )
{
fprintf(stderr, "tcptable_t= OK \tnum_connected=%d\n", *(unsigned __int16 *)(v6 + 274));
v7 = *(_QWORD *)(v6 + 280);
if ( v7 )
break;
fwrite("tcpconn_t= NULL\n", 1uLL, 0x10uLL, stderr);
v6 = *(_QWORD *)(v6 + 296);
if ( !v6 )
goto LABEL_16;
}
do
{
fprintf(stderr, "tcpconn_t= OK \ttotal_count=%d\n", *(unsigned int *)(v7 + 152));
v7 = *(_QWORD *)(v7 + 216);
}
while ( v7 );
v6 = *(_QWORD *)(v6 + 296);
}
while ( v6 );
LABEL_16:
v5 = *(_QWORD *)(v5 + 136);
}
while ( v5 );
LABEL_17:
v4 = *(_QWORD *)(v4 + 1280);
}
while ( v4 );
}
else
{
fwrite("bss_t= NULL\n", 1uLL, 0xCuLL, stderr);
}
}
else
{
fwrite("detailed_overview_t= NULL\n", 1uLL, 0x1AuLL, stderr);
}
return fwrite("\n-----------------------------------------------------------------\n\n", 1uLL, 0x44uLL, stderr);
}

canonical_decompiled_code:
size_t func3()
{
__int64 v0; // r13
__int64 v1; // r12
unsigned int *v2; // rbp
__int64 v3; // rbx
__int64 v4; // r13
__int64 v5; // r12
__int64 v6; // rbp
__int64 v7; // rbx

v0 = get_p_nodes();
v1 = get_p_aps();
v2 = (unsigned int *)get_channel_snapshot();
v3 = get_detailed_snapshot();
fwrite("\n--------------- TRACE DUMP --------------------\n", 1uLL, 0x33uLL, stderr);
fwrite("SETTINGS:\n", 1uLL, 0xAuLL, stderr);
fprintf(
stderr,
"card_type=%d \tinterface=%s \truntime_mode=%d \tconn_mode=%d\n",
*(unsigned int *)myset_ptr,
*(const char **)(myset_ptr + 8),
*(unsigned int *)(myset_ptr + 16),
*(unsigned int *)(myset_ptr + 20));
fprintf(
stderr,
"signal_support=%d \tsniff_socket=%d \tscan_mode=%d ",
*(unsigned int *)(myset_ptr + 36),
*(unsigned int *)(myset_ptr + 40),
*(unsigned int *)(myset_ptr + 44));
if ( *(_QWORD *)(myset_ptr + 48) )
fwrite("\tchosen_ap= OK\n\n", 1uLL, 0x10uLL, stderr);
else
fwrite("\tchosen_ap= NULL\n\n", 1uLL, 0x12uLL, stderr);
fwrite("DATA STRUCTURES:\n", 1uLL, 0x11uLL, stderr);
if ( v0 )
fprintf(stderr, "potential_nodes= OK \tnum=%d\n", *(unsigned __int8 *)(v0 + 2000));
else
fwrite("potential_nodes= NULL\n", 1uLL, 0x16uLL, stderr);
if ( v1 )
fprintf(stderr, "potential_aps= OK \tnum=%d\n", *(unsigned __int8 *)(v1 + 8800));
else
fwrite("potential_aps= NULL\n", 1uLL, 0x14uLL, stderr);
if ( v2 )
fprintf(stderr, "channel_overview= OK \tnum_det_aps=%d\n", *v2);
else
fwrite("channel_overview= NULL\n", 1uLL, 0x17uLL, stderr);
if ( v3 )
{
fprintf(
stderr,
"detailed_overview_t= OK \ttot_ap=%d \ttot_nodes=%d\n",
*(unsigned __int8 *)(v3 + 48),
*(unsigned __int16 *)(v3 + 50));
v4 = *(_QWORD *)(v3 + 56);
if ( v4 )
{
do
{
while ( 1 )
{
fprintf(stderr, "bss_t= OK \tnum nodes=%d\n", *(unsigned __int8 *)(v4 + 1256));
v5 = *(_QWORD *)(v4 + 1264);
if ( v5 )
break;
fwrite("bss_node_t= NULL\n", 1uLL, 0x11uLL, stderr);
v4 = *(_QWORD *)(v4 + 1280);
if ( !v4 )
return fwrite(
"\n-----------------------------------------------------------------\n\n",
1uLL,
0x44uLL,
stderr);
}
do
{
while ( 1 )
{
fprintf(
stderr,
"bss_node_t= OK \tstatus=%d \ttot_packet=%d \ttcp_conns=%d\n",
*(unsigned __int8 *)(v5 + 80),
*(unsigned int *)(v5 + 28),
*(unsigned __int16 *)(v5 + 116));
v6 = *(_QWORD *)(v5 + 120);
if ( v6 )
break;
fwrite("tcptable_t= NULL\n", 1uLL, 0x11uLL, stderr);
v5 = *(_QWORD *)(v5 + 136);
if ( !v5 )
goto LABEL_17;
}
do
{
while ( 1 )
{
fprintf(stderr, "tcptable_t= OK \tnum_connected=%d\n", *(unsigned __int16 *)(v6 + 274));
v7 = *(_QWORD *)(v6 + 280);
if ( v7 )
break;
fwrite("tcpconn_t= NULL\n", 1uLL, 0x10uLL, stderr);
v6 = *(_QWORD *)(v6 + 296);
if ( !v6 )
goto LABEL_16;
}
do
{
fprintf(stderr, "tcpconn_t= OK \ttotal_count=%d\n", *(unsigned int *)(v7 + 152));
v7 = *(_QWORD *)(v7 + 216);
}
while ( v7 );
v6 = *(_QWORD *)(v6 + 296);
}
while ( v6 );
LABEL_16:
v5 = *(_QWORD *)(v5 + 136);
}
while ( v5 );
LABEL_17:
v4 = *(_QWORD *)(v4 + 1280);
}
while ( v4 );
}
else
{
fwrite("bss_t= NULL\n", 1uLL, 0xCuLL, stderr);
}
}
else
{
fwrite("detailed_overview_t= NULL\n", 1uLL, 0x1AuLL, stderr);
}
return fwrite("\n-----------------------------------------------------------------\n\n", 1uLL, 0x44uLL, stderr);
}

original_code:
void dump_trace()
{
  potential_node_t * pnt = (potential_node_t *)get_p_nodes();
  potential_ap_t * pat = (potential_ap_t *)get_p_aps();
  struct channel_overview *cov = get_channel_snapshot();
  detailed_overview_t *ov = get_detailed_snapshot();
  bss_t *bsst = ((void *)0);
  bss_node_t *bsnt = ((void *)0);
  tcptable_t *tent = ((void *)0);
  tcpconn_t *tcon = ((void *)0);
  fprintf(stderr, "\n---------------  TRACE DUMP  --------------------\n");
  fprintf(stderr, "SETTINGS:\n");
  fprintf(stderr, "card_type=%d \tinterface=%s \truntime_mode=%d \tconn_mode=%d\n",
   myset_ptr->card_type, myset_ptr->interface, myset_ptr->runtime_mode, myset_ptr->conn_mode);
  fprintf(stderr, "signal_support=%d \tsniff_socket=%d \tscan_mode=%d ",
  myset_ptr->signal_support, myset_ptr->sniff_socket, myset_ptr->scan_mode);
  if (myset_ptr->chosen_ap != ((void *)0))
    fprintf(stderr, "\tchosen_ap= OK\n\n");
  else
    fprintf(stderr, "\tchosen_ap= NULL\n\n");
  fprintf(stderr, "DATA STRUCTURES:\n");
  if (pnt == ((void *)0))
    fprintf(stderr, "potential_nodes= NULL\n");
  else{
    fprintf(stderr, "potential_nodes= OK \tnum=%d\n", pnt->num);
  }
  if (pat == ((void *)0))
    fprintf(stderr, "potential_aps= NULL\n");
  else{
    fprintf(stderr, "potential_aps= OK \tnum=%d\n", pat->num);
  }
  if (cov == ((void *)0))
    fprintf(stderr, "channel_overview= NULL\n");
  else{
    fprintf(stderr, "channel_overview= OK \tnum_det_aps=%d\n", cov->num_det_aps);
  }
  if (ov == ((void *)0))
    fprintf(stderr, "detailed_overview_t= NULL\n");
  else{
    fprintf(stderr, "detailed_overview_t= OK \ttot_ap=%d \ttot_nodes=%d\n",
     ov->tot_num_ap, ov->tot_num_nodes);
    if (((void *)0) == (bsst = ov->bss_list_top))
      fprintf(stderr, "bss_t= NULL\n");
    else{
      while (bsst != ((void *)0)){
 fprintf(stderr, "bss_t= OK \tnum nodes=%d\n", bsst->num);
 if (((void *)0)== (bsnt = bsst->addr_list_head))
   fprintf(stderr, "bss_node_t= NULL\n");
 else{
   while (bsnt != ((void *)0)){
     fprintf(stderr, "bss_node_t= OK \tstatus=%d \ttot_packet=%d \ttcp_conns=%d\n",
      bsnt->status, bsnt->tot_packet, bsnt->tcp_connections);
     if (((void *)0) == (tent = bsnt->tcpinfo_head))
       fprintf(stderr, "tcptable_t= NULL\n");
     else{
       while (tent != ((void *)0)){
  fprintf(stderr, "tcptable_t= OK \tnum_connected=%d\n", tent->num_connected);
  if (((void *)0) == (tcon = tent->tcpconn_head))
    fprintf(stderr, "tcpconn_t= NULL\n");
  else{
    while (tcon != ((void *)0)){
      fprintf(stderr, "tcpconn_t= OK \ttotal_count=%d\n", tcon->total_count);
      tcon = tcon->next;
    }
  }
  tent = tent->next;
       }
     }
     bsnt = bsnt->next;
   }
 }
 bsst = bsst->next;
      }
    }
  }
  fprintf(stderr, "\n-----------------------------------------------------------------\n\n");
}

canonical_original_code:
void dump_trace()
{
  struct potential_node_t *pnt = (potential_node_t *)get_p_nodes();
  struct potential_ap_t *pat = (potential_ap_t *)get_p_aps();
  struct channel_overview *cov = get_channel_snapshot();
  struct detailed_overview_t *ov = get_detailed_snapshot();
  struct bss_t *bsst = ((void *)0);
  struct bss_node_t *bsnt = ((void *)0);
  struct tcptable_t *tent = ((void *)0);
  struct tcpconn_t *tcon = ((void *)0);
  fprintf(stderr, "\n---------------  TRACE DUMP  --------------------\n");
  fprintf(stderr, "SETTINGS:\n");
  fprintf(stderr, "card_type=%d \tinterface=%s \truntime_mode=%d \tconn_mode=%d\n",
   myset_ptr->card_type, myset_ptr->interface, myset_ptr->runtime_mode, myset_ptr->conn_mode);
  fprintf(stderr, "signal_support=%d \tsniff_socket=%d \tscan_mode=%d ",
  myset_ptr->signal_support, myset_ptr->sniff_socket, myset_ptr->scan_mode);
  if (myset_ptr->chosen_ap != ((void *)0))
    fprintf(stderr, "\tchosen_ap= OK\n\n");
  else
    fprintf(stderr, "\tchosen_ap= NULL\n\n");
  fprintf(stderr, "DATA STRUCTURES:\n");
  if (pnt == ((void *)0))
    fprintf(stderr, "potential_nodes= NULL\n");
  else{
    fprintf(stderr, "potential_nodes= OK \tnum=%d\n", pnt->num);
  }
  if (pat == ((void *)0))
    fprintf(stderr, "potential_aps= NULL\n");
  else{
    fprintf(stderr, "potential_aps= OK \tnum=%d\n", pat->num);
  }
  if (cov == ((void *)0))
    fprintf(stderr, "channel_overview= NULL\n");
  else{
    fprintf(stderr, "channel_overview= OK \tnum_det_aps=%d\n", cov->num_det_aps);
  }
  if (ov == ((void *)0))
    fprintf(stderr, "detailed_overview_t= NULL\n");
  else{
    fprintf(stderr, "detailed_overview_t= OK \ttot_ap=%d \ttot_nodes=%d\n",
     ov->tot_num_ap, ov->tot_num_nodes);
    if (((void *)0) == (bsst = ov->bss_list_top))
      fprintf(stderr, "bss_t= NULL\n");
    else{
      while (bsst != ((void *)0)){
 fprintf(stderr, "bss_t= OK \tnum nodes=%d\n", bsst->num);
 if (((void *)0)== (bsnt = bsst->addr_list_head))
   fprintf(stderr, "bss_node_t= NULL\n");
 else{
   while (bsnt != ((void *)0)){
     fprintf(stderr, "bss_node_t= OK \tstatus=%d \ttot_packet=%d \ttcp_conns=%d\n",
      bsnt->status, bsnt->tot_packet, bsnt->tcp_connections);
     if (((void *)0) == (tent = bsnt->tcpinfo_head))
       fprintf(stderr, "tcptable_t= NULL\n");
     else{
       while (tent != ((void *)0)){
  fprintf(stderr, "tcptable_t= OK \tnum_connected=%d\n", tent->num_connected);
  if (((void *)0) == (tcon = tent->tcpconn_head))
    fprintf(stderr, "tcpconn_t= NULL\n");
  else{
    while (tcon != ((void *)0)){
      fprintf(stderr, "tcpconn_t= OK \ttotal_count=%d\n", tcon->total_count);
      tcon = tcon->next;
    }
  }
  tent = tent->next;
       }
     }
     bsnt = bsnt->next;
   }
 }
 bsst = bsst->next;
      }
    }
  }
  fprintf(stderr, "\n-----------------------------------------------------------------\n\n");
}

variable_types: struct potential_node_t { struct pnode_t { unsigned char mac_addr[6]; unsigned int time_of_entry; unsigned int bytes_seen; unsigned char status; } nodes[100]; unsigned char num; } *

variable_types: struct potential_ap_t { struct access_point { unsigned char channel; unsigned char bssid[6]; unsigned char ssid[32]; unsigned char available_band; unsigned char wep_status; unsigned char traffic_type; unsigned short mgmt_count; unsigned short ctrl_count; unsigned short data_count; unsigned int packet_count; unsigned short encrypt_count; struct timeval { long tv_sec; long tv_usec; } timestamp; unsigned char status; float signal_str; void *next; } ap_list[100]; unsigned char num; } *

variable_types: struct channel_overview { unsigned int num_det_aps; unsigned int num_active_aps; struct access_point { unsigned char channel; unsigned char bssid[6]; unsigned char ssid[32]; unsigned char available_band; unsigned char wep_status; unsigned char traffic_type; unsigned short mgmt_count; unsigned short ctrl_count; unsigned short data_count; unsigned int packet_count; unsigned short encrypt_count; struct timeval { long tv_sec; long tv_usec; } timestamp; unsigned char status; float signal_str; void *next; } *all_chan[15]; } *

variable_types: struct detailed_overview_t { struct in_addr { unsigned int s_addr; } sniffer_ip; struct in_addr poller_ip; unsigned short bad_mac; unsigned int bad_mac_byte; unsigned short bad_ip_chksum; unsigned int bad_ip_chksum_byte; unsigned short fcs_error; unsigned int fcs_error_byte; unsigned short filtered_data; unsigned int filtered_data_byte; unsigned short corrupt_tot; unsigned int corrupt_tot_byte; unsigned char tot_num_ap; unsigned short tot_num_nodes; struct bss_t { unsigned char bssid[6]; unsigned char ssid[32]; unsigned char channel; unsigned char available_band; unsigned char wep_status; unsigned int overall_count; unsigned int overall_byte; float link_utilization; float background_noise; float packet_loss; struct mgmt_t { unsigned int mgmt_count; unsigned int mgmt_byte; unsigned short beacon; unsigned short disassoc; unsigned short other; struct bandwidth_t { unsigned int old_count_frame; unsigned int old_byte_tot; unsigned int tot_byte; unsigned short num; struct timeval { long tv_sec; long tv_usec; } old_time; float curr; float high; float low; float avg; } bndwth; } mgmt_data; struct control_t { unsigned int control_count; unsigned int control_byte; unsigned short ack; unsigned short other; struct bandwidth_t bndwth; } ctrl_data; struct data_t { unsigned int data_count; unsigned int data_byte; unsigned int external_count; unsigned int external_byte; unsigned int internal_count; unsigned int internal_byte; struct bandwidth_t bndwth; struct bandwidth_t extband; } normal_data; struct netproto_t { struct proto_info_t { unsigned int count; unsigned int byte; unsigned int out_count; unsigned int out_byte; unsigned int in_count; unsigned int in_byte; struct bandwidth_t band; unsigned int ext_count; unsigned int ext_byte; struct bandwidth_t extband; } ip; struct proto_info_t ipv6; struct proto_info_t other; } network_data; struct transproto_t { struct proto_info_t tcp; struct proto_info_t udp; struct proto_info_t icmp; struct proto_info_t other; } transport_data; struct bandwidth_t bndwth; unsigned char num; struct bss_node_t { struct in_addr ip_addr; unsigned char mac_addr[6]; unsigned int inc_packet; unsigned int inc_byte; unsigned int out_packet; unsigned int out_byte; unsigned int tot_packet; struct bandwidth_t bndwth; unsigned char status; unsigned int tot_signal_str; float avg_signal_str; unsigned int tcp_total_count; unsigned int tcp_total_byte; unsigned short tcp_retransmit_count; unsigned int tcp_retransmit_byte; unsigned short tcp_existing_count; unsigned int tcp_existing_byte; unsigned short tcp_connections; struct tcptable_t { struct in_addr other_addr; unsigned short service_port; unsigned char initiator; unsigned int incoming_count; unsigned int incoming_byte; struct latency_t { struct timeval last_time; unsigned short num; float curr; float high; float low; float avg; } incoming_latency; struct bandwidth_t incoming_rate; unsigned int outgoing_count; unsigned int outgoing_byte; struct latency_t outgoing_latency; struct bandwidth_t outgoing_rate; unsigned int total_count; unsigned int total_byte; unsigned short retransmit_count; unsigned int retransmit_byte; unsigned short reset_count; float avg_rtt_latency; struct bandwidth_t total_rate; unsigned short closed_connections; unsigned short num_connected; struct tcpconn_t { unsigned short unique_port; unsigned char initiator; unsigned char conn_status; unsigned short inc_window; unsigned short inc_old_window; unsigned int incoming_count; unsigned int incoming_byte; unsigned int last_incoming_seq_num; unsigned int curr_incoming_seq_num; unsigned int acked_incoming_seq_num; unsigned int ack_outgoing_seq_num; unsigned char incoming_dup_ack; struct latency_t incoming_latency; unsigned short out_window; unsigned short out_old_window; unsigned int outgoing_count; unsigned int outgoing_byte; unsigned int last_outgoing_seq_num; unsigned int curr_outgoing_seq_num; unsigned int acked_outgoing_seq_num; unsigned int tracked_seq_num; unsigned char outgoing_dup_ack; struct latency_t outgoing_latency; unsigned int total_count; unsigned int total_byte; unsigned short retransmit_count; unsigned int retransmit_byte; unsigned char tracking_rtt; struct latency_t total_rtt; void *next; } *tcpconn_head; struct tcpconn_t *tcpconn_tail; void *next; } *tcpinfo_head; struct tcptable_t *tcpinfo_tail; void *next; } *addr_list_head; struct bss_node_t *addr_list_tail; void *next; } *bss_list_top; } *

variable_types: struct bss_t { unsigned char bssid[6]; unsigned char ssid[32]; unsigned char channel; unsigned char available_band; unsigned char wep_status; unsigned int overall_count; unsigned int overall_byte; float link_utilization; float background_noise; float packet_loss; struct mgmt_t { unsigned int mgmt_count; unsigned int mgmt_byte; unsigned short beacon; unsigned short disassoc; unsigned short other; struct bandwidth_t { unsigned int old_count_frame; unsigned int old_byte_tot; unsigned int tot_byte; unsigned short num; struct timeval { long tv_sec; long tv_usec; } old_time; float curr; float high; float low; float avg; } bndwth; } mgmt_data; struct control_t { unsigned int control_count; unsigned int control_byte; unsigned short ack; unsigned short other; struct bandwidth_t bndwth; } ctrl_data; struct data_t { unsigned int data_count; unsigned int data_byte; unsigned int external_count; unsigned int external_byte; unsigned int internal_count; unsigned int internal_byte; struct bandwidth_t bndwth; struct bandwidth_t extband; } normal_data; struct netproto_t { struct proto_info_t { unsigned int count; unsigned int byte; unsigned int out_count; unsigned int out_byte; unsigned int in_count; unsigned int in_byte; struct bandwidth_t band; unsigned int ext_count; unsigned int ext_byte; struct bandwidth_t extband; } ip; struct proto_info_t ipv6; struct proto_info_t other; } network_data; struct transproto_t { struct proto_info_t tcp; struct proto_info_t udp; struct proto_info_t icmp; struct proto_info_t other; } transport_data; struct bandwidth_t bndwth; unsigned char num; struct bss_node_t { struct in_addr { unsigned int s_addr; } ip_addr; unsigned char mac_addr[6]; unsigned int inc_packet; unsigned int inc_byte; unsigned int out_packet; unsigned int out_byte; unsigned int tot_packet; struct bandwidth_t bndwth; unsigned char status; unsigned int tot_signal_str; float avg_signal_str; unsigned int tcp_total_count; unsigned int tcp_total_byte; unsigned short tcp_retransmit_count; unsigned int tcp_retransmit_byte; unsigned short tcp_existing_count; unsigned int tcp_existing_byte; unsigned short tcp_connections; struct tcptable_t { struct in_addr other_addr; unsigned short service_port; unsigned char initiator; unsigned int incoming_count; unsigned int incoming_byte; struct latency_t { struct timeval last_time; unsigned short num; float curr; float high; float low; float avg; } incoming_latency; struct bandwidth_t incoming_rate; unsigned int outgoing_count; unsigned int outgoing_byte; struct latency_t outgoing_latency; struct bandwidth_t outgoing_rate; unsigned int total_count; unsigned int total_byte; unsigned short retransmit_count; unsigned int retransmit_byte; unsigned short reset_count; float avg_rtt_latency; struct bandwidth_t total_rate; unsigned short closed_connections; unsigned short num_connected; struct tcpconn_t { unsigned short unique_port; unsigned char initiator; unsigned char conn_status; unsigned short inc_window; unsigned short inc_old_window; unsigned int incoming_count; unsigned int incoming_byte; unsigned int last_incoming_seq_num; unsigned int curr_incoming_seq_num; unsigned int acked_incoming_seq_num; unsigned int ack_outgoing_seq_num; unsigned char incoming_dup_ack; struct latency_t incoming_latency; unsigned short out_window; unsigned short out_old_window; unsigned int outgoing_count; unsigned int outgoing_byte; unsigned int last_outgoing_seq_num; unsigned int curr_outgoing_seq_num; unsigned int acked_outgoing_seq_num; unsigned int tracked_seq_num; unsigned char outgoing_dup_ack; struct latency_t outgoing_latency; unsigned int total_count; unsigned int total_byte; unsigned short retransmit_count; unsigned int retransmit_byte; unsigned char tracking_rtt; struct latency_t total_rtt; void *next; } *tcpconn_head; struct tcpconn_t *tcpconn_tail; void *next; } *tcpinfo_head; struct tcptable_t *tcpinfo_tail; void *next; } *addr_list_head; struct bss_node_t *addr_list_tail; void *next; } *

variable_types: struct bss_node_t { struct in_addr { unsigned int s_addr; } ip_addr; unsigned char mac_addr[6]; unsigned int inc_packet; unsigned int inc_byte; unsigned int out_packet; unsigned int out_byte; unsigned int tot_packet; struct bandwidth_t { unsigned int old_count_frame; unsigned int old_byte_tot; unsigned int tot_byte; unsigned short num; struct timeval { long tv_sec; long tv_usec; } old_time; float curr; float high; float low; float avg; } bndwth; unsigned char status; unsigned int tot_signal_str; float avg_signal_str; unsigned int tcp_total_count; unsigned int tcp_total_byte; unsigned short tcp_retransmit_count; unsigned int tcp_retransmit_byte; unsigned short tcp_existing_count; unsigned int tcp_existing_byte; unsigned short tcp_connections; struct tcptable_t { struct in_addr other_addr; unsigned short service_port; unsigned char initiator; unsigned int incoming_count; unsigned int incoming_byte; struct latency_t { struct timeval last_time; unsigned short num; float curr; float high; float low; float avg; } incoming_latency; struct bandwidth_t incoming_rate; unsigned int outgoing_count; unsigned int outgoing_byte; struct latency_t outgoing_latency; struct bandwidth_t outgoing_rate; unsigned int total_count; unsigned int total_byte; unsigned short retransmit_count; unsigned int retransmit_byte; unsigned short reset_count; float avg_rtt_latency; struct bandwidth_t total_rate; unsigned short closed_connections; unsigned short num_connected; struct tcpconn_t { unsigned short unique_port; unsigned char initiator; unsigned char conn_status; unsigned short inc_window; unsigned short inc_old_window; unsigned int incoming_count; unsigned int incoming_byte; unsigned int last_incoming_seq_num; unsigned int curr_incoming_seq_num; unsigned int acked_incoming_seq_num; unsigned int ack_outgoing_seq_num; unsigned char incoming_dup_ack; struct latency_t incoming_latency; unsigned short out_window; unsigned short out_old_window; unsigned int outgoing_count; unsigned int outgoing_byte; unsigned int last_outgoing_seq_num; unsigned int curr_outgoing_seq_num; unsigned int acked_outgoing_seq_num; unsigned int tracked_seq_num; unsigned char outgoing_dup_ack; struct latency_t outgoing_latency; unsigned int total_count; unsigned int total_byte; unsigned short retransmit_count; unsigned int retransmit_byte; unsigned char tracking_rtt; struct latency_t total_rtt; void *next; } *tcpconn_head; struct tcpconn_t *tcpconn_tail; void *next; } *tcpinfo_head; struct tcptable_t *tcpinfo_tail; void *next; } *

variable_types: struct tcptable_t { struct in_addr { unsigned int s_addr; } other_addr; unsigned short service_port; unsigned char initiator; unsigned int incoming_count; unsigned int incoming_byte; struct latency_t { struct timeval { long tv_sec; long tv_usec; } last_time; unsigned short num; float curr; float high; float low; float avg; } incoming_latency; struct bandwidth_t { unsigned int old_count_frame; unsigned int old_byte_tot; unsigned int tot_byte; unsigned short num; struct timeval old_time; float curr; float high; float low; float avg; } incoming_rate; unsigned int outgoing_count; unsigned int outgoing_byte; struct latency_t outgoing_latency; struct bandwidth_t outgoing_rate; unsigned int total_count; unsigned int total_byte; unsigned short retransmit_count; unsigned int retransmit_byte; unsigned short reset_count; float avg_rtt_latency; struct bandwidth_t total_rate; unsigned short closed_connections; unsigned short num_connected; struct tcpconn_t { unsigned short unique_port; unsigned char initiator; unsigned char conn_status; unsigned short inc_window; unsigned short inc_old_window; unsigned int incoming_count; unsigned int incoming_byte; unsigned int last_incoming_seq_num; unsigned int curr_incoming_seq_num; unsigned int acked_incoming_seq_num; unsigned int ack_outgoing_seq_num; unsigned char incoming_dup_ack; struct latency_t incoming_latency; unsigned short out_window; unsigned short out_old_window; unsigned int outgoing_count; unsigned int outgoing_byte; unsigned int last_outgoing_seq_num; unsigned int curr_outgoing_seq_num; unsigned int acked_outgoing_seq_num; unsigned int tracked_seq_num; unsigned char outgoing_dup_ack; struct latency_t outgoing_latency; unsigned int total_count; unsigned int total_byte; unsigned short retransmit_count; unsigned int retransmit_byte; unsigned char tracking_rtt; struct latency_t total_rtt; void *next; } *tcpconn_head; struct tcpconn_t *tcpconn_tail; void *next; } *

variable_types: struct tcpconn_t { unsigned short unique_port; unsigned char initiator; unsigned char conn_status; unsigned short inc_window; unsigned short inc_old_window; unsigned int incoming_count; unsigned int incoming_byte; unsigned int last_incoming_seq_num; unsigned int curr_incoming_seq_num; unsigned int acked_incoming_seq_num; unsigned int ack_outgoing_seq_num; unsigned char incoming_dup_ack; struct latency_t { struct timeval { long tv_sec; long tv_usec; } last_time; unsigned short num; float curr; float high; float low; float avg; } incoming_latency; unsigned short out_window; unsigned short out_old_window; unsigned int outgoing_count; unsigned int outgoing_byte; unsigned int last_outgoing_seq_num; unsigned int curr_outgoing_seq_num; unsigned int acked_outgoing_seq_num; unsigned int tracked_seq_num; unsigned char outgoing_dup_ack; struct latency_t outgoing_latency; unsigned int total_count; unsigned int total_byte; unsigned short retransmit_count; unsigned int retransmit_byte; unsigned char tracking_rtt; struct latency_t total_rtt; void *next; } *

user_defined_types: struct potential_node_t { struct pnode_t nodes[100]; unsigned char num; }

user_defined_types: struct potential_ap_t { struct access_point ap_list[100]; unsigned char num; }

user_defined_types: struct channel_overview { unsigned int num_det_aps; unsigned int num_active_aps; struct access_point *all_chan[15]; }

user_defined_types: struct detailed_overview_t { struct in_addr sniffer_ip; struct in_addr poller_ip; unsigned short bad_mac; unsigned int bad_mac_byte; unsigned short bad_ip_chksum; unsigned int bad_ip_chksum_byte; unsigned short fcs_error; unsigned int fcs_error_byte; unsigned short filtered_data; unsigned int filtered_data_byte; unsigned short corrupt_tot; unsigned int corrupt_tot_byte; unsigned char tot_num_ap; unsigned short tot_num_nodes; struct bss_t *bss_list_top; }

user_defined_types: struct bss_t { unsigned char bssid[6]; unsigned char ssid[32]; unsigned char channel; unsigned char available_band; unsigned char wep_status; unsigned int overall_count; unsigned int overall_byte; float link_utilization; float background_noise; float packet_loss; struct mgmt_t mgmt_data; struct control_t ctrl_data; struct data_t normal_data; struct netproto_t network_data; struct transproto_t transport_data; struct bandwidth_t bndwth; unsigned char num; struct bss_node_t *addr_list_head; struct bss_node_t *addr_list_tail; void *next; }

user_defined_types: struct bss_node_t { struct in_addr ip_addr; unsigned char mac_addr[6]; unsigned int inc_packet; unsigned int inc_byte; unsigned int out_packet; unsigned int out_byte; unsigned int tot_packet; struct bandwidth_t bndwth; unsigned char status; unsigned int tot_signal_str; float avg_signal_str; unsigned int tcp_total_count; unsigned int tcp_total_byte; unsigned short tcp_retransmit_count; unsigned int tcp_retransmit_byte; unsigned short tcp_existing_count; unsigned int tcp_existing_byte; unsigned short tcp_connections; struct tcptable_t *tcpinfo_head; struct tcptable_t *tcpinfo_tail; void *next; }

user_defined_types: struct tcptable_t { struct in_addr other_addr; unsigned short service_port; unsigned char initiator; unsigned int incoming_count; unsigned int incoming_byte; struct latency_t incoming_latency; struct bandwidth_t incoming_rate; unsigned int outgoing_count; unsigned int outgoing_byte; struct latency_t outgoing_latency; struct bandwidth_t outgoing_rate; unsigned int total_count; unsigned int total_byte; unsigned short retransmit_count; unsigned int retransmit_byte; unsigned short reset_count; float avg_rtt_latency; struct bandwidth_t total_rate; unsigned short closed_connections; unsigned short num_connected; struct tcpconn_t *tcpconn_head; struct tcpconn_t *tcpconn_tail; void *next; }

user_defined_types: struct mgmt_t { unsigned int mgmt_count; unsigned int mgmt_byte; unsigned short beacon; unsigned short disassoc; unsigned short other; struct bandwidth_t bndwth; }

user_defined_types: struct netproto_t { struct proto_info_t ip; struct proto_info_t ipv6; struct proto_info_t other; }

user_defined_types: struct access_point { unsigned char channel; unsigned char bssid[6]; unsigned char ssid[32]; unsigned char available_band; unsigned char wep_status; unsigned char traffic_type; unsigned short mgmt_count; unsigned short ctrl_count; unsigned short data_count; unsigned int packet_count; unsigned short encrypt_count; struct timeval timestamp; unsigned char status; float signal_str; void *next; }


segvhandler

decompiled_code:
void __noreturn segvhandler()
{
unsigned int v0; // eax

dump_trace();
fwrite("Fatal: memory allocation error\n\n", 1uLL, 0x20uLL, stderr);
fwrite("If you suspect a bug, please report the exact circumstances under which this\n", 1uLL, 0x4DuLL, stderr);
fwrite("error was generated. If possible, include gdb or strace data which may point\n", 1uLL, 0x4EuLL, stderr);
fwrite("out where the error occured. Bug reports may be sent in to saint@elixar.net.\n\n", 1uLL, 0x4FuLL, stderr);
v0 = getpid();
fprintf(stderr, "AirTraf process %u aborting on signal 11.\n\n", v0);
exit(2);
}

canonical_decompiled_code:
void __noreturn func4()
{
unsigned int v0; // eax

func3();
fwrite("Fatal: memory allocation error\n\n", 1uLL, 0x20uLL, stderr);
fwrite("If you suspect a bug, please report the exact circumstances under which this\n", 1uLL, 0x4DuLL, stderr);
fwrite("error was generated. If possible, include gdb or strace data which may point\n", 1uLL, 0x4EuLL, stderr);
fwrite("out where the error occured. Bug reports may be sent in to saint@elixar.net.\n\n", 1uLL, 0x4FuLL, stderr);
v0 = getpid();
fprintf(stderr, "AirTraf process %u aborting on signal 11.\n\n", v0);
exit(2);
}

original_code:
void segvhandler()
{
  dump_trace();
  fprintf(stderr, "Fatal: memory allocation error\n\n");
  fprintf(stderr, "If you suspect a bug, please report the exact circumstances under which this\n");
  fprintf(stderr, "error was generated.  If possible, include gdb or strace data which may point\n");
  fprintf(stderr, "out where the error occured.  Bug reports may be sent in to saint@elixar.net.\n\n");
  fprintf(stderr, "AirTraf process %u aborting on signal 11.\n\n", getpid());
  exit(2);
}


decompiled_code:
void stop_signal()
{
if ( !sysexit )
{
sysexit = 1;
ask_stop_sniffer_engine();
}
}

canonical_decompiled_code:
void func2()
{
if ( !sysexit )
{
sysexit = 1;
ask_stop_sniffer_engine();
}
}

original_code:
void stop_signal ()
{
  if (!sysexit){
    sysexit = 1;
    ask_stop_sniffer_engine();
  }
}

canonical_original_code:
void stop_signal()
{
  if (!sysexit){
    sysexit = 1;
    ask_stop_sniffer_engine();
  }
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
int v4; // er12
unsigned int v5; // er14
int v6; // eax
char *v7; // r15
char *v8; // r12
char *v9; // r15
char *v10; // rbp
const char *v12; // [rsp+8h] [rbp-1B0h]
int v13; // [rsp+18h] [rbp-1A0h] BYREF
int longind; // [rsp+1Ch] [rbp-19Ch] BYREF
char dest[112]; // [rsp+20h] [rbp-198h] BYREF
char v16[16]; // [rsp+90h] [rbp-128h] BYREF
char v17[80]; // [rsp+A0h] [rbp-118h] BYREF
int v18; // [rsp+F0h] [rbp-C8h]
char v19[184]; // [rsp+100h] [rbp-B8h] BYREF

v3 = *argv;
myset_ptr = (__int64)&mySettings_0;
v13 = 0;
v12 = v3;
qword_810 = 0x100000001LL;
memset(v17, 0, sizeof(v17));
longind = 0;
mySettings_0 = 0;
qword_808 = 0LL;
qword_818 = (__int64)"log.connection";
qword_820 = 0LL;
dword_828 = 0;
v18 = 0;
qword_840 = (__int64)v16;
qword_838 = 1LL;
dword_848 = 0;
qword_850 = 0LL;
qword_858 = 1065353216LL;
dword_860 = 0;
dword_868 = 0;
*(__m128i *)v16 = _mm_load_si128((const __m128i *)&LC65);
if ( !getenv("TERM") )
{
fwrite("Your TERM variable is not set.\n", 1uLL, 0x1FuLL, stderr);
fwrite("Please set it to an appropriate value.\n", 1uLL, 0x27uLL, stderr);
exit(1);
}
v4 = 0;
v5 = 0;
init_autoconfig(v19, &v13);
while ( 2 )
{
v6 = getopt_long(argc, (char *const *)argv, "C:I:DSA::L::hlfzx", &long_options, &longind);
if ( v6 != -1 )
{
switch ( v6 )
{
case '?':
fwrite("\nInvalid option or missing parameter, use airtraf -h for help\n\n", 1uLL, 0x3FuLL, stderr);
exit(1);
case 'A':
v9 = optarg;
HIDWORD(qword_838) = 1;
if ( optarg )
{
strncpy(v16, optarg, 0x63uLL);
HIBYTE(v18) = 0;
qword_840 = (__int64)v16;
if ( *v9 )
{
do
{
optarg = v9 + 1;
*v9 = 32;
v9 = optarg;
}
while ( *optarg );
}
}
continue;
case 'C':
fwrite(
"-C (cardtype) is now deprecated by default autoconfig feature (use only if you desire manual override)\n",
1uLL,
0x67uLL,
stderr);
v8 = optarg;
if ( !strcasecmp("prism2", optarg) )
{
mySettings_0 = 2;
v4 = 1;
}
else if ( !strcasecmp("aironet", v8) )
{
mySettings_0 = 1;
v4 = 1;
}
else if ( !strcasecmp("hermes", v8) )
{
mySettings_0 = 4;
v4 = 1;
}
else if ( !strcasecmp("hostap", v8) )
{
mySettings_0 = 3;
v4 = 1;
}
else
{
if ( strcasecmp("wlanng", v8) )
{
fwrite(
"Invalid card type chosen! Valid types: 'prism2' or 'aironet' (default)\n\n",
1uLL,
0x49uLL,
stderr);
exit(1);
}
mySettings_0 = 5;
v4 = 1;
}
continue;
case 'D':
puts("set to daemonized mode...");
LODWORD(qword_810) = 0;
continue;
case 'I':
v4 = 1;
fwrite(
"-I (interface) is now deprecated by default autoconfig feature (use only if you desire manual override)\n",
1uLL,
0x68uLL,
stderr);
qword_808 = (__int64)optarg;
continue;
case 'L':
v7 = optarg;
LODWORD(qword_820) = 1;
if ( optarg )
{
strncpy(dest, optarg, 0x63uLL);
dest[99] = 0;
qword_818 = (__int64)dest;
if ( *v7 )
{
do
{
optarg = v7 + 1;
*v7 = 32;
v7 = optarg;
}
while ( *optarg );
}
}
continue;
case 'S':
HIDWORD(qword_810) = 2;
continue;
case 'f':
v5 = 1;
continue;
case 'h':
goto LABEL_45;
case 'l':
print_autoconfig(v19, &v13);
exit(1);
case 'x':
HIDWORD(qword_820) = 1;
continue;
default:
continue;
}
}
break;
}
fwrite("-----------------------------------------\n", 1uLL, 0x2AuLL, stderr);
fprintf(stderr, "Airtraf %s %c 2001,2002 Elixar, Inc.\n", "1.1", 169LL);
fwrite("Mode: sniffing server\n", 1uLL, 0x16uLL, stderr);
fwrite("Author: Peter K. Lee All Rights Reserved\n", 1uLL, 0x2AuLL, stderr);
fwrite("-----------------------------------------\n", 1uLL, 0x2AuLL, stderr);
if ( !v4 )
{
print_autoconfig(v19, &v13);
if ( v13 == 1 )
{
v10 = v19;
}
else
{
if ( v13 <= 1 )
goto LABEL_48;
v10 = (char *)prompt_device(v19, &v13);
}
if ( (unsigned int)enable_monitor(v10, v5) )
{
qword_808 = (__int64)v10;
switch ( *((_WORD *)v10 + 54) )
{
case 0:
case 1:
mySettings_0 = 1;
goto LABEL_27;
case 2:
mySettings_0 = 5;
goto LABEL_27;
case 3:
mySettings_0 = 2;
goto LABEL_27;
case 4:
case 5:
mySettings_0 = 3;
goto LABEL_27;
case 6:
case 7:
mySettings_0 = 4;
goto LABEL_27;
default:
fwrite("Unknown card type? Why are we here? PANIC!\n", 1uLL, 0x2DuLL, stderr);
break;
}
}
LABEL_48:
exit(1);
}
if ( !mySettings_0 )
{
fwrite("\nYou need to specify card type, see below:\n\n", 1uLL, 0x2CuLL, stderr);
LABEL_45:
usage(v12);
}
v10 = 0LL;
if ( !qword_808 )
{
fwrite("\nYou need to specify which interface to listen on, see below:\n\n", 1uLL, 0x3FuLL, stderr);
usage(v12);
}
LABEL_27:
signal(11, (__sighandler_t)segvhandler);
signal(15, (__sighandler_t)term_signal_handler);
signal(1, (__sighandler_t)term_signal_handler);
signal(2, (__sighandler_t)stop_signal);
airtraf_init(&mySettings_0);
airtraf_start(&mySettings_0);
disable_monitor(v10);
airtraf_end(&mySettings_0);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
int v4; // er12
unsigned int v5; // er14
int v6; // eax
char *v7; // r15
char *v8; // r12
char *v9; // r15
char *v10; // rbp
const char *v12; // [rsp+8h] [rbp-1B0h]
int v13; // [rsp+18h] [rbp-1A0h] BYREF
int longind; // [rsp+1Ch] [rbp-19Ch] BYREF
char dest[112]; // [rsp+20h] [rbp-198h] BYREF
char v16[16]; // [rsp+90h] [rbp-128h] BYREF
char v17[80]; // [rsp+A0h] [rbp-118h] BYREF
int v18; // [rsp+F0h] [rbp-C8h]
char v19[184]; // [rsp+100h] [rbp-B8h] BYREF

v3 = *argv;
myset_ptr = (__int64)&mySettings_0;
v13 = 0;
v12 = v3;
qword_810 = 0x100000001LL;
memset(v17, 0, sizeof(v17));
longind = 0;
mySettings_0 = 0;
qword_808 = 0LL;
qword_818 = (__int64)"log.connection";
qword_820 = 0LL;
dword_828 = 0;
v18 = 0;
qword_840 = (__int64)v16;
qword_838 = 1LL;
dword_848 = 0;
qword_850 = 0LL;
qword_858 = 1065353216LL;
dword_860 = 0;
dword_868 = 0;
*(__m128i *)v16 = _mm_load_si128((const __m128i *)&LC65);
if ( !getenv("TERM") )
{
fwrite("Your TERM variable is not set.\n", 1uLL, 0x1FuLL, stderr);
fwrite("Please set it to an appropriate value.\n", 1uLL, 0x27uLL, stderr);
exit(1);
}
v4 = 0;
v5 = 0;
init_autoconfig(v19, &v13);
while ( 2 )
{
v6 = getopt_long(argc, (char *const *)argv, "C:I:DSA::L::hlfzx", &long_options, &longind);
if ( v6 != -1 )
{
switch ( v6 )
{
case '?':
fwrite("\nInvalid option or missing parameter, use airtraf -h for help\n\n", 1uLL, 0x3FuLL, stderr);
exit(1);
case 'A':
v9 = optarg;
HIDWORD(qword_838) = 1;
if ( optarg )
{
strncpy(v16, optarg, 0x63uLL);
HIBYTE(v18) = 0;
qword_840 = (__int64)v16;
if ( *v9 )
{
do
{
optarg = v9 + 1;
*v9 = 32;
v9 = optarg;
}
while ( *optarg );
}
}
continue;
case 'C':
fwrite(
"-C (cardtype) is now deprecated by default autoconfig feature (use only if you desire manual override)\n",
1uLL,
0x67uLL,
stderr);
v8 = optarg;
if ( !strcasecmp("prism2", optarg) )
{
mySettings_0 = 2;
v4 = 1;
}
else if ( !strcasecmp("aironet", v8) )
{
mySettings_0 = 1;
v4 = 1;
}
else if ( !strcasecmp("hermes", v8) )
{
mySettings_0 = 4;
v4 = 1;
}
else if ( !strcasecmp("hostap", v8) )
{
mySettings_0 = 3;
v4 = 1;
}
else
{
if ( strcasecmp("wlanng", v8) )
{
fwrite(
"Invalid card type chosen! Valid types: 'prism2' or 'aironet' (default)\n\n",
1uLL,
0x49uLL,
stderr);
exit(1);
}
mySettings_0 = 5;
v4 = 1;
}
continue;
case 'D':
puts("set to daemonized mode...");
LODWORD(qword_810) = 0;
continue;
case 'I':
v4 = 1;
fwrite(
"-I (interface) is now deprecated by default autoconfig feature (use only if you desire manual override)\n",
1uLL,
0x68uLL,
stderr);
qword_808 = (__int64)optarg;
continue;
case 'L':
v7 = optarg;
LODWORD(qword_820) = 1;
if ( optarg )
{
strncpy(dest, optarg, 0x63uLL);
dest[99] = 0;
qword_818 = (__int64)dest;
if ( *v7 )
{
do
{
optarg = v7 + 1;
*v7 = 32;
v7 = optarg;
}
while ( *optarg );
}
}
continue;
case 'S':
HIDWORD(qword_810) = 2;
continue;
case 'f':
v5 = 1;
continue;
case 'h':
goto LABEL_45;
case 'l':
print_autoconfig(v19, &v13);
exit(1);
case 'x':
HIDWORD(qword_820) = 1;
continue;
default:
continue;
}
}
break;
}
fwrite("-----------------------------------------\n", 1uLL, 0x2AuLL, stderr);
fprintf(stderr, "Airtraf %s %c 2001,2002 Elixar, Inc.\n", "1.1", 169LL);
fwrite("Mode: sniffing server\n", 1uLL, 0x16uLL, stderr);
fwrite("Author: Peter K. Lee All Rights Reserved\n", 1uLL, 0x2AuLL, stderr);
fwrite("-----------------------------------------\n", 1uLL, 0x2AuLL, stderr);
if ( !v4 )
{
print_autoconfig(v19, &v13);
if ( v13 == 1 )
{
v10 = v19;
}
else
{
if ( v13 <= 1 )
goto LABEL_48;
v10 = (char *)prompt_device(v19, &v13);
}
if ( (unsigned int)enable_monitor(v10, v5) )
{
qword_808 = (__int64)v10;
switch ( *((_WORD *)v10 + 54) )
{
case 0:
case 1:
mySettings_0 = 1;
goto LABEL_27;
case 2:
mySettings_0 = 5;
goto LABEL_27;
case 3:
mySettings_0 = 2;
goto LABEL_27;
case 4:
case 5:
mySettings_0 = 3;
goto LABEL_27;
case 6:
case 7:
mySettings_0 = 4;
goto LABEL_27;
default:
fwrite("Unknown card type? Why are we here? PANIC!\n", 1uLL, 0x2DuLL, stderr);
break;
}
}
LABEL_48:
exit(1);
}
if ( !mySettings_0 )
{
fwrite("\nYou need to specify card type, see below:\n\n", 1uLL, 0x2CuLL, stderr);
LABEL_45:
func1(v12);
}
v10 = 0LL;
if ( !qword_808 )
{
fwrite("\nYou need to specify which interface to listen on, see below:\n\n", 1uLL, 0x3FuLL, stderr);
func1(v12);
}
LABEL_27:
signal(11, (__sighandler_t)segvhandler);
signal(15, (__sighandler_t)term_signal_handler);
signal(1, (__sighandler_t)term_signal_handler);
signal(2, (__sighandler_t)stop_signal);
airtraf_init(&mySettings_0);
airtraf_start(&mySettings_0);
disable_monitor(v10);
airtraf_end(&mySettings_0);
return 0;
}

original_code:
int main(int argc, char **argv)
{
  int num_dev = 0;
  int force = 0, override = 0;
  wireless_devices iwlist;
  wireless_devices *select = ((void *)0);
  void *blah = compat_drivers;
  static struct SETTINGS mySettings;
  char *pname = argv[0];
  char lognamebuf[100];
  char capturebuf[100];
  int c, option_index = 0;
  myset_ptr = &mySettings;
  blah = blah;
  mySettings.card_type = 0;
  mySettings.interface = ((void *)0);
  mySettings.runtime_mode = 1;
  mySettings.conn_mode = 1;
  mySettings.logfile = "log.connection";
  mySettings.logging_mode = 0;
  mySettings.signal_support = 0;
  mySettings.sniff_socket = 0;
  bzero(capturebuf, sizeof(capturebuf));
  mySettings.capture_file = capturebuf;
  strcpy(mySettings.capture_file, "airtraf.capture");
  mySettings.capture_version = 1;
  mySettings.capture_mode = 0;
  mySettings.capture_size = 0;
  mySettings.capture_timestamp = ((void *)0);
  mySettings.capture_duration = 0;
  mySettings.capture_interval = 1;
  mySettings.capture_overwrite = 0;
  mySettings.capture_status = 0;
  if (getenv("TERM") == ((void *)0)) {
    fprintf(stderr, "Your TERM variable is not set.\n");
    fprintf(stderr, "Please set it to an appropriate value.\n");
    exit(1);
  }
  init_autoconfig(&iwlist, &num_dev);
  while ((c = getopt_long (argc, argv, "C:I:DSA::L::hlfzx", long_options,
      &option_index)) != (-1))
    {
      switch(c)
 {
 case 'l':
   print_autoconfig(&iwlist, &num_dev);
   exit(1);
   break;
 case 'f':
   force = 1;
   break;
 case 'C':
   fprintf(stderr,"-C (cardtype) is now deprecated by default autoconfig feature (use only if you desire manual override)\n");
   override = 1;
   if(!strcasecmp("prism2", optarg)) {
     mySettings.card_type = 2;
   } else if(!strcasecmp("aironet", optarg)) {
     mySettings.card_type = 1;
   } else if(!strcasecmp("hermes", optarg)) {
     mySettings.card_type = 4;
   } else if(!strcasecmp("hostap", optarg)) {
     mySettings.card_type = 3;
   } else if(!strcasecmp("wlanng", optarg)) {
     mySettings.card_type = 5;
   } else {
     fprintf(stderr,"Invalid card type chosen!  Valid types: 'prism2' or 'aironet' (default)\n\n");
     exit(1);
   }
   break;
 case 'I':
   fprintf(stderr,"-I (interface) is now deprecated by default autoconfig feature (use only if you desire manual override)\n");
   override = 1;
   mySettings.interface = optarg;
   break;
 case 'D':
   printf("set to daemonized mode...\n");
   mySettings.runtime_mode = 0;
   break;
 case 'S':
   mySettings.conn_mode = 2;
   break;
 case 'A':
   mySettings.capture_mode = 1;
   if (optarg){
     strncpy(capturebuf, optarg, sizeof(capturebuf) -1);
     capturebuf[sizeof(capturebuf)-1] = '\0';
     mySettings.capture_file = capturebuf;
     while (*optarg){
       *optarg++ = ' ';
     }
   }
   break;
 case 'L':
   mySettings.logging_mode = 1;
   if (optarg){
     strncpy(lognamebuf, optarg, sizeof(lognamebuf) -1);
     lognamebuf[sizeof(lognamebuf)-1] = '\0';
     mySettings.logfile = lognamebuf;
     while (*optarg){
       *optarg++ = ' ';
     }
   }
   break;
 case 'x':
   mySettings.signal_support = 1;
   break;
 case 'h':
   usage(pname);
   break;
 case 'z':
   break;
 case '?':
   fprintf(stderr,"\nInvalid option or missing parameter, use airtraf -h for help\n\n");
   exit(1);
 }
    }
  fprintf(stderr,"-----------------------------------------\n");
  fprintf(stderr,"Airtraf %s %c 2001,2002 Elixar, Inc.\n", "1.1",(int)169);
  fprintf(stderr,"Mode: sniffing server\n");
  fprintf(stderr,"Author: Peter K. Lee  All Rights Reserved\n");
  fprintf(stderr,"-----------------------------------------\n");
  if (override){
    if (mySettings.card_type == 0){
      fprintf(stderr,"\nYou need to specify card type, see below:\n\n");
      usage(pname);
    }
    if (mySettings.interface == ((void *)0)){
      fprintf(stderr,"\nYou need to specify which interface to listen on, see below:\n\n");
      usage(pname);
    }
  }
  else{
    print_autoconfig(&iwlist, &num_dev);
    if (num_dev == 1)
      select = &iwlist;
    else if (num_dev > 1)
      select = prompt_device(&iwlist, &num_dev);
    else
      exit(1);
    if (!enable_monitor(select, force)) exit(1);
    mySettings.interface = select->ifname;
    switch(select->compat_id){
    case 0:
    case 1:
      mySettings.card_type = 1;
      break;
    case 2:
      mySettings.card_type = 5;
      break;
    case 3:
      mySettings.card_type = 2;
      break;
    case 4:
    case 5:
      mySettings.card_type = 3;
      break;
    case 6:
    case 7:
      mySettings.card_type = 4;
      break;
    default:
      fprintf(stderr,"Unknown card type?  Why are we here?  PANIC!\n");
      exit(1);
      break;
    }
  }
  signal(11, (void *) segvhandler);
  signal(15, (void *) term_signal_handler);
  signal(1, (void *) term_signal_handler);
  signal (2, (void *) stop_signal);
  airtraf_init(&mySettings);
  airtraf_start(&mySettings);
  disable_monitor(select);
  airtraf_end(&mySettings);
  return(0);
}

canonical_original_code:
int main(int argc, char **argv)
{
  int num_dev = 0;
  int force = 0; int override = 0;
  struct wireless_devices iwlist;
  struct wireless_devices *select = ((void *)0);
  void *blah = compat_drivers;
  static struct SETTINGS mySettings;
  char *pname = argv[0];
  char lognamebuf[100];
  char capturebuf[100];
  int c; int option_index = 0;
  myset_ptr = &mySettings;
  blah = blah;
  mySettings.card_type = 0;
  mySettings.interface = ((void *)0);
  mySettings.runtime_mode = 1;
  mySettings.conn_mode = 1;
  mySettings.logfile = "log.connection";
  mySettings.logging_mode = 0;
  mySettings.signal_support = 0;
  mySettings.sniff_socket = 0;
  bzero(capturebuf, sizeof(capturebuf));
  mySettings.capture_file = capturebuf;
  strcpy(mySettings.capture_file, "airtraf.capture");
  mySettings.capture_version = 1;
  mySettings.capture_mode = 0;
  mySettings.capture_size = 0;
  mySettings.capture_timestamp = ((void *)0);
  mySettings.capture_duration = 0;
  mySettings.capture_interval = 1;
  mySettings.capture_overwrite = 0;
  mySettings.capture_status = 0;
  if (getenv("TERM") == ((void *)0)) {
    fprintf(stderr, "Your TERM variable is not set.\n");
    fprintf(stderr, "Please set it to an appropriate value.\n");
    exit(1);
  }
  init_autoconfig(&iwlist, &num_dev);
  while ((c = getopt_long (argc, argv, "C:I:DSA::L::hlfzx", long_options,
      &option_index)) != (-1))
    {
      switch(c)
 {
 case 'l':
   print_autoconfig(&iwlist, &num_dev);
   exit(1);
   break;
 case 'f':
   force = 1;
   break;
 case 'C':
   fprintf(stderr,"-C (cardtype) is now deprecated by default autoconfig feature (use only if you desire manual override)\n");
   override = 1;
   if(!strcasecmp("prism2", optarg)) {
     mySettings.card_type = 2;
   } else if(!strcasecmp("aironet", optarg)) {
     mySettings.card_type = 1;
   } else if(!strcasecmp("hermes", optarg)) {
     mySettings.card_type = 4;
   } else if(!strcasecmp("hostap", optarg)) {
     mySettings.card_type = 3;
   } else if(!strcasecmp("wlanng", optarg)) {
     mySettings.card_type = 5;
   } else {
     fprintf(stderr,"Invalid card type chosen!  Valid types: 'prism2' or 'aironet' (default)\n\n");
     exit(1);
   }
   break;
 case 'I':
   fprintf(stderr,"-I (interface) is now deprecated by default autoconfig feature (use only if you desire manual override)\n");
   override = 1;
   mySettings.interface = optarg;
   break;
 case 'D':
   printf("set to daemonized mode...\n");
   mySettings.runtime_mode = 0;
   break;
 case 'S':
   mySettings.conn_mode = 2;
   break;
 case 'A':
   mySettings.capture_mode = 1;
   if (optarg){
     strncpy(capturebuf, optarg, sizeof(capturebuf) -1);
     capturebuf[sizeof(capturebuf)-1] = '\0';
     mySettings.capture_file = capturebuf;
     while (*optarg){
       *optarg++ = ' ';
     }
   }
   break;
 case 'L':
   mySettings.logging_mode = 1;
   if (optarg){
     strncpy(lognamebuf, optarg, sizeof(lognamebuf) -1);
     lognamebuf[sizeof(lognamebuf)-1] = '\0';
     mySettings.logfile = lognamebuf;
     while (*optarg){
       *optarg++ = ' ';
     }
   }
   break;
 case 'x':
   mySettings.signal_support = 1;
   break;
 case 'h':
   usage(pname);
   break;
 case 'z':
   break;
 case '?':
   fprintf(stderr,"\nInvalid option or missing parameter, use airtraf -h for help\n\n");
   exit(1);
 }
    }
  fprintf(stderr,"-----------------------------------------\n");
  fprintf(stderr,"Airtraf %s %c 2001,2002 Elixar, Inc.\n", "1.1",(int)169);
  fprintf(stderr,"Mode: sniffing server\n");
  fprintf(stderr,"Author: Peter K. Lee  All Rights Reserved\n");
  fprintf(stderr,"-----------------------------------------\n");
  if (override){
    if (mySettings.card_type == 0){
      fprintf(stderr,"\nYou need to specify card type, see below:\n\n");
      usage(pname);
    }
    if (mySettings.interface == ((void *)0)){
      fprintf(stderr,"\nYou need to specify which interface to listen on, see below:\n\n");
      usage(pname);
    }
  }
  else{
    print_autoconfig(&iwlist, &num_dev);
    if (num_dev == 1)
      select = &iwlist;
    else if (num_dev > 1)
      select = prompt_device(&iwlist, &num_dev);
    else
      exit(1);
    if (!enable_monitor(select, force)) exit(1);
    mySettings.interface = select->ifname;
    switch(select->compat_id){
    case 0:
    case 1:
      mySettings.card_type = 1;
      break;
    case 2:
      mySettings.card_type = 5;
      break;
    case 3:
      mySettings.card_type = 2;
      break;
    case 4:
    case 5:
      mySettings.card_type = 3;
      break;
    case 6:
    case 7:
      mySettings.card_type = 4;
      break;
    default:
      fprintf(stderr,"Unknown card type?  Why are we here?  PANIC!\n");
      exit(1);
      break;
    }
  }
  signal(11, (void *) segvhandler);
  signal(15, (void *) term_signal_handler);
  signal(1, (void *) term_signal_handler);
  signal (2, (void *) stop_signal);
  airtraf_init(&mySettings);
  airtraf_start(&mySettings);
  disable_monitor(select);
  airtraf_end(&mySettings);
  return(0);
}

variable_types: argc int

variable_types:
argv
char **

variable_types: force int

variable_types: override int

variable_types: struct wireless_devices { char ifname[-1]; char real_ifname[-1]; char iwname[-1]; char drvname[-1]; char version[-1]; unsigned short base_addr; unsigned char irq; short flags; short compat_id; void *next; } *

variable_types:
blah
void *

variable_types: struct SETTINGS { int card_type; char *interface; int runtime_mode; int conn_mode; char *logfile; int logging_mode; int signal_support; int sniff_socket; int scan_mode; void *chosen_ap; int capture_version; int capture_mode; char *capture_file; unsigned int capture_size; unsigned int capture_seq; long *capture_timestamp; float capture_interval; float capture_duration; int capture_overwrite; int capture_command; int capture_status; }

variable_types:
lognamebuf
char [100]

variable_types:
capturebuf
char [100]

variable_types: c int

return_type: int


decompiled_code:
void __fastcall parse_capture_key(__int64 a1, int a2)
{
switch ( a2 )
{
case 'B':
if ( !(unsigned int)get_capture_status() )
{
*(_DWORD *)(a1 + 100) = 5;
start_capture_engine(a1);
}
break;
case 'F':
if ( !(unsigned int)get_capture_status() )
{
*(_DWORD *)(a1 + 100) = 3;
start_capture_engine(a1);
}
break;
case 'P':
case 'p':
if ( !(unsigned int)get_capture_status() )
{
*(_DWORD *)(a1 + 100) = 1;
start_capture_engine(a1);
}
break;
case 'R':
case 'r':
if ( !(unsigned int)get_capture_status() )
capture_playback_beginning(a1);
break;
case 'S':
case 's':
if ( (unsigned int)get_capture_status() )
{
stop_capture_engine(a1);
*(_DWORD *)(a1 + 100) = 0;
capture_playback_forward(a1);
}
break;
case 'b':
if ( !(unsigned int)get_capture_status() )
{
capture_playback_rewind(a1);
capture_playback_rewind(a1);
goto LABEL_13;
}
break;
case 'f':
if ( !(unsigned int)get_capture_status() )
LABEL_13:
capture_playback_forward(a1);
break;
default:
return;
}
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
switch ( a2 )
{
case 'B':
if ( !(unsigned int)get_capture_status() )
{
*(_DWORD *)(a1 + 100) = 5;
start_capture_engine(a1);
}
break;
case 'F':
if ( !(unsigned int)get_capture_status() )
{
*(_DWORD *)(a1 + 100) = 3;
start_capture_engine(a1);
}
break;
case 'P':
case 'p':
if ( !(unsigned int)get_capture_status() )
{
*(_DWORD *)(a1 + 100) = 1;
start_capture_engine(a1);
}
break;
case 'R':
case 'r':
if ( !(unsigned int)get_capture_status() )
capture_playback_beginning(a1);
break;
case 'S':
case 's':
if ( (unsigned int)get_capture_status() )
{
stop_capture_engine(a1);
*(_DWORD *)(a1 + 100) = 0;
capture_playback_forward(a1);
}
break;
case 'b':
if ( !(unsigned int)get_capture_status() )
{
capture_playback_rewind(a1);
capture_playback_rewind(a1);
goto LABEL_13;
}
break;
case 'f':
if ( !(unsigned int)get_capture_status() )
LABEL_13:
capture_playback_forward(a1);
break;
default:
return;
}
}

original_code:
void parse_capture_key(struct SETTINGS *mySettings, int ch)
{
  switch(ch){
  case 'F':
    if (!get_capture_status()){
      mySettings->capture_command = 3;
      start_capture_engine(mySettings);
    }
    break;
  case 'f':
    if (!get_capture_status())
      capture_playback_forward(mySettings);
    break;
  case 'B':
    if (!get_capture_status()){
      mySettings->capture_command = 5;
      start_capture_engine(mySettings);
    }
    break;
  case 'b':
    if (!get_capture_status()){
      capture_playback_rewind(mySettings);
      capture_playback_rewind(mySettings);
      capture_playback_forward(mySettings);
    }
    break;
  case 'R':
  case 'r':
    if (!get_capture_status()){
      capture_playback_beginning(mySettings);
    }
    break;
  case 'S':
  case 's':
    if (get_capture_status()){
      stop_capture_engine(mySettings);
      mySettings->capture_command = 0;
      capture_playback_forward(mySettings);
    }
    break;
  case 'P':
  case 'p':
    if (!get_capture_status()){
      mySettings->capture_command = 1;
      start_capture_engine(mySettings);
    }
    break;
  }
}

variable_types: struct SETTINGS { int card_type; char *interface; int runtime_mode; int conn_mode; char *logfile; int logging_mode; int signal_support; int sniff_socket; int scan_mode; void *chosen_ap; int capture_version; int capture_mode; char *capture_file; unsigned int capture_size; unsigned int capture_seq; long *capture_timestamp; float capture_interval; float capture_duration; int capture_overwrite; int capture_command; int capture_status; } *

variable_types: ch int


decompiled_code:
__int64 __fastcall write_into_log(int a1, const char *a2)
{
int v2; // eax

if ( a1 == 1 )
{
v2 = fprintf(connect_log, a2);
}
else
{
if ( a1 != 2 )
goto LABEL_6;
v2 = fprintf(error_log, a2);
}
if ( v2 >= 0 )
return 1LL;
LABEL_6:
fwrite("Could not write to logfile!\n", (size_t)init_log + 1, 0x1CuLL, error_log);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1, const char *a2)
{
int v2; // eax

if ( a1 == 1 )
{
v2 = fprintf(connect_log, a2);
}
else
{
if ( a1 != 2 )
goto LABEL_6;
v2 = fprintf(error_log, a2);
}
if ( v2 >= 0 )
return 1LL;
LABEL_6:
fwrite("Could not write to logfile!\n", (size_t)init_log + 1, 0x1CuLL, error_log);
return 0xFFFFFFFFLL;
}

original_code:
int write_into_log(int type, char * text)
{
  int status = -1;
  switch (type)
    {
    case 1: status = fprintf(connect_log, text);
      break;
    case 2: status = fprintf(error_log, text);
      break;
    default:
      break;
    }
  if (status < 0){
    fprintf(error_log, "Could not write to logfile!\n");
    return (-1);
  }
  return (1);
}

canonical_original_code:
int write_into_log(int type, char *text)
{
  int status = -1;
  switch (type)
    {
    case 1: status = fprintf(connect_log, text);
      break;
    case 2: status = fprintf(error_log, text);
      break;
    default:
      break;
    }
  if (status < 0){
    fprintf(error_log, "Could not write to logfile!\n");
    return (-1);
  }
  return (1);
}

variable_types: type int

variable_types:
text
char *

variable_types: status int


decompiled_code:
__int64 __fastcall write_log(int a1, __int64 a2)
{
time_t v2; // rax

v2 = time(0LL);
genatime(v2, &atime);
memset(logmsg, 0, sizeof(logmsg));
sprintf(logmsg, "%s] %s", &atime, a2);
return write_into_log(a1, logmsg);
}

canonical_decompiled_code:
__int64 __fastcall func2(int a1, __int64 a2)
{
time_t v2; // rax

v2 = time(0LL);
genatime(v2, &atime);
memset(logmsg, 0, sizeof(logmsg));
sprintf(logmsg, "%s] %s", &atime, a2);
return func1(a1, logmsg);
}

original_code:
int write_log(int type, char * text)
{
  genatime(time((time_t *) ((void *)0)), atime);
  bzero(logmsg,sizeof(logmsg));
  sprintf(logmsg,"%s]   %s",atime,text);
  return write_into_log(type,logmsg);
}

canonical_original_code:
int write_log(int type, char *text)
{
  genatime(time((long *) ((void *)0)), atime);
  bzero(logmsg,sizeof(logmsg));
  sprintf(logmsg,"%s]   %s",atime,text);
  return write_into_log(type,logmsg);
}


decompiled_code:
int __fastcall flush_log(int a1)
{
int result; // eax

if ( a1 == 1 )
return fflush(connect_log);
if ( a1 == 2 )
result = fflush(error_log);
return result;
}

canonical_decompiled_code:
int __fastcall func3(int a1)
{
int result; // eax

if ( a1 == 1 )
return fflush(connect_log);
if ( a1 == 2 )
result = fflush(error_log);
return result;
}

original_code:
void flush_log(int type)
{
  switch (type)
    {
    case 1: fflush(connect_log);
      break;
    case 2: fflush(error_log);
      break;
    default:
      break;
    }
}


decompiled_code:
int __fastcall close_log(int a1)
{
int result; // eax

if ( a1 == 1 )
return fclose(connect_log);
if ( a1 == 2 )
result = fclose(error_log);
return result;
}

canonical_decompiled_code:
int __fastcall func4(int a1)
{
int result; // eax

if ( a1 == 1 )
return fclose(connect_log);
if ( a1 == 2 )
result = fclose(error_log);
return result;
}

original_code:
void close_log(int type)
{
    switch (type)
    {
    case 1: fclose(connect_log);
      break;
    case 2: fclose(error_log);
      break;
    default:
      break;
    }
}


decompiled_code:
void *initialize_channel_scan()
{
void *result; // rax

overview = calloc(0x80uLL, 1uLL);
if ( !overview || (result = calloc(0x2268uLL, 1uLL), (ap_filter = result) == 0LL) )
{
perror("malloc");
exit(-1);
}
return result;
}

canonical_decompiled_code:
void *func0()
{
void *result; // rax

overview = calloc(0x80uLL, 1uLL);
if ( !overview || (result = calloc(0x2268uLL, 1uLL), (ap_filter = result) == 0LL) )
{
perror("malloc");
exit(-1);
}
return result;
}

original_code:
void initialize_channel_scan()
{
  if (((void *)0) == (overview = malloc(sizeof(struct channel_overview)))){
    perror("malloc");
    exit(-1);
  }
  memset(overview,0,sizeof(struct channel_overview));
  if (((void *)0) == (ap_filter = malloc(sizeof(potential_ap_t)))){
    perror("malloc");
    exit(-1);
  }
  memset(ap_filter,0,sizeof(potential_ap_t));
}

user_defined_types: struct timeval { long tv_sec; long tv_usec; }