server

decompiled_code:
__int64 __fastcall server(__int64 a1, const char *a2, unsigned int a3, __int64 a4, char *a5)
{
int v7; // ebx
__pid_t v8; // eax
const char *v9; // rax
size_t v10; // rax
__int64 result; // rax
char v12[256]; // [rsp+0h] [rbp-148h] BYREF
struct sockaddr addr; // [rsp+100h] [rbp-48h] BYREF
__WAIT_STATUS stat_loc; // [rsp+11Ch] [rbp-2Ch] BYREF

puts("******* Info Server *******");
v7 = socket(2, 1, 0);
if ( v7 < 0 )
perror("socket");
addr.sa_family = 2;
*(_WORD *)addr.sa_data = _bswap_16(5000);
inet_aton(a2, (struct in_addr *)&addr.sa_data[2]);
printf("try to connect to %s\n", a2);
if ( connect(v7, &addr, 0x10u) < 0 )
{
perror("connect");
result = 4294967294LL;
}
else
{
v8 = fork();
if ( v8 < 0 )
{
perror("fork");
result = 0xFFFFFFFFLL;
}
else
{
if ( !v8 )
{
while ( 1 )
{
v9 = (const char *)get_client_info_FQDN(a5);
strcpy(v12, v9);
printf("send: %s\n", v12);
v10 = strlen(v12);
send(v7, v12, v10, 0);
sleep(a3);
}
}
sslserv();
wait((__WAIT_STATUS)&stat_loc);
close(v7);
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, const char *a2, unsigned int a3, __int64 a4, char *a5)
{
int v7; // ebx
__pid_t v8; // eax
const char *v9; // rax
size_t v10; // rax
__int64 result; // rax
char v12[256]; // [rsp+0h] [rbp-148h] BYREF
struct sockaddr addr; // [rsp+100h] [rbp-48h] BYREF
__WAIT_STATUS stat_loc; // [rsp+11Ch] [rbp-2Ch] BYREF

puts("******* Info Server *******");
v7 = socket(2, 1, 0);
if ( v7 < 0 )
perror("socket");
addr.sa_family = 2;
*(_WORD *)addr.sa_data = func0(5000);
inet_aton(a2, (struct in_addr *)&addr.sa_data[2]);
printf("try to connect to %s\n", a2);
if ( connect(v7, &addr, 0x10u) < 0 )
{
perror("connect");
result = 4294967294LL;
}
else
{
v8 = fork();
if ( v8 < 0 )
{
perror("fork");
result = 0xFFFFFFFFLL;
}
else
{
if ( !v8 )
{
while ( 1 )
{
v9 = (const char *)func6(a5);
strcpy(v12, v9);
printf("send: %s\n", v12);
v10 = strlen(v12);
send(v7, v12, v10, 0);
sleep(a3);
}
}
sslserv();
wait((__WAIT_STATUS)&stat_loc);
close(v7);
result = 0LL;
}
}
return result;
}

original_code:
int server(char **envp, char *peer_host, int interval, char *interface_name, char *host_id)
{
 printf("******* Info Server *******\n");
 int sock_fd, len, status;
 struct sockaddr_in serv;
 unsigned short info_port = 5000;
 unsigned short port = 5002;
 char *hostname = peer_host;
 pid_t pid, cpid;
 if ((sock_fd = socket(2, SOCK_STREAM, 0)) < 0) {
  perror ("socket");
 }
 serv.sin_family = 2;
 serv.sin_port = htons(info_port);
 inet_aton(hostname, &serv.sin_addr);
 printf("try to connect to %s\n", hostname);
 if (connect(sock_fd, (struct sockaddr*)&serv, sizeof(struct sockaddr_in)) < 0)
 {
  perror("connect");
  return -2;
 }
 pid = fork();
 if (pid < 0) {
  perror("fork");
  return -1;
 }
 if (pid != 0) {
  sslserv();
  cpid = wait(&status);
 } else {
  while (1) {
   char client_info[256];
   strcpy(client_info, get_client_info_FQDN(host_id));
   printf("send: %s\n", client_info);
   len = send(sock_fd, client_info, strlen(client_info), 0);
   sleep(interval);
  }
 }
 close(sock_fd);
 return 0;
}

canonical_original_code:
int server(char **envp, char *peer_host, int interval, char *interface_name, char *host_id)
{
 printf("******* Info Server *******\n");
 int sock_fd; int len; int status;
 struct sockaddr_in serv;
 unsigned short info_port = 5000;
 unsigned short port = 5002;
 char *hostname = peer_host;
 int pid; int cpid;
 if ((sock_fd = socket(2, SOCK_STREAM, 0)) < 0) {
  perror ("socket");
 }
 serv.sin_family = 2;
 serv.sin_port = htons(info_port);
 inet_aton(hostname, &serv.sin_addr);
 printf("try to connect to %s\n", hostname);
 if (connect(sock_fd, (struct sockaddr *)&serv, sizeof(struct sockaddr_in)) < 0)
 {
  perror("connect");
  return -2;
 }
 pid = fork();
 if (pid < 0) {
  perror("fork");
  return -1;
 }
 if (pid != 0) {
  sslserv();
  cpid = wait(&status);
 } else {
  while (1) {
   char client_info[256];
   strcpy(client_info, get_client_info_FQDN(host_id));
   printf("send: %s\n", client_info);
   len = send(sock_fd, client_info, strlen(client_info), 0);
   sleep(interval);
  }
 }
 close(sock_fd);
 return 0;
}

variable_types:
envp
char **

variable_types: interval int

variable_types: status int

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

variable_types:
port
unsigned short

variable_types:
hostname
char *

variable_types: pid int

variable_types: cpid int

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


client

repo: iomz/DARSH

original_code:
int client(char *peer_host)
{
 printf("******* Client Mode *******\n");
 int sock_fd, len;
 char buf[256];
 struct sockaddr_in serv;
 unsigned short port = 5001;
 char *hostname = peer_host;
 if ((sock_fd = socket(2, SOCK_STREAM, 0)) < 0) {
  perror ("socket");
 }
 serv.sin_family = 2;
 serv.sin_port = htons(port);
 inet_aton(hostname, &serv.sin_addr);
 if (connect(sock_fd, (struct sockaddr*)&serv, sizeof(struct sockaddr_in)) < 0)
 {
  perror("connect");
  return -2;
 }
 len = read_line(sock_fd, buf);
 printf("First Peer Server Message: %s\n", buf);
 while (1) {
  char get[256] = {0};
  printf("-> %s", get);
  scanf("%s", get);
  len = send(sock_fd, get, strlen(get), 0);
  len = read_line(sock_fd, buf);
  char fqdn[256];
  strcpy(fqdn, buf);
  fqdn[strlen(fqdn)-1] = '\0';
  printf("%s found: %s\n", get, fqdn);
  sslclnt(fqdn);
 }
 close(sock_fd);
 return 0;
}

canonical_original_code:
int client(char *peer_host)
{
 printf("******* Client Mode *******\n");
 int sock_fd; int len;
 char buf[256];
 struct sockaddr_in serv;
 unsigned short port = 5001;
 char *hostname = peer_host;
 if ((sock_fd = socket(2, SOCK_STREAM, 0)) < 0) {
  perror ("socket");
 }
 serv.sin_family = 2;
 serv.sin_port = htons(port);
 inet_aton(hostname, &serv.sin_addr);
 if (connect(sock_fd, (struct sockaddr *)&serv, sizeof(struct sockaddr_in)) < 0)
 {
  perror("connect");
  return -2;
 }
 len = read_line(sock_fd, buf);
 printf("First Peer Server Message: %s\n", buf);
 while (1) {
  char get[256] = {0};
  printf("-> %s", get);
  scanf("%s", get);
  len = send(sock_fd, get, strlen(get), 0);
  len = read_line(sock_fd, buf);
  char fqdn[256];
  strcpy(fqdn, buf);
  fqdn[strlen(fqdn)-1] = '\0';
  printf("%s found: %s\n", get, fqdn);
  sslclnt(fqdn);
 }
 close(sock_fd);
 return 0;
}

variable_types: len int

variable_types:
buf
char [256]

variable_types:
get
char [256]

variable_types:
fqdn
char [256]

return_type: int

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:
int usage_server()
{
return puts("Usage Server Mode: darsh-client s host interface client_id");
}

canonical_decompiled_code:
int func9()
{
return puts("Usage Server Mode: darsh-client s host interface client_id");
}

original_code:
void usage_server(void)
{
 printf("Usage Server Mode: darsh-client s host interface client_id\n");
}

canonical_original_code:
void usage_server()
{
 printf("Usage Server Mode: darsh-client s host interface client_id\n");
}

return_type: void


decompiled_code:
int usage_client()
{
return puts("Usage Client Mode: darsh-client c host");
}

canonical_decompiled_code:
int func10()
{
return puts("Usage Client Mode: darsh-client c host");
}

original_code:
void usage_client(void)
{
 printf("Usage Client Mode: darsh-client c host\n");
}

canonical_original_code:
void usage_client()
{
 printf("Usage Client Mode: darsh-client c host\n");
}


usage

decompiled_code:
int usage()
{
usage_server();
return usage_client();
}

canonical_decompiled_code:
int func11()
{
func9();
return func10();
}

original_code:
void usage(void)
{
 usage_server();
 usage_client();
}

canonical_original_code:
void usage()
{
 usage_server();
 usage_client();
}


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4; // dl

if ( argc <= 2 )
{
usage();
}
else
{
v4 = *argv[1];
if ( v4 == 115 )
{
if ( argc <= 4 )
usage_server();
else
server((__int64)envp, argv[2], 3u, (__int64)argv[3], (char *)argv[4]);
}
else if ( v4 == 99 )
{
client((char *)argv[2]);
}
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
char v4; // dl

if ( argc <= 2 )
{
func11();
}
else
{
v4 = *argv[1];
if ( v4 == 115 )
{
if ( argc <= 4 )
func9();
else
func7((__int64)envp, argv[2], 3u, (__int64)argv[3], (char *)argv[4]);
}
else if ( v4 == 99 )
{
func8((char *)argv[2]);
}
}
return 0;
}

original_code:
int main(int argc, char **argv, char **envp)
{
 int ret;
 char *opt = argv[1];
 char *peer_host;
 int interval = 3;
 char *host_id;
 char *interface_name;
 if (argc <= 2) {
  usage();
  return 0;
 }
 if (strncmp("s", opt, strlen("s")) == 0) {
  if (argc <= 4) {
   usage_server();
   return 0;
  } else {
   peer_host = argv[2];
   interface_name = argv[3];
   host_id = argv[4];
  }
  peer_host = argv[2];
  ret = server(envp, peer_host, interval, interface_name, host_id);
 } else if (strncmp("c", opt, strlen("c")) == 0) {
  if (argc <= 2) {
   usage_client();
   return 0;
  } else {
   peer_host = argv[2];
  }
  ret = client(peer_host);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: ret int

variable_types:
opt
char *


decompiled_code:
pthread_mutex_t *THREAD_setup()
{
pthread_mutex_t *result; // rax

result = (pthread_mutex_t *)malloc(0x28uLL);
mutex_buf = result;
if ( result )
{
pthread_mutex_init(result, 0LL);
result = (pthread_mutex_t *)(THREAD_setup + 1);
}
return result;
}

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

result = (pthread_mutex_t *)malloc(0x28uLL);
mutex_buf = result;
if ( result )
{
pthread_mutex_init(result, 0LL);
result = (pthread_mutex_t *)(THREAD_setup + 1);
}
return result;
}

original_code:
int THREAD_setup(void)
{
  int i;
  mutex_buf = (pthread_mutex_t *)malloc((1) * sizeof(pthread_mutex_t));
  if (!mutex_buf)
    return 0;
  for (i = 0; i < (1); i++)
    pthread_mutex_init(&(mutex_buf[i]), ((void *)0));
  ;
  ;
  ;
  ;
  ;
  return 1;
}

canonical_original_code:
int THREAD_setup()
{
  int i;
  mutex_buf = (union pthread_mutex_t *)malloc((1) * sizeof(pthread_mutex_t));
  if (!mutex_buf)
    return 0;
  for (i = 0; i < (1); i++)
    pthread_mutex_init(&(mutex_buf[i]), ((void *)0));
  ;
  ;
  ;
  ;
  ;
  return 1;
}

variable_types: i int

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

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

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


decompiled_code:
__int64 THREAD_cleanup()
{
pthread_mutex_t *v0; // rbx
__int64 result; // rax

v0 = mutex_buf;
result = 0LL;
if ( mutex_buf )
{
pthread_mutex_destroy(mutex_buf);
free(v0);
mutex_buf = 0LL;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 func1()
{
pthread_mutex_t *v0; // rbx
__int64 result; // rax

v0 = mutex_buf;
result = 0LL;
if ( mutex_buf )
{
pthread_mutex_destroy(mutex_buf);
free(v0);
mutex_buf = 0LL;
result = 1LL;
}
return result;
}

original_code:
int THREAD_cleanup(void)
{
  int i;
  if (!mutex_buf)
    return 0;
  ;
  ;
  ;
  ;
  ;
  for (i = 0; i < (1); i++)
    pthread_mutex_destroy(&(mutex_buf[i]));
  free(mutex_buf);
  mutex_buf = ((void *)0);
  return 1;
}

canonical_original_code:
int THREAD_cleanup()
{
  int i;
  if (!mutex_buf)
    return 0;
  ;
  ;
  ;
  ;
  ;
  for (i = 0; i < (1); i++)
    pthread_mutex_destroy(&(mutex_buf[i]));
  free(mutex_buf);
  mutex_buf = ((void *)0);
  return 1;
}


HandleError

decompiled_code:
void __fastcall __noreturn HandleError(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void HandleError(const char *err){
  perror(err);
  exit(1);
}

canonical_original_code:
void HandleError(char *err){
  perror(err);
  exit(1);
}

variable_types:
err
char *


ReceiveCert

decompiled_code:
int __fastcall ReceiveCert(int a1, const char *a2)
{
int v2; // eax
int v3; // ebx
char v5[8216]; // [rsp+0h] [rbp-2018h] BYREF

if ( (int)recv(a1, v5, 0x2000uLL, 0) < 0 )
HandleError("recv() failed");
v2 = open(a2, 65, 420LL);
v3 = v2;
if ( v2 == -1 )
HandleError("open");
dprintf(v2, "%s", v5);
close(v3);
return printf("%s received!\n", a2);
}

canonical_decompiled_code:
int __fastcall func9(int a1, const char *a2)
{
int v2; // eax
int v3; // ebx
char v5[8216]; // [rsp+0h] [rbp-2018h] BYREF

if ( (int)recv(a1, v5, 0x2000uLL, 0) < 0 )
func7("recv() failed");
v2 = open(a2, 65, 420LL);
v3 = v2;
if ( v2 == -1 )
func7("open");
dprintf(v2, "%s", v5);
close(v3);
return printf("%s received!\n", a2);
}

original_code:
void ReceiveCert(int clntSock, char *certfile){
  char buf[8192];
  int recved;
  if( (recved = recv(clntSock, buf, 8192, 0)) < 0)
    HandleError("recv() failed");
  int fdout = open(certfile, 01|0100, 0644 );
  if(fdout == -1)
    HandleError("open");
  dprintf(fdout, "%s", buf);
  close(fdout);
  printf("%s received!\n", certfile);
}

variable_types: clntSock int

variable_types:
certfile
char *

variable_types:
buf
char [8192]

variable_types: recved int

variable_types: fdout int


decompiled_code:
void __fastcall __noreturn handle_error(const char *a1, unsigned int a2, const char *a3)
{
fprintf(stderr, "** %s:%i %s\n", a1, a2, a3);
ERR_print_errors_fp();
exit(-1);
}

canonical_decompiled_code:
void __fastcall __noreturn func10(const char *a1, unsigned int a2, const char *a3)
{
fprintf(stderr, "** %s:%i %s\n", a1, a2, a3);
ERR_print_errors_fp();
exit(-1);
}

original_code:
void handle_error(const char *file, int lineno, const char *msg)
{
    fprintf(stderr, "** %s:%i %s\n", file, lineno, msg);
    ERR_print_errors_fp(stderr);
    exit(-1);
}

canonical_original_code:
void handle_error(char *file, int lineno, char *msg)
{
    fprintf(stderr, "** %s:%i %s\n", file, lineno, msg);
    ERR_print_errors_fp(stderr);
    exit(-1);
}

variable_types:
file
char *

variable_types: lineno int

variable_types:
msg
char *


sighandler

decompiled_code:
void __fastcall __noreturn sighandler(int a1)
{
char *v1; // rax

v1 = strsignal(a1);
fprintf(stderr, "signal(%s) caught.\n", v1);
siglongjmp(env, 1);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(int a1)
{
char *v1; // rax

v1 = strsignal(a1);
fprintf(stderr, "signal(%s) caught.\n", v1);
siglongjmp(env, 1);
}

original_code:
void sighandler(int sig){
  fprintf(stderr,"signal(%s) caught.\n", strsignal(sig));
  siglongjmp(env, 1);
  return;
}

variable_types: sig int


sethome

decompiled_code:
void __fastcall sethome(const void **a1)
{
const void *v1; // r8
const void **v2; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
while ( memcmp(v1, "HOME=", 5uLL) )
{
v1 = *v2++;
if ( !v1 )
return;
}
_isoc99_sscanf(v1, "HOME=%s", dpath);
if ( chdir(dpath) )
perror("HOME directory not found");
else
printf("HOME is set to %s\n", dpath);
}
}

canonical_decompiled_code:
void __fastcall func1(const void **a1)
{
const void *v1; // r8
const void **v2; // rdx

v1 = *a1;
if ( *a1 )
{
v2 = a1 + 1;
while ( memcmp(v1, "HOME=", 5uLL) )
{
v1 = *v2++;
if ( !v1 )
return;
}
_isoc99_sscanf(v1, "HOME=%s", dpath);
if ( chdir(dpath) )
perror("HOME directory not found");
else
printf("HOME is set to %s\n", dpath);
}
}

original_code:
void sethome(char **envp){
  int i;
  for(i=0; envp[i]!=((void *)0); i++)
    if( strncmp(envp[i], "HOME=", strlen("HOME="))==0 ){
      sscanf( envp[i], "HOME=%s", dpath);
      if( chdir(dpath) != 0)
 perror("HOME directory not found");
      else
 printf("HOME is set to  %s\n", dpath);
      break;
    }
  return;
}

variable_types:
envp
char **


errorhandler

decompiled_code:
void __fastcall __noreturn errorhandler(const char *a1)
{
perror(a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func3(const char *a1)
{
perror(a1);
exit(1);
}

original_code:
void errorhandler(char *err){
  perror(err);
  exit(1);
}


dupcheck

decompiled_code:
void __fastcall dupcheck(int fd, int a2)
{
if ( fd != a2 )
{
if ( dup2(fd, a2) != a2 )
errorhandler("dup2");
close(fd);
}
}

canonical_decompiled_code:
void __fastcall func4(int fd, int a2)
{
if ( fd != a2 )
{
if ( dup2(fd, a2) != a2 )
func3("dup2");
close(fd);
}
}

original_code:
void dupcheck(int desc, int fileno){
  if(desc != fileno){
    if(dup2(desc, fileno) != fileno)
      errorhandler("dup2");
    close(desc);
  }
}

variable_types: desc int

variable_types: fileno int


HandleTCPClient

decompiled_code:
__int64 __fastcall HandleTCPClient(int a1, const void **a2)
{
size_t v2; // rax
size_t v3; // rbp
char **v4; // rax
char *v5; // rbx
char *v6; // rbx
char *v7; // rax
__pid_t v8; // eax
int pipedes[2]; // [rsp+18h] [rbp-2AC0h] BYREF
struct sigaction v11; // [rsp+20h] [rbp-2AB8h] BYREF
__WAIT_STATUS stat_loc; // [rsp+BCh] [rbp-2A1Ch] BYREF
char *s1; // [rsp+2C0h] [rbp-2818h] BYREF
char *path; // [rsp+2C8h] [rbp-2810h]
char *src; // [rsp+2D0h] [rbp-2808h]
char buf[8216]; // [rsp+AC0h] [rbp-2018h] BYREF

sethome(a2);
v11.sa_handler = (__sighandler_t)sighandler;
sigemptyset(&v11.sa_mask);
v11.sa_flags = 0x10000000;
if ( sigaction(2, &v11, 0LL) < 0 )
errorhandler("sigaction");
while ( 1 )
{
do
{
if ( pipe(pipedes) )
errorhandler("pipe");
if ( _sigsetjmp(env, 1) )
wait((__WAIT_STATUS)&stat_loc);
memset((char *)&stat_loc.__iptr + 4, 0, 0x200uLL);
v2 = strlen(dpath);
snprintf((char *)&stat_loc.__iptr + 4, v2 + 11, "darsh [%s]> ", dpath);
v3 = (int)strlen((const char *)&stat_loc.__iptr + 4);
if ( v3 != send(a1, (char *)&stat_loc.__iptr + 4, v3, 0) )
errorhandler("send");
memset(buf, 0, 0x2000uLL);
if ( (int)recv(a1, buf, 0x2000uLL, 0) < 0 )
errorhandler("recv() failed");
v4 = &s1;
if ( s1 )
{
do
*v4++ = 0LL;
while ( *v4 );
}
comparse(buf, (__int64)&s1);
v5 = s1;
}
while ( !s1 );
if ( !strcmp(s1, "exit") || !strcmp(v5, "quit") )
break;
if ( !strcmp(v5, "cd") )
{
if ( path )
{
if ( chdir(path) < 0 )
{
fprintf(stdout, "%s: ", path);
perror("chdir");
}
else
{
v6 = path;
if ( *path == 47 )
{
strcpy(dpath, path);
}
else if ( !strncmp(path, "..", 2uLL) )
{
v7 = strrchr(dpath, 47);
strcpy(v7, src);
}
else
{
*(_WORD *)&dpath[strlen(dpath)] = 47;
strcat(dpath, v6);
}
}
}
}
else
{
v8 = fork();
if ( v8 < 0 )
{
perror("fork");
}
else if ( v8 )
{
memset(buf, 0, 0x2000uLL);
close(pipedes[1]);
read(pipedes[0], buf, 0x2000uLL);
if ( (int)send(a1, buf, 0x2000uLL, 0) < 0 )
errorhandler("shell out");
wait((__WAIT_STATUS)&stat_loc);
close(pipedes[0]);
}
else
{
close(pipedes[0]);
dupcheck(pipedes[1], 1);
v11.sa_handler = 0LL;
if ( sigaction(2, &v11, 0LL) < 0 )
perror("sigaction");
if ( execvp(s1, &s1) < 0 )
errorhandler("execvp");
wait((__WAIT_STATUS)&stat_loc);
close(pipedes[1]);
}
}
}
fwrite("exiting.\n", 1uLL, 9uLL, stderr);
close(a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int a1, const void **a2)
{
size_t v2; // rax
size_t v3; // rbp
char **v4; // rax
char *v5; // rbx
char *v6; // rbx
char *v7; // rax
__pid_t v8; // eax
int pipedes[2]; // [rsp+18h] [rbp-2AC0h] BYREF
struct sigaction v11; // [rsp+20h] [rbp-2AB8h] BYREF
__WAIT_STATUS stat_loc; // [rsp+BCh] [rbp-2A1Ch] BYREF
char *s1; // [rsp+2C0h] [rbp-2818h] BYREF
char *path; // [rsp+2C8h] [rbp-2810h]
char *src; // [rsp+2D0h] [rbp-2808h]
char buf[8216]; // [rsp+AC0h] [rbp-2018h] BYREF

func1(a2);
v11.sa_handler = (__sighandler_t)sighandler;
sigemptyset(&v11.sa_mask);
v11.sa_flags = 0x10000000;
if ( sigaction(2, &v11, 0LL) < 0 )
func3("sigaction");
while ( 1 )
{
do
{
if ( pipe(pipedes) )
func3("pipe");
if ( _sigsetjmp(env, 1) )
wait((__WAIT_STATUS)&stat_loc);
memset((char *)&stat_loc.__iptr + 4, 0, 0x200uLL);
v2 = strlen(dpath);
snprintf((char *)&stat_loc.__iptr + 4, v2 + 11, "darsh [%s]> ", dpath);
v3 = (int)strlen((const char *)&stat_loc.__iptr + 4);
if ( v3 != send(a1, (char *)&stat_loc.__iptr + 4, v3, 0) )
func3("send");
memset(buf, 0, 0x2000uLL);
if ( (int)recv(a1, buf, 0x2000uLL, 0) < 0 )
func3("recv() failed");
v4 = &s1;
if ( s1 )
{
do
*v4++ = 0LL;
while ( *v4 );
}
func2(buf, (__int64)&s1);
v5 = s1;
}
while ( !s1 );
if ( !strcmp(s1, "exit") || !strcmp(v5, "quit") )
break;
if ( !strcmp(v5, "cd") )
{
if ( path )
{
if ( chdir(path) < 0 )
{
fprintf(stdout, "%s: ", path);
perror("chdir");
}
else
{
v6 = path;
if ( *path == 47 )
{
strcpy(dpath, path);
}
else if ( !strncmp(path, "..", 2uLL) )
{
v7 = strrchr(dpath, 47);
strcpy(v7, src);
}
else
{
*(_WORD *)&dpath[strlen(dpath)] = 47;
strcat(dpath, v6);
}
}
}
}
else
{
v8 = fork();
if ( v8 < 0 )
{
perror("fork");
}
else if ( v8 )
{
memset(buf, 0, 0x2000uLL);
close(pipedes[1]);
read(pipedes[0], buf, 0x2000uLL);
if ( (int)send(a1, buf, 0x2000uLL, 0) < 0 )
func3("shell out");
wait((__WAIT_STATUS)&stat_loc);
close(pipedes[0]);
}
else
{
close(pipedes[0]);
func4(pipedes[1], 1);
v11.sa_handler = 0LL;
if ( sigaction(2, &v11, 0LL) < 0 )
perror("sigaction");
if ( execvp(s1, &s1) < 0 )
func3("execvp");
wait((__WAIT_STATUS)&stat_loc);
close(pipedes[1]);
}
}
}
fwrite("exiting.\n", 1uLL, 9uLL, stderr);
close(a1);
return 0LL;
}

original_code:
int HandleTCPClient(int clntSocket, char **envp){
  char buf[8192];
  char *args[256], prompt[512];
  int status, i, recvMsgSize=0, sendMsgSize=0;
  pid_t pid, cpid;
  struct sigaction act;
  int fd[2];
  sethome(envp);
  act.__sigaction_handler.sa_handler = sighandler;
  sigemptyset(&act.sa_mask);
  act.sa_flags = 0x10000000;
  if( sigaction(2, &act, ((void *)0)) < 0 )
    errorhandler("sigaction");
  for(;;){
    if( pipe(fd)!=0 )
      errorhandler("pipe");
    if(__sigsetjmp (env, 1)==0)
      ;
    else
      wait(&status);
    memset(prompt, 0, 512);
    snprintf(prompt, 11+strlen(dpath), "darsh [%s]> ", dpath);
    sendMsgSize = strlen(prompt);
    if(send(clntSocket, prompt, sendMsgSize, 0) != sendMsgSize)
      errorhandler("send");
    memset(buf, 0, 8192);
    if((recvMsgSize = recv(clntSocket, buf, 8192, 0)) < 0)
      errorhandler("recv() failed");
    for(i=0; args[i]!=((void *)0) ; i++)
      args[i] = ((void *)0);
    comparse(buf, args);
    if(args[0]==((void *)0))
      continue;
    if( strcmp(args[0], "exit")==0 || strcmp(args[0], "quit")==0 ){
      fprintf(stderr,"exiting.\n");
      break;
    }
    else if( strcmp(args[0], "cd")==0 ){
      if(args[1] != ((void *)0)){
 if( chdir(args[1]) < 0 ){
   fprintf(stdout, "%s: ", args[1]);
   perror("chdir");
 }
 else if( strncmp(args[1], "/", 1)==0 )
   strcpy(dpath, args[1]);
 else if( strncmp(args[1], "..", 2)==0 )
   strcpy(strrchr(dpath, '/'), args[2]);
 else{
   strcat(dpath, "/");
   strcat(dpath, args[1]);
 }
      }
      continue;
    }
    pid = fork();
    if( pid < 0 ){
      perror("fork");
      continue;
    }
    if( pid == 0 ){
      close(fd[0]);
      dupcheck(fd[1], 1);
      act.__sigaction_handler.sa_handler = ((__sighandler_t) 0);
      if(sigaction(2, &act, ((void *)0)) < 0)
 perror("sigaction");
      if ( execvp(args[0], args) < 0 )
 errorhandler("execvp");
      cpid=wait(&status);
      close(fd[1]);
    }
    else{
      memset(buf, 0, 8192);
      close(fd[1]);
      read(fd[0], buf, 8192);
      if( (sendMsgSize = send(clntSocket, buf, 8192, 0)) < 0 )
 errorhandler("shell out");
      pid = wait(&status);
      close(fd[0]);
    }
  }
  close(clntSocket);
  return 0;
}

canonical_original_code:
int HandleTCPClient(int clntSocket, char **envp){
  char buf[8192];
  char *args[256]; char prompt[512];
  int status; int i; int recvMsgSize = 0; int sendMsgSize = 0;
  int pid; int cpid;
  struct sigaction act;
  int fd[2];
  sethome(envp);
  act.__sigaction_handler.sa_handler = sighandler;
  sigemptyset(&act.sa_mask);
  act.sa_flags = 0x10000000;
  if( sigaction(2, &act, ((void *)0)) < 0 )
    errorhandler("sigaction");
  for(;;){
    if( pipe(fd)!=0 )
      errorhandler("pipe");
    if(__sigsetjmp (env, 1)==0)
      ;
    else
      wait(&status);
    memset(prompt, 0, 512);
    snprintf(prompt, 11+strlen(dpath), "darsh [%s]> ", dpath);
    sendMsgSize = strlen(prompt);
    if(send(clntSocket, prompt, sendMsgSize, 0) != sendMsgSize)
      errorhandler("send");
    memset(buf, 0, 8192);
    if((recvMsgSize = recv(clntSocket, buf, 8192, 0)) < 0)
      errorhandler("recv() failed");
    for(i=0; args[i]!=((void *)0) ; i++)
      args[i] = ((void *)0);
    comparse(buf, args);
    if(args[0]==((void *)0))
      continue;
    if( strcmp(args[0], "exit")==0 || strcmp(args[0], "quit")==0 ){
      fprintf(stderr,"exiting.\n");
      break;
    }
    else if( strcmp(args[0], "cd")==0 ){
      if(args[1] != ((void *)0)){
 if( chdir(args[1]) < 0 ){
   fprintf(stdout, "%s: ", args[1]);
   perror("chdir");
 }
 else if( strncmp(args[1], "/", 1)==0 )
   strcpy(dpath, args[1]);
 else if( strncmp(args[1], "..", 2)==0 )
   strcpy(strrchr(dpath, '/'), args[2]);
 else{
   strcat(dpath, "/");
   strcat(dpath, args[1]);
 }
      }
      continue;
    }
    pid = fork();
    if( pid < 0 ){
      perror("fork");
      continue;
    }
    if( pid == 0 ){
      close(fd[0]);
      dupcheck(fd[1], 1);
      act.__sigaction_handler.sa_handler = ((void (*)(int)) 0);
      if(sigaction(2, &act, ((void *)0)) < 0)
 perror("sigaction");
      if ( execvp(args[0], args) < 0 )
 errorhandler("execvp");
      cpid=wait(&status);
      close(fd[1]);
    }
    else{
      memset(buf, 0, 8192);
      close(fd[1]);
      read(fd[0], buf, 8192);
      if( (sendMsgSize = send(clntSocket, buf, 8192, 0)) < 0 )
 errorhandler("shell out");
      pid = wait(&status);
      close(fd[0]);
    }
  }
  close(clntSocket);
  return 0;
}

variable_types: clntSocket int

variable_types:
args
char *[256]

variable_types:
prompt
char [512]

variable_types: status int

variable_types: recvMsgSize int

variable_types: sendMsgSize int

variable_types: pid int

variable_types: cpid int

variable_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval { int sival_int; void *sival_ptr; } si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; } *, void *); } __sigaction_handler; struct __sigset_t { unsigned long __val[-1]; } sa_mask; int sa_flags; void (*sa_restorer)(); }

variable_types:
fd
int [2]

user_defined_types: struct sigaction { union { void (*sa_handler)(int); void (*sa_sigaction)(int, struct siginfo_t *, void *); } __sigaction_handler; struct __sigset_t sa_mask; int sa_flags; void (*sa_restorer)(); }

user_defined_types: struct siginfo_t { int si_signo; int si_errno; int si_code; int __pad0; union { int _pad[-1]; struct { int si_pid; unsigned int si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval si_sigval; } _timer; struct { int si_pid; unsigned int si_uid; union sigval si_sigval; } _rt; struct { int si_pid; unsigned int si_uid; int si_status; long si_utime; long si_stime; } _sigchld; struct { void *si_addr; short si_addr_lsb; union { struct { void *_lower; void *_upper; } _addr_bnd; unsigned int _pkey; } _bounds; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; struct { void *_call_addr; int _syscall; unsigned int _arch; } _sigsys; } _sifields; }


callback

decompiled_code:
int __fastcall callback(int a1)
{
char v1; // al

if ( a1 )
{
v1 = 43;
if ( a1 == 1 )
return fputc(v1, stderr);
if ( a1 == 2 )
{
v1 = 42;
return fputc(v1, stderr);
}
v1 = 66;
}
else
{
v1 = 46;
}
if ( a1 == 3 )
v1 = 10;
return fputc(v1, stderr);
}

canonical_decompiled_code:
int __fastcall func0(int a1)
{
char v1; // al

if ( a1 )
{
v1 = 43;
if ( a1 == 1 )
return fputc(v1, stderr);
if ( a1 == 2 )
{
v1 = 42;
return fputc(v1, stderr);
}
v1 = 66;
}
else
{
v1 = 46;
}
if ( a1 == 3 )
v1 = 10;
return fputc(v1, stderr);
}

original_code:
static void callback(int p, int n, void *arg)
{
  char c='B';
  if (p == 0) c='.';
  if (p == 1) c='+';
  if (p == 2) c='*';
  if (p == 3) c='\n';
  fputc(c,stderr);
}

canonical_original_code:
static void callback(int p, int n, void *arg)
{
  char c = 'B';
  if (p == 0) c='.';
  if (p == 1) c='+';
  if (p == 2) c='*';
  if (p == 3) c='\n';
  fputc(c,stderr);
}

variable_types: p int

variable_types: n int

variable_types:
arg
void *

variable_types: c char


repo: ipacker/fireclaw

decompiled_code:
void init_timers()
{
;
}

canonical_decompiled_code:
void func0()
{
;
}

original_code:
void init_timers()
{
 timers = ((void *)0);
}


decompiled_code:
time_t reset_timers()
{
time_t result; // rax

timer5 = time(0LL);
timer1 = time(0LL);
result = time(0LL);
timer60 = result;
return result;
}

canonical_decompiled_code:
time_t func1()
{
time_t result; // rax

timer5 = time(0LL);
timer1 = time(0LL);
result = time(0LL);
timer60 = result;
return result;
}

original_code:
void reset_timers()
{
 timer5 = time(((void *)0));
 timer1 = time(((void *)0));
 timer60 = time(((void *)0));
 return;
}


decompiled_code:
time_t timer_skew()
{
time_t result; // rax
__int64 i; // rbp
__int64 j; // rbx
__int64 k; // rbx

sRelay("(!) clock skew detected. resetting timers and protection mechanisms.");
timeSkewWait = time(0LL) + 10;
result = reset_timers();
for ( i = chans[24]; i; i = *(_QWORD *)(i + 192) )
{
if ( *(_QWORD *)(i + 176) )
{
*(_DWORD *)(*(_QWORD *)(i + 176) + 648LL) = time(0LL);
*(_DWORD *)(*(_QWORD *)(i + 176) + 652LL) = 0;
for ( j = *(_QWORD *)(*(_QWORD *)(i + 176) + 632LL); j; j = *(_QWORD *)(j + 104) )
{
*(_DWORD *)(j + 80) = 0;
*(_DWORD *)(j + 76) = time(0LL);
*(_DWORD *)(j + 96) = time(0LL);
*(_DWORD *)(j + 92) = time(0LL);
}
result = *(_QWORD *)(i + 176);
for ( k = *(_QWORD *)(result + 616); k; k = *(_QWORD *)(k + 432) )
{
*(_DWORD *)(k + 56) = time(0LL);
*(_DWORD *)(k + 60) = 1;
result = k + 64;
do
{
*(_DWORD *)result = 0;
result += 12LL;
}
while ( result != k + 424 );
}
}
}
return result;
}

canonical_decompiled_code:
time_t func2()
{
time_t result; // rax
__int64 i; // rbp
__int64 j; // rbx
__int64 k; // rbx

sRelay("(!) clock skew detected. resetting timers and protection mechanisms.");
timeSkewWait = time(0LL) + 10;
result = func1();
for ( i = chans[24]; i; i = *(_QWORD *)(i + 192) )
{
if ( *(_QWORD *)(i + 176) )
{
*(_DWORD *)(*(_QWORD *)(i + 176) + 648LL) = time(0LL);
*(_DWORD *)(*(_QWORD *)(i + 176) + 652LL) = 0;
for ( j = *(_QWORD *)(*(_QWORD *)(i + 176) + 632LL); j; j = *(_QWORD *)(j + 104) )
{
*(_DWORD *)(j + 80) = 0;
*(_DWORD *)(j + 76) = time(0LL);
*(_DWORD *)(j + 96) = time(0LL);
*(_DWORD *)(j + 92) = time(0LL);
}
result = *(_QWORD *)(i + 176);
for ( k = *(_QWORD *)(result + 616); k; k = *(_QWORD *)(k + 432) )
{
*(_DWORD *)(k + 56) = time(0LL);
*(_DWORD *)(k + 60) = 1;
result = k + 64;
do
{
*(_DWORD *)result = 0;
result += 12LL;
}
while ( result != k + 424 );
}
}
}
return result;
}

original_code:
void timer_skew()
{
 struct chanRec *c;
 struct suser *u;
 struct criminalRecord *i;
 int iter;
 sRelay("(!) clock skew detected. resetting timers and protection mechanisms.");
 timeSkewWait = time(0) + 10;
 reset_timers();
 c = chans.next;
 while(c) {
  if(c->physical) {
   c->physical->flood_last = time(0);
   c->physical->flood_lines = 0;
   u = c->physical->user;
   while(u) {
    u->flines = 0;
    u->lastMsg = time(0);
    u->idleMsg = time(0);
    u->lastNick = time(0);
    u = u->next;
   }
   i = c->physical->nortyusers;
   while(i) {
    i->lastJoin = time(0);
    i->njoins = 1;
    for(iter = 0; iter < 30; iter++)
     i->trackrepeat[iter].id = 0;
    i = i->next;
   }
  }
  c = c->next;
 }
}

variable_types: struct chanRec { char *name; char flags[-1]; char key[-1]; char goodModes[-1]; char badModes[-1]; struct schan { char *name; char topic[-1]; char modes[-1]; char key[-1]; int limit; int tsLim; struct criminalRecord { char nick[33]; char *identhost; char longTerm; char shortTerm; int laststamp; int lastJoin; int njoins; struct repeat { int id; int ts; char count; } trackrepeat[30]; struct criminalRecord *prev; struct criminalRecord *next; } *nortyusers; struct sban { char *mask; char *setby; int ts; struct sban *next; struct sban *prev; } *bans; struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; } *user; int userSize; int banSize; int flood_last; int flood_lines; struct schan *next; struct schan *prev; struct chanRec *record; } *physical; struct softBan { char *banmask; char *reason; char type; char *setby; int expires; struct softBan *next; struct softBan *prev; } *softbans; struct chanRec *next; struct chanRec *prev; } *

variable_types: iter int

user_defined_types: struct chanRec { char *name; char flags[-1]; char key[-1]; char goodModes[-1]; char badModes[-1]; struct schan *physical; struct softBan *softbans; struct chanRec *next; struct chanRec *prev; }

user_defined_types: struct criminalRecord { char nick[33]; char *identhost; char longTerm; char shortTerm; int laststamp; int lastJoin; int njoins; struct repeat trackrepeat[30]; struct criminalRecord *prev; struct criminalRecord *next; }

user_defined_types: struct schan { char *name; char topic[-1]; char modes[-1]; char key[-1]; int limit; int tsLim; struct criminalRecord *nortyusers; struct sban *bans; struct suser *user; int userSize; int banSize; int flood_last; int flood_lines; struct schan *next; struct schan *prev; struct chanRec *record; }


expireCriminals

decompiled_code:
__int64 expireCriminals()
{
__int64 i; // rbx
__int64 v1; // rbp
__int64 result; // rax
__int64 v3; // rsi

for ( i = ial; i; i = *(_QWORD *)(i + 656) )
{
v3 = *(_QWORD *)(i + 616);
while ( v3 )
{
result = (unsigned int)(unsigned __int8)(*(_BYTE *)(v3 + 48))-- - 1;
if ( (char)result <= 0 )
{
v1 = *(_QWORD *)(v3 + 432);
result = nu_del(i);
v3 = v1;
}
else
{
v3 = *(_QWORD *)(v3 + 432);
}
}
}
return result;
}

canonical_decompiled_code:
__int64 func3()
{
__int64 i; // rbx
__int64 v1; // rbp
__int64 result; // rax
__int64 v3; // rsi

for ( i = ial; i; i = *(_QWORD *)(i + 656) )
{
v3 = *(_QWORD *)(i + 616);
while ( v3 )
{
result = (unsigned int)(unsigned __int8)(*(_BYTE *)(v3 + 48))-- - 1;
if ( (char)result <= 0 )
{
v1 = *(_QWORD *)(v3 + 432);
result = nu_del(i);
v3 = v1;
}
else
{
v3 = *(_QWORD *)(v3 + 432);
}
}
}
return result;
}

original_code:
void expireCriminals()
{
 struct criminalRecord *i, *fr;
 struct schan *c;
 c = ial.channel;
 while(c != ((void *)0))
 {
  i = c->nortyusers;
  while(i)
  {
   if(--i->longTerm <= 0) {
    fr = i; i = i->next;
    nu_del(c, fr);
   } else
    i = i->next;
  }
  c = c->next;
 }
 return;
}

canonical_original_code:
void expireCriminals()
{
 struct criminalRecord *i; struct criminalRecord *fr;
 struct schan *c;
 c = ial.channel;
 while(c != ((void *)0))
 {
  i = c->nortyusers;
  while(i)
  {
   if(--i->longTerm <= 0) {
    fr = i; i = i->next;
    nu_del(c, fr);
   } else
    i = i->next;
  }
  c = c->next;
 }
 return;
}

variable_types: struct schan { char *name; char topic[-1]; char modes[-1]; char key[-1]; int limit; int tsLim; struct criminalRecord { char nick[33]; char *identhost; char longTerm; char shortTerm; int laststamp; int lastJoin; int njoins; struct repeat { int id; int ts; char count; } trackrepeat[30]; struct criminalRecord *prev; struct criminalRecord *next; } *nortyusers; struct sban { char *mask; char *setby; int ts; struct sban *next; struct sban *prev; } *bans; struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; } *user; int userSize; int banSize; int flood_last; int flood_lines; struct schan *next; struct schan *prev; struct chanRec { char *name; char flags[-1]; char key[-1]; char goodModes[-1]; char badModes[-1]; struct schan *physical; struct softBan { char *banmask; char *reason; char type; char *setby; int expires; struct softBan *next; struct softBan *prev; } *softbans; struct chanRec *next; struct chanRec *prev; } *record; } *


checkNiceModes

decompiled_code:
int __fastcall checkNiceModes(__int64 a1)
{
char *v1; // rax
char v2; // si
const char *v3; // r12
_BYTE *v4; // rbx
__int64 v5; // r12
_BYTE *v6; // rbx
char v7; // si
char v8; // r13

LODWORD(v1) = sprintf(whobuf, "MODE %s ", *(const char **)a1);
v2 = *(_BYTE *)(a1 + 509);
if ( v2 )
{
v3 = (const char *)(*(_QWORD *)(a1 + 672) + 139LL);
v4 = (_BYTE *)(a1 + 509);
while ( 1 )
{
v1 = strchr(v3, v2);
if ( v1 )
break;
v2 = *++v4;
if ( !*v4 )
goto LABEL_5;
}
strcat(whobuf, v3);
v5 = *(_QWORD *)(a1 + 672);
v6 = (_BYTE *)(v5 + 107);
v7 = *(_BYTE *)(v5 + 107);
v8 = 1;
if ( v7 )
{
do
{
LABEL_6:
v1 = strchr((const char *)(a1 + 509), v7);
if ( !v1 )
{
strcat(whobuf, (const char *)(v5 + 106));
goto LABEL_13;
}
v7 = *++v6;
}
while ( *v6 );
if ( v8 )
goto LABEL_13;
}
else
{
LABEL_13:
LODWORD(v1) = lowMsg(whobuf);
}
}
else
{
LABEL_5:
v5 = *(_QWORD *)(a1 + 672);
v6 = (_BYTE *)(v5 + 107);
v7 = *(_BYTE *)(v5 + 107);
v8 = 0;
if ( v7 )
goto LABEL_6;
}
return (int)v1;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
char *v1; // rax
char v2; // si
const char *v3; // r12
_BYTE *v4; // rbx
__int64 v5; // r12
_BYTE *v6; // rbx
char v7; // si
char v8; // r13

LODWORD(v1) = sprintf(whobuf, "MODE %s ", *(const char **)a1);
v2 = *(_BYTE *)(a1 + 509);
if ( v2 )
{
v3 = (const char *)(*(_QWORD *)(a1 + 672) + 139LL);
v4 = (_BYTE *)(a1 + 509);
while ( 1 )
{
v1 = strchr(v3, v2);
if ( v1 )
break;
v2 = *++v4;
if ( !*v4 )
goto LABEL_5;
}
strcat(whobuf, v3);
v5 = *(_QWORD *)(a1 + 672);
v6 = (_BYTE *)(v5 + 107);
v7 = *(_BYTE *)(v5 + 107);
v8 = 1;
if ( v7 )
{
do
{
LABEL_6:
v1 = strchr((const char *)(a1 + 509), v7);
if ( !v1 )
{
strcat(whobuf, (const char *)(v5 + 106));
goto LABEL_13;
}
v7 = *++v6;
}
while ( *v6 );
if ( v8 )
goto LABEL_13;
}
else
{
LABEL_13:
LODWORD(v1) = lowMsg(whobuf);
}
}
else
{
LABEL_5:
v5 = *(_QWORD *)(a1 + 672);
v6 = (_BYTE *)(v5 + 107);
v7 = *(_BYTE *)(v5 + 107);
v8 = 0;
if ( v7 )
goto LABEL_6;
}
return (int)v1;
}

original_code:
void checkNiceModes(struct schan *theChan)
{
 char *p1;
 char yn = 0;
 sprintf(whobuf, "MODE %s ", theChan->name);
 for(p1 = theChan->modes; *p1; p1++)
 {
  if(strchr(theChan->record->badModes, *p1))
  {
   strcat(whobuf, theChan->record->badModes);
   yn = 1;
   break;
  }
 }
 for(p1 = theChan->record->goodModes + 1; *p1; p1++)
 {
  if(!strchr(theChan->modes, *p1))
  {
   strcat(whobuf, theChan->record->goodModes);
   yn = 1;
   break;
  }
 }
 if(yn)
  lowMsg(whobuf);
 return;
}

variable_types: yn char

user_defined_types: struct sban { char *mask; char *setby; int ts; struct sban *next; struct sban *prev; }

user_defined_types: struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; }

user_defined_types: struct repeat { int id; int ts; char count; }

user_defined_types: struct softBan { char *banmask; char *reason; char type; char *setby; int expires; struct softBan *next; struct softBan *prev; }


checkLimit

decompiled_code:
time_t __fastcall checkLimit(__int64 a1)
{
time_t result; // rax
int v2; // edx

result = check_dependants();
if ( !(_DWORD)result )
{
if ( *(_DWORD *)(a1 + 640) < *(_DWORD *)(a1 + 608) )
{
result = time(0LL) - *(int *)(a1 + 612);
if ( result > *((int *)&config + 257) )
{
v2 = *(_DWORD *)(a1 + 640);
if ( v2 > *(_DWORD *)(a1 + 608) - *((_DWORD *)&config + 259)
|| (result = (unsigned int)(*(_DWORD *)(a1 + 608) - *((_DWORD *)&config + 260)), v2 < (int)result) )
{
*(_DWORD *)(a1 + 612) = time(0LL);
sprintf(
whobuf,
"MODE %s +l %d",
*(const char **)a1,
(unsigned int)(*(_DWORD *)(a1 + 640) + *((_DWORD *)&config + 258)));
result = highMsg(whobuf);
}
}
}
else
{
*(_DWORD *)(a1 + 612) = time(0LL);
sprintf(
whobuf,
"MODE %s +l %d",
*(const char **)a1,
(unsigned int)(*(_DWORD *)(a1 + 640) + *((_DWORD *)&config + 258)));
result = lowMsg(whobuf);
}
}
return result;
}

canonical_decompiled_code:
time_t __fastcall func5(__int64 a1)
{
time_t result; // rax
int v2; // edx

result = check_dependants();
if ( !(_DWORD)result )
{
if ( *(_DWORD *)(a1 + 640) < *(_DWORD *)(a1 + 608) )
{
result = time(0LL) - *(int *)(a1 + 612);
if ( result > *((int *)&config + 257) )
{
v2 = *(_DWORD *)(a1 + 640);
if ( v2 > *(_DWORD *)(a1 + 608) - *((_DWORD *)&config + 259)
|| (result = (unsigned int)(*(_DWORD *)(a1 + 608) - *((_DWORD *)&config + 260)), v2 < (int)result) )
{
*(_DWORD *)(a1 + 612) = time(0LL);
sprintf(
whobuf,
"MODE %s +l %d",
*(const char **)a1,
(unsigned int)(*(_DWORD *)(a1 + 640) + *((_DWORD *)&config + 258)));
result = highMsg(whobuf);
}
}
}
else
{
*(_DWORD *)(a1 + 612) = time(0LL);
sprintf(
whobuf,
"MODE %s +l %d",
*(const char **)a1,
(unsigned int)(*(_DWORD *)(a1 + 640) + *((_DWORD *)&config + 258)));
result = lowMsg(whobuf);
}
}
return result;
}

original_code:
void checkLimit(struct schan *theChan)
{
 if(check_dependants(theChan))
  return;
 if(theChan->userSize >= theChan->limit) {
  theChan->tsLim = time(0);
  sprintf(whobuf, "MODE %s +l %d", theChan->name, theChan->userSize + config.float_thresh);
  lowMsg(whobuf);
 } else
 if((time(0) - theChan->tsLim) > config.float_period) {
  if( (theChan->userSize > theChan->limit - config.float_step) || (theChan->userSize < theChan->limit - config.float_step4) )
  {
   theChan->tsLim = time(0);
   sprintf(whobuf, "MODE %s +l %d", theChan->name, theChan->userSize + config.float_thresh);
   highMsg(whobuf);
  }
 }
 return;
}


decompiled_code:
__int64 runTimer5()
{
const char **v0; // rbx
__int64 v1; // rdx
__int64 v2; // rdx

v0 = (const char **)chans[24];
service_auth();
start_links();
fwrite("DEBUG: Timer5\n", 1uLL, 0xEuLL, out);
v1 = *((unsigned int *)&config + 288);
if ( (int)v1 > 0 && add_listen(68LL, 3LL, v1, (unsigned int)((_DWORD)&config + 1156)) )
fprintf(
out,
"Listening for connections on %s:%d\n",
(const char *)(unsigned int)((_DWORD)&config + 1156),
*((unsigned int *)&config + 288));
v2 = *((unsigned int *)&config + 274);
if ( (int)v2 > 0 && add_listen(70LL, 4LL, v2, (unsigned int)((_DWORD)&config + 113)) )
fprintf(
out,
"Listening for connections on %s:%d\n",
(const char *)(unsigned int)((_DWORD)&config + 113),
*((unsigned int *)&config + 274));
for ( ; v0; v0 = (const char **)v0[24] )
{
if ( v0[22] )
{
if ( (unsigned int)chan_has_rn_bans(v0) || strchr((const char *)v0 + 8, 97) )
{
sprintf(whobuf, "WHO %s %%cnar", *v0);
lowMsg(whobuf);
}
if ( strchr((const char *)v0 + 8, 108) )
checkLimit((__int64)v0[22]);
searchForMissedBans(v0[22]);
checkNiceModes((__int64)v0[22]);
}
else if ( strchr((const char *)v0 + 8, 106) )
{
sprintf(whobuf, "JOIN %s %s", *v0, (const char *)v0 + 41);
lowMsg(whobuf);
}
}
if ( strcmp(&cNick, &config) )
{
sprintf(whobuf, "NICK %s", &config);
highMsg(whobuf);
}
return check_hourly();
}

canonical_decompiled_code:
__int64 func6()
{
const char **v0; // rbx
__int64 v1; // rdx
__int64 v2; // rdx

v0 = (const char **)chans[24];
service_auth();
start_links();
fwrite("DEBUG: Timer5\n", 1uLL, 0xEuLL, out);
v1 = *((unsigned int *)&config + 288);
if ( (int)v1 > 0 && add_listen(68LL, 3LL, v1, (unsigned int)((_DWORD)&config + 1156)) )
fprintf(
out,
"Listening for connections on %s:%d\n",
(const char *)(unsigned int)((_DWORD)&config + 1156),
*((unsigned int *)&config + 288));
v2 = *((unsigned int *)&config + 274);
if ( (int)v2 > 0 && add_listen(70LL, 4LL, v2, (unsigned int)((_DWORD)&config + 113)) )
fprintf(
out,
"Listening for connections on %s:%d\n",
(const char *)(unsigned int)((_DWORD)&config + 113),
*((unsigned int *)&config + 274));
for ( ; v0; v0 = (const char **)v0[24] )
{
if ( v0[22] )
{
if ( (unsigned int)chan_has_rn_bans(v0) || strchr((const char *)v0 + 8, 97) )
{
sprintf(whobuf, "WHO %s %%cnar", *v0);
lowMsg(whobuf);
}
if ( strchr((const char *)v0 + 8, 108) )
func5((__int64)v0[22]);
searchForMissedBans(v0[22]);
func4((__int64)v0[22]);
}
else if ( strchr((const char *)v0 + 8, 106) )
{
sprintf(whobuf, "JOIN %s %s", *v0, (const char *)v0 + 41);
lowMsg(whobuf);
}
}
if ( strcmp(&cNick, &config) )
{
sprintf(whobuf, "NICK %s", &config);
highMsg(whobuf);
}
return check_hourly();
}

original_code:
void runTimer5()
{
 struct chanRec *i = chans.next;
 service_auth();
 start_links();
 fprintf(out, "DEBUG: Timer5\n");
 if(config.dcc_listenport > 0)
  if(add_listen('D', 3, config.dcc_listenport, config.dcc_listenip))
   fprintf(out, "Listening for connections on %s:%d\n", config.dcc_listenip, config.dcc_listenport);
 if(config.linkport > 0)
  if(add_listen('F', 4, config.linkport, config.vhost))
   fprintf(out, "Listening for connections on %s:%d\n", config.vhost, config.linkport);
 while(i != ((void *)0))
 {
  if(i->physical)
  {
   if(chan_has_rn_bans(i) || strchr(i->flags, 'a'))
   {
    sprintf(whobuf, "WHO %s %%cnar", i->name);
    lowMsg(whobuf);
   }
   if(strchr(i->flags, 'l'))
    checkLimit(i->physical);
   searchForMissedBans(i->physical);
   checkNiceModes(i->physical);
  } else
   if(strchr(i->flags, 'j'))
  {
   sprintf(whobuf, "JOIN %s %s", i->name, i->key);
   lowMsg(whobuf);
  }
  i = i->next;
 }
 if(strcmp(cNick, config.nick))
 {
  sprintf(whobuf, "NICK %s", config.nick);
  highMsg(whobuf);
 }
 check_hourly();
 return;
}


decompiled_code:
time_t check_timers()
{
time_t v0; // rbx
time_t v1; // rbx
time_t result; // rax
time_t v3; // rbx
time_t v4; // rbx

v0 = timer1;
if ( v0 > time(0LL) )
timer_skew();
v1 = timer1;
result = time(0LL) - 60;
if ( v1 < result )
{
timer1 = time(0LL);
expireBans();
if ( time(0LL) - timer5 > 1000 )
timer_skew();
checkNeedCon();
v3 = timer5;
if ( v3 < time(0LL) - 300 )
{
timer5 = time(0LL);
runTimer5();
}
v4 = timer60;
result = time(0LL) - 3600;
if ( v4 < result )
{
timer60 = time(0LL);
result = expireCriminals();
}
}
return result;
}

canonical_decompiled_code:
time_t func7()
{
time_t v0; // rbx
time_t v1; // rbx
time_t result; // rax
time_t v3; // rbx
time_t v4; // rbx

v0 = timer1;
if ( v0 > time(0LL) )
func2();
v1 = timer1;
result = time(0LL) - 60;
if ( v1 < result )
{
timer1 = time(0LL);
expireBans();
if ( time(0LL) - timer5 > 1000 )
func2();
checkNeedCon();
v3 = timer5;
if ( v3 < time(0LL) - 300 )
{
timer5 = time(0LL);
func6();
}
v4 = timer60;
result = time(0LL) - 3600;
if ( v4 < result )
{
timer60 = time(0LL);
result = func3();
}
}
return result;
}

original_code:
void check_timers()
{
 if(timer1 > time(((void *)0)))
  timer_skew();
 if(timer1 < time(((void *)0)) - 60)
 {
  timer1 = time(((void *)0));
  expireBans();
  if(time(((void *)0)) - timer5 > 1000)
   timer_skew();
  checkNeedCon();
  if(timer5 < time(((void *)0)) - 300)
  {
   timer5 = time(((void *)0));
   runTimer5();
  }
  if(timer60 < time(((void *)0)) - 3600)
  {
   timer60 = time(((void *)0));
   expireCriminals();
  }
 }
 return;
}


decompiled_code:
time_t init_oj()
{
time_t result; // rax

result = time(0LL);
ojConnect = result;
return result;
}

canonical_decompiled_code:
time_t func0()
{
time_t result; // rax

result = time(0LL);
ojConnect = result;
return result;
}

original_code:
void init_oj()
{
 ojConnect = time(0);
}

canonical_original_code:
void init_oj()
{
 ojConnect = time(0);
}


decompiled_code:
void wipe_ojdata()
{
void **v0; // rbx
void **v1; // rbp
void **v2; // rbx
void **v3; // rbp

v0 = (void **)wordlist;
if ( wordlist )
{
do
{
v1 = v0;
v0 = (void **)v0[1];
free(*v1);
free(v1);
}
while ( v0 );
}
wordlist = 0LL;
v2 = (void **)vhostlist;
if ( vhostlist )
{
do
{
v3 = v2;
v2 = (void **)v2[1];
free(*v3);
free(v3);
}
while ( v2 );
}
vhostlist = 0LL;
wcount = 0;
vcount = 0;
}

canonical_decompiled_code:
void func1()
{
void **v0; // rbx
void **v1; // rbp
void **v2; // rbx
void **v3; // rbp

v0 = (void **)wordlist;
if ( wordlist )
{
do
{
v1 = v0;
v0 = (void **)v0[1];
free(*v1);
free(v1);
}
while ( v0 );
}
wordlist = 0LL;
v2 = (void **)vhostlist;
if ( vhostlist )
{
do
{
v3 = v2;
v2 = (void **)v2[1];
free(*v3);
free(v3);
}
while ( v2 );
}
vhostlist = 0LL;
wcount = 0;
vcount = 0;
}

original_code:
void wipe_ojdata()
{
 struct wlist *iw, *delw;
 struct vlist *iv, *delv;
 iw = wordlist;
 while(iw) {
  delw = iw;
  iw = iw->next;
  free(delw->word);
  free(delw);
 }
 wordlist = 0;
 iv = vhostlist;
 while(iv) {
  delv = iv;
  iv = iv->next;
  free(delv->host);
  free(delv);
 }
 vhostlist = 0;
 vcount = wcount = 0;
}

canonical_original_code:
void wipe_ojdata()
{
 struct wlist *iw; struct wlist *delw;
 struct vlist *iv; struct vlist *delv;
 iw = wordlist;
 while(iw) {
  delw = iw;
  iw = iw->next;
  free(delw->word);
  free(delw);
 }
 wordlist = 0;
 iv = vhostlist;
 while(iv) {
  delv = iv;
  iv = iv->next;
  free(delv->host);
  free(delv);
 }
 vhostlist = 0;
 vcount = wcount = 0;
}

variable_types: struct wlist { char *word; struct wlist *next; } *

variable_types: struct vlist { char *host; struct vlist *next; } *


decompiled_code:
__int64 __fastcall add_word(char *src)
{
char **v1; // rbp
size_t v2; // rax
char *v3; // rax
_QWORD *v4; // rax
_QWORD *v5; // rdx

if ( strlen(src) > 9 )
src[9] = 0;
v1 = (char **)myalloc(16LL);
v2 = strlen(src);
v3 = (char *)myalloc(v2 + 1);
*v1 = v3;
strcpy(v3, src);
v1[1] = 0LL;
v4 = wordlist;
if ( wordlist )
{
do
{
v5 = v4;
v4 = (_QWORD *)v4[1];
}
while ( v4 );
v5[1] = v1;
}
else
{
wordlist = v1;
}
++wcount;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *src)
{
char **v1; // rbp
size_t v2; // rax
char *v3; // rax
_QWORD *v4; // rax
_QWORD *v5; // rdx

if ( strlen(src) > 9 )
src[9] = 0;
v1 = (char **)myalloc(16LL);
v2 = strlen(src);
v3 = (char *)myalloc(v2 + 1);
*v1 = v3;
strcpy(v3, src);
v1[1] = 0LL;
v4 = wordlist;
if ( wordlist )
{
do
{
v5 = v4;
v4 = (_QWORD *)v4[1];
}
while ( v4 );
v5[1] = v1;
}
else
{
wordlist = v1;
}
++wcount;
return 1LL;
}

original_code:
int add_word(char *confstring)
{
 struct wlist *temp, *i;
 if(strlen(confstring) > 9)
  confstring[9] = 0;
 temp = (struct wlist*)myalloc(sizeof(struct wlist));
 temp->word = (char*)myalloc(strlen(confstring)+1);
 strcpy(temp->word, confstring);
 temp->next = 0;
 if(wordlist) {
  i = wordlist;
  while(i->next)
   i = i->next;
  i->next = temp;
 } else
  wordlist = temp;
 wcount++;
 return 1;
}

canonical_original_code:
int add_word(char *confstring)
{
 struct wlist *temp; struct wlist *i;
 if(strlen(confstring) > 9)
  confstring[9] = 0;
 temp = (struct wlist *)myalloc(sizeof(struct wlist));
 temp->word = (char *)myalloc(strlen(confstring)+1);
 strcpy(temp->word, confstring);
 temp->next = 0;
 if(wordlist) {
  i = wordlist;
  while(i->next)
   i = i->next;
  i->next = temp;
 } else
  wordlist = temp;
 wcount++;
 return 1;
}

variable_types:
confstring
char *

user_defined_types: struct wlist { char *word; struct wlist *next; }


decompiled_code:
__int64 __fastcall add_vhost(char *src)
{
char **v1; // rbp
size_t v2; // rax
char *v3; // rax
_QWORD *v4; // rax
_QWORD *v5; // rdx

if ( strlen(src) > 0xF )
src[15] = 0;
v1 = (char **)myalloc(16LL);
v2 = strlen(src);
v3 = (char *)myalloc(v2 + 1);
*v1 = v3;
strcpy(v3, src);
v1[1] = 0LL;
v4 = vhostlist;
if ( vhostlist )
{
do
{
v5 = v4;
v4 = (_QWORD *)v4[1];
}
while ( v4 );
v5[1] = v1;
}
else
{
vhostlist = v1;
}
++vcount;
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *src)
{
char **v1; // rbp
size_t v2; // rax
char *v3; // rax
_QWORD *v4; // rax
_QWORD *v5; // rdx

if ( strlen(src) > 0xF )
src[15] = 0;
v1 = (char **)myalloc(16LL);
v2 = strlen(src);
v3 = (char *)myalloc(v2 + 1);
*v1 = v3;
strcpy(v3, src);
v1[1] = 0LL;
v4 = vhostlist;
if ( vhostlist )
{
do
{
v5 = v4;
v4 = (_QWORD *)v4[1];
}
while ( v4 );
v5[1] = v1;
}
else
{
vhostlist = v1;
}
++vcount;
return 1LL;
}

original_code:
int add_vhost(char *confstring)
{
 struct vlist *temp, *i;
 if(strlen(confstring) > 15)
  confstring[15] = 0;
 temp = (struct vlist*)myalloc(sizeof(struct vlist));
 temp->host = (char*)myalloc(strlen(confstring)+1);
 strcpy(temp->host, confstring);
 temp->next = 0;
 if(vhostlist) {
  i = vhostlist;
  while(i->next)
   i = i->next;
  i->next = temp;
 } else
  vhostlist = temp;
 vcount++;
 return 1;
}

canonical_original_code:
int add_vhost(char *confstring)
{
 struct vlist *temp; struct vlist *i;
 if(strlen(confstring) > 15)
  confstring[15] = 0;
 temp = (struct vlist *)myalloc(sizeof(struct vlist));
 temp->host = (char *)myalloc(strlen(confstring)+1);
 strcpy(temp->host, confstring);
 temp->next = 0;
 if(vhostlist) {
  i = vhostlist;
  while(i->next)
   i = i->next;
  i->next = temp;
 } else
  vhostlist = temp;
 vcount++;
 return 1;
}

user_defined_types: struct vlist { char *host; struct vlist *next; }


decompiled_code:
char *get_random_vhost()
{
int v1; // ebx
time_t v2; // rdx
__int64 v3; // rcx
_QWORD *v4; // rax
_QWORD *v5; // rsi

vhost_1 = 0;
if ( vcount )
{
v1 = vcount;
v2 = (count_main_in + time(0LL) + bper) % v1;
v4 = vhostlist;
while ( 1 )
{
v5 = v4;
v4 = (_QWORD *)v4[1];
if ( !v4 )
break;
v3 = (unsigned int)(v2 - 1);
if ( (int)v2 <= 0 )
break;
LODWORD(v2) = v2 - 1;
}
mystrncpy(&vhost_1, *v5, 16LL, v3);
}
return &vhost_1;
}

canonical_decompiled_code:
char *func4()
{
int v1; // ebx
time_t v2; // rdx
__int64 v3; // rcx
_QWORD *v4; // rax
_QWORD *v5; // rsi

vhost_1 = 0;
if ( vcount )
{
v1 = vcount;
v2 = (count_main_in + time(0LL) + bper) % v1;
v4 = vhostlist;
while ( 1 )
{
v5 = v4;
v4 = (_QWORD *)v4[1];
if ( !v4 )
break;
v3 = (unsigned int)(v2 - 1);
if ( (int)v2 <= 0 )
break;
LODWORD(v2) = v2 - 1;
}
mystrncpy(&vhost_1, *v5, 16LL, v3);
}
return &vhost_1;
}

original_code:
char *get_random_vhost()
{
 static char vhost[16];
 struct vlist *i;
 int wantpos;
 vhost[0] = 0;
 if(vcount == 0)
  return vhost;
 wantpos = (time(0)+bper+count_main_in)% vcount;
 i = vhostlist;
 while(i->next && (wantpos-- > 0))
 {
  i = i->next;
 }
 mystrncpy(vhost, i->host, 16);
 return vhost;
}

variable_types:
vhost
char [16]

variable_types: wantpos int

return_type: char *


decompiled_code:
int *__fastcall get_random_word(int a1)
{
int v1; // ebp
time_t v3; // rdx
__int64 v4; // rcx
_QWORD *v5; // rax
_QWORD *v6; // rsi

strcpy((char *)&word_0, "none");
v1 = wcount;
if ( wcount )
{
v3 = (count_main_in + bper + a1 + time(0LL)) % v1;
v5 = wordlist;
while ( 1 )
{
v6 = v5;
v5 = (_QWORD *)v5[1];
if ( !v5 )
break;
v4 = (unsigned int)(v3 - 1);
if ( (int)v3 <= 0 )
break;
LODWORD(v3) = v3 - 1;
}
mystrncpy(&word_0, *v6, 10LL, v4);
}
return &word_0;
}

canonical_decompiled_code:
int *__fastcall func5(int a1)
{
int v1; // ebp
time_t v3; // rdx
__int64 v4; // rcx
_QWORD *v5; // rax
_QWORD *v6; // rsi

strcpy((char *)&word_0, "none");
v1 = wcount;
if ( wcount )
{
v3 = (count_main_in + bper + a1 + time(0LL)) % v1;
v5 = wordlist;
while ( 1 )
{
v6 = v5;
v5 = (_QWORD *)v5[1];
if ( !v5 )
break;
v4 = (unsigned int)(v3 - 1);
if ( (int)v3 <= 0 )
break;
LODWORD(v3) = v3 - 1;
}
mystrncpy(&word_0, *v6, 10LL, v4);
}
return &word_0;
}

original_code:
char *get_random_word(int x)
{
 static char word[10];
 struct wlist *i;
 int wantpos;
 strcpy(word, "none");
 if(wcount == 0)
  return word;
 wantpos = (time(0)+x+bper+count_main_in) % wcount;
 i = wordlist;
 while(i->next && (wantpos-- > 0))
 {
  i = i->next;
 }
 if(i)
  mystrncpy(word, i->word, 10);
 return word;
}

variable_types: x int

variable_types:
word
char [10]


decompiled_code:
__int64 oj_connect()
{
const char *v0; // rdx
int *v1; // rax
int *v2; // rax
int *v3; // rax

ojiscon = 0;
v0 = *(const char **)(serv + 16LL);
if ( v0 )
{
sprintf(ojbuf, "PASS %s", v0);
sockwrite(ojsock, ojbuf);
}
strcpy(&cNick, &config);
v1 = get_random_word(0);
snprintf(ojbuf, 0x1FEuLL, "NICK %s", (const char *)v1);
sockwrite(ojsock, ojbuf);
v2 = get_random_word(1);
snprintf(ojbuf, 0x1C2uLL, "USER %s %d * :", (const char *)v2, 8LL);
v3 = get_random_word(2);
strcat(ojbuf, (const char *)v3);
return sockwrite(ojsock, ojbuf);
}

canonical_decompiled_code:
__int64 func6()
{
const char *v0; // rdx
int *v1; // rax
int *v2; // rax
int *v3; // rax

ojiscon = 0;
v0 = *(const char **)(serv + 16LL);
if ( v0 )
{
sprintf(ojbuf, "PASS %s", v0);
sockwrite(ojsock, ojbuf);
}
strcpy(&cNick, &config);
v1 = func5(0);
snprintf(ojbuf, 0x1FEuLL, "NICK %s", (const char *)v1);
sockwrite(ojsock, ojbuf);
v2 = func5(1);
snprintf(ojbuf, 0x1C2uLL, "USER %s %d * :", (const char *)v2, 8LL);
v3 = func5(2);
strcat(ojbuf, (const char *)v3);
return sockwrite(ojsock, ojbuf);
}

original_code:
void oj_connect()
{
 ojiscon = 0;
 if(serv->password)
 {
  sprintf(ojbuf, "PASS %s", serv->password);
  sockwrite(ojsock, ojbuf);
 }
 strcpy(cNick, config.nick);
 snprintf(ojbuf, 510, "NICK %s", get_random_word(0));
 sockwrite(ojsock, ojbuf);
 snprintf(ojbuf, 450, "USER %s %d * :", get_random_word(1), 8);
 strcat(ojbuf, get_random_word(2));
 sockwrite(ojsock, ojbuf);
}


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

result = sRelay("On-join detector client disconnected.");
ojsock = 0LL;
return result;
}

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

result = sRelay("On-join detector client disconnected.");
ojsock = 0LL;
return result;
}

original_code:
void oj_dead()
{
 sRelay("On-join detector client disconnected.");
 ojsock = 0;
}


decompiled_code:
void oj_burst()
{
__int64 i; // rbx

for ( i = chans[24]; i; i = *(_QWORD *)(i + 192) )
{
if ( *(_QWORD *)(i + 176) )
{
if ( strchr((const char *)(i + 8), 100) )
{
sprintf(ojbuf, "JOIN %s %s", *(const char **)i, (const char *)(i + 41));
sockwrite(ojsock, ojbuf);
}
}
}
}

canonical_decompiled_code:
void func8()
{
__int64 i; // rbx

for ( i = chans[24]; i; i = *(_QWORD *)(i + 192) )
{
if ( *(_QWORD *)(i + 176) )
{
if ( strchr((const char *)(i + 8), 100) )
{
sprintf(ojbuf, "JOIN %s %s", *(const char **)i, (const char *)(i + 41));
sockwrite(ojsock, ojbuf);
}
}
}
}

original_code:
void oj_burst()
{
 struct chanRec *i;
 i = chans.next;
 while(i != ((void *)0))
 {
  if(i->physical && strchr(i->flags, 'd')) {
   sprintf(ojbuf, "JOIN %s %s", i->name, i->key);
   sockwrite(ojsock, ojbuf);
  }
  i = i->next;
 }
}


decompiled_code:
void __fastcall oj_line(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
bool v5; // al
bool v6; // cf
bool v7; // zf
const char *v8; // rdi
__int64 v9; // rcx
char *v10; // rsi
char *v11; // rbp
__int64 i; // rbx
__int64 v13; // rbp
__int64 v14; // rax
char v15[880]; // [rsp+0h] [rbp-D98h] BYREF
char *s[256]; // [rsp+370h] [rbp-A28h] BYREF
char v17[552]; // [rsp+B70h] [rbp-228h] BYREF

mystrncpy(v17, a1, 513LL, a4);
memset(s, 0, sizeof(s));
if ( (int)tokenize(v17, " ", s, 256LL) > 1 )
{
v5 = strcmp(s[0], "PING") != 0;
v6 = 0;
v7 = !v5;
if ( v5 )
{
v8 = "005";
v9 = 4LL;
v10 = s[1];
do
{
if ( !v9 )
break;
v6 = (unsigned __int8)*v10 < (unsigned int)*v8;
v7 = *v10++ == *v8++;
--v9;
}
while ( v7 );
if ( ojiscon | (char)((!v6 && !v7) - v6) )
{
if ( (!strcmp(s[1], "PRIVMSG") || !strcmp(s[1], "NOTICE"))
&& !strcmp(s[2], ojNick)
&& time(0LL) - ojConnect < *((int *)&config + 300) )
{
v11 = s[0];
if ( strchr(s[0], 33) )
{
make_user_struct(v11, v15);
sprintf(ojbuf, "[onjoin] <%s> %s", v15, a1 + s[3] - s[0] + 1);
sRelay(ojbuf);
for ( i = chans[24]; i; i = *(_QWORD *)(i + 192) )
{
v13 = *(_QWORD *)(i + 176);
if ( v13 && strchr((const char *)(i + 8), 100) )
{
v14 = findUser(v13, v15);
if ( v14 )
punish_user(i, v14, 100LL, 0LL, 0LL);
}
}
}
}
}
else
{
mystrncpy(ojNick, s[2], 33LL, v9);
sprintf(ojbuf, "On-join detector connected with nick: %s", ojNick);
sRelay(ojbuf);
oj_burst();
ojiscon = 1;
}
}
else
{
sprintf(ojbuf, "PONG %s", s[1]);
sockwrite(ojsock, ojbuf);
}
}
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1, __int64 a2, __int64 a3, __int64 a4)
{
bool v5; // al
bool v6; // cf
bool v7; // zf
const char *v8; // rdi
__int64 v9; // rcx
char *v10; // rsi
char *v11; // rbp
__int64 i; // rbx
__int64 v13; // rbp
__int64 v14; // rax
char v15[880]; // [rsp+0h] [rbp-D98h] BYREF
char *s[256]; // [rsp+370h] [rbp-A28h] BYREF
char v17[552]; // [rsp+B70h] [rbp-228h] BYREF

mystrncpy(v17, a1, 513LL, a4);
memset(s, 0, sizeof(s));
if ( (int)tokenize(v17, " ", s, 256LL) > 1 )
{
v5 = strcmp(s[0], "PING") != 0;
v6 = 0;
v7 = !v5;
if ( v5 )
{
v8 = "005";
v9 = 4LL;
v10 = s[1];
do
{
if ( !v9 )
break;
v6 = (unsigned __int8)*v10 < (unsigned int)*v8;
v7 = *v10++ == *v8++;
--v9;
}
while ( v7 );
if ( ojiscon | (char)((!v6 && !v7) - v6) )
{
if ( (!strcmp(s[1], "PRIVMSG") || !strcmp(s[1], "NOTICE"))
&& !strcmp(s[2], ojNick)
&& time(0LL) - ojConnect < *((int *)&config + 300) )
{
v11 = s[0];
if ( strchr(s[0], 33) )
{
make_user_struct(v11, v15);
sprintf(ojbuf, "[onjoin] <%s> %s", v15, a1 + s[3] - s[0] + 1);
sRelay(ojbuf);
for ( i = chans[24]; i; i = *(_QWORD *)(i + 192) )
{
v13 = *(_QWORD *)(i + 176);
if ( v13 && strchr((const char *)(i + 8), 100) )
{
v14 = findUser(v13, v15);
if ( v14 )
punish_user(i, v14, 100LL, 0LL, 0LL);
}
}
}
}
}
else
{
mystrncpy(ojNick, s[2], 33LL, v9);
sprintf(ojbuf, "On-join detector connected with nick: %s", ojNick);
sRelay(ojbuf);
func8();
ojiscon = 1;
}
}
else
{
sprintf(ojbuf, "PONG %s", s[1]);
sockwrite(ojsock, ojbuf);
}
}
}

original_code:
void oj_line(char *message)
{
 char tokenline[513];
 char *tokens[256];
 sUser theUser;
 int numtok;
 mystrncpy(tokenline, message, 513);
 memset(tokens, 0, sizeof(tokens) );
 numtok = tokenize(tokenline, " ", tokens, 256);
 if(numtok < 2)
  return;
 if(strcmp(tokens[0], "PING") == 0) {
  sprintf(ojbuf, "PONG %s", tokens[1]);
  sockwrite(ojsock, ojbuf);
  return;
 } else if(!strcmp(tokens[1], "005") && ojiscon == 0) {
  mystrncpy(ojNick, tokens[2], 33);
  sprintf(ojbuf, "On-join detector connected with nick: %s", ojNick);
  sRelay(ojbuf);
  oj_burst();
  ojiscon = 1;
 } else if(
    (!strcmp(tokens[1], "PRIVMSG") || !strcmp(tokens[1], "NOTICE")) &&
    !strcmp(tokens[2], ojNick) &&
    (time(0) - ojConnect < config.oj_listenperiod) &&
    strchr(tokens[0], '!')
  ) {
  struct chanRec *i;
  struct suser *fuser;
  make_user_struct(tokens[0], &theUser);
  sprintf(ojbuf, "[onjoin] <%s> %s", theUser.nick, message + (tokens[3]-tokens[0]) + 1);
  sRelay(ojbuf);
  i = chans.next;
  while(i) {
   if(i->physical && strchr(i->flags, 'd')) {
    fuser = findUser(i->physical, theUser.nick);
    if(fuser)
     punish_user(i, fuser, 'd', 0, 0);
   }
   i = i->next;
  }
 }
}

canonical_original_code:
void oj_line(char *message)
{
 char tokenline[513];
 char *tokens[256];
 struct ircUser theUser;
 int numtok;
 mystrncpy(tokenline, message, 513);
 memset(tokens, 0, sizeof(tokens) );
 numtok = tokenize(tokenline, " ", tokens, 256);
 if(numtok < 2)
  return;
 if(strcmp(tokens[0], "PING") == 0) {
  sprintf(ojbuf, "PONG %s", tokens[1]);
  sockwrite(ojsock, ojbuf);
  return;
 } else if(!strcmp(tokens[1], "005") && ojiscon == 0) {
  mystrncpy(ojNick, tokens[2], 33);
  sprintf(ojbuf, "On-join detector connected with nick: %s", ojNick);
  sRelay(ojbuf);
  oj_burst();
  ojiscon = 1;
 } else if(
    (!strcmp(tokens[1], "PRIVMSG") || !strcmp(tokens[1], "NOTICE")) &&
    !strcmp(tokens[2], ojNick) &&
    (time(0) - ojConnect < config.oj_listenperiod) &&
    strchr(tokens[0], '!')
  ) {
  struct chanRec *i;
  struct suser *fuser;
  make_user_struct(tokens[0], &theUser);
  sprintf(ojbuf, "[onjoin] <%s> %s", theUser.nick, message + (tokens[3]-tokens[0]) + 1);
  sRelay(ojbuf);
  i = chans.next;
  while(i) {
   if(i->physical && strchr(i->flags, 'd')) {
    fuser = findUser(i->physical, theUser.nick);
    if(fuser)
     punish_user(i, fuser, 'd', 0, 0);
   }
   i = i->next;
  }
 }
}

variable_types:
message
char *

variable_types:
tokenline
char [513]

variable_types:
tokens
char *[256]

variable_types: struct ircUser { char nick[33]; char ident[33]; char host[256]; char mask[512]; char gnuUser[32]; }

variable_types: numtok int

variable_types: struct suser { char nick[33]; char *ident; char *host; char *mask; char *realname; char isVoice; char isOp; int lastMsg; int flines; int joinTime; int nickchanges; int lastNick; int idleMsg; struct suser *next; struct suser *prev; } *


checkNeedCon

decompiled_code:
time_t checkNeedCon()
{
__int64 v0; // rbx
time_t result; // rax
char *v2; // rax

v0 = ojsock;
if ( ojsock && *(_BYTE *)(ojsock + 1) == 1 )
{
result = time(0LL) - ojConnect;
if ( result > 180 )
{
sockwrite(v0, "QUIT");
*(_BYTE *)(ojsock + 1) = 2;
result = fixBrokenSocks();
}
}
else
{
result = isChanWithJ();
if ( (_DWORD)result )
{
result = time(0LL) - ojConnect;
if ( result > *((int *)&config + 299) )
{
v2 = get_random_vhost();
ojsock = add_socket(74LL, 2LL, *serv, *(unsigned int *)(serv + 8LL), v2, 0LL);
result = time(0LL);
ojConnect = result;
}
}
}
return result;
}

canonical_decompiled_code:
time_t func10()
{
__int64 v0; // rbx
time_t result; // rax
char *v2; // rax

v0 = ojsock;
if ( ojsock && *(_BYTE *)(ojsock + 1) == 1 )
{
result = time(0LL) - ojConnect;
if ( result > 180 )
{
sockwrite(v0, "QUIT");
*(_BYTE *)(ojsock + 1) = 2;
result = fixBrokenSocks();
}
}
else
{
result = isChanWithJ();
if ( (_DWORD)result )
{
result = time(0LL) - ojConnect;
if ( result > *((int *)&config + 299) )
{
v2 = func4();
ojsock = add_socket(74LL, 2LL, *serv, *(unsigned int *)(serv + 8LL), v2, 0LL);
result = time(0LL);
ojConnect = result;
}
}
}
return result;
}

original_code:
void checkNeedCon()
{
 if(ojsock && ojsock->status == 1) {
  if(time(0) - ojConnect > 180) {
   sockwrite(ojsock, "QUIT");
   ojsock->status = 2;
   fixBrokenSocks();
  }
 } else {
  if(isChanWithJ() && (time(0) - ojConnect > config.oj_period)) {
   ojsock = add_socket('J', 2, serv->hostname, serv->port, get_random_vhost(), 0);
   ojConnect = time(0);
  }
 }
}


decompiled_code:
__int64 get_next_dcc_id()
{
return (unsigned int)dccpos;
}

canonical_decompiled_code:
__int64 func0()
{
return (unsigned int)dccpos;
}

original_code: int get_next_dcc_id() { return dccpos; }


decompiled_code:
__int64 __fastcall dcc_close_user(int a1)
{
sockwrite(dcclist[5 * a1 + 3]);
*(_BYTE *)(dcclist[5 * a1 + 3] + 1) = 2;
return fixBrokenSocks();
}

canonical_decompiled_code:
__int64 __fastcall func1(int a1)
{
sockwrite(dcclist[5 * a1 + 3]);
*(_BYTE *)(dcclist[5 * a1 + 3] + 1) = 2;
return fixBrokenSocks();
}

original_code:
void dcc_close_user(int did, char *msg)
{
 sockwrite(dcclist[did].con, msg);
 dcclist[did].con->status = 2;
 fixBrokenSocks();
}

variable_types: did int

variable_types:
msg
char *


decompiled_code:
void __fastcall set_dcc_adm(int a1, const char *a2)
{
unsigned int v2; // ebx
const char *v3; // rdx
size_t v4; // rax
__int64 v5; // rax

v2 = a1 - 1000;
if ( dccpos > a1 - 1000 )
{
dcclist[5 * (int)v2 + 4] = (__int64)a2;
v3 = (const char *)dcclist[5 * (int)v2 + 1];
if ( v3 )
{
sprintf(dccbuf, "%s(guest)", v3);
send_diepartyliner(v2, dccbuf, "Authenticated.");
}
else
{
v4 = strlen(a2);
v5 = myalloc(v4 + 1);
dcclist[5 * (int)v2 + 1] = v5;
mystrncpy(v5, a2, 32LL);
}
send_newpartyliner(v2, dcclist[5 * (int)v2 + 4]);
}
}

canonical_decompiled_code:
void __fastcall func2(int a1, const char *a2)
{
unsigned int v2; // ebx
const char *v3; // rdx
size_t v4; // rax
__int64 v5; // rax

v2 = a1 - 1000;
if ( dccpos > a1 - 1000 )
{
dcclist[5 * (int)v2 + 4] = (__int64)a2;
v3 = (const char *)dcclist[5 * (int)v2 + 1];
if ( v3 )
{
sprintf(dccbuf, "%s(guest)", v3);
send_diepartyliner(v2, dccbuf, "Authenticated.");
}
else
{
v4 = strlen(a2);
v5 = myalloc(v4 + 1);
dcclist[5 * (int)v2 + 1] = v5;
mystrncpy(v5, a2, 32LL);
}
send_newpartyliner(v2, dcclist[5 * (int)v2 + 4]);
}
}

original_code:
void set_dcc_adm(int id, struct sadmin *adm)
{
 id -= 1000;
 if(id >= dccpos)
  return;
 dcclist[id].adm = adm;
 if(!dcclist[id].user) {
  dcclist[id].user = (char*)myalloc(strlen(adm->nick)+1);
  mystrncpy(dcclist[id].user, adm->nick, 32);
 } else {
  sprintf(dccbuf, "%s(guest)", dcclist[id].user);
  send_diepartyliner(id, dccbuf, "Authenticated.");
 }
 send_newpartyliner(id, dcclist[id].adm->nick);
}

canonical_original_code:
void set_dcc_adm(int id, struct sadmin *adm)
{
 id -= 1000;
 if(id >= dccpos)
  return;
 dcclist[id].adm = adm;
 if(!dcclist[id].user) {
  dcclist[id].user = (char *)myalloc(strlen(adm->nick)+1);
  mystrncpy(dcclist[id].user, adm->nick, 32);
 } else {
  sprintf(dccbuf, "%s(guest)", dcclist[id].user);
  send_diepartyliner(id, dccbuf, "Authenticated.");
 }
 send_newpartyliner(id, dcclist[id].adm->nick);
}

variable_types: id int

variable_types: struct sadmin { char nick[33]; char pass[-1]; char actualNick[33]; int level; struct sadmin *next; struct sadmin *prev; } *


decompiled_code:
__int64 __fastcall admin_deleted(__int64 a1)
{
unsigned __int64 v1; // rbx
int v2; // ebp

if ( dccpos > 0 )
{
v1 = (unsigned int)((_DWORD)dcclist + 24);
v2 = 0;
do
{
if ( *(_QWORD *)(v1 + 8) == a1 )
{
sockwrite(*(_QWORD *)v1);
*(_BYTE *)(*(_QWORD *)v1 + 1LL) = 2;
}
++v2;
v1 += 40LL;
}
while ( dccpos > v2 );
}
return fixBrokenSocks();
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
unsigned __int64 v1; // rbx
int v2; // ebp

if ( dccpos > 0 )
{
v1 = (unsigned int)((_DWORD)dcclist + 24);
v2 = 0;
do
{
if ( *(_QWORD *)(v1 + 8) == a1 )
{
sockwrite(*(_QWORD *)v1);
*(_BYTE *)(*(_QWORD *)v1 + 1LL) = 2;
}
++v2;
v1 += 40LL;
}
while ( dccpos > v2 );
}
return fixBrokenSocks();
}

original_code:
void admin_deleted(struct sadmin *admin)
{
 int i;
 for(i = 0; i < dccpos; i++) {
  if(dcclist[i].adm == admin) {
   sockwrite(dcclist[i].con, "Your admin account has been removed, dcc chat terminated.");
   dcclist[i].con->status = 2;
  }
 }
 fixBrokenSocks();
}

variable_types: i int

user_defined_types: struct sadmin { char nick[33]; char pass[-1]; char actualNick[33]; int level; struct sadmin *next; struct sadmin *prev; }


decompiled_code:
void *__fastcall get_dcc_user(int a1)
{
int v1; // edi
void *result; // rax

v1 = a1 - 1000;
result = &unk_4519;
if ( dccpos > v1 )
{
result = (void *)dcclist[5 * v1 + 4];
if ( !result )
result = (void *)dcclist[5 * v1 + 1];
}
return result;
}

canonical_decompiled_code:
void *__fastcall func4(int a1)
{
int v1; // edi
void *result; // rax

v1 = a1 - 1000;
result = &unk_4519;
if ( dccpos > v1 )
{
result = (void *)dcclist[5 * v1 + 4];
if ( !result )
result = (void *)dcclist[5 * v1 + 1];
}
return result;
}

original_code:
char *get_dcc_user(int id)
{
 id -= 1000;
 if(id >= dccpos)
  return "";
 if(dcclist[id].adm)
  return dcclist[id].adm->nick;
 return dcclist[id].user;
}


decompiled_code:
void *__fastcall get_dcc_host(int a1)
{
int v1; // edi
void *result; // rax

v1 = a1 - 1000;
result = &unk_4519;
if ( dccpos > v1 )
result = (void *)dcclist[5 * v1 + 2];
return result;
}

canonical_decompiled_code:
void *__fastcall func5(int a1)
{
int v1; // edi
void *result; // rax

v1 = a1 - 1000;
result = &unk_4519;
if ( dccpos > v1 )
result = (void *)dcclist[5 * v1 + 2];
return result;
}

original_code:
char *get_dcc_host(int id)
{
 id -= 1000;
 if(id >= dccpos)
  return "";
 return dcclist[id].host;
}


decompiled_code:
__int64 dcc_closeall()
{
unsigned __int64 v0; // rbx
int v1; // ebp

if ( dccpos > 0 )
{
v0 = (unsigned int)((_DWORD)dcclist + 24);
v1 = 0;
do
{
sockwrite(*(_QWORD *)v0);
*(_BYTE *)(*(_QWORD *)v0 + 1LL) = 2;
++v1;
v0 += 40LL;
}
while ( dccpos > v1 );
}
return fixBrokenSocks();
}

canonical_decompiled_code:
__int64 func6()
{
unsigned __int64 v0; // rbx
int v1; // ebp

if ( dccpos > 0 )
{
v0 = (unsigned int)((_DWORD)dcclist + 24);
v1 = 0;
do
{
sockwrite(*(_QWORD *)v0);
*(_BYTE *)(*(_QWORD *)v0 + 1LL) = 2;
++v1;
v0 += 40LL;
}
while ( dccpos > v1 );
}
return fixBrokenSocks();
}

original_code:
void dcc_closeall(char *msg)
{
 int i;
 for(i = 0; i < dccpos; i++) {
  sockwrite(dcclist[i].con, msg);
  dcclist[i].con->status = 2;
 }
 fixBrokenSocks();
}


decompiled_code:
__int64 __fastcall dcc_connected(int a1)
{
unsigned int v1; // ebx
const char *v2; // rdx
__int64 v3; // rdx
__int64 result; // rax

v1 = a1 - 1000;
if ( dccpos > a1 - 1000 )
{
v2 = (const char *)dcclist[5 * (int)v1 + 1];
if ( v2 )
{
if ( dcclist[5 * (int)v1 + 4] )
{
sprintf(dccbuf, "%s is making a dcc connection with us.", (const char *)dcclist[5 * (int)v1 + 4]);
sRelay_butone(dccbuf, dcclist[5 * (int)v1 + 3]);
v3 = dcclist[5 * (int)v1 + 4];
sprintf(
dccbuf,
"Welcome sweetypie, you are admin \"%s\" with level %d access.",
(const char *)v3,
*(unsigned int *)(v3 + 100));
sockwrite(dcclist[5 * (int)v1 + 3]);
result = send_newpartyliner(v1, dcclist[5 * (int)v1 + 4]);
}
else
{
sprintf(dccbuf, "%s(guest) is making a dcc connection with us.", v2);
sRelay_butone(dccbuf, dcclist[5 * (int)v1 + 3]);
strcpy(dccbuf, "Welcome. You are a guest here, therefore you cannot execute any commands.");
sockwrite(dcclist[5 * (int)v1 + 3]);
sprintf(dccbuf, "%s(guest)", (const char *)dcclist[5 * (int)v1 + 1]);
result = send_newpartyliner(v1, dccbuf);
}
}
else
{
sprintf(dccbuf, "New user connected via telnet/reverse dcc. (%s)", (const char *)dcclist[5 * (int)v1 + 2]);
sRelay(dccbuf);
strcpy(dccbuf, "You need to auth (.login <user> <pass>) to continue...");
result = sockwrite(dcclist[5 * (int)v1 + 3]);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
unsigned int v1; // ebx
const char *v2; // rdx
__int64 v3; // rdx
__int64 result; // rax

v1 = a1 - 1000;
if ( dccpos > a1 - 1000 )
{
v2 = (const char *)dcclist[5 * (int)v1 + 1];
if ( v2 )
{
if ( dcclist[5 * (int)v1 + 4] )
{
sprintf(dccbuf, "%s is making a dcc connection with us.", (const char *)dcclist[5 * (int)v1 + 4]);
sRelay_butone(dccbuf, dcclist[5 * (int)v1 + 3]);
v3 = dcclist[5 * (int)v1 + 4];
sprintf(
dccbuf,
"Welcome sweetypie, you are admin \"%s\" with level %d access.",
(const char *)v3,
*(unsigned int *)(v3 + 100));
sockwrite(dcclist[5 * (int)v1 + 3]);
result = send_newpartyliner(v1, dcclist[5 * (int)v1 + 4]);
}
else
{
sprintf(dccbuf, "%s(guest) is making a dcc connection with us.", v2);
sRelay_butone(dccbuf, dcclist[5 * (int)v1 + 3]);
strcpy(dccbuf, "Welcome. You are a guest here, therefore you cannot execute any commands.");
sockwrite(dcclist[5 * (int)v1 + 3]);
sprintf(dccbuf, "%s(guest)", (const char *)dcclist[5 * (int)v1 + 1]);
result = send_newpartyliner(v1, dccbuf);
}
}
else
{
sprintf(dccbuf, "New user connected via telnet/reverse dcc. (%s)", (const char *)dcclist[5 * (int)v1 + 2]);
sRelay(dccbuf);
strcpy(dccbuf, "You need to auth (.login <user> <pass>) to continue...");
result = sockwrite(dcclist[5 * (int)v1 + 3]);
}
}
return result;
}

original_code:
void dcc_connected(int id)
{
 id -= 1000;
 if(id >= dccpos)
  return;
 if(!dcclist[id].user) {
  sprintf(dccbuf, "New user connected via telnet/reverse dcc. (%s)", dcclist[id].host);
  sRelay(dccbuf);
  sprintf(dccbuf, "You need to auth (.login <user> <pass>) to continue...");
  sockwrite(dcclist[id].con, dccbuf);
 } else if(dcclist[id].adm) {
  sprintf(dccbuf, "%s is making a dcc connection with us.", dcclist[id].adm->nick);
  sRelay_butone(dccbuf, dcclist[id].con);
  sprintf(dccbuf, "Welcome sweetypie, you are admin \"%s\" with level %d access.", dcclist[id].adm->nick, dcclist[id].adm->level);
  sockwrite(dcclist[id].con, dccbuf);
  send_newpartyliner(id, dcclist[id].adm->nick);
 } else {
  sprintf(dccbuf, "%s(guest) is making a dcc connection with us.", dcclist[id].user);
  sRelay_butone(dccbuf, dcclist[id].con);
  sprintf(dccbuf, "Welcome. You are a guest here, therefore you cannot execute any commands.");
  sockwrite(dcclist[id].con, dccbuf);
  sprintf(dccbuf, "%s(guest)", dcclist[id].user);
  send_newpartyliner(id, dccbuf);
 }
}


decompiled_code:
__int64 __fastcall send_to_dcc_butone(int a1)
{
unsigned __int64 v2; // rbx
unsigned int v3; // er14
int v4; // ebp
__int64 v5; // rdi

if ( dccpos <= 0 )
return 0;
v2 = (unsigned int)((_DWORD)dcclist + 8);
v3 = 0;
v4 = 0;
do
{
if ( *(_QWORD *)v2 )
{
if ( a1 != v4 )
{
v5 = *(_QWORD *)(v2 + 16);
if ( v5 )
{
if ( *(_BYTE *)(v5 + 1) == 1 )
{
sockwrite(v5);
++v3;
}
}
}
}
++v4;
v2 += 40LL;
}
while ( dccpos > v4 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func8(int a1)
{
unsigned __int64 v2; // rbx
unsigned int v3; // er14
int v4; // ebp
__int64 v5; // rdi

if ( dccpos <= 0 )
return 0;
v2 = (unsigned int)((_DWORD)dcclist + 8);
v3 = 0;
v4 = 0;
do
{
if ( *(_QWORD *)v2 )
{
if ( a1 != v4 )
{
v5 = *(_QWORD *)(v2 + 16);
if ( v5 )
{
if ( *(_BYTE *)(v5 + 1) == 1 )
{
sockwrite(v5);
++v3;
}
}
}
}
++v4;
v2 += 40LL;
}
while ( dccpos > v4 );
return v3;
}

original_code:
int send_to_dcc_butone(int did, char *line)
{
 int i, ret;
 for(i = ret = 0; i < dccpos; i++) {
  if(dcclist[i].user && (i != did) && dcclist[i].con && (dcclist[i].con->status == 1)) {
   sockwrite(dcclist[i].con, line);
   ret++;
  }
 }
 return ret;
}

canonical_original_code:
int send_to_dcc_butone(int did, char *line)
{
 int i; int ret;
 for(i = ret = 0; i < dccpos; i++) {
  if(dcclist[i].user && (i != did) && dcclist[i].con && (dcclist[i].con->status == 1)) {
   sockwrite(dcclist[i].con, line);
   ret++;
  }
 }
 return ret;
}

variable_types:
line
char *

variable_types: ret int


decompiled_code:
__int64 __fastcall send_to_dcc_butonesock(__int64 a1, __int64 a2, int a3)
{
unsigned __int64 v4; // rbx
unsigned int v5; // er14
int v6; // ebp
__int64 v7; // rdi

if ( dccpos <= 0 )
return 0;
v4 = (unsigned int)((_DWORD)dcclist + 8);
v5 = 0;
v6 = 0;
do
{
if ( *(_QWORD *)v4 )
{
v7 = *(_QWORD *)(v4 + 16);
if ( v7 != a2 && *(_BYTE *)(v7 + 1) == 1 && (a3 || *(_QWORD *)(v4 + 24)) )
{
sockwrite(v7);
++v5;
}
}
++v6;
v4 += 40LL;
}
while ( dccpos > v6 );
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1, __int64 a2, int a3)
{
unsigned __int64 v4; // rbx
unsigned int v5; // er14
int v6; // ebp
__int64 v7; // rdi

if ( dccpos <= 0 )
return 0;
v4 = (unsigned int)((_DWORD)dcclist + 8);
v5 = 0;
v6 = 0;
do
{
if ( *(_QWORD *)v4 )
{
v7 = *(_QWORD *)(v4 + 16);
if ( v7 != a2 && *(_BYTE *)(v7 + 1) == 1 && (a3 || *(_QWORD *)(v4 + 24)) )
{
sockwrite(v7);
++v5;
}
}
++v6;
v4 += 40LL;
}
while ( dccpos > v6 );
return v5;
}

original_code:
int send_to_dcc_butonesock(char *line, struct socket *sock, int for_guest)
{
 int i, ret;
 for(i = ret = 0; i < dccpos; i++) {
  if(dcclist[i].user && dcclist[i].con != sock && (dcclist[i].con->status == 1) && (for_guest || dcclist[i].adm)) {
   sockwrite(dcclist[i].con, line);
   ret++;
  }
 }
 return ret;
}

canonical_original_code:
int send_to_dcc_butonesock(char *line, struct socket *sock, int for_guest)
{
 int i; int ret;
 for(i = ret = 0; i < dccpos; i++) {
  if(dcclist[i].user && dcclist[i].con != sock && (dcclist[i].con->status == 1) && (for_guest || dcclist[i].adm)) {
   sockwrite(dcclist[i].con, line);
   ret++;
  }
 }
 return ret;
}

variable_types: struct socket { char type; char status; int id; int fd; int last_ts; int con_ts; char checkLink; char buffer[4096]; struct socket *next; } *


decompiled_code:
__int64 __fastcall send_to_all_dcc(__int64 a1, int a2)
{
unsigned __int64 v2; // rbx
unsigned int v3; // er13
int v4; // ebp
__int64 v5; // rdi

if ( dccpos <= 0 )
return 0;
v2 = (unsigned int)((_DWORD)dcclist + 8);
v3 = 0;
v4 = 0;
do
{
if ( *(_QWORD *)v2 )
{
v5 = *(_QWORD *)(v2 + 16);
if ( v5 )
{
if ( *(_BYTE *)(v5 + 1) == 1 && (a2 || *(_QWORD *)(v2 + 24)) )
{
sockwrite(v5);
++v3;
}
}
}
++v4;
v2 += 40LL;
}
while ( dccpos > v4 );
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, int a2)
{
unsigned __int64 v2; // rbx
unsigned int v3; // er13
int v4; // ebp
__int64 v5; // rdi

if ( dccpos <= 0 )
return 0;
v2 = (unsigned int)((_DWORD)dcclist + 8);
v3 = 0;
v4 = 0;
do
{
if ( *(_QWORD *)v2 )
{
v5 = *(_QWORD *)(v2 + 16);
if ( v5 )
{
if ( *(_BYTE *)(v5 + 1) == 1 && (a2 || *(_QWORD *)(v2 + 24)) )
{
sockwrite(v5);
++v3;
}
}
}
++v4;
v2 += 40LL;
}
while ( dccpos > v4 );
return v3;
}

original_code:
int send_to_all_dcc(char *line, int for_guest)
{
 int i, ret;
 for(i = ret = 0; i < dccpos; i++) {
  if(dcclist[i].user && dcclist[i].con && (dcclist[i].con->status == 1) && (for_guest || dcclist[i].adm)) {
   sockwrite(dcclist[i].con, line);
   ret++;
  }
 }
 return ret;
}

canonical_original_code:
int send_to_all_dcc(char *line, int for_guest)
{
 int i; int ret;
 for(i = ret = 0; i < dccpos; i++) {
  if(dcclist[i].user && dcclist[i].con && (dcclist[i].con->status == 1) && (for_guest || dcclist[i].adm)) {
   sockwrite(dcclist[i].con, line);
   ret++;
  }
 }
 return ret;
}


parseDCC

decompiled_code:
void __fastcall parseDCC(int a1, const char *a2)
{
int v2; // ebx
__int64 v4; // rsi
const char *v5; // rdx
__int64 v6; // rdi
const char *v7; // rbp
const char *v8; // rbp
__int64 v9; // rdi
char v10[66]; // [rsp+0h] [rbp-DA8h] BYREF
char v11[810]; // [rsp+42h] [rbp-D66h] BYREF
int v12; // [rsp+36Ch] [rbp-A3Ch] BYREF
__int64 v13[256]; // [rsp+370h] [rbp-A38h] BYREF
char v14[568]; // [rsp+B70h] [rbp-238h] BYREF

v2 = a1 - 1000;
if ( dccpos > a1 - 1000 && *a2 )
{
v4 = dcclist[5 * v2 + 1];
if ( v4 )
mystrncpy(v10, v4, 33LL);
else
v10[0] = 0;
mystrncpy(v11, dcclist[5 * v2 + 2], 256LL);
v10[33] = 0;
v11[256] = 0;
mystrncpy(v14, a2, 513LL);
memset(v13, 0, sizeof(v13));
v12 = tokenize(v14, " ", &v13[3], 253LL) + 3;
if ( *a2 == 46 )
{
if ( dcclist[5 * v2 + 4] || !strcmp((const char *)v13[3], ".login") || !strcmp((const char *)v13[3], ".who") )
admin_msg(v10, a2 + 1, v13, &v12, dcclist[5 * v2 + 3]);
else
sockwrite(dcclist[5 * v2 + 3]);
}
else
{
v5 = (const char *)dcclist[5 * v2 + 1];
if ( v5 )
{
if ( !memcmp((const void *)v13[3], &unk_4576, 8uLL) )
{
a2[strlen(a2) - 1] = 0;
v6 = dcclist[5 * v2 + 4];
if ( v6 )
{
v7 = a2 + 8;
send_partylineaction(v6, v7);
sprintf(dccbuf, "* %s %s", (const char *)dcclist[5 * v2 + 4], v7);
}
else
{
sprintf(dccbuf, "%s(guest)", (const char *)dcclist[5 * v2 + 1]);
v8 = a2 + 8;
send_partylineaction(dccbuf, v8);
sprintf(dccbuf, "* %s(guest) %s", (const char *)dcclist[5 * v2 + 1], v8);
}
}
else
{
v9 = dcclist[5 * v2 + 4];
if ( v9 )
{
send_partylinemsg(v9, a2);
sprintf(dccbuf, "<%s> %s", (const char *)dcclist[5 * v2 + 4], a2);
}
else
{
sprintf(dccbuf, "%s(guest)", v5);
send_partylinemsg(dccbuf, a2);
sprintf(dccbuf, "<%s(guest)> %s", (const char *)dcclist[5 * v2 + 1], a2);
}
}
send_to_dcc_butone(v2);
}
}
}
}

canonical_decompiled_code:
void __fastcall func11(int a1, const char *a2)
{
int v2; // ebx
__int64 v4; // rsi
const char *v5; // rdx
__int64 v6; // rdi
const char *v7; // rbp
const char *v8; // rbp
__int64 v9; // rdi
char v10[66]; // [rsp+0h] [rbp-DA8h] BYREF
char v11[810]; // [rsp+42h] [rbp-D66h] BYREF
int v12; // [rsp+36Ch] [rbp-A3Ch] BYREF
__int64 v13[256]; // [rsp+370h] [rbp-A38h] BYREF
char v14[568]; // [rsp+B70h] [rbp-238h] BYREF

v2 = a1 - 1000;
if ( dccpos > a1 - 1000 && *a2 )
{
v4 = dcclist[5 * v2 + 1];
if ( v4 )
mystrncpy(v10, v4, 33LL);
else
v10[0] = 0;
mystrncpy(v11, dcclist[5 * v2 + 2], 256LL);
v10[33] = 0;
v11[256] = 0;
mystrncpy(v14, a2, 513LL);
memset(v13, 0, sizeof(v13));
v12 = tokenize(v14, " ", &v13[3], 253LL) + 3;
if ( *a2 == 46 )
{
if ( dcclist[5 * v2 + 4] || !strcmp((const char *)v13[3], ".login") || !strcmp((const char *)v13[3], ".who") )
admin_msg(v10, a2 + 1, v13, &v12, dcclist[5 * v2 + 3]);
else
sockwrite(dcclist[5 * v2 + 3]);
}
else
{
v5 = (const char *)dcclist[5 * v2 + 1];
if ( v5 )
{
if ( !memcmp((const void *)v13[3], &unk_4576, 8uLL) )
{
a2[strlen(a2) - 1] = 0;
v6 = dcclist[5 * v2 + 4];
if ( v6 )
{
v7 = a2 + 8;
send_partylineaction(v6, v7);
sprintf(dccbuf, "* %s %s", (const char *)dcclist[5 * v2 + 4], v7);
}
else
{
sprintf(dccbuf, "%s(guest)", (const char *)dcclist[5 * v2 + 1]);
v8 = a2 + 8;
send_partylineaction(dccbuf, v8);
sprintf(dccbuf, "* %s(guest) %s", (const char *)dcclist[5 * v2 + 1], v8);
}
}
else
{
v9 = dcclist[5 * v2 + 4];
if ( v9 )
{
send_partylinemsg(v9, a2);
sprintf(dccbuf, "<%s> %s", (const char *)dcclist[5 * v2 + 4], a2);
}
else
{
sprintf(dccbuf, "%s(guest)", v5);
send_partylinemsg(dccbuf, a2);
sprintf(dccbuf, "<%s(guest)> %s", (const char *)dcclist[5 * v2 + 1], a2);
}
}
func8(v2);
}
}
}
}

original_code:
void parseDCC(int id, char *line)
{
 char tokenline[513];
 char *tokens[256];
 int numtok;
 sUser theUser;
 id -= 1000;
 if(id >= dccpos)
  return;
 if(!*line)
  return;
 if(dcclist[id].user)
  mystrncpy(theUser.nick, dcclist[id].user, 33);
 else
  strcpy(theUser.nick, "");
 mystrncpy(theUser.host, dcclist[id].host, 256);
 theUser.ident[0] = 0;
 theUser.mask[0] = 0;
 mystrncpy(tokenline, line, 513);
 memset(tokens, 0, sizeof(tokens) );
 numtok = tokenize(tokenline, " ", &tokens[3], 256 -3) + 3;
 if(*line == '.') {
  if(dcclist[id].adm || !strcmp(tokens[3], ".login") || !strcmp(tokens[3], ".who"))
   admin_msg(&theUser, line + 1, tokens, &numtok, dcclist[id].con, dcclist[id].adm);
  else
   sockwrite(dcclist[id].con, "You are a guest, you may not execute commands here.");
 } else if(dcclist[id].user) {
  if(!strcmp(tokens[3], "\001ACTION")) {
   line[strlen(line)-1] = 0;
   if(dcclist[id].adm) {
    send_partylineaction(dcclist[id].adm->nick, line + 8);
    sprintf(dccbuf, "* %s %s", dcclist[id].adm->nick, line + 8);
   } else {
    sprintf(dccbuf, "%s(guest)", dcclist[id].user);
    send_partylineaction(dccbuf, line + 8);
    sprintf(dccbuf, "* %s(guest) %s", dcclist[id].user, line + 8);
   }
  } else {
   if(dcclist[id].adm) {
    send_partylinemsg(dcclist[id].adm->nick, line);
    sprintf(dccbuf, "<%s> %s", dcclist[id].adm->nick, line);
   } else {
    sprintf(dccbuf, "%s(guest)", dcclist[id].user);
    send_partylinemsg(dccbuf, line);
    sprintf(dccbuf, "<%s(guest)> %s", dcclist[id].user, line);
   }
  }
  send_to_dcc_butone(id, dccbuf);
 }
}

canonical_original_code:
void parseDCC(int id, char *line)
{
 char tokenline[513];
 char *tokens[256];
 int numtok;
 struct ircUser theUser;
 id -= 1000;
 if(id >= dccpos)
  return;
 if(!*line)
  return;
 if(dcclist[id].user)
  mystrncpy(theUser.nick, dcclist[id].user, 33);
 else
  strcpy(theUser.nick, "");
 mystrncpy(theUser.host, dcclist[id].host, 256);
 theUser.ident[0] = 0;
 theUser.mask[0] = 0;
 mystrncpy(tokenline, line, 513);
 memset(tokens, 0, sizeof(tokens) );
 numtok = tokenize(tokenline, " ", &tokens[3], 256 -3) + 3;
 if(*line == '.') {
  if(dcclist[id].adm || !strcmp(tokens[3], ".login") || !strcmp(tokens[3], ".who"))
   admin_msg(&theUser, line + 1, tokens, &numtok, dcclist[id].con, dcclist[id].adm);
  else
   sockwrite(dcclist[id].con, "You are a guest, you may not execute commands here.");
 } else if(dcclist[id].user) {
  if(!strcmp(tokens[3], "\001ACTION")) {
   line[strlen(line)-1] = 0;
   if(dcclist[id].adm) {
    send_partylineaction(dcclist[id].adm->nick, line + 8);
    sprintf(dccbuf, "* %s %s", dcclist[id].adm->nick, line + 8);
   } else {
    sprintf(dccbuf, "%s(guest)", dcclist[id].user);
    send_partylineaction(dccbuf, line + 8);
    sprintf(dccbuf, "* %s(guest) %s", dcclist[id].user, line + 8);
   }
  } else {
   if(dcclist[id].adm) {
    send_partylinemsg(dcclist[id].adm->nick, line);
    sprintf(dccbuf, "<%s> %s", dcclist[id].adm->nick, line);
   } else {
    sprintf(dccbuf, "%s(guest)", dcclist[id].user);
    send_partylinemsg(dccbuf, line);
    sprintf(dccbuf, "<%s(guest)> %s", dcclist[id].user, line);
   }
  }
  send_to_dcc_butone(id, dccbuf);
 }
}

user_defined_types: struct ircUser { char nick[33]; char ident[33]; char host[256]; char mask[512]; char gnuUser[32]; }


decompiled_code:
void setup_queue()
{
dword_1B44 = 0;
dword_1B40 = 0;
bper = 0;
bytets = 0;
}

canonical_decompiled_code:
void func0()
{
dword_1B44 = 0;
dword_1B40 = 0;
bper = 0;
bytets = 0;
}

original_code:
void setup_queue()
{
 sendQ.highSize = sendQ.lowSize = 0;
 bytets = bper = 0;
 return;
}


decompiled_code:
void reset_queue()
{
__int64 v0; // rbx
__int64 v1; // rbx

if ( dword_1B40 > 0 )
{
v0 = 0LL;
do
free((&sendQ)[2 * v0++]);
while ( *((_DWORD *)&sendQ + 1536) > (int)v0 );
}
if ( dword_1B44 > 0 )
{
v1 = 0LL;
do
free((&dest)[2 * v1++]);
while ( *((_DWORD *)&sendQ + 1537) > (int)v1 );
}
setup_queue();
}

original_code:
void reset_queue()
{
 int i;
 for(i = 0; i < sendQ.highSize; i++)
  free(sendQ.high[i].message);
 for(i = 0; i < sendQ.lowSize; i++)
  free(sendQ.low[i].message);
 setup_queue();
}


highMsg

decompiled_code:
__int64 __fastcall highMsg(void *src)
{
int v1; // ebp
int v2; // ebx
unsigned __int64 v3; // rbp
size_t v4; // rbx
char *v5; // rax
__int64 result; // rax

v1 = dword_1B40++;
if ( v1 > 127 )
{
dword_1B40 = v1;
result = fwrite("Max sendQ exceeded (high).\n", 1uLL, 0x1BuLL, out);
}
else
{
v2 = strlen((const char *)src);
v3 = 16LL * v1;
dword_348[v3 / 4] = time(0LL);
v4 = v2 + 1;
v5 = (char *)myalloc(v4);
(&sendQ)[v3 / 8] = v5;
result = (__int64)memcpy(v5, src, v4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(void *src)
{
int v1; // ebp
int v2; // ebx
unsigned __int64 v3; // rbp
size_t v4; // rbx
char *v5; // rax
__int64 result; // rax

v1 = dword_1B40++;
if ( v1 > 127 )
{
dword_1B40 = v1;
result = fwrite("Max sendQ exceeded (high).\n", 1uLL, 0x1BuLL, out);
}
else
{
v2 = strlen((const char *)src);
v3 = 16LL * v1;
dword_348[v3 / 4] = time(0LL);
v4 = v2 + 1;
v5 = (char *)myalloc(v4);
(&sendQ)[v3 / 8] = v5;
result = (__int64)memcpy(v5, src, v4);
}
return result;
}

original_code:
void highMsg(char *message)
{
 int size;
 int pos = sendQ.highSize++;
 if(pos >= 128)
 {
  sendQ.highSize--;
  fprintf(out, "Max sendQ exceeded (high).\n");
  return;
 }
 size = strlen(message) + 1;
 sendQ.high[pos].ts = (int)time(0);
 sendQ.high[pos].message = myalloc(size * sizeof(char));
 memcpy(sendQ.high[pos].message, message, size);
 return;
}

variable_types: size int

variable_types: pos int


lowMsg

decompiled_code:
__int64 __fastcall lowMsg(void *src)
{
int v1; // ebx
int v2; // ebp
unsigned __int64 v3; // rbx
size_t v4; // rbp
char *v5; // rax
__int64 result; // rax

v1 = dword_1B44++;
if ( v1 > 255 )
{
dword_1B44 = v1;
result = fwrite("Max sendQ exceeded (low).\n", 1uLL, 0x1AuLL, out);
}
else
{
v2 = strlen((const char *)src);
v3 = 16 * (v1 + 128LL);
dword_348[v3 / 4] = time(0LL);
v4 = v2 + 1;
v5 = (char *)myalloc(v4);
(&sendQ)[v3 / 8] = v5;
result = (__int64)memcpy(v5, src, v4);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(void *src)
{
int v1; // ebx
int v2; // ebp
unsigned __int64 v3; // rbx
size_t v4; // rbp
char *v5; // rax
__int64 result; // rax

v1 = dword_1B44++;
if ( v1 > 255 )
{
dword_1B44 = v1;
result = fwrite("Max sendQ exceeded (low).\n", 1uLL, 0x1AuLL, out);
}
else
{
v2 = strlen((const char *)src);
v3 = 16 * (v1 + 128LL);
dword_348[v3 / 4] = time(0LL);
v4 = v2 + 1;
v5 = (char *)myalloc(v4);
(&sendQ)[v3 / 8] = v5;
result = (__int64)memcpy(v5, src, v4);
}
return result;
}

original_code:
void lowMsg(char *message)
{
 int size;
 int pos = sendQ.lowSize++;
 if(pos >= 256)
 {
  sendQ.lowSize--;
  fprintf(out, "Max sendQ exceeded (low).\n");
  return;
 }
 size = strlen(message) + 1;
 sendQ.low[pos].ts = (int)time(0);
 sendQ.low[pos].message = myalloc(size * sizeof(char));
 memcpy(sendQ.low[pos].message, message, size);
 return;
}


popMsg

decompiled_code:
time_t popMsg()
{
time_t v0; // rbx
time_t result; // rax
time_t v2; // rbx
char *v3; // rbx
time_t v4; // rbx
char *v5; // rbx

v0 = bytets;
result = time(0LL) - 1;
if ( v0 < result )
{
bytets = time(0LL);
result = bper;
if ( bper > 74 )
{
result = (unsigned int)(bper - 75);
bper -= 75;
}
}
if ( bper <= 1000 )
{
if ( dword_1B40 )
{
v4 = lastMsg;
result = time(0LL) - 1;
if ( v4 < result || bper <= 599 )
{
v5 = sendQ;
bper += strlen(sendQ);
irc_write(v5);
free(sendQ);
result = (time_t)memcpy(&sendQ, &unk_350, 16LL * --dword_1B40);
}
}
else if ( dword_1B44 > 0 )
{
v2 = lastMsg;
result = time(0LL) - 2;
if ( v2 < result )
{
v3 = dest;
bper += strlen(dest);
irc_write(v3);
free(dest);
result = (time_t)memcpy(&dest, &unk_B50, 16LL * --dword_1B44);
}
}
}
return result;
}

canonical_decompiled_code:
time_t func4()
{
time_t v0; // rbx
time_t result; // rax
time_t v2; // rbx
char *v3; // rbx
time_t v4; // rbx
char *v5; // rbx

v0 = bytets;
result = time(0LL) - 1;
if ( v0 < result )
{
bytets = time(0LL);
result = bper;
if ( bper > 74 )
{
result = (unsigned int)(bper - 75);
bper -= 75;
}
}
if ( bper <= 1000 )
{
if ( dword_1B40 )
{
v4 = lastMsg;
result = time(0LL) - 1;
if ( v4 < result || bper <= 599 )
{
v5 = sendQ;
bper += strlen(sendQ);
irc_write(v5);
free(sendQ);
result = (time_t)memcpy(&sendQ, &unk_350, 16LL * --dword_1B40);
}
}
else if ( dword_1B44 > 0 )
{
v2 = lastMsg;
result = time(0LL) - 2;
if ( v2 < result )
{
v3 = dest;
bper += strlen(dest);
irc_write(v3);
free(dest);
result = (time_t)memcpy(&dest, &unk_B50, 16LL * --dword_1B44);
}
}
}
return result;
}

original_code:
void popMsg()
{
 if(bytets < time(((void *)0)) - 1)
 {
  bytets = time(((void *)0));
  if(bper >= 75)
   bper -= 75;
 }
 if(bper > 1000)
  return;
 if(sendQ.highSize == 0)
 {
  if((sendQ.lowSize > 0) && (lastMsg < time(0) - 2))
  {
   bper += strlen(sendQ.low[0].message);
   irc_write(sendQ.low[0].message);
   free(sendQ.low[0].message);
   memcpy(sendQ.low, &sendQ.low[1], --sendQ.lowSize * sizeof(struct nodeQ) );
  }
 } else if( (lastMsg < time(0) - 1) || (bper < 600) ) {
  bper += strlen(sendQ.high[0].message);
  irc_write(sendQ.high[0].message);
  free(sendQ.high[0].message);
  memcpy(sendQ.high, &sendQ.high[1], --sendQ.highSize * sizeof(struct nodeQ) );
 }
 return;
}


quickMsg

decompiled_code:
__int64 __fastcall quickMsg(void *a1)
{
__int64 result; // rax

if ( bper <= 800 )
result = irc_write(a1);
else
result = highMsg(a1);
return result;
}

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

if ( bper <= 800 )
result = irc_write(a1);
else
result = func2(a1);
return result;
}

original_code:
void quickMsg(char *message)
{
 if(bper > 800)
  highMsg(message);
 else
  irc_write(message);
 return;
}


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

for ( result = admins[13]; result; result = *(_QWORD *)(result + 104) )
*(_BYTE *)(result + 67) = 0;
return result;
}

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

for ( result = admins[13]; result; result = *(_QWORD *)(result + 104) )
*(_BYTE *)(result + 67) = 0;
return result;
}

original_code:
void logout_all_admins()
{
 struct sadmin *i;
 i = admins.next;
 while(i)
 {
  i->actualNick[0] = 0;
  i = i->next;
 }
 return;
}


decompiled_code:
__int64 count_admins()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = admins[13];
if ( !v0 )
return 0;
v1 = 0;
do
{
++v1;
v0 = *(_QWORD *)(v0 + 104);
}
while ( v0 );
return v1;
}

canonical_decompiled_code:
__int64 func2()
{
__int64 v0; // rax
unsigned int v1; // edx

v0 = admins[13];
if ( !v0 )
return 0;
v1 = 0;
do
{
++v1;
v0 = *(_QWORD *)(v0 + 104);
}
while ( v0 );
return v1;
}

original_code:
int count_admins()
{
 struct sadmin *i;
 int count = 0;
 i = &admins;
 while(i->next)
 {
  count++;
  i = i->next;
 }
 return count;
}

variable_types: count int


findActualAdmin

decompiled_code:
__int64 __fastcall findActualAdmin(char *s2)
{
__int64 i; // rbx

for ( i = admins[13]; i; i = *(_QWORD *)(i + 104) )
{
if ( !strcmp((const char *)(i + 67), s2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s2)
{
__int64 i; // rbx

for ( i = admins[13]; i; i = *(_QWORD *)(i + 104) )
{
if ( !strcmp((const char *)(i + 67), s2) )
break;
}
return i;
}

original_code:
struct sadmin *findActualAdmin(char *name)
{
 struct sadmin *i;
 i = admins.next;
 while(i != ((void *)0))
 {
  if(!strcmp(i->actualNick, name))
   return i;
  i = i->next;
 }
 return ((void *)0);
}

variable_types:
name
char *

return_type: struct sadmin { char nick[33]; char pass[-1]; char actualNick[33]; int level; struct sadmin *next; struct sadmin *prev; } *


passCheck

decompiled_code:
_BOOL8 __fastcall passCheck(const char *a1, const char *a2)
{
char *v2; // rbp
size_t v3; // rax

v2 = crypt(a1, a2);
v3 = strlen(a2);
return strncmp(v2, a2, v3) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(const char *a1, const char *a2)
{
char *v2; // rbp
size_t v3; // rax

v2 = crypt(a1, a2);
v3 = strlen(a2);
return strncmp(v2, a2, v3) == 0;
}

original_code:
int passCheck(char *supplied, char *hash)
{
 char *hash2 = crypt(supplied, hash);
 return !strncmp(hash2, hash, strlen(hash));
}

variable_types:
supplied
char *

variable_types:
hash
char *


passCrypt

decompiled_code:
char *__fastcall passCrypt(char *key)
{
__int64 i; // rdx
char salt[12]; // [rsp+4h] [rbp-34h] BYREF
__int64 v4[5]; // [rsp+10h] [rbp-28h]

strcpy(salt, "$1$........");
v4[0] = time(0LL);
v4[1] = getpid() ^ ((unsigned __int64)v4[0] >> 14) & 0x30000;
for ( i = 0LL; i != 8; ++i )
salt[i + 3] = byte_6D0[((unsigned __int64)v4[(int)i / 5] >> (6 * (unsigned __int8)((int)i % 5))) & 0x3F];
return crypt(key, salt);
}

original_code:
char *passCrypt(char *in)
{
 unsigned long seed[2];
 char salt[] = "$1$........";
 const char *seedchars = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 int i;
 seed[0] = time(((void *)0));
 seed[1] = getpid() ^ (seed[0] >> 14 & 0x30000);
 for (i = 0; i < 8; i++)
  salt[3+i] = seedchars[(seed[i/5] >> (i%5)*6) & 0x3f];
 return crypt(in, salt);
}

canonical_original_code:
char *passCrypt(char *in)
{
 unsigned long seed[2];
 char salt[] = "$1$........";
 char *seedchars = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
 int i;
 seed[0] = time(((void *)0));
 seed[1] = getpid() ^ (seed[0] >> 14 & 0x30000);
 for (i = 0; i < 8; i++)
  salt[3+i] = seedchars[(seed[i/5] >> (i%5)*6) & 0x3f];
 return crypt(in, salt);
}

variable_types:
in
char *

variable_types:
seed
unsigned long [2]

variable_types:
salt
char []

variable_types:
seedchars
char *


findAdmin

decompiled_code:
__int64 __fastcall findAdmin(__int64 a1)
{
__int64 i; // rbx

for ( i = admins[13]; i; i = *(_QWORD *)(i + 104) )
{
if ( (unsigned int)strmi(a1, i) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
__int64 i; // rbx

for ( i = admins[13]; i; i = *(_QWORD *)(i + 104) )
{
if ( (unsigned int)strmi(a1, i) )
break;
}
return i;
}

original_code:
struct sadmin *findAdmin(char *nick)
{
 struct sadmin *i;
 i = admins.next;
 while(i != ((void *)0))
 {
  if(strmi(nick, i->nick))
   return i;
  i = i->next;
 }
 return ((void *)0);
}

variable_types:
nick
char *