decompiled_code:
__int64 __fastcall init_config(char *a1, int a2, const char **a3)
{
unsigned int v4; // er12
__int64 result; // rax

memset(a1, 0, 0xD3F0uLL);
while ( 1 )
{
v4 = getopt(a2, (char *const *)a3, "f:dv");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'f':
strcpy(a1 + 4, optarg);
break;
case 'v':
a1[3] = 1;
break;
case 'd':
a1[2] = 1;
break;
default:
printf("usage:%s\n%s\n", *a3, "\t-f\tconfigfile\n\t-d\t[daemon]\n\t-v\t[verbose]\n");
break;
}
}
if ( a1[4] )
{
if ( access(a1 + 4, 4) )
{
printf("access file '%s' failed\n", a1 + 4);
result = v4;
}
else
{
result = 1LL;
}
}
else
{
puts("specify a command with '-c command'");
printf("usage:%s\n%s\n", *a3, "\t-f\tconfigfile\n\t-d\t[daemon]\n\t-v\t[verbose]\n");
result = v4;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *a1, int a2, const char **a3)
{
unsigned int v4; // er12
__int64 result; // rax

memset(a1, 0, 0xD3F0uLL);
while ( 1 )
{
v4 = getopt(a2, (char *const *)a3, "f:dv");
if ( v4 == -1 )
break;
switch ( v4 )
{
case 'f':
strcpy(a1 + 4, optarg);
break;
case 'v':
a1[3] = 1;
break;
case 'd':
a1[2] = 1;
break;
default:
printf("usage:%s\n%s\n", *a3, "\t-f\tconfigfile\n\t-d\t[daemon]\n\t-v\t[verbose]\n");
break;
}
}
if ( a1[4] )
{
if ( access(a1 + 4, 4) )
{
printf("access file '%s' failed\n", a1 + 4);
result = v4;
}
else
{
result = 1LL;
}
}
else
{
puts("specify a command with '-c command'");
printf("usage:%s\n%s\n", *a3, "\t-f\tconfigfile\n\t-d\t[daemon]\n\t-v\t[verbose]\n");
result = v4;
}
return result;
}

original_code:
int init_config (config_t * config, int argc, char* argv[])
{
 int c = 0;
 const char* szuse = "\t-f\tconfigfile\n\t-d\t[daemon]\n\t-v\t[verbose]\n";
 memset (config, 0, sizeof(config_t));
 config->daemon = 0;
 config->verb = 0;
 while ((c = getopt (argc, argv, "f:dv")) != -1)
 {
  switch (c)
  {
   case 'f':
    strcpy(config->conf, optarg);
    break;
   case 'd':
    config->daemon = 1;
    break;
   case 'v':
    config->verb = 1;
    break;
   default:
     printf ("usage:%s\n%s\n", argv[0], szuse);
   break;
  }
 }
 if (!strlen(config->conf))
 {
  printf ("specify a command with '-c command'\n");
  printf ("usage:%s\n%s\n", argv[0], szuse);
  return -1;
 }
 if (access (config->conf, 4))
 {
  printf ("access file '%s' failed\n", config->conf);
  return -1;
 }
 return 1;
}

canonical_original_code:
int init_config(struct config_t *config, int argc, char *argv[])
{
 int c = 0;
 char *szuse = "\t-f\tconfigfile\n\t-d\t[daemon]\n\t-v\t[verbose]\n";
 memset (config, 0, sizeof(config_t));
 config->daemon = 0;
 config->verb = 0;
 while ((c = getopt (argc, argv, "f:dv")) != -1)
 {
  switch (c)
  {
   case 'f':
    strcpy(config->conf, optarg);
    break;
   case 'd':
    config->daemon = 1;
    break;
   case 'v':
    config->verb = 1;
    break;
   default:
     printf ("usage:%s\n%s\n", argv[0], szuse);
   break;
  }
 }
 if (!strlen(config->conf))
 {
  printf ("specify a command with '-c command'\n");
  printf ("usage:%s\n%s\n", argv[0], szuse);
  return -1;
 }
 if (access (config->conf, 4))
 {
  printf ("access file '%s' failed\n", config->conf);
  return -1;
 }
 return 1;
}

variable_types: argc int

variable_types:
szuse
char *


decompiled_code:
char *__fastcall get_time_str(const time_t *a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

if ( a1 )
{
v1 = gmtime(a1);
}
else
{
time(&timer);
v1 = gmtime(&timer);
}
sprintf(
s_0,
"%04d-%02d-%02d %02d:%02d:%02d",
(unsigned int)(v1->tm_year + 1900),
(unsigned int)((v1->tm_mon + 1) % 12),
(unsigned int)v1->tm_mday,
(unsigned int)((v1->tm_hour + 8) % 24),
(unsigned int)v1->tm_min,
(unsigned int)v1->tm_sec);
return s_0;
}

canonical_decompiled_code:
char *__fastcall func6(const time_t *a1)
{
struct tm *v1; // rax
time_t timer; // [rsp+8h] [rbp-10h] BYREF

if ( a1 )
{
v1 = gmtime(a1);
}
else
{
time(&timer);
v1 = gmtime(&timer);
}
sprintf(
s_0,
"%04d-%02d-%02d %02d:%02d:%02d",
(unsigned int)(v1->tm_year + 1900),
(unsigned int)((v1->tm_mon + 1) % 12),
(unsigned int)v1->tm_mday,
(unsigned int)((v1->tm_hour + 8) % 24),
(unsigned int)v1->tm_min,
(unsigned int)v1->tm_sec);
return s_0;
}

original_code:
char* get_time_str(time_t * tm)
{
 struct tm * newtime;
 static char s[32]= {0};
  if(tm == ((void *)0))
 {
  time_t ct;
         time(&ct);
         newtime = gmtime(&ct);
 }else
 {
  newtime = gmtime(tm);
 }
 sprintf( s,"%04d-%02d-%02d %02d:%02d:%02d",
 newtime->tm_year + 1900,
    (newtime->tm_mon + 1)%12,
    newtime->tm_mday,
           (newtime->tm_hour + 8)%24,
    newtime->tm_min, newtime->tm_sec );
  return s;
}

canonical_original_code:
char *get_time_str(long *tm)
{
 struct tm *newtime;
 static char s[32] = {0};
  if(tm == ((void *)0))
 {
  long ct;
         time(&ct);
         newtime = gmtime(&ct);
 }else
 {
  newtime = gmtime(tm);
 }
 sprintf( s,"%04d-%02d-%02d %02d:%02d:%02d",
 newtime->tm_year + 1900,
    (newtime->tm_mon + 1)%12,
    newtime->tm_mday,
           (newtime->tm_hour + 8)%24,
    newtime->tm_min, newtime->tm_sec );
  return s;
}

variable_types:
tm
long *

variable_types: struct tm { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst; long tm_gmtoff; char *tm_zone; } *

variable_types:
s
char [32]

variable_types: ct long

return_type: char *


decompiled_code:
__int64 __fastcall repo_build_func(__int64 a1)
{
__int64 v1; // r13
__int64 v2; // rbp
__int64 v3; // rbx
unsigned int v4; // er14
unsigned int v5; // er15
char *v6; // rax
__int64 result; // rax
__uid_t uid; // [rsp+Ch] [rbp-2CCh] BYREF
struct stat v9; // [rsp+10h] [rbp-2C8h] BYREF
char s[16]; // [rsp+A0h] [rbp-238h] BYREF
char v11[496]; // [rsp+B0h] [rbp-228h] BYREF

v1 = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(a1 + 24);
if ( v1 )
{
do
{
v3 = v1;
sleep(1u);
do
{
if ( *(_QWORD *)(v3 + 528) + *(int *)(v3 + 512) <= time(0LL) || !access((const char *)(v3 + 256), 0) )
{
unlink((const char *)(v3 + 256));
v4 = *(_DWORD *)(a1 + 16);
v5 = *(_DWORD *)(v3 + 512);
v6 = get_time_str(0LL);
printf("%s:time for thread_%03d to update <path=%s,interval=%d>\n", v6, v4, (const char *)v3, v5);
if ( stat((const char *)v3, &v9) )
{
*(_OWORD *)s = 0LL;
memset(v11, 0, sizeof(v11));
sprintf(s, "/bin/mkdir -p %s", v3);
system(s);
}
if ( stat((const char *)v3, &v9) )
{
if ( *(_BYTE *)(v2 + 3) )
printf("stat \x1B[0;32;31m%s\x1B[m failed\n", (const char *)v3);
}
else if ( (v9.st_mode & 0xF000) == 0x4000 )
{
*(_OWORD *)s = 0LL;
memset(v11, 0, sizeof(v11));
if ( (int)get_userid((char *)(v2 + 260), (int *)&uid) <= 0 )
{
puts("get uid failed");
}
else if ( !getuid() && setuid(uid) )
{
puts("getuid and setuid faild");
}
else
{
sprintf(s, "/usr/bin/createrepo -d -p --update -o %s %s", (const char *)v3, (const char *)v3);
printf("Run commad:\x1B[1;33m%s\x1B[m\n", s);
system(s);
}
}
else if ( *(_BYTE *)(v2 + 3) )
{
printf("\x1B[0;32;31m%s\x1B[m is not a directory\n", (const char *)v3);
}
*(_QWORD *)(v3 + 528) = time(0LL);
}
v3 = *(_QWORD *)(v3 + 520);
usleep(0x64u);
}
while ( v3 );
}
while ( *(_DWORD *)(v2 + 54252) );
result = 1LL;
}
else
{
printf("invalid repo list for thread:%d\n", *(unsigned int *)(a1 + 16));
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // r13
__int64 v2; // rbp
__int64 v3; // rbx
unsigned int v4; // er14
unsigned int v5; // er15
char *v6; // rax
__int64 result; // rax
__uid_t uid; // [rsp+Ch] [rbp-2CCh] BYREF
struct stat v9; // [rsp+10h] [rbp-2C8h] BYREF
char s[16]; // [rsp+A0h] [rbp-238h] BYREF
char v11[496]; // [rsp+B0h] [rbp-228h] BYREF

v1 = *(_QWORD *)(a1 + 8);
v2 = *(_QWORD *)(a1 + 24);
if ( v1 )
{
do
{
v3 = v1;
sleep(1u);
do
{
if ( *(_QWORD *)(v3 + 528) + *(int *)(v3 + 512) <= time(0LL) || !access((const char *)(v3 + 256), 0) )
{
unlink((const char *)(v3 + 256));
v4 = *(_DWORD *)(a1 + 16);
v5 = *(_DWORD *)(v3 + 512);
v6 = func6(0LL);
printf("%s:time for thread_%03d to update <path=%s,interval=%d>\n", v6, v4, (const char *)v3, v5);
if ( stat((const char *)v3, &v9) )
{
*(_OWORD *)s = 0LL;
memset(v11, 0, sizeof(v11));
sprintf(s, "/bin/mkdir -p %s", v3);
system(s);
}
if ( stat((const char *)v3, &v9) )
{
if ( *(_BYTE *)(v2 + 3) )
printf("stat \x1B[0;32;31m%s\x1B[m failed\n", (const char *)v3);
}
else if ( (v9.st_mode & 0xF000) == 0x4000 )
{
*(_OWORD *)s = 0LL;
memset(v11, 0, sizeof(v11));
if ( (int)func0((char *)(v2 + 260), (int *)&uid) <= 0 )
{
puts("get uid failed");
}
else if ( !getuid() && setuid(uid) )
{
puts("getuid and setuid faild");
}
else
{
sprintf(s, "/usr/bin/createrepo -d -p --update -o %s %s", (const char *)v3, (const char *)v3);
printf("Run commad:\x1B[1;33m%s\x1B[m\n", s);
system(s);
}
}
else if ( *(_BYTE *)(v2 + 3) )
{
printf("\x1B[0;32;31m%s\x1B[m is not a directory\n", (const char *)v3);
}
*(_QWORD *)(v3 + 528) = time(0LL);
}
v3 = *(_QWORD *)(v3 + 520);
usleep(0x64u);
}
while ( v3 );
}
while ( *(_DWORD *)(v2 + 54252) );
result = 1LL;
}
else
{
printf("invalid repo list for thread:%d\n", *(unsigned int *)(a1 + 16));
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int repo_build_func (void*data)
{
 param_t * pa = (param_t*)data;
 repo_t * pr = ((void *)0);
 config_t * conf = (config_t*)pa->conf;
 if (!pa)
 {
  printf ("%s-%d:invalid parameter data\n", "configserver.c", 136);
  return -1;
 }
 repo_t * rp = (repo_t*)pa->data;
 if (!rp)
 {
  printf ("invalid repo list for thread:%d\n", pa->index);
  return -1;
 }
 do{
  sleep (1);
  pr = rp;
  while (pr)
  {
    time_t ct = time (0);
    if ( (ct >= pr->last_update + pr->intv) || (access(pr->sigfile, 0) == 0))
    {
     struct stat st;
     unlink (pr->sigfile);
     printf ("%s:time for thread_%03d to update <path=%s,interval=%d>\n",
     get_time_str(((void *)0)),
     pa->index, pr->path, pr->intv);
     if (stat(pr->path, &st))
     {
      char cmd[512] = {0};
      sprintf (cmd, "/bin/mkdir -p %s", pr->path);
      system (cmd);
     }
     if (!stat(pr->path, &st))
     {
       if (((((st.st_mode)) & 0170000) == (0040000)))
       {
        char cmd[512] = {0};
        uid_t uid;
        if( get_userid (conf->user, &uid) <= 0)
        {
         printf("get uid failed\n");
        }else
        {
         if (!getuid()&& setuid(uid))
         {
          printf("getuid and setuid faild\n");
         }else
         {
           sprintf (cmd, "/usr/bin/createrepo -d -p --update -o %s %s", pr->path, pr->path);
          printf ("Run commad:""\033[1;33m""%s""\033[m""\n", cmd);
          system(cmd);
         }
        }
       }else
       {
        if(conf->verb)
        printf ("""\033[0;32;31m""%s""\033[m"" is not a directory\n", pr->path);
       }
     }else
     {
      if(conf->verb)
      printf ("stat ""\033[0;32;31m""%s""\033[m"" failed\n", pr->path);
     }
     pr->last_update = time(0);
    }
    pr=pr->next;
    usleep(100);
  }
 }while(conf->loop);
 return 1;
}

canonical_original_code:
int repo_build_func(void *data)
{
 struct param_t *pa = (param_t*)data;
 struct _repo *pr = ((void *)0);
 struct config_t *conf = (config_t*)pa->conf;
 if (!pa)
 {
  printf ("%s-%d:invalid parameter data\n", "configserver.c", 136);
  return -1;
 }
 struct _repo *rp = (repo_t*)pa->data;
 if (!rp)
 {
  printf ("invalid repo list for thread:%d\n", pa->index);
  return -1;
 }
 do{
  sleep (1);
  pr = rp;
  while (pr)
  {
    long ct = time (0);
    if ( (ct >= pr->last_update + pr->intv) || (access(pr->sigfile, 0) == 0))
    {
     struct stat st;
     unlink (pr->sigfile);
     printf ("%s:time for thread_%03d to update <path=%s,interval=%d>\n",
     get_time_str(((void *)0)),
     pa->index, pr->path, pr->intv);
     if (stat(pr->path, &st))
     {
      char cmd[512] = {0};
      sprintf (cmd, "/bin/mkdir -p %s", pr->path);
      system (cmd);
     }
     if (!stat(pr->path, &st))
     {
       if (((((st.st_mode)) & 0170000) == (0040000)))
       {
        char cmd[512] = {0};
        unsigned int uid;
        if( get_userid (conf->user, &uid) <= 0)
        {
         printf("get uid failed\n");
        }else
        {
         if (!getuid()&& setuid(uid))
         {
          printf("getuid and setuid faild\n");
         }else
         {
           sprintf (cmd, "/usr/bin/createrepo -d -p --update -o %s %s", pr->path, pr->path);
          printf ("Run commad:""\033[1;33m""%s""\033[m""\n", cmd);
          system(cmd);
         }
        }
       }else
       {
        if(conf->verb)
        printf ("""\033[0;32;31m""%s""\033[m"" is not a directory\n", pr->path);
       }
     }else
     {
      if(conf->verb)
      printf ("stat ""\033[0;32;31m""%s""\033[m"" failed\n", pr->path);
     }
     pr->last_update = time(0);
    }
    pr=pr->next;
    usleep(100);
  }
 }while(conf->loop);
 return 1;
}

variable_types:
data
void *

variable_types: struct param_t { int (*func)(void *data); void *data; int index; void *conf; } *

variable_types: struct _repo { char path[256]; char sigfile[256]; int intv; void *next; long last_update; } *

variable_types: struct config_t { unsigned short nthread; unsigned char daemon; unsigned char verb; char conf[256]; char user[64]; char basedir[256]; char sigfile[64]; int interval; struct _repo { char path[256]; char sigfile[256]; int intv; void *next; long last_update; } repo_list[100]; int repo_num; int loop; } *

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

variable_types:
cmd
char [512]

variable_types:
uid
unsigned int

return_type: int

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct config_t { unsigned short nthread; unsigned char daemon; unsigned char verb; char conf[256]; char user[64]; char basedir[256]; char sigfile[64]; int interval; struct _repo repo_list[100]; int repo_num; int loop; }


decompiled_code:
__int64 __fastcall load_repo_conf(unsigned __int16 *a1)
{
__int64 v2; // rax
__int64 v3; // r13
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax
const char *v7; // rax
const char *v8; // rax
const char *v9; // rax
int v10; // er12
char *v11; // rbx
unsigned __int16 *v12; // rcx
__int64 v13; // rdi
__int64 v14; // rdx
unsigned __int16 *v15; // rax
int v16; // eax
__int64 result; // rax
const char *v18; // [rsp+0h] [rbp-98B8h]
const char *v19; // [rsp+8h] [rbp-98B0h]
char dest[256]; // [rsp+10h] [rbp-98A8h] BYREF
char s[256]; // [rsp+110h] [rbp-97A8h] BYREF
unsigned int v22; // [rsp+210h] [rbp-96A8h]
__int64 v23; // [rsp+220h] [rbp-9698h]
int v24[32]; // [rsp+230h] [rbp-9688h] BYREF
char nptr; // [rsp+2B0h] [rbp-9608h] BYREF
int v26; // [rsp+9870h] [rbp-48h]

v2 = init_ini(a1 + 2);
if ( v2 )
{
v3 = v2;
v4 = (const char *)read_string(v2, "general", "interval", "600");
*((_DWORD *)a1 + 161) = atoi(v4);
v5 = (const char *)read_string(v3, "general", "thread_num", "10");
*a1 = atoi(v5);
v6 = (const char *)read_string(v3, "general", "loop", "0");
*((_DWORD *)a1 + 13563) = atoi(v6);
v7 = (const char *)read_string(v3, "general", "basedir", "NONE");
v18 = (const char *)(a1 + 162);
strcpy((char *)a1 + 324, v7);
v8 = (const char *)read_string(v3, "general", "signalfile", "update.txt");
v19 = (const char *)(a1 + 290);
strcpy((char *)a1 + 580, v8);
v9 = (const char *)read_string(v3, "general", "user", "root");
strcpy((char *)a1 + 260, v9);
if ( *((_BYTE *)a1 + 3) )
printf(
"repobuilder conf:\n"
"\tinterval = \x1B[1;33m%d\x1B[m\n"
"\tthread_num = \x1B[1;33m%d\x1B[m\n"
"\tsignalfile=\x1B[1;33m%s\x1B[m\n",
*((unsigned int *)a1 + 161),
*a1,
v19);
*((_DWORD *)a1 + 13562) = 0;
LABEL_5:
while ( (unsigned int)read_section(v3, v24) )
{
v22 = *((_DWORD *)a1 + 161);
if ( v24[0] != 1869636978 )
goto LABEL_5;
v10 = 0;
if ( v26 > 0 )
{
v11 = &nptr;
do
{
if ( !strncasecmp(v11 - 64, "path", 4uLL) )
{
if ( !strcmp(v18, "NONE") )
strcpy(dest, v11);
else
sprintf(dest, "%s/%s", v18, v11);
}
else if ( !strncasecmp(v11 - 64, "on", 2uLL) )
{
if ( !atoi(v11) )
{
if ( *((_BYTE *)a1 + 3) )
printf("just ignore \x1B[1;33m'%s'\x1B[m..\n", dest);
goto LABEL_5;
}
}
else if ( !strncasecmp(v11 - 64, "interval", 8uLL) )
{
v16 = atoi(v11);
if ( v16 > 0 )
v22 = v16;
}
++v10;
v11 += 192;
}
while ( v26 > v10 );
}
sprintf(s, "%s/%s", dest, v19);
v12 = &a1[268 * *((int *)a1 + 13562) + 324];
v13 = (__int64)&a1[268 * *((int *)a1 + 13562) + 328];
*(_QWORD *)v12 = *(_QWORD *)dest;
*((_QWORD *)v12 + 66) = v23;
qmemcpy(
(void *)(v13 & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(dest - ((char *)v12 - (v13 & 0xFFFFFFFFFFFFFFF8LL))),
8 * ((unsigned __int64)((unsigned int)v12 - (v13 & 0xFFFFFFF8) + 536) >> 3));
v14 = *((int *)a1 + 13562);
v15 = &a1[268 * v14];
*((_QWORD *)v15 + 146) = 0LL;
*((_QWORD *)v15 + 147) = 0LL;
if ( *((_BYTE *)a1 + 3) )
{
printf(
"load repo conf:\tpath=\t\x1B[1;33m%s\x1B[m\tinterval=\t\x1B[1;33m%d\x1B[m\tsigfile=\x1B[1;33m%s\x1B[m\n",
dest,
v22,
s);
LODWORD(v14) = *((_DWORD *)a1 + 13562);
}
*((_DWORD *)a1 + 13562) = v14 + 1;
}
close_ini(v3);
if ( *((_BYTE *)a1 + 3) )
printf("totally \x1B[1;33m%d\x1B[m repo loaded\n", *((unsigned int *)a1 + 13562));
result = *((unsigned int *)a1 + 13562);
if ( *a1 > (int)result )
*a1 = result;
}
else
{
printf("%s-%d:open file '%s' for reading failed\n", "configserver.c", 301LL, (const char *)a1 + 4);
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int16 *a1)
{
__int64 v2; // rax
__int64 v3; // r13
const char *v4; // rax
const char *v5; // rax
const char *v6; // rax
const char *v7; // rax
const char *v8; // rax
const char *v9; // rax
int v10; // er12
char *v11; // rbx
unsigned __int16 *v12; // rcx
__int64 v13; // rdi
__int64 v14; // rdx
unsigned __int16 *v15; // rax
int v16; // eax
__int64 result; // rax
const char *v18; // [rsp+0h] [rbp-98B8h]
const char *v19; // [rsp+8h] [rbp-98B0h]
char dest[256]; // [rsp+10h] [rbp-98A8h] BYREF
char s[256]; // [rsp+110h] [rbp-97A8h] BYREF
unsigned int v22; // [rsp+210h] [rbp-96A8h]
__int64 v23; // [rsp+220h] [rbp-9698h]
int v24[32]; // [rsp+230h] [rbp-9688h] BYREF
char nptr; // [rsp+2B0h] [rbp-9608h] BYREF
int v26; // [rsp+9870h] [rbp-48h]

v2 = init_ini(a1 + 2);
if ( v2 )
{
v3 = v2;
v4 = (const char *)read_string(v2, "general", "interval", "600");
*((_DWORD *)a1 + 161) = atoi(v4);
v5 = (const char *)read_string(v3, "general", "thread_num", "10");
*a1 = atoi(v5);
v6 = (const char *)read_string(v3, "general", "loop", "0");
*((_DWORD *)a1 + 13563) = atoi(v6);
v7 = (const char *)read_string(v3, "general", "basedir", "NONE");
v18 = (const char *)(a1 + 162);
strcpy((char *)a1 + 324, v7);
v8 = (const char *)read_string(v3, "general", "signalfile", "update.txt");
v19 = (const char *)(a1 + 290);
strcpy((char *)a1 + 580, v8);
v9 = (const char *)read_string(v3, "general", "user", "root");
strcpy((char *)a1 + 260, v9);
if ( *((_BYTE *)a1 + 3) )
printf(
"repobuilder conf:\n"
"\tinterval = \x1B[1;33m%d\x1B[m\n"
"\tthread_num = \x1B[1;33m%d\x1B[m\n"
"\tsignalfile=\x1B[1;33m%s\x1B[m\n",
*((unsigned int *)a1 + 161),
*a1,
v19);
*((_DWORD *)a1 + 13562) = 0;
LABEL_5:
while ( (unsigned int)read_section(v3, v24) )
{
v22 = *((_DWORD *)a1 + 161);
if ( v24[0] != 1869636978 )
goto LABEL_5;
v10 = 0;
if ( v26 > 0 )
{
v11 = &nptr;
do
{
if ( !strncasecmp(v11 - 64, "path", 4uLL) )
{
if ( !strcmp(v18, "NONE") )
strcpy(dest, v11);
else
sprintf(dest, "%s/%s", v18, v11);
}
else if ( !strncasecmp(v11 - 64, "on", 2uLL) )
{
if ( !atoi(v11) )
{
if ( *((_BYTE *)a1 + 3) )
printf("just ignore \x1B[1;33m'%s'\x1B[m..\n", dest);
goto LABEL_5;
}
}
else if ( !strncasecmp(v11 - 64, "interval", 8uLL) )
{
v16 = atoi(v11);
if ( v16 > 0 )
v22 = v16;
}
++v10;
v11 += 192;
}
while ( v26 > v10 );
}
sprintf(s, "%s/%s", dest, v19);
v12 = &a1[268 * *((int *)a1 + 13562) + 324];
v13 = (__int64)&a1[268 * *((int *)a1 + 13562) + 328];
*(_QWORD *)v12 = *(_QWORD *)dest;
*((_QWORD *)v12 + 66) = v23;
qmemcpy(
(void *)(v13 & 0xFFFFFFFFFFFFFFF8LL),
(const void *)(dest - ((char *)v12 - (v13 & 0xFFFFFFFFFFFFFFF8LL))),
8 * ((unsigned __int64)((unsigned int)v12 - (v13 & 0xFFFFFFF8) + 536) >> 3));
v14 = *((int *)a1 + 13562);
v15 = &a1[268 * v14];
*((_QWORD *)v15 + 146) = 0LL;
*((_QWORD *)v15 + 147) = 0LL;
if ( *((_BYTE *)a1 + 3) )
{
printf(
"load repo conf:\tpath=\t\x1B[1;33m%s\x1B[m\tinterval=\t\x1B[1;33m%d\x1B[m\tsigfile=\x1B[1;33m%s\x1B[m\n",
dest,
v22,
s);
LODWORD(v14) = *((_DWORD *)a1 + 13562);
}
*((_DWORD *)a1 + 13562) = v14 + 1;
}
close_ini(v3);
if ( *((_BYTE *)a1 + 3) )
printf("totally \x1B[1;33m%d\x1B[m repo loaded\n", *((unsigned int *)a1 + 13562));
result = *((unsigned int *)a1 + 13562);
if ( *a1 > (int)result )
*a1 = result;
}
else
{
printf("%s-%d:open file '%s' for reading failed\n", "configserver.c", 301LL, (const char *)a1 + 4);
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int load_repo_conf (config_t * conf)
{
 void * ini = ((void *)0);
 section sc;
 if(((void *)0) == (ini = init_ini(conf->conf)))
     {
   printf ("%s-%d:open file '%s' for reading failed\n","configserver.c", 301, conf->conf);
            return -1;
     }
 conf->interval = atoi (read_string(ini, "general", "interval", "600"));
 conf->nthread = atoi (read_string(ini, "general", "thread_num", "10"));
 conf->loop = atoi (read_string(ini, "general", "loop", "0"));
 sprintf (conf->basedir, "%s", read_string(ini, "general", "basedir", "NONE"));
 sprintf (conf->sigfile, "%s", read_string(ini, "general", "signalfile", "update.txt"));
 sprintf (conf->user, "%s", read_string(ini, "general", "user", "root"));
 if (conf->verb)
 {
  printf ("repobuilder conf:\n\tinterval = ""\033[1;33m""%d""\033[m""\n\tthread_num = ""\033[1;33m""%d""\033[m""\n\tsignalfile=""\033[1;33m""%s""\033[m""\n",
  conf->interval, conf->nthread, conf->sigfile);
 }
 conf->repo_num = 0;
 while (read_section(ini, &sc))
    {
        int i = 0;
  repo_t rp;
  int on = 1;
  int valid = 1;
  rp.intv = conf->interval;
  if (strncmp(sc.title, "repo", 4))continue;
        for ( i = 0; i < sc.entry_number; i++)
           {
                  if (strncasecmp(sc.entry_list[i].var_name, "path", 4) == 0)
                    {
       if(strcmp(conf->basedir, "NONE"))
                             sprintf(rp.path, "%s/%s", conf->basedir, sc.entry_list[i].var_value);
       else
        sprintf(rp.path, "%s", sc.entry_list[i].var_value);
                            continue;
                     }
     if (strncasecmp(sc.entry_list[i].var_name, "on", 2) == 0)
                    {
                            on = atoi(sc.entry_list[i].var_value);
       if (!on)
       {
        valid = 0;
        break;
       }
                           continue;
                     }
     if (strncasecmp(sc.entry_list[i].var_name, "interval", 8) == 0)
                    {
       int intv = 0;
                            intv = atoi(sc.entry_list[i].var_value);
       if (intv > 0) rp.intv = intv;
                            continue;
                     }
   }
   if (!valid )
   {
    if (conf->verb) printf ("just ignore ""\033[1;33m""'%s'""\033[m""..\n", rp.path);
    continue;
   }
   sprintf (rp.sigfile, "%s/%s", rp.path, conf->sigfile);
   memcpy (conf->repo_list + conf->repo_num, &rp, sizeof(repo_t));
   conf->repo_list[conf->repo_num].next = ((void *)0);
   conf->repo_list[conf->repo_num].last_update = 0;
      if (conf->verb)
   {
    printf ("load repo conf:\tpath=\t""\033[1;33m""%s""\033[m""\tinterval=\t""\033[1;33m""%d""\033[m""\tsigfile=""\033[1;33m""%s""\033[m""\n",
     rp.path,rp.intv,rp.sigfile);
   }
   conf->repo_num++;
 }
 close_ini (ini);
 if (conf->verb)
 {
  printf ("totally ""\033[1;33m""%d""\033[m"" repo loaded\n", conf->repo_num);
 }
 if (conf->nthread > conf->repo_num) conf->nthread = conf->repo_num;
 return conf->repo_num;
}

canonical_original_code:
int load_repo_conf(struct config_t *conf)
{
 void *ini = ((void *)0);
 struct _section sc;
 if(((void *)0) == (ini = init_ini(conf->conf)))
     {
   printf ("%s-%d:open file '%s' for reading failed\n","configserver.c", 301, conf->conf);
            return -1;
     }
 conf->interval = atoi (read_string(ini, "general", "interval", "600"));
 conf->nthread = atoi (read_string(ini, "general", "thread_num", "10"));
 conf->loop = atoi (read_string(ini, "general", "loop", "0"));
 sprintf (conf->basedir, "%s", read_string(ini, "general", "basedir", "NONE"));
 sprintf (conf->sigfile, "%s", read_string(ini, "general", "signalfile", "update.txt"));
 sprintf (conf->user, "%s", read_string(ini, "general", "user", "root"));
 if (conf->verb)
 {
  printf ("repobuilder conf:\n\tinterval = ""\033[1;33m""%d""\033[m""\n\tthread_num = ""\033[1;33m""%d""\033[m""\n\tsignalfile=""\033[1;33m""%s""\033[m""\n",
  conf->interval, conf->nthread, conf->sigfile);
 }
 conf->repo_num = 0;
 while (read_section(ini, &sc))
    {
        int i = 0;
  struct _repo rp;
  int on = 1;
  int valid = 1;
  rp.intv = conf->interval;
  if (strncmp(sc.title, "repo", 4))continue;
        for ( i = 0; i < sc.entry_number; i++)
           {
                  if (strncasecmp(sc.entry_list[i].var_name, "path", 4) == 0)
                    {
       if(strcmp(conf->basedir, "NONE"))
                             sprintf(rp.path, "%s/%s", conf->basedir, sc.entry_list[i].var_value);
       else
        sprintf(rp.path, "%s", sc.entry_list[i].var_value);
                            continue;
                     }
     if (strncasecmp(sc.entry_list[i].var_name, "on", 2) == 0)
                    {
                            on = atoi(sc.entry_list[i].var_value);
       if (!on)
       {
        valid = 0;
        break;
       }
                           continue;
                     }
     if (strncasecmp(sc.entry_list[i].var_name, "interval", 8) == 0)
                    {
       int intv = 0;
                            intv = atoi(sc.entry_list[i].var_value);
       if (intv > 0) rp.intv = intv;
                            continue;
                     }
   }
   if (!valid )
   {
    if (conf->verb) printf ("just ignore ""\033[1;33m""'%s'""\033[m""..\n", rp.path);
    continue;
   }
   sprintf (rp.sigfile, "%s/%s", rp.path, conf->sigfile);
   memcpy (conf->repo_list + conf->repo_num, &rp, sizeof(repo_t));
   conf->repo_list[conf->repo_num].next = ((void *)0);
   conf->repo_list[conf->repo_num].last_update = 0;
      if (conf->verb)
   {
    printf ("load repo conf:\tpath=\t""\033[1;33m""%s""\033[m""\tinterval=\t""\033[1;33m""%d""\033[m""\tsigfile=""\033[1;33m""%s""\033[m""\n",
     rp.path,rp.intv,rp.sigfile);
   }
   conf->repo_num++;
 }
 close_ini (ini);
 if (conf->verb)
 {
  printf ("totally ""\033[1;33m""%d""\033[m"" repo loaded\n", conf->repo_num);
 }
 if (conf->nthread > conf->repo_num) conf->nthread = conf->repo_num;
 return conf->repo_num;
}

variable_types:
ini
void *

variable_types: struct _section { char title[64]; struct _var_entry { char var_name[64]; char var_value[128]; } entry_list[200]; int entry_number; }

variable_types: i int

variable_types: struct _repo { char path[256]; char sigfile[256]; int intv; void *next; long last_update; }

variable_types: on int

variable_types: valid int

variable_types: intv int

user_defined_types: struct _section { char title[64]; struct _var_entry entry_list[200]; int entry_number; }


decompiled_code:
int __fastcall act_uploadpkg_init(int argc, char **argv, char *a3)
{
char *v3; // r13
int v5; // eax
int result; // eax
const char *v7; // r12
struct stat v8; // [rsp+0h] [rbp-B8h] BYREF

v3 = a3 + 1028;
optind = 1;
while ( 2 )
{
v5 = getopt(argc, argv, "hc:k:f:v:r:a:i:e:m:");
if ( v5 != -1 )
{
switch ( v5 )
{
case 'f':
sprintf(a3 + 132, optarg);
continue;
case 'h':
goto LABEL_5;
case 'i':
sprintf(a3 + 388, optarg);
continue;
case 'm':
sprintf(v3, optarg);
continue;
case 'r':
sprintf(a3 + 260, optarg);
continue;
case 'v':
sprintf(a3 + 324, optarg);
continue;
default:
continue;
}
}
break;
}
if ( a3[132] )
{
if ( a3[260] )
{
if ( a3[324] )
{
if ( a3[388] )
{
v7 = a3 + 132;
result = stat(v7, &v8);
if ( result )
{
printf("can not access file: '%s'\n", v7);
result = 1;
}
}
else
{
puts("instance name is needed");
my_usage_constprop_0_isra_0(*argv);
result = 1;
}
}
else
{
puts("version is needed");
my_usage_constprop_0_isra_0(*argv);
result = 1;
}
}
else
{
puts("repo is needed");
my_usage_constprop_0_isra_0(*argv);
result = 1;
}
}
else
{
puts("uploadpkg file is needed");
LABEL_5:
my_usage_constprop_0_isra_0(*argv);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int argc, char **argv, char *a3)
{
char *v3; // r13
int v5; // eax
int result; // eax
const char *v7; // r12
struct stat v8; // [rsp+0h] [rbp-B8h] BYREF

v3 = a3 + 1028;
optind = 1;
while ( 2 )
{
v5 = getopt(argc, argv, "hc:k:f:v:r:a:i:e:m:");
if ( v5 != -1 )
{
switch ( v5 )
{
case 'f':
sprintf(a3 + 132, optarg);
continue;
case 'h':
goto LABEL_5;
case 'i':
sprintf(a3 + 388, optarg);
continue;
case 'm':
sprintf(v3, optarg);
continue;
case 'r':
sprintf(a3 + 260, optarg);
continue;
case 'v':
sprintf(a3 + 324, optarg);
continue;
default:
continue;
}
}
break;
}
if ( a3[132] )
{
if ( a3[260] )
{
if ( a3[324] )
{
if ( a3[388] )
{
v7 = a3 + 132;
result = stat(v7, &v8);
if ( result )
{
printf("can not access file: '%s'\n", v7);
result = 1;
}
}
else
{
puts("instance name is needed");
func0(*argv);
result = 1;
}
}
else
{
puts("version is needed");
func0(*argv);
result = 1;
}
}
else
{
puts("repo is needed");
func0(*argv);
result = 1;
}
}
else
{
puts("uploadpkg file is needed");
LABEL_5:
func0(*argv);
result = 1;
}
return result;
}

original_code:
int act_uploadpkg_init(int argc, char* argv[], gk_conf_t * gc)
{
 int opt;
 struct stat st;
    char *string = "hc:k:f:v:r:a:i:e:m:";
 optind = 1;
    while ((opt = getopt(argc, argv, string))!= -1)
    {
  switch(opt)
  {
   case 'f':
     sprintf(gc->file, optarg);
     break;
   case 'r':
     sprintf(gc->repo, optarg);
     break;
   case 'v':
     sprintf(gc->osv, optarg);
     break;
   case 'i':
     sprintf(gc->app, optarg);
     break;
   case 'm':
     sprintf(gc->info, optarg);
     break;
   case 'h':
    my_usage(argc, argv);
    return 1;
  }
    }
 if(strlen(gc->file) == 0) {printf("uploadpkg file is needed\n"); my_usage(argc, argv);return 1;}
 if(strlen(gc->repo) == 0) {printf("repo is needed\n"); my_usage(argc, argv);return 1;}
 if(strlen(gc->osv) == 0) {printf("version is needed\n"); my_usage(argc, argv);return 1;}
 if(strlen(gc->app) == 0) {printf("instance name is needed\n"); my_usage(argc, argv);return 1;}
 if(stat(gc->file, &st)) {printf("can not access file: '%s'\n",gc->file);return 1;}
 return 0;
}

canonical_original_code:
int act_uploadpkg_init(int argc, char *argv[], struct _gk_conf_t *gc)
{
 int opt;
 struct stat st;
    char *string = "hc:k:f:v:r:a:i:e:m:";
 optind = 1;
    while ((opt = getopt(argc, argv, string))!= -1)
    {
  switch(opt)
  {
   case 'f':
     sprintf(gc->file, optarg);
     break;
   case 'r':
     sprintf(gc->repo, optarg);
     break;
   case 'v':
     sprintf(gc->osv, optarg);
     break;
   case 'i':
     sprintf(gc->app, optarg);
     break;
   case 'm':
     sprintf(gc->info, optarg);
     break;
   case 'h':
    my_usage(argc, argv);
    return 1;
  }
    }
 if(strlen(gc->file) == 0) {printf("uploadpkg file is needed\n"); my_usage(argc, argv);return 1;}
 if(strlen(gc->repo) == 0) {printf("repo is needed\n"); my_usage(argc, argv);return 1;}
 if(strlen(gc->osv) == 0) {printf("version is needed\n"); my_usage(argc, argv);return 1;}
 if(strlen(gc->app) == 0) {printf("instance name is needed\n"); my_usage(argc, argv);return 1;}
 if(stat(gc->file, &st)) {printf("can not access file: '%s'\n",gc->file);return 1;}
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct _gk_conf_t { enum GK_ACTION { ACT_MIN_ACTION=0, ACT_UPLOAD_PKG=1, ACT_LIST_REPO=2, ACT_LIST_PKG=3, ACT_MAX_ACTION=4 } action; char conf[128]; char file[128]; char repo[64]; char osv[64]; char app[64]; char ak[64]; char as[64]; char uid[64]; char url[128]; char user[64]; char output[64]; char upload_method[64]; char endpoint[64]; char info[512]; } *

variable_types: opt int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }

variable_types:
string
char *

user_defined_types: struct _gk_conf_t { enum GK_ACTION action; char conf[128]; char file[128]; char repo[64]; char osv[64]; char app[64]; char ak[64]; char as[64]; char uid[64]; char url[128]; char user[64]; char output[64]; char upload_method[64]; char endpoint[64]; char info[512]; }


original_code:
int get_nic_list(nic_t *list)
{
 int _sock;
 int nRet = 0;
 int i = 0;
 struct ifreq _ifr;
 struct ifconf _ifc;
 int n;
 struct ifreq *pifr = 0;
 nic_t _device;
 _sock = socket( 2, SOCK_DGRAM, 0 );
 if (_sock <= 0)
 {
  printf ("socket failed\n");
   return -1;
 }
 bzero( &_ifc, sizeof(_ifc) );
 int ret = ioctl( _sock, 0x8912, &_ifc, sizeof(_ifc) );
 if (ret != 0)
 {
  printf ("ioclt SIOCGIFCONF, failed:%d:%d\n", ret, _sock);
   return -1;
 }
 _ifc.ifc_ifcu.ifcu_buf = (char *)malloc( _ifc.ifc_len );
 bzero( _ifc.ifc_ifcu.ifcu_buf, _ifc.ifc_len );
 ret = ioctl( _sock, 0x8912, &_ifc, sizeof(_ifc) );
 if (ret != 0) goto out;
  n = _ifc.ifc_len / sizeof(struct ifreq);
 pifr = (struct ifreq *)_ifc.ifc_ifcu.ifcu_buf;
 for ( i = 0; i < n; ++i, ++pifr )
 {
  if ( pifr->ifr_ifru.ifru_addr.sa_family != 2 ) continue;
  bzero( &_device, sizeof(_device) );
  bzero( &_ifr, sizeof(_ifr) );
  strcpy( _ifr.ifr_ifrn.ifrn_name, pifr->ifr_ifrn.ifrn_name );
  int ret = ioctl( _sock, 0x8927, &_ifr, sizeof(_ifr) );
  if (ret != 0) continue;
  if ( _ifr.ifr_ifru.ifru_hwaddr.sa_family != 1 ) continue;
  memcpy( _device.mac, _ifr.ifr_ifru.ifru_hwaddr.sa_data, 6 );
  ret = ioctl( _sock, 0x8915, &_ifr, sizeof(_ifr) );
  if (ret != 0) continue;
  memcpy( &_device.ip, _ifr.ifr_ifru.ifru_addr.sa_data, 4 );
  _device.ip = ((struct sockaddr_in *)(&_ifr.ifr_ifru.ifru_addr))->sin_addr.s_addr;
  ret = ioctl( _sock, 0x891b, &_ifr, sizeof(_ifr) );
  if (ret != 0) continue;
  _device.netmask = ((struct sockaddr_in *)(&_ifr.ifr_ifru.ifru_netmask))->sin_addr.s_addr;
  strncpy( _device.name, _ifr.ifr_ifrn.ifrn_name, sizeof(_device.name)-1 );
  memcpy (list + nRet, &_device, sizeof(nic_t));
  nRet++;
 }
out:
 free( _ifc.ifc_ifcu.ifcu_buf);
 close(_sock);
 return nRet;
}

canonical_original_code:
int get_nic_list(struct nic_t *list)
{
 int _sock;
 int nRet = 0;
 int i = 0;
 struct ifreq _ifr;
 struct ifconf _ifc;
 int n;
 struct ifreq *pifr = 0;
 struct nic_t _device;
 _sock = socket( 2, SOCK_DGRAM, 0 );
 if (_sock <= 0)
 {
  printf ("socket failed\n");
   return -1;
 }
 bzero( &_ifc, sizeof(_ifc) );
 int ret = ioctl( _sock, 0x8912, &_ifc, sizeof(_ifc) );
 if (ret != 0)
 {
  printf ("ioclt SIOCGIFCONF, failed:%d:%d\n", ret, _sock);
   return -1;
 }
 _ifc.ifc_ifcu.ifcu_buf = (char *)malloc( _ifc.ifc_len );
 bzero( _ifc.ifc_ifcu.ifcu_buf, _ifc.ifc_len );
 ret = ioctl( _sock, 0x8912, &_ifc, sizeof(_ifc) );
 if (ret != 0) goto out;
  n = _ifc.ifc_len / sizeof(struct ifreq);
 pifr = (struct ifreq *)_ifc.ifc_ifcu.ifcu_buf;
 for ( i = 0; i < n; ++i, ++pifr )
 {
  if ( pifr->ifr_ifru.ifru_addr.sa_family != 2 ) continue;
  bzero( &_device, sizeof(_device) );
  bzero( &_ifr, sizeof(_ifr) );
  strcpy( _ifr.ifr_ifrn.ifrn_name, pifr->ifr_ifrn.ifrn_name );
  int ret = ioctl( _sock, 0x8927, &_ifr, sizeof(_ifr) );
  if (ret != 0) continue;
  if ( _ifr.ifr_ifru.ifru_hwaddr.sa_family != 1 ) continue;
  memcpy( _device.mac, _ifr.ifr_ifru.ifru_hwaddr.sa_data, 6 );
  ret = ioctl( _sock, 0x8915, &_ifr, sizeof(_ifr) );
  if (ret != 0) continue;
  memcpy( &_device.ip, _ifr.ifr_ifru.ifru_addr.sa_data, 4 );
  _device.ip = ((struct sockaddr_in *)(&_ifr.ifr_ifru.ifru_addr))->sin_addr.s_addr;
  ret = ioctl( _sock, 0x891b, &_ifr, sizeof(_ifr) );
  if (ret != 0) continue;
  _device.netmask = ((struct sockaddr_in *)(&_ifr.ifr_ifru.ifru_netmask))->sin_addr.s_addr;
  strncpy( _device.name, _ifr.ifr_ifrn.ifrn_name, sizeof(_device.name)-1 );
  memcpy (list + nRet, &_device, sizeof(nic_t));
  nRet++;
 }
out:
 free( _ifc.ifc_ifcu.ifcu_buf);
 close(_sock);
 return nRet;
}

variable_types: struct nic_t { unsigned int ip; unsigned int netmask; unsigned char mac[6]; char name[30]; } *

variable_types: nRet int

variable_types: struct ifconf { int ifc_len; union { char *ifcu_buf; struct ifreq { union { char ifrn_name[16]; } ifr_ifrn; union { struct sockaddr { unsigned short sa_family; char sa_data[14]; } ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; short ifru_flags; int ifru_ivalue; int ifru_mtu; struct ifmap { unsigned long mem_start; unsigned long mem_end; unsigned short base_addr; unsigned char irq; unsigned char dma; unsigned char port; } ifru_map; char ifru_slave[16]; char ifru_newname[16]; char *ifru_data; } ifr_ifru; } *ifcu_req; } ifc_ifcu; }

variable_types: n int

variable_types: ret int

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

user_defined_types: struct ifconf { int ifc_len; union { char *ifcu_buf; struct ifreq *ifcu_req; } ifc_ifcu; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }


decompiled_code:
void __fastcall __noreturn app_thread(void *a1)
{
pthread_t v2; // rax
char v3; // al
void (**v4)(void); // rdi

v2 = pthread_self();
pthread_detach(v2);
v3 = *((_BYTE *)a1 + 48);
LABEL_2:
if ( v3 == 5 )
{
LABEL_9:
*((_BYTE *)a1 + 48) = 6;
pthread_exit(0LL);
}
while ( 1 )
{
if ( v3 != 1 )
{
if ( v3 == 2 )
{
*((_BYTE *)a1 + 48) = 3;
LABEL_11:
v4 = (void (**)(void))*((_QWORD *)a1 + 7);
if ( v4 )
{
if ( *v4 )
(*v4)();
else
printf("error paramter (func,data) for thread %u\n", *((unsigned int *)a1 + 13));
}
else
{
printf("error parameter for thread %u\n", *((unsigned int *)a1 + 13));
}
*((_BYTE *)a1 + 48) = 4;
usleep(0xAu);
v3 = *((_BYTE *)a1 + 48);
goto LABEL_8;
}
if ( v3 == 3 )
goto LABEL_11;
if ( v3 != 4 )
goto LABEL_2;
}
usleep(0xAu);
v3 = *((_BYTE *)a1 + 48);
LABEL_8:
if ( v3 == 5 )
goto LABEL_9;
}
}

canonical_decompiled_code:
void __fastcall __noreturn func0(void *a1)
{
pthread_t v2; // rax
char v3; // al
void (**v4)(void); // rdi

v2 = pthread_self();
pthread_detach(v2);
v3 = *((_BYTE *)a1 + 48);
LABEL_2:
if ( v3 == 5 )
{
LABEL_9:
*((_BYTE *)a1 + 48) = 6;
pthread_exit(0LL);
}
while ( 1 )
{
if ( v3 != 1 )
{
if ( v3 == 2 )
{
*((_BYTE *)a1 + 48) = 3;
LABEL_11:
v4 = (void (**)(void))*((_QWORD *)a1 + 7);
if ( v4 )
{
if ( *v4 )
(*v4)();
else
printf("error paramter (func,data) for thread %u\n", *((unsigned int *)a1 + 13));
}
else
{
printf("error parameter for thread %u\n", *((unsigned int *)a1 + 13));
}
*((_BYTE *)a1 + 48) = 4;
usleep(0xAu);
v3 = *((_BYTE *)a1 + 48);
goto LABEL_8;
}
if ( v3 == 3 )
goto LABEL_11;
if ( v3 != 4 )
goto LABEL_2;
}
usleep(0xAu);
v3 = *((_BYTE *)a1 + 48);
LABEL_8:
if ( v3 == 5 )
goto LABEL_9;
}
}

original_code:
void * app_thread(void*data)
{
 thread_t * pt = (thread_t*)data;
 pthread_detach (pthread_self());
 while (pt->status != status_dead)
 {
  if (pt->status == status_free)
  {
   usleep (10);
   continue;
  }
  if (pt->status == status_ready)
  {
   pt->status = status_running;
   continue;
  }
  if (pt->status == status_running)
  {
   if (!pt->param)
   {
    printf ("error parameter for thread %u\n", pt->index);
    goto OVER;
   }
   if (pt->param->func && pt->param)
   {
    pt->param->func (pt->param);
   }else
   {
    printf ("error paramter (func,data) for thread %u\n",pt->index);
   }
   OVER:
   pt->status = status_over;
   continue;
  }
  if (pt->status == status_over)
  {
   usleep(10);
   continue;
  }
  if (pt->status == status_dead)
  {
   printf ("good luck, i'm now exiting..bye\n");
   break;
  }
 }
 pt->status = status_already_dead;
 pthread_exit (0);
}

canonical_original_code:
void *app_thread(void *data)
{
 struct thread_t *pt = (thread_t*)data;
 pthread_detach (pthread_self());
 while (pt->status != status_dead)
 {
  if (pt->status == status_free)
  {
   usleep (10);
   continue;
  }
  if (pt->status == status_ready)
  {
   pt->status = status_running;
   continue;
  }
  if (pt->status == status_running)
  {
   if (!pt->param)
   {
    printf ("error parameter for thread %u\n", pt->index);
    goto OVER;
   }
   if (pt->param->func && pt->param)
   {
    pt->param->func (pt->param);
   }else
   {
    printf ("error paramter (func,data) for thread %u\n",pt->index);
   }
   OVER:
   pt->status = status_over;
   continue;
  }
  if (pt->status == status_over)
  {
   usleep(10);
   continue;
  }
  if (pt->status == status_dead)
  {
   printf ("good luck, i'm now exiting..bye\n");
   break;
  }
 }
 pt->status = status_already_dead;
 pthread_exit (0);
}

variable_types:
data
void *

variable_types: struct thread_t { unsigned long thread; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned char status; unsigned int index; struct param_t { int (*func)(void *data); void *data; int index; void *conf; } *param; } *

return_type: void *

user_defined_types: struct thread_t { unsigned long thread; union pthread_mutex_t mutex; unsigned char status; unsigned int index; struct param_t *param; }

user_defined_types: union pthread_mutex_t { struct __pthread_mutex_s __data; char __size[40]; long __align; }

user_defined_types: struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list __list; }


decompiled_code:
__int64 __fastcall init_thread_slot(void *arg, __int64 a2)
{
char *v2; // rbx
unsigned int v3; // ebp

if ( !arg )
{
printf("error thread_pool pointer, program bug!!!");
exit(0);
}
if ( (unsigned int)(*((_DWORD *)arg + 1600) - 1) > 0x63 )
{
puts("error thread number, default value is used");
*((_DWORD *)arg + 1600) = 99;
}
v2 = (char *)arg;
v3 = 0;
while ( 1 )
{
v2[48] = 1;
*((_DWORD *)v2 + 13) = v3;
*((_QWORD *)v2 + 7) = 0LL;
if ( pthread_mutex_init((pthread_mutex_t *)(v2 + 8), 0LL) )
{
printf("pthread_mutex_init for thread_%u failed\n", v3);
return 0xFFFFFFFFLL;
}
if ( pthread_create((pthread_t *)v2, 0LL, (void *(*)(void *))app_thread, v2) )
break;
++v3;
if ( *(_BYTE *)(a2 + 3) )
{
v2 += 64;
printf("create thread \x1B[0;32;32m%03d\x1B[m success\n", v3);
if ( *((_DWORD *)arg + 1600) <= v3 )
return 1LL;
}
else
{
v2 += 64;
if ( *((_DWORD *)arg + 1600) <= v3 )
return 1LL;
}
}
printf("create thread for thread %u failed\n", v3);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func1(void *arg, __int64 a2)
{
char *v2; // rbx
unsigned int v3; // ebp

if ( !arg )
{
printf("error thread_pool pointer, program bug!!!");
exit(0);
}
if ( (unsigned int)(*((_DWORD *)arg + 1600) - 1) > 0x63 )
{
puts("error thread number, default value is used");
*((_DWORD *)arg + 1600) = 99;
}
v2 = (char *)arg;
v3 = 0;
while ( 1 )
{
v2[48] = 1;
*((_DWORD *)v2 + 13) = v3;
*((_QWORD *)v2 + 7) = 0LL;
if ( pthread_mutex_init((pthread_mutex_t *)(v2 + 8), 0LL) )
{
printf("pthread_mutex_init for thread_%u failed\n", v3);
return 0xFFFFFFFFLL;
}
if ( pthread_create((pthread_t *)v2, 0LL, (void *(*)(void *))app_thread, v2) )
break;
++v3;
if ( *(_BYTE *)(a2 + 3) )
{
v2 += 64;
printf("create thread \x1B[0;32;32m%03d\x1B[m success\n", v3);
if ( *((_DWORD *)arg + 1600) <= v3 )
return 1LL;
}
else
{
v2 += 64;
if ( *((_DWORD *)arg + 1600) <= v3 )
return 1LL;
}
}
printf("create thread for thread %u failed\n", v3);
return 0xFFFFFFFFLL;
}

original_code:
int init_thread_slot(thread_pool_t * pp, const config_t * conf)
{
 unsigned int index = 0;
 if (!pp)
 {
  printf ("error thread_pool pointer, program bug!!!");
  exit (0);
 }
 if ((pp->thread_num <=0) || (pp->thread_num > 100))
 {
  printf ("error thread number, default value is used\n");
  pp->thread_num = 100 - 1;
 }
 for ( index = 0; index < pp->thread_num; index++)
 {
  pp->thread_list[index].status = status_free;
  pp->thread_list[index].index = index;
  pp->thread_list[index].param = 0;
  if(pthread_mutex_init (&(pp->thread_list[index].mutex), 0))
  {
   printf ("pthread_mutex_init for thread_%u failed\n", index);
   return -1;
  }
  if (pthread_create (
   &(pp->thread_list[index].thread),
   0,
   app_thread,
   pp->thread_list + index))
  {
   printf ("create thread for thread %u failed\n", index);
   return -1;
  }else
  {
   if (conf->verb)
   printf ("create thread ""\033[0;32;32m""%03d""\033[m"" success\n", index + 1);
  }
 }
 return 1;
}

canonical_original_code:
int init_thread_slot(struct thread_pool_t *pp, struct config_t *conf)
{
 unsigned int index = 0;
 if (!pp)
 {
  printf ("error thread_pool pointer, program bug!!!");
  exit (0);
 }
 if ((pp->thread_num <=0) || (pp->thread_num > 100))
 {
  printf ("error thread number, default value is used\n");
  pp->thread_num = 100 - 1;
 }
 for ( index = 0; index < pp->thread_num; index++)
 {
  pp->thread_list[index].status = status_free;
  pp->thread_list[index].index = index;
  pp->thread_list[index].param = 0;
  if(pthread_mutex_init (&(pp->thread_list[index].mutex), 0))
  {
   printf ("pthread_mutex_init for thread_%u failed\n", index);
   return -1;
  }
  if (pthread_create (
   &(pp->thread_list[index].thread),
   0,
   app_thread,
   pp->thread_list + index))
  {
   printf ("create thread for thread %u failed\n", index);
   return -1;
  }else
  {
   if (conf->verb)
   printf ("create thread ""\033[0;32;32m""%03d""\033[m"" success\n", index + 1);
  }
 }
 return 1;
}

variable_types: struct thread_pool_t { struct thread_t { unsigned long thread; union pthread_mutex_t { struct __pthread_mutex_s { int __lock; unsigned int __count; int __owner; unsigned int __nusers; int __kind; short __spins; short __elision; struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; } __list; } __data; char __size[40]; long __align; } mutex; unsigned char status; unsigned int index; struct param_t { int (*func)(void *data); void *data; int index; void *conf; } *param; } thread_list[100]; unsigned int thread_num; } *

variable_types: struct config_t { unsigned short nthread; unsigned char daemon; unsigned char verb; char conf[256]; char user[64]; char basedir[256]; char sigfile[64]; int interval; struct _repo { char path[256]; char sigfile[256]; int intv; void *next; long last_update; } repo_list[100]; int repo_num; int loop; } *

variable_types:
index
unsigned int

user_defined_types: struct thread_pool_t { struct thread_t thread_list[100]; unsigned int thread_num; }


decompiled_code:
__int64 __fastcall run_over(__int64 a1)
{
int v1; // edx
_BYTE *v2; // rax
unsigned __int64 v3; // rdx

v1 = *(_DWORD *)(a1 + 6400);
if ( !v1 )
return 1LL;
v2 = (_BYTE *)(a1 + 48);
v3 = a1 + ((unsigned __int64)(unsigned int)(v1 - 1) << 6) + 112;
while ( *v2 == 4 )
{
v2 += 64;
if ( v2 == (_BYTE *)v3 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
int v1; // edx
_BYTE *v2; // rax
unsigned __int64 v3; // rdx

v1 = *(_DWORD *)(a1 + 6400);
if ( !v1 )
return 1LL;
v2 = (_BYTE *)(a1 + 48);
v3 = a1 + ((unsigned __int64)(unsigned int)(v1 - 1) << 6) + 112;
while ( *v2 == 4 )
{
v2 += 64;
if ( v2 == (_BYTE *)v3 )
return 1LL;
}
return 0LL;
}

original_code:
unsigned char run_over(thread_pool_t * pool)
{
 unsigned char bRet = 1;
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  if (pool->thread_list[index].status != status_over)
  {
   bRet = 0;
   break;
  }
 }
 return bRet;
}

canonical_original_code:
unsigned char run_over(struct thread_pool_t *pool)
{
 unsigned char bRet = 1;
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  if (pool->thread_list[index].status != status_over)
  {
   bRet = 0;
   break;
  }
 }
 return bRet;
}

variable_types:
bRet
unsigned char

return_type: unsigned char

user_defined_types: struct param_t { int (*func)(void *data); void *data; int index; void *conf; }

user_defined_types: struct __pthread_internal_list { struct __pthread_internal_list *__prev; struct __pthread_internal_list *__next; }


original_code:
int reset_thread (thread_pool_t * pool)
{
 int nRet = 0;
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  if (pool->thread_list[index].status == status_over)
  {
   pool->thread_list[index].status = status_free;
   pool->thread_list[index].param = 0;
   nRet++;
  }
 }
 return nRet;
}

canonical_original_code:
int reset_thread(struct thread_pool_t *pool)
{
 int nRet = 0;
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  if (pool->thread_list[index].status == status_over)
  {
   pool->thread_list[index].status = status_free;
   pool->thread_list[index].param = 0;
   nRet++;
  }
 }
 return nRet;
}


decompiled_code:
__int64 __fastcall terminate_thread(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // er12
time_t v3; // rax
time_t v4; // rbp

if ( !*(_DWORD *)(a1 + 6400) )
return 0LL;
v1 = a1 + 48;
v2 = 0;
do
{
v3 = time(0LL);
*(_BYTE *)v1 = 5;
v4 = v3;
while ( 1 )
{
usleep(0xAu);
if ( time(0LL) - v4 > 4 )
break;
if ( *(_BYTE *)v1 == 6 )
goto LABEL_6;
}
printf("waitting for thread_%u to exit timeout\n", *(unsigned int *)(v1 + 4));
LABEL_6:
++v2;
v1 += 64LL;
}
while ( *(_DWORD *)(a1 + 6400) > v2 );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
__int64 v1; // rbx
unsigned int v2; // er12
time_t v3; // rax
time_t v4; // rbp

if ( !*(_DWORD *)(a1 + 6400) )
return 0LL;
v1 = a1 + 48;
v2 = 0;
do
{
v3 = time(0LL);
*(_BYTE *)v1 = 5;
v4 = v3;
while ( 1 )
{
usleep(0xAu);
if ( time(0LL) - v4 > 4 )
break;
if ( *(_BYTE *)v1 == 6 )
goto LABEL_6;
}
printf("waitting for thread_%u to exit timeout\n", *(unsigned int *)(v1 + 4));
LABEL_6:
++v2;
v1 += 64LL;
}
while ( *(_DWORD *)(a1 + 6400) > v2 );
return v2;
}

original_code:
int terminate_thread (thread_pool_t * pool)
{
 int nRet = 0;
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  time_t start = time (0);
  pool->thread_list[index].status = status_dead;
  while (pool->thread_list[index].status != status_already_dead)
  {
   usleep (10);
   if (time(0) - start >= 5)
   {
    printf ("waitting for thread_%u to exit timeout\n",
    pool->thread_list[index].index);
    break;
   }
  }
  nRet++;
 }
 return nRet;
}

canonical_original_code:
int terminate_thread(struct thread_pool_t *pool)
{
 int nRet = 0;
 unsigned int index = 0;
 for (index = 0; index < pool->thread_num; index++)
 {
  long start = time (0);
  pool->thread_list[index].status = status_dead;
  while (pool->thread_list[index].status != status_already_dead)
  {
   usleep (10);
   if (time(0) - start >= 5)
   {
    printf ("waitting for thread_%u to exit timeout\n",
    pool->thread_list[index].index);
    break;
   }
  }
  nRet++;
 }
 return nRet;
}

variable_types: start long


daemon

decompiled_code:
__int64 __fastcall daemon(int a1, int a2)
{
__pid_t v2; // eax
unsigned int v3; // er12
int v5; // eax
int v6; // ebp

v2 = fork();
if ( v2 < 0 )
{
v3 = -1;
perror("fork");
return v3;
}
if ( v2 )
exit(0);
v3 = 0;
if ( setsid() < -1 )
{
v3 = -1;
perror("setsid");
return v3;
}
if ( !a1 )
{
chdir("/");
if ( a2 )
goto LABEL_6;
LABEL_10:
v5 = open("/dev/null", 2, 0LL);
v6 = v5;
if ( v5 != -1 )
{
dup2(v5, 0);
dup2(v6, 1);
dup2(v6, 2);
close(v6);
}
goto LABEL_6;
}
if ( !a2 )
goto LABEL_10;
LABEL_6:
umask(0x17u);
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1, int a2)
{
__pid_t v2; // eax
unsigned int v3; // er12
int v5; // eax
int v6; // ebp

v2 = fork();
if ( v2 < 0 )
{
v3 = -1;
perror("fork");
return v3;
}
if ( v2 )
exit(0);
v3 = 0;
if ( setsid() < -1 )
{
v3 = -1;
perror("setsid");
return v3;
}
if ( !a1 )
{
chdir("/");
if ( a2 )
goto LABEL_6;
LABEL_10:
v5 = open("/dev/null", 2, 0LL);
v6 = v5;
if ( v5 != -1 )
{
dup2(v5, 0);
dup2(v6, 1);
dup2(v6, 2);
close(v6);
}
goto LABEL_6;
}
if ( !a2 )
goto LABEL_10;
LABEL_6:
umask(0x17u);
return v3;
}

original_code:
int daemon (int nochdir, int noclose)
{
  pid_t pid;
  pid = fork ();
  if (pid < 0)
    {
      perror ("fork");
      return -1;
    }
  if (pid != 0)
    exit (0);
  pid = setsid();
  if (pid < -1)
    {
      perror ("setsid");
      return -1;
    }
  if (! nochdir)
    chdir ("/");
  if (! noclose)
    {
      int fd;
      fd = open ("/dev/null", 02, 0);
      if (fd != -1)
    {
      dup2 (fd, 0);
      dup2 (fd, 1);
      dup2 (fd, 2);
      close(fd);
    }
    }
  umask (0027);
  return 0;
}

canonical_original_code:
int daemon(int nochdir, int noclose)
{
  int pid;
  pid = fork ();
  if (pid < 0)
    {
      perror ("fork");
      return -1;
    }
  if (pid != 0)
    exit (0);
  pid = setsid();
  if (pid < -1)
    {
      perror ("setsid");
      return -1;
    }
  if (! nochdir)
    chdir ("/");
  if (! noclose)
    {
      int fd;
      fd = open ("/dev/null", 02, 0);
      if (fd != -1)
    {
      dup2 (fd, 0);
      dup2 (fd, 1);
      dup2 (fd, 2);
      close(fd);
    }
    }
  umask (0027);
  return 0;
}

variable_types: nochdir int

variable_types: noclose int

variable_types: pid int

variable_types: fd int


decompiled_code:
int __fastcall act_listpkg_init(int argc, char **argv, __int64 a3)
{
char *v3; // r13
int v5; // eax
int result; // eax
const char *v7; // r12
struct stat v8; // [rsp+0h] [rbp-B8h] BYREF

v3 = (char *)(a3 + 260);
optind = 1;
while ( 1 )
{
v5 = getopt(argc, argv, "hc:k:u:r:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'r':
sprintf(v3, optarg);
break;
case 'u':
if ( (*optarg != 109 || optarg[1] != 101 || optarg[2]) && strcmp(optarg, "any") )
{
LABEL_6:
my_usage_constprop_0_isra_0(*argv);
return 1;
}
sprintf((char *)(a3 + 772), optarg);
break;
case 'h':
goto LABEL_6;
}
}
if ( !*(_BYTE *)(a3 + 772) )
*(_DWORD *)(a3 + 772) = 7958113;
if ( !*(_BYTE *)(a3 + 260) )
*(_DWORD *)(a3 + 260) = 7958113;
v7 = (const char *)(a3 + 4);
result = stat(v7, &v8);
if ( result )
{
printf("can not access file: '%s'\n", v7);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int argc, char **argv, __int64 a3)
{
char *v3; // r13
int v5; // eax
int result; // eax
const char *v7; // r12
struct stat v8; // [rsp+0h] [rbp-B8h] BYREF

v3 = (char *)(a3 + 260);
optind = 1;
while ( 1 )
{
v5 = getopt(argc, argv, "hc:k:u:r:");
if ( v5 == -1 )
break;
switch ( v5 )
{
case 'r':
sprintf(v3, optarg);
break;
case 'u':
if ( (*optarg != 109 || optarg[1] != 101 || optarg[2]) && strcmp(optarg, "any") )
{
LABEL_6:
func0(*argv);
return 1;
}
sprintf((char *)(a3 + 772), optarg);
break;
case 'h':
goto LABEL_6;
}
}
if ( !*(_BYTE *)(a3 + 772) )
*(_DWORD *)(a3 + 772) = 7958113;
if ( !*(_BYTE *)(a3 + 260) )
*(_DWORD *)(a3 + 260) = 7958113;
v7 = (const char *)(a3 + 4);
result = stat(v7, &v8);
if ( result )
{
printf("can not access file: '%s'\n", v7);
result = 1;
}
return result;
}

original_code:
int act_listpkg_init(int argc, char* argv[], gk_conf_t * gc)
{
 int opt;
 struct stat st;
     char *string = "hc:k:u:r:";
 optind = 1;
    while ((opt = getopt(argc, argv, string))!= -1)
    {
  switch(opt)
  {
   case 'u':
     if((strcmp(optarg,"me"))&&(strcmp(optarg, "any")))
     {
      my_usage(argc, argv);
      return 1;
     }
     sprintf(gc->user, optarg);
     break;
   case 'r':
     sprintf(gc->repo, optarg);
     break;
   case 'h':
    my_usage(argc, argv);
    return 1;
  }
    }
 if(strlen(gc->user) == 0)
 {
  sprintf(gc->user, "%s", "any");
 }
 if(strlen(gc->repo) == 0)
 {
  sprintf(gc->repo, "%s", "any");
 }
 if(stat(gc->conf, &st)) {printf("can not access file: '%s'\n",gc->conf);return 1;}
 return 0;
}

canonical_original_code:
int act_listpkg_init(int argc, char *argv[], struct _gk_conf_t *gc)
{
 int opt;
 struct stat st;
     char *string = "hc:k:u:r:";
 optind = 1;
    while ((opt = getopt(argc, argv, string))!= -1)
    {
  switch(opt)
  {
   case 'u':
     if((strcmp(optarg,"me"))&&(strcmp(optarg, "any")))
     {
      my_usage(argc, argv);
      return 1;
     }
     sprintf(gc->user, optarg);
     break;
   case 'r':
     sprintf(gc->repo, optarg);
     break;
   case 'h':
    my_usage(argc, argv);
    return 1;
  }
    }
 if(strlen(gc->user) == 0)
 {
  sprintf(gc->user, "%s", "any");
 }
 if(strlen(gc->repo) == 0)
 {
  sprintf(gc->repo, "%s", "any");
 }
 if(stat(gc->conf, &st)) {printf("can not access file: '%s'\n",gc->conf);return 1;}
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct _gk_conf_t { enum GK_ACTION { ACT_MIN_ACTION=0, ACT_UPLOAD_PKG=1, ACT_LIST_REPO=2, ACT_LIST_PKG=3, ACT_MAX_ACTION=4 } action; char conf[128]; char file[128]; char repo[64]; char osv[64]; char app[64]; char ak[64]; char as[64]; char uid[64]; char url[128]; char user[64]; char output[64]; char upload_method[64]; char endpoint[64]; char info[512]; } *

variable_types: opt int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }

variable_types:
string
char *


randstr

original_code:
char * randstr(int len)
{
 static char ret[128]= {0};
 memset(ret, 0, 128);
 int i = 0;
 int nlen = len;
 if(nlen > 128) nlen = 128;
 for(i=0; i < nlen; i++)
 {
  char ch;
  int a = rand()%26;
  if(i%3==0) ch = 'A';
  else ch = 'a';
  ch = ch + a;
  ret[i] = ch;
 }
 return ret;
}

canonical_original_code:
char *randstr(int len)
{
 static char ret[128] = {0};
 memset(ret, 0, 128);
 int i = 0;
 int nlen = len;
 if(nlen > 128) nlen = 128;
 for(i=0; i < nlen; i++)
 {
  char ch;
  int a = rand()%26;
  if(i%3==0) ch = 'A';
  else ch = 'a';
  ch = ch + a;
  ret[i] = ch;
 }
 return ret;
}

variable_types: len int

variable_types:
ret
char [128]

variable_types: i int

variable_types: nlen int

variable_types: ch char

variable_types: a int


decompiled_code:
int __fastcall act_listrepo_init(int argc, char **argv, __int64 a3)
{
char *v3; // r13
int v5; // eax
int result; // eax
const char *v7; // r12
struct stat v8; // [rsp+0h] [rbp-B8h] BYREF

v3 = (char *)(a3 + 772);
optind = 1;
while ( 1 )
{
v5 = getopt(argc, argv, "hc:k:u:");
if ( v5 == -1 )
break;
if ( v5 == 104 )
goto LABEL_8;
if ( v5 == 117 )
{
if ( (*optarg != 109 || optarg[1] != 101 || optarg[2]) && strcmp(optarg, "any") )
{
LABEL_8:
my_usage_constprop_0_isra_0(*argv);
return 1;
}
sprintf(v3, optarg);
}
}
if ( !*(_BYTE *)(a3 + 772) )
*(_DWORD *)(a3 + 772) = 7958113;
v7 = (const char *)(a3 + 4);
result = stat(v7, &v8);
if ( result )
{
printf("can not access file: '%s'\n", v7);
result = 1;
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(int argc, char **argv, __int64 a3)
{
char *v3; // r13
int v5; // eax
int result; // eax
const char *v7; // r12
struct stat v8; // [rsp+0h] [rbp-B8h] BYREF

v3 = (char *)(a3 + 772);
optind = 1;
while ( 1 )
{
v5 = getopt(argc, argv, "hc:k:u:");
if ( v5 == -1 )
break;
if ( v5 == 104 )
goto LABEL_8;
if ( v5 == 117 )
{
if ( (*optarg != 109 || optarg[1] != 101 || optarg[2]) && strcmp(optarg, "any") )
{
LABEL_8:
func0(*argv);
return 1;
}
sprintf(v3, optarg);
}
}
if ( !*(_BYTE *)(a3 + 772) )
*(_DWORD *)(a3 + 772) = 7958113;
v7 = (const char *)(a3 + 4);
result = stat(v7, &v8);
if ( result )
{
printf("can not access file: '%s'\n", v7);
result = 1;
}
return result;
}

original_code:
int act_listrepo_init(int argc, char* argv[], gk_conf_t * gc)
{
 int opt;
 struct stat st;
    char *string = "hc:k:u:";
 optind = 1;
    while ((opt = getopt(argc, argv, string))!= -1)
    {
  switch(opt)
  {
   case 'u':
     if((strcmp(optarg,"me"))&&(strcmp(optarg, "any")))
     {
      my_usage(argc, argv);
      return 1;
     }
     sprintf(gc->user, optarg);
     break;
   case 'h':
    my_usage(argc, argv);
    return 1;
  }
    }
 if(strlen(gc->user) == 0)
 {
  sprintf(gc->user, "%s", "any");
 }
 if(stat(gc->conf, &st)) {printf("can not access file: '%s'\n",gc->conf);return 1;}
 return 0;
}

canonical_original_code:
int act_listrepo_init(int argc, char *argv[], struct _gk_conf_t *gc)
{
 int opt;
 struct stat st;
    char *string = "hc:k:u:";
 optind = 1;
    while ((opt = getopt(argc, argv, string))!= -1)
    {
  switch(opt)
  {
   case 'u':
     if((strcmp(optarg,"me"))&&(strcmp(optarg, "any")))
     {
      my_usage(argc, argv);
      return 1;
     }
     sprintf(gc->user, optarg);
     break;
   case 'h':
    my_usage(argc, argv);
    return 1;
  }
    }
 if(strlen(gc->user) == 0)
 {
  sprintf(gc->user, "%s", "any");
 }
 if(stat(gc->conf, &st)) {printf("can not access file: '%s'\n",gc->conf);return 1;}
 return 0;
}

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; long st_atime; unsigned long st_atimensec; long st_mtime; unsigned long st_mtimensec; long st_ctime; unsigned long st_ctimensec; long __glibc_reserved[3]; }

user_defined_types: enum GK_ACTION { ACT_MIN_ACTION=0, ACT_UPLOAD_PKG=1, ACT_LIST_REPO=2, ACT_LIST_PKG=3, ACT_MAX_ACTION=4 }


main

canonical_name: main

repo: duckythescientist/obfuscatedLife

variable_types: O int


repo: duffrohde/RaadhusLED

decompiled_code:
__int64 __fastcall setup_shader(const char *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebp
__int64 v3; // r12
__int64 result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = load_shader(a1, 0x8B30u);
if ( v1 )
{
v2 = v1;
v3 = (unsigned int)glCreateProgramObjectARB();
glAttachObjectARB(v3, v2);
glLinkProgramARB((unsigned int)v3);
glGetObjectParameterivARB((unsigned int)v3, 35714LL, v5);
if ( v5[0] )
{
result = (unsigned int)v3;
}
else
{
fwrite("shader linking failed\n", 1uLL, 0x16uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("shader loading failed\n", 1uLL, 0x16uLL, stderr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
unsigned int v1; // eax
unsigned int v2; // ebp
__int64 v3; // r12
__int64 result; // rax
int v5[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v1 = func0(a1, 0x8B30u);
if ( v1 )
{
v2 = v1;
v3 = (unsigned int)glCreateProgramObjectARB();
glAttachObjectARB(v3, v2);
glLinkProgramARB((unsigned int)v3);
glGetObjectParameterivARB((unsigned int)v3, 35714LL, v5);
if ( v5[0] )
{
result = (unsigned int)v3;
}
else
{
fwrite("shader linking failed\n", 1uLL, 0x16uLL, stderr);
result = 0LL;
}
}
else
{
fwrite("shader loading failed\n", 1uLL, 0x16uLL, stderr);
result = 0LL;
}
return result;
}

original_code:
unsigned int setup_shader(const char *fname) {
 unsigned int prog, sdr;
 int linked;
 sdr = load_shader(fname, 0x8B30);
 if(!sdr) {
  fprintf(stderr, "shader loading failed\n");
  return 0;
 }
 prog = glCreateProgramObjectARB();
 glAttachObjectARB(prog, sdr);
 glLinkProgramARB(prog);
 glGetObjectParameterivARB(prog, 0x8B82, &linked);
 if(!linked) {
  fprintf(stderr, "shader linking failed\n");
  return 0;
 }
 return prog;
}

canonical_original_code:
unsigned int setup_shader(char *fname) {
 unsigned int prog; unsigned int sdr;
 int linked;
 sdr = load_shader(fname, 0x8B30);
 if(!sdr) {
  fprintf(stderr, "shader loading failed\n");
  return 0;
 }
 prog = glCreateProgramObjectARB();
 glAttachObjectARB(prog, sdr);
 glLinkProgramARB(prog);
 glGetObjectParameterivARB(prog, 0x8B82, &linked);
 if(!linked) {
  fprintf(stderr, "shader linking failed\n");
  return 0;
 }
 return prog;
}

variable_types:
fname
char *

variable_types:
prog
unsigned int

variable_types:
sdr
unsigned int

variable_types: linked int

return_type: unsigned int


decompiled_code:
__int64 __fastcall setup_shader_vertex(const char *a1, const char *a2)
{
unsigned int v2; // eax
unsigned int v3; // ebp
unsigned int v4; // er13
unsigned int v5; // er12
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = load_shader(a1, 0x8B30u);
if ( v2 && (v3 = v2, (v4 = load_shader(a2, 0x8B31u)) != 0) )
{
v5 = glCreateProgramObjectARB();
glAttachObjectARB(v5, v3);
glAttachObjectARB(v5, v4);
glLinkProgramARB(v5);
glGetObjectParameterivARB(v5, 35714LL, v7);
if ( !v7[0] )
{
v5 = 0;
fwrite("shader linking failed\n", 1uLL, 0x16uLL, stderr);
}
}
else
{
v5 = 0;
fwrite("shader loading failed\n", 1uLL, 0x16uLL, stderr);
}
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1, const char *a2)
{
unsigned int v2; // eax
unsigned int v3; // ebp
unsigned int v4; // er13
unsigned int v5; // er12
int v7[7]; // [rsp+Ch] [rbp-1Ch] BYREF

v2 = func0(a1, 0x8B30u);
if ( v2 && (v3 = v2, (v4 = func0(a2, 0x8B31u)) != 0) )
{
v5 = glCreateProgramObjectARB();
glAttachObjectARB(v5, v3);
glAttachObjectARB(v5, v4);
glLinkProgramARB(v5);
glGetObjectParameterivARB(v5, 35714LL, v7);
if ( !v7[0] )
{
v5 = 0;
fwrite("shader linking failed\n", 1uLL, 0x16uLL, stderr);
}
}
else
{
v5 = 0;
fwrite("shader loading failed\n", 1uLL, 0x16uLL, stderr);
}
return v5;
}

original_code:
unsigned int setup_shader_vertex(const char *fname_frag, const char *fname_vertex) {
 unsigned int prog, sdr_frag, sdr_vertex;
 int linked;
 sdr_frag = load_shader(fname_frag, 0x8B30);
 if(!sdr_frag) {
  fprintf(stderr, "shader loading failed\n");
  return 0;
 }
 sdr_vertex = load_shader(fname_vertex, 0x8B31);
 if(!sdr_vertex) {
  fprintf(stderr, "shader loading failed\n");
  return 0;
 }
 prog = glCreateProgramObjectARB();
 glAttachObjectARB(prog, sdr_frag);
 glAttachObjectARB(prog, sdr_vertex);
 glLinkProgramARB(prog);
 glGetObjectParameterivARB(prog, 0x8B82, &linked);
 if(!linked) {
  fprintf(stderr, "shader linking failed\n");
  return 0;
 }
 return prog;
}

canonical_original_code:
unsigned int setup_shader_vertex(char *fname_frag, char *fname_vertex) {
 unsigned int prog; unsigned int sdr_frag; unsigned int sdr_vertex;
 int linked;
 sdr_frag = load_shader(fname_frag, 0x8B30);
 if(!sdr_frag) {
  fprintf(stderr, "shader loading failed\n");
  return 0;
 }
 sdr_vertex = load_shader(fname_vertex, 0x8B31);
 if(!sdr_vertex) {
  fprintf(stderr, "shader loading failed\n");
  return 0;
 }
 prog = glCreateProgramObjectARB();
 glAttachObjectARB(prog, sdr_frag);
 glAttachObjectARB(prog, sdr_vertex);
 glLinkProgramARB(prog);
 glGetObjectParameterivARB(prog, 0x8B82, &linked);
 if(!linked) {
  fprintf(stderr, "shader linking failed\n");
  return 0;
 }
 return prog;
}


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

result = glGetUniformLocationARB();
if ( (_DWORD)result != -1 )
result = glUniform1f((unsigned int)result, a1);
return result;
}

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

result = glGetUniformLocationARB();
if ( (_DWORD)result != -1 )
result = glUniform1f((unsigned int)result, a1);
return result;
}

original_code:
void set_uniform1f(unsigned int prog, const char *name, float val) {
 int loc = glGetUniformLocationARB(prog, name);
 if(loc != -1) {
  glUniform1f(loc, val);
 }
}

canonical_original_code:
void set_uniform1f(unsigned int prog, char *name, float val) {
 int loc = glGetUniformLocationARB(prog, name);
 if(loc != -1) {
  glUniform1f(loc, val);
 }
}

variable_types:
name
char *

variable_types: val float

variable_types: loc int

return_type: void


decompiled_code:
__int64 __fastcall set_uniform2f(float a1, float a2)
{
__int64 result; // rax

result = glGetUniformLocationARB();
if ( (_DWORD)result != -1 )
result = glUniform2f((unsigned int)result, a1, a2);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(float a1, float a2)
{
__int64 result; // rax

result = glGetUniformLocationARB();
if ( (_DWORD)result != -1 )
result = glUniform2f((unsigned int)result, a1, a2);
return result;
}

original_code:
void set_uniform2f(unsigned int prog, const char *name, float v1, float v2) {
 int loc = glGetUniformLocationARB(prog, name);
 if(loc != -1) {
  glUniform2f(loc, v1, v2);
 }
}

canonical_original_code:
void set_uniform2f(unsigned int prog, char *name, float v1, float v2) {
 int loc = glGetUniformLocationARB(prog, name);
 if(loc != -1) {
  glUniform2f(loc, v1, v2);
 }
}


decompiled_code:
__int64 __fastcall set_uniform1i(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax

result = glGetUniformLocationARB();
if ( (_DWORD)result != -1 )
result = glUniform1i((unsigned int)result, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax

result = glGetUniformLocationARB();
if ( (_DWORD)result != -1 )
result = glUniform1i((unsigned int)result, a3);
return result;
}

original_code:
void set_uniform1i(unsigned int prog, const char *name, int val) {
 int loc = glGetUniformLocationARB(prog, name);
 if(loc != -1) {
  glUniform1i(loc, val);
 }
}

canonical_original_code:
void set_uniform1i(unsigned int prog, char *name, int val) {
 int loc = glGetUniformLocationARB(prog, name);
 if(loc != -1) {
  glUniform1i(loc, val);
 }
}

variable_types: val int


decompiled_code:
// attributes: thunk
__int64 set_shader()
{
return glUseProgramObjectARB();
}

canonical_decompiled_code:
__int64 func6()
{
return glUseProgramObjectARB();
}

original_code:
void set_shader(unsigned int prog) {
 glUseProgramObjectARB(prog);
}


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

gettimeofday(&timeval_1, 0LL);
if ( (_QWORD)first_timeval_0 )
return (timeval_1.tv_usec - *((_QWORD *)&first_timeval_0 + 1)) / 1000 + 1000 * (timeval_1.tv_sec - first_timeval_0);
result = 0LL;
first_timeval_0 = (__int128)_mm_load_si128((const __m128i *)&timeval_1);
return result;
}

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

gettimeofday(&timeval_1, 0LL);
if ( (_QWORD)first_timeval_0 )
return (timeval_1.tv_usec - *((_QWORD *)&first_timeval_0 + 1)) / 1000 + 1000 * (timeval_1.tv_sec - first_timeval_0);
result = 0LL;
first_timeval_0 = (__int128)_mm_load_si128((const __m128i *)&timeval_1);
return result;
}

original_code:
unsigned long get_msec(void) {
 static struct timeval timeval, first_timeval;
 gettimeofday(&timeval, 0);
 if(first_timeval.tv_sec == 0) {
  first_timeval = timeval;
  return 0;
 }
 return (timeval.tv_sec - first_timeval.tv_sec) * 1000 + (timeval.tv_usec - first_timeval.tv_usec) / 1000;
}

canonical_original_code:
unsigned long get_msec() {
 static struct timeval timeval; static struct timeval first_timeval;
 gettimeofday(&timeval, 0);
 if(first_timeval.tv_sec == 0) {
  first_timeval = timeval;
  return 0;
 }
 return (timeval.tv_sec - first_timeval.tv_sec) * 1000 + (timeval.tv_usec - first_timeval.tv_usec) / 1000;
}

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

return_type: unsigned long


repo: duskwuff/lmgdbserver

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v6; // eax
int result; // eax
__int64 v8; // rdi
const char *v9; // rsi
const char *v10; // rax

v3 = 0;
appname = (__int64)*argv;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "htvqD:P:");
if ( v6 == -1 )
break;
if ( v6 != 68 )
{
switch ( v6 )
{
case 'P':
v8 = optarg;
v9 = "%x:%x:%x";
if ( (unsigned int)__isoc99_sscanf() != 3 )
goto LABEL_11;
continue;
case 'h':
usage((unsigned int)argc, argv);
return 0;
case 'q':
--v3;
continue;
case 't':
++trace;
continue;
case 'v':
++v3;
continue;
default:
usage((unsigned int)argc, argv);
return 1;
}
}
v8 = optarg;
v9 = "%x:%x:%x" + 3;
if ( (unsigned int)__isoc99_sscanf() != 2 )
LABEL_11:
usage(v8, v9);
}
if ( (unsigned int)libusb_init() )
{
v10 = (const char *)libusb_error_name();
fprintf(stderr, "ICDI: libusb init failed: %s\n", v10);
result = 1;
}
else
{
libusb_set_debug();
lph = libusb_open_device_with_vid_pid();
if ( lph )
{
if ( !(unsigned int)libusb_claim_interface() )
{
fwrite("ICDI connected\n", 1uLL, 0xFuLL, stderr);
if ( isatty(0) )
fwrite("(Good luck using this thing interactively. You'll need it.)\n", 1uLL, 0x3CuLL, stderr);
while ( 1 )
{
pump_gdb2icdi(2LL);
pump_icdi2gdb(131LL);
}
}
fwrite("ICDI: Couldn't claim interface!\n", 1uLL, 0x20uLL, stderr);
result = 1;
}
else
{
fwrite("ICDI: No LaunchPad found!\n", 1uLL, 0x1AuLL, stderr);
result = 1;
}
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v6; // eax
int result; // eax
__int64 v8; // rdi
const char *v9; // rsi
const char *v10; // rax

v3 = 0;
appname = (__int64)*argv;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "htvqD:P:");
if ( v6 == -1 )
break;
if ( v6 != 68 )
{
switch ( v6 )
{
case 'P':
v8 = optarg;
v9 = "%x:%x:%x";
if ( (unsigned int)__isoc99_sscanf() != 3 )
goto LABEL_11;
continue;
case 'h':
func9((unsigned int)argc, argv);
return 0;
case 'q':
--v3;
continue;
case 't':
++trace;
continue;
case 'v':
++v3;
continue;
default:
func9((unsigned int)argc, argv);
return 1;
}
}
v8 = optarg;
v9 = "%x:%x:%x" + 3;
if ( (unsigned int)__isoc99_sscanf() != 2 )
LABEL_11:
func9(v8, v9);
}
if ( (unsigned int)libusb_init() )
{
v10 = (const char *)libusb_error_name();
fprintf(stderr, "ICDI: libusb init failed: %s\n", v10);
result = 1;
}
else
{
libusb_set_debug();
lph = libusb_open_device_with_vid_pid();
if ( lph )
{
if ( !(unsigned int)libusb_claim_interface() )
{
fwrite("ICDI connected\n", 1uLL, 0xFuLL, stderr);
if ( isatty(0) )
fwrite("(Good luck using this thing interactively. You'll need it.)\n", 1uLL, 0x3CuLL, stderr);
while ( 1 )
{
func7(2LL);
func8(131LL);
}
}
fwrite("ICDI: Couldn't claim interface!\n", 1uLL, 0x20uLL, stderr);
result = 1;
}
else
{
fwrite("ICDI: No LaunchPad found!\n", 1uLL, 0x1AuLL, stderr);
result = 1;
}
}
return result;
}

original_code:
int main(int argc, char **argv)
{
    int lu_verbosity = 0;
    int icdi_vid = 0x1cbe;
    int icdi_pid = 0x00fd;
    int icdi_interface = 0x02;
    int icdi_ep_in = 0x83;
    int icdi_ep_out = 0x02;
    appname = argv[0];
    int ch;
    while ((ch = getopt(argc, argv, "htvqD:P:")) != -1) {
        switch (ch) {
            case 't':
                trace++;
                break;
            case 'h':
                usage();
                return 0;
            case 'v':
                lu_verbosity++;
                break;
            case 'q':
                lu_verbosity--;
                break;
            case 'D':
                if (sscanf(optarg, "%x:%x", &icdi_vid, &icdi_pid) != 2)
                    usage();
                break;
            case 'P':
                if (sscanf(optarg, "%x:%x:%x", &icdi_interface, &icdi_ep_in, &icdi_ep_out) != 3)
                    usage();
                break;
            default:
                usage();
                return 1;
        }
    }
    int rc;
    rc = libusb_init(((void *)0));
    if (rc != 0) {
        fprintf(stderr, "ICDI: libusb init failed: %s\n", libusb_error_name(rc));
        return 1;
    }
    libusb_set_debug(((void *)0), lu_verbosity);
    lph = libusb_open_device_with_vid_pid(((void *)0), icdi_vid, icdi_pid);
    if (lph == ((void *)0)) {
        fprintf(stderr, "ICDI: No LaunchPad found!\n");
        return 1;
    }
    rc = libusb_claim_interface(lph, icdi_interface);
    if (rc) {
        fprintf(stderr, "ICDI: Couldn't claim interface!\n");
        return 1;
    }
    fprintf(stderr, "ICDI connected\n");
    if (isatty(0))
        fprintf(stderr, "(Good luck using this thing interactively. You'll need it.)\n");
    for (;;) {
        pump_gdb2icdi(icdi_ep_out);
        pump_icdi2gdb(icdi_ep_in);
    }
}

variable_types: argc int

variable_types:
argv
char **

variable_types: ch int

variable_types: rc int


decompiled_code:
__int64 pump_gdb2icdi()
{
__int64 v0; // rbx
int v1; // ebp
__int64 v2; // r13
char v3; // al
char v4; // al
FILE *v5; // rdi
__int64 result; // rax
const char *v7; // rax

v0 = 1LL;
while ( 1 )
{
v1 = v0;
v2 = (int)v0;
v3 = fgetc(stdin);
byte_4040FF[v0] = v3;
if ( v3 == -1 )
{
libusb_close();
exit(0);
}
if ( v3 == 3 && (int)v0 <= 2 )
break;
if ( v0 == 4092 )
{
fwrite("ICDI ERROR: Line too long!!\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
++v0;
if ( v3 == 35 )
{
v4 = fgetc(stdin);
v5 = stdin;
buf[v2] = v4;
LODWORD(v2) = v1 + 2;
buf[v1 + 1] = fgetc(v5);
buf[v1 + 2] = 0;
if ( trace )
fprintf(stderr, "ICDI <<- %s\n", buf);
break;
}
}
result = libusb_bulk_transfer();
if ( (_DWORD)result || (_DWORD)v2 )
{
v7 = (const char *)libusb_error_name();
fprintf(stderr, "ICDI send error: %s\n", v7);
exit(1);
}
return result;
}

canonical_decompiled_code:
__int64 func7()
{
__int64 v0; // rbx
int v1; // ebp
__int64 v2; // r13
char v3; // al
char v4; // al
FILE *v5; // rdi
__int64 result; // rax
const char *v7; // rax

v0 = 1LL;
while ( 1 )
{
v1 = v0;
v2 = (int)v0;
v3 = fgetc(stdin);
byte_4040FF[v0] = v3;
if ( v3 == -1 )
{
libusb_close();
exit(0);
}
if ( v3 == 3 && (int)v0 <= 2 )
break;
if ( v0 == 4092 )
{
fwrite("ICDI ERROR: Line too long!!\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
++v0;
if ( v3 == 35 )
{
v4 = fgetc(stdin);
v5 = stdin;
buf[v2] = v4;
LODWORD(v2) = v1 + 2;
buf[v1 + 1] = fgetc(v5);
buf[v1 + 2] = 0;
if ( trace )
fprintf(stderr, "ICDI <<- %s\n", buf);
break;
}
}
result = libusb_bulk_transfer();
if ( (_DWORD)result || (_DWORD)v2 )
{
v7 = (const char *)libusb_error_name();
fprintf(stderr, "ICDI send error: %s\n", v7);
exit(1);
}
return result;
}

original_code:
void pump_gdb2icdi(int endpoint)
{
    int p = 0;
    int ch;
    do {
        ch = buf[p++] = fgetc(stdin);
        if (ch == -1) {
            libusb_close(lph);
            exit(0);
        }
        if (ch == 0x03 && p < 3)
            goto sendnow;
        if (p >= sizeof(buf) - 4) {
            fprintf(stderr, "ICDI ERROR: Line too long!!\n");
            exit(1);
        }
    } while (ch != '#');
    buf[p++] = fgetc(stdin);
    buf[p++] = fgetc(stdin);
    buf[p] = 0;
    if (trace) fprintf(stderr, "ICDI <<- %s\n", buf);
sendnow: ;
    int count = 0;
    int rc = libusb_bulk_transfer(lph, endpoint, (uint8_t *) buf, p, &count, 0);
    if (rc != 0 || count != p) {
        fprintf(stderr, "ICDI send error: %s\n", libusb_error_name(rc));
        exit(1);
    }
}

variable_types: endpoint int

variable_types: p int

variable_types: count int


decompiled_code:
int pump_icdi2gdb()
{
int result; // eax
const char *v1; // rax

if ( (unsigned int)libusb_bulk_transfer() )
{
v1 = (const char *)libusb_error_name();
result = fprintf(stderr, "ICDI recv error: %s\n", v1);
}
else
{
buf[0] = 0;
if ( trace )
fprintf(stderr, "ICDI ->> %s\n", buf);
fwrite(buf, 0LL, 1uLL, _bss_start);
result = fflush(_bss_start);
}
return result;
}

canonical_decompiled_code:
int func8()
{
int result; // eax
const char *v1; // rax

if ( (unsigned int)libusb_bulk_transfer() )
{
v1 = (const char *)libusb_error_name();
result = fprintf(stderr, "ICDI recv error: %s\n", v1);
}
else
{
buf[0] = 0;
if ( trace )
fprintf(stderr, "ICDI ->> %s\n", buf);
fwrite(buf, 0LL, 1uLL, _bss_start);
result = fflush(_bss_start);
}
return result;
}

original_code:
void pump_icdi2gdb(int endpoint)
{
    int count = 0;
again: ;
    int rc = libusb_bulk_transfer(lph, endpoint, (uint8_t *) buf, sizeof(buf), &count, 100);
    if (rc != 0) {
        fprintf(stderr, "ICDI recv error: %s\n", libusb_error_name(rc));
        return;
    }
    buf[count] = 0;
    if (trace) fprintf(stderr, "ICDI ->> %s\n", buf);
    fwrite(buf, count, 1, stdout);
    fflush(stdout);
    if(count == 1 && buf[0] == '+') goto again;
}


usage

decompiled_code:
int usage()
{
return fprintf(
stderr,
"USAGE: (gdb) target remote | %s [opts]\n"
" -h : this message\n"
" -t : enable ICDI command tracing\n"
" -v : increase libusb verbosity\n"
" -q : decrease libusb verbosity\n"
" -D : specify alternate VID:PID\n"
" default: -D %04x:%04x\n"
" -P : specify alternate interface & in/out endpoints\n"
" default: -P %02x:%02x:%02x\n",
(const char *)appname,
7358LL,
253LL,
2LL,
131LL,
2LL);
}

canonical_decompiled_code:
int func9()
{
return fprintf(
stderr,
"USAGE: (gdb) target remote | %s [opts]\n"
" -h : this message\n"
" -t : enable ICDI command tracing\n"
" -v : increase libusb verbosity\n"
" -q : decrease libusb verbosity\n"
" -D : specify alternate VID:PID\n"
" default: -D %04x:%04x\n"
" -P : specify alternate interface & in/out endpoints\n"
" default: -P %02x:%02x:%02x\n",
(const char *)appname,
7358LL,
253LL,
2LL,
131LL,
2LL);
}

original_code:
void usage()
{
    fprintf(stderr,
            "USAGE: (gdb) target remote | %s [opts]\n"
            "    -h : this message\n"
            "    -t : enable ICDI command tracing\n"
            "    -v : increase libusb verbosity\n"
            "    -q : decrease libusb verbosity\n"
            "    -D : specify alternate VID:PID\n"
            "         default: -D %04x:%04x\n"
            "    -P : specify alternate interface & in/out endpoints\n"
            "         default: -P %02x:%02x:%02x\n",
            appname,
            0x1cbe, 0x00fd,
            0x02, 0x83, 0x02
            );
}


main

repo: dvdalilue/sistemas

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

printf("%d\n", 1LL);
v4[0] = 1;
hola();
cambiar_cont(v4);
printf("%d\n", v4[0]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v4[3]; // [rsp+Ch] [rbp-Ch] BYREF

printf("%d\n", 1LL);
v4[0] = 1;
func8();
func7(v4);
printf("%d\n", v4[0]);
return 0;
}

original_code:
int main(){
    NUEVA_ESTRUCTURA nuevo;
    ESTRUCTURA_NUEVA2 nuevo2;
    printf("%d\n",1);
    nuevo.cont = 1;
    hola();
    cambiar_cont(&nuevo);
    printf("%d\n", nuevo.cont);
}

canonical_original_code:
int main(){
    struct nuevo nuevo;
    struct nuevo2 nuevo2;
    printf("%d\n",1);
    nuevo.cont = 1;
    hola();
    cambiar_cont(&nuevo);
    printf("%d\n", nuevo.cont);
}

variable_types:
nuevo
struct nuevo { int cont; }

user_defined_types:
struct nuevo { int cont; }
struct nuevo2 { char a; }


hola

decompiled_code:
int hola()
{
return puts("Hola Mundo!");
}

canonical_decompiled_code:
int func8()
{
return puts("Hola Mundo!");
}

original_code:
void hola(){
    printf("Hola Mundo!\n");
}

canonical_original_code:
void hola(){
    printf("Hola Mundo!\n");
}


repo: dweinstein/vmxos-osx

decompiled_code:
void __noreturn guest_entry()
{
puts("VM_ENTER: inside guest\n");
while ( 1 )
;
}

canonical_decompiled_code:
void __noreturn func0()
{
puts("VM_ENTER: inside guest\n");
while ( 1 )
;
}

original_code:
void guest_entry()
{
 puts("VM_ENTER: inside guest\n");
 while(1);
}


decompiled_code:
void __noreturn host_entry()
{
unsigned int v0; // ebx
const char *v1; // rax
const char *v2; // rax
const char *v3; // rax

v0 = vmx_vmread(17410LL);
puts("VM_EXIT: back to the host.. finally!\n");
puts("Exit reason:\n");
puts("- Basic exit reason: ");
puts((const char *)vmx_exit_reasons[(unsigned __int16)v0]);
puts("\n");
puts("- Pending MTF VM exit: ");
v1 = (const char *)dec2string((v0 >> 28) & 1);
puts(v1);
puts("\n");
puts("- VM exit from VMX root operation: ");
v2 = (const char *)dec2string((v0 >> 29) & 1);
puts(v2);
puts("\n");
puts("- VM-entry failure: ");
v3 = (const char *)dec2string(v0 >> 31);
puts(v3);
puts("\n");
sti();
vmx_vmresume();
while ( 1 )
;
}

canonical_decompiled_code:
void __noreturn func1()
{
unsigned int v0; // ebx
const char *v1; // rax
const char *v2; // rax
const char *v3; // rax

v0 = vmx_vmread(17410LL);
puts("VM_EXIT: back to the host.. finally!\n");
puts("Exit reason:\n");
puts("- Basic exit reason: ");
puts((const char *)vmx_exit_reasons[(unsigned __int16)v0]);
puts("\n");
puts("- Pending MTF VM exit: ");
v1 = (const char *)dec2string((v0 >> 28) & 1);
puts(v1);
puts("\n");
puts("- VM exit from VMX root operation: ");
v2 = (const char *)dec2string((v0 >> 29) & 1);
puts(v2);
puts("\n");
puts("- VM-entry failure: ");
v3 = (const char *)dec2string(v0 >> 31);
puts(v3);
puts("\n");
sti();
vmx_vmresume();
while ( 1 )
;
}

original_code:
void host_entry()
{
 VM_EXIT_REASON_t er;
 *(unsigned int *) &er = vmx_vmread(0x00004402);
 puts("VM_EXIT: back to the host.. finally!\n");
 puts("Exit reason:\n");
 puts("- Basic exit reason: "); puts(vmx_exit_reasons[er.b0015_Basic_exit_reason]); puts("\n");
 puts("- Pending MTF VM exit: "); puts(dec2string(er.b28_Pending_MTF_VM_exit)); puts("\n");
 puts("- VM exit from VMX root operation: "); puts(dec2string(er.b29_VM_exit_from_VMX_root_operation)); puts("\n");
 puts("- VM-entry failure: "); puts(dec2string(er.b31_VM_entry_failure)); puts("\n");
 sti();
 vmx_vmresume();
 while(1);
}

canonical_original_code:
void host_entry()
{
 struct VM_EXIT_REASON_t er;
 *(unsigned int *) &er = vmx_vmread(0x00004402);
 puts("VM_EXIT: back to the host.. finally!\n");
 puts("Exit reason:\n");
 puts("- Basic exit reason: "); puts(vmx_exit_reasons[er.b0015_Basic_exit_reason]); puts("\n");
 puts("- Pending MTF VM exit: "); puts(dec2string(er.b28_Pending_MTF_VM_exit)); puts("\n");
 puts("- VM exit from VMX root operation: "); puts(dec2string(er.b29_VM_exit_from_VMX_root_operation)); puts("\n");
 puts("- VM-entry failure: "); puts(dec2string(er.b31_VM_entry_failure)); puts("\n");
 sti();
 vmx_vmresume();
 while(1);
}

variable_types: struct VM_EXIT_REASON_t { unsigned int b0015_Basic_exit_reason; unsigned int b2716_Reserved_zeros; unsigned int b28_Pending_MTF_VM_exit; unsigned int b29_VM_exit_from_VMX_root_operation; unsigned int b30_Reserved_zeros; unsigned int b31_VM_entry_failure; }