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

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

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

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


repo: saintkepha/airtraf

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

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

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

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

return_type: void


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

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

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

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

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

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


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

if ( *(_DWORD *)(a1 + 32) == 1 )
{
memset(v4, 0, sizeof(v4));
v3[0] = 0x7254726941202A2ALL;
v3[1] = 0x6576726553206661LL;
v3[2] = 0x6974747568532072LL;
v3[3] = 0x206E776F4420676ELL;
v4[0] = 168438314;
write_log(1LL, v3);
close_log(1LL);
}
if ( *(_DWORD *)(a1 + 60) == 1 )
free_capture();
pkt_card_sock_close(a1);
gettimeofday(&t_end, 0LL);
hour = (LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) / 3600;
v1 = (unsigned int)((LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) / 60 - 60 * hour);
min = v1;
sec = (LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) % 3600 - 60 * v1;
fprintf(
stderr,
"airtraf_end: [info] Elapsed Time: %02d:%02d:%02d\n",
(unsigned int)((LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) / 3600),
v1,
(unsigned int)sec);
return fwrite("airtraf_end: [info] Exiting gracefully...\n\n", 1uLL, 0x2BuLL, stderr);
}

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

if ( *(_DWORD *)(a1 + 32) == 1 )
{
memset(v4, 0, sizeof(v4));
v3[0] = 0x7254726941202A2ALL;
v3[1] = 0x6576726553206661LL;
v3[2] = 0x6974747568532072LL;
v3[3] = 0x206E776F4420676ELL;
v4[0] = 168438314;
write_log(1LL, v3);
close_log(1LL);
}
if ( *(_DWORD *)(a1 + 60) == 1 )
free_capture();
pkt_card_sock_close(a1);
gettimeofday(&t_end, 0LL);
hour = (LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) / 3600;
v1 = (unsigned int)((LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) / 60 - 60 * hour);
min = v1;
sec = (LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) % 3600 - 60 * v1;
fprintf(
stderr,
"airtraf_end: [info] Elapsed Time: %02d:%02d:%02d\n",
(unsigned int)((LODWORD(t_end.tv_sec) - LODWORD(t_start.tv_sec)) / 3600),
v1,
(unsigned int)sec);
return fwrite("airtraf_end: [info] Exiting gracefully...\n\n", 1uLL, 0x2BuLL, stderr);
}

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

variable_types:
logmsg
unsigned char [256]


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

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

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

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

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

variable_types: signo int


usage

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

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

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

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

variable_types:
pname
char *


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


segvhandler

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

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

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

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

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


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

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

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

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


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
int v4; // er13
char *v5; // rbx
int v6; // eax
char *v7; // rbx
char *v8; // rbx
char *v9; // rbx
unsigned int v11; // [rsp+Ch] [rbp-1ACh]
int longind; // [rsp+1Ch] [rbp-19Ch] BYREF
char dest[16]; // [rsp+20h] [rbp-198h] BYREF
char v14[80]; // [rsp+30h] [rbp-188h] BYREF
int v15; // [rsp+80h] [rbp-138h]
char v16[112]; // [rsp+90h] [rbp-128h] BYREF
char v17[124]; // [rsp+100h] [rbp-B8h] BYREF
int v18[15]; // [rsp+17Ch] [rbp-3Ch] BYREF

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

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // r14
int v4; // er13
char *v5; // rbx
int v6; // eax
char *v7; // rbx
char *v8; // rbx
char *v9; // rbx
unsigned int v11; // [rsp+Ch] [rbp-1ACh]
int longind; // [rsp+1Ch] [rbp-19Ch] BYREF
char dest[16]; // [rsp+20h] [rbp-198h] BYREF
char v14[80]; // [rsp+30h] [rbp-188h] BYREF
int v15; // [rsp+80h] [rbp-138h]
char v16[112]; // [rsp+90h] [rbp-128h] BYREF
char v17[124]; // [rsp+100h] [rbp-B8h] BYREF
int v18[15]; // [rsp+17Ch] [rbp-3Ch] BYREF

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

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

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

variable_types: argc int

variable_types:
argv
char **

variable_types: force int

variable_types: override int

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

variable_types:
blah
void *

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

variable_types:
lognamebuf
char [100]

variable_types:
capturebuf
char [100]

variable_types: c int

return_type: int


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

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

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

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

variable_types: ch int


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

if ( a1 == 1 )
{
v4 = fprintf(connect_log, a2);
goto LABEL_6;
}
if ( a1 == 2 )
{
v4 = fprintf(error_log, a2);
LABEL_6:
v2 = 1;
if ( v4 >= 0 )
return v2;
}
fwrite("Could not write to logfile!\n", (size_t)&loc_1, 0x1CuLL, error_log);
return (unsigned int)-1;
}

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

if ( a1 == 1 )
{
v4 = fprintf(connect_log, a2);
goto LABEL_6;
}
if ( a1 == 2 )
{
v4 = fprintf(error_log, a2);
LABEL_6:
v2 = 1;
if ( v4 >= 0 )
return v2;
}
fwrite("Could not write to logfile!\n", (size_t)&loc_1, 0x1CuLL, error_log);
return (unsigned int)-1;
}

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

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

variable_types: type int

variable_types:
text
char *

variable_types: status int


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

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

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

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

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

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


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

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

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

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

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


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

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

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

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

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


decompiled_code:
void *initialize_channel_scan()
{
void *v0; // rax
void *v1; // rdi

v0 = malloc(0x80uLL);
overview = v0;
if ( !v0 )
{
perror("malloc");
exit(-1);
}
memset(v0, 0, 0x80uLL);
v1 = malloc(0x2268uLL);
ap_filter = v1;
if ( !v1 )
{
perror("malloc");
exit(-1);
}
return memset(v1, 0, 0x2268uLL);
}

canonical_decompiled_code:
void *func0()
{
void *v0; // rax
void *v1; // rdi

v0 = malloc(0x80uLL);
overview = v0;
if ( !v0 )
{
perror("malloc");
exit(-1);
}
memset(v0, 0, 0x80uLL);
v1 = malloc(0x2268uLL);
ap_filter = v1;
if ( !v1 )
{
perror("malloc");
exit(-1);
}
return memset(v1, 0, 0x2268uLL);
}

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

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


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

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

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

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

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


decompiled_code:
void free_channel_scan()
{
int i; // ebx
void *v1; // rbp

for ( i = 0; i != 15; ++i )
{
v1 = overview;
reset_ap_list(*((void **)overview + i + 1));
}
free(v1);
free(ap_filter);
overview = 0LL;
ap_filter = 0LL;
}

canonical_decompiled_code:
void func2()
{
int i; // ebx
void *v1; // rbp

for ( i = 0; i != 15; ++i )
{
v1 = overview;
func1(*((void **)overview + i + 1));
}
free(v1);
free(ap_filter);
overview = 0LL;
ap_filter = 0LL;
}

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

variable_types: i int


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

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


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

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

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


decompiled_code:
int __fastcall update_ap_info(__int64 a1, float a2)
{
const void *v2; // r12
_DWORD *v3; // rax
_DWORD *v4; // r13
__int64 v5; // rbx
int v6; // ebx
int v8; // [rsp+14h] [rbp-34h] BYREF
__int16 v9; // [rsp+18h] [rbp-30h]
int s1; // [rsp+1Ah] [rbp-2Eh] BYREF
__int16 v11; // [rsp+1Eh] [rbp-2Ah]

s1 = -1;
v11 = -1;
v8 = 0;
v9 = 0;
v2 = *(const void **)(a1 + 8);
LODWORD(v3) = memcmp(&s1, v2, 6uLL);
if ( (_DWORD)v3 )
{
LODWORD(v3) = memcmp(&v8, v2, 6uLL);
if ( (_DWORD)v3 )
{
LODWORD(v3) = *(unsigned __int8 *)(a1 + 32);
if ( (unsigned __int8)((_BYTE)v3 - 1) <= 0xDu )
{
v4 = overview;
v5 = *((_QWORD *)overview + (unsigned __int8)v3 + 1);
if ( v5 )
{
while ( memcmp((const void *)(v5 + 1), v2, 6uLL) )
{
if ( !*(_QWORD *)(v5 + 80) )
{
LODWORD(v3) = filter_ap(a1);
if ( (_DWORD)v3 )
{
*(_QWORD *)(v5 + 80) = new_access_point(a1, (__m128i)LODWORD(a2));
v3 = overview;
++*(_DWORD *)overview;
++v3[1];
}
return (int)v3;
}
v5 = *(_QWORD *)(v5 + 80);
}
++*(_WORD *)(v5 + 42);
++*(_DWORD *)(v5 + 48);
*(float *)(v5 + 76) = a2;
if ( !strcmp((const char *)(v5 + 7), " ") && strcmp((const char *)(a1 + 33), " ") )
strncpy((char *)(v5 + 7), (const char *)(a1 + 33), 0x20uLL);
LODWORD(v3) = gettimeofday((struct timeval *)(v5 + 56), 0LL);
if ( *(_BYTE *)(v5 + 72) == 5 )
{
*(_BYTE *)(v5 + 72) = 2;
++v4[1];
}
}
else
{
LODWORD(v3) = filter_ap(a1);
if ( (_DWORD)v3 )
{
v6 = *(unsigned __int8 *)(a1 + 32);
*(_QWORD *)&v4[2 * v6 + 2] = new_access_point(a1, (__m128i)LODWORD(a2));
v3 = overview;
++*(_DWORD *)overview;
++v3[1];
}
}
}
}
}
return (int)v3;
}

canonical_decompiled_code:
int __fastcall func5(__int64 a1, float a2)
{
const void *v2; // r12
_DWORD *v3; // rax
_DWORD *v4; // r13
__int64 v5; // rbx
int v6; // ebx
int v8; // [rsp+14h] [rbp-34h] BYREF
__int16 v9; // [rsp+18h] [rbp-30h]
int s1; // [rsp+1Ah] [rbp-2Eh] BYREF
__int16 v11; // [rsp+1Eh] [rbp-2Ah]

s1 = -1;
v11 = -1;
v8 = 0;
v9 = 0;
v2 = *(const void **)(a1 + 8);
LODWORD(v3) = memcmp(&s1, v2, 6uLL);
if ( (_DWORD)v3 )
{
LODWORD(v3) = memcmp(&v8, v2, 6uLL);
if ( (_DWORD)v3 )
{
LODWORD(v3) = *(unsigned __int8 *)(a1 + 32);
if ( (unsigned __int8)((_BYTE)v3 - 1) <= 0xDu )
{
v4 = overview;
v5 = *((_QWORD *)overview + (unsigned __int8)v3 + 1);
if ( v5 )
{
while ( memcmp((const void *)(v5 + 1), v2, 6uLL) )
{
if ( !*(_QWORD *)(v5 + 80) )
{
LODWORD(v3) = func3(a1);
if ( (_DWORD)v3 )
{
*(_QWORD *)(v5 + 80) = new_access_point(a1, (__m128i)LODWORD(a2));
v3 = overview;
++*(_DWORD *)overview;
++v3[1];
}
return (int)v3;
}
v5 = *(_QWORD *)(v5 + 80);
}
++*(_WORD *)(v5 + 42);
++*(_DWORD *)(v5 + 48);
*(float *)(v5 + 76) = a2;
if ( !strcmp((const char *)(v5 + 7), " ") && strcmp((const char *)(a1 + 33), " ") )
strncpy((char *)(v5 + 7), (const char *)(a1 + 33), 0x20uLL);
LODWORD(v3) = gettimeofday((struct timeval *)(v5 + 56), 0LL);
if ( *(_BYTE *)(v5 + 72) == 5 )
{
*(_BYTE *)(v5 + 72) = 2;
++v4[1];
}
}
else
{
LODWORD(v3) = func3(a1);
if ( (_DWORD)v3 )
{
v6 = *(unsigned __int8 *)(a1 + 32);
*(_QWORD *)&v4[2 * v6 + 2] = new_access_point(a1, (__m128i)LODWORD(a2));
v3 = overview;
++*(_DWORD *)overview;
++v3[1];
}
}
}
}
}
return (int)v3;
}

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

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

variable_types: signal float

variable_types:
bcast
unsigned char [6]

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


decompiled_code:
__int64 __fastcall find_access_point(void *s2)
{
__int64 *v1; // r12
char *v2; // r13
__int64 v3; // rbx

v1 = (__int64 *)((char *)overview + 16);
v2 = (char *)overview + 128;
while ( 1 )
{
v3 = *v1;
if ( *v1 )
break;
LABEL_5:
if ( ++v1 == (__int64 *)v2 )
return 0LL;
}
while ( memcmp((const void *)(v3 + 1), s2, 6uLL) )
{
v3 = *(_QWORD *)(v3 + 80);
if ( !v3 )
goto LABEL_5;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(void *s2)
{
__int64 *v1; // r12
char *v2; // r13
__int64 v3; // rbx

v1 = (__int64 *)((char *)overview + 16);
v2 = (char *)overview + 128;
while ( 1 )
{
v3 = *v1;
if ( *v1 )
break;
LABEL_5:
if ( ++v1 == (__int64 *)v2 )
return 0LL;
}
while ( memcmp((const void *)(v3 + 1), s2, 6uLL) )
{
v3 = *(_QWORD *)(v3 + 80);
if ( !v3 )
goto LABEL_5;
}
return v3;
}

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

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

variable_types:
bssid
unsigned char *

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


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

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


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

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

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


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

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

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

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

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

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

user_defined_types: struct hfa384x_descript_t { unsigned short status; unsigned int time; unsigned char silence; unsigned char signal; unsigned char rate; unsigned char rxflow; unsigned int reserved; }

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


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

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

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

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