main

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

if ( argc != 2 )
{
fwrite("USAGE: simple_server <port>\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
ioloop_init(argc, argv, envp);
v3 = atoi(argv[1]);
server_handler_init(v3);
ioloop_start();
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 if (argc != 2) {
  fprintf(stderr, "USAGE: simple_server <port>\n");
  exit(1);
 }
 ioloop_init();
 server_handler_init(atoi(argv[1]));
 ioloop_start();
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


repo: vpj/ahira

decompiled_code:
int __fastcall ioloop_set_nonblocking(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3, 0LL);
if ( v1 == -1 )
v1 = 0;
BYTE1(v1) |= 8u;
return fcntl(fd, 4, v1);
}

canonical_decompiled_code:
int __fastcall func4(int fd)
{
unsigned int v1; // eax

v1 = fcntl(fd, 3, 0LL);
if ( v1 == -1 )
v1 = 0;
BYTE1(v1) |= 8u;
return fcntl(fd, 4, v1);
}

original_code:
int ioloop_set_nonblocking(int fd) {
 int flags = 0;
 if (-1 == (flags = fcntl(fd, 3, 0)))
  flags = 0;
 return fcntl(fd, 4, flags | 04000);
}

variable_types: fd int

variable_types: flags int

return_type: int


decompiled_code:
void *ioloop_init()
{
__int64 v0; // rbp
_QWORD *v1; // rbx
void *result; // rax

ioloop = malloc(0x18uLL);
*(_DWORD *)(ioloop + 16LL) = epoll_create(100);
if ( *(int *)(ioloop + 16LL) < 0 )
log_error("Failed to create epoll", 2LL);
v0 = ioloop;
*(_QWORD *)(v0 + 8) = hash_table_init(97);
v1 = (_QWORD *)ioloop;
result = malloc(0x4B0uLL);
*v1 = result;
return result;
}

canonical_decompiled_code:
void *func5()
{
__int64 v0; // rbp
_QWORD *v1; // rbx
void *result; // rax

ioloop = malloc(0x18uLL);
*(_DWORD *)(ioloop + 16LL) = epoll_create(100);
if ( *(int *)(ioloop + 16LL) < 0 )
log_error("Failed to create epoll", 2LL);
v0 = ioloop;
*(_QWORD *)(v0 + 8) = hash_table_init(97);
v1 = (_QWORD *)ioloop;
result = malloc(0x4B0uLL);
*v1 = result;
return result;
}

original_code:
void
ioloop_init() {
 ioloop = malloc(sizeof(ioloop_context));
 ioloop->epfd = epoll_create(100);
 if(ioloop->epfd < 0)
  log_error("Failed to create epoll", 2);
 ioloop->handlers = hash_table_init(97);
 ioloop->events = malloc(sizeof(struct epoll_event) * 100);
}

return_type: void

user_defined_types: struct epoll_event { unsigned int events; union epoll_data data; }

user_defined_types: union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; }


decompiled_code:
void __noreturn ioloop_start()
{
int v0; // eax
__int64 v1; // r13
__int64 v2; // rbp
__int64 v3; // rax

while ( 1 )
{
do
v0 = epoll_wait(*((_DWORD *)ioloop + 4), (struct epoll_event *)*ioloop, 100, -1);
while ( v0 <= 0 );
v1 = 12LL * (unsigned int)v0;
v2 = 0LL;
do
{
v3 = hash_get((_QWORD *)ioloop[1], *(_DWORD *)(*ioloop + v2 + 4));
if ( v3 )
(*(void (__fastcall **)(_QWORD))v3)(*(_QWORD *)(v3 + 8));
else
log_error("Event handler not present", 1LL);
v2 += 12LL;
}
while ( v2 != v1 );
}
}

canonical_decompiled_code:
void __noreturn func6()
{
int v0; // eax
__int64 v1; // r13
__int64 v2; // rbp
__int64 v3; // rax

while ( 1 )
{
do
v0 = epoll_wait(*((_DWORD *)ioloop + 4), (struct epoll_event *)*ioloop, 100, -1);
while ( v0 <= 0 );
v1 = 12LL * (unsigned int)v0;
v2 = 0LL;
do
{
v3 = func1((_QWORD *)ioloop[1], *(_DWORD *)(*ioloop + v2 + 4));
if ( v3 )
(*(void (__fastcall **)(_QWORD))v3)(*(_QWORD *)(v3 + 8));
else
log_error("Event handler not present", 1LL);
v2 += 12LL;
}
while ( v2 != v1 );
}
}

original_code:
void
ioloop_start() {
 int nfds;
 int i;
 int fd;
 handler *h;
 for(;;) {
  nfds = epoll_wait(ioloop->epfd, ioloop->events, 100, -1 );
  for(i = 0; i < nfds; ++i) {
   fd = ioloop->events[i].data.fd;
   if(!(h = hash_get(ioloop->handlers, fd))) {
    log_error("Event handler not present", 1);
    continue;
   }
   h->h(ioloop->events[i], h->context);
  }
 }
}

canonical_original_code:
void ioloop_start() {
 int nfds;
 int i;
 int fd;
 struct handler *h;
 for(;;) {
  nfds = epoll_wait(ioloop->epfd, ioloop->events, 100, -1 );
  for(i = 0; i < nfds; ++i) {
   fd = ioloop->events[i].data.fd;
   if(!(h = hash_get(ioloop->handlers, fd))) {
    log_error("Event handler not present", 1);
    continue;
   }
   h->h(ioloop->events[i], h->context);
  }
 }
}

variable_types: nfds int

variable_types: i int

variable_types: struct handler { int (*h)(struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } e, void *context); void *context; } *

user_defined_types: struct handler { int (*h)(struct epoll_event e, void *context); void *context; }


decompiled_code:
int __fastcall ioloop_add_handler(int fd, __int64 a2, __int64 a3, uint32_t a4)
{
_QWORD *v6; // rax
int result; // eax
struct epoll_event event; // [rsp+14h] [rbp-34h] BYREF

v6 = malloc(0x10uLL);
*v6 = a2;
v6[1] = a3;
hash_set((_QWORD *)ioloop[1], fd, (__int64)v6);
event.data.fd = fd;
event.events = a4;
result = epoll_ctl(*((_DWORD *)ioloop + 4), 1, fd, &event);
if ( result < 0 )
{
log_error("Failed to insert handler to epoll", 1LL);
result = log_epoll_event("Failed to insert handler to epoll", 1LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func7(int fd, __int64 a2, __int64 a3, uint32_t a4)
{
_QWORD *v6; // rax
int result; // eax
struct epoll_event event; // [rsp+14h] [rbp-34h] BYREF

v6 = malloc(0x10uLL);
*v6 = a2;
v6[1] = a3;
func3((_QWORD *)ioloop[1], fd, (__int64)v6);
event.data.fd = fd;
event.events = a4;
result = epoll_ctl(*((_DWORD *)ioloop + 4), 1, fd, &event);
if ( result < 0 )
{
log_error("Failed to insert handler to epoll", 1LL);
result = log_epoll_event("Failed to insert handler to epoll", 1LL);
}
return result;
}

original_code:
void
ioloop_add_handler(int fd, handler_function hf, void *context, unsigned int events) {
 handler *h;
 struct epoll_event e;
 h = malloc(sizeof(handler));
 h->h = hf;
 h->context = context;
 hash_set(ioloop->handlers, fd, h);
 e.data.fd = fd;
 e.events = events;
 if(epoll_ctl(ioloop->epfd, 1, fd, &e) < 0) {
  log_error("Failed to insert handler to epoll", 1);
  log_epoll_event(e);
 }
}

canonical_original_code:
void ioloop_add_handler(int fd, int (*hf)(struct epoll_event e, void *context), void *context, unsigned int events) {
 struct handler *h;
 struct epoll_event e;
 h = malloc(sizeof(handler));
 h->h = hf;
 h->context = context;
 hash_set(ioloop->handlers, fd, h);
 e.data.fd = fd;
 e.events = events;
 if(epoll_ctl(ioloop->epfd, 1, fd, &e) < 0) {
  log_error("Failed to insert handler to epoll", 1);
  log_epoll_event(e);
 }
}

variable_types: int (*)(struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; } e, void *context)

variable_types:
context
void *

variable_types:
events
unsigned int


decompiled_code:
int __fastcall ioloop_modify_handler(int fd, uint32_t a2)
{
_QWORD *v2; // r12
int result; // eax
struct epoll_event event; // [rsp+14h] [rbp-24h] BYREF

v2 = ioloop;
if ( !hash_get((_QWORD *)ioloop[1], fd) )
return log_error("Changing handler of a non registered file descriptor", 1LL);
event.data.fd = fd;
event.events = a2;
result = epoll_ctl(*((_DWORD *)v2 + 4), 3, fd, &event);
if ( result < 0 )
{
log_error("Failed to modify epoll events", 1LL);
result = log_epoll_event("Failed to modify epoll events", 1LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func8(int fd, uint32_t a2)
{
_QWORD *v2; // r12
int result; // eax
struct epoll_event event; // [rsp+14h] [rbp-24h] BYREF

v2 = ioloop;
if ( !func1((_QWORD *)ioloop[1], fd) )
return log_error("Changing handler of a non registered file descriptor", 1LL);
event.data.fd = fd;
event.events = a2;
result = epoll_ctl(*((_DWORD *)v2 + 4), 3, fd, &event);
if ( result < 0 )
{
log_error("Failed to modify epoll events", 1LL);
result = log_epoll_event("Failed to modify epoll events", 1LL);
}
return result;
}

original_code:
void
ioloop_modify_handler(int fd, unsigned int events) {
 struct epoll_event e;
 if(!hash_get(ioloop->handlers, fd)) {
  log_error("Changing handler of a non registered file descriptor", 1);
  return;
 }
 e.data.fd = fd;
 e.events = events;
 if(epoll_ctl(ioloop->epfd, 3, fd, &e) < 0) {
  log_error("Failed to modify epoll events", 1);
  log_epoll_event(e);
 }
}

variable_types: struct epoll_event { unsigned int events; union epoll_data { void *ptr; int fd; unsigned int u32; unsigned long u64; } data; }


decompiled_code:
int __fastcall ioloop_remove_handler(int fd)
{
int result; // eax
struct epoll_event event; // [rsp+14h] [rbp-14h] BYREF

if ( !(unsigned int)hash_remove((_QWORD *)ioloop[1], fd) )
return log_error("Removing handler of a non registered file descriptor", 1LL);
event.data.fd = fd;
result = epoll_ctl(*((_DWORD *)ioloop + 4), 2, fd, &event);
if ( result < 0 )
{
log_error("Failed to modify epoll events", 1LL);
result = log_epoll_event("Failed to modify epoll events", 1LL);
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(int fd)
{
int result; // eax
struct epoll_event event; // [rsp+14h] [rbp-14h] BYREF

if ( !(unsigned int)func2((_QWORD *)ioloop[1], fd) )
return log_error("Removing handler of a non registered file descriptor", 1LL);
event.data.fd = fd;
result = epoll_ctl(*((_DWORD *)ioloop + 4), 2, fd, &event);
if ( result < 0 )
{
log_error("Failed to modify epoll events", 1LL);
result = log_epoll_event("Failed to modify epoll events", 1LL);
}
return result;
}

original_code:
void
ioloop_remove_handler(int fd) {
 struct epoll_event e;
 if(!hash_remove(ioloop->handlers, fd)) {
  log_error("Removing handler of a non registered file descriptor", 1);
  return;
 }
 e.data.fd = fd;
 if(epoll_ctl(ioloop->epfd, 2, fd, &e) < 0) {
  log_error("Failed to modify epoll events", 1);
  log_epoll_event(e);
 }
}


decompiled_code:
__int64 __fastcall handle_echo_events(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 result; // rax
ssize_t v8; // rax

puts("echo event");
log_epoll_event("echo event", a2);
if ( (a7 & 0x10) != 0 )
{
close(*(_DWORD *)(a1 + 16));
ioloop_remove_handler(*(unsigned int *)(a1 + 16));
free_context((void *)a1);
result = 0xFFFFFFFFLL;
}
else if ( (a7 & 8) != 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
if ( (a7 & 4) != 0 )
{
if ( *(int *)(a1 + 1020) > 0 )
{
printf("Writing: %s\n", (const char *)(a1 + 20));
if ( send(*(_DWORD *)(a1 + 16), (const void *)(a1 + 20), *(int *)(a1 + 1020), 0) != *(_DWORD *)(a1 + 1020) )
log_error("Could not write to stream", 1LL);
}
*(_DWORD *)(a1 + 1020) = 0;
ioloop_modify_handler(*(unsigned int *)(a1 + 16), 1LL);
}
result = 0LL;
if ( (a7 & 1) != 0 )
{
v8 = recv(*(_DWORD *)(a1 + 16), (void *)(a1 + 20), 0x3E8uLL, 0);
*(_DWORD *)(a1 + 1020) = v8;
if ( (int)v8 < 0 )
{
log_error("Error reading from socket", 1LL);
}
else
{
*(_BYTE *)(a1 + (int)v8 + 20) = 0;
printf("Reading %d bytes: %s\n", v8, (const char *)(a1 + 20));
}
if ( *(int *)(a1 + 1020) <= 0 )
{
close(*(_DWORD *)(a1 + 16));
ioloop_remove_handler(*(unsigned int *)(a1 + 16));
free_context((void *)a1);
}
else
{
ioloop_modify_handler(*(unsigned int *)(a1 + 16), 4LL);
}
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, __int64 a7)
{
__int64 result; // rax
ssize_t v8; // rax

puts("echo event");
log_epoll_event("echo event", a2);
if ( (a7 & 0x10) != 0 )
{
close(*(_DWORD *)(a1 + 16));
ioloop_remove_handler(*(unsigned int *)(a1 + 16));
func0((void *)a1);
result = 0xFFFFFFFFLL;
}
else if ( (a7 & 8) != 0 )
{
result = 0xFFFFFFFFLL;
}
else
{
if ( (a7 & 4) != 0 )
{
if ( *(int *)(a1 + 1020) > 0 )
{
printf("Writing: %s\n", (const char *)(a1 + 20));
if ( send(*(_DWORD *)(a1 + 16), (const void *)(a1 + 20), *(int *)(a1 + 1020), 0) != *(_DWORD *)(a1 + 1020) )
log_error("Could not write to stream", 1LL);
}
*(_DWORD *)(a1 + 1020) = 0;
ioloop_modify_handler(*(unsigned int *)(a1 + 16), 1LL);
}
result = 0LL;
if ( (a7 & 1) != 0 )
{
v8 = recv(*(_DWORD *)(a1 + 16), (void *)(a1 + 20), 0x3E8uLL, 0);
*(_DWORD *)(a1 + 1020) = v8;
if ( (int)v8 < 0 )
{
log_error("Error reading from socket", 1LL);
}
else
{
*(_BYTE *)(a1 + (int)v8 + 20) = 0;
printf("Reading %d bytes: %s\n", v8, (const char *)(a1 + 20));
}
if ( *(int *)(a1 + 1020) <= 0 )
{
close(*(_DWORD *)(a1 + 16));
ioloop_remove_handler(*(unsigned int *)(a1 + 16));
func0((void *)a1);
}
else
{
ioloop_modify_handler(*(unsigned int *)(a1 + 16), 4LL);
}
result = 0LL;
}
}
return result;
}

original_code:
int
handle_echo_events(struct epoll_event e, void *context) {
 echo_handler_context *c = (echo_handler_context *)context;
 printf("echo event\n");
 log_epoll_event(e);
 if(e.events & EPOLLHUP) {
  close(c->fd);
  ioloop_remove_handler(c->fd);
  free_context(c);
  return -1;
 }
 if(e.events & EPOLLERR) {
  return -1;
 }
 if(e.events & EPOLLOUT) {
  if(c->received > 0) {
   printf("Writing: %s\n", c->buffer);
   if (send(c->fd, c->buffer, c->received, 0) != c->received) {
    log_error("Could not write to stream", 1);
   }
  }
  c->received = 0;
  ioloop_modify_handler(c->fd, EPOLLIN);
 }
 if(e.events & EPOLLIN) {
  if ((c->received = recv(c->fd, c->buffer, 1000, 0)) < 0) {
   log_error("Error reading from socket", 1);
  } else {
   c->buffer[c->received] = 0;
   printf("Reading %d bytes: %s\n", c->received, c->buffer);
  }
  if(c->received > 0) {
   ioloop_modify_handler(c->fd, EPOLLOUT);
  } else {
   close(c->fd);
   ioloop_remove_handler(c->fd);
   free_context(c);
  }
 }
 return 0;
}

canonical_original_code:
int handle_echo_events(struct epoll_event e, void *context) {
 struct echo_handler_context *c = (echo_handler_context *)context;
 printf("echo event\n");
 log_epoll_event(e);
 if(e.events & EPOLLHUP) {
  close(c->fd);
  ioloop_remove_handler(c->fd);
  free_context(c);
  return -1;
 }
 if(e.events & EPOLLERR) {
  return -1;
 }
 if(e.events & EPOLLOUT) {
  if(c->received > 0) {
   printf("Writing: %s\n", c->buffer);
   if (send(c->fd, c->buffer, c->received, 0) != c->received) {
    log_error("Could not write to stream", 1);
   }
  }
  c->received = 0;
  ioloop_modify_handler(c->fd, EPOLLIN);
 }
 if(e.events & EPOLLIN) {
  if ((c->received = recv(c->fd, c->buffer, 1000, 0)) < 0) {
   log_error("Error reading from socket", 1);
  } else {
   c->buffer[c->received] = 0;
   printf("Reading %d bytes: %s\n", c->received, c->buffer);
  }
  if(c->received > 0) {
   ioloop_modify_handler(c->fd, EPOLLOUT);
  } else {
   close(c->fd);
   ioloop_remove_handler(c->fd);
   free_context(c);
  }
 }
 return 0;
}

variable_types: struct echo_handler_context { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; int fd; char buffer[1000]; int received; } *

user_defined_types: struct echo_handler_context { struct sockaddr_in addr; int fd; char buffer[1000]; int received; }

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


decompiled_code:
void __fastcall free_context(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
free(a1);
}

original_code:
static void
free_context(echo_handler_context *c) {
 free(c);
}

canonical_original_code:
static void free_context(struct echo_handler_context *c) {
 free(c);
}


decompiled_code:
__int64 __fastcall handle_server_events(__int64 a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebx
char *v4; // rax
__int64 result; // rax
socklen_t addr_len; // [rsp+1Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

addr_len = 16;
log_epoll_event(a1, a2);
v2 = accept(*(_DWORD *)(a1 + 16), &addr, &addr_len);
if ( v2 < 0 )
{
log_error("Error accepting", 1LL);
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
v4 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("Client connected: %s\n", v4);
echo_handler_init(v3, *(_QWORD *)&addr.sa_family, *(_QWORD *)&addr.sa_data[6]);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, __int64 a2)
{
int v2; // eax
unsigned int v3; // ebx
char *v4; // rax
__int64 result; // rax
socklen_t addr_len; // [rsp+1Ch] [rbp-1Ch] BYREF
struct sockaddr addr; // [rsp+20h] [rbp-18h] BYREF

addr_len = 16;
log_epoll_event(a1, a2);
v2 = accept(*(_DWORD *)(a1 + 16), &addr, &addr_len);
if ( v2 < 0 )
{
log_error("Error accepting", 1LL);
result = 0xFFFFFFFFLL;
}
else
{
v3 = v2;
v4 = inet_ntoa(*(struct in_addr *)&addr.sa_data[2]);
printf("Client connected: %s\n", v4);
echo_handler_init(v3, *(_QWORD *)&addr.sa_family, *(_QWORD *)&addr.sa_data[6]);
result = 0LL;
}
return result;
}

original_code:
int
handle_server_events(struct epoll_event e, void *context) {
 server_handler_context *c = (server_handler_context *)context;
 struct sockaddr_in client_addr;
 socklen_t ca_len = sizeof(client_addr);
 log_epoll_event(e);
 int client = accept(c->fd, (struct sockaddr *) &client_addr,
                 &ca_len);
 if(client < 0){
  log_error("Error accepting", 1);
  return -1;
 }
 printf("Client connected: %s\n", inet_ntoa(client_addr.sin_addr));
 echo_handler_init(client, client_addr);
 return 0;
}

canonical_original_code:
int handle_server_events(struct epoll_event e, void *context) {
 struct server_handler_context_s *c = (server_handler_context *)context;
 struct sockaddr_in client_addr;
 unsigned int ca_len = sizeof(client_addr);
 log_epoll_event(e);
 int client = accept(c->fd, (struct sockaddr *) &client_addr,
                 &ca_len);
 if(client < 0){
  log_error("Error accepting", 1);
  return -1;
 }
 printf("Client connected: %s\n", inet_ntoa(client_addr.sin_addr));
 echo_handler_init(client, client_addr);
 return 0;
}

variable_types: struct server_handler_context_s { struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } addr; int fd; } *

variable_types: client int

user_defined_types: struct server_handler_context_s { struct sockaddr_in addr; int fd; }


inc

repo: vpuydoyeux/Polarssl

decompiled_code:
__int64 __fastcall inc(char *a1, __int64 a2)
{
char v2; // al
unsigned int v3; // edx

v2 = *a1;
v3 = 0;
if ( !*a1 )
return v3;
if ( v2 != 122 )
{
*a1 = v2 + 1;
return 1;
}
*a1 = 97;
return inc(a1 + 1, a2, 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1, __int64 a2)
{
char v2; // al
unsigned int v3; // edx

v2 = *a1;
v3 = 0;
if ( !*a1 )
return v3;
if ( v2 != 122 )
{
*a1 = v2 + 1;
return 1;
}
*a1 = 97;
return func0(a1 + 1, a2, 0LL);
}

original_code:
int inc(char *c)
{
    if (c[0] == 0)
        return 0;
    if (c[0] == 'z')
    {
        c[0] = 'a';
        return inc(c + sizeof(char));
    }
    c[0]++;
    return 1;
}

variable_types:
c
char *


decompiled_code:
__int64 __fastcall b64_from_24bit(unsigned int a1, unsigned __int8 a2, unsigned __int8 a3, int a4, _DWORD *a5, _QWORD *a6)
{
__int64 result; // rax
unsigned int v8; // edx
int v9; // ecx

result = a1;
v8 = a3 | (a2 << 8) | ((unsigned __int8)result << 16);
if ( a4 > 0 )
{
v9 = 0;
do
{
*(_BYTE *)(*a6)++ = itoa64[v8 & 0x3F];
result = (unsigned int)*a5;
*a5 = result - 1;
if ( (int)result < 0 )
break;
v8 >>= 6;
++v9;
}
while ( a4 != v9 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, unsigned __int8 a2, unsigned __int8 a3, int a4, _DWORD *a5, _QWORD *a6)
{
__int64 result; // rax
unsigned int v8; // edx
int v9; // ecx

result = a1;
v8 = a3 | (a2 << 8) | ((unsigned __int8)result << 16);
if ( a4 > 0 )
{
v9 = 0;
do
{
*(_BYTE *)(*a6)++ = itoa64[v8 & 0x3F];
result = (unsigned int)*a5;
*a5 = result - 1;
if ( (int)result < 0 )
break;
v8 >>= 6;
++v9;
}
while ( a4 != v9 );
}
return result;
}

original_code:
void b64_from_24bit(uint8_t B2, uint8_t B1, uint8_t B0, int n,
        int *buflen, char **cp)
{
    uint32_t w;
    int i;
    w = (B2 << 16) | (B1 << 8) | B0;
    for (i = 0; i < n; i++) {
        **cp = itoa64[w&0x3f];
        (*cp)++;
        if ((*buflen)-- < 0)
            break;
        w >>= 6;
    }
}

canonical_original_code:
void b64_from_24bit(unsigned char B2, unsigned char B1, unsigned char B0, int n, int *buflen, char **cp)
{
    unsigned int w;
    int i;
    w = (B2 << 16) | (B1 << 8) | B0;
    for (i = 0; i < n; i++) {
        **cp = itoa64[w&0x3f];
        (*cp)++;
        if ((*buflen)-- < 0)
            break;
        w >>= 6;
    }
}

variable_types: n int

variable_types:
buflen
int *

variable_types:
cp
char **

variable_types:
w
unsigned int


AccountsLen

decompiled_code:
__int64 __fastcall AccountsLen(_QWORD *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1)
{
__int64 v1; // rax
unsigned int v2; // edx

if ( !*a1 )
return 0;
v1 = 1LL;
do
v2 = v1++;
while ( a1[v1 - 1] );
return v2;
}

original_code:
int AccountsLen(Account **array)
{
    int accounts_len;
    accounts_len = 0;
    while (array[accounts_len] != ((void *)0))
        accounts_len++;
    return accounts_len;
}

canonical_original_code:
int AccountsLen(struct Account_ **array)
{
    int accounts_len;
    accounts_len = 0;
    while (array[accounts_len] != ((void *)0))
        accounts_len++;
    return accounts_len;
}

variable_types: struct Account_ { char *login; int id; int rounds; char *salt; char *hash; char *password; } **


bruteforceAttack

original_code:
void bruteforceAttack(Account **accounts, int max_len)
{
    int i, j, k, nb, found;
    char *word = ((void *)0);
    char *hash = ((void *)0);
    Account *account = ((void *)0);
    if (accounts == ((void *)0))
        goto exit;
    if (max_len < 1)
        max_len = 4;
    nb = AccountsLen(accounts);
    found = 0;
    word = malloc((max_len + 1) * sizeof(char));
    if (word == ((void *)0))
    {
        fprintf(stderr, "error : memory allocation failed\n");
        goto exit;
    }
    for (i = 1; i <= max_len; i++)
    {
        for (j = 0; j < i; j++)
            word[j]='a';
        word[i]=0;
        do
        {
            if (found == nb)
                goto exit;
            printf(" %s\n", word);
            for (k = 0; k < nb; k++)
            {
                account = accounts[k];
                switch(account->id)
                {
                    case 1:
                        hash = crypt_md5(word, account->salt,
                                account->rounds);
                        break;
                    case 5:
                        hash = crypt_sha256(word, account->salt,
                                account->rounds);
                        break;
                    case 6:
                        hash = crypt_sha512(word, account->salt,
                                account->rounds);
                        break;
                }
                if (hash != ((void *)0))
                {
                    if (account->password == ((void *)0) &&
                        !strcmp(account->hash, hash))
                    {
                        printf("\nlogin    : %s\n", account->login);
                        printf("password : %s\n", word);
                        account->password = (char *) malloc(strlen(word)
                                                             + 1);
                        if (account->password == ((void *)0))
                            fprintf(stderr, "error : memory allocation " "failed\n");
                        memset(account->password + strlen(word), '\0', 1);
                        getchar();
                        found++;
                    }
                    free(hash);
                    hash = ((void *)0);
                }
            }
        } while (inc(word));
    }
    free(word);
    word = ((void *)0);
exit:
    if (hash != ((void *)0))
        free(hash);
    return ;
}

canonical_original_code:
void bruteforceAttack(struct Account_ **accounts, int max_len)
{
    int i; int j; int k; int nb; int found;
    char *word = ((void *)0);
    char *hash = ((void *)0);
    struct Account_ *account = ((void *)0);
    if (accounts == ((void *)0))
        goto exit;
    if (max_len < 1)
        max_len = 4;
    nb = AccountsLen(accounts);
    found = 0;
    word = malloc((max_len + 1) * sizeof(char));
    if (word == ((void *)0))
    {
        fprintf(stderr, "error : memory allocation failed\n");
        goto exit;
    }
    for (i = 1; i <= max_len; i++)
    {
        for (j = 0; j < i; j++)
            word[j]='a';
        word[i]=0;
        do
        {
            if (found == nb)
                goto exit;
            printf(" %s\n", word);
            for (k = 0; k < nb; k++)
            {
                account = accounts[k];
                switch(account->id)
                {
                    case 1:
                        hash = crypt_md5(word, account->salt,
                                account->rounds);
                        break;
                    case 5:
                        hash = crypt_sha256(word, account->salt,
                                account->rounds);
                        break;
                    case 6:
                        hash = crypt_sha512(word, account->salt,
                                account->rounds);
                        break;
                }
                if (hash != ((void *)0))
                {
                    if (account->password == ((void *)0) &&
                        !strcmp(account->hash, hash))
                    {
                        printf("\nlogin    : %s\n", account->login);
                        printf("password : %s\n", word);
                        account->password = (char *) malloc(strlen(word)
                                                             + 1);
                        if (account->password == ((void *)0))
                            fprintf(stderr, "error : memory allocation " "failed\n");
                        memset(account->password + strlen(word), '\0', 1);
                        getchar();
                        found++;
                    }
                    free(hash);
                    hash = ((void *)0);
                }
            }
        } while (inc(word));
    }
    free(word);
    word = ((void *)0);
exit:
    if (hash != ((void *)0))
        free(hash);
    return ;
}

variable_types: j int

variable_types: k int

variable_types: nb int

variable_types: found int

variable_types:
word
char *

variable_types:
hash
char *

variable_types: struct Account_ { char *login; int id; int rounds; char *salt; char *hash; char *password; } *


freeAccounts

decompiled_code:
void __fastcall freeAccounts(void *ptr)
{
void *v1; // r13
int v2; // eax
void ***v3; // rbp
void ***v4; // r12
void **v5; // rbx
void *v6; // rdi
void *v7; // rdi
void *v8; // rdi
void *v9; // rdi

if ( ptr )
{
v1 = ptr;
v2 = AccountsLen(ptr);
if ( v2 > 0 )
{
v3 = (void ***)ptr;
v4 = (void ***)((char *)ptr + 8 * (unsigned int)(v2 - 1) + 8);
do
{
v5 = *v3;
v6 = **v3;
if ( v6 )
free(v6);
v7 = v5[2];
if ( v7 )
free(v7);
v8 = v5[3];
if ( v8 )
free(v8);
v9 = v5[4];
if ( v9 )
free(v9);
free(v5);
++v3;
}
while ( v3 != v4 );
}
free(v1);
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
void *v1; // r13
int v2; // eax
void ***v3; // rbp
void ***v4; // r12
void **v5; // rbx
void *v6; // rdi
void *v7; // rdi
void *v8; // rdi
void *v9; // rdi

if ( ptr )
{
v1 = ptr;
v2 = func3(ptr);
if ( v2 > 0 )
{
v3 = (void ***)ptr;
v4 = (void ***)((char *)ptr + 8 * (unsigned int)(v2 - 1) + 8);
do
{
v5 = *v3;
v6 = **v3;
if ( v6 )
free(v6);
v7 = v5[2];
if ( v7 )
free(v7);
v8 = v5[3];
if ( v8 )
free(v8);
v9 = v5[4];
if ( v9 )
free(v9);
free(v5);
++v3;
}
while ( v3 != v4 );
}
free(v1);
}
}

original_code:
void freeAccounts(Account **array)
{
    int i, nb;
    Account *it;
    if (array == ((void *)0))
        return;
    nb = AccountsLen(array);
    for (i = 0; i < nb; i++)
    {
        it = array[i];
        if (it->login != ((void *)0))
            free(it->login);
        if (it->salt != ((void *)0))
            free(it->salt);
        if (it->hash != ((void *)0))
            free(it->hash);
        if (it->password != ((void *)0))
            free(it->password);
        free(it);
    }
    free(array);
}

canonical_original_code:
void freeAccounts(struct Account_ **array)
{
    int i; int nb;
    struct Account_ *it;
    if (array == ((void *)0))
        return;
    nb = AccountsLen(array);
    for (i = 0; i < nb; i++)
    {
        it = array[i];
        if (it->login != ((void *)0))
            free(it->login);
        if (it->salt != ((void *)0))
            free(it->salt);
        if (it->hash != ((void *)0))
            free(it->hash);
        if (it->password != ((void *)0))
            free(it->password);
        free(it);
    }
    free(array);
}

variable_types: i int

user_defined_types: struct Account_ { char *login; int id; int rounds; char *salt; char *hash; char *password; }


crack

decompiled_code:
void __fastcall crack(__int64 a1, int a2, const char *a3, int a4)
{
const char ***v6; // rax
const char ***v7; // r12
int v8; // eax
const char ***v9; // rbp
__int64 v10; // r13
const char *v11; // rsi
const char **v12; // rbx
int v13; // eax

v6 = (const char ***)readShadowFile();
if ( v6 )
{
v7 = v6;
if ( a2 == 1 )
dictionaryAttack(v6, a3);
else
bruteforceAttack(v6, a4);
v8 = AccountsLen(v7);
if ( v8 > 0 )
{
v9 = v7;
v10 = (__int64)&v7[(unsigned int)(v8 - 1) + 1];
do
{
v12 = *v9;
puts("\n********************************************************************");
printf("login : %s\n", *v12);
v13 = *((_DWORD *)v12 + 2);
switch ( v13 )
{
case 5:
puts("type : SHA-256");
break;
case 6:
puts("type : SHA-512");
break;
case 1:
puts("type : MD5");
break;
}
printf("salt : %s\n", v12[2]);
printf("rounds : %d\n", *((unsigned int *)v12 + 3));
printf("login : %s\n", *v12);
v11 = v12[4];
if ( v11 )
printf("password : %s\n", v11);
else
puts("password not found");
++v9;
}
while ( v9 != (const char ***)v10 );
}
freeAccounts(v7);
}
else
{
fwrite("error : no valid account found\n", 1uLL, 0x1FuLL, stderr);
}
}

canonical_decompiled_code:
void __fastcall func7(__int64 a1, int a2, const char *a3, int a4)
{
const char ***v6; // rax
const char ***v7; // r12
int v8; // eax
const char ***v9; // rbp
__int64 v10; // r13
const char *v11; // rsi
const char **v12; // rbx
int v13; // eax

v6 = (const char ***)readShadowFile();
if ( v6 )
{
v7 = v6;
if ( a2 == 1 )
func4(v6, a3);
else
func5(v6, a4);
v8 = func3(v7);
if ( v8 > 0 )
{
v9 = v7;
v10 = (__int64)&v7[(unsigned int)(v8 - 1) + 1];
do
{
v12 = *v9;
puts("\n********************************************************************");
printf("login : %s\n", *v12);
v13 = *((_DWORD *)v12 + 2);
switch ( v13 )
{
case 5:
puts("type : SHA-256");
break;
case 6:
puts("type : SHA-512");
break;
case 1:
puts("type : MD5");
break;
}
printf("salt : %s\n", v12[2]);
printf("rounds : %d\n", *((unsigned int *)v12 + 3));
printf("login : %s\n", *v12);
v11 = v12[4];
if ( v11 )
printf("password : %s\n", v11);
else
puts("password not found");
++v9;
}
while ( v9 != (const char ***)v10 );
}
func6(v7);
}
else
{
fwrite("error : no valid account found\n", 1uLL, 0x1FuLL, stderr);
}
}

original_code:
void crack(const char *shadow, MODE mode, const char *dico,
        int bruteforceLen)
{
    int i, nb;
    Account **accounts = ((void *)0);
    Account *account = ((void *)0);
    accounts = readShadowFile(shadow);
    if (accounts == ((void *)0))
    {
        fprintf(stderr, "error : no valid account found\n");
        return;
    }
    if (mode == DICO)
        dictionaryAttack(accounts, dico);
    else
        bruteforceAttack(accounts, bruteforceLen);
    nb = AccountsLen(accounts);
    for (i = 0; i < nb; i++)
    {
        account = accounts[i];
        printf("\n**************************************************" "******************\n");
        printf("login    : %s\n", account->login);
        switch(account->id)
        {
            case 1:
                printf("type     : MD5\n");
                break;
            case 5:
                printf("type     : SHA-256\n");
                break;
            case 6:
                printf("type     : SHA-512\n");
                break;
        }
        printf("salt     : %s\n", account->salt);
        printf("rounds   : %d\n", account->rounds);
        printf("login    : %s\n", account->login);
        if (account->password != ((void *)0))
            printf("password : %s\n", account->password);
        else
            printf("password not found\n");
    }
    freeAccounts(accounts);
}

canonical_original_code:
void crack(char *shadow, enum MODE mode, char *dico, int bruteforceLen)
{
    int i; int nb;
    struct Account_ **accounts = ((void *)0);
    struct Account_ *account = ((void *)0);
    accounts = readShadowFile(shadow);
    if (accounts == ((void *)0))
    {
        fprintf(stderr, "error : no valid account found\n");
        return;
    }
    if (mode == DICO)
        dictionaryAttack(accounts, dico);
    else
        bruteforceAttack(accounts, bruteforceLen);
    nb = AccountsLen(accounts);
    for (i = 0; i < nb; i++)
    {
        account = accounts[i];
        printf("\n**************************************************" "******************\n");
        printf("login    : %s\n", account->login);
        switch(account->id)
        {
            case 1:
                printf("type     : MD5\n");
                break;
            case 5:
                printf("type     : SHA-256\n");
                break;
            case 6:
                printf("type     : SHA-512\n");
                break;
        }
        printf("salt     : %s\n", account->salt);
        printf("rounds   : %d\n", account->rounds);
        printf("login    : %s\n", account->login);
        if (account->password != ((void *)0))
            printf("password : %s\n", account->password);
        else
            printf("password not found\n");
    }
    freeAccounts(accounts);
}

variable_types:
shadow
char *

variable_types:
mode
enum MODE { BRUTE_FORCE=0, DICO=1 }

variable_types:
dico
char *

variable_types: bruteforceLen int


decompiled_code:
__int64 __fastcall deriv_passwd(__m128i *a1, const char *a2, __int64 a3, int a4, unsigned int a5)
{
size_t v9; // rax
size_t v10; // rax
_BYTE v11[240]; // [rsp+0h] [rbp-148h] BYREF
__m128i v12; // [rsp+F0h] [rbp-58h] BYREF
__m128i v13; // [rsp+100h] [rbp-48h] BYREF
int v14[11]; // [rsp+11Ch] [rbp-2Ch] BYREF

v14[0] = 0;
if ( !a1 || !a2 )
return 1LL;
if ( a4 <= 0 || a3 == 0 || !a5 )
return 1LL;
sha2_starts(v11, 0LL);
v9 = strlen(a2);
sha2_update(v11, a2, v9);
sha2_update(v11, a3, a4);
sha2_update(v11, v14, 4LL);
sha2_finish(v11, &v12);
for ( v14[0] = 1; v14[0] < a5; ++v14[0] )
{
sha2_starts(v11, 0LL);
sha2_update(v11, &v12, 32LL);
v10 = strlen(a2);
sha2_update(v11, a2, v10);
sha2_update(v11, a3, a4);
sha2_update(v11, v14, 4LL);
sha2_finish(v11, &v12);
}
*a1 = _mm_loadu_si128(&v12);
a1[1] = _mm_loadu_si128(&v13);
return 0LL;
}

original_code:
int deriv_passwd(unsigned char *key, char *password,
   unsigned char *salt, int salt_len,
   unsigned int iterations)
{
 int ret;
 unsigned int i;
 unsigned char hash[32];
 sha2_context ctx;
 ret = 1;
 i = 0;
 if((key == ((void *)0)) || (password == ((void *)0)) || (salt == ((void *)0))
  || (salt_len <= 0) || (iterations == 0))
  goto cleanup;
 sha2_starts(&ctx, 0);
 sha2_update(&ctx, (unsigned char *)password, strlen(password));
 sha2_update(&ctx, salt, salt_len);
 sha2_update(&ctx, (unsigned char *)&i, sizeof(int));
 sha2_finish(&ctx, hash);
 for(i = 1; i < iterations; i++) {
  sha2_starts(&ctx, 0);
  sha2_update(&ctx, hash, 32);
  sha2_update(&ctx, (unsigned char *)password,
       strlen(password));
  sha2_update(&ctx, salt, salt_len);
  sha2_update(&ctx, (unsigned char *)&i, sizeof(int));
  sha2_finish(&ctx, hash);
 }
 memcpy(key, hash, 32);
 ret = 0;
cleanup:
 memset(&ctx, 0x00, sizeof(sha2_context));
 memset(hash, 0x00, 32);
 return ret;
}

canonical_original_code:
int deriv_passwd(unsigned char *key, char *password, unsigned char *salt, int salt_len, unsigned int iterations)
{
 int ret;
 unsigned int i;
 unsigned char hash[32];
 struct sha2_context ctx;
 ret = 1;
 i = 0;
 if((key == ((void *)0)) || (password == ((void *)0)) || (salt == ((void *)0))
  || (salt_len <= 0) || (iterations == 0))
  goto cleanup;
 sha2_starts(&ctx, 0);
 sha2_update(&ctx, (unsigned char *)password, strlen(password));
 sha2_update(&ctx, salt, salt_len);
 sha2_update(&ctx, (unsigned char *)&i, sizeof(int));
 sha2_finish(&ctx, hash);
 for(i = 1; i < iterations; i++) {
  sha2_starts(&ctx, 0);
  sha2_update(&ctx, hash, 32);
  sha2_update(&ctx, (unsigned char *)password,
       strlen(password));
  sha2_update(&ctx, salt, salt_len);
  sha2_update(&ctx, (unsigned char *)&i, sizeof(int));
  sha2_finish(&ctx, hash);
 }
 memcpy(key, hash, 32);
 ret = 0;
cleanup:
 memset(&ctx, 0x00, sizeof(sha2_context));
 memset(hash, 0x00, 32);
 return ret;
}

variable_types:
key
unsigned char *

variable_types:
password
char *

variable_types:
salt
unsigned char *

variable_types:
iterations
unsigned int

variable_types: ret int

variable_types:
i
unsigned int

variable_types:
hash
unsigned char [32]

variable_types: struct sha2_context { unsigned int total[2]; unsigned int state[8]; unsigned char buffer[64]; unsigned char ipad[64]; unsigned char opad[64]; int is224; }


decompiled_code:
__int64 __fastcall print_hex(unsigned __int8 *a1, int a2, const char *a3)
{
unsigned __int8 *v3; // rbx

printf(">>> %s\n", a3);
if ( a2 > 0 )
{
v3 = a1;
do
printf("%02X", *v3++);
while ( v3 != &a1[a2 - 1 + 1] );
}
putchar(10);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned __int8 *a1, int a2, const char *a3)
{
unsigned __int8 *v3; // rbx

printf(">>> %s\n", a3);
if ( a2 > 0 )
{
v3 = a1;
do
printf("%02X", *v3++);
while ( v3 != &a1[a2 - 1 + 1] );
}
putchar(10);
return 0LL;
}

original_code:
int print_hex(unsigned char *buffer, int buffer_len, char *id)
{
 int i;
 printf(">>> %s\n", id);
 for(i = 0; i < buffer_len; i++)
  printf("%02X", buffer[i]);
 printf("\n");
 return 0;
}

variable_types:
buffer
unsigned char *

variable_types:
id
char *


getPaddingOffset

decompiled_code:
__int64 __fastcall getPaddingOffset(__int64 a1, int a2)
{
__int64 result; // rax
_BYTE *v3; // rdi

result = (unsigned int)(a2 - 1);
if ( a2 - 1 >= 0 )
{
v3 = (_BYTE *)((int)result + a1);
do
{
if ( *v3 == 0x80 )
break;
result = (unsigned int)(result - 1);
--v3;
}
while ( (_DWORD)result != -1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, int a2)
{
__int64 result; // rax
_BYTE *v3; // rdi

result = (unsigned int)(a2 - 1);
if ( a2 - 1 >= 0 )
{
v3 = (_BYTE *)((int)result + a1);
do
{
if ( *v3 == 0x80 )
break;
result = (unsigned int)(result - 1);
--v3;
}
while ( (_DWORD)result != -1 );
}
return result;
}

original_code:
int getPaddingOffset(unsigned char* input_padd, int len)
{
 int i = 0;
 for (i = len - 1; i >= 0; i--)
  if (input_padd[i] == 0x80)
   return i;
 return i;
}

canonical_original_code:
int getPaddingOffset(unsigned char *input_padd, int len)
{
 int i = 0;
 for (i = len - 1; i >= 0; i--)
  if (input_padd[i] == 0x80)
   return i;
 return i;
}

variable_types: len int


decompiled_code:
__int64 __fastcall unprotect_buffer(_QWORD *a1, _DWORD *a2, char *a3, int a4, __int64 a5, __int64 a6, unsigned int a7, unsigned int a8)
{
int v10; // er15
void *v11; // rax
void *v12; // rbp
void *v13; // r13
unsigned int v14; // ebx
int v15; // er14
_BYTE *v16; // rax
_BYTE *v17; // r12
char v21[240]; // [rsp+20h] [rbp-2F8h] BYREF
char v22[288]; // [rsp+110h] [rbp-208h] BYREF
__int128 s2[2]; // [rsp+230h] [rbp-E8h] BYREF
__m128i v24; // [rsp+250h] [rbp-C8h] BYREF
__m128i v25; // [rsp+260h] [rbp-B8h]
int v26; // [rsp+270h] [rbp-A8h]
char s1[32]; // [rsp+280h] [rbp-98h] BYREF
char v28[32]; // [rsp+2A0h] [rbp-78h] BYREF
__m128i v29; // [rsp+2C0h] [rbp-58h] BYREF
__m128i v30[4]; // [rsp+2D0h] [rbp-48h] BYREF

v10 = a4 - 32;
v11 = malloc(a4 - 32);
if ( v11 )
{
v12 = v11;
memcpy(v11, a3, v10);
v13 = malloc(v10);
if ( v13 )
{
s2[0] = (__int128)_mm_loadu_si128((const __m128i *)&a3[a4 - 32]);
s2[1] = (__int128)_mm_loadu_si128((const __m128i *)&a3[a4 - 16]);
if ( (unsigned int)deriv_passwd(&v29, a5, a6, a7, a8) )
{
fwrite("error: deriv_passwd failed\n", 1uLL, 0x1BuLL, stderr);
v14 = 1;
}
else
{
v24 = _mm_loadu_si128(&v29);
v25 = _mm_loadu_si128(v30);
v26 = 0;
sha2(&v24, 36LL, v28, 0LL);
v24 = _mm_loadu_si128(&v29);
v25 = _mm_loadu_si128(v30);
v26 = 1;
sha2(&v24, 36LL, s1, 0LL);
sha2_hmac_starts(v21, s1, 32LL, 0LL);
sha2_hmac_update(v21, v12, v10);
sha2_hmac_finish(v21, s1);
if ( !memcmp(s1, s2, 0x20uLL) )
{
if ( (unsigned int)aes_setkey_dec(v22, v28, 256LL) )
{
fwrite("error : aes_setkey_dec failed\n", 1uLL, 0x1EuLL, stderr);
v14 = 1;
}
else
{
v14 = aes_crypt_cbc(v22, 0LL, v10, &iv, v12, v13);
if ( v14 )
{
fwrite("error : aes_crypt_cbc failed\n", 1uLL, 0x1DuLL, stderr);
v14 = 1;
}
else
{
v15 = getPaddingOffset((__int64)v13, v10);
v16 = malloc(v15 + 1LL);
v17 = v16;
if ( v16 )
{
memcpy(v16, v13, v15);
v17[v15] = 0;
*a1 = v17;
*a2 = v15;
}
else
{
fwrite("error : memory allocation failed\n", 1uLL, 0x21uLL, stderr);
v14 = 1;
}
}
}
}
else
{
fwrite("error : keys are differents\n", 1uLL, 0x1CuLL, stderr);
v14 = 1;
}
}
free(v13);
}
else
{
fwrite("error : memory allocation failed\n", 1uLL, 0x21uLL, stderr);
v14 = 1;
}
free(v12);
}
else
{
fwrite("error : memory allocation failed\n", 1uLL, 0x21uLL, stderr);
v14 = 1;
}
return v14;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, _DWORD *a2, char *a3, int a4, __int64 a5, __int64 a6, unsigned int a7, unsigned int a8)
{
int v10; // er15
void *v11; // rax
void *v12; // rbp
void *v13; // r13
unsigned int v14; // ebx
int v15; // er14
_BYTE *v16; // rax
_BYTE *v17; // r12
char v21[240]; // [rsp+20h] [rbp-2F8h] BYREF
char v22[288]; // [rsp+110h] [rbp-208h] BYREF
__int128 s2[2]; // [rsp+230h] [rbp-E8h] BYREF
__m128i v24; // [rsp+250h] [rbp-C8h] BYREF
__m128i v25; // [rsp+260h] [rbp-B8h]
int v26; // [rsp+270h] [rbp-A8h]
char s1[32]; // [rsp+280h] [rbp-98h] BYREF
char v28[32]; // [rsp+2A0h] [rbp-78h] BYREF
__m128i v29; // [rsp+2C0h] [rbp-58h] BYREF
__m128i v30[4]; // [rsp+2D0h] [rbp-48h] BYREF

v10 = a4 - 32;
v11 = malloc(a4 - 32);
if ( v11 )
{
v12 = v11;
memcpy(v11, a3, v10);
v13 = malloc(v10);
if ( v13 )
{
s2[0] = (__int128)_mm_loadu_si128((const __m128i *)&a3[a4 - 32]);
s2[1] = (__int128)_mm_loadu_si128((const __m128i *)&a3[a4 - 16]);
if ( (unsigned int)deriv_passwd(&v29, a5, a6, a7, a8) )
{
fwrite("error: deriv_passwd failed\n", 1uLL, 0x1BuLL, stderr);
v14 = 1;
}
else
{
v24 = _mm_loadu_si128(&v29);
v25 = _mm_loadu_si128(v30);
v26 = 0;
sha2(&v24, 36LL, v28, 0LL);
v24 = _mm_loadu_si128(&v29);
v25 = _mm_loadu_si128(v30);
v26 = 1;
sha2(&v24, 36LL, s1, 0LL);
sha2_hmac_starts(v21, s1, 32LL, 0LL);
sha2_hmac_update(v21, v12, v10);
sha2_hmac_finish(v21, s1);
if ( !memcmp(s1, s2, 0x20uLL) )
{
if ( (unsigned int)aes_setkey_dec(v22, v28, 256LL) )
{
fwrite("error : aes_setkey_dec failed\n", 1uLL, 0x1EuLL, stderr);
v14 = 1;
}
else
{
v14 = aes_crypt_cbc(v22, 0LL, v10, &iv, v12, v13);
if ( v14 )
{
fwrite("error : aes_crypt_cbc failed\n", 1uLL, 0x1DuLL, stderr);
v14 = 1;
}
else
{
v15 = func0((__int64)v13, v10);
v16 = malloc(v15 + 1LL);
v17 = v16;
if ( v16 )
{
memcpy(v16, v13, v15);
v17[v15] = 0;
*a1 = v17;
*a2 = v15;
}
else
{
fwrite("error : memory allocation failed\n", 1uLL, 0x21uLL, stderr);
v14 = 1;
}
}
}
}
else
{
fwrite("error : keys are differents\n", 1uLL, 0x1CuLL, stderr);
v14 = 1;
}
}
free(v13);
}
else
{
fwrite("error : memory allocation failed\n", 1uLL, 0x21uLL, stderr);
v14 = 1;
}
free(v12);
}
else
{
fwrite("error : memory allocation failed\n", 1uLL, 0x21uLL, stderr);
v14 = 1;
}
return v14;
}

original_code:
int unprotect_buffer(unsigned char **output, int *output_len,
       unsigned char *input, int input_len,
       char *password,
       unsigned char *salt, int salt_len,
           unsigned int iterations)
{
 int ret, i, offset;
 unsigned char k_m[32];
 unsigned char k_c[32];
 unsigned char k_i[32];
 unsigned char tmp_1[36];
 unsigned char tmp_2[32];
 unsigned char *input_padd;
 unsigned char *cipher;
 unsigned char *plain;
 aes_context aes_ctx;
 sha2_context sha_ctx;
 ret = 1;
 i = 0;
 offset = 0;
 input_padd = ((void *)0);
 cipher = ((void *)0);
 plain = ((void *)0);
 cipher = (unsigned char *) malloc((input_len - 32) * sizeof(char));
 if (cipher == ((void *)0)) {
  fprintf(stderr, "error : memory allocation failed\n");
  ret = 1;
  goto cleanup;
 }
 memcpy(cipher, input, input_len - 32);
 input_padd = (unsigned char *) malloc((input_len - 32) *
            sizeof(char));
 if (input_padd == ((void *)0)) {
  fprintf(stderr, "error : memory allocation failed\n");
  ret = 1;
  goto cleanup;
 }
 memcpy(tmp_2, input + (input_len - 32), 32);
 ret = deriv_passwd(k_m, password, salt, salt_len, iterations);
 if(ret != 0) {
  fprintf(stderr, "error: deriv_passwd failed\n");
  ret = 1;
  goto cleanup;
 }
 i = 0;
 memcpy(tmp_1, k_m, 32);
 memcpy(tmp_1+32, &i, sizeof(int));
 sha2(tmp_1, 36, k_c, 0);
 i++;
 memcpy(tmp_1, k_m, 32);
 memcpy(tmp_1+32, &i, sizeof(int));
 sha2(tmp_1, 36, k_i, 0);
 sha2_hmac_starts(&sha_ctx, k_i, 32, 0);
 sha2_hmac_update(&sha_ctx, cipher, input_len - 32);
 sha2_hmac_finish(&sha_ctx, k_i);
 if (memcmp(k_i, tmp_2, 32) != 0) {
  fprintf(stderr, "error : keys are differents\n");
  ret = 1;
  goto cleanup;
 }
 ret = aes_setkey_dec(&aes_ctx, k_c, 256);
 if (ret != 0) {
  fprintf(stderr, "error : aes_setkey_dec failed\n");
  ret = 1;
  goto cleanup;
 }
 ret = aes_crypt_cbc(&aes_ctx, 0, input_len - 32, iv,
       cipher, input_padd);
 if (ret != 0) {
  fprintf(stderr, "error : aes_crypt_cbc failed\n");
  ret = 1;
  goto cleanup;
 }
 offset = getPaddingOffset(input_padd, input_len - 32);
 plain = (unsigned char *) malloc(offset * sizeof(char) + 1);
 if (plain == ((void *)0)) {
  fprintf(stderr, "error : memory allocation failed\n");
  ret = 1;
  goto cleanup;
 }
 memcpy(plain, input_padd, offset);
    plain[offset * sizeof(char)] = '\0';
 *output = plain;
 *output_len = offset;
 ret = 0;
cleanup:
 if (input_padd != ((void *)0)) {
  memset(input_padd, 0x00, input_len - 32);
  free(input_padd);
 }
 if (cipher != ((void *)0)) {
  memset(cipher, 0x00, input_len - 32);
  free(cipher);
 }
 memset(&aes_ctx, 0x00, sizeof(aes_context));
 memset(&sha_ctx, 0x00, sizeof(sha_ctx));
 memset(k_m, 0x00, 32);
 memset(k_c, 0x00, 32);
 memset(k_i, 0x00, 32);
 memset(tmp_1, 0x00, 36);
 memset(tmp_2, 0x00, 32);
 i = 0;
 return ret;
}

canonical_original_code:
int unprotect_buffer(unsigned char **output, int *output_len, unsigned char *input, int input_len, char *password, unsigned char *salt, int salt_len, unsigned int iterations)
{
 int ret; int i; int offset;
 unsigned char k_m[32];
 unsigned char k_c[32];
 unsigned char k_i[32];
 unsigned char tmp_1[36];
 unsigned char tmp_2[32];
 unsigned char *input_padd;
 unsigned char *cipher;
 unsigned char *plain;
 struct aes_context aes_ctx;
 struct sha2_context sha_ctx;
 ret = 1;
 i = 0;
 offset = 0;
 input_padd = ((void *)0);
 cipher = ((void *)0);
 plain = ((void *)0);
 cipher = (unsigned char *) malloc((input_len - 32) * sizeof(char));
 if (cipher == ((void *)0)) {
  fprintf(stderr, "error : memory allocation failed\n");
  ret = 1;
  goto cleanup;
 }
 memcpy(cipher, input, input_len - 32);
 input_padd = (unsigned char *) malloc((input_len - 32) *
            sizeof(char));
 if (input_padd == ((void *)0)) {
  fprintf(stderr, "error : memory allocation failed\n");
  ret = 1;
  goto cleanup;
 }
 memcpy(tmp_2, input + (input_len - 32), 32);
 ret = deriv_passwd(k_m, password, salt, salt_len, iterations);
 if(ret != 0) {
  fprintf(stderr, "error: deriv_passwd failed\n");
  ret = 1;
  goto cleanup;
 }
 i = 0;
 memcpy(tmp_1, k_m, 32);
 memcpy(tmp_1+32, &i, sizeof(int));
 sha2(tmp_1, 36, k_c, 0);
 i++;
 memcpy(tmp_1, k_m, 32);
 memcpy(tmp_1+32, &i, sizeof(int));
 sha2(tmp_1, 36, k_i, 0);
 sha2_hmac_starts(&sha_ctx, k_i, 32, 0);
 sha2_hmac_update(&sha_ctx, cipher, input_len - 32);
 sha2_hmac_finish(&sha_ctx, k_i);
 if (memcmp(k_i, tmp_2, 32) != 0) {
  fprintf(stderr, "error : keys are differents\n");
  ret = 1;
  goto cleanup;
 }
 ret = aes_setkey_dec(&aes_ctx, k_c, 256);
 if (ret != 0) {
  fprintf(stderr, "error : aes_setkey_dec failed\n");
  ret = 1;
  goto cleanup;
 }
 ret = aes_crypt_cbc(&aes_ctx, 0, input_len - 32, iv,
       cipher, input_padd);
 if (ret != 0) {
  fprintf(stderr, "error : aes_crypt_cbc failed\n");
  ret = 1;
  goto cleanup;
 }
 offset = getPaddingOffset(input_padd, input_len - 32);
 plain = (unsigned char *) malloc(offset * sizeof(char) + 1);
 if (plain == ((void *)0)) {
  fprintf(stderr, "error : memory allocation failed\n");
  ret = 1;
  goto cleanup;
 }
 memcpy(plain, input_padd, offset);
    plain[offset * sizeof(char)] = '\0';
 *output = plain;
 *output_len = offset;
 ret = 0;
cleanup:
 if (input_padd != ((void *)0)) {
  memset(input_padd, 0x00, input_len - 32);
  free(input_padd);
 }
 if (cipher != ((void *)0)) {
  memset(cipher, 0x00, input_len - 32);
  free(cipher);
 }
 memset(&aes_ctx, 0x00, sizeof(aes_context));
 memset(&sha_ctx, 0x00, sizeof(sha_ctx));
 memset(k_m, 0x00, 32);
 memset(k_c, 0x00, 32);
 memset(k_i, 0x00, 32);
 memset(tmp_1, 0x00, 36);
 memset(tmp_2, 0x00, 32);
 i = 0;
 return ret;
}

variable_types:
output
unsigned char **

variable_types:
input
unsigned char *

variable_types: offset int

variable_types:
cipher
unsigned char *

variable_types:
plain
unsigned char *

variable_types: struct aes_context { int nr; unsigned int *rk; unsigned int buf[68]; }

user_defined_types: struct sha2_context { unsigned int total[2]; unsigned int state[8]; unsigned char buffer[64]; unsigned char ipad[64]; unsigned char opad[64]; int is224; }


original_code:
int protect_buffer(unsigned char **output, int *output_len,
       unsigned char *input, int input_len,
     char *password,
      unsigned char *salt, int salt_len,
     unsigned int iterations)
{
 int i, pad_len, ret;
 unsigned char k_m[32];
 unsigned char k_c[32];
 unsigned char k_i[32];
 unsigned char tmp_1[36];
 unsigned char *input_padd;
 unsigned char *cipher;
 aes_context aes_ctx;
 i = 0;
 pad_len = 0;
 ret = 1;
 input_padd = ((void *)0);
 cipher = ((void *)0);
 ret = deriv_passwd(k_m, password, salt, salt_len, iterations);
 if(ret != 0) {
  fprintf(stderr, "error: deriv_passwd failed\n");
  return 1;
 }
 i = 0;
 memcpy(tmp_1, k_m, 32);
 memcpy(tmp_1+32, &i, sizeof(int));
 sha2(tmp_1, 36, k_c, 0);
 i ++;
 memcpy(tmp_1, k_m, 32);
 memcpy(tmp_1+32, &i, sizeof(int));
 sha2(tmp_1, 36, k_i, 0);
 pad_len = 16 - (input_len % 16);
 input_padd = (unsigned char *) malloc((input_len + pad_len) *
           sizeof(char));
 if(input_padd == ((void *)0)) {
  fprintf(stderr, "error : memory allocation failed\n");
  ret = 1;
  goto cleanup;
 }
 cipher = (unsigned char *)malloc((input_len + pad_len + 32) *
      sizeof(char));
 if(cipher == ((void *)0)) {
  fprintf(stderr, "error : memory allocation failed\n");
  ret = 1;
  goto cleanup;
 }
 memcpy(input_padd, input, input_len);
 memcpy(input_padd+input_len, padding, pad_len);
 ret = aes_setkey_enc(&aes_ctx, k_c, 256);
 if(ret != 0) {
  fprintf(stderr, "error : aes_setkey_enc failed\n");
  ret = 1;
  goto cleanup;
 }
 ret = aes_crypt_cbc(&aes_ctx, 1, (size_t)
       (input_len + pad_len), iv, input_padd, cipher);
 if(ret != 0) {
  fprintf(stderr, "error : aes_crypt_cbc failed\n");
  ret = 1;
  goto cleanup;
 }
 sha2_hmac(k_i, 32, cipher, input_len + pad_len, cipher +
    input_len + pad_len, 0);
 *output = cipher;
 *output_len = input_len + pad_len + 32;
 ret = 0;
cleanup:
 if(input_padd != ((void *)0)) {
  memset(input_padd, 0x00, input_len + pad_len);
  free(input_padd);
 }
 memset(&aes_ctx, 0x00, sizeof(aes_context));
 memset(k_m, 0x00, 32);
 memset(k_c, 0x00, 32);
 memset(k_i, 0x00, 32);
 memset(tmp_1, 0x00, 36);
 pad_len = 0;
 i = 0;
 return ret;
}

canonical_original_code:
int protect_buffer(unsigned char **output, int *output_len, unsigned char *input, int input_len, char *password, unsigned char *salt, int salt_len, unsigned int iterations)
{
 int i; int pad_len; int ret;
 unsigned char k_m[32];
 unsigned char k_c[32];
 unsigned char k_i[32];
 unsigned char tmp_1[36];
 unsigned char *input_padd;
 unsigned char *cipher;
 struct aes_context aes_ctx;
 i = 0;
 pad_len = 0;
 ret = 1;
 input_padd = ((void *)0);
 cipher = ((void *)0);
 ret = deriv_passwd(k_m, password, salt, salt_len, iterations);
 if(ret != 0) {
  fprintf(stderr, "error: deriv_passwd failed\n");
  return 1;
 }
 i = 0;
 memcpy(tmp_1, k_m, 32);
 memcpy(tmp_1+32, &i, sizeof(int));
 sha2(tmp_1, 36, k_c, 0);
 i ++;
 memcpy(tmp_1, k_m, 32);
 memcpy(tmp_1+32, &i, sizeof(int));
 sha2(tmp_1, 36, k_i, 0);
 pad_len = 16 - (input_len % 16);
 input_padd = (unsigned char *) malloc((input_len + pad_len) *
           sizeof(char));
 if(input_padd == ((void *)0)) {
  fprintf(stderr, "error : memory allocation failed\n");
  ret = 1;
  goto cleanup;
 }
 cipher = (unsigned char *)malloc((input_len + pad_len + 32) *
      sizeof(char));
 if(cipher == ((void *)0)) {
  fprintf(stderr, "error : memory allocation failed\n");
  ret = 1;
  goto cleanup;
 }
 memcpy(input_padd, input, input_len);
 memcpy(input_padd+input_len, padding, pad_len);
 ret = aes_setkey_enc(&aes_ctx, k_c, 256);
 if(ret != 0) {
  fprintf(stderr, "error : aes_setkey_enc failed\n");
  ret = 1;
  goto cleanup;
 }
 ret = aes_crypt_cbc(&aes_ctx, 1, (unsigned long)
       (input_len + pad_len), iv, input_padd, cipher);
 if(ret != 0) {
  fprintf(stderr, "error : aes_crypt_cbc failed\n");
  ret = 1;
  goto cleanup;
 }
 sha2_hmac(k_i, 32, cipher, input_len + pad_len, cipher +
    input_len + pad_len, 0);
 *output = cipher;
 *output_len = input_len + pad_len + 32;
 ret = 0;
cleanup:
 if(input_padd != ((void *)0)) {
  memset(input_padd, 0x00, input_len + pad_len);
  free(input_padd);
 }
 memset(&aes_ctx, 0x00, sizeof(aes_context));
 memset(k_m, 0x00, 32);
 memset(k_c, 0x00, 32);
 memset(k_i, 0x00, 32);
 memset(tmp_1, 0x00, 36);
 pad_len = 0;
 i = 0;
 return ret;
}

variable_types: i int

user_defined_types: struct aes_context { int nr; unsigned int *rk; unsigned int buf[68]; }


decompiled_code:
char *__fastcall crypt_md5(char *s, const char *a2, unsigned __int64 a3)
{
const char *v4; // r12
const char *v6; // rcx
const char *v7; // rax
unsigned int v8; // ebx
size_t v9; // rax
size_t v10; // rax
size_t v11; // rax
int v12; // eax
int v13; // ebx
unsigned int v14; // er13
unsigned int v15; // edx
unsigned int i; // ebx
unsigned int v17; // ebx
size_t v18; // rax
size_t v19; // rax
size_t v20; // rax
char *v21; // rbx
int v22; // eax
int v23; // ebp
char *v24; // rbx
size_t n; // [rsp+0h] [rbp-298h]
int v27; // [rsp+8h] [rbp-290h]
char dest[4]; // [rsp+10h] [rbp-288h] BYREF
char src[120]; // [rsp+18h] [rbp-280h] BYREF
__int64 v30; // [rsp+90h] [rbp-208h] BYREF
__int64 v31; // [rsp+98h] [rbp-200h]
char v32[224]; // [rsp+A0h] [rbp-1F8h] BYREF
char v33[280]; // [rsp+180h] [rbp-118h] BYREF

v4 = a2;
if ( !memcmp(a2, &unk_52A, 3uLL) )
v4 += 3;
if ( !*v4 || *v4 == 36 )
{
LODWORD(v6) = (_DWORD)v4;
}
else
{
v6 = v4 + 8;
v7 = v4;
while ( *++v7 && *v7 != 36 )
{
if ( v7 == v6 )
goto LABEL_9;
}
LODWORD(v6) = (_DWORD)v7;
}
LABEL_9:
v8 = (_DWORD)v6 - (_DWORD)v4;
v27 = (_DWORD)v6 - (_DWORD)v4;
md5_starts(v33);
v9 = strlen(s);
md5_update(v33, s, v9);
md5_update(v33, &unk_52A, 3LL);
n = v8;
md5_update(v33, v4, v8);
md5_starts(v32);
v10 = strlen(s);
md5_update(v32, s, v10);
md5_update(v32, v4, v8);
v11 = strlen(s);
md5_update(v32, s, v11);
md5_finish(v32, &v30);
v12 = strlen(s);
v13 = v12;
if ( v12 > 0 )
{
v14 = v12 - 16 - ((v12 - 1) & 0xFFFFFFF0);
do
{
v15 = 16;
if ( v13 <= 16 )
v15 = v13;
md5_update(v33, &v30, v15);
v13 -= 16;
}
while ( v13 != v14 );
}
v30 = 0LL;
v31 = 0LL;
for ( i = strlen(s); i; i >>= 1 )
{
if ( (i & 1) != 0 )
md5_update(v33, &v30, 1LL);
else
md5_update(v33, s, 1LL);
}
strcpy(dest, "$1$");
strncat(dest, v4, n);
*(_WORD *)&dest[strlen(dest)] = 36;
md5_finish(v33, &v30);
if ( a3 )
{
v17 = 0;
do
{
md5_starts(v32);
if ( (v17 & 1) != 0 )
{
v20 = strlen(s);
md5_update(v32, s, v20);
}
else
{
md5_update(v32, &v30, 16LL);
}
if ( v17 != 3 * (v17 / 3) )
md5_update(v32, v4, n);
if ( v17 != 7 * (v17 / 7) )
{
v18 = strlen(s);
md5_update(v32, s, v18);
}
if ( (v17 & 1) != 0 )
{
md5_update(v32, &v30, 16LL);
}
else
{
v19 = strlen(s);
md5_update(v32, s, v19);
}
md5_finish(v32, &v30);
++v17;
}
while ( v17 < a3 );
}
v21 = &dest[strlen(dest)];
crypt_to64(v21, BYTE4(v31) | (BYTE6(v30) << 8) | ((unsigned __int8)v30 << 16), 4LL);
crypt_to64(v21 + 4, BYTE5(v31) | (HIBYTE(v30) << 8) | (BYTE1(v30) << 16), 4LL);
crypt_to64(v21 + 8, BYTE6(v31) | ((unsigned __int8)v31 << 8) | (BYTE2(v30) << 16), 4LL);
crypt_to64(v21 + 12, HIBYTE(v31) | (BYTE1(v31) << 8) | (BYTE3(v30) << 16), 4LL);
crypt_to64(v21 + 16, BYTE5(v30) | (BYTE2(v31) << 8) | (BYTE4(v30) << 16), 4LL);
crypt_to64(v21 + 20, BYTE3(v31), 2LL);
v21[22] = 0;
v22 = strlen(dest) - v27;
v23 = v22 - 8;
v24 = (char *)malloc(v22 - 7);
if ( v24 )
{
strncpy(v24, &src[v27], v23);
v24[v23] = 0;
}
else
{
fwrite("error : memory allocation failed\n", 1uLL, 0x21uLL, stderr);
}
return v24;
}

canonical_decompiled_code:
char *__fastcall func0(char *s, const char *a2, unsigned __int64 a3)
{
const char *v4; // r12
const char *v6; // rcx
const char *v7; // rax
unsigned int v8; // ebx
size_t v9; // rax
size_t v10; // rax
size_t v11; // rax
int v12; // eax
int v13; // ebx
unsigned int v14; // er13
unsigned int v15; // edx
unsigned int i; // ebx
unsigned int v17; // ebx
size_t v18; // rax
size_t v19; // rax
size_t v20; // rax
char *v21; // rbx
int v22; // eax
int v23; // ebp
char *v24; // rbx
size_t n; // [rsp+0h] [rbp-298h]
int v27; // [rsp+8h] [rbp-290h]
char dest[4]; // [rsp+10h] [rbp-288h] BYREF
char src[120]; // [rsp+18h] [rbp-280h] BYREF
__int64 v30; // [rsp+90h] [rbp-208h] BYREF
__int64 v31; // [rsp+98h] [rbp-200h]
char v32[224]; // [rsp+A0h] [rbp-1F8h] BYREF
char v33[280]; // [rsp+180h] [rbp-118h] BYREF

v4 = a2;
if ( !memcmp(a2, &unk_52A, 3uLL) )
v4 += 3;
if ( !*v4 || *v4 == 36 )
{
LODWORD(v6) = (_DWORD)v4;
}
else
{
v6 = v4 + 8;
v7 = v4;
while ( *++v7 && *v7 != 36 )
{
if ( v7 == v6 )
goto LABEL_9;
}
LODWORD(v6) = (_DWORD)v7;
}
LABEL_9:
v8 = (_DWORD)v6 - (_DWORD)v4;
v27 = (_DWORD)v6 - (_DWORD)v4;
md5_starts(v33);
v9 = strlen(s);
md5_update(v33, s, v9);
md5_update(v33, &unk_52A, 3LL);
n = v8;
md5_update(v33, v4, v8);
md5_starts(v32);
v10 = strlen(s);
md5_update(v32, s, v10);
md5_update(v32, v4, v8);
v11 = strlen(s);
md5_update(v32, s, v11);
md5_finish(v32, &v30);
v12 = strlen(s);
v13 = v12;
if ( v12 > 0 )
{
v14 = v12 - 16 - ((v12 - 1) & 0xFFFFFFF0);
do
{
v15 = 16;
if ( v13 <= 16 )
v15 = v13;
md5_update(v33, &v30, v15);
v13 -= 16;
}
while ( v13 != v14 );
}
v30 = 0LL;
v31 = 0LL;
for ( i = strlen(s); i; i >>= 1 )
{
if ( (i & 1) != 0 )
md5_update(v33, &v30, 1LL);
else
md5_update(v33, s, 1LL);
}
strcpy(dest, "$1$");
strncat(dest, v4, n);
*(_WORD *)&dest[strlen(dest)] = 36;
md5_finish(v33, &v30);
if ( a3 )
{
v17 = 0;
do
{
md5_starts(v32);
if ( (v17 & 1) != 0 )
{
v20 = strlen(s);
md5_update(v32, s, v20);
}
else
{
md5_update(v32, &v30, 16LL);
}
if ( v17 != 3 * (v17 / 3) )
md5_update(v32, v4, n);
if ( v17 != 7 * (v17 / 7) )
{
v18 = strlen(s);
md5_update(v32, s, v18);
}
if ( (v17 & 1) != 0 )
{
md5_update(v32, &v30, 16LL);
}
else
{
v19 = strlen(s);
md5_update(v32, s, v19);
}
md5_finish(v32, &v30);
++v17;
}
while ( v17 < a3 );
}
v21 = &dest[strlen(dest)];
crypt_to64(v21, BYTE4(v31) | (BYTE6(v30) << 8) | ((unsigned __int8)v30 << 16), 4LL);
crypt_to64(v21 + 4, BYTE5(v31) | (HIBYTE(v30) << 8) | (BYTE1(v30) << 16), 4LL);
crypt_to64(v21 + 8, BYTE6(v31) | ((unsigned __int8)v31 << 8) | (BYTE2(v30) << 16), 4LL);
crypt_to64(v21 + 12, HIBYTE(v31) | (BYTE1(v31) << 8) | (BYTE3(v30) << 16), 4LL);
crypt_to64(v21 + 16, BYTE5(v30) | (BYTE2(v31) << 8) | (BYTE4(v30) << 16), 4LL);
crypt_to64(v21 + 20, BYTE3(v31), 2LL);
v21[22] = 0;
v22 = strlen(dest) - v27;
v23 = v22 - 8;
v24 = (char *)malloc(v22 - 7);
if ( v24 )
{
strncpy(v24, &src[v27], v23);
v24[v23] = 0;
}
else
{
fwrite("error : memory allocation failed\n", 1uLL, 0x21uLL, stderr);
}
return v24;
}

original_code:
char* crypt_md5(const char *pw, const char *salt, size_t rounds)
{
 md5_context ctx,ctx1;
 unsigned long l;
 int sl, pl, out_len;
 u_int i;
 u_char final[16];
 const char *sp, *ep;
 char passwd[120], *p;
 const char *magic = "$1$";
 char *output;
 sp = salt;
 if(!strncmp(sp, magic, strlen(magic)))
  sp += strlen(magic);
 for(ep = sp; *ep && *ep != '$' && ep < (sp + 8); ep++)
  continue;
 sl = ep - sp;
 md5_starts(&ctx);
 md5_update(&ctx, (unsigned char*)pw, strlen(pw));
 md5_update(&ctx, (unsigned char*)magic, strlen(magic));
 md5_update(&ctx, (unsigned char*)sp, (u_int)sl);
 md5_starts(&ctx1);
 md5_update(&ctx1, (unsigned char*)pw, strlen(pw));
 md5_update(&ctx1, (unsigned char*)sp, (u_int)sl);
 md5_update(&ctx1, (unsigned char*)pw, strlen(pw));
 md5_finish(&ctx1, final);
 for(pl = (int)strlen(pw); pl > 0; pl -= 16)
  md5_update(&ctx, (unsigned char*)final,
      (u_int)(pl > 16 ? 16 : pl));
 memset(final, 0, sizeof(final));
 for (i = strlen(pw); i; i >>= 1)
  if(i & 1)
      md5_update(&ctx, (unsigned char*)final, 1);
  else
      md5_update(&ctx, (unsigned char*)pw, 1);
 strcpy(passwd, magic);
 strncat(passwd, sp, (u_int)sl);
 strcat(passwd, "$");
 md5_finish(&ctx, final);
 for(i = 0; i < rounds; i++) {
  md5_starts(&ctx1);
  if(i & 1)
   md5_update(&ctx1, (unsigned char*)pw, strlen(pw));
  else
   md5_update(&ctx1, (unsigned char*)final, 16);
  if(i % 3)
   md5_update(&ctx1, (unsigned char*)sp, (u_int)sl);
  if(i % 7)
   md5_update(&ctx1, (unsigned char*)pw, strlen(pw));
  if(i & 1)
   md5_update(&ctx1, (unsigned char*)final, 16);
  else
   md5_update(&ctx1, (unsigned char*)pw, strlen(pw));
  md5_finish(&ctx1, final);
 }
 p = passwd + strlen(passwd);
 l = (final[ 0]<<16) | (final[ 6]<<8) | final[12];
 _crypt_to64(p, l, 4); p += 4;
 l = (final[ 1]<<16) | (final[ 7]<<8) | final[13];
 _crypt_to64(p, l, 4); p += 4;
 l = (final[ 2]<<16) | (final[ 8]<<8) | final[14];
 _crypt_to64(p, l, 4); p += 4;
 l = (final[ 3]<<16) | (final[ 9]<<8) | final[15];
 _crypt_to64(p, l, 4); p += 4;
 l = (final[ 4]<<16) | (final[10]<<8) | final[ 5];
 _crypt_to64(p, l, 4); p += 4;
 l = final[11];
 _crypt_to64(p, l, 2); p += 2;
 *p = '\0';
 out_len = strlen(passwd) - sl - sizeof(magic);
 output = (char *) malloc(out_len + 1);
 if (output == ((void *)0))
 {
  fprintf(stderr, "error : memory allocation failed\n");
  return ((void *)0);
 }
 strncpy(output, passwd + sizeof(magic) + sl, out_len);
 output[out_len] = '\0';
 return (output);
}

canonical_original_code:
char *crypt_md5(char *pw, char *salt, unsigned long rounds)
{
 struct md5_context ctx; struct md5_context ctx1;
 unsigned long l;
 int sl; int pl; int out_len;
 unsigned int i;
 unsigned char final[16];
 char *sp; char *ep;
 char passwd[120]; char *p;
 char *magic = "$1$";
 char *output;
 sp = salt;
 if(!strncmp(sp, magic, strlen(magic)))
  sp += strlen(magic);
 for(ep = sp; *ep && *ep != '$' && ep < (sp + 8); ep++)
  continue;
 sl = ep - sp;
 md5_starts(&ctx);
 md5_update(&ctx, (unsigned char *)pw, strlen(pw));
 md5_update(&ctx, (unsigned char *)magic, strlen(magic));
 md5_update(&ctx, (unsigned char *)sp, (unsigned int)sl);
 md5_starts(&ctx1);
 md5_update(&ctx1, (unsigned char *)pw, strlen(pw));
 md5_update(&ctx1, (unsigned char *)sp, (unsigned int)sl);
 md5_update(&ctx1, (unsigned char *)pw, strlen(pw));
 md5_finish(&ctx1, final);
 for(pl = (int)strlen(pw); pl > 0; pl -= 16)
  md5_update(&ctx, (unsigned char *)final,
      (u_int)(pl > 16 ? 16 : pl));
 memset(final, 0, sizeof(final));
 for (i = strlen(pw); i; i >>= 1)
  if(i & 1)
      md5_update(&ctx, (unsigned char *)final, 1);
  else
      md5_update(&ctx, (unsigned char *)pw, 1);
 strcpy(passwd, magic);
 strncat(passwd, sp, (unsigned int)sl);
 strcat(passwd, "$");
 md5_finish(&ctx, final);
 for(i = 0; i < rounds; i++) {
  md5_starts(&ctx1);
  if(i & 1)
   md5_update(&ctx1, (unsigned char *)pw, strlen(pw));
  else
   md5_update(&ctx1, (unsigned char *)final, 16);
  if(i % 3)
   md5_update(&ctx1, (unsigned char *)sp, (unsigned int)sl);
  if(i % 7)
   md5_update(&ctx1, (unsigned char *)pw, strlen(pw));
  if(i & 1)
   md5_update(&ctx1, (unsigned char *)final, 16);
  else
   md5_update(&ctx1, (unsigned char *)pw, strlen(pw));
  md5_finish(&ctx1, final);
 }
 p = passwd + strlen(passwd);
 l = (final[ 0]<<16) | (final[ 6]<<8) | final[12];
 _crypt_to64(p, l, 4); p += 4;
 l = (final[ 1]<<16) | (final[ 7]<<8) | final[13];
 _crypt_to64(p, l, 4); p += 4;
 l = (final[ 2]<<16) | (final[ 8]<<8) | final[14];
 _crypt_to64(p, l, 4); p += 4;
 l = (final[ 3]<<16) | (final[ 9]<<8) | final[15];
 _crypt_to64(p, l, 4); p += 4;
 l = (final[ 4]<<16) | (final[10]<<8) | final[ 5];
 _crypt_to64(p, l, 4); p += 4;
 l = final[11];
 _crypt_to64(p, l, 2); p += 2;
 *p = '\0';
 out_len = strlen(passwd) - sl - sizeof(magic);
 output = (char *) malloc(out_len + 1);
 if (output == ((void *)0))
 {
  fprintf(stderr, "error : memory allocation failed\n");
  return ((void *)0);
 }
 strncpy(output, passwd + sizeof(magic) + sl, out_len);
 output[out_len] = '\0';
 return (output);
}

variable_types:
pw
char *

variable_types:
salt
char *

variable_types:
rounds
unsigned long

variable_types: struct md5_context { unsigned int total[2]; unsigned int state[4]; unsigned char buffer[64]; unsigned char ipad[64]; unsigned char opad[64]; }

variable_types:
l
unsigned long

variable_types: sl int

variable_types: pl int

variable_types:
final
unsigned char [16]

variable_types:
sp
char *

variable_types:
ep
char *

variable_types:
passwd
char [120]

variable_types:
p
char *

variable_types:
magic
char *

variable_types:
output
char *

return_type: char *


usage

decompiled_code:
size_t __fastcall usage(const char *a1)
{
fprintf(stderr, "\nusage : %s -f <shadow> [-b <max_len>] [-f <dico>]\n", a1);
fwrite("-f <shadow> file passwords (/etc/shadow)\n", 1uLL, 0x2CuLL, stderr);
fwrite("-b <max_len> brute force attack(4 characters by default)\n", 1uLL, 0x3BuLL, stderr);
return fwrite("-d <dico> dictionary attack\n", 1uLL, 0x21uLL, stderr);
}

canonical_decompiled_code:
size_t __fastcall func0(const char *a1)
{
fprintf(stderr, "\nusage : %s -f <shadow> [-b <max_len>] [-f <dico>]\n", a1);
fwrite("-f <shadow> file passwords (/etc/shadow)\n", 1uLL, 0x2CuLL, stderr);
fwrite("-b <max_len> brute force attack(4 characters by default)\n", 1uLL, 0x3BuLL, stderr);
return fwrite("-d <dico> dictionary attack\n", 1uLL, 0x21uLL, stderr);
}

original_code:
void usage(char *program)
{
    fprintf(stderr, "\nusage : %s -f <shadow> [-b <max_len>] " "[-f <dico>]\n", program);
    fprintf(stderr, "-f <shadow>    file passwords (/etc/shadow)\n");
    fprintf(stderr, "-b <max_len>   brute force attack(4 characters by " "default)\n");
    fprintf(stderr, "-d <dico>      dictionary attack\n");
}

variable_types:
program
char *


main

canonical_name: main

repo: vpuydoyeux/Suricatac

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v3; // al
__int64 v4; // rdx
__int64 v5; // rax
_QWORD *v6; // rbp
__int64 v7; // rdi
__int64 v8; // rdx
unsigned int v9; // eax
const char *v10; // rdi
unsigned int v11; // eax
unsigned int v12; // eax
unsigned int v13; // ebp
void *v14; // r13
void *v15; // r12
void *v16; // rbx
__int64 v17; // rdx
unsigned int v18; // eax
__int64 v19; // rdx
unsigned int v20; // er13
void *v21; // rbx
__int64 v22; // rdx
_QWORD *v23; // rbx
void *v24; // r12
__int64 v25; // rdx

v3 = myopt(argc, argv, envp);
v4 = 0LL;
if ( (unsigned __int8)(v3 - 2) > 2u )
{
LOBYTE(v4) = argc == 3;
if ( v3 == 5 && argc == 3 )
{
v9 = is_readable(argv[1], argv, v4);
LODWORD(v4) = v9;
if ( v9 != -1 )
{
v10 = argv[2];
v11 = is_directory(v10, argv, v9);
LODWORD(v4) = v11;
if ( v11 != -1 )
{
v12 = suricata_connect(v10, argv, v11);
v13 = v12;
LODWORD(v4) = 0;
if ( v12 != 1 )
{
suricata_send("{\"version\": \"0.1\"}", v12, 0LL);
v14 = (void *)get_realpath(argv[1]);
v15 = (void *)get_realpath(argv[2]);
v16 = (void *)suricata_cmd_pcaps(v14, v15);
suricata_send(v16, v13, v17);
suricata_close(v13);
free(v14);
free(v15);
free(v16);
LODWORD(v4) = 0;
}
}
}
}
else if ( v3 == 1 && argc == 3 )
{
v5 = build_list(argv[2], argv, v4);
v6 = (_QWORD *)v5;
if ( v5 )
{
v7 = v5;
if ( !(unsigned int)check_list(v5) )
{
v18 = suricata_connect(v7, argv, v8);
v20 = v18;
if ( v18 != 1 )
{
suricata_send("{\"version\": \"0.1\"}", v18, v19);
v21 = (void *)suricata_cmd_pcaps(*v6, v6[1]);
suricata_send(v21, v20, v22);
free(v21);
v23 = v6;
while ( 1 )
{
v23 = (_QWORD *)v23[2];
if ( !v23 )
break;
v24 = (void *)suricata_cmd_pcaps(*v23, v23[1]);
suricata_send(v24, v20, v25);
free(v24);
}
suricata_close(v20);
}
}
free_list(v6);
LODWORD(v4) = 0;
}
else
{
LODWORD(v4) = -1;
}
}
else
{
usage(argc, argv, v4);
LODWORD(v4) = 0;
}
}
return v4;
}

original_code:
int main(int argc, char **argv) {
 int socket;
 char opt;
 char *cmd, *file, *dir;
 PCAP *list = ((void *)0);
 PCAP *tmp;
 opt = myopt(argc, argv);
 if (opt == 3 || opt == 2 || opt == 4)
  return 0;
 else if (opt == 5 && argc == 3) {
  if (is_readable(argv[1]) == -1 || is_directory(argv[2]) == -1)
   return -1;
  if ((socket = suricata_connect()) != 1) {
   suricata_send("{\"version\": \"0.1\"}", socket);
   file = get_realpath(argv[1]);
   dir = get_realpath(argv[2]);
   cmd = suricata_cmd_pcaps(file, dir);
   suricata_send(cmd, socket);
   suricata_close(socket);
   free(file);
   free(dir);
   free(cmd);
  }
 }
 else if ((opt == 1 && argc == 3)) {
  if ((list = build_list(argv[2])) == ((void *)0))
   return -1;
  if (check_list(list) == 0) {
   tmp = list;
   if ((socket = suricata_connect()) != 1) {
    suricata_send("{\"version\": \"0.1\"}", socket);
    cmd = suricata_cmd_pcaps(tmp->file, tmp->dir);
    suricata_send(cmd, socket);
    free(cmd);
    while (tmp->next != ((void *)0)) {
     tmp = tmp->next;
     cmd = suricata_cmd_pcaps(tmp->file, tmp->dir);
     suricata_send(cmd, socket);
     free(cmd);
    }
    suricata_close(socket);
   }
  }
  free_list(list);
 }
 else
  usage();
 return 0;
}

canonical_original_code:
int main(int argc, char **argv) {
 int socket;
 char opt;
 char *cmd; char *file; char *dir;
 struct PCAP_ *list = ((void *)0);
 struct PCAP_ *tmp;
 opt = myopt(argc, argv);
 if (opt == 3 || opt == 2 || opt == 4)
  return 0;
 else if (opt == 5 && argc == 3) {
  if (is_readable(argv[1]) == -1 || is_directory(argv[2]) == -1)
   return -1;
  if ((socket = suricata_connect()) != 1) {
   suricata_send("{\"version\": \"0.1\"}", socket);
   file = get_realpath(argv[1]);
   dir = get_realpath(argv[2]);
   cmd = suricata_cmd_pcaps(file, dir);
   suricata_send(cmd, socket);
   suricata_close(socket);
   free(file);
   free(dir);
   free(cmd);
  }
 }
 else if ((opt == 1 && argc == 3)) {
  if ((list = build_list(argv[2])) == ((void *)0))
   return -1;
  if (check_list(list) == 0) {
   tmp = list;
   if ((socket = suricata_connect()) != 1) {
    suricata_send("{\"version\": \"0.1\"}", socket);
    cmd = suricata_cmd_pcaps(tmp->file, tmp->dir);
    suricata_send(cmd, socket);
    free(cmd);
    while (tmp->next != ((void *)0)) {
     tmp = tmp->next;
     cmd = suricata_cmd_pcaps(tmp->file, tmp->dir);
     suricata_send(cmd, socket);
     free(cmd);
    }
    suricata_close(socket);
   }
  }
  free_list(list);
 }
 else
  usage();
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: socket int

variable_types: opt char

variable_types:
cmd
char *

variable_types:
file
char *

variable_types:
dir
char *

variable_types: struct PCAP_ { char *file; char *dir; struct PCAP_ *next; } *


myopt

decompiled_code:
__int64 __fastcall myopt(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax
__int64 j; // r12
const char *v5; // r13
size_t v6; // rax
__int64 i; // r12
int v8; // eax

do
{
while ( 1 )
{
v2 = getopt(argc, argv, "v:d:f:h");
if ( v2 == -1 )
return 5LL;
if ( v2 == 104 )
{
puts("Suricatac - HELP");
return 3LL;
}
if ( v2 > 104 )
break;
if ( v2 == 100 )
{
if ( argc <= 3 )
{
puts("usage: ./Suricatac -d [timeout] [args]");
result = 4LL;
}
else
{
for ( i = 3LL; i != argc; ++i )
{
printf("arg%d: %s\n", (unsigned int)(i - 2), argv[i]);
v8 = atoi(optarg);
sleep(v8);
}
result = 4LL;
}
return result;
}
if ( v2 == 102 )
{
result = 1LL;
if ( argc != 3 )
{
puts("usage: -f [file]");
result = 1LL;
}
return result;
}
}
}
while ( v2 != 118 );
if ( argc <= 2 )
{
printf("usage: ./Suricatac -v [args]");
result = 2LL;
}
else
{
for ( j = 2LL; j != argc; printf("arg%d: %s - length: %zu\n", (unsigned int)(j++ - 1), v5, v6) )
{
v5 = argv[j];
v6 = strlen(v5);
}
result = 2LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(int argc, char **argv)
{
int v2; // eax
__int64 result; // rax
__int64 j; // r12
const char *v5; // r13
size_t v6; // rax
__int64 i; // r12
int v8; // eax

do
{
while ( 1 )
{
v2 = getopt(argc, argv, "v:d:f:h");
if ( v2 == -1 )
return 5LL;
if ( v2 == 104 )
{
puts("Suricatac - HELP");
return 3LL;
}
if ( v2 > 104 )
break;
if ( v2 == 100 )
{
if ( argc <= 3 )
{
puts("usage: ./Suricatac -d [timeout] [args]");
result = 4LL;
}
else
{
for ( i = 3LL; i != argc; ++i )
{
printf("arg%d: %s\n", (unsigned int)(i - 2), argv[i]);
v8 = atoi(optarg);
sleep(v8);
}
result = 4LL;
}
return result;
}
if ( v2 == 102 )
{
result = 1LL;
if ( argc != 3 )
{
puts("usage: -f [file]");
result = 1LL;
}
return result;
}
}
}
while ( v2 != 118 );
if ( argc <= 2 )
{
printf("usage: ./Suricatac -v [args]");
result = 2LL;
}
else
{
for ( j = 2LL; j != argc; printf("arg%d: %s - length: %zu\n", (unsigned int)(j++ - 1), v5, v6) )
{
v5 = argv[j];
v6 = strlen(v5);
}
result = 2LL;
}
return result;
}

original_code:
int myopt(int argc, char **argv) {
 int i;
 int ret;
 int opt;
 ret = 5;
 while ((opt = getopt(argc, argv, "v:d:f:h")) != -1) {
  switch (opt) {
   case 'h':
    printf("Suricatac - HELP\n");
    ret = 3;
    return ret;
   case 'v':
    if (argc > 2) {
     for (i=2; i < argc; i++)
      printf("arg%d: %s - length: %zu\n", i-1, argv[i], strlen(argv[i]));
    }
    else
     printf("usage: ./Suricatac -v [args]");
    ret = 2;
    return ret;
   case 'd':
    if (argc > 3) {
     for (i=3; i < argc; i++) {
      printf("arg%d: %s\n", i-2, argv[i]);
      sleep(atoi(optarg));
     }
    }
    else
     printf("usage: ./Suricatac -d [timeout] [args]\n");
    ret = 4;
    return ret;
   case 'f':
    if (argc != 3)
     printf("usage: -f [file]\n");
    ret = 1;
    return ret;
  }
 }
 return ret;
}

variable_types: i int

variable_types: ret int

variable_types: opt int


usage

decompiled_code:
int usage()
{
return puts(
"usage: ./Suricatac [option] [args]\n"
" \t\t\toptions: -h HELP\n"
" \t\t\t-v [args]\n"
" \t\t\t-d [timeout] [args]\n"
" \t\t\t-f [list_pcaps]\n"
" \t\t\t[pcapfile] [outputdir]");
}

canonical_decompiled_code:
int func1()
{
return puts(
"usage: ./Suricatac [option] [args]\n"
" \t\t\toptions: -h HELP\n"
" \t\t\t-v [args]\n"
" \t\t\t-d [timeout] [args]\n"
" \t\t\t-f [list_pcaps]\n"
" \t\t\t[pcapfile] [outputdir]");
}

original_code:
void usage() {
 printf("usage: ./Suricatac [option] [args]\n 			options: -h HELP\n 			-v [args]\n 			-d [timeout] [args]\n 			-f [list_pcaps]\n 			[pcapfile] [outputdir]\n");
}


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

if ( access(a1, 4) != -1 )
return 0;
v1 = -1;
fprintf(stderr, "error: %s is not readable\n", a1);
return v1;
}

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

if ( access(a1, 4) != -1 )
return 0;
v1 = -1;
fprintf(stderr, "error: %s is not readable\n", a1);
return v1;
}

original_code:
int is_readable(char *file) {
 if (access(file, 4) == -1) {
  fprintf(stderr, "error: %s is not readable\n", file);
  return -1;
 }
 return 0;
}


decompiled_code:
__int64 __fastcall is_directory(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

stat(a1, &v2);
if ( (v2.st_mode & 0xF000) == 0x4000 )
return 0LL;
fprintf(stderr, "error: %s is not a directory\n", a1);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func3(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

stat(a1, &v2);
if ( (v2.st_mode & 0xF000) == 0x4000 )
return 0LL;
fprintf(stderr, "error: %s is not a directory\n", a1);
return 0xFFFFFFFFLL;
}

original_code:
int is_directory(char *dir) {
 struct stat st;
 stat(dir, &st);
 if (!((((st.st_mode)) & 0170000) == (0040000))) {
  fprintf(stderr, "error: %s is not a directory\n", dir);
  return -1;
 }
 return 0;
}

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

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 is_empty(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

stat(a1, &v2);
return (unsigned int)-(v2.st_size != 0);
}

canonical_decompiled_code:
__int64 __fastcall func4(const char *a1)
{
struct stat v2; // [rsp+0h] [rbp-98h] BYREF

stat(a1, &v2);
return (unsigned int)-(v2.st_size != 0);
}

original_code:
int is_empty(char *file) {
 struct stat st;
 stat(file, &st);
 if (st.st_size == 0)
  return 0;
 return -1;
}

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


decompiled_code:
__int64 __fastcall check_list(const char **a1)
{
const char **v1; // rbx
__int64 result; // rax

v1 = a1;
result = is_readable(*a1);
if ( (_DWORD)result != -1 )
{
result = is_directory(a1[1]);
if ( (_DWORD)result != -1 )
{
while ( 1 )
{
v1 = (const char **)v1[2];
if ( !v1 )
break;
result = is_readable(*v1);
if ( (_DWORD)result != -1 )
{
result = is_directory(v1[1]);
if ( (_DWORD)result != -1 )
continue;
}
return result;
}
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char **a1)
{
const char **v1; // rbx
__int64 result; // rax

v1 = a1;
result = func2(*a1);
if ( (_DWORD)result != -1 )
{
result = func3(a1[1]);
if ( (_DWORD)result != -1 )
{
while ( 1 )
{
v1 = (const char **)v1[2];
if ( !v1 )
break;
result = func2(*v1);
if ( (_DWORD)result != -1 )
{
result = func3(v1[1]);
if ( (_DWORD)result != -1 )
continue;
}
return result;
}
result = 0LL;
}
}
return result;
}

original_code:
int check_list(PCAP *list) {
 PCAP *tmp;
 tmp = list;
 if (is_readable(tmp->file) == -1 || is_directory(tmp->dir) == -1)
  return -1;
 while (tmp != ((void *)0) && tmp->next != ((void *)0)) {
  tmp = tmp->next;
  if (is_readable(tmp->file) == -1 || is_directory(tmp->dir) == -1)
   return -1;
 }
 return 0;
}

canonical_original_code:
int check_list(struct PCAP_ *list) {
 struct PCAP_ *tmp;
 tmp = list;
 if (is_readable(tmp->file) == -1 || is_directory(tmp->dir) == -1)
  return -1;
 while (tmp != ((void *)0) && tmp->next != ((void *)0)) {
  tmp = tmp->next;
  if (is_readable(tmp->file) == -1 || is_directory(tmp->dir) == -1)
   return -1;
 }
 return 0;
}

user_defined_types: struct PCAP_ { char *file; char *dir; struct PCAP_ *next; }


decompiled_code:
void __fastcall free_list(void *ptr)
{
void **v1; // rbx
void **v2; // rbp
void *v3; // rdi
void *v4; // rdi

if ( ptr )
{
v1 = (void **)ptr;
v2 = (void **)*((_QWORD *)ptr + 2);
if ( v2 )
{
while ( 1 )
{
if ( *v1 )
free(*v1);
v4 = v1[1];
if ( v4 )
free(v4);
free(v1);
v1 = v2;
if ( !v2[2] )
break;
v2 = (void **)v2[2];
}
}
else
{
v2 = (void **)ptr;
}
if ( *v2 )
free(*v2);
v3 = v2[1];
if ( v3 )
free(v3);
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
void **v1; // rbx
void **v2; // rbp
void *v3; // rdi
void *v4; // rdi

if ( ptr )
{
v1 = (void **)ptr;
v2 = (void **)*((_QWORD *)ptr + 2);
if ( v2 )
{
while ( 1 )
{
if ( *v1 )
free(*v1);
v4 = v1[1];
if ( v4 )
free(v4);
free(v1);
v1 = v2;
if ( !v2[2] )
break;
v2 = (void **)v2[2];
}
}
else
{
v2 = (void **)ptr;
}
if ( *v2 )
free(*v2);
v3 = v2[1];
if ( v3 )
free(v3);
free(v2);
}
}

original_code:
void free_list(PCAP *list) {
 PCAP *tmp = ((void *)0);
 PCAP *del = ((void *)0);
 if (list != ((void *)0)) {
  tmp = list;
  while(tmp->next != ((void *)0)) {
   del = tmp;
   tmp = tmp->next;
   if (del->file != ((void *)0))
    free(del->file);
   if (del->dir != ((void *)0))
    free(del->dir);
   free(del);
  }
  if (tmp->file != ((void *)0))
   free(tmp->file);
  if (tmp->dir != ((void *)0))
   free(tmp->dir);
  free(tmp);
 }
}

canonical_original_code:
void free_list(struct PCAP_ *list) {
 struct PCAP_ *tmp = ((void *)0);
 struct PCAP_ *del = ((void *)0);
 if (list != ((void *)0)) {
  tmp = list;
  while(tmp->next != ((void *)0)) {
   del = tmp;
   tmp = tmp->next;
   if (del->file != ((void *)0))
    free(del->file);
   if (del->dir != ((void *)0))
    free(del->dir);
   free(del);
  }
  if (tmp->file != ((void *)0))
   free(tmp->file);
  if (tmp->dir != ((void *)0))
   free(tmp->dir);
  free(tmp);
 }
}


decompiled_code:
__int64 suricata_connect()
{
unsigned int v0; // ebx
int *v2; // rbx
char *v3; // rax
struct sockaddr v4[8]; // [rsp+0h] [rbp-88h] BYREF

v0 = socket(1, 1, 0);
v4[0].sa_family = 1;
strcpy(v4[0].sa_data, "/usr/local/var/run/suricata/suricata-command.socket");
if ( connect(v0, v4, 0x6Eu) == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "error %i: %s\n", (unsigned int)*v2, v3);
v0 = -1;
}
return v0;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // ebx
int *v2; // rbx
char *v3; // rax
struct sockaddr v4[8]; // [rsp+0h] [rbp-88h] BYREF

v0 = socket(1, 1, 0);
v4[0].sa_family = 1;
strcpy(v4[0].sa_data, "/usr/local/var/run/suricata/suricata-command.socket");
if ( connect(v0, v4, 0x6Eu) == -1 )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "error %i: %s\n", (unsigned int)*v2, v3);
v0 = -1;
}
return v0;
}

original_code:
int suricata_connect() {
 int socketfd;
 struct sockaddr_un addr;
 socketfd = socket(1, SOCK_STREAM, 0);
 addr.sun_family = 1;
 strcpy(addr.sun_path, "/usr/local/var/run/suricata/suricata-command.socket");
 if (connect(socketfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
  fprintf(stderr, "error %i: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
  return -1;
 }
 return socketfd;
}

variable_types: socketfd int

variable_types: struct sockaddr_un { unsigned short sun_family; char sun_path[108]; }

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


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

if ( a1 == -1 )
result = -1;
else
result = close(a1);
return result;
}

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

if ( a1 == -1 )
result = -1;
else
result = close(a1);
return result;
}

original_code:
int suricata_close(int socket) {
 if (socket != -1)
  return close(socket);
 return -1;
}


decompiled_code:
__int64 __fastcall suricata_send(void *buf, int fd)
{
int v2; // eax
_BYTE *v3; // rbp
char *v4; // r14
int v5; // er15
signed int v6; // eax
signed int v7; // ebx
int *v9; // rbx
char *v10; // rax
int *v11; // rbx
char *v12; // rax
unsigned int v13; // [rsp+8h] [rbp-40h]
int v14; // [rsp+Ch] [rbp-3Ch]

v2 = strlen((const char *)buf);
if ( send(fd, buf, v2, 0) == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "error %i: %s\n", (unsigned int)*v9, v10);
v13 = -1;
}
else
{
v3 = malloc(0x1000uLL);
if ( v3 )
{
memset(v3, 0, 0x1000uLL);
v4 = v3;
v5 = 4096;
v14 = 0;
while ( 1 )
{
v6 = recv(fd, v4, v5, 64);
v13 = v6;
if ( !v6 )
break;
if ( v6 == -1 )
{
v11 = _errno_location();
if ( *v11 != 11 )
{
v12 = strerror(*v11);
fprintf(stderr, "error %i: %s\n", (unsigned int)*v11, v12);
return v13;
}
if ( ++v14 > 1000000 )
break;
}
else
{
v7 = v6;
if ( v6 + strlen(v4) > 0xFFE )
break;
v4 += v7;
v5 = 4096 - ((_DWORD)v4 - (_DWORD)v3);
}
}
printf("command : %s\n", (const char *)buf);
if ( *v3 )
printf("suricata : %s\n", v3);
free(v3);
puts("\n");
v13 = 0;
}
else
{
v13 = -1;
}
}
return v13;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *buf, int fd)
{
int v2; // eax
_BYTE *v3; // rbp
char *v4; // r14
int v5; // er15
signed int v6; // eax
signed int v7; // ebx
int *v9; // rbx
char *v10; // rax
int *v11; // rbx
char *v12; // rax
unsigned int v13; // [rsp+8h] [rbp-40h]
int v14; // [rsp+Ch] [rbp-3Ch]

v2 = strlen((const char *)buf);
if ( send(fd, buf, v2, 0) == -1 )
{
v9 = _errno_location();
v10 = strerror(*v9);
fprintf(stderr, "error %i: %s\n", (unsigned int)*v9, v10);
v13 = -1;
}
else
{
v3 = malloc(0x1000uLL);
if ( v3 )
{
memset(v3, 0, 0x1000uLL);
v4 = v3;
v5 = 4096;
v14 = 0;
while ( 1 )
{
v6 = recv(fd, v4, v5, 64);
v13 = v6;
if ( !v6 )
break;
if ( v6 == -1 )
{
v11 = _errno_location();
if ( *v11 != 11 )
{
v12 = strerror(*v11);
fprintf(stderr, "error %i: %s\n", (unsigned int)*v11, v12);
return v13;
}
if ( ++v14 > 1000000 )
break;
}
else
{
v7 = v6;
if ( v6 + strlen(v4) > 0xFFE )
break;
v4 += v7;
v5 = 4096 - ((_DWORD)v4 - (_DWORD)v3);
}
}
printf("command : %s\n", (const char *)buf);
if ( *v3 )
printf("suricata : %s\n", v3);
free(v3);
puts("\n");
v13 = 0;
}
else
{
v13 = -1;
}
}
return v13;
}

original_code:
int suricata_send(char *cmd, int socket) {
 int ret;
 int cpt = 0;
 int len = strlen(cmd);
 char *buf, *offset;
 if (send(socket, cmd, len, 0) == -1) {
  fprintf(stderr, "error %i: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
  return -1;
 }
 len = 4096;
 if ((buf = (char *) malloc(4096)) == ((void *)0))
  return -1;
 offset = buf;
 memset(buf, '\0', 4096);
 while ((ret = recv(socket, offset, len, MSG_DONTWAIT))) {
  if (ret == -1) {
   if ((*__errno_location ()) == 11) {
    cpt++;
    if (cpt > 1000000)
     break;
    else
     continue;
   }
   else {
    fprintf(stderr, "error %i: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
    return -1;
   }
  }
  else {
   if (strlen(offset) + ret < 4096 - 1) {
    offset += ret;
    len = 4096 - (offset - buf);
    continue;
   }
   else
    break;
  }
 }
 printf("command  : %s\n", cmd);
 if (strlen(buf) > 0)
  printf("suricata : %s\n", buf);
 free(buf);
 printf("\n\n");
 return 0;
}

canonical_original_code:
int suricata_send(char *cmd, int socket) {
 int ret;
 int cpt = 0;
 int len = strlen(cmd);
 char *buf; char *offset;
 if (send(socket, cmd, len, 0) == -1) {
  fprintf(stderr, "error %i: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
  return -1;
 }
 len = 4096;
 if ((buf = (char *) malloc(4096)) == ((void *)0))
  return -1;
 offset = buf;
 memset(buf, '\0', 4096);
 while ((ret = recv(socket, offset, len, MSG_DONTWAIT))) {
  if (ret == -1) {
   if ((*__errno_location ()) == 11) {
    cpt++;
    if (cpt > 1000000)
     break;
    else
     continue;
   }
   else {
    fprintf(stderr, "error %i: %s\n", (*__errno_location ()), strerror((*__errno_location ())));
    return -1;
   }
  }
  else {
   if (strlen(offset) + ret < 4096 - 1) {
    offset += ret;
    len = 4096 - (offset - buf);
    continue;
   }
   else
    break;
  }
 }
 printf("command  : %s\n", cmd);
 if (strlen(buf) > 0)
  printf("suricata : %s\n", buf);
 free(buf);
 printf("\n\n");
 return 0;
}

variable_types: cpt int

variable_types: len int

variable_types:
buf
char *

variable_types:
offset
char *


decompiled_code:
char *__fastcall suricata_cmd_pcaps(char *s, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rbx
size_t v5; // r13
size_t v6; // rax

v2 = strlen(s);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 80);
if ( v4 )
{
v5 = strlen(s);
v6 = strlen(a2);
snprintf(
v4,
v5 + v6 + 79,
"{\"command\": \"pcap-file\", \"arguments\": { \"filename\": \"%s\", \"output-dir\": \"%s\"}}",
s,
a2);
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func3(char *s, char *a2)
{
size_t v2; // rbx
size_t v3; // rax
char *v4; // rbx
size_t v5; // r13
size_t v6; // rax

v2 = strlen(s);
v3 = strlen(a2);
v4 = (char *)malloc(v2 + v3 + 80);
if ( v4 )
{
v5 = strlen(s);
v6 = strlen(a2);
snprintf(
v4,
v5 + v6 + 79,
"{\"command\": \"pcap-file\", \"arguments\": { \"filename\": \"%s\", \"output-dir\": \"%s\"}}",
s,
a2);
}
return v4;
}

original_code:
char* suricata_cmd_pcaps(char *pcap, char *dir) {
 char *cmd = (char *) malloc(sizeof("{\"command\": \"pcap-file\", \"arguments\": { \"filename\": \"%s\", \"output-dir\": \"%s\"}}") + strlen(pcap) + strlen(dir) + 1);
 if (cmd == ((void *)0))
  return ((void *)0);
 snprintf(cmd, sizeof("{\"command\": \"pcap-file\", \"arguments\": { \"filename\": \"%s\", \"output-dir\": \"%s\"}}") + strlen(pcap) + strlen(dir), "{\"command\": \"pcap-file\", \"arguments\": { \"filename\": \"%s\", \"output-dir\": \"%s\"}}", pcap, dir);
 return cmd;
}

canonical_original_code:
char *suricata_cmd_pcaps(char *pcap, char *dir) {
 char *cmd = (char *) malloc(sizeof("{\"command\": \"pcap-file\", \"arguments\": { \"filename\": \"%s\", \"output-dir\": \"%s\"}}") + strlen(pcap) + strlen(dir) + 1);
 if (cmd == ((void *)0))
  return ((void *)0);
 snprintf(cmd, sizeof("{\"command\": \"pcap-file\", \"arguments\": { \"filename\": \"%s\", \"output-dir\": \"%s\"}}") + strlen(pcap) + strlen(dir), "{\"command\": \"pcap-file\", \"arguments\": { \"filename\": \"%s\", \"output-dir\": \"%s\"}}", pcap, dir);
 return cmd;
}

variable_types:
pcap
char *


deleteDILNode

repo: vraisamis/pjeuler-c

decompiled_code:
void __fastcall deleteDILNode(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
free(a1);
}

original_code:
void deleteDILNode(DILNode *node) {
 free(node);
}

canonical_original_code:
void deleteDILNode(struct tagDILinkNode *node) {
 free(node);
}

variable_types: struct tagDILinkNode { struct tagDILinkNode *prev; struct tagDILinkNode *next; int data; } *


newDILList

decompiled_code:
_QWORD *newDILList()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx

v0 = malloc(0x18uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
*((_DWORD *)v0 + 4) = 0;
}
else
{
putErr("can't create DILList.");
}
return v1;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *v0; // rax
_QWORD *v1; // rbx

v0 = malloc(0x18uLL);
v1 = v0;
if ( v0 )
{
*v0 = 0LL;
v0[1] = 0LL;
*((_DWORD *)v0 + 4) = 0;
}
else
{
putErr("can't create DILList.");
}
return v1;
}

original_code:
DILList *newDILList(void) {
 DILList *list = (DILList *)malloc(sizeof(DILList));
 if (list == ((void *)0)) putErr("can't create DILList.");
 else {
  list->start = ((void *)0);
  list->end = ((void *)0);
  list->items = 0;
 }
 return list;
}

canonical_original_code:
struct tagDILinkList *newDILList() {
 struct tagDILinkList *list = (DILList *)malloc(sizeof(DILList));
 if (list == ((void *)0)) putErr("can't create DILList.");
 else {
  list->start = ((void *)0);
  list->end = ((void *)0);
  list->items = 0;
 }
 return list;
}

variable_types: struct tagDILinkList { struct tagDILinkNode { struct tagDILinkNode *prev; struct tagDILinkNode *next; int data; } *start; struct tagDILinkNode *end; int items; } *

user_defined_types: struct tagDILinkList { struct tagDILinkNode *start; struct tagDILinkNode *end; int items; }


initDILList

decompiled_code:
__int64 __fastcall initDILList(__int64 a1)
{
void *v2; // rdi

v2 = *(void **)a1;
if ( v2 )
{
do
{
*(_QWORD *)a1 = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
deleteDILNode(v2);
v2 = *(void **)a1;
}
while ( *(_QWORD *)a1 );
}
*(_QWORD *)(a1 + 8) = 0LL;
*(_DWORD *)(a1 + 16) = 0;
return a1;
}

original_code:
DILList *initDILList(DILList *list) {
 DILNode *node;
 for (node = list->start; node != ((void *)0); node = list->start) {
  list->start = list->start->next;
  deleteDILNode(node);
 }
 list->end = ((void *)0);
 list->items = 0;
 return list;
}

canonical_original_code:
struct tagDILinkList *initDILList(struct tagDILinkList *list) {
 struct tagDILinkNode *node;
 for (node = list->start; node != ((void *)0); node = list->start) {
  list->start = list->start->next;
  deleteDILNode(node);
 }
 list->end = ((void *)0);
 list->items = 0;
 return list;
}

variable_types:
list
struct tagDILinkList *

return_type: struct tagDILinkList { struct tagDILinkNode { struct tagDILinkNode *prev; struct tagDILinkNode *next; int data; } *start; struct tagDILinkNode *end; int items; } *


deleteDILList

decompiled_code:
void __fastcall deleteDILList(void *ptr)
{
initSILList();
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(void *ptr)
{
initSILList();
free(ptr);
}

original_code:
void deleteDILList(DILList *list) {
 initSILList(list);
 free(list);
}

canonical_original_code:
void deleteDILList(struct tagDILinkList *list) {
 initSILList(list);
 free(list);
}

user_defined_types: struct tagDILinkNode { struct tagDILinkNode *prev; struct tagDILinkNode *next; int data; }


addDILNode

decompiled_code:
__int64 __fastcall addDILNode(__int64 a1, _QWORD *a2, int a3)
{
_QWORD *i; // rax

if ( *(_DWORD *)(a1 + 16) < a3 )
{
putErr("Index out of bound.");
return 0LL;
}
if ( a3 == -1 )
{
a2[1] = 0LL;
LABEL_11:
*a2 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = 0LL;
goto LABEL_12;
}
for ( i = *(_QWORD **)a1; a3 > 0 && i; --a3 )
i = (_QWORD *)i[1];
a2[1] = i;
if ( !i )
goto LABEL_11;
*a2 = *i;
*i = a2;
LABEL_12:
if ( *a2 )
*(_QWORD *)(*a2 + 8LL) = a2;
else
*(_QWORD *)a1 = a2;
return a1;
}

original_code:
DILList *addDILNode(DILList *list, DILNode *node, int index) {
 DILNode *p;
 if (index > list->items) {
  putErr("Index out of bound.");
  return ((void *)0);
 }
 if (index == -1) p = ((void *)0);
 else for (p = list->start; index > 0 && p != ((void *)0); p = p->next, index--) ;
 node->next = p;
 if (p == ((void *)0)) {
  node->prev = list->end;
  list->end = p;
 } else {
  node->prev = p->prev;
  p->prev = node;
 }
 if (node->prev == ((void *)0)) list->start = node;
 else node->prev->next = node;
 return list;
}

canonical_original_code:
struct tagDILinkList *addDILNode(struct tagDILinkList *list, struct tagDILinkNode *node, int index) {
 struct tagDILinkNode *p;
 if (index > list->items) {
  putErr("Index out of bound.");
  return ((void *)0);
 }
 if (index == -1) p = ((void *)0);
 else for (p = list->start; index > 0 && p != ((void *)0); p = p->next, index--) ;
 node->next = p;
 if (p == ((void *)0)) {
  node->prev = list->end;
  list->end = p;
 } else {
  node->prev = p->prev;
  p->prev = node;
 }
 if (node->prev == ((void *)0)) list->start = node;
 else node->prev->next = node;
 return list;
}

variable_types:
node
struct tagDILinkNode *

variable_types: index int


searchDILNode

decompiled_code:
__int64 __fastcall searchDILNode(__int64 *a1, int a2)
{
__int64 result; // rax

for ( result = *a1; result; result = *(_QWORD *)(result + 8) )
{
if ( *(_DWORD *)(result + 16) == a2 )
break;
}
return result;
}

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

for ( result = *a1; result; result = *(_QWORD *)(result + 8) )
{
if ( *(_DWORD *)(result + 16) == a2 )
break;
}
return result;
}

original_code:
DILNode *searchDILNode(DILList *list, int data) {
 DILNode *point;
 for (point = list->start; point != ((void *)0) && point->data != data; point = point->next) ;
 return point;
}

canonical_original_code:
struct tagDILinkNode *searchDILNode(struct tagDILinkList *list, int data) {
 struct tagDILinkNode *point;
 for (point = list->start; point != ((void *)0) && point->data != data; point = point->next) ;
 return point;
}

variable_types: struct tagDILinkList { struct tagDILinkNode *start; struct tagDILinkNode *end; int items; } *

variable_types: data int

return_type: struct tagDILinkNode { struct tagDILinkNode *prev; struct tagDILinkNode *next; int data; } *


deleteDILIterator

decompiled_code:
void __fastcall deleteDILIterator(void *a1)
{
free(a1);
}

canonical_decompiled_code:
void __fastcall func6(void *a1)
{
free(a1);
}

original_code:
void deleteDILIterator(DILIterator *iterator) {
 free(iterator);
}

canonical_original_code:
void deleteDILIterator(struct tagDILinkListIterator *iterator) {
 free(iterator);
}

variable_types: struct tagDILinkListIterator { struct tagDILinkNode { struct tagDILinkNode *prev; struct tagDILinkNode *next; int data; } *current; struct tagDILinkList { struct tagDILinkNode *start; struct tagDILinkNode *end; int items; } *target; enum enBool { FALSE=0, TRUE=1 } isForward; } *

user_defined_types: struct tagDILinkListIterator { struct tagDILinkNode *current; struct tagDILinkList *target; enum enBool isForward; }


hasNextDILNode

decompiled_code:
_BOOL8 __fastcall hasNextDILNode(_QWORD *a1)
{
return *a1 != 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(_QWORD *a1)
{
return *a1 != 0LL;
}

original_code:
boolean hasNextDILNode(DILIterator *iterator) {
 return iterator->current == ((void *)0) ? FALSE : TRUE;
}

canonical_original_code:
enum enBool hasNextDILNode(struct tagDILinkListIterator *iterator) {
 return iterator->current == ((void *)0) ? FALSE : TRUE;
}

return_type: enum enBool { FALSE=0, TRUE=1 }


nextDILNode

decompiled_code:
__int64 __fastcall nextDILNode(_DWORD *a1)
{
__int64 result; // rax

if ( a1[4] )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
else
result = **(_QWORD **)a1;
*(_QWORD *)a1 = result;
return result;
}

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

if ( a1[4] )
result = *(_QWORD *)(*(_QWORD *)a1 + 8LL);
else
result = **(_QWORD **)a1;
*(_QWORD *)a1 = result;
return result;
}

original_code:
void nextDILNode(DILIterator *iterator) {
 iterator->current = iterator->isForward ? iterator->current->next : iterator->current->prev;
}

canonical_original_code:
void nextDILNode(struct tagDILinkListIterator *iterator) {
 iterator->current = iterator->isForward ? iterator->current->next : iterator->current->prev;
}


getCurrentDILNode

decompiled_code:
__int64 __fastcall getCurrentDILNode(__int64 a1)
{
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
return *(_QWORD *)a1;
}

original_code:
DILNode *getCurrentDILNode(DILIterator *iterator) {
 return iterator->current;
}

canonical_original_code:
struct tagDILinkNode *getCurrentDILNode(struct tagDILinkListIterator *iterator) {
 return iterator->current;
}

variable_types: struct tagDILinkListIterator { struct tagDILinkNode *current; struct tagDILinkList { struct tagDILinkNode *start; struct tagDILinkNode *end; int items; } *target; enum enBool { FALSE=0, TRUE=1 } isForward; } *


deleteSILNode

decompiled_code:
void __fastcall deleteSILNode(void *a1)
{
free(a1);
}

original_code:
void deleteSILNode(SILNode *node) {
 free(node);
}

canonical_original_code:
void deleteSILNode(struct tagSILinkNode *node) {
 free(node);
}

variable_types: struct tagSILinkNode { struct tagSILinkNode *next; int data; } *