decompiled_code:
void __fastcall reset_ap_list(void *ptr)
{
if ( ptr )
{
reset_ap_list(*((void **)ptr + 10));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( ptr )
{
func1(*((void **)ptr + 10));
free(ptr);
}
}

original_code:
void reset_ap_list(struct access_point *ap)
{
  struct access_point * temp = ap;
  if (temp != ((void *)0)){
    reset_ap_list((struct access_point *)ap->next);
    free(temp);
    return;
  }
  else{
    return;
  }
}

canonical_original_code:
void reset_ap_list(struct access_point *ap)
{
  struct access_point *temp = ap;
  if (temp != ((void *)0)){
    reset_ap_list((struct access_point *)ap->next);
    free(temp);
    return;
  }
  else{
    return;
  }
}

variable_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 { long tv_sec; long tv_usec; } timestamp; unsigned char status; float signal_str; void *next; } *


repo: saintkepha/airtraf

decompiled_code:
void free_channel_scan()
{
void *v0; // r12
void **v1; // rbp
void **v2; // rbx
void *v3; // rdi

v0 = overview;
v1 = (void **)((char *)overview + 128);
v2 = (void **)((char *)overview + 8);
do
{
v3 = *v2++;
reset_ap_list(v3);
}
while ( v2 != v1 );
free(v0);
free(ap_filter);
overview = 0LL;
ap_filter = 0LL;
}

canonical_decompiled_code:
void func2()
{
void *v0; // r12
void **v1; // rbp
void **v2; // rbx
void *v3; // rdi

v0 = overview;
v1 = (void **)((char *)overview + 128);
v2 = (void **)((char *)overview + 8);
do
{
v3 = *v2++;
func1(v3);
}
while ( v2 != v1 );
free(v0);
free(ap_filter);
overview = 0LL;
ap_filter = 0LL;
}

original_code:
void free_channel_scan()
{
  int i;
  for (i = 0; i < 15; i++){
    reset_ap_list(overview->all_chan[i]);
  }
  free(overview);
  free(ap_filter);
  overview = ((void *)0);
  ap_filter = ((void *)0);
}

variable_types: i int

return_type: void


original_code:
int filter_ap(struct p802_11b_info *info)
{
  int i;
  for (i = 0; i < ap_filter->num; i++){
    if ((0 == memcmp(&ap_filter->ap_list[i].bssid,info->bssid,6))&&
 (0 == memcmp(&ap_filter->ap_list[i].ssid, info->ssid, 32))&&
 (ap_filter->ap_list[i].channel == info->channel)){
      if (ap_filter->ap_list[i].packet_count > 5){
 return (1);
      }
      else{
 ap_filter->ap_list[i].packet_count++;
 return (0);
      }
    }
  }
  if (ap_filter->num < 100){
    memcpy(&ap_filter->ap_list[ap_filter->num].bssid, info->bssid, 6);
    strncpy(ap_filter->ap_list[ap_filter->num].ssid, info->ssid, 32);
    ap_filter->ap_list[ap_filter->num].channel = info->channel;
    ap_filter->ap_list[ap_filter->num].packet_count = 0;
    ap_filter->num++;
  }
  return (0);
}

variable_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]; } *

return_type: int


decompiled_code:
void *clean_filter()
{
return memset(ap_filter, 0, 0x2268uLL);
}

canonical_decompiled_code:
void *func5()
{
return memset(ap_filter, 0, 0x2268uLL);
}

original_code:
void clean_filter()
{
  memset(ap_filter, 0, sizeof(potential_ap_t));
}


original_code:
void update_ap_info(struct p802_11b_info *info, float signal)
{
  __u8 bcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  __u8 null_addr[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  struct access_point *temp;
  struct access_point *last;
  if (0 == memcmp(bcast, info->bssid, 6))
    return;
  if (0 == memcmp (null_addr, info->bssid, 6))
    return;
  if ((info->channel < 1)||(info->channel > 14))
    return;
  if (overview->all_chan[info->channel] == ((void *)0)){
    if (!filter_ap(info))
      return;
    overview->all_chan[info->channel] = new_access_point(info, signal);
    overview->num_det_aps++;
    overview->num_active_aps++;
  }
  else{
    temp = overview->all_chan[info->channel];
    while (temp != ((void *)0)){
      if (0 == memcmp(&temp->bssid, info->bssid, 6)){
 temp->mgmt_count++;
 temp->packet_count++;
 temp->signal_str = signal;
 if (!strncmp(temp->ssid," ",32)&&strncmp(info->ssid," ",32)){
   strncpy(temp->ssid, info->ssid, 32);
 }
 gettimeofday(&temp->timestamp, ((void *)0));
 if (temp->status == 5){
   temp->status = 2;
   overview->num_active_aps++;
 }
 return;
      }
      last = temp;
      temp = (struct access_point*)temp->next;
    }
    if (!filter_ap(info))
      return;
    last->next = new_access_point(info, signal);
    overview->num_det_aps++;
    overview->num_active_aps++;
  }
}

canonical_original_code:
void update_ap_info(struct p802_11b_info *info, float signal)
{
  unsigned char bcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  unsigned char null_addr[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  struct access_point *temp;
  struct access_point *last;
  if (0 == memcmp(bcast, info->bssid, 6))
    return;
  if (0 == memcmp (null_addr, info->bssid, 6))
    return;
  if ((info->channel < 1)||(info->channel > 14))
    return;
  if (overview->all_chan[info->channel] == ((void *)0)){
    if (!filter_ap(info))
      return;
    overview->all_chan[info->channel] = new_access_point(info, signal);
    overview->num_det_aps++;
    overview->num_active_aps++;
  }
  else{
    temp = overview->all_chan[info->channel];
    while (temp != ((void *)0)){
      if (0 == memcmp(&temp->bssid, info->bssid, 6)){
 temp->mgmt_count++;
 temp->packet_count++;
 temp->signal_str = signal;
 if (!strncmp(temp->ssid," ",32)&&strncmp(info->ssid," ",32)){
   strncpy(temp->ssid, info->ssid, 32);
 }
 gettimeofday(&temp->timestamp, ((void *)0));
 if (temp->status == 5){
   temp->status = 2;
   overview->num_active_aps++;
 }
 return;
      }
      last = temp;
      temp = (struct access_point *)temp->next;
    }
    if (!filter_ap(info))
      return;
    last->next = new_access_point(info, signal);
    overview->num_det_aps++;
    overview->num_active_aps++;
  }
}

variable_types: signal float

variable_types:
bcast
unsigned char [6]

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]; }

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; }

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


decompiled_code:
__int64 __fastcall find_access_point(__int64 a1)
{
__int64 *v1; // rcx
__int64 result; // rax

v1 = (__int64 *)((char *)overview + 16);
while ( 1 )
{
result = *v1;
if ( *v1 )
break;
LABEL_8:
if ( ++v1 == (__int64 *)((char *)overview + 128) )
return 0LL;
}
while ( *(_DWORD *)(result + 1) != *(_DWORD *)a1 || *(_WORD *)(result + 5) != *(_WORD *)(a1 + 4) )
{
result = *(_QWORD *)(result + 80);
if ( !result )
goto LABEL_8;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 *v1; // rcx
__int64 result; // rax

v1 = (__int64 *)((char *)overview + 16);
while ( 1 )
{
result = *v1;
if ( *v1 )
break;
LABEL_8:
if ( ++v1 == (__int64 *)((char *)overview + 128) )
return 0LL;
}
while ( *(_DWORD *)(result + 1) != *(_DWORD *)a1 || *(_WORD *)(result + 5) != *(_WORD *)(a1 + 4) )
{
result = *(_QWORD *)(result + 80);
if ( !result )
goto LABEL_8;
}
return result;
}

original_code:
struct access_point *find_access_point(__u8 *bssid)
{
  int i;
  struct access_point *temp;
  for (i = 1; i < 15; i++){
    temp = overview->all_chan[i];
    while (temp != ((void *)0)){
      if (0 == memcmp(&temp->bssid, bssid, 6)){
 return (temp);
      }
      temp = (struct access_point*)temp->next;
    }
  }
  return (((void *)0));
}

canonical_original_code:
struct access_point *find_access_point(unsigned char *bssid)
{
  int i;
  struct access_point *temp;
  for (i = 1; i < 15; i++){
    temp = overview->all_chan[i];
    while (temp != ((void *)0)){
      if (0 == memcmp(&temp->bssid, bssid, 6)){
 return (temp);
      }
      temp = (struct access_point *)temp->next;
    }
  }
  return (((void *)0));
}

variable_types:
bssid
unsigned char *

return_type: 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; } *


original_code:
void check_activity(struct p802_11b_info *info)
{
  __u8 bcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  __u8 null_addr[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  struct access_point *temp;
  if (0 == memcmp(bcast, info->bssid, 6))
    return;
  if (0 == memcmp (null_addr, info->bssid, 6))
    return;
  if ((temp = find_access_point(info->bssid)) != ((void *)0)){
    switch(info->type)
      {
      case 0:
 temp->mgmt_count++;
 break;
      case 1:
 temp->ctrl_count++;
 break;
      case 2:
 temp->data_count++;
 temp->traffic_type = info->datatype;
 temp->wep_status = info->wep;
 break;
      }
    if (info->wep){
      temp->encrypt_count++;
    }
    temp->packet_count++;
    gettimeofday(&temp->timestamp,((void *)0));
    if (temp->status == 5){
      temp->status = 2;
    }
  }
}

canonical_original_code:
void check_activity(struct p802_11b_info *info)
{
  unsigned char bcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
  unsigned char null_addr[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  struct access_point *temp;
  if (0 == memcmp(bcast, info->bssid, 6))
    return;
  if (0 == memcmp (null_addr, info->bssid, 6))
    return;
  if ((temp = find_access_point(info->bssid)) != ((void *)0)){
    switch(info->type)
      {
      case 0:
 temp->mgmt_count++;
 break;
      case 1:
 temp->ctrl_count++;
 break;
      case 2:
 temp->data_count++;
 temp->traffic_type = info->datatype;
 temp->wep_status = info->wep;
 break;
      }
    if (info->wep){
      temp->encrypt_count++;
    }
    temp->packet_count++;
    gettimeofday(&temp->timestamp,((void *)0));
    if (temp->status == 5){
      temp->status = 2;
    }
  }
}


decompiled_code:
void __fastcall update_channel(__int64 a1, float a2)
{
__int64 v2; // rax

if ( *(_BYTE *)(a1 + 32) )
{
update_ap_info(a1, a2);
}
else if ( *(_QWORD *)(a1 + 8) )
{
check_activity(a1);
}
else if ( *(_BYTE *)a1 == 1 )
{
v2 = find_access_point(*(_QWORD *)(a1 + 16));
if ( v2 )
++*(_WORD *)(v2 + 44);
}
}

original_code:
void update_channel(struct p802_11b_info *info, float signal)
{
  struct access_point *temp;
  if (info->channel)
    update_ap_info(info, signal);
  else{
    if (info->bssid != ((void *)0)){
      check_activity(info);
    }
    else if (info->type == 1){
      if ((temp = find_access_point(info->da)) != ((void *)0))
 temp->ctrl_count++;
    }
  }
}


original_code:
void process_channel_scan(struct packet_info *packet)
{
  struct p802_11b_info *info = ((void *)0);
  float signal_str = 0;
  if (packet->error_status)
    return;
  if (packet->driver_proto == 1){
    signal_str = packet->driver_pkt->signal;
  }
  if (packet->mac_proto == 1){
    info = parse_p802_11b_hdr((wlan_hdr_t *)packet->mac_pkt);
  }
  else if (packet->mac_proto == 2){
    signal_str = ((prism2_hdr_t *)packet->mac_pkt)->frame_descriptor.signal;
    info = parse_hfa384x_hdr((prism2_hdr_t *)packet->mac_pkt);
  }
  else if (packet->mac_proto == 3){
    signal_str = ((wlan_ng_hdr_t *)packet->mac_pkt)->signal.data;
    info = parse_wlanngp2_hdr((wlan_ng_hdr_t *)packet->mac_pkt);
  }
  else{
    return;
  }
  if (!info->status){
    return;
  }
  update_channel(info, signal_str);
}

canonical_original_code:
void process_channel_scan(struct packet_info *packet)
{
  struct p802_11b_info *info = ((void *)0);
  float signal_str = 0;
  if (packet->error_status)
    return;
  if (packet->driver_proto == 1){
    signal_str = packet->driver_pkt->signal;
  }
  if (packet->mac_proto == 1){
    info = parse_p802_11b_hdr((struct wlan_hdr_t *)packet->mac_pkt);
  }
  else if (packet->mac_proto == 2){
    signal_str = ((struct prism2_hdr_t *)packet->mac_pkt)->frame_descriptor.signal;
    info = parse_hfa384x_hdr((struct prism2_hdr_t *)packet->mac_pkt);
  }
  else if (packet->mac_proto == 3){
    signal_str = ((struct wlan_ng_hdr_t *)packet->mac_pkt)->signal.data;
    info = parse_wlanngp2_hdr((struct wlan_ng_hdr_t *)packet->mac_pkt);
  }
  else{
    return;
  }
  if (!info->status){
    return;
  }
  update_channel(info, signal_str);
}

variable_types: struct packet_info { unsigned int packet_size; unsigned int net_pkt_size; unsigned char error_status; unsigned char driver_proto; unsigned char mac_proto; unsigned char net_proto; unsigned char trans_proto; unsigned short data_size; struct airids_frame_info { unsigned char card_type; unsigned char fcs_error; unsigned char undecrypt; unsigned char channel; unsigned char signal; unsigned long time; } *driver_pkt; void *mac_pkt; void *net_pkt; void *trans_pkt; void *data; } *

user_defined_types: struct packet_info { unsigned int packet_size; unsigned int net_pkt_size; unsigned char error_status; unsigned char driver_proto; unsigned char mac_proto; unsigned char net_proto; unsigned char trans_proto; unsigned short data_size; struct airids_frame_info *driver_pkt; void *mac_pkt; void *net_pkt; void *trans_pkt; void *data; }

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]; }

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]; }

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; }

user_defined_types: 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; }

user_defined_types: struct p80211item_t { unsigned int did; unsigned short status; unsigned short len; unsigned int data; }


decompiled_code:
void *get_channel_snapshot()
{
return overview;
}

canonical_decompiled_code:
void *func11()
{
return overview;
}

original_code:
struct channel_overview *get_channel_snapshot()
{
  return (overview);
}

return_type: 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]; } *

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


original_code:
void update_all_ap_status()
{
  int i;
  struct timeval now;
  struct access_point *curr_ap = ((void *)0);
  struct access_point *prev_ap = ((void *)0);
  gettimeofday(&now, ((void *)0));
  for (i = 1; i < 15; i++){
    curr_ap = overview->all_chan[i];
    while (curr_ap != ((void *)0)){
      if (get_time_diff(&now, &curr_ap->timestamp) > 60){
 if (curr_ap->status != 5){
   curr_ap->status = 4;
   overview->num_active_aps--;
 }
      }
      if (get_time_diff(&now, &curr_ap->timestamp) > 300){
 if (curr_ap == overview->all_chan[i]){
   overview->all_chan[i] = curr_ap->next;
   free(curr_ap);
   curr_ap = overview->all_chan[i];
   overview->num_det_aps--;
   continue;
 }
 else{
   prev_ap->next = curr_ap->next;
   free(curr_ap);
   curr_ap = prev_ap;
   overview->num_det_aps--;
 }
      }
      prev_ap = curr_ap;
      curr_ap = (struct access_point*)curr_ap->next;
    }
  }
}

canonical_original_code:
void update_all_ap_status()
{
  int i;
  struct timeval now;
  struct access_point *curr_ap = ((void *)0);
  struct access_point *prev_ap = ((void *)0);
  gettimeofday(&now, ((void *)0));
  for (i = 1; i < 15; i++){
    curr_ap = overview->all_chan[i];
    while (curr_ap != ((void *)0)){
      if (get_time_diff(&now, &curr_ap->timestamp) > 60){
 if (curr_ap->status != 5){
   curr_ap->status = 4;
   overview->num_active_aps--;
 }
      }
      if (get_time_diff(&now, &curr_ap->timestamp) > 300){
 if (curr_ap == overview->all_chan[i]){
   overview->all_chan[i] = curr_ap->next;
   free(curr_ap);
   curr_ap = overview->all_chan[i];
   overview->num_det_aps--;
   continue;
 }
 else{
   prev_ap->next = curr_ap->next;
   free(curr_ap);
   curr_ap = prev_ap;
   overview->num_det_aps--;
 }
      }
      prev_ap = curr_ap;
      curr_ap = (struct access_point *)curr_ap->next;
    }
  }
}

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


decompiled_code:
// attributes: thunk
__int64 channel_range()
{
return pkt_card_channel_range();
}

canonical_decompiled_code:
__int64 func13()
{
return pkt_card_channel_range();
}

original_code:
int channel_range(struct SETTINGS*myset)
{
  return pkt_card_channel_range(myset);
}

canonical_original_code:
int channel_range(struct SETTINGS *myset)
{
  return pkt_card_channel_range(myset);
}

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:
// attributes: thunk
__int64 select_channel()
{
return pkt_card_chan_set();
}

canonical_decompiled_code:
__int64 func14()
{
return pkt_card_chan_set();
}

original_code:
int select_channel(struct SETTINGS*myset, int channel)
{
  return pkt_card_chan_set(myset, channel);
}

canonical_original_code:
int select_channel(struct SETTINGS *myset, int channel)
{
  return pkt_card_chan_set(myset, channel);
}

variable_types: channel int

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; }


hexdump

decompiled_code:
char *__fastcall hexdump(unsigned __int8 *a1, int a2)
{
__int64 v2; // r12
char *v3; // rbp
unsigned __int8 *v4; // rbx
__int64 v5; // rdx
char *v6; // rdi

if ( a2 <= 0 )
return dummybuf;
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = dummybuf;
v4 = a1;
do
{
v5 = *v4;
v6 = v3;
++v4;
v3 += 2;
sprintf(v6, "%02x", v5);
}
while ( v4 != (unsigned __int8 *)v2 );
return dummybuf;
}

canonical_decompiled_code:
char *__fastcall func0(unsigned __int8 *a1, int a2)
{
__int64 v2; // r12
char *v3; // rbp
unsigned __int8 *v4; // rbx
__int64 v5; // rdx
char *v6; // rdi

if ( a2 <= 0 )
return dummybuf;
v2 = (__int64)&a1[a2 - 1 + 1];
v3 = dummybuf;
v4 = a1;
do
{
v5 = *v4;
v6 = v3;
++v4;
v3 += 2;
sprintf(v6, "%02x", v5);
}
while ( v4 != (unsigned __int8 *)v2 );
return dummybuf;
}

original_code:
char *hexdump (__u8 * x, int y)
{
  int i = -1;
  while (++i < y)
    sprintf(&dummybuf[(i * 2)], "%02x", x[i]);
  return (dummybuf);
}

canonical_original_code:
char *hexdump(unsigned char *x, int y)
{
  int i = -1;
  while (++i < y)
    sprintf(&dummybuf[(i * 2)], "%02x", x[i]);
  return (dummybuf);
}

variable_types:
x
unsigned char *

variable_types: y int

return_type: char *


decompiled_code:
float __fastcall get_time_diff(_QWORD *a1, _QWORD *a2)
{
return (double)(int)a1[1] / 1000000.0 + (double)(int)*a1 - ((double)(int)a2[1] / 1000000.0 + (double)(int)*a2);
}

canonical_decompiled_code:
float __fastcall func2(_QWORD *a1, _QWORD *a2)
{
return (double)(int)a1[1] / 1000000.0 + (double)(int)*a1 - ((double)(int)a2[1] / 1000000.0 + (double)(int)*a2);
}

original_code:
float get_time_diff(struct timeval *t_new, struct timeval *t_old)
{
  float t_diff;
  double new_time;
  double old_time;
  new_time = (double)t_new->tv_sec + ((double)t_new->tv_usec/1000000);
  old_time = (double)t_old->tv_sec + ((double)t_old->tv_usec/1000000);
  t_diff = (double)new_time - (double)old_time;
  return (t_diff);
}

variable_types: struct timeval { long tv_sec; long tv_usec; } *

return_type: float


original_code:
void get_elapsed_time(struct timeval *t_end, struct timeval *t_start, char * buf)
{
  int hour, min, sec = 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));
  snprintf(buf,10,"%02d:%02d:%02d",hour,min,sec);
}

canonical_original_code:
void get_elapsed_time(struct timeval *t_end, struct timeval *t_start, char *buf)
{
  int hour; int min; int sec = 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));
  snprintf(buf,10,"%02d:%02d:%02d",hour,min,sec);
}

variable_types:
buf
char *

variable_types: hour int

variable_types: min int

variable_types: sec int


decompiled_code:
_BOOL8 __fastcall verify_chksum(char *a1)
{
char v1; // si
int v2; // ebx

v1 = *a1;
v2 = *((unsigned __int16 *)a1 + 5);
*((_WORD *)a1 + 5) = 0;
return v2 == (unsigned int)in_cksum(a1, 4 * (v1 & 0xFu));
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(char *a1)
{
char v1; // si
int v2; // ebx

v1 = *a1;
v2 = *((unsigned __int16 *)a1 + 5);
*((_WORD *)a1 + 5) = 0;
return v2 == (unsigned int)in_cksum(a1, 4 * (v1 & 0xFu));
}

original_code:
int verify_chksum(struct iphdr *ip)
{
  int ip_len = 0;
  int hdrcsum;
  int hdrchk;
  ip_len = ip->ihl * 4;
  hdrcsum = ip->check;
  ip->check = 0;
  hdrchk = in_cksum((u_short *) ip, ip_len);
  if (hdrcsum != hdrchk)
    return 0;
  else
    return 1;
}

canonical_original_code:
int verify_chksum(struct iphdr *ip)
{
  int ip_len = 0;
  int hdrcsum;
  int hdrchk;
  ip_len = ip->ihl * 4;
  hdrcsum = ip->check;
  ip->check = 0;
  hdrchk = in_cksum((unsigned short *) ip, ip_len);
  if (hdrcsum != hdrchk)
    return 0;
  else
    return 1;
}

variable_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; } *

variable_types: hdrcsum int

variable_types: hdrchk int


decompiled_code:
void dump_bsss()
{
;
}

canonical_decompiled_code:
void func5()
{
;
}

original_code:
void dump_bsss (bss_t * info)
{
}

canonical_original_code:
void dump_bsss(struct bss_t *info)
{
}

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; } *

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 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 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; }

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; }


decompiled_code:
__int64 __fastcall pkt_card_sock_open(__int64 a1)
{
int v1; // eax
int v2; // ebp
int v3; // er12
const char *v4; // rsi
const char *v5; // rsi
unsigned int v6; // er13
int v8; // eax
const char *v9; // rdi
int optval; // [rsp+Ch] [rbp-7Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-78h] BYREF
int v12; // [rsp+20h] [rbp-68h]
char dest[16]; // [rsp+30h] [rbp-58h] BYREF
__int128 v14; // [rsp+40h] [rbp-48h]
__int64 v15; // [rsp+50h] [rbp-38h]

optval = 10;
dummy_sock = socket(2, 2, 0);
if ( dummy_sock < 0 )
{
perror("can't open generic socket!");
close(dummy_sock);
exit(-1);
}
v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 != 2 )
{
if ( v1 <= 2 )
{
if ( v1 == 1 )
{
v2 = (unsigned __int16)_bswap_16_constprop_0();
v3 = socket(17, 3, v2);
if ( v3 >= 0 )
{
v4 = *(const char **)(a1 + 8);
v15 = 0LL;
*(_OWORD *)dest = 0LL;
v14 = 0LL;
strcpy(dest, v4);
if ( *(_DWORD *)(a1 + 36) )
{
if ( ioctl(v3, 0x89F3uLL, dest) < 0 )
{
perror("Could not get info");
fwrite("make sure your driver has signal strength capabilities.\n", 1uLL, 0x38uLL, stderr);
exit(0);
}
LOWORD(v14) = 1;
if ( ioctl(v3, 0x89F2uLL, dest) < 0 )
{
perror("Could not set info");
exit(0);
}
}
if ( ioctl(v3, 0x8933uLL, dest) < 0 )
{
perror("Could not get index");
fwrite("make sure you specified the proper interface.\n", 1uLL, 0x2EuLL, stderr);
exit(0);
}
LABEL_15:
addr.sa_family = 17;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v12 = 0;
*(_DWORD *)&addr.sa_data[2] = v14;
*(_WORD *)addr.sa_data = v2;
if ( bind(v3, &addr, 0x14u) < 0 )
{
perror("Call to bind failed");
exit(0);
}
return (unsigned int)v3;
}
LABEL_20:
perror("Could not create socket");
fwrite("You usually have to be root to open raw sockets\n", 1uLL, 0x30uLL, stderr);
exit(0);
}
return 0;
}
if ( (unsigned int)(v1 - 3) > 2 )
return 0;
v2 = (unsigned __int16)_bswap_16_constprop_0();
v3 = socket(17, 3, v2);
if ( v3 < 0 )
goto LABEL_20;
v5 = *(const char **)(a1 + 8);
v15 = 0LL;
*(_OWORD *)dest = 0LL;
v14 = 0LL;
strcpy(dest, v5);
if ( !ioctl(v3, 0x8927uLL, dest) )
{
v6 = (unsigned __int16)v14;
if ( (unsigned int)(unsigned __int16)v14 - 801 > 1 )
{
close(v3);
fprintf(
stderr,
"Unsupported arptype 0x%04x\nUsually a result of card not being properly set to monitor mode.\n",
v6);
fwrite(
"Check the version of your driver and make sure you're using a compatible driver with monitoring capabilities.\n",
1uLL,
0x6EuLL,
stderr);
exit(-1);
}
if ( ioctl(v3, 0x8933uLL, dest) < 0 )
{
perror("Could not get index");
close(v3);
fwrite("make sure you specified the proper interface.\n", 1uLL, 0x2EuLL, stderr);
exit(-1);
}
goto LABEL_15;
}
v9 = "ioctl(SIOCGIFHWADDR)";
LABEL_32:
perror(v9);
close(v3);
exit(-1);
}
v8 = socket(16, 3, 2);
v3 = v8;
if ( v8 < 0 )
goto LABEL_20;
if ( setsockopt(v8, 1, 2, &optval, 4u) < 0 )
{
perror("Could not set socket options");
exit(0);
}
*(_DWORD *)&dest[8] = 0;
*(_QWORD *)dest = 16LL;
*(_DWORD *)&dest[4] = getpid();
*(_DWORD *)&dest[8] = 1;
if ( bind(v3, (const struct sockaddr *)dest, 0xCu) < 0 )
{
v9 = "bind";
goto LABEL_32;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // eax
int v2; // ebp
int v3; // er12
const char *v4; // rsi
const char *v5; // rsi
unsigned int v6; // er13
int v8; // eax
const char *v9; // rdi
int optval; // [rsp+Ch] [rbp-7Ch] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-78h] BYREF
int v12; // [rsp+20h] [rbp-68h]
char dest[16]; // [rsp+30h] [rbp-58h] BYREF
__int128 v14; // [rsp+40h] [rbp-48h]
__int64 v15; // [rsp+50h] [rbp-38h]

optval = 10;
dummy_sock = socket(2, 2, 0);
if ( dummy_sock < 0 )
{
perror("can't open generic socket!");
close(dummy_sock);
exit(-1);
}
v1 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 != 2 )
{
if ( v1 <= 2 )
{
if ( v1 == 1 )
{
v2 = (unsigned __int16)func0();
v3 = socket(17, 3, v2);
if ( v3 >= 0 )
{
v4 = *(const char **)(a1 + 8);
v15 = 0LL;
*(_OWORD *)dest = 0LL;
v14 = 0LL;
strcpy(dest, v4);
if ( *(_DWORD *)(a1 + 36) )
{
if ( ioctl(v3, 0x89F3uLL, dest) < 0 )
{
perror("Could not get info");
fwrite("make sure your driver has signal strength capabilities.\n", 1uLL, 0x38uLL, stderr);
exit(0);
}
LOWORD(v14) = 1;
if ( ioctl(v3, 0x89F2uLL, dest) < 0 )
{
perror("Could not set info");
exit(0);
}
}
if ( ioctl(v3, 0x8933uLL, dest) < 0 )
{
perror("Could not get index");
fwrite("make sure you specified the proper interface.\n", 1uLL, 0x2EuLL, stderr);
exit(0);
}
LABEL_15:
addr.sa_family = 17;
*(_QWORD *)&addr.sa_data[6] = 0LL;
v12 = 0;
*(_DWORD *)&addr.sa_data[2] = v14;
*(_WORD *)addr.sa_data = v2;
if ( bind(v3, &addr, 0x14u) < 0 )
{
perror("Call to bind failed");
exit(0);
}
return (unsigned int)v3;
}
LABEL_20:
perror("Could not create socket");
fwrite("You usually have to be root to open raw sockets\n", 1uLL, 0x30uLL, stderr);
exit(0);
}
return 0;
}
if ( (unsigned int)(v1 - 3) > 2 )
return 0;
v2 = (unsigned __int16)func0();
v3 = socket(17, 3, v2);
if ( v3 < 0 )
goto LABEL_20;
v5 = *(const char **)(a1 + 8);
v15 = 0LL;
*(_OWORD *)dest = 0LL;
v14 = 0LL;
strcpy(dest, v5);
if ( !ioctl(v3, 0x8927uLL, dest) )
{
v6 = (unsigned __int16)v14;
if ( (unsigned int)(unsigned __int16)v14 - 801 > 1 )
{
close(v3);
fprintf(
stderr,
"Unsupported arptype 0x%04x\nUsually a result of card not being properly set to monitor mode.\n",
v6);
fwrite(
"Check the version of your driver and make sure you're using a compatible driver with monitoring capabilities.\n",
1uLL,
0x6EuLL,
stderr);
exit(-1);
}
if ( ioctl(v3, 0x8933uLL, dest) < 0 )
{
perror("Could not get index");
close(v3);
fwrite("make sure you specified the proper interface.\n", 1uLL, 0x2EuLL, stderr);
exit(-1);
}
goto LABEL_15;
}
v9 = "ioctl(SIOCGIFHWADDR)";
LABEL_32:
perror(v9);
close(v3);
exit(-1);
}
v8 = socket(16, 3, 2);
v3 = v8;
if ( v8 < 0 )
goto LABEL_20;
if ( setsockopt(v8, 1, 2, &optval, 4u) < 0 )
{
perror("Could not set socket options");
exit(0);
}
*(_DWORD *)&dest[8] = 0;
*(_QWORD *)dest = 16LL;
*(_DWORD *)&dest[4] = getpid();
*(_DWORD *)&dest[8] = 1;
if ( bind(v3, (const struct sockaddr *)dest, 0xCu) < 0 )
{
v9 = "bind";
goto LABEL_32;
}
return (unsigned int)v3;
}

original_code:
int pkt_card_sock_open (struct SETTINGS *mySettings)
{
  int msock_h = 0;
  int arptype;
  struct sockaddr_ll sock_addr;
  struct sockaddr_nl nl_addr;
  struct ifreq req;
  int myset = 10;
  if ((dummy_sock = socket(2, SOCK_DGRAM, 0)) < 0){
    perror ("can't open generic socket!");
    close(dummy_sock);
    exit (-1);
  }
  switch (mySettings->card_type){
  case 1:
    if (( msock_h= socket (17, SOCK_RAW, htons(0x0003))) < 0){
      perror ("Could not create socket");
      fprintf(stderr,"You usually have to be root to open raw sockets\n");
      exit(0);
    }
    memset(&req, 0, sizeof(struct ifreq));
    strcpy(req.ifr_ifrn.ifrn_name, mySettings->interface);
    if(mySettings->signal_support){
      if(ioctl(msock_h, (0x89F0 + 3), &req) < 0){
 perror ("Could not get info");
 fprintf(stderr,"make sure your driver has signal strength capabilities.\n");
 exit(0);
      }
      req.ifr_ifru.ifru_flags = 1;
      if(ioctl(msock_h, (0x89F0 + 2), &req) < 0){
 perror ("Could not set info");
 exit(0);
      }
    }
    if(ioctl(msock_h, 0x8933, &req) < 0) {
      perror ("Could not get index");
      fprintf(stderr,"make sure you specified the proper interface.\n");
      exit(0);
    }
    memset(&sock_addr, 0, sizeof (struct sockaddr_ll));
    sock_addr.sll_ifindex = req.ifr_ifru.ifru_ivalue;
    sock_addr.sll_protocol = htons(0x0003);
    sock_addr.sll_family = 17;
    if (bind(msock_h, (struct sockaddr *) &sock_addr,sizeof (struct sockaddr_ll)) < 0){
      perror ("Call to bind failed");
      exit(0);
    }
    break;
  case 2:
    if (( msock_h = socket(16, SOCK_RAW, 2)) < 0){
      perror ("Could not create socket");
      fprintf(stderr,"You usually have to be root to open raw sockets\n");
      exit(0);
    }
    if (setsockopt(msock_h, 1, 2, &myset, sizeof(myset)) < 0){
      perror ("Could not set socket options");
      exit(0);
    }
    memset(&nl_addr, 0, sizeof(nl_addr));
    nl_addr.nl_family = 16;
    nl_addr.nl_pid = (unsigned int) getpid();
    nl_addr.nl_groups = (1 << (0));
    if (bind(msock_h, (struct sockaddr *) &nl_addr, sizeof(nl_addr)) < 0) {
      perror("bind");
      close(msock_h);
      exit(-1);
    }
    break;
  case 4:
  case 3:
  case 5:
    if (( msock_h= socket (17, SOCK_RAW, htons(0x0003))) < 0){
      perror ("Could not create socket");
      fprintf(stderr,"You usually have to be root to open raw sockets\n");
      exit(0);
    }
    memset(&req, 0, sizeof(struct ifreq));
    strcpy(req.ifr_ifrn.ifrn_name, mySettings->interface);
    if (ioctl(msock_h, 0x8927, &req) != 0) {
      perror("ioctl(SIOCGIFHWADDR)");
      close(msock_h);
      exit(-1);
    }
    arptype = req.ifr_ifru.ifru_hwaddr.sa_family;
    if (arptype != 801 && arptype != 802) {
      close(msock_h);
      fprintf(stderr, "Unsupported arptype 0x%04x\nUsually a result of card not being properly set to monitor mode.\n", arptype);
      fprintf(stderr, "Check the version of your driver and make sure you're using a compatible driver with monitoring capabilities.\n");
      exit(-1);
    }
    if(ioctl(msock_h, 0x8933, &req) < 0) {
      perror ("Could not get index");
      close(msock_h);
      fprintf(stderr,"make sure you specified the proper interface.\n");
      exit(-1);
    }
    memset(&sock_addr, 0, sizeof (struct sockaddr_ll));
    sock_addr.sll_ifindex = req.ifr_ifru.ifru_ivalue;
    sock_addr.sll_protocol = htons(0x0003);
    sock_addr.sll_family = 17;
    if (bind(msock_h, (struct sockaddr *) &sock_addr,sizeof (struct sockaddr_ll)) < 0){
      perror ("Call to bind failed");
      exit(0);
    }
    break;
  }
  return (msock_h);
}

canonical_original_code:
int pkt_card_sock_open(struct SETTINGS *mySettings)
{
  int msock_h = 0;
  int arptype;
  struct sockaddr_ll sock_addr;
  struct sockaddr_nl nl_addr;
  struct ifreq req;
  int myset = 10;
  if ((dummy_sock = socket(2, SOCK_DGRAM, 0)) < 0){
    perror ("can't open generic socket!");
    close(dummy_sock);
    exit (-1);
  }
  switch (mySettings->card_type){
  case 1:
    if (( msock_h= socket (17, SOCK_RAW, htons(0x0003))) < 0){
      perror ("Could not create socket");
      fprintf(stderr,"You usually have to be root to open raw sockets\n");
      exit(0);
    }
    memset(&req, 0, sizeof(struct ifreq));
    strcpy(req.ifr_ifrn.ifrn_name, mySettings->interface);
    if(mySettings->signal_support){
      if(ioctl(msock_h, (0x89F0 + 3), &req) < 0){
 perror ("Could not get info");
 fprintf(stderr,"make sure your driver has signal strength capabilities.\n");
 exit(0);
      }
      req.ifr_ifru.ifru_flags = 1;
      if(ioctl(msock_h, (0x89F0 + 2), &req) < 0){
 perror ("Could not set info");
 exit(0);
      }
    }
    if(ioctl(msock_h, 0x8933, &req) < 0) {
      perror ("Could not get index");
      fprintf(stderr,"make sure you specified the proper interface.\n");
      exit(0);
    }
    memset(&sock_addr, 0, sizeof (struct sockaddr_ll));
    sock_addr.sll_ifindex = req.ifr_ifru.ifru_ivalue;
    sock_addr.sll_protocol = htons(0x0003);
    sock_addr.sll_family = 17;
    if (bind(msock_h, (struct sockaddr *) &sock_addr,sizeof (struct sockaddr_ll)) < 0){
      perror ("Call to bind failed");
      exit(0);
    }
    break;
  case 2:
    if (( msock_h = socket(16, SOCK_RAW, 2)) < 0){
      perror ("Could not create socket");
      fprintf(stderr,"You usually have to be root to open raw sockets\n");
      exit(0);
    }
    if (setsockopt(msock_h, 1, 2, &myset, sizeof(myset)) < 0){
      perror ("Could not set socket options");
      exit(0);
    }
    memset(&nl_addr, 0, sizeof(nl_addr));
    nl_addr.nl_family = 16;
    nl_addr.nl_pid = (unsigned int) getpid();
    nl_addr.nl_groups = (1 << (0));
    if (bind(msock_h, (struct sockaddr *) &nl_addr, sizeof(nl_addr)) < 0) {
      perror("bind");
      close(msock_h);
      exit(-1);
    }
    break;
  case 4:
  case 3:
  case 5:
    if (( msock_h= socket (17, SOCK_RAW, htons(0x0003))) < 0){
      perror ("Could not create socket");
      fprintf(stderr,"You usually have to be root to open raw sockets\n");
      exit(0);
    }
    memset(&req, 0, sizeof(struct ifreq));
    strcpy(req.ifr_ifrn.ifrn_name, mySettings->interface);
    if (ioctl(msock_h, 0x8927, &req) != 0) {
      perror("ioctl(SIOCGIFHWADDR)");
      close(msock_h);
      exit(-1);
    }
    arptype = req.ifr_ifru.ifru_hwaddr.sa_family;
    if (arptype != 801 && arptype != 802) {
      close(msock_h);
      fprintf(stderr, "Unsupported arptype 0x%04x\nUsually a result of card not being properly set to monitor mode.\n", arptype);
      fprintf(stderr, "Check the version of your driver and make sure you're using a compatible driver with monitoring capabilities.\n");
      exit(-1);
    }
    if(ioctl(msock_h, 0x8933, &req) < 0) {
      perror ("Could not get index");
      close(msock_h);
      fprintf(stderr,"make sure you specified the proper interface.\n");
      exit(-1);
    }
    memset(&sock_addr, 0, sizeof (struct sockaddr_ll));
    sock_addr.sll_ifindex = req.ifr_ifru.ifru_ivalue;
    sock_addr.sll_protocol = htons(0x0003);
    sock_addr.sll_family = 17;
    if (bind(msock_h, (struct sockaddr *) &sock_addr,sizeof (struct sockaddr_ll)) < 0){
      perror ("Call to bind failed");
      exit(0);
    }
    break;
  }
  return (msock_h);
}

variable_types: arptype int

variable_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; }

variable_types: struct sockaddr_nl { unsigned short nl_family; unsigned short nl_pad; unsigned int nl_pid; unsigned int nl_groups; }

variable_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto { unsigned short encoding; unsigned short parity; } *raw_hdlc; struct cisco_proto { unsigned int interval; unsigned int timeout; } *cisco; struct fr_proto { unsigned int t391; unsigned int t392; unsigned int n391; unsigned int n392; unsigned int n393; unsigned short lmi; unsigned short dce; } *fr; struct fr_proto_pvc { unsigned int dlci; } *fr_pvc; struct fr_proto_pvc_info { unsigned int dlci; char master[16]; } *fr_pvc_info; struct sync_serial_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; } *sync; struct te1_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; unsigned int slot_map; } *te1; } ifs_ifsu; } ifru_settings; } ifr_ifru; }

variable_types: myset int

user_defined_types: struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap ifru_map; char ifru_slave[16]; char ifru_newname[16]; void *ifru_data; struct if_settings ifru_settings; } ifr_ifru; }

user_defined_types: struct if_settings { unsigned int type; unsigned int size; union { struct raw_hdlc_proto *raw_hdlc; struct cisco_proto *cisco; struct fr_proto *fr; struct fr_proto_pvc *fr_pvc; struct fr_proto_pvc_info *fr_pvc_info; struct sync_serial_settings *sync; struct te1_settings *te1; } ifs_ifsu; }


decompiled_code:
ssize_t __fastcall pkt_card_sock_read(int fd, void *a2, int a3, struct sockaddr *a4)
{
__int64 v5; // r12
__int64 v6; // r14
ssize_t result; // rax
socklen_t addr_len; // [rsp+1Ch] [rbp-CCh] BYREF
struct timeval timeout; // [rsp+20h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-B8h] BYREF

memset(&readfds, 0, sizeof(readfds));
timeout.tv_sec = 0LL;
timeout.tv_usec = 5000LL;
v5 = fd / 64;
v6 = 1LL << (fd % 64);
readfds.fds_bits[v5] |= v6;
while ( select(fd + 1, &readfds, 0LL, 0LL, &timeout) < 0 && *_errno_location() == 4 )
;
result = 0LL;
if ( (readfds.fds_bits[v5] & v6) != 0 )
{
addr_len = 18;
result = recvfrom(fd, a2, a3, 0, a4, &addr_len);
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func2(int fd, void *a2, int a3, struct sockaddr *a4)
{
__int64 v5; // r12
__int64 v6; // r14
ssize_t result; // rax
socklen_t addr_len; // [rsp+1Ch] [rbp-CCh] BYREF
struct timeval timeout; // [rsp+20h] [rbp-C8h] BYREF
fd_set readfds; // [rsp+30h] [rbp-B8h] BYREF

memset(&readfds, 0, sizeof(readfds));
timeout.tv_sec = 0LL;
timeout.tv_usec = 5000LL;
v5 = fd / 64;
v6 = 1LL << (fd % 64);
readfds.fds_bits[v5] |= v6;
while ( select(fd + 1, &readfds, 0LL, 0LL, &timeout) < 0 && *_errno_location() == 4 )
;
result = 0LL;
if ( (readfds.fds_bits[v5] & v6) != 0 )
{
addr_len = 18;
result = recvfrom(fd, a2, a3, 0, a4, &addr_len);
}
return result;
}

original_code:
int pkt_card_sock_read(int msock_h, char *buf, int maxlen,
         struct sockaddr_ll *fromaddr)
{
  fd_set fds;
  int ret_val, recvlen;
  int fromlen;
  struct timeval tv;
  recvlen = 0;
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&fds)->__fds_bits)[((msock_h) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((msock_h) % (8 * (int) sizeof (__fd_mask)))))));
  tv.tv_sec = 0;
  tv.tv_usec = 5000;
  do {
    ret_val = select(msock_h+1, &fds, ((void *)0), ((void *)0), &tv);
  } while ((ret_val < 0)&&((*__errno_location ()) == 4));
  if (((((&fds)->__fds_bits)[((msock_h) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((msock_h) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    fromlen = sizeof(struct sockaddr_pkt);
    recvlen =recvfrom(msock_h,buf,maxlen,0,
        (struct sockaddr *)fromaddr, &fromlen);
  }
  return (recvlen);
}

canonical_original_code:
int pkt_card_sock_read(int msock_h, char *buf, int maxlen, struct sockaddr_ll *fromaddr)
{
  struct fd_set fds;
  int ret_val; int recvlen;
  int fromlen;
  struct timeval tv;
  recvlen = 0;
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  ((void) (((&fds)->__fds_bits)[((msock_h) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((msock_h) % (8 * (int) sizeof (__fd_mask)))))));
  tv.tv_sec = 0;
  tv.tv_usec = 5000;
  do {
    ret_val = select(msock_h+1, &fds, ((void *)0), ((void *)0), &tv);
  } while ((ret_val < 0)&&((*__errno_location ()) == 4));
  if (((((&fds)->__fds_bits)[((msock_h) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((msock_h) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    fromlen = sizeof(struct sockaddr_pkt);
    recvlen =recvfrom(msock_h,buf,maxlen,0,
        (struct sockaddr *)fromaddr, &fromlen);
  }
  return (recvlen);
}

variable_types: maxlen int

variable_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; } *

variable_types:
fds
struct fd_set { long __fds_bits[-1]; }

variable_types: recvlen int

variable_types: fromlen int

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

user_defined_types: struct sockaddr_pkt { unsigned short spkt_family; unsigned char spkt_device[14]; unsigned short spkt_protocol; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }


decompiled_code:
__int64 __fastcall pkt_card_sock_close(__int64 a1)
{
const char *v1; // rsi
int v2; // ebp
int v3; // edi
__int128 v5; // [rsp+0h] [rbp-48h] BYREF
__int128 v6; // [rsp+10h] [rbp-38h]
__int64 v7; // [rsp+20h] [rbp-28h]

v1 = *(const char **)(a1 + 8);
v2 = *(_DWORD *)(a1 + 40);
v5 = 0LL;
v7 = 0LL;
v6 = 0LL;
strcpy((char *)&v5, v1);
if ( *(_DWORD *)(a1 + 36) )
{
if ( ioctl(v2, 0x89F3uLL, &v5) < 0 )
{
perror("Could not get info");
exit(0);
}
LOWORD(v6) = 0;
if ( ioctl(v2, 0x89F2uLL, &v5) < 0 )
{
perror("Could not set info");
exit(0);
}
}
if ( v2 >= 0 )
{
close(v2);
v3 = dummy_sock;
if ( dummy_sock < 0 )
return 1LL;
}
else
{
v3 = dummy_sock;
if ( dummy_sock < 0 )
return 1LL;
}
close(v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
const char *v1; // rsi
int v2; // ebp
int v3; // edi
__int128 v5; // [rsp+0h] [rbp-48h] BYREF
__int128 v6; // [rsp+10h] [rbp-38h]
__int64 v7; // [rsp+20h] [rbp-28h]

v1 = *(const char **)(a1 + 8);
v2 = *(_DWORD *)(a1 + 40);
v5 = 0LL;
v7 = 0LL;
v6 = 0LL;
strcpy((char *)&v5, v1);
if ( *(_DWORD *)(a1 + 36) )
{
if ( ioctl(v2, 0x89F3uLL, &v5) < 0 )
{
perror("Could not get info");
exit(0);
}
LOWORD(v6) = 0;
if ( ioctl(v2, 0x89F2uLL, &v5) < 0 )
{
perror("Could not set info");
exit(0);
}
}
if ( v2 >= 0 )
{
close(v2);
v3 = dummy_sock;
if ( dummy_sock < 0 )
return 1LL;
}
else
{
v3 = dummy_sock;
if ( dummy_sock < 0 )
return 1LL;
}
close(v3);
return 1LL;
}

original_code:
int pkt_card_sock_close(struct SETTINGS* mySettings)
{
  struct ifreq req;
  int msock_h = mySettings->sniff_socket;
  memset(&req, 0, sizeof(struct ifreq));
  strcpy(req.ifr_ifrn.ifrn_name, mySettings->interface);
  if(mySettings->signal_support){
    if(ioctl(msock_h, (0x89F0 + 3), &req) < 0){
      perror ("Could not get info");
      exit(0);
    }
    req.ifr_ifru.ifru_flags = 0;
    if(ioctl(msock_h, (0x89F0 + 2), &req) < 0){
      perror ("Could not set info");
      exit(0);
    }
  }
  if (msock_h >= 0) close(msock_h);
  if (dummy_sock >= 0) close(dummy_sock);
  return (1);
}

canonical_original_code:
int pkt_card_sock_close(struct SETTINGS *mySettings)
{
  struct ifreq req;
  int msock_h = mySettings->sniff_socket;
  memset(&req, 0, sizeof(struct ifreq));
  strcpy(req.ifr_ifrn.ifrn_name, mySettings->interface);
  if(mySettings->signal_support){
    if(ioctl(msock_h, (0x89F0 + 3), &req) < 0){
      perror ("Could not get info");
      exit(0);
    }
    req.ifr_ifru.ifru_flags = 0;
    if(ioctl(msock_h, (0x89F0 + 2), &req) < 0){
      perror ("Could not set info");
      exit(0);
    }
  }
  if (msock_h >= 0) close(msock_h);
  if (dummy_sock >= 0) close(dummy_sock);
  return (1);
}

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; } *

user_defined_types: struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; }

user_defined_types: struct raw_hdlc_proto { unsigned short encoding; unsigned short parity; }

user_defined_types: struct cisco_proto { unsigned int interval; unsigned int timeout; }

user_defined_types: struct fr_proto { unsigned int t391; unsigned int t392; unsigned int n391; unsigned int n392; unsigned int n393; unsigned short lmi; unsigned short dce; }

user_defined_types: struct fr_proto_pvc { unsigned int dlci; }

user_defined_types: struct fr_proto_pvc_info { unsigned int dlci; char master[16]; }

user_defined_types: struct sync_serial_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; }

user_defined_types: struct te1_settings { unsigned int clock_rate; unsigned int clock_type; unsigned short loopback; unsigned int slot_map; }


decompiled_code:
_BOOL8 __fastcall pkt_card_ifup(__int64 a1)
{
return (int)set_flag((unsigned int)dummy_sock, *(_QWORD *)(a1 + 8), 65LL) > 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1)
{
return (int)set_flag((unsigned int)dummy_sock, *(_QWORD *)(a1 + 8), 65LL) > 0;
}

original_code:
int pkt_card_ifup(struct SETTINGS* mySettings)
{
  if (set_flag(dummy_sock, mySettings->interface, (IFF_UP|IFF_RUNNING)) > 0)
    return (1);
  else
    return (0);
}

canonical_original_code:
int pkt_card_ifup(struct SETTINGS *mySettings)
{
  if (set_flag(dummy_sock, mySettings->interface, (IFF_UP|IFF_RUNNING)) > 0)
    return (1);
  else
    return (0);
}

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:
_BOOL8 __fastcall pkt_card_is_chan_hop(int a1)
{
return (unsigned int)(a1 - 1) <= 4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(int a1)
{
return (unsigned int)(a1 - 1) <= 4;
}

original_code:
int pkt_card_is_chan_hop(int card_type)
{
 if ((card_type==1)||(card_type==2)||(card_type==3)||(card_type==4)||(card_type==5))
   return (1);
 else
   return (0);
}


decompiled_code:
__int64 __fastcall pkt_card_channel_range(const char **a1)
{
int v1; // ebx

v1 = 1;
while ( (unsigned int)pkt_card_chan_set(a1, v1) != -1 )
{
if ( ++v1 == 15 )
return 14LL;
}
return (unsigned int)(v1 - 1);
}

canonical_decompiled_code:
__int64 __fastcall func8(const char **a1)
{
int v1; // ebx

v1 = 1;
while ( (unsigned int)func7(a1, v1) != -1 )
{
if ( ++v1 == 15 )
return 14LL;
}
return (unsigned int)(v1 - 1);
}

original_code:
int pkt_card_channel_range(struct SETTINGS* mySettings)
{
  int i;
  for (i = 1; i < 15; i++){
    if (pkt_card_chan_set(mySettings, i) == -1)
      return (--i);
  }
  return (--i);
}

canonical_original_code:
int pkt_card_channel_range(struct SETTINGS *mySettings)
{
  int i;
  for (i = 1; i < 15; i++){
    if (pkt_card_chan_set(mySettings, i) == -1)
      return (--i);
  }
  return (--i);
}

variable_types: i int


decompiled_code:
int draw_desktop()
{
int v0; // ebx
int v1; // esi
char s[18]; // [rsp+6h] [rbp-12h] BYREF

sprintf(s, "%%%dc", (unsigned int)COLS);
scrollok(stdscr, 0);
wattrset(stdscr, STATUSBARATTR);
wmove(stdscr, 0, 0);
printw(s, 32LL);
wmove(stdscr, LINES - 1, 0);
printw(s, 32LL);
wattrset(stdscr, FIELDATTR);
if ( LINES > 2 )
{
v0 = 1;
do
{
v1 = v0++;
wmove(stdscr, v1, 0);
printw(s, 32LL);
}
while ( LINES - 1 > v0 );
}
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func0()
{
int v0; // ebx
int v1; // esi
char s[18]; // [rsp+6h] [rbp-12h] BYREF

sprintf(s, "%%%dc", (unsigned int)COLS);
scrollok(stdscr, 0);
wattrset(stdscr, STATUSBARATTR);
wmove(stdscr, 0, 0);
printw(s, 32LL);
wmove(stdscr, LINES - 1, 0);
printw(s, 32LL);
wattrset(stdscr, FIELDATTR);
if ( LINES > 2 )
{
v0 = 1;
do
{
v1 = v0++;
wmove(stdscr, v1, 0);
printw(s, 32LL);
}
while ( LINES - 1 > v0 );
}
return wrefresh(stdscr);
}

original_code:
void draw_desktop(void)
{
    int row;
    char sp_buf[10];
    sprintf(sp_buf, "%%%dc", COLS);
    scrollok(stdscr, 0);
    wattrset(stdscr,(STATUSBARATTR));
    wmove(stdscr,(0),(0));
    printw(sp_buf, ' ');
    wmove(stdscr,(LINES - 1),(0));
    printw(sp_buf, ' ');
    wattrset(stdscr,(FIELDATTR));
    for (row = 1; row <= LINES - 2; row++) {
 wmove(stdscr,(row),(0));
 printw(sp_buf, ' ');
    }
    wrefresh(stdscr);
}

canonical_original_code:
void draw_desktop()
{
    int row;
    char sp_buf[10];
    sprintf(sp_buf, "%%%dc", COLS);
    scrollok(stdscr, 0);
    wattrset(stdscr,(STATUSBARATTR));
    wmove(stdscr,(0),(0));
    printw(sp_buf, ' ');
    wmove(stdscr,(LINES - 1),(0));
    printw(sp_buf, ' ');
    wattrset(stdscr,(FIELDATTR));
    for (row = 1; row <= LINES - 2; row++) {
 wmove(stdscr,(row),(0));
 printw(sp_buf, ' ');
    }
    wrefresh(stdscr);
}

variable_types: row int


coloreol

decompiled_code:
void coloreol()
{
int v0; // ebx
char *v1; // rax
char *v2; // rbp
int v3; // er12

v0 = -1;
v1 = (char *)malloc(COLS + 1);
*v1 = 0;
v2 = v1;
if ( stdscr )
v0 = stdscr->_curx;
v3 = COLS;
if ( v0 < COLS )
{
do
{
++v0;
*(_WORD *)&v2[strlen(v2)] = 32;
}
while ( v0 != v3 );
}
printw(v2);
free(v2);
}

canonical_decompiled_code:
void func2()
{
int v0; // ebx
char *v1; // rax
char *v2; // rbp
int v3; // er12

v0 = -1;
v1 = (char *)malloc(COLS + 1);
*v1 = 0;
v2 = v1;
if ( stdscr )
v0 = stdscr->_curx;
v3 = COLS;
if ( v0 < COLS )
{
do
{
++v0;
*(_WORD *)&v2[strlen(v2)] = 32;
}
while ( v0 != v3 );
}
printw(v2);
free(v2);
}

original_code:
void coloreol()
{
    char *blankpad;
    int y, x;
    int i;
    blankpad = (char *) malloc(sizeof(char) * (COLS + 1));
    strcpy(blankpad, "");
    (y = ((0 != (const void *)((stdscr))) ? (stdscr)->_cury : (-1)), x = ((0 != (const void *)((stdscr))) ? (stdscr)->_curx : (-1)));
    for (i = x; i <= COLS - 1; i++)
 strcat(blankpad, " ");
    printw(blankpad);
    free(blankpad);
}

canonical_original_code:
void coloreol()
{
    char *blankpad;
    int y; int x;
    int i;
    blankpad = (char *) malloc(sizeof(char) * (COLS + 1));
    strcpy(blankpad, "");
    (y = ((0 != (void *)((stdscr))) ? (stdscr)->_cury : (-1)), x = ((0 != (void *)((stdscr))) ? (stdscr)->_curx : (-1)));
    for (i = x; i <= COLS - 1; i++)
 strcat(blankpad, " ");
    printw(blankpad);
    free(blankpad);
}

variable_types:
blankpad
char *

variable_types: y int

variable_types: x int


printnomem

decompiled_code:
int printnomem()
{
wattrset(stdscr, ERRTXTATTR);
return mvprintw(0, 68, " Memory Low ");
}

canonical_decompiled_code:
int func4()
{
wattrset(stdscr, ERRTXTATTR);
return mvprintw(0, 68, " Memory Low ");
}

original_code:
void printnomem()
{
    wattrset(stdscr,(ERRTXTATTR));
    mvprintw(0, 68, " Memory Low ");
}


printipcerr

decompiled_code:
int printipcerr()
{
wattrset(stdscr, ERRTXTATTR);
return mvprintw(0, 68, " IPC Error ");
}

canonical_decompiled_code:
int func5()
{
wattrset(stdscr, ERRTXTATTR);
return mvprintw(0, 68, " IPC Error ");
}

original_code:
void printipcerr()
{
    wattrset(stdscr,(ERRTXTATTR));
    mvprintw(0, 68, "  IPC Error ");
}


sortkeyhelp

decompiled_code:
int sortkeyhelp()
{
return printkeyhelp("S", "-sort ", stdscr, HIGHATTR, STATUSBARATTR);
}

canonical_decompiled_code:
int func8()
{
return func6("S", "-sort ", stdscr, HIGHATTR, STATUSBARATTR);
}

original_code:
void sortkeyhelp(void)
{
    printkeyhelp("S", "-sort  ", stdscr, HIGHATTR, STATUSBARATTR);
}

canonical_original_code:
void sortkeyhelp()
{
    printkeyhelp("S", "-sort  ", stdscr, HIGHATTR, STATUSBARATTR);
}


stdexitkeyhelp

decompiled_code:
void stdexitkeyhelp()
{
printkeyhelp("X", "-exit", stdscr, HIGHATTR, STATUSBARATTR);
coloreol();
}

canonical_decompiled_code:
void func9()
{
func6("X", "-exit", stdscr, HIGHATTR, STATUSBARATTR);
func2();
}

original_code:
void stdexitkeyhelp(void)
{
    printkeyhelp("X", "-exit", stdscr, HIGHATTR, STATUSBARATTR);
    coloreol(stdscr);
}

canonical_original_code:
void stdexitkeyhelp()
{
    printkeyhelp("X", "-exit", stdscr, HIGHATTR, STATUSBARATTR);
    coloreol(stdscr);
}


changewinkeyhelp

decompiled_code:
int changewinkeyhelp()
{
return printkeyhelp("W", "-change active window ", stdscr, HIGHATTR, STATUSBARATTR);
}

canonical_decompiled_code:
int func10()
{
return func6("W", "-change active window ", stdscr, HIGHATTR, STATUSBARATTR);
}

original_code:
void changewinkeyhelp(void)
{
  printkeyhelp("W", "-change active window  ", stdscr, HIGHATTR, STATUSBARATTR);
}

canonical_original_code:
void changewinkeyhelp()
{
  printkeyhelp("W", "-change active window  ", stdscr, HIGHATTR, STATUSBARATTR);
}


scrollkeyhelp

decompiled_code:
int scrollkeyhelp()
{
return printkeyhelp("Up/Down/PgUp/PgDn", "-scroll window ", stdscr, HIGHATTR, STDATTR);
}

canonical_decompiled_code:
int func11()
{
return func6("Up/Down/PgUp/PgDn", "-scroll window ", stdscr, HIGHATTR, STDATTR);
}

original_code:
void scrollkeyhelp(void)
{
  printkeyhelp("Up/Down/PgUp/PgDn", "-scroll window  ", stdscr, HIGHATTR, STDATTR);
}

canonical_original_code:
void scrollkeyhelp()
{
  printkeyhelp("Up/Down/PgUp/PgDn", "-scroll window  ", stdscr, HIGHATTR, STDATTR);
}


channelkeyhelp

decompiled_code:
int channelkeyhelp()
{
return printkeyhelp("Left/Right", "-change channels ", stdscr, HIGHATTR, STATUSBARATTR);
}

canonical_decompiled_code:
int func12()
{
return func6("Left/Right", "-change channels ", stdscr, HIGHATTR, STATUSBARATTR);
}

original_code:
void channelkeyhelp(void)
{
  printkeyhelp("Left/Right", "-change channels  ", stdscr, HIGHATTR, STATUSBARATTR);
}

canonical_original_code:
void channelkeyhelp()
{
  printkeyhelp("Left/Right", "-change channels  ", stdscr, HIGHATTR, STATUSBARATTR);
}


viewkeyhelp

decompiled_code:
int viewkeyhelp()
{
return printkeyhelp("V", "-toggle view ", stdscr, HIGHATTR, STATUSBARATTR);
}

canonical_decompiled_code:
int func13()
{
return func6("V", "-toggle view ", stdscr, HIGHATTR, STATUSBARATTR);
}

original_code:
void viewkeyhelp(void)
{
  printkeyhelp("V", "-toggle view  ", stdscr, HIGHATTR, STATUSBARATTR);
}

canonical_original_code:
void viewkeyhelp()
{
  printkeyhelp("V", "-toggle view  ", stdscr, HIGHATTR, STATUSBARATTR);
}


pausekeyhelp

decompiled_code:
int pausekeyhelp()
{
return printkeyhelp("P", "-pause ", stdscr, HIGHATTR, STATUSBARATTR);
}

canonical_decompiled_code:
int func14()
{
return func6("P", "-pause ", stdscr, HIGHATTR, STATUSBARATTR);
}

original_code:
void pausekeyhelp(void)
{
  printkeyhelp("P", "-pause  ", stdscr, HIGHATTR, STATUSBARATTR);
}

canonical_original_code:
void pausekeyhelp()
{
  printkeyhelp("P", "-pause  ", stdscr, HIGHATTR, STATUSBARATTR);
}


menukeyhelp

decompiled_code:
void menukeyhelp()
{
wmove(stdscr, LINES - 1, 1);
printkeyhelp("Up/Down", "-Move selector ", stdscr, HIGHATTR, STATUSBARATTR);
printkeyhelp("Enter", "-execute", stdscr, HIGHATTR, STATUSBARATTR);
coloreol();
}

canonical_decompiled_code:
void func15()
{
wmove(stdscr, LINES - 1, 1);
func6("Up/Down", "-Move selector ", stdscr, HIGHATTR, STATUSBARATTR);
func6("Enter", "-execute", stdscr, HIGHATTR, STATUSBARATTR);
func2();
}

original_code:
void menukeyhelp(void)
{
    wmove(stdscr,(LINES - 1),(1));
    printkeyhelp("Up/Down", "-Move selector  ", stdscr, HIGHATTR, STATUSBARATTR);
    printkeyhelp("Enter", "-execute", stdscr, HIGHATTR, STATUSBARATTR);
    coloreol(stdscr);
}

canonical_original_code:
void menukeyhelp()
{
    wmove(stdscr,(LINES - 1),(1));
    printkeyhelp("Up/Down", "-Move selector  ", stdscr, HIGHATTR, STATUSBARATTR);
    printkeyhelp("Enter", "-execute", stdscr, HIGHATTR, STATUSBARATTR);
    coloreol(stdscr);
}


listkeyhelp

decompiled_code:
void listkeyhelp()
{
wmove(stdscr, LINES - 1, 1);
printkeyhelp("Up/Down", "-move pointer ", stdscr, HIGHATTR, STATUSBARATTR);
printkeyhelp("Enter", "-select ", stdscr, HIGHATTR, STATUSBARATTR);
stdexitkeyhelp();
}

canonical_decompiled_code:
void func16()
{
wmove(stdscr, LINES - 1, 1);
func6("Up/Down", "-move pointer ", stdscr, HIGHATTR, STATUSBARATTR);
func6("Enter", "-select ", stdscr, HIGHATTR, STATUSBARATTR);
func9();
}

original_code:
void listkeyhelp()
{
    wmove(stdscr,(LINES - 1),(1));
    printkeyhelp("Up/Down", "-move pointer  ", stdscr, HIGHATTR, STATUSBARATTR);
    printkeyhelp("Enter", "-select  ", stdscr, HIGHATTR, STATUSBARATTR);
    stdexitkeyhelp();
}


indicate

decompiled_code:
int __fastcall indicate(char *a1)
{
char s[18]; // [rsp+6h] [rbp-12h] BYREF

wattrset(stdscr, STATUSBARATTR);
sprintf(s, "%%%dc", (unsigned int)COLS);
mvprintw(LINES - 1, 0, s, 32LL);
mvprintw(LINES - 1, 1, a1);
return wrefresh(stdscr);
}

canonical_decompiled_code:
int __fastcall func18(char *a1)
{
char s[18]; // [rsp+6h] [rbp-12h] BYREF

wattrset(stdscr, STATUSBARATTR);
sprintf(s, "%%%dc", (unsigned int)COLS);
mvprintw(LINES - 1, 0, s, 32LL);
mvprintw(LINES - 1, 1, a1);
return wrefresh(stdscr);
}

original_code:
void indicate(char *message)
{
    char sp_buf[10];
    wattrset(stdscr,(STATUSBARATTR));
    sprintf(sp_buf, "%%%dc", COLS);
    mvprintw(LINES - 1, 0, sp_buf, ' ');
    mvprintw(LINES - 1, 1, message);
    wrefresh(stdscr);
}

variable_types:
message
char *


standardcolors

decompiled_code:
void __fastcall standardcolors(int a1)
{
if ( a1 && has_colors() )
{
init_pair(1, 4, 7);
init_pair(2, 0, 6);
init_pair(3, 6, 4);
init_pair(4, 3, 1);
init_pair(5, 7, 1);
init_pair(6, 4, 6);
init_pair(7, 4, 7);
init_pair(9, 1, 7);
init_pair(10, 2, 4);
init_pair(11, 6, 0);
init_pair(12, 1, 6);
init_pair(14, 3, 4);
init_pair(15, 3, 0);
init_pair(16, 7, 6);
init_pair(17, 3, 6);
init_pair(18, 1, 4);
STDATTR = 2100736;
HIGHATTR = 2097920;
BOXATTR = 768;
ACTIVEATTR = 2099712;
ALERTATTR = 2101760;
BARSTDATTR = 2100992;
BARHIGHATTR = 2099968;
DESCATTR = 512;
DLGTEXTATTR = 512;
DLGBOXATTR = 1536;
DLGHIGHATTR = 3072;
STATUSBARATTR = 2100736;
IPSTATLABELATTR = 512;
IPSTATATTR = 3072;
PTRATTR = 2099712;
FIELDATTR = 256;
ERRBOXATTR = 2098432;
ERRTXTATTR = 2098176;
OSPFATTR = 512;
UDPATTR = 2304;
IGPATTR = 3072;
IGMPATTR = 2099712;
IGRPATTR = 2101248;
ARPATTR = 2098432;
GREATTR = 256;
UNKNATTR = 2098176;
}
else
{
STDATTR = 0;
HIGHATTR = 0x200000;
BOXATTR = 0;
ACTIVEATTR = 0x200000;
BARSTDATTR = 0x40000;
BARHIGHATTR = 0x200000;
DESCATTR = 0;
DLGBOXATTR = 0x40000;
DLGTEXTATTR = 0x40000;
DLGHIGHATTR = 0x200000;
STATUSBARATTR = 0x40000;
IPSTATLABELATTR = 0x40000;
IPSTATATTR = 0x10000;
PTRATTR = 0x200000;
FIELDATTR = 0x200000;
ERRBOXATTR = 0x200000;
ERRTXTATTR = 0;
OSPFATTR = 0x40000;
UDPATTR = 0x200000;
IGPATTR = 0x40000;
IGMPATTR = 0x40000;
IGRPATTR = 0x40000;
ARPATTR = 0x200000;
GREATTR = 0x200000;
UNKNATTR = 0x200000;
}
}

canonical_decompiled_code:
void __fastcall func22(int a1)
{
if ( a1 && has_colors() )
{
init_pair(1, 4, 7);
init_pair(2, 0, 6);
init_pair(3, 6, 4);
init_pair(4, 3, 1);
init_pair(5, 7, 1);
init_pair(6, 4, 6);
init_pair(7, 4, 7);
init_pair(9, 1, 7);
init_pair(10, 2, 4);
init_pair(11, 6, 0);
init_pair(12, 1, 6);
init_pair(14, 3, 4);
init_pair(15, 3, 0);
init_pair(16, 7, 6);
init_pair(17, 3, 6);
init_pair(18, 1, 4);
STDATTR = 2100736;
HIGHATTR = 2097920;
BOXATTR = 768;
ACTIVEATTR = 2099712;
ALERTATTR = 2101760;
BARSTDATTR = 2100992;
BARHIGHATTR = 2099968;
DESCATTR = 512;
DLGTEXTATTR = 512;
DLGBOXATTR = 1536;
DLGHIGHATTR = 3072;
STATUSBARATTR = 2100736;
IPSTATLABELATTR = 512;
IPSTATATTR = 3072;
PTRATTR = 2099712;
FIELDATTR = 256;
ERRBOXATTR = 2098432;
ERRTXTATTR = 2098176;
OSPFATTR = 512;
UDPATTR = 2304;
IGPATTR = 3072;
IGMPATTR = 2099712;
IGRPATTR = 2101248;
ARPATTR = 2098432;
GREATTR = 256;
UNKNATTR = 2098176;
}
else
{
STDATTR = 0;
HIGHATTR = 0x200000;
BOXATTR = 0;
ACTIVEATTR = 0x200000;
BARSTDATTR = 0x40000;
BARHIGHATTR = 0x200000;
DESCATTR = 0;
DLGBOXATTR = 0x40000;
DLGTEXTATTR = 0x40000;
DLGHIGHATTR = 0x200000;
STATUSBARATTR = 0x40000;
IPSTATLABELATTR = 0x40000;
IPSTATATTR = 0x10000;
PTRATTR = 0x200000;
FIELDATTR = 0x200000;
ERRBOXATTR = 0x200000;
ERRTXTATTR = 0;
OSPFATTR = 0x40000;
UDPATTR = 0x200000;
IGPATTR = 0x40000;
IGMPATTR = 0x40000;
IGRPATTR = 0x40000;
ARPATTR = 0x200000;
GREATTR = 0x200000;
UNKNATTR = 0x200000;
}
}

variable_types: color int


decompiled_code:
int refresh_screen()
{
endwin();
doupdate();
return curs_set(0);
}

canonical_decompiled_code:
int func23()
{
endwin();
doupdate();
return curs_set(0);
}

original_code:
void refresh_screen(void)
{
    endwin();
    doupdate();
    curs_set(0);
}

canonical_original_code:
void refresh_screen()
{
    endwin();
    doupdate();
    curs_set(0);
}


decompiled_code:
__int64 __fastcall sniff_packet(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rdi

result = get_packet();
if ( result )
{
v3 = result;
result = *(unsigned int *)(a1 + 44);
if ( (_DWORD)result == 2 )
{
result = process_channel_scan(v3);
}
else if ( (_DWORD)result == 1 )
{
if ( !*(_DWORD *)(a1 + 16) )
*(_QWORD *)(a1 + 48) = 0LL;
result = process_detailed_scan(v3);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 result; // rax
__int64 v3; // rdi

result = get_packet();
if ( result )
{
v3 = result;
result = *(unsigned int *)(a1 + 44);
if ( (_DWORD)result == 2 )
{
result = process_channel_scan(v3);
}
else if ( (_DWORD)result == 1 )
{
if ( !*(_DWORD *)(a1 + 16) )
*(_QWORD *)(a1 + 48) = 0LL;
result = process_detailed_scan(v3);
}
}
return result;
}

original_code:
void sniff_packet(struct SETTINGS *mySettings)
{
  struct packet_info *packet;
  if (0) printf("reading socket\n");
  if (((void *)0) == (packet = get_packet(mySettings)))
    return;
  if (0) printf("socket read ok\n");
  if (mySettings->scan_mode == 2){
    process_channel_scan(packet);
  }
  else if (mySettings->scan_mode == 1){
    if (mySettings->runtime_mode == 0)
      mySettings->chosen_ap = ((void *)0);
    if (mySettings->chosen_ap != ((void *)0))
      process_detailed_scan(packet,
      (struct access_point *)mySettings->chosen_ap);
    else
      process_detailed_scan(packet, ((void *)0));
  }
}

variable_types: struct packet_info { unsigned int packet_size; unsigned int net_pkt_size; unsigned char error_status; unsigned char driver_proto; unsigned char mac_proto; unsigned char net_proto; unsigned char trans_proto; unsigned short data_size; struct airids_frame_info { unsigned char card_type; unsigned char fcs_error; unsigned char undecrypt; unsigned char channel; unsigned char signal; unsigned long time; } *driver_pkt; void *mac_pkt; void *net_pkt; void *trans_pkt; void *data; } *

user_defined_types: struct packet_info { unsigned int packet_size; unsigned int net_pkt_size; unsigned char error_status; unsigned char driver_proto; unsigned char mac_proto; unsigned char net_proto; unsigned char trans_proto; unsigned short data_size; struct airids_frame_info *driver_pkt; void *mac_pkt; void *net_pkt; void *trans_pkt; void *data; }

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; }

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


decompiled_code:
void __fastcall __noreturn sniffer_engine(void *a1, float a2)
{
__m128i v2; // xmm3
int v3; // eax
bool v4; // zf
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF
__m128i v6; // [rsp+20h] [rbp-28h] BYREF
struct timeval v7; // [rsp+30h] [rbp-18h] BYREF

pthread_mutex_lock(&engine_lock);
gettimeofday(&tv, 0LL);
v2 = _mm_loadu_si128((const __m128i *)&tv);
engine_status = 1;
channel_change = 0;
v6 = v2;
pthread_cond_broadcast(&engine_ready);
pthread_mutex_unlock(&engine_lock);
LABEL_2:
if ( stop_scanning )
{
LABEL_8:
pthread_mutex_lock(&engine_lock);
engine_status = 0;
pthread_cond_broadcast(&engine_dead);
pthread_mutex_unlock(&engine_lock);
pthread_exit(&engine);
}
while ( 1 )
{
gettimeofday(&v7, 0LL);
get_time_diff(&v7, &v6);
v3 = *((_DWORD *)a1 + 11);
if ( v3 != 1 )
goto LABEL_4;
if ( a2 > 1.0 )
{
pthread_mutex_lock(&engine_lock);
update_all_bandwidth();
v6 = _mm_loadu_si128((const __m128i *)&v7);
pthread_mutex_unlock(&engine_lock);
if ( *((_DWORD *)a1 + 4) != 1 )
{
v3 = *((_DWORD *)a1 + 11);
goto LABEL_4;
}
}
else if ( *((_DWORD *)a1 + 4) != 1 )
{
goto LABEL_7;
}
get_time_diff(&v7, &tv);
if ( a2 > 30.0 )
{
pthread_mutex_lock(&engine_lock);
track_bad_data();
clean_up_bss_nodes();
clear_potential_structs();
pthread_mutex_unlock(&engine_lock);
v4 = *((_DWORD *)a1 + 11) == 2;
tv = (struct timeval)_mm_loadu_si128((const __m128i *)&v7);
if ( v4 )
goto LABEL_14;
goto LABEL_7;
}
v3 = *((_DWORD *)a1 + 11);
LABEL_4:
if ( v3 == 2 )
{
if ( a2 > 30.0 )
{
LABEL_14:
update_all_ap_status();
v6 = _mm_loadu_si128((const __m128i *)&v7);
}
if ( channel_change )
goto LABEL_2;
}
LABEL_7:
pthread_mutex_lock(&engine_lock);
sniff_packet((__int64)a1);
pthread_mutex_unlock(&engine_lock);
if ( stop_scanning )
goto LABEL_8;
}
}

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1, float a2)
{
__m128i v2; // xmm3
int v3; // eax
bool v4; // zf
struct timeval tv; // [rsp+10h] [rbp-38h] BYREF
__m128i v6; // [rsp+20h] [rbp-28h] BYREF
struct timeval v7; // [rsp+30h] [rbp-18h] BYREF

pthread_mutex_lock(&engine_lock);
gettimeofday(&tv, 0LL);
v2 = _mm_loadu_si128((const __m128i *)&tv);
engine_status = 1;
channel_change = 0;
v6 = v2;
pthread_cond_broadcast(&engine_ready);
pthread_mutex_unlock(&engine_lock);
LABEL_2:
if ( stop_scanning )
{
LABEL_8:
pthread_mutex_lock(&engine_lock);
engine_status = 0;
pthread_cond_broadcast(&engine_dead);
pthread_mutex_unlock(&engine_lock);
pthread_exit(&engine);
}
while ( 1 )
{
gettimeofday(&v7, 0LL);
get_time_diff(&v7, &v6);
v3 = *((_DWORD *)a1 + 11);
if ( v3 != 1 )
goto LABEL_4;
if ( a2 > 1.0 )
{
pthread_mutex_lock(&engine_lock);
update_all_bandwidth();
v6 = _mm_loadu_si128((const __m128i *)&v7);
pthread_mutex_unlock(&engine_lock);
if ( *((_DWORD *)a1 + 4) != 1 )
{
v3 = *((_DWORD *)a1 + 11);
goto LABEL_4;
}
}
else if ( *((_DWORD *)a1 + 4) != 1 )
{
goto LABEL_7;
}
get_time_diff(&v7, &tv);
if ( a2 > 30.0 )
{
pthread_mutex_lock(&engine_lock);
track_bad_data();
clean_up_bss_nodes();
clear_potential_structs();
pthread_mutex_unlock(&engine_lock);
v4 = *((_DWORD *)a1 + 11) == 2;
tv = (struct timeval)_mm_loadu_si128((const __m128i *)&v7);
if ( v4 )
goto LABEL_14;
goto LABEL_7;
}
v3 = *((_DWORD *)a1 + 11);
LABEL_4:
if ( v3 == 2 )
{
if ( a2 > 30.0 )
{
LABEL_14:
update_all_ap_status();
v6 = _mm_loadu_si128((const __m128i *)&v7);
}
if ( channel_change )
goto LABEL_2;
}
LABEL_7:
pthread_mutex_lock(&engine_lock);
func0((__int64)a1);
pthread_mutex_unlock(&engine_lock);
if ( stop_scanning )
goto LABEL_8;
}
}

original_code:
void * sniffer_engine(void *var)
{
  struct SETTINGS *mySettings;
  struct timeval tv_pot_reset;
  struct timeval tv_old;
  struct timeval tv_new;
  float t_diff;
  pthread_mutex_lock(&engine_lock);
  mySettings = (struct SETTINGS*)var;
  gettimeofday(&tv_pot_reset, ((void *)0));
  tv_old = tv_pot_reset;
  engine_status = 1;
  channel_change = 0;
  pthread_cond_broadcast(&engine_ready);
  pthread_mutex_unlock(&engine_lock);
  while (!stop_scanning){
    gettimeofday(&tv_new, ((void *)0));
    t_diff = get_time_diff(&tv_new, &tv_old);
    if (mySettings->scan_mode == 1){
      if (t_diff > 1){
 pthread_mutex_lock(&engine_lock);
 update_all_bandwidth();
 tv_old = tv_new;
 pthread_mutex_unlock(&engine_lock);
      }
      if (mySettings->runtime_mode == 1){
 t_diff = get_time_diff(&tv_new, &tv_pot_reset);
 if (t_diff > 30){
   pthread_mutex_lock(&engine_lock);
   track_bad_data();
   clean_up_bss_nodes();
   clear_potential_structs();
   pthread_mutex_unlock(&engine_lock);
   tv_pot_reset = tv_new;
 }
      }
    }
    if (mySettings->scan_mode == 2){
      if (t_diff > 30){
 update_all_ap_status();
 tv_old = tv_new;
      }
      if (channel_change)
 continue;
    }
    pthread_mutex_lock(&engine_lock);
    if (0) fprintf(stderr,"calling sniff_packet()\n");
    sniff_packet(mySettings);
    if (0) fprintf(stderr,"returned from sniff_packet()\n");
    pthread_mutex_unlock(&engine_lock);
  }
  if (0) fprintf(stderr,"sniffer_engine(): trying to exit...\n");
  pthread_mutex_lock(&engine_lock);
  engine_status = 0;
  pthread_cond_broadcast(&engine_dead);
  pthread_mutex_unlock(&engine_lock);
  pthread_exit(&engine);
}

canonical_original_code:
void *sniffer_engine(void *var)
{
  struct SETTINGS *mySettings;
  struct timeval tv_pot_reset;
  struct timeval tv_old;
  struct timeval tv_new;
  float t_diff;
  pthread_mutex_lock(&engine_lock);
  mySettings = (struct SETTINGS *)var;
  gettimeofday(&tv_pot_reset, ((void *)0));
  tv_old = tv_pot_reset;
  engine_status = 1;
  channel_change = 0;
  pthread_cond_broadcast(&engine_ready);
  pthread_mutex_unlock(&engine_lock);
  while (!stop_scanning){
    gettimeofday(&tv_new, ((void *)0));
    t_diff = get_time_diff(&tv_new, &tv_old);
    if (mySettings->scan_mode == 1){
      if (t_diff > 1){
 pthread_mutex_lock(&engine_lock);
 update_all_bandwidth();
 tv_old = tv_new;
 pthread_mutex_unlock(&engine_lock);
      }
      if (mySettings->runtime_mode == 1){
 t_diff = get_time_diff(&tv_new, &tv_pot_reset);
 if (t_diff > 30){
   pthread_mutex_lock(&engine_lock);
   track_bad_data();
   clean_up_bss_nodes();
   clear_potential_structs();
   pthread_mutex_unlock(&engine_lock);
   tv_pot_reset = tv_new;
 }
      }
    }
    if (mySettings->scan_mode == 2){
      if (t_diff > 30){
 update_all_ap_status();
 tv_old = tv_new;
      }
      if (channel_change)
 continue;
    }
    pthread_mutex_lock(&engine_lock);
    if (0) fprintf(stderr,"calling sniff_packet()\n");
    sniff_packet(mySettings);
    if (0) fprintf(stderr,"returned from sniff_packet()\n");
    pthread_mutex_unlock(&engine_lock);
  }
  if (0) fprintf(stderr,"sniffer_engine(): trying to exit...\n");
  pthread_mutex_lock(&engine_lock);
  engine_status = 0;
  pthread_cond_broadcast(&engine_dead);
  pthread_mutex_unlock(&engine_lock);
  pthread_exit(&engine);
}

variable_types:
var
void *

return_type: void *


decompiled_code:
int __fastcall start_sniffer_engine(void *arg)
{
stop_scanning = 0;
pthread_cond_init(&engine_ready, 0LL);
pthread_cond_init(&engine_dead, 0LL);
pthread_mutex_init(&engine_lock, 0LL);
pthread_mutex_lock(&engine_lock);
pthread_create(&engine, 0LL, (void *(*)(void *))sniffer_engine, arg);
pthread_cond_wait(&engine_ready, &engine_lock);
return pthread_mutex_unlock(&engine_lock);
}

canonical_decompiled_code:
int __fastcall func2(void *arg)
{
stop_scanning = 0;
pthread_cond_init(&engine_ready, 0LL);
pthread_cond_init(&engine_dead, 0LL);
pthread_mutex_init(&engine_lock, 0LL);
pthread_mutex_lock(&engine_lock);
pthread_create(&engine, 0LL, (void *(*)(void *))sniffer_engine, arg);
pthread_cond_wait(&engine_ready, &engine_lock);
return pthread_mutex_unlock(&engine_lock);
}

original_code:
void start_sniffer_engine(struct SETTINGS *mySettings)
{
  stop_scanning = 0;
  pthread_cond_init(&engine_ready, ((void *)0));
  pthread_cond_init(&engine_dead, ((void *)0));
  pthread_mutex_init(&engine_lock, ((void *)0));
  pthread_mutex_lock(&engine_lock);
  pthread_create(&engine, ((void *)0), sniffer_engine, (void *)mySettings);
  pthread_cond_wait(&engine_ready, &engine_lock);
  pthread_mutex_unlock(&engine_lock);
}


decompiled_code:
void ask_stop_sniffer_engine()
{
stop_scanning = 1;
}

canonical_decompiled_code:
void func3()
{
stop_scanning = 1;
}


decompiled_code:
int stop_sniffer_engine()
{
pthread_mutex_lock(&engine_lock);
stop_scanning = 1;
pthread_cond_wait(&engine_dead, &engine_lock);
return pthread_mutex_unlock(&engine_lock);
}

canonical_decompiled_code:
int func4()
{
pthread_mutex_lock(&engine_lock);
stop_scanning = 1;
pthread_cond_wait(&engine_dead, &engine_lock);
return pthread_mutex_unlock(&engine_lock);
}

original_code:
void stop_sniffer_engine(struct SETTINGS *mySettings)
{
  pthread_mutex_lock(&engine_lock);
  stop_scanning = 1;
  pthread_cond_wait(&engine_dead, &engine_lock);
  pthread_mutex_unlock(&engine_lock);
}


decompiled_code:
__int64 get_engine_status()
{
return (unsigned int)engine_status;
}

canonical_decompiled_code:
__int64 func5()
{
return (unsigned int)engine_status;
}

original_code:
int get_engine_status()
{
  return (engine_status);
}


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

result = calloc(0x38uLL, 1uLL);
packet = (__int64)result;
if ( !result )
{
perror("malloc: initialize_packet_abstraction()");
exit(-1);
}
return result;
}

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

result = calloc(0x38uLL, 1uLL);
packet = (__int64)result;
if ( !result )
{
perror("malloc: initialize_packet_abstraction()");
exit(-1);
}
return result;
}

original_code:
void initialize_packet_abstraction()
{
  if (((void *)0) == (packet = malloc(sizeof(struct packet_info)))){
    perror("malloc: initialize_packet_abstraction()");
    exit(-1);
  }
  memset(packet, 0, sizeof(struct packet_info));
}

user_defined_types: struct airids_frame_info { unsigned char card_type; unsigned char fcs_error; unsigned char undecrypt; unsigned char channel; unsigned char signal; unsigned long time; }


decompiled_code:
__int64 __fastcall get_packet(int *a1)
{
_OWORD *v1; // rax
int v2; // eax
int v3; // edx
int v4; // ebp
__int64 result; // rax
int v6; // ecx
bool v7; // cc
int v8; // ebx
char *v9; // rdi
bool v10; // zf
_BYTE *v11; // rdi
int v12; // esi
int v13; // edx
__int64 v14; // rcx
int v15; // edx
_BYTE *v16; // rcx
char v17; // si
int v18; // esi
__int64 v19; // [rsp-28h] [rbp-38h] BYREF

memset(msgbuf, 0, sizeof(msgbuf));
v1 = (_OWORD *)packet;
*(_QWORD *)(packet + 48) = 0LL;
*v1 = 0LL;
v1[1] = 0LL;
v1[2] = 0LL;
v2 = pkt_card_sock_read((unsigned int)a1[10], msgbuf, 4096LL, &v19);
if ( v2 <= 0 )
return 0LL;
v3 = a1[9];
v4 = v2;
result = packet;
if ( v3 )
{
*(_BYTE *)(packet + 9) = 1;
*(_DWORD *)result = v4 - 16;
v3 = 16;
*(_QWORD *)(result + 16) = msgbuf;
if ( (msgbuf[0] & 4) != 0 )
{
*(_BYTE *)(result + 8) = 1;
return result;
}
}
else
{
*(_DWORD *)packet = v4;
}
v6 = *a1;
if ( *a1 == 1 )
{
*(_BYTE *)(result + 10) = 1;
v7 = *(_DWORD *)result <= 0x20u;
*(_QWORD *)(result + 24) = &msgbuf[v3];
if ( v7 )
return result;
if ( msgbuf[v3 + 31] || msgbuf[v3 + 30] != 8 )
goto LABEL_10;
v8 = v3 + 32;
v9 = &msgbuf[v3 + 32];
*(_QWORD *)(result + 32) = v9;
goto LABEL_24;
}
if ( v6 == 2 )
{
*(_BYTE *)(result + 10) = 2;
*(_QWORD *)(result + 24) = &msgbuf[v3];
if ( *(_DWORD *)result <= 0x44u )
return result;
*(_DWORD *)result -= 21;
if ( msgbuf[v3 + 66] != 8 || msgbuf[v3 + 67] )
goto LABEL_10;
v8 = v3 + 68;
v9 = &msgbuf[v3 + 68];
*(_QWORD *)(result + 32) = v9;
goto LABEL_24;
}
if ( (unsigned int)(v6 - 3) > 2 )
{
fwrite("card type unsupported!\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
*(_BYTE *)(result + 10) = 3;
*(_QWORD *)(result + 24) = &msgbuf[v3];
if ( *(_DWORD *)result > 0x92u )
{
*(_DWORD *)result -= 144;
if ( msgbuf[v3 + 174] != 8 || msgbuf[v3 + 175] )
{
LABEL_10:
*(_BYTE *)(result + 11) = -1;
return result;
}
v8 = v3 + 176;
v9 = &msgbuf[v3 + 176];
*(_QWORD *)(result + 32) = v9;
LABEL_24:
if ( (*v9 & 0xF0) == 64 )
{
*(_BYTE *)(result + 11) = 1;
v10 = (unsigned int)verify_chksum(0.0) == 0;
result = packet;
if ( v10 )
{
*(_BYTE *)(packet + 8) = 2;
}
else
{
v11 = *(_BYTE **)(packet + 32);
v12 = 4096;
v13 = 4 * (*v11 & 0xF);
v14 = v13;
v15 = v8 + v13;
v16 = &v11[v14];
if ( v4 <= 4096 )
v12 = v4;
*(_QWORD *)(packet + 40) = v16;
if ( v12 < v15 )
{
*(_BYTE *)(result + 8) = 3;
}
else
{
v17 = v11[9];
if ( v17 == 6 )
{
*(_BYTE *)(result + 12) = 1;
v18 = 4 * (v16[12] >> 4);
*(_QWORD *)(result + 48) = &v16[v18];
*(_WORD *)(result + 14) = v4 - (v18 + v15);
}
else if ( v17 == 17 )
{
*(_BYTE *)(result + 12) = 2;
}
else
{
*(_BYTE *)(result + 12) = 4 * (v17 == 1) - 1;
}
}
}
}
else
{
*(_BYTE *)(result + 11) = 3 * ((*v9 & 0xF0) == 96) - 1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(int *a1)
{
_OWORD *v1; // rax
int v2; // eax
int v3; // edx
int v4; // ebp
__int64 result; // rax
int v6; // ecx
bool v7; // cc
int v8; // ebx
char *v9; // rdi
bool v10; // zf
_BYTE *v11; // rdi
int v12; // esi
int v13; // edx
__int64 v14; // rcx
int v15; // edx
_BYTE *v16; // rcx
char v17; // si
int v18; // esi
__int64 v19; // [rsp-28h] [rbp-38h] BYREF

memset(msgbuf, 0, sizeof(msgbuf));
v1 = (_OWORD *)packet;
*(_QWORD *)(packet + 48) = 0LL;
*v1 = 0LL;
v1[1] = 0LL;
v1[2] = 0LL;
v2 = pkt_card_sock_read((unsigned int)a1[10], msgbuf, 4096LL, &v19);
if ( v2 <= 0 )
return 0LL;
v3 = a1[9];
v4 = v2;
result = packet;
if ( v3 )
{
*(_BYTE *)(packet + 9) = 1;
*(_DWORD *)result = v4 - 16;
v3 = 16;
*(_QWORD *)(result + 16) = msgbuf;
if ( (msgbuf[0] & 4) != 0 )
{
*(_BYTE *)(result + 8) = 1;
return result;
}
}
else
{
*(_DWORD *)packet = v4;
}
v6 = *a1;
if ( *a1 == 1 )
{
*(_BYTE *)(result + 10) = 1;
v7 = *(_DWORD *)result <= 0x20u;
*(_QWORD *)(result + 24) = &msgbuf[v3];
if ( v7 )
return result;
if ( msgbuf[v3 + 31] || msgbuf[v3 + 30] != 8 )
goto LABEL_10;
v8 = v3 + 32;
v9 = &msgbuf[v3 + 32];
*(_QWORD *)(result + 32) = v9;
goto LABEL_24;
}
if ( v6 == 2 )
{
*(_BYTE *)(result + 10) = 2;
*(_QWORD *)(result + 24) = &msgbuf[v3];
if ( *(_DWORD *)result <= 0x44u )
return result;
*(_DWORD *)result -= 21;
if ( msgbuf[v3 + 66] != 8 || msgbuf[v3 + 67] )
goto LABEL_10;
v8 = v3 + 68;
v9 = &msgbuf[v3 + 68];
*(_QWORD *)(result + 32) = v9;
goto LABEL_24;
}
if ( (unsigned int)(v6 - 3) > 2 )
{
fwrite("card type unsupported!\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
*(_BYTE *)(result + 10) = 3;
*(_QWORD *)(result + 24) = &msgbuf[v3];
if ( *(_DWORD *)result > 0x92u )
{
*(_DWORD *)result -= 144;
if ( msgbuf[v3 + 174] != 8 || msgbuf[v3 + 175] )
{
LABEL_10:
*(_BYTE *)(result + 11) = -1;
return result;
}
v8 = v3 + 176;
v9 = &msgbuf[v3 + 176];
*(_QWORD *)(result + 32) = v9;
LABEL_24:
if ( (*v9 & 0xF0) == 64 )
{
*(_BYTE *)(result + 11) = 1;
v10 = (unsigned int)verify_chksum(0.0) == 0;
result = packet;
if ( v10 )
{
*(_BYTE *)(packet + 8) = 2;
}
else
{
v11 = *(_BYTE **)(packet + 32);
v12 = 4096;
v13 = 4 * (*v11 & 0xF);
v14 = v13;
v15 = v8 + v13;
v16 = &v11[v14];
if ( v4 <= 4096 )
v12 = v4;
*(_QWORD *)(packet + 40) = v16;
if ( v12 < v15 )
{
*(_BYTE *)(result + 8) = 3;
}
else
{
v17 = v11[9];
if ( v17 == 6 )
{
*(_BYTE *)(result + 12) = 1;
v18 = 4 * (v16[12] >> 4);
*(_QWORD *)(result + 48) = &v16[v18];
*(_WORD *)(result + 14) = v4 - (v18 + v15);
}
else if ( v17 == 17 )
{
*(_BYTE *)(result + 12) = 2;
}
else
{
*(_BYTE *)(result + 12) = 4 * (v17 == 1) - 1;
}
}
}
}
else
{
*(_BYTE *)(result + 11) = 3 * ((*v9 & 0xF0) == 96) - 1;
}
}
return result;
}

original_code:
struct packet_info *get_packet (struct SETTINGS *mySettings)
{
  struct sockaddr_ll ifinfo;
  int wlan_ng_hdr_len = sizeof(wlan_ng_hdr_t);
  int pream_size = sizeof(struct airids_frame_info);
  int wlan_hdr_len = sizeof(wlan_hdr_t);
  int prism2_hdr_len = sizeof(prism2_hdr_t);
  int recvlen = 0;
  int ip_len = 0;
  int tcp_len = 0;
  int offset = 0;
  int total_hlen = 0;
  char proto[2];
  memset(msgbuf, 0, 4096);
  memset(packet, 0, sizeof(struct packet_info));
  recvlen = pkt_card_sock_read(mySettings->sniff_socket, msgbuf, 4096, &ifinfo);
  if (0) fprintf(stderr,"total packet size: %d\n",recvlen);
  if (recvlen < 1){
    return (((void *)0));
  }
  if(mySettings->signal_support){
    packet->driver_proto = 1;
    packet->packet_size = recvlen - pream_size;
    packet->driver_pkt = (struct airids_frame_info *)msgbuf;
    if(packet->driver_pkt->fcs_error){
      packet->error_status = 1;
      return (packet);
    }
    offset = pream_size;
  }
  else{
    packet->packet_size = recvlen;
    offset = 0;
  }
  if(mySettings->card_type == 1){
    packet->mac_proto = 1;
    packet->mac_pkt = (void *) (msgbuf + offset);
    if (packet->packet_size < (wlan_hdr_len + 3)){
      return (packet);
    }
    proto[0] = msgbuf[offset+wlan_hdr_len];
    proto[1] = msgbuf[offset+wlan_hdr_len+1];
  }
  else if(mySettings->card_type == 2){
    packet->mac_proto = 2;
    packet->mac_pkt = (void *) (msgbuf + offset);
    if (packet->packet_size < (prism2_hdr_len + 3)){
      return (packet);
    }
    packet->packet_size -= (sizeof(hfa384x_descript_t)+(sizeof(__u8)*7));
    proto[0] = msgbuf[offset+prism2_hdr_len];
    proto[1] = msgbuf[offset+prism2_hdr_len+1];
  }
  else if((mySettings->card_type==4)||(mySettings->card_type==3)||(mySettings->card_type==5)){
    packet->mac_proto = 3;
    packet->mac_pkt = (void *) (msgbuf + offset);
    if (packet->packet_size < (wlan_ng_hdr_len + 3)){
      return (packet);
    }
    packet->packet_size -= wlan_ng_hdr_len;
    proto[0] = msgbuf[offset+wlan_ng_hdr_len+wlan_hdr_len];
    proto[1] = msgbuf[offset+wlan_ng_hdr_len+wlan_hdr_len+1];
  }
  else{
    fprintf(stderr,"card type unsupported!\n");
    exit(1);
  }
  if ((proto[0] == 8) && (proto[1] == 0)){
    if (mySettings->card_type == 1){
      packet->net_pkt = (void *) (msgbuf + offset + wlan_hdr_len + 2);
      total_hlen += offset + wlan_hdr_len + 2;
    }
    else if (mySettings->card_type == 2){
      packet->net_pkt = (void *) (msgbuf + offset + prism2_hdr_len + 2);
      total_hlen += offset + prism2_hdr_len + 2;
    }
    else if ((mySettings->card_type == 4)||(mySettings->card_type == 3)||(mySettings->card_type == 5)){
      packet->net_pkt = (void *) (msgbuf + offset + wlan_ng_hdr_len + wlan_hdr_len + 2);
      total_hlen += offset + wlan_ng_hdr_len + wlan_hdr_len + 2;
    }
    else{
      fprintf(stderr, "major internal error!");
      exit(1);
    }
    if ( ((struct iphdr *)packet->net_pkt)->version == 4){
      packet->net_proto = 1;
      if (!verify_chksum((struct iphdr *)packet->net_pkt)){
 packet->error_status = 2;
 return (packet);
      }
      ip_len = ((struct iphdr *)packet->net_pkt)->ihl * 4;
      packet->trans_pkt = (void *) (packet->net_pkt + ip_len);
      total_hlen += ip_len;
      if ((total_hlen > 4096)||(total_hlen > recvlen)){
 packet->error_status = 3;
 return (packet);
      }
      if (((struct iphdr *)packet->net_pkt)->protocol == IPPROTO_TCP){
 packet->trans_proto = 1;
 tcp_len = ((struct tcphdr *)packet->trans_pkt)->doff * 4;
 packet->data = (void *) (packet->trans_pkt + tcp_len);
 total_hlen += tcp_len;
 packet->data_size = recvlen - total_hlen;
      }
      else if (((struct iphdr *)packet->net_pkt)->protocol == IPPROTO_UDP){
 packet->trans_proto = 2;
      }
      else if (((struct iphdr *)packet->net_pkt)->protocol == IPPROTO_ICMP){
 packet->trans_proto = 3;
      }
      else{
 packet->trans_proto = -1;
      }
    }
    else if ( ((struct iphdr *)packet->net_pkt)->version == 6){
      packet->net_proto = 2;
    }
    else{
      packet->net_proto = -1;
    }
  }
  else{
    packet->net_proto = -1;
  }
  return(packet);
}

canonical_original_code:
struct packet_info *get_packet(struct SETTINGS *mySettings)
{
  struct sockaddr_ll ifinfo;
  int wlan_ng_hdr_len = sizeof(wlan_ng_hdr_t);
  int pream_size = sizeof(struct airids_frame_info);
  int wlan_hdr_len = sizeof(wlan_hdr_t);
  int prism2_hdr_len = sizeof(prism2_hdr_t);
  int recvlen = 0;
  int ip_len = 0;
  int tcp_len = 0;
  int offset = 0;
  int total_hlen = 0;
  char proto[2];
  memset(msgbuf, 0, 4096);
  memset(packet, 0, sizeof(struct packet_info));
  recvlen = pkt_card_sock_read(mySettings->sniff_socket, msgbuf, 4096, &ifinfo);
  if (0) fprintf(stderr,"total packet size: %d\n",recvlen);
  if (recvlen < 1){
    return (((void *)0));
  }
  if(mySettings->signal_support){
    packet->driver_proto = 1;
    packet->packet_size = recvlen - pream_size;
    packet->driver_pkt = (struct airids_frame_info *)msgbuf;
    if(packet->driver_pkt->fcs_error){
      packet->error_status = 1;
      return (packet);
    }
    offset = pream_size;
  }
  else{
    packet->packet_size = recvlen;
    offset = 0;
  }
  if(mySettings->card_type == 1){
    packet->mac_proto = 1;
    packet->mac_pkt = (void *) (msgbuf + offset);
    if (packet->packet_size < (wlan_hdr_len + 3)){
      return (packet);
    }
    proto[0] = msgbuf[offset+wlan_hdr_len];
    proto[1] = msgbuf[offset+wlan_hdr_len+1];
  }
  else if(mySettings->card_type == 2){
    packet->mac_proto = 2;
    packet->mac_pkt = (void *) (msgbuf + offset);
    if (packet->packet_size < (prism2_hdr_len + 3)){
      return (packet);
    }
    packet->packet_size -= (sizeof(hfa384x_descript_t)+(sizeof(__u8)*7));
    proto[0] = msgbuf[offset+prism2_hdr_len];
    proto[1] = msgbuf[offset+prism2_hdr_len+1];
  }
  else if((mySettings->card_type==4)||(mySettings->card_type==3)||(mySettings->card_type==5)){
    packet->mac_proto = 3;
    packet->mac_pkt = (void *) (msgbuf + offset);
    if (packet->packet_size < (wlan_ng_hdr_len + 3)){
      return (packet);
    }
    packet->packet_size -= wlan_ng_hdr_len;
    proto[0] = msgbuf[offset+wlan_ng_hdr_len+wlan_hdr_len];
    proto[1] = msgbuf[offset+wlan_ng_hdr_len+wlan_hdr_len+1];
  }
  else{
    fprintf(stderr,"card type unsupported!\n");
    exit(1);
  }
  if ((proto[0] == 8) && (proto[1] == 0)){
    if (mySettings->card_type == 1){
      packet->net_pkt = (void *) (msgbuf + offset + wlan_hdr_len + 2);
      total_hlen += offset + wlan_hdr_len + 2;
    }
    else if (mySettings->card_type == 2){
      packet->net_pkt = (void *) (msgbuf + offset + prism2_hdr_len + 2);
      total_hlen += offset + prism2_hdr_len + 2;
    }
    else if ((mySettings->card_type == 4)||(mySettings->card_type == 3)||(mySettings->card_type == 5)){
      packet->net_pkt = (void *) (msgbuf + offset + wlan_ng_hdr_len + wlan_hdr_len + 2);
      total_hlen += offset + wlan_ng_hdr_len + wlan_hdr_len + 2;
    }
    else{
      fprintf(stderr, "major internal error!");
      exit(1);
    }
    if ( ((struct iphdr *)packet->net_pkt)->version == 4){
      packet->net_proto = 1;
      if (!verify_chksum((struct iphdr *)packet->net_pkt)){
 packet->error_status = 2;
 return (packet);
      }
      ip_len = ((struct iphdr *)packet->net_pkt)->ihl * 4;
      packet->trans_pkt = (void *) (packet->net_pkt + ip_len);
      total_hlen += ip_len;
      if ((total_hlen > 4096)||(total_hlen > recvlen)){
 packet->error_status = 3;
 return (packet);
      }
      if (((struct iphdr *)packet->net_pkt)->protocol == IPPROTO_TCP){
 packet->trans_proto = 1;
 tcp_len = ((struct tcphdr *)packet->trans_pkt)->doff * 4;
 packet->data = (void *) (packet->trans_pkt + tcp_len);
 total_hlen += tcp_len;
 packet->data_size = recvlen - total_hlen;
      }
      else if (((struct iphdr *)packet->net_pkt)->protocol == IPPROTO_UDP){
 packet->trans_proto = 2;
      }
      else if (((struct iphdr *)packet->net_pkt)->protocol == IPPROTO_ICMP){
 packet->trans_proto = 3;
      }
      else{
 packet->trans_proto = -1;
      }
    }
    else if ( ((struct iphdr *)packet->net_pkt)->version == 6){
      packet->net_proto = 2;
    }
    else{
      packet->net_proto = -1;
    }
  }
  else{
    packet->net_proto = -1;
  }
  return(packet);
}

variable_types: struct sockaddr_ll { unsigned short sll_family; unsigned short sll_protocol; int sll_ifindex; unsigned short sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; }

variable_types: offset int

variable_types:
proto
char [2]

return_type: struct packet_info { unsigned int packet_size; unsigned int net_pkt_size; unsigned char error_status; unsigned char driver_proto; unsigned char mac_proto; unsigned char net_proto; unsigned char trans_proto; unsigned short data_size; struct airids_frame_info { unsigned char card_type; unsigned char fcs_error; unsigned char undecrypt; unsigned char channel; unsigned char signal; unsigned long time; } *driver_pkt; void *mac_pkt; void *net_pkt; void *trans_pkt; void *data; } *

user_defined_types: struct iphdr { unsigned int ihl; unsigned int version; unsigned char tos; unsigned short tot_len; unsigned short id; unsigned short frag_off; unsigned char ttl; unsigned char protocol; unsigned short check; unsigned int saddr; unsigned int daddr; }

user_defined_types: struct tcphdr { union { struct { unsigned short th_sport; unsigned short th_dport; unsigned int th_seq; unsigned int th_ack; unsigned char th_x2; unsigned char th_off; unsigned char th_flags; unsigned short th_win; unsigned short th_sum; unsigned short th_urp; }; struct { unsigned short source; unsigned short dest; unsigned int seq; unsigned int ack_seq; unsigned short res1; unsigned short doff; unsigned short fin; unsigned short syn; unsigned short rst; unsigned short psh; unsigned short ack; unsigned short urg; unsigned short res2; unsigned short window; unsigned short check; unsigned short urg_ptr; }; }; }


decompiled_code:
int __fastcall write_error(const char *a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

return errbox(a1, "Press a key to continue", v2);
}

canonical_decompiled_code:
int __fastcall func1(const char *a1)
{
int v2[3]; // [rsp+Ch] [rbp-Ch] BYREF

return func0(a1, "Press a key to continue", v2);
}

original_code:
void write_error(char *msg, int daemonized)
{
    int response;
 errbox(msg, "Press a key to continue", &response);
}

variable_types:
msg
char *

variable_types: daemonized int

variable_types: response int