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


repo: saintkepha/airtraf

decompiled_code:
__int64 channel_range()
{
return pkt_card_channel_range();
}

canonical_decompiled_code:
__int64 func12()
{
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; } *

return_type: int


decompiled_code:
__int64 select_channel()
{
return pkt_card_chan_set();
}

canonical_decompiled_code:
__int64 func13()
{
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)
{
unsigned __int8 *v2; // rbx
char *v3; // rbp

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

canonical_decompiled_code:
char *__fastcall func0(unsigned __int8 *a1, int a2)
{
unsigned __int8 *v2; // rbx
char *v3; // rbp

if ( a2 <= 0 )
return dummybuf;
v2 = a1;
v3 = dummybuf;
do
{
sprintf(v3, "%02x", *v2++);
v3 += 2;
}
while ( v2 != &a1[a2 - 1 + 1] );
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

variable_types: i 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

return_type: void

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


decompiled_code:
_BOOL8 __fastcall verify_chksum(__int64 a1)
{
__int64 v1; // rsi
int v2; // ebx

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

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1)
{
__int64 v1; // rsi
int v2; // ebx

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

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; // ebx
unsigned __int16 v3; // r12
unsigned __int16 v4; // r12
unsigned __int16 v5; // bp
int v6; // eax
int optval; // [rsp+Ch] [rbp-7Ch] BYREF
char dest[8]; // [rsp+10h] [rbp-78h] BYREF
__int64 v10; // [rsp+18h] [rbp-70h]
__int64 v11; // [rsp+20h] [rbp-68h]
__int64 v12; // [rsp+28h] [rbp-60h]
__int64 v13; // [rsp+30h] [rbp-58h]
struct sockaddr addr; // [rsp+44h] [rbp-44h] BYREF
int v15; // [rsp+54h] [rbp-34h]
__int64 v16; // [rsp+58h] [rbp-30h]
int v17; // [rsp+60h] [rbp-28h]

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 )
{
v6 = socket(16, 3, 2);
v2 = v6;
if ( v6 < 0 )
{
perror("Could not create socket");
fwrite("You usually have to be root to open raw sockets\n", 1uLL, 0x30uLL, stderr);
exit(0);
}
if ( setsockopt(v6, 1, 2, &optval, 4u) < 0 )
{
perror("Could not set socket options");
exit(0);
}
*(_QWORD *)&addr.sa_family = 16LL;
*(_DWORD *)&addr.sa_data[6] = 0;
*(_DWORD *)&addr.sa_data[2] = getpid();
*(_DWORD *)&addr.sa_data[6] = 1;
if ( bind(v2, &addr, 0xCu) < 0 )
{
perror("bind");
close(v2);
exit(-1);
}
}
else if ( v1 > 2 )
{
if ( (unsigned int)(v1 - 3) > 2 )
{
v2 = 0;
}
else
{
v4 = _bswap_16(3);
v2 = socket(17, 3, v4);
if ( v2 < 0 )
{
perror("Could not create socket");
fwrite("You usually have to be root to open raw sockets\n", 1uLL, 0x30uLL, stderr);
exit(0);
}
*(_QWORD *)dest = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
strcpy(dest, *(const char **)(a1 + 8));
if ( ioctl(v2, 0x8927uLL, dest) )
{
perror("ioctl(SIOCGIFHWADDR)");
close(v2);
exit(-1);
}
v5 = v11;
if ( (unsigned int)(unsigned __int16)v11 - 801 > 1 )
{
close(v2);
fprintf(
stderr,
"Unsupported arptype 0x%04x\nUsually a result of card not being properly set to monitor mode.\n",
v5);
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(v2, 0x8933uLL, dest) < 0 )
{
perror("Could not get index");
close(v2);
fwrite("make sure you specified the proper interface.\n", 1uLL, 0x2EuLL, stderr);
exit(-1);
}
v16 = 0LL;
v17 = 0;
v15 = v11;
*(_WORD *)&addr.sa_data[12] = v4;
*(_WORD *)&addr.sa_data[10] = 17;
if ( bind(v2, (const struct sockaddr *)&addr.sa_data[10], 0x14u) < 0 )
{
perror("Call to bind failed");
exit(0);
}
}
}
else
{
v2 = 0;
if ( v1 == 1 )
{
v3 = _bswap_16(3);
v2 = socket(17, 3, v3);
if ( v2 < 0 )
{
perror("Could not create socket");
fwrite("You usually have to be root to open raw sockets\n", 1uLL, 0x30uLL, stderr);
exit(0);
}
*(_QWORD *)dest = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
strcpy(dest, *(const char **)(a1 + 8));
if ( *(_DWORD *)(a1 + 36) )
{
if ( ioctl(v2, 0x89F3uLL, dest) < 0 )
{
perror("Could not get info");
fwrite("make sure your driver has signal strength capabilities.\n", 1uLL, 0x38uLL, stderr);
exit(0);
}
LOWORD(v11) = 1;
if ( ioctl(v2, 0x89F2uLL, dest) < 0 )
{
perror("Could not set info");
exit(0);
}
}
if ( ioctl(v2, 0x8933uLL, dest) < 0 )
{
perror("Could not get index");
fwrite("make sure you specified the proper interface.\n", 1uLL, 0x2EuLL, stderr);
exit(0);
}
v16 = 0LL;
v17 = 0;
v15 = v11;
*(_WORD *)&addr.sa_data[12] = v3;
*(_WORD *)&addr.sa_data[10] = 17;
if ( bind(v2, (const struct sockaddr *)&addr.sa_data[10], 0x14u) < 0 )
{
perror("Call to bind failed");
exit(0);
}
}
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // eax
int v2; // ebx
unsigned __int16 v3; // r12
unsigned __int16 v4; // r12
unsigned __int16 v5; // bp
int v6; // eax
int optval; // [rsp+Ch] [rbp-7Ch] BYREF
char dest[8]; // [rsp+10h] [rbp-78h] BYREF
__int64 v10; // [rsp+18h] [rbp-70h]
__int64 v11; // [rsp+20h] [rbp-68h]
__int64 v12; // [rsp+28h] [rbp-60h]
__int64 v13; // [rsp+30h] [rbp-58h]
struct sockaddr addr; // [rsp+44h] [rbp-44h] BYREF
int v15; // [rsp+54h] [rbp-34h]
__int64 v16; // [rsp+58h] [rbp-30h]
int v17; // [rsp+60h] [rbp-28h]

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 )
{
v6 = socket(16, 3, 2);
v2 = v6;
if ( v6 < 0 )
{
perror("Could not create socket");
fwrite("You usually have to be root to open raw sockets\n", 1uLL, 0x30uLL, stderr);
exit(0);
}
if ( setsockopt(v6, 1, 2, &optval, 4u) < 0 )
{
perror("Could not set socket options");
exit(0);
}
*(_QWORD *)&addr.sa_family = 16LL;
*(_DWORD *)&addr.sa_data[6] = 0;
*(_DWORD *)&addr.sa_data[2] = getpid();
*(_DWORD *)&addr.sa_data[6] = 1;
if ( bind(v2, &addr, 0xCu) < 0 )
{
perror("bind");
close(v2);
exit(-1);
}
}
else if ( v1 > 2 )
{
if ( (unsigned int)(v1 - 3) > 2 )
{
v2 = 0;
}
else
{
v4 = func0(3);
v2 = socket(17, 3, v4);
if ( v2 < 0 )
{
perror("Could not create socket");
fwrite("You usually have to be root to open raw sockets\n", 1uLL, 0x30uLL, stderr);
exit(0);
}
*(_QWORD *)dest = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
strcpy(dest, *(const char **)(a1 + 8));
if ( ioctl(v2, 0x8927uLL, dest) )
{
perror("ioctl(SIOCGIFHWADDR)");
close(v2);
exit(-1);
}
v5 = v11;
if ( (unsigned int)(unsigned __int16)v11 - 801 > 1 )
{
close(v2);
fprintf(
stderr,
"Unsupported arptype 0x%04x\nUsually a result of card not being properly set to monitor mode.\n",
v5);
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(v2, 0x8933uLL, dest) < 0 )
{
perror("Could not get index");
close(v2);
fwrite("make sure you specified the proper interface.\n", 1uLL, 0x2EuLL, stderr);
exit(-1);
}
v16 = 0LL;
v17 = 0;
v15 = v11;
*(_WORD *)&addr.sa_data[12] = v4;
*(_WORD *)&addr.sa_data[10] = 17;
if ( bind(v2, (const struct sockaddr *)&addr.sa_data[10], 0x14u) < 0 )
{
perror("Call to bind failed");
exit(0);
}
}
}
else
{
v2 = 0;
if ( v1 == 1 )
{
v3 = func0(3);
v2 = socket(17, 3, v3);
if ( v2 < 0 )
{
perror("Could not create socket");
fwrite("You usually have to be root to open raw sockets\n", 1uLL, 0x30uLL, stderr);
exit(0);
}
*(_QWORD *)dest = 0LL;
v10 = 0LL;
v11 = 0LL;
v12 = 0LL;
v13 = 0LL;
strcpy(dest, *(const char **)(a1 + 8));
if ( *(_DWORD *)(a1 + 36) )
{
if ( ioctl(v2, 0x89F3uLL, dest) < 0 )
{
perror("Could not get info");
fwrite("make sure your driver has signal strength capabilities.\n", 1uLL, 0x38uLL, stderr);
exit(0);
}
LOWORD(v11) = 1;
if ( ioctl(v2, 0x89F2uLL, dest) < 0 )
{
perror("Could not set info");
exit(0);
}
}
if ( ioctl(v2, 0x8933uLL, dest) < 0 )
{
perror("Could not get index");
fwrite("make sure you specified the proper interface.\n", 1uLL, 0x2EuLL, stderr);
exit(0);
}
v16 = 0LL;
v17 = 0;
v15 = v11;
*(_WORD *)&addr.sa_data[12] = v3;
*(_WORD *)&addr.sa_data[10] = 17;
if ( bind(v2, (const struct sockaddr *)&addr.sa_data[10], 0x14u) < 0 )
{
perror("Call to bind failed");
exit(0);
}
}
}
return (unsigned int)v2;
}

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 *buf, int a3, struct sockaddr *a4)
{
__int64 v6; // r12
ssize_t result; // rax
struct timeval v8; // [rsp+0h] [rbp-D8h] BYREF
socklen_t addr_len; // [rsp+1Ch] [rbp-BCh] BYREF
fd_set readfds; // [rsp+20h] [rbp-B8h] BYREF

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

canonical_decompiled_code:
ssize_t __fastcall func2(int fd, void *buf, int a3, struct sockaddr *a4)
{
__int64 v6; // r12
ssize_t result; // rax
struct timeval v8; // [rsp+0h] [rbp-D8h] BYREF
socklen_t addr_len; // [rsp+1Ch] [rbp-BCh] BYREF
fd_set readfds; // [rsp+20h] [rbp-B8h] BYREF

memset(&readfds, 0, sizeof(readfds));
v6 = 1LL << (fd % 64);
readfds.fds_bits[fd / 64] |= v6;
v8.tv_sec = 0LL;
v8.tv_usec = 5000LL;
while ( select(fd + 1, &readfds, 0LL, 0LL, &v8) < 0 && *_errno_location() == 4 )
;
result = 0LL;
if ( (readfds.fds_bits[fd / 64] & v6) != 0 )
{
addr_len = 18;
result = recvfrom(fd, buf, 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)
{
int v1; // ebp
__int64 v3[2]; // [rsp+0h] [rbp-48h] BYREF
__int64 v4; // [rsp+10h] [rbp-38h]
__int64 v5; // [rsp+18h] [rbp-30h]
__int64 v6; // [rsp+20h] [rbp-28h]

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

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
int v1; // ebp
__int64 v3[2]; // [rsp+0h] [rbp-48h] BYREF
__int64 v4; // [rsp+10h] [rbp-38h]
__int64 v5; // [rsp+18h] [rbp-30h]
__int64 v6; // [rsp+20h] [rbp-28h]

v1 = *(_DWORD *)(a1 + 40);
v3[0] = 0LL;
v3[1] = 0LL;
v4 = 0LL;
v5 = 0LL;
v6 = 0LL;
strcpy((char *)v3, *(const char **)(a1 + 8));
if ( *(_DWORD *)(a1 + 36) )
{
if ( ioctl(v1, 0x89F3uLL, v3) < 0 )
{
perror("Could not get info");
exit(0);
}
LOWORD(v4) = 0;
if ( ioctl(v1, 0x89F2uLL, v3) < 0 )
{
perror("Could not set info");
exit(0);
}
}
if ( v1 >= 0 )
close(v1);
if ( dummy_sock >= 0 )
close(dummy_sock);
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
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
{
wmove(stdscr, v0, 0);
printw(s, 32LL);
++v0;
}
while ( LINES - 1 > v0 );
}
return wrefresh(stdscr);
}

canonical_decompiled_code:
int func0()
{
int v0; // ebx
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
{
wmove(stdscr, v0, 0);
printw(s, 32LL);
++v0;
}
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()
{
char *v0; // rbp
int v1; // ebx
int v2; // er12

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

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

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

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 v1; // xmm0_4
float v2; // [rsp+Ch] [rbp-3Ch]
struct timeval v3; // [rsp+10h] [rbp-38h] BYREF
__m128i v4; // [rsp+20h] [rbp-28h] BYREF
struct timeval tv; // [rsp+30h] [rbp-18h] BYREF

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

canonical_decompiled_code:
void __fastcall __noreturn func1(void *a1)
{
float v1; // xmm0_4
float v2; // [rsp+Ch] [rbp-3Ch]
struct timeval v3; // [rsp+10h] [rbp-38h] BYREF
__m128i v4; // [rsp+20h] [rbp-28h] BYREF
struct timeval tv; // [rsp+30h] [rbp-18h] BYREF

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

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:
_QWORD *initialize_packet_abstraction()
{
_QWORD *result; // rax

result = malloc(0x38uLL);
packet = (__int64)result;
if ( !result )
{
perror("malloc: initialize_packet_abstraction()");
exit(-1);
}
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
result[6] = 0LL;
return result;
}

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

result = malloc(0x38uLL);
packet = (__int64)result;
if ( !result )
{
perror("malloc: initialize_packet_abstraction()");
exit(-1);
}
*result = 0LL;
result[1] = 0LL;
result[2] = 0LL;
result[3] = 0LL;
result[4] = 0LL;
result[5] = 0LL;
result[6] = 0LL;
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)
{
_QWORD *v1; // rax
int v2; // eax
int v3; // ebp
int v4; // edx
__int64 result; // rax
int v6; // eax
char v7; // cl
char v8; // al
int v9; // eax
int v10; // ebx
char v11; // al
_BYTE *v12; // rdi
int v13; // edx
_BYTE *v14; // rcx
int v15; // edx
int v16; // esi
char v17; // si
int v18; // esi
__int64 v19; // [rsp+0h] [rbp-38h] BYREF

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

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

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

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


original_code:
int in_cksum(u_short * addr, int len)
{
    register int nleft = len;
    register u_short *w = addr;
    register int sum = 0;
    u_short answer = 0;
    while (nleft > 1) {
 sum += *w++;
 nleft -= 2;
    }
    if (nleft == 1) {
 *(u_char *) (&answer) = *(u_char *) w;
 sum += answer;
    }
    sum = (sum >> 16) + (sum & 0xffff);
    sum += (sum >> 16);
    answer = ~sum;
    return (answer);
}

canonical_original_code:
int in_cksum(unsigned short *addr, int len)
{
    register int nleft = len;
    register unsigned short *w = addr;
    register int sum = 0;
    unsigned short answer = 0;
    while (nleft > 1) {
 sum += *w++;
 nleft -= 2;
    }
    if (nleft == 1) {
 *(unsigned char *) (&answer) = *(unsigned char *) w;
 sum += answer;
    }
    sum = (sum >> 16) + (sum & 0xffff);
    sum += (sum >> 16);
    answer = ~sum;
    return (answer);
}

variable_types:
addr
unsigned short *

variable_types: len int

variable_types: nleft int

variable_types:
w
unsigned short *

variable_types: sum int

variable_types:
answer
unsigned short


usage

repo: saintspierres/uv-vis

decompiled_code:
void __noreturn usage()
{
fwrite("usage: uv-vis [options] [inputfile]\n\n", 1uLL, 0x25uLL, stderr);
fwrite(" -i inpfile\n", 1uLL, 0x18uLL, stderr);
fwrite(" -o outfile\n", 1uLL, 0x18uLL, stderr);
fwrite(" --fwhm val set fwhm to val\n", 1uLL, 0x20uLL, stderr);
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
fwrite("usage: uv-vis [options] [inputfile]\n\n", 1uLL, 0x25uLL, stderr);
fwrite(" -i inpfile\n", 1uLL, 0x18uLL, stderr);
fwrite(" -o outfile\n", 1uLL, 0x18uLL, stderr);
fwrite(" --fwhm val set fwhm to val\n", 1uLL, 0x20uLL, stderr);
exit(0);
}

original_code:
void usage()
{
 fprintf(stderr, "usage: uv-vis [options] [inputfile]\n\n");
        fprintf(stderr, "   -i           inpfile\n");
 fprintf(stderr, "   -o           outfile\n");
 fprintf(stderr, "   --fwhm val   set fwhm to val\n");
 exit(0);
}


rcmdl

decompiled_code:
void __fastcall rcmdl(int a1, __int64 a2, char *a3, char *a4, double *a5)
{
__int64 v7; // rbx
int v8; // er13

if ( a1 == 1 )
usage();
if ( a1 == 2 )
{
strcpy(a3, *(const char **)(a2 + 8));
}
else if ( a1 <= 1 )
{
if ( *a3 )
goto LABEL_24;
goto LABEL_23;
}
v7 = 1LL;
v8 = a1 - 1;
do
{
if ( !strcmp(*(const char **)(a2 + 8 * v7), "-h") )
usage();
if ( !strcmp(*(const char **)(a2 + 8 * v7), "-i") )
{
if ( v8 <= (int)v7 )
fwrite("uv-vis: missing argument for -i\n", 1uLL, 0x20uLL, stderr);
else
strcpy(a3, *(const char **)(a2 + 8 * v7 + 8));
}
else if ( !strcmp(*(const char **)(a2 + 8 * v7), "-o") )
{
if ( v8 <= (int)v7 )
fwrite("uv-vis: missing argument for -o\n", 1uLL, 0x20uLL, stderr);
else
strcpy(a4, *(const char **)(a2 + 8 * v7 + 8));
}
else if ( !strcmp(*(const char **)(a2 + 8 * v7), "--fwhm") )
{
if ( v8 <= (int)v7 )
fwrite("uv-vis: missing argument for --fwhm\n", 1uLL, 0x24uLL, stderr);
else
*a5 = (double)atoi(*(const char **)(a2 + 8 * v7 + 8));
}
++v7;
}
while ( a1 > (int)v7 );
LABEL_23:
strcpy(a3, *(const char **)(a2 + 8));
LABEL_24:
if ( !*a4 )
strcpy(a4, "stdout");
}

canonical_decompiled_code:
void __fastcall func1(int a1, __int64 a2, char *a3, char *a4, double *a5)
{
__int64 v7; // rbx
int v8; // er13

if ( a1 == 1 )
func0();
if ( a1 == 2 )
{
strcpy(a3, *(const char **)(a2 + 8));
}
else if ( a1 <= 1 )
{
if ( *a3 )
goto LABEL_24;
goto LABEL_23;
}
v7 = 1LL;
v8 = a1 - 1;
do
{
if ( !strcmp(*(const char **)(a2 + 8 * v7), "-h") )
func0();
if ( !strcmp(*(const char **)(a2 + 8 * v7), "-i") )
{
if ( v8 <= (int)v7 )
fwrite("uv-vis: missing argument for -i\n", 1uLL, 0x20uLL, stderr);
else
strcpy(a3, *(const char **)(a2 + 8 * v7 + 8));
}
else if ( !strcmp(*(const char **)(a2 + 8 * v7), "-o") )
{
if ( v8 <= (int)v7 )
fwrite("uv-vis: missing argument for -o\n", 1uLL, 0x20uLL, stderr);
else
strcpy(a4, *(const char **)(a2 + 8 * v7 + 8));
}
else if ( !strcmp(*(const char **)(a2 + 8 * v7), "--fwhm") )
{
if ( v8 <= (int)v7 )
fwrite("uv-vis: missing argument for --fwhm\n", 1uLL, 0x24uLL, stderr);
else
*a5 = (double)atoi(*(const char **)(a2 + 8 * v7 + 8));
}
++v7;
}
while ( a1 > (int)v7 );
LABEL_23:
strcpy(a3, *(const char **)(a2 + 8));
LABEL_24:
if ( !*a4 )
strcpy(a4, "stdout");
}

original_code:
void rcmdl(int argc, char *argv[], char *inpfile, char *outfile, double *fwhm)
{
    int i;
    if (argc==1)
    {
        usage();
    }
    else if (argc==2)
    {
       strcpy(inpfile, argv[1]);
    }
    for (i=1; i<argc; i++)
    {
        if (!strcmp(argv[i], "-h"))
        {
            usage();
        }
        else if (!strcmp(argv[i], "-i"))
        {
            if (i<argc-1)
            {
                strcpy(inpfile, argv[i+1]);
            }
            else
            {
                fprintf(stderr, "uv-vis: missing argument for -i\n");
            }
        }
        else if (!strcmp(argv[i], "-o"))
        {
            if (i<argc-1)
            {
                strcpy(outfile, argv[i+1]);
            }
            else
            {
                fprintf(stderr, "uv-vis: missing argument for -o\n");
            }
        }
        else if (!strcmp(argv[i], "--fwhm"))
        {
            if (i<argc-1)
            {
                *fwhm=atoi(argv[i+1]);
            }
            else
            {
                fprintf(stderr, "uv-vis: missing argument for --fwhm\n");
            }
        }
    }
    if (inpfile[0] == '\0' || argc>1)
    {
        strcpy(inpfile, argv[1]);
    }
    if (outfile[0] == '\0')
    {
        strcpy(outfile, "stdout");
    }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types:
inpfile
char *

variable_types:
outfile
char *

variable_types:
fwhm
double *

variable_types: i int


gauss

original_code:
double gauss(double x, double mu, double A, double fwhm)
{
    double pi = acos(-1.);
    double pos = 0.;
    double h = 0.;
    fwhm = fwhm / ( 2. * sqrt(2.) ) ;
    pos = ( x - mu ) / fwhm;
    h = A / fwhm / sqrt(pi);
    return h * exp(- pow(pos, 2.) );
}

variable_types: x double

variable_types: mu double

variable_types: A double

variable_types: fwhm double

variable_types: pi double

variable_types: pos double

variable_types: h double

return_type: double


spectrum

original_code:
void spectrum(int *npts, double pts[][3], double xmin, double xmax, double xstp, int ntrans, double trans[][3])
{
    int i, j;
    double evnm = 1241.25;
    double x = 0.;
    double sum = 0.;
    *npts=abs( (xmax - xmin) / xstp ) + 1;
    for (i=0; i<*npts; i++)
    {
        x = xmin + (double)i * xstp;
        sum = 0.;
        for (j=0; j<ntrans; j++)
        {
            sum+=gauss(evnm / x, trans[j][0], trans[j][1], trans[j][2]);
        }
        pts[i][0] = x;
        pts[i][1] = sum;
    }
}

canonical_original_code:
void spectrum(int *npts, double pts[][3], double xmin, double xmax, double xstp, int ntrans, double trans[][3])
{
    int i; int j;
    double evnm = 1241.25;
    double x = 0.;
    double sum = 0.;
    *npts=abs( (xmax - xmin) / xstp ) + 1;
    for (i=0; i<*npts; i++)
    {
        x = xmin + (double)i * xstp;
        sum = 0.;
        for (j=0; j<ntrans; j++)
        {
            sum+=gauss(evnm / x, trans[j][0], trans[j][1], trans[j][2]);
        }
        pts[i][0] = x;
        pts[i][1] = sum;
    }
}

variable_types:
npts
int *

variable_types:
pts
double [][3]

variable_types: xmin double

variable_types: xmax double

variable_types: xstp double

variable_types: ntrans int

variable_types:
trans
double [][3]

variable_types: j int

variable_types: evnm double

variable_types: sum double


main

canonical_name: main

original_code:
int main(int argc, char *argv[])
{
    int i, j;
    int ntrans = 0;
    int npts = 0;
    double fwhm = .5;
    double trans[100][3] = {{0.}};
    double xmin = 190.;
    double xmax = 800.;
    double xstp = 1.;
    double pts[650][3] = {{0.}};
    char inpfile[100] = "";
    char outfile[100] = "";
    rcmdl(argc, argv, inpfile, outfile, &fwhm);
    rgauss(inpfile, &ntrans, trans, fwhm);
    if (ntrans == 0)
    {
        rtrans(inpfile, &ntrans, trans, fwhm);
    }
    printf(" %s: %d transitions\n", inpfile, ntrans);
    for (i=0; i<ntrans; i++)
    {
       printf("%12.6lf%12.6lf%12.6lf\n", trans[i][0], trans[i][1], trans[i][2]);
    }
    spectrum(&npts, pts, xmin, xmax, xstp, ntrans, trans);
    wspec(outfile, npts, pts);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int i; int j;
    int ntrans = 0;
    int npts = 0;
    double fwhm = .5;
    double trans[100][3] = {{0.}};
    double xmin = 190.;
    double xmax = 800.;
    double xstp = 1.;
    double pts[650][3] = {{0.}};
    char inpfile[100] = "";
    char outfile[100] = "";
    rcmdl(argc, argv, inpfile, outfile, &fwhm);
    rgauss(inpfile, &ntrans, trans, fwhm);
    if (ntrans == 0)
    {
        rtrans(inpfile, &ntrans, trans, fwhm);
    }
    printf(" %s: %d transitions\n", inpfile, ntrans);
    for (i=0; i<ntrans; i++)
    {
       printf("%12.6lf%12.6lf%12.6lf\n", trans[i][0], trans[i][1], trans[i][2]);
    }
    spectrum(&npts, pts, xmin, xmax, xstp, ntrans, trans);
    wspec(outfile, npts, pts);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types: npts int

variable_types:
trans
double [100][3]

variable_types:
pts
double [650][3]

variable_types:
inpfile
char [100]

variable_types:
outfile
char [100]


getPrimeMap

original_code:
void getPrimeMap(int *primeMap, int N){
 primeMap[0] = 0;
 primeMap[1] = 0;
 int i;
 for(i=2; i<N; i++)
  primeMap[i] = 1;
 for(i=2; i<N; i++){
  if(primeMap[i]){
   int j=i*2;
   while(j<N){
    primeMap[j] = 0;
    j += i;
   }
  }
 }
}

canonical_original_code:
void getPrimeMap(int *primeMap, int N){
 primeMap[0] = 0;
 primeMap[1] = 0;
 int i;
 for(i=2; i<N; i++)
  primeMap[i] = 1;
 for(i=2; i<N; i++){
  if(primeMap[i]){
   int j = i*2;
   while(j<N){
    primeMap[j] = 0;
    j += i;
   }
  }
 }
}

variable_types:
primeMap
int *

variable_types: N int


getSumMap

original_code:
void getSumMap(int *sumMap1, int *sumMap2){
 int i, ti, digit;
 for(i=0; i<100; i++){
  sumMap1[i] = 0;
  sumMap2[i] = 0;
  ti = i;
  while(ti > 0){
   digit = ti % 10;
   sumMap1[i] += digit;
   sumMap2[i] += digit*digit;
   ti /= 10;
  }
 }
}

canonical_original_code:
void getSumMap(int *sumMap1, int *sumMap2){
 int i; int ti; int digit;
 for(i=0; i<100; i++){
  sumMap1[i] = 0;
  sumMap2[i] = 0;
  ti = i;
  while(ti > 0){
   digit = ti % 10;
   sumMap1[i] += digit;
   sumMap2[i] += digit*digit;
   ti /= 10;
  }
 }
}

variable_types: ti int

variable_types: digit int


getDigitSum

original_code:
void getDigitSum(long long num, int *sum1, int *sum2, int *sumMap1, int *sumMap2){
 *sum1 = 0;
 *sum2 = 0;
 int last = 0;
 while(num > 0){
  last = num % 100;
  *sum1 += sumMap1[last];
  *sum2 += sumMap2[last];
  num /= 100;
 }
}

variable_types:
num
long long

variable_types: last int


getDiffMap

original_code:
void getDiffMap(int *diffMap1, int *diffMap2, int *sumMap1, int *sumMap2){
 int *tmpSum1 = (int*)calloc(100, sizeof(int));
 int *tmpSum2 = (int*)calloc(100, sizeof(int));
 int i, sum1, sum2;
 diffMap1[0] = 0;
 diffMap2[0] = 0;
 for(i=1; i<100; i++){
  getDigitSum(i, &sum1, &sum2, sumMap1, sumMap2);
  tmpSum1[i] = sum1;
  tmpSum2[i] = sum2;
 }
 for(i=1; i<100; i++){
  diffMap1[i] = tmpSum1[i] - tmpSum1[i-1];
  diffMap2[i] = tmpSum2[i] - tmpSum2[i-1];
 }
 free(tmpSum1);
 free(tmpSum2);
}

canonical_original_code:
void getDiffMap(int *diffMap1, int *diffMap2, int *sumMap1, int *sumMap2){
 int *tmpSum1 = (int*)calloc(100, sizeof(int));
 int *tmpSum2 = (int*)calloc(100, sizeof(int));
 int i; int sum1; int sum2;
 diffMap1[0] = 0;
 diffMap2[0] = 0;
 for(i=1; i<100; i++){
  getDigitSum(i, &sum1, &sum2, sumMap1, sumMap2);
  tmpSum1[i] = sum1;
  tmpSum2[i] = sum2;
 }
 for(i=1; i<100; i++){
  diffMap1[i] = tmpSum1[i] - tmpSum1[i-1];
  diffMap2[i] = tmpSum2[i] - tmpSum2[i-1];
 }
 free(tmpSum1);
 free(tmpSum2);
}


main

original_code:
int main(){
 int T;
 scanf("%d", &T);
 int *primeMap = (int*)malloc(1500*sizeof(int));
 getPrimeMap(primeMap, 1500);
 int *sumMap1 = (int*)malloc(100*sizeof(int));
 int *sumMap2 = (int*)malloc(100*sizeof(int));
 int *diffMap1 = (int*)malloc(100*sizeof(int));
 int *diffMap2 = (int*)malloc(100*sizeof(int));
 getSumMap(sumMap1, sumMap2);
 getDiffMap(diffMap1, diffMap2, sumMap1, sumMap2);
 long long A, B, curNum, count;
 int sum1, sum2, curLoop;
 while(T>0){
  scanf("%Ld %Ld", &A, &B);
  count = 0;
  curNum = A;
  while(curNum <= B){
   curLoop = curNum % 100;
   getDigitSum(curNum, &sum1, &sum2, sumMap1, sumMap2);
   if(primeMap[sum1] && primeMap[sum2]){
    count ++;
   }
   curLoop++;
   curNum++;
   while(curNum<=B && curLoop<100){
    sum1 += diffMap1[curLoop];
    sum2 += diffMap2[curLoop];
    if(primeMap[sum1] && primeMap[sum2]){
     count ++;
    }
    curNum++;
    curLoop++;
   }
  }
  printf("%Ld\n", count);
  T--;
 }
 free(primeMap);
 free(sumMap1);
 free(sumMap2);
 free(diffMap1);
 free(diffMap2);
}

canonical_original_code:
int main(){
 int T;
 scanf("%d", &T);
 int *primeMap = (int*)malloc(1500*sizeof(int));
 getPrimeMap(primeMap, 1500);
 int *sumMap1 = (int*)malloc(100*sizeof(int));
 int *sumMap2 = (int*)malloc(100*sizeof(int));
 int *diffMap1 = (int*)malloc(100*sizeof(int));
 int *diffMap2 = (int*)malloc(100*sizeof(int));
 getSumMap(sumMap1, sumMap2);
 getDiffMap(diffMap1, diffMap2, sumMap1, sumMap2);
 long long A; long long B; long long curNum; long long count;
 int sum1; int sum2; int curLoop;
 while(T>0){
  scanf("%Ld %Ld", &A, &B);
  count = 0;
  curNum = A;
  while(curNum <= B){
   curLoop = curNum % 100;
   getDigitSum(curNum, &sum1, &sum2, sumMap1, sumMap2);
   if(primeMap[sum1] && primeMap[sum2]){
    count ++;
   }
   curLoop++;
   curNum++;
   while(curNum<=B && curLoop<100){
    sum1 += diffMap1[curLoop];
    sum2 += diffMap2[curLoop];
    if(primeMap[sum1] && primeMap[sum2]){
     count ++;
    }
    curNum++;
    curLoop++;
   }
  }
  printf("%Ld\n", count);
  T--;
 }
 free(primeMap);
 free(sumMap1);
 free(sumMap2);
 free(diffMap1);
 free(diffMap2);
}

variable_types: T int

variable_types:
A
long long

variable_types:
B
long long

variable_types:
curNum
long long

variable_types:
count
long long

variable_types: curLoop int


getPrimeMap

decompiled_code:
__int64 __fastcall getPrimeMap(int *a1, int a2)
{
__int64 result; // rax
int k; // [rsp+14h] [rbp-8h]
int i; // [rsp+18h] [rbp-4h]
int j; // [rsp+18h] [rbp-4h]

*a1 = 0;
a1[1] = 0;
for ( i = 2; i < a2; ++i )
a1[i] = 1;
for ( j = 2; ; ++j )
{
result = (unsigned int)j;
if ( j >= a2 )
break;
if ( a1[j] )
{
for ( k = 2 * j; k < a2; k += j )
a1[k] = 0;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, int a2)
{
__int64 result; // rax
int k; // [rsp+14h] [rbp-8h]
int i; // [rsp+18h] [rbp-4h]
int j; // [rsp+18h] [rbp-4h]

*a1 = 0;
a1[1] = 0;
for ( i = 2; i < a2; ++i )
a1[i] = 1;
for ( j = 2; ; ++j )
{
result = (unsigned int)j;
if ( j >= a2 )
break;
if ( a1[j] )
{
for ( k = 2 * j; k < a2; k += j )
a1[k] = 0;
}
}
return result;
}

variable_types: i int

variable_types: j int