decompiled_code:
ssize_t __fastcall mak_cmd(int a1, unsigned __int8 a2, char a3)
{
char v4[10]; // [rsp+Eh] [rbp-Ah] BYREF

v4[0] = a2;
v4[1] = a3;
printf("Attempting to send command: %c\n", a2);
return serial_write(a1, v4, 2uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func14(int a1, unsigned __int8 a2, char a3)
{
char v4[10]; // [rsp+Eh] [rbp-Ah] BYREF

v4[0] = a2;
v4[1] = a3;
printf("Attempting to send command: %c\n", a2);
return func10(a1, v4, 2uLL);
}

original_code:
int
mak_cmd(int fd, uint8_t c, uint8_t tracks)
{
 mak_generic_cmd_t cmd;
 cmd.mak_cmd = c;
 cmd.mak_track_mask = tracks;
 printf("Attempting to send command: %c\n", cmd.mak_cmd);
 return (serial_write(fd,&cmd, sizeof(cmd)));
}

canonical_original_code:
int mak_cmd(int fd, unsigned char c, unsigned char tracks)
{
 struct mak_cmd cmd;
 cmd.mak_cmd = c;
 cmd.mak_track_mask = tracks;
 printf("Attempting to send command: %c\n", cmd.mak_cmd);
 return (serial_write(fd,&cmd, sizeof(cmd)));
}

variable_types:
c
unsigned char

variable_types:
tracks
unsigned char

variable_types: struct mak_cmd { unsigned char mak_cmd; unsigned char mak_track_mask; }


repo: ioerror/libmsr

decompiled_code:
__int64 __fastcall mak_reset(int fd)
{
unsigned int v1; // eax
unsigned int v2; // er12
__int64 v4; // [rsp+0h] [rbp-18h] BYREF
int v5; // [rsp+8h] [rbp-10h]
__int16 v6; // [rsp+Ch] [rbp-Ch]
char v7; // [rsp+Eh] [rbp-Ah]
char v8; // [rsp+Fh] [rbp-9h]

v6 = 0;
v4 = 63LL;
v5 = 0;
v7 = 0;
printf("Sending reset command: %c\n", 63LL);
serial_write(fd, &v4, 4uLL);
printf("We expect: %s\n", "MSUSB CI.270209");
printf("We got ");
v1 = serial_read(fd, (__int64)&v4, 15LL);
v8 = 0;
v2 = v1;
printf("buf: %s\n", (const char *)&v4);
printf("Reset status: %d\n", v2);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func15(int fd)
{
unsigned int v1; // eax
unsigned int v2; // er12
__int64 v4; // [rsp+0h] [rbp-18h] BYREF
int v5; // [rsp+8h] [rbp-10h]
__int16 v6; // [rsp+Ch] [rbp-Ch]
char v7; // [rsp+Eh] [rbp-Ah]
char v8; // [rsp+Fh] [rbp-9h]

v6 = 0;
v4 = 63LL;
v5 = 0;
v7 = 0;
printf("Sending reset command: %c\n", 63LL);
func10(fd, &v4, 4uLL);
printf("We expect: %s\n", "MSUSB CI.270209");
printf("We got ");
v1 = func9(fd, (__int64)&v4, 15LL);
v8 = 0;
v2 = v1;
printf("buf: %s\n", (const char *)&v4);
printf("Reset status: %d\n", v2);
return v2;
}

original_code:
int mak_reset(int fd)
{
 int r;
 int i;
 char buf[strlen("MSUSB CI.270209") + 1];
 memset(buf, 0, strlen("MSUSB CI.270209"));
 buf[0] = '?';
 printf("Sending reset command: %c\n", '?');
 serial_write(fd, buf, sizeof('?'));
 printf("We expect: %s\n", "MSUSB CI.270209");
 printf("We got ");
 r = serial_read(fd, buf, strlen("MSUSB CI.270209"));
 buf[strlen("MSUSB CI.270209")] = '\0';
 printf("buf: %s\n", buf);
 printf("Reset status: %d\n", r);
 return r;
}

canonical_original_code:
int mak_reset(int fd)
{
 int r;
 int i;
 char buf[-1];
 memset(buf, 0, strlen("MSUSB CI.270209"));
 buf[0] = '?';
 printf("Sending reset command: %c\n", '?');
 serial_write(fd, buf, sizeof('?'));
 printf("We expect: %s\n", "MSUSB CI.270209");
 printf("We got ");
 r = serial_read(fd, buf, strlen("MSUSB CI.270209"));
 buf[strlen("MSUSB CI.270209")] = '\0';
 printf("buf: %s\n", buf);
 printf("Reset status: %d\n", r);
 return r;
}

variable_types: fd int

variable_types: r int

variable_types: i int

variable_types:
buf
char [-1]

return_type: int


decompiled_code:
__int64 __fastcall mak_read(int fd, char a2)
{
__int64 result; // rax
unsigned int v3; // ebx
__int64 v4; // r12
__int64 v5; // rsi
unsigned __int16 v6; // [rsp+6h] [rbp-22h] BYREF
char v7[2]; // [rsp+9h] [rbp-1Fh] BYREF
int s1; // [rsp+Bh] [rbp-1Dh] BYREF
char v9; // [rsp+Fh] [rbp-19h]

puts("Attempting to perform a read...");
mak_cmd(fd, 0x52u, a2);
puts("Command sent!");
serial_read(fd, (__int64)&s1, 5LL);
printf("We got: %s\n", (const char *)&s1);
printf("We expected: %s\n", "Ready ");
if ( !memcmp(&s1, "Ready ", 6uLL) )
{
puts("Doh!");
result = 0xFFFFFFFFLL;
}
else
{
puts("Please swipe a card for read...");
LOWORD(s1) = 0;
BYTE2(s1) = 0;
serial_read(fd, (__int64)&s1, 3LL);
printf("We expect: %s\n", "RD ");
printf("We expect it to be of len: %d\n", 3LL);
printf("We got: %s\n", (const char *)&s1);
if ( (_WORD)s1 == 17490 && BYTE2(s1) == 32 )
{
v3 = 0;
serial_read(fd, (__int64)&v6, 2LL);
printf("Sample count appears to be: %d\n", v6);
v4 = (unsigned __int16)_bswap_16(v6);
printf("Sample count appears to be: %d\n", v4);
if ( (_DWORD)v4 )
{
do
{
serial_read(fd, (__int64)v7, 2LL);
v5 = v3++;
printf("%d %02x %02x\n", v5, (unsigned __int8)v7[0], (unsigned __int8)v7[1]);
}
while ( (_DWORD)v4 != v3 );
}
puts("In theory, we have dumped the full sample data now...");
serial_read(fd, (__int64)&s1, 5LL);
printf("Sample read returned status: %s\n", (const char *)&s1);
if ( s1 == 1329415250 && v9 == 75 )
result = 0LL;
else
result = 0xFFFFFFFFLL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func17(int fd, char a2)
{
__int64 result; // rax
unsigned int v3; // ebx
__int64 v4; // r12
__int64 v5; // rsi
unsigned __int16 v6; // [rsp+6h] [rbp-22h] BYREF
char v7[2]; // [rsp+9h] [rbp-1Fh] BYREF
int s1; // [rsp+Bh] [rbp-1Dh] BYREF
char v9; // [rsp+Fh] [rbp-19h]

puts("Attempting to perform a read...");
func14(fd, 0x52u, a2);
puts("Command sent!");
func9(fd, (__int64)&s1, 5LL);
printf("We got: %s\n", (const char *)&s1);
printf("We expected: %s\n", "Ready ");
if ( !memcmp(&s1, "Ready ", 6uLL) )
{
puts("Doh!");
result = 0xFFFFFFFFLL;
}
else
{
puts("Please swipe a card for read...");
LOWORD(s1) = 0;
BYTE2(s1) = 0;
func9(fd, (__int64)&s1, 3LL);
printf("We expect: %s\n", "RD ");
printf("We expect it to be of len: %d\n", 3LL);
printf("We got: %s\n", (const char *)&s1);
if ( (_WORD)s1 == 17490 && BYTE2(s1) == 32 )
{
v3 = 0;
func9(fd, (__int64)&v6, 2LL);
printf("Sample count appears to be: %d\n", v6);
v4 = (unsigned __int16)func13(v6);
printf("Sample count appears to be: %d\n", v4);
if ( (_DWORD)v4 )
{
do
{
func9(fd, (__int64)v7, 2LL);
v5 = v3++;
printf("%d %02x %02x\n", v5, (unsigned __int8)v7[0], (unsigned __int8)v7[1]);
}
while ( (_DWORD)v4 != v3 );
}
puts("In theory, we have dumped the full sample data now...");
func9(fd, (__int64)&s1, 5LL);
printf("Sample read returned status: %s\n", (const char *)&s1);
if ( s1 == 1329415250 && v9 == 75 )
result = 0LL;
else
result = 0xFFFFFFFFLL;
}
else
{
result = 0xFFFFFFFFLL;
}
}
return result;
}

original_code:
int
mak_read(int fd, uint8_t tracks)
{
 int r;
 int i;
 char buf[5];
 unsigned char sample_tmp[2];
 uint16_t sample_count;
 int sample_count_guessing;
 printf("Attempting to perform a read...\n");
 r = mak_cmd(fd, 'R', tracks);
 printf("Command sent!\n");
 serial_read(fd, buf, strlen("Ready ") -1);
 printf("We got: %s\n", buf);
 printf("We expected: %s\n", "Ready ");
 if (!memcmp(buf, "Ready ", strlen("Ready "))) {
  printf("Doh!\n");
  return -1;
 }
 printf("Please swipe a card for read...\n");
 memset(buf, 0, 3);
 serial_read(fd, buf, 3);
 printf("We expect: %s\n", "RD ");
 printf("We expect it to be of len: %d\n", strlen("RD "));
 printf("We got: %s\n", buf);
 r = memcmp(buf, "RD ", strlen("RD "));
 if (r != 0) {
  return -1;
 }
 serial_read(fd, &sample_count, 2);
 printf("Sample count appears to be: %d\n", sample_count);
 sample_count_guessing = ntohs(sample_count);
 printf("Sample count appears to be: %d\n", sample_count_guessing);
 for (i = 0; i < sample_count_guessing ; i++) {
  serial_read(fd, sample_tmp, 2);
  printf("%d %02x %02x\n", i, sample_tmp[0], sample_tmp[1]);
 }
 printf("In theory, we have dumped the full sample data now...\n");
 serial_read(fd, buf, 5);
 printf("Sample read returned status: %s\n", buf);
 r = memcmp(buf, "RD=OK", 5);
 if (r != 0)
  return -1;
 return r;
}

canonical_original_code:
int mak_read(int fd, unsigned char tracks)
{
 int r;
 int i;
 char buf[5];
 unsigned char sample_tmp[2];
 unsigned short sample_count;
 int sample_count_guessing;
 printf("Attempting to perform a read...\n");
 r = mak_cmd(fd, 'R', tracks);
 printf("Command sent!\n");
 serial_read(fd, buf, strlen("Ready ") -1);
 printf("We got: %s\n", buf);
 printf("We expected: %s\n", "Ready ");
 if (!memcmp(buf, "Ready ", strlen("Ready "))) {
  printf("Doh!\n");
  return -1;
 }
 printf("Please swipe a card for read...\n");
 memset(buf, 0, 3);
 serial_read(fd, buf, 3);
 printf("We expect: %s\n", "RD ");
 printf("We expect it to be of len: %d\n", strlen("RD "));
 printf("We got: %s\n", buf);
 r = memcmp(buf, "RD ", strlen("RD "));
 if (r != 0) {
  return -1;
 }
 serial_read(fd, &sample_count, 2);
 printf("Sample count appears to be: %d\n", sample_count);
 sample_count_guessing = ntohs(sample_count);
 printf("Sample count appears to be: %d\n", sample_count_guessing);
 for (i = 0; i < sample_count_guessing ; i++) {
  serial_read(fd, sample_tmp, 2);
  printf("%d %02x %02x\n", i, sample_tmp[0], sample_tmp[1]);
 }
 printf("In theory, we have dumped the full sample data now...\n");
 serial_read(fd, buf, 5);
 printf("Sample read returned status: %s\n", buf);
 r = memcmp(buf, "RD=OK", 5);
 if (r != 0)
  return -1;
 return r;
}

variable_types:
buf
char [5]


decompiled_code:
__int64 __fastcall mak_successful_read(int fd, char a2)
{
__int64 result; // rax

do
{
mak_reset(fd);
result = mak_read(fd, a2);
}
while ( (_DWORD)result );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func18(int fd, char a2)
{
__int64 result; // rax

do
{
func15(fd);
result = func17(fd, a2);
}
while ( (_DWORD)result );
return result;
}

original_code:
int
mak_successful_read(int fd, uint8_t tracks)
{
 int r;
 do {
  mak_reset(fd);
  r = mak_read(fd, tracks);
 } while (r != 0);
 return r;
}

canonical_original_code:
int mak_successful_read(int fd, unsigned char tracks)
{
 int r;
 do {
  mak_reset(fd);
  r = mak_read(fd, tracks);
 } while (r != 0);
 return r;
}


decompiled_code:
__int64 __fastcall mak_clone(int fd)
{
unsigned int v1; // eax
__int64 result; // rax
unsigned int v3; // eax
unsigned int v4; // er12
int v5; // [rsp+Bh] [rbp-1Dh] BYREF
char v6; // [rsp+Fh] [rbp-19h]

LOWORD(v5) = 1859;
v1 = serial_write(fd, &v5, 2uLL);
printf("Serial write status: %i\n", v1);
serial_read(fd, (__int64)&v5, 3LL);
if ( (_WORD)v5 == 20547 && BYTE2(v5) == 32 )
{
puts("Ready to clone from Makstripe buffer to card.");
puts("Please swipe blank card");
v3 = serial_read(fd, (__int64)&v5, 5LL);
v4 = v3;
if ( v5 == 1329418307 && v6 == 75 )
{
printf("Clone succesfull: %i\n", v3);
result = v4;
}
else
{
printf("We expect a string of length: %i\n", 5LL);
printf("buf was unequal to MAKSTRIPE_CLONE_STS_OK: %s\n", "CP=OK");
printf(
"%c%c%c%c%c\n",
(unsigned int)(char)v5,
(unsigned int)SBYTE1(v5),
(unsigned int)SBYTE2(v5),
(unsigned int)SHIBYTE(v5),
(unsigned int)v6);
result = 0xFFFFFFFFLL;
}
}
else
{
printf("buf should be: %s\n", "CP ");
printf(
"%c%c%c%c%c\n",
(unsigned int)(char)v5,
(unsigned int)SBYTE1(v5),
(unsigned int)SBYTE2(v5),
(unsigned int)SHIBYTE(v5),
(unsigned int)v6);
puts("buf was unequal to MAKSTRIPE_CLONE_RESP.");
result = 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func19(int fd)
{
unsigned int v1; // eax
__int64 result; // rax
unsigned int v3; // eax
unsigned int v4; // er12
int v5; // [rsp+Bh] [rbp-1Dh] BYREF
char v6; // [rsp+Fh] [rbp-19h]

LOWORD(v5) = 1859;
v1 = func10(fd, &v5, 2uLL);
printf("Serial write status: %i\n", v1);
func9(fd, (__int64)&v5, 3LL);
if ( (_WORD)v5 == 20547 && BYTE2(v5) == 32 )
{
puts("Ready to clone from Makstripe buffer to card.");
puts("Please swipe blank card");
v3 = func9(fd, (__int64)&v5, 5LL);
v4 = v3;
if ( v5 == 1329418307 && v6 == 75 )
{
printf("Clone succesfull: %i\n", v3);
result = v4;
}
else
{
printf("We expect a string of length: %i\n", 5LL);
printf("buf was unequal to MAKSTRIPE_CLONE_STS_OK: %s\n", "CP=OK");
printf(
"%c%c%c%c%c\n",
(unsigned int)(char)v5,
(unsigned int)SBYTE1(v5),
(unsigned int)SBYTE2(v5),
(unsigned int)SHIBYTE(v5),
(unsigned int)v6);
result = 0xFFFFFFFFLL;
}
}
else
{
printf("buf should be: %s\n", "CP ");
printf(
"%c%c%c%c%c\n",
(unsigned int)(char)v5,
(unsigned int)SBYTE1(v5),
(unsigned int)SBYTE2(v5),
(unsigned int)SHIBYTE(v5),
(unsigned int)v6);
puts("buf was unequal to MAKSTRIPE_CLONE_RESP.");
result = 0xFFFFFFFFLL;
}
return result;
}

original_code:
int
mak_clone(int fd)
{
 int c;
 char buf[strlen("CP=OK")];
 buf[0] = 'C';
 buf[1] = 0x7;
 c = serial_write(fd, buf, 2);
 printf("Serial write status: %i\n", c);
 c = serial_read(fd, buf, strlen("CP "));
 if (memcmp(buf, "CP ", strlen("CP ")) != 0) {
  printf("buf should be: %s\n", "CP ");
  printf("%c%c%c%c%c\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
  printf("buf was unequal to MAKSTRIPE_CLONE_RESP.\n");
  return -1;
 }
 printf("Ready to clone from Makstripe buffer to card.\n");
 printf("Please swipe blank card\n");
 c = serial_read(fd, buf, strlen("CP=OK"));
 if (memcmp(buf, "CP=OK", strlen("CP=OK")) != 0) {
  printf("We expect a string of length: %i\n", strlen("CP=OK"));
  printf("buf was unequal to MAKSTRIPE_CLONE_STS_OK: %s\n", "CP=OK");
  printf("%c%c%c%c%c\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
  return -1;
 }
 printf("Clone succesfull: %i\n", c);
 return c;
}

canonical_original_code:
int mak_clone(int fd)
{
 int c;
 char buf[-1];
 buf[0] = 'C';
 buf[1] = 0x7;
 c = serial_write(fd, buf, 2);
 printf("Serial write status: %i\n", c);
 c = serial_read(fd, buf, strlen("CP "));
 if (memcmp(buf, "CP ", strlen("CP ")) != 0) {
  printf("buf should be: %s\n", "CP ");
  printf("%c%c%c%c%c\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
  printf("buf was unequal to MAKSTRIPE_CLONE_RESP.\n");
  return -1;
 }
 printf("Ready to clone from Makstripe buffer to card.\n");
 printf("Please swipe blank card\n");
 c = serial_read(fd, buf, strlen("CP=OK"));
 if (memcmp(buf, "CP=OK", strlen("CP=OK")) != 0) {
  printf("We expect a string of length: %i\n", strlen("CP=OK"));
  printf("buf was unequal to MAKSTRIPE_CLONE_STS_OK: %s\n", "CP=OK");
  printf("%c%c%c%c%c\n", buf[0], buf[1], buf[2], buf[3], buf[4]);
  return -1;
 }
 printf("Clone succesfull: %i\n", c);
 return c;
}

variable_types: c int


decompiled_code:
__int64 __fastcall mak_successful_clone(int fd)
{
__int64 result; // rax

do
result = mak_clone(fd);
while ( (_DWORD)result );
return result;
}

canonical_decompiled_code:
__int64 __fastcall func20(int fd)
{
__int64 result; // rax

do
result = func19(fd);
while ( (_DWORD)result );
return result;
}

original_code:
int
mak_successful_clone(int fd)
{
 int r;
 do {
  r = mak_clone(fd);
 } while (r != 0);
 return r;
}


decompiled_code:
__int64 __fastcall reverse_byte(unsigned int a1)
{
unsigned int v1; // eax

v1 = a1;
LOBYTE(v1) = (unsigned __int8)a1 >> 7;
return (32 * (_BYTE)a1) & 0x40 | (8 * (_BYTE)a1) & 0x20 | (2 * (_BYTE)a1) & 0x10 | ((int)(unsigned __int8)a1 >> 1) & 8 | ((int)(unsigned __int8)a1 >> 3) & 4 | ((int)(unsigned __int8)a1 >> 5) & 2 | ((unsigned __int8)a1 << 7) | v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1)
{
unsigned int v1; // eax

v1 = a1;
LOBYTE(v1) = (unsigned __int8)a1 >> 7;
return (32 * (_BYTE)a1) & 0x40 | (8 * (_BYTE)a1) & 0x20 | (2 * (_BYTE)a1) & 0x10 | ((int)(unsigned __int8)a1 >> 1) & 8 | ((int)(unsigned __int8)a1 >> 3) & 4 | ((int)(unsigned __int8)a1 >> 5) & 2 | ((unsigned __int8)a1 << 7) | v1;
}

variable_types:
byte
unsigned char

return_type: unsigned char


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
__off_t v4; // rbx
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( argc <= 1 )
{
printf("Usage: %s [file]\n", *argv);
exit(1);
}
v3 = open(argv[1], 0, envp);
v4 = lseek(v3, 0LL, 2);
while ( v4 > 0 )
{
v4 = lseek(v3, v4 - 1, 0);
read(v3, buf, 1uLL);
buf[0] = reverse_byte((unsigned __int8)buf[0], buf);
write(2, buf, 1uLL);
}
close(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
__off_t v4; // rbx
char buf[25]; // [rsp+Fh] [rbp-19h] BYREF

if ( argc <= 1 )
{
printf("Usage: %s [file]\n", *argv);
exit(1);
}
v3 = open(argv[1], 0, envp);
v4 = lseek(v3, 0LL, 2);
while ( v4 > 0 )
{
v4 = lseek(v3, v4 - 1, 0);
read(v3, buf, 1uLL);
buf[0] = func7((unsigned __int8)buf[0], buf);
write(2, buf, 1uLL);
}
close(v3);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int fd = -1;
 off_t filepos;
 unsigned char byte;
 if (argc < 2)
 {
  printf("Usage: %s [file]\n", argv[0]);
  exit(1);
 }
 fd = open(argv[1], 00);
 filepos = lseek(fd, 0, 2);
 while (filepos > 0)
 {
  filepos = lseek(fd, filepos - 1, 0);
  read(fd, &byte, 1);
  byte = reverse_byte(byte);
  write(2, &byte, 1);
 }
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int fd = -1;
 long filepos;
 unsigned char byte;
 if (argc < 2)
 {
  printf("Usage: %s [file]\n", argv[0]);
  exit(1);
 }
 fd = open(argv[1], 00);
 filepos = lseek(fd, 0, 2);
 while (filepos > 0)
 {
  filepos = lseek(fd, filepos - 1, 0);
  read(fd, &byte, 1);
  byte = reverse_byte(byte);
  write(2, &byte, 1);
 }
 close(fd);
 return 0;
}

variable_types: argc int

variable_types:
argv
char **

variable_types: filepos long


rshift

decompiled_code:
__int64 __fastcall rshift(__int16 a1, unsigned __int8 a2, char a3)
{
return (int)(unsigned __int16)(a2 | (unsigned __int16)(a1 << 8)) >> (8 - a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int16 a1, unsigned __int8 a2, char a3)
{
return (int)(unsigned __int16)(a2 | (unsigned __int16)(a1 << 8)) >> (8 - a3);
}

original_code:
unsigned char rshift(unsigned char a, unsigned char b, int shift)
{
    return (((unsigned short)(a<<8 | b) >> (8 - shift)) & 0x00ff);
}

variable_types:
a
unsigned char

variable_types:
b
unsigned char

variable_types: shift int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
ssize_t v4; // rbx
unsigned __int8 buf; // [rsp+9h] [rbp-1Fh] BYREF
unsigned __int8 v7; // [rsp+Ah] [rbp-1Eh] BYREF
char v8; // [rsp+Bh] [rbp-1Dh] BYREF
unsigned int v9; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc <= 2 )
{
printf("Usage: %s [file] [offset]\n", *argv);
exit(1);
}
sscanf(argv[2], "%d", &v9);
if ( v9 > 7 )
{
puts("Error: Offset must be between 0 and 7 (inclusive).");
exit(1);
}
printf("Offset: %d bits.\n", v9);
v3 = open(argv[1], 0);
read(v3, &buf, 1uLL);
do
{
v4 = read(v3, &v7, 1uLL);
v8 = rshift(buf, v7, v9);
write(2, &v8, 1uLL);
buf = v7;
}
while ( v4 );
close(v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
ssize_t v4; // rbx
unsigned __int8 buf; // [rsp+9h] [rbp-1Fh] BYREF
unsigned __int8 v7; // [rsp+Ah] [rbp-1Eh] BYREF
char v8; // [rsp+Bh] [rbp-1Dh] BYREF
unsigned int v9; // [rsp+Ch] [rbp-1Ch] BYREF

if ( argc <= 2 )
{
printf("Usage: %s [file] [offset]\n", *argv);
exit(1);
}
sscanf(argv[2], "%d", &v9);
if ( v9 > 7 )
{
puts("Error: Offset must be between 0 and 7 (inclusive).");
exit(1);
}
printf("Offset: %d bits.\n", v9);
v3 = open(argv[1], 0);
read(v3, &buf, 1uLL);
do
{
v4 = read(v3, &v7, 1uLL);
v8 = func7(buf, v7, v9);
write(2, &v8, 1uLL);
buf = v7;
}
while ( v4 );
close(v3);
return 0;
}

original_code:
int main(int argc, char **argv)
{
 int fd = -1;
 ssize_t bytes_read = 0;
 unsigned char a, b, byte;
 int offset;
 if (argc < 3)
 {
  printf("Usage: %s [file] [offset]\n", argv[0]);
  exit(1);
 }
 sscanf(argv[2], "%d", &offset);
 if (offset < 0 || offset > 7)
 {
  printf("Error: Offset must be between 0 and 7 (inclusive).\n");
  exit(1);
 }
 printf("Offset: %d bits.\n", offset);
 fd = open(argv[1], 00);
 read(fd, &a, 1);
 do
 {
  bytes_read = read(fd, &b, 1);
  byte = rshift(a, b, offset);
  write(2, &byte, 1);
  a = b;
 }
 while (bytes_read != 0);
 close(fd);
 return 0;
}

canonical_original_code:
int main(int argc, char **argv)
{
 int fd = -1;
 long bytes_read = 0;
 unsigned char a; unsigned char b; unsigned char byte;
 int offset;
 if (argc < 3)
 {
  printf("Usage: %s [file] [offset]\n", argv[0]);
  exit(1);
 }
 sscanf(argv[2], "%d", &offset);
 if (offset < 0 || offset > 7)
 {
  printf("Error: Offset must be between 0 and 7 (inclusive).\n");
  exit(1);
 }
 printf("Offset: %d bits.\n", offset);
 fd = open(argv[1], 00);
 read(fd, &a, 1);
 do
 {
  bytes_read = read(fd, &b, 1);
  byte = rshift(a, b, offset);
  write(2, &byte, 1);
  a = b;
 }
 while (bytes_read != 0);
 close(fd);
 return 0;
}

variable_types: offset int


decompiled_code:
__int64 __fastcall do_leet_led_dance(unsigned int a1, __int64 a2, __int64 a3, const char *a4)
{
int v4; // ebp
const char *v5; // rdx
const char *v6; // rdx
const char *v7; // rdx

v4 = 3;
do
{
msr_flash_led(a1, "k%d: [%s]\n", a3, a4);
msr_flash_led(a1, "d: [%s]\n", v5);
msr_flash_led(a1, ": [%s]\n", v6);
msr_flash_led(a1, " [%s]\n", v7);
usleep(0x186A0u);
--v4;
}
while ( v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2, __int64 a3, const char *a4)
{
int v4; // ebp
const char *v5; // rdx
const char *v6; // rdx
const char *v7; // rdx

v4 = 3;
do
{
msr_flash_led(a1, "k%d: [%s]\n", a3, a4);
msr_flash_led(a1, "d: [%s]\n", v5);
msr_flash_led(a1, ": [%s]\n", v6);
msr_flash_led(a1, " [%s]\n", v7);
usleep(0x186A0u);
--v4;
}
while ( v4 );
return 0LL;
}

original_code:
int
do_leet_led_dance (int fd)
{
 int z = 0;
 while (z < 3) {
 msr_flash_led(fd, 0x81);
 msr_flash_led(fd, 0x83);
 msr_flash_led(fd, 0x84);
 msr_flash_led(fd, 0x85);
 usleep (100000);
 z++;
 }
 return(0);
}

canonical_original_code:
int do_leet_led_dance(int fd)
{
 int z = 0;
 while (z < 3) {
 msr_flash_led(fd, 0x81);
 msr_flash_led(fd, 0x83);
 msr_flash_led(fd, 0x84);
 msr_flash_led(fd, 0x85);
 usleep (100000);
 z++;
 }
 return(0);
}

variable_types: z int


decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
char *v4; // rbp
unsigned int v5; // ebx
__int64 v6; // rdx
const char *v7; // rcx
unsigned int v8; // [rsp+Ch] [rbp-31Ch] BYREF
char s[792]; // [rsp+10h] [rbp-318h] BYREF

v3 = argv[1];
v8 = -1;
if ( !v3 )
{
v3 = "/dev/ttyS0";
printf("no device specified, defaulting to %s\n", "/dev/ttyS0");
}
if ( (unsigned int)serial_open(v3, &v8, 2048LL, 13LL) != -1 )
{
v4 = s;
v5 = 0;
msr_init(v8);
msr_model(v8);
msr_fwrev(v8);
msr_set_lo_co(v8);
msr_sensor_test(v8);
msr_ram_test(v8);
puts("Preparing reader for reading...");
do_leet_led_dance(v8, (__int64)&v8, v6, v7);
puts("Ready to read an ISO formatted card. Please slide a card.");
bzero(s, 0x300uLL);
s[255] = -1;
s[511] = -1;
s[767] = -1;
msr_iso_read(v8, s);
while ( 1 )
{
if ( v4[255] )
printf("track%d: [%s]\n", v5, v4);
++v5;
v4 += 256;
if ( v5 == 3 )
{
msr_init(v8);
puts("Attempting erase, please swipe card...");
msr_erase(v8, 7LL);
msr_init(v8);
puts("Attempting ISO write, please swipe card...");
msr_iso_write(v8, s);
puts("write complete");
msr_init(v8);
serial_close(v8);
exit(0);
}
}
}
err(1, "Serial open of %s failed", v3);
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
const char *v3; // r12
char *v4; // rbp
unsigned int v5; // ebx
__int64 v6; // rdx
const char *v7; // rcx
unsigned int v8; // [rsp+Ch] [rbp-31Ch] BYREF
char s[792]; // [rsp+10h] [rbp-318h] BYREF

v3 = argv[1];
v8 = -1;
if ( !v3 )
{
v3 = "/dev/ttyS0";
printf("no device specified, defaulting to %s\n", "/dev/ttyS0");
}
if ( (unsigned int)serial_open(v3, &v8, 2048LL, 13LL) != -1 )
{
v4 = s;
v5 = 0;
msr_init(v8);
msr_model(v8);
msr_fwrev(v8);
msr_set_lo_co(v8);
msr_sensor_test(v8);
msr_ram_test(v8);
puts("Preparing reader for reading...");
func0(v8, (__int64)&v8, v6, v7);
puts("Ready to read an ISO formatted card. Please slide a card.");
bzero(s, 0x300uLL);
s[255] = -1;
s[511] = -1;
s[767] = -1;
msr_iso_read(v8, s);
while ( 1 )
{
if ( v4[255] )
printf("track%d: [%s]\n", v5, v4);
++v5;
v4 += 256;
if ( v5 == 3 )
{
msr_init(v8);
puts("Attempting erase, please swipe card...");
msr_erase(v8, 7LL);
msr_init(v8);
puts("Attempting ISO write, please swipe card...");
msr_iso_write(v8, s);
puts("write complete");
msr_init(v8);
serial_close(v8);
exit(0);
}
}
}
err(1, "Serial open of %s failed", v3);
}

original_code:
int main(int argc, char * argv[])
{
 int fd = -1;
 int serial;
 msr_tracks_t tracks;
 int i;
 char *device = "/dev/ttyS0";
 if (argv[1] != ((void *)0))
  device = argv[1];
 else
  printf ("no device specified, defaulting to %s\n", device);
 serial = serial_open (device, &fd, 04000, 0000015);
 if (serial == -1) {
  err(1, "Serial open of %s failed", device);
  exit(1);
 }
 msr_init (fd);
 msr_model (fd);
 msr_fwrev (fd);
 msr_set_lo_co (fd);
 msr_sensor_test (fd);
 msr_ram_test (fd);
 printf("Preparing reader for reading...\n");
 do_leet_led_dance (fd);
 printf("Ready to read an ISO formatted card. Please slide a card.\n");
 bzero ((char *)&tracks, sizeof(tracks));
 for (i = 0; i < 3; i++)
  tracks.msr_tracks[i].msr_tk_len = 255;
 msr_iso_read (fd, &tracks);
 for (i = 0; i < 3; i++) {
  if (tracks.msr_tracks[i].msr_tk_len)
   printf ("track%d: [%s]\n", i,
    tracks.msr_tracks[i].msr_tk_data);
 }
 msr_init (fd);
 printf ("Attempting erase, please swipe card...\n");
 msr_erase (fd, 0x07);
 msr_init (fd);
 printf ("Attempting ISO write, please swipe card...\n");
 msr_iso_write (fd, &tracks);
 printf ("write complete\n");
 msr_init (fd);
 serial_close (fd);
 exit(0);
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fd = -1;
 int serial;
 struct msr_tracks tracks;
 int i;
 char *device = "/dev/ttyS0";
 if (argv[1] != ((void *)0))
  device = argv[1];
 else
  printf ("no device specified, defaulting to %s\n", device);
 serial = serial_open (device, &fd, 04000, 0000015);
 if (serial == -1) {
  err(1, "Serial open of %s failed", device);
  exit(1);
 }
 msr_init (fd);
 msr_model (fd);
 msr_fwrev (fd);
 msr_set_lo_co (fd);
 msr_sensor_test (fd);
 msr_ram_test (fd);
 printf("Preparing reader for reading...\n");
 do_leet_led_dance (fd);
 printf("Ready to read an ISO formatted card. Please slide a card.\n");
 bzero ((char *)&tracks, sizeof(tracks));
 for (i = 0; i < 3; i++)
  tracks.msr_tracks[i].msr_tk_len = 255;
 msr_iso_read (fd, &tracks);
 for (i = 0; i < 3; i++) {
  if (tracks.msr_tracks[i].msr_tk_len)
   printf ("track%d: [%s]\n", i,
    tracks.msr_tracks[i].msr_tk_data);
 }
 msr_init (fd);
 printf ("Attempting erase, please swipe card...\n");
 msr_erase (fd, 0x07);
 msr_init (fd);
 printf ("Attempting ISO write, please swipe card...\n");
 msr_iso_write (fd, &tracks);
 printf ("write complete\n");
 msr_init (fd);
 serial_close (fd);
 exit(0);
}

variable_types:
argv
char *[]

variable_types: serial int

variable_types: struct msr_tracks { struct msr_track { unsigned char msr_tk_data[255]; unsigned char msr_tk_len; } msr_tracks[3]; }

variable_types:
device
char *

user_defined_types: struct msr_tracks { struct msr_track msr_tracks[3]; }


repo: iomz/DARSH

decompiled_code:
__int64 __fastcall permute_str(const char *a1, const char *a2, const char *a3)
{
int v5; // eax
size_t v6; // rbx
int i; // er14
const char *v8; // rsi
int v10; // [rsp+0h] [rbp-148h]
int v11; // [rsp+4h] [rbp-144h]
char dest[312]; // [rsp+10h] [rbp-138h] BYREF

dest[0] = (unsigned __int8)&unk_5E1;
v10 = strlen(a1);
v5 = strlen(a2);
v6 = v5;
v11 = v5 - 1;
if ( v10 >= 0 )
{
for ( i = 0; i <= v10; ++i )
{
while ( !strncmp(&a1[i], a2, v6) )
{
strcat(dest, a3);
i += v11 + 1;
if ( v10 < i )
return 0LL;
}
v8 = &a1[i];
strncat(dest, v8, 1uLL);
}
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1, const char *a2, const char *a3)
{
int v5; // eax
size_t v6; // rbx
int i; // er14
const char *v8; // rsi
int v10; // [rsp+0h] [rbp-148h]
int v11; // [rsp+4h] [rbp-144h]
char dest[312]; // [rsp+10h] [rbp-138h] BYREF

dest[0] = (unsigned __int8)&unk_5E1;
v10 = strlen(a1);
v5 = strlen(a2);
v6 = v5;
v11 = v5 - 1;
if ( v10 >= 0 )
{
for ( i = 0; i <= v10; ++i )
{
while ( !strncmp(&a1[i], a2, v6) )
{
strcat(dest, a3);
i += v11 + 1;
if ( v10 < i )
return 0LL;
}
v8 = &a1[i];
strncat(dest, v8, 1uLL);
}
}
return 0LL;
}

original_code:
char *permute_str(const char *a, const char *b, const char *c)
{
 int i = 0, max_a, max_b;
 char result[256];
 result[0] = "\0";
 max_a = strlen(a);
 max_b = strlen(b);
 for (i = 0; i <= max_a; i++) {
  if (0 == strncmp(&a[i], b, max_b)) {
   strcat(result, c);
   i += max_b - 1;
  } else {
   strncat(result, &a[i], 1);
  }
 }
 return result;
}

canonical_original_code:
char *permute_str(char *a, char *b, char *c)
{
 int i = 0; int max_a; int max_b;
 char result[256];
 result[0] = "\0";
 max_a = strlen(a);
 max_b = strlen(b);
 for (i = 0; i <= max_a; i++) {
  if (0 == strncmp(&a[i], b, max_b)) {
   strcat(result, c);
   i += max_b - 1;
  } else {
   strncat(result, &a[i], 1);
  }
 }
 return result;
}

variable_types:
a
char *

variable_types:
b
char *

variable_types:
c
char *

variable_types: i int

variable_types:
result
char [256]

return_type: char *


decompiled_code:
__int64 __fastcall read_line(int fd, void *buf)
{
unsigned int v2; // er12
int v4; // eax
__int64 result; // rax

v2 = 0;
while ( 1 )
{
v4 = read(fd, buf, 1uLL);
if ( v4 == -1 )
{
perror("read");
return 0xFFFFFFFFLL;
}
if ( !v4 )
break;
++v2;
if ( *(_BYTE *)buf == 10 )
{
buf = (char *)buf + 1;
break;
}
if ( !*(_BYTE *)buf )
break;
buf = (char *)buf + 1;
}
result = v2;
*(_BYTE *)buf = 0;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(int fd, void *buf)
{
unsigned int v2; // er12
int v4; // eax
__int64 result; // rax

v2 = 0;
while ( 1 )
{
v4 = read(fd, buf, 1uLL);
if ( v4 == -1 )
{
perror("read");
return 0xFFFFFFFFLL;
}
if ( !v4 )
break;
++v2;
if ( *(_BYTE *)buf == 10 )
{
buf = (char *)buf + 1;
break;
}
if ( !*(_BYTE *)buf )
break;
buf = (char *)buf + 1;
}
result = v2;
*(_BYTE *)buf = 0;
return result;
}

original_code:
int read_line(int socket, char *p)
{
 int len = 0;
 while (1) {
  int ret;
  ret = read(socket, p, 1);
  if (ret == -1) {
   perror("read");
   return -1;
  } else if (ret == 0) {
   break;
  }
  if (*p == '\n') {
   p++;
   len++;
   break;
  }
  if (*p == '\0') {
   len++;
   break;
  }
  p++;
  len++;
 }
 *p = '\0';
 return len;
}

variable_types: socket int

variable_types:
p
char *

variable_types: len int

variable_types: ret int


decompiled_code:
char *get_host()
{
struct utsname *v0; // rbx

v0 = (struct utsname *)malloc(0x186uLL);
if ( uname(v0) < 0 )
fwrite("failed to uname()", 1uLL, 0x11uLL, stderr);
return v0->nodename;
}

canonical_decompiled_code:
char *func3()
{
struct utsname *v0; // rbx

v0 = (struct utsname *)malloc(0x186uLL);
if ( uname(v0) < 0 )
fwrite("failed to uname()", 1uLL, 0x11uLL, stderr);
return v0->nodename;
}

original_code:
char *get_host(void)
{
 struct utsname *uname_info;
 uname_info = (struct utsname *)malloc(sizeof(struct utsname));
 if (uname(uname_info) < 0) {
  fprintf(stderr, "failed to uname()");
 }
 return uname_info->nodename;
}

canonical_original_code:
char *get_host()
{
 struct utsname *uname_info;
 uname_info = (struct utsname *)malloc(sizeof(struct utsname));
 if (uname(uname_info) < 0) {
  fprintf(stderr, "failed to uname()");
 }
 return uname_info->nodename;
}

variable_types: struct utsname { char sysname[65]; char nodename[65]; char release[65]; char version[65]; char machine[65]; char __domainname[65]; } *


decompiled_code:
char *__fastcall get_ip(char *src)
{
int v1; // ebp
char v3[16]; // [rsp+0h] [rbp-48h] BYREF
__int16 v4; // [rsp+10h] [rbp-38h]
struct in_addr in; // [rsp+14h] [rbp-34h]

v1 = socket(2, 2, 0);
v4 = 2;
strncpy(v3, src, 0xFuLL);
ioctl(v1, 0x8915uLL, v3);
close(v1);
return inet_ntoa(in);
}

canonical_decompiled_code:
char *__fastcall func4(char *src)
{
int v1; // ebp
char v3[16]; // [rsp+0h] [rbp-48h] BYREF
__int16 v4; // [rsp+10h] [rbp-38h]
struct in_addr in; // [rsp+14h] [rbp-34h]

v1 = socket(2, 2, 0);
v4 = 2;
strncpy(v3, src, 0xFuLL);
ioctl(v1, 0x8915uLL, v3);
close(v1);
return inet_ntoa(in);
}

original_code:
char *get_ip(char *interface_name) {
 int fd;
 struct ifreq ifr;
 fd = socket(2, SOCK_DGRAM, 0);
 ifr.ifr_ifru.ifru_addr.sa_family = 2;
 strncpy(ifr.ifr_ifrn.ifrn_name, interface_name, 16 -1);
 ioctl(fd, 0x8915, &ifr);
 close(fd);
 return inet_ntoa(((struct sockaddr_in *)&ifr.ifr_ifru.ifru_addr)->sin_addr);
}

variable_types: fd int

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

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

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


decompiled_code:
__int64 __fastcall get_client_info(char *src, char *a2)
{
char *v2; // rbx
char *v3; // rax
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = stpcpy(v5, src);
v3 = get_ip(a2);
strcpy(v2 + 2, v3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *src, char *a2)
{
char *v2; // rbx
char *v3; // rax
char v5[280]; // [rsp+0h] [rbp-118h] BYREF

v2 = stpcpy(v5, src);
v3 = func4(a2);
strcpy(v2 + 2, v3);
return 0LL;
}

original_code:
char *get_client_info(char *host_id, char *interface_name)
{
 char client_info[256];
 strcpy(client_info, host_id);
 char *client_ip = get_ip(interface_name);
 strcat(client_info, ", ");
 strcat(client_info, client_ip);
 strcat(client_info, "\n");
 return client_info;
}


decompiled_code:
__int64 __fastcall get_client_info_FQDN(char *src)
{
char *v1; // rbx
char *v2; // rax
char *v3; // rax
char v5[256]; // [rsp+0h] [rbp-218h] BYREF
char dest[280]; // [rsp+100h] [rbp-118h] BYREF

v1 = stpcpy(v5, src);
v2 = get_host();
v3 = stpcpy(dest, v2);
strcpy(v1, ", ");
strncat(v5, dest, v3 - dest);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *src)
{
char *v1; // rbx
char *v2; // rax
char *v3; // rax
char v5[256]; // [rsp+0h] [rbp-218h] BYREF
char dest[280]; // [rsp+100h] [rbp-118h] BYREF

v1 = stpcpy(v5, src);
v2 = func3();
v3 = stpcpy(dest, v2);
strcpy(v1, ", ");
strncat(v5, dest, v3 - dest);
return 0LL;
}

original_code:
char *get_client_info_FQDN(char *host_id)
{
 char client_info[256];
 char host_name[256];
 strcpy(client_info, host_id);
 strcpy(host_name, get_host());
 strcat(client_info, ", ");
 strncat(client_info, host_name, strlen(host_name));
 strcat(client_info, "\n");
 return client_info;
}


server

decompiled_code:
__int64 __fastcall server(__int64 a1, const char *a2, unsigned int a3, __int64 a4, char *a5)
{
int v7; // ebp
__pid_t v8; // eax
const char *v9; // rax
size_t v10; // rax
__int64 result; // rax
struct sockaddr v12; // [rsp+0h] [rbp-138h] BYREF
char dest[296]; // [rsp+10h] [rbp-128h] BYREF

puts("******* Info Server *******");
v7 = socket(2, 1, 0);
if ( v7 < 0 )
perror("socket");
v12.sa_family = 2;
*(_WORD *)v12.sa_data = _bswap_16(5000);
inet_aton(a2, (struct in_addr *)&v12.sa_data[2]);
printf("try to connect to %s\n", a2);
if ( connect(v7, &v12, 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(dest, v9);
printf("send: %s\n", dest);
v10 = strlen(dest);
send(v7, dest, v10, 0);
sleep(a3);
}
}
sslserv((unsigned int)v7);
wait((__WAIT_STATUS)dest);
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; // ebp
__pid_t v8; // eax
const char *v9; // rax
size_t v10; // rax
__int64 result; // rax
struct sockaddr v12; // [rsp+0h] [rbp-138h] BYREF
char dest[296]; // [rsp+10h] [rbp-128h] BYREF

puts("******* Info Server *******");
v7 = socket(2, 1, 0);
if ( v7 < 0 )
perror("socket");
v12.sa_family = 2;
*(_WORD *)v12.sa_data = func0(5000);
inet_aton(a2, (struct in_addr *)&v12.sa_data[2]);
printf("try to connect to %s\n", a2);
if ( connect(v7, &v12, 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(dest, v9);
printf("send: %s\n", dest);
v10 = strlen(dest);
send(v7, dest, v10, 0);
sleep(a3);
}
}
sslserv((unsigned int)v7);
wait((__WAIT_STATUS)dest);
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

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:
buf
char [256]

variable_types:
get
char [256]

variable_types:
fqdn
char [256]


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

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

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

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

if ( argc <= 2 )
{
func11();
}
else
{
v3 = *argv[1];
if ( v3 == 115 )
{
if ( argc <= 4 )
func9();
else
func7((__int64)envp, argv[2], 3u, (__int64)argv[3], (char *)argv[4]);
}
else if ( v3 == 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:
opt
char *


decompiled_code:
__int64 THREAD_setup()
{
pthread_mutex_t *v0; // rax

v0 = (pthread_mutex_t *)malloc(0x28uLL);
mutex_buf = v0;
if ( !v0 )
return 0LL;
pthread_mutex_init(v0, 0LL);
return 1LL;
}

canonical_decompiled_code:
__int64 func0()
{
pthread_mutex_t *v0; // rax

v0 = (pthread_mutex_t *)malloc(0x28uLL);
mutex_buf = v0;
if ( !v0 )
return 0LL;
pthread_mutex_init(v0, 0LL);
return 1LL;
}

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; // rbp
__int64 result; // rax

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

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

v0 = mutex_buf;
result = 0LL;
if ( mutex_buf )
{
pthread_mutex_destroy(mutex_buf);
free(v0);
result = 1LL;
mutex_buf = 0LL;
}
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; // ebp
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; // ebp
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; // r12
char **v4; // rax
char *v5; // r12
char *v6; // rbp
char *v7; // rax
__pid_t v9; // eax
size_t v10; // rax
__WAIT_STATUS stat_loc; // [rsp+14h] [rbp-2AC4h] BYREF
int v12; // [rsp+1Ch] [rbp-2ABCh]
struct sigaction v13; // [rsp+20h] [rbp-2AB8h] BYREF
char s[512]; // [rsp+C0h] [rbp-2A18h] 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);
v13.sa_handler = (__sighandler_t)sighandler;
sigemptyset(&v13.sa_mask);
v13.sa_flags = 0x10000000;
if ( sigaction(2, &v13, 0LL) < 0 )
errorhandler("sigaction");
while ( 1 )
{
do
{
if ( pipe((int *)&stat_loc.__iptr + 1) )
errorhandler("pipe");
if ( _sigsetjmp(env, 1) )
wait((__WAIT_STATUS)&stat_loc);
memset(s, 0, sizeof(s));
v2 = strlen(dpath);
snprintf(s, v2 + 11, "darsh [%s]> ", dpath);
v3 = strlen(s);
if ( v3 != send(a1, s, 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, &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
{
v10 = strlen(dpath);
dpath[v10] = 47;
strcpy(&dpath[v10 + 1], v6);
}
}
}
}
else
{
v9 = fork();
if ( v9 < 0 )
{
perror("fork");
}
else if ( v9 )
{
memset(buf, 0, 0x2000uLL);
close(v12);
read(SHIDWORD(stat_loc.__iptr), buf, 0x2000uLL);
if ( (int)send(a1, buf, 0x2000uLL, 0) < 0 )
errorhandler("shell out");
wait((__WAIT_STATUS)&stat_loc);
close(SHIDWORD(stat_loc.__iptr));
}
else
{
close(SHIDWORD(stat_loc.__iptr));
dupcheck(v12, 1);
v13.sa_handler = 0LL;
if ( sigaction(2, &v13, 0LL) < 0 )
perror("sigaction");
if ( execvp(s1, &s1) < 0 )
errorhandler("execvp");
wait((__WAIT_STATUS)&stat_loc);
close(v12);
}
}
}
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; // r12
char **v4; // rax
char *v5; // r12
char *v6; // rbp
char *v7; // rax
__pid_t v9; // eax
size_t v10; // rax
__WAIT_STATUS stat_loc; // [rsp+14h] [rbp-2AC4h] BYREF
int v12; // [rsp+1Ch] [rbp-2ABCh]
struct sigaction v13; // [rsp+20h] [rbp-2AB8h] BYREF
char s[512]; // [rsp+C0h] [rbp-2A18h] 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);
v13.sa_handler = (__sighandler_t)sighandler;
sigemptyset(&v13.sa_mask);
v13.sa_flags = 0x10000000;
if ( sigaction(2, &v13, 0LL) < 0 )
func3("sigaction");
while ( 1 )
{
do
{
if ( pipe((int *)&stat_loc.__iptr + 1) )
func3("pipe");
if ( _sigsetjmp(env, 1) )
wait((__WAIT_STATUS)&stat_loc);
memset(s, 0, sizeof(s));
v2 = strlen(dpath);
snprintf(s, v2 + 11, "darsh [%s]> ", dpath);
v3 = strlen(s);
if ( v3 != send(a1, s, 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, &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
{
v10 = strlen(dpath);
dpath[v10] = 47;
strcpy(&dpath[v10 + 1], v6);
}
}
}
}
else
{
v9 = fork();
if ( v9 < 0 )
{
perror("fork");
}
else if ( v9 )
{
memset(buf, 0, 0x2000uLL);
close(v12);
read(SHIDWORD(stat_loc.__iptr), buf, 0x2000uLL);
if ( (int)send(a1, buf, 0x2000uLL, 0) < 0 )
func3("shell out");
wait((__WAIT_STATUS)&stat_loc);
close(SHIDWORD(stat_loc.__iptr));
}
else
{
close(SHIDWORD(stat_loc.__iptr));
func4(v12, 1);
v13.sa_handler = 0LL;
if ( sigaction(2, &v13, 0LL) < 0 )
perror("sigaction");
if ( execvp(s1, &s1) < 0 )
func3("execvp");
wait((__WAIT_STATUS)&stat_loc);
close(v12);
}
}
}
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)
{
int v1; // er8

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

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

v1 = 46;
if ( !a1 )
return fputc(v1, stderr);
v1 = 43;
if ( a1 == 1 )
return fputc(v1, stderr);
if ( a1 == 2 )
return fputc(42, stderr);
if ( a1 != 3 )
{
v1 = 66;
return fputc(v1, stderr);
}
return fputc(10, 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
unsigned int v2; // er8
__int64 v3; // rbx
__int64 v4; // rbx
int v5; // eax

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) )
{
while ( 1 )
{
if ( *(_QWORD *)(i + 176) )
{
v2 = time(0LL);
result = *(_QWORD *)(i + 176);
v3 = *(_QWORD *)(result + 632);
*(_QWORD *)(result + 648) = v2;
if ( v3 )
{
do
{
*(_DWORD *)(v3 + 80) = 0;
*(_DWORD *)(v3 + 76) = time(0LL);
*(_DWORD *)(v3 + 96) = time(0LL);
*(_DWORD *)(v3 + 92) = time(0LL);
v3 = *(_QWORD *)(v3 + 104);
}
while ( v3 );
result = *(_QWORD *)(i + 176);
}
v4 = *(_QWORD *)(result + 616);
if ( v4 )
break;
}
i = *(_QWORD *)(i + 192);
if ( !i )
return result;
}
do
{
v5 = time(0LL);
*(_DWORD *)(v4 + 60) = 1;
*(_DWORD *)(v4 + 56) = v5;
result = v4 + 64;
do
{
*(_DWORD *)result = 0;
result += 12LL;
}
while ( result != v4 + 424 );
v4 = *(_QWORD *)(v4 + 432);
}
while ( v4 );
}
return result;
}

canonical_decompiled_code:
time_t func2()
{
time_t result; // rax
__int64 i; // rbp
unsigned int v2; // er8
__int64 v3; // rbx
__int64 v4; // rbx
int v5; // eax

sRelay("(!) clock skew detected. resetting timers and protection mechanisms.");
timeSkewWait = time(0LL) + 10;
result = func1();
for ( i = chans[24]; i; i = *(_QWORD *)(i + 192) )
{
while ( 1 )
{
if ( *(_QWORD *)(i + 176) )
{
v2 = time(0LL);
result = *(_QWORD *)(i + 176);
v3 = *(_QWORD *)(result + 632);
*(_QWORD *)(result + 648) = v2;
if ( v3 )
{
do
{
*(_DWORD *)(v3 + 80) = 0;
*(_DWORD *)(v3 + 76) = time(0LL);
*(_DWORD *)(v3 + 96) = time(0LL);
*(_DWORD *)(v3 + 92) = time(0LL);
v3 = *(_QWORD *)(v3 + 104);
}
while ( v3 );
result = *(_QWORD *)(i + 176);
}
v4 = *(_QWORD *)(result + 616);
if ( v4 )
break;
}
i = *(_QWORD *)(i + 192);
if ( !i )
return result;
}
do
{
v5 = time(0LL);
*(_DWORD *)(v4 + 60) = 1;
*(_DWORD *)(v4 + 56) = v5;
result = v4 + 64;
do
{
*(_DWORD *)result = 0;
result += 12LL;
}
while ( result != v4 + 424 );
v4 = *(_QWORD *)(v4 + 432);
}
while ( v4 );
}
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; // rbp
__int64 v1; // rbx
__int64 v2; // rsi
__int64 result; // rax

for ( i = ial; i; i = *(_QWORD *)(i + 656) )
{
v1 = *(_QWORD *)(i + 616);
while ( v1 )
{
while ( 1 )
{
v2 = v1;
result = (unsigned int)(unsigned __int8)(*(_BYTE *)(v1 + 48))-- - 1;
v1 = *(_QWORD *)(v1 + 432);
if ( (char)result > 0 )
break;
result = nu_del(i, v2);
if ( !v1 )
goto LABEL_6;
}
}
LABEL_6:
;
}
return result;
}

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

for ( i = ial; i; i = *(_QWORD *)(i + 656) )
{
v1 = *(_QWORD *)(i + 616);
while ( v1 )
{
while ( 1 )
{
v2 = v1;
result = (unsigned int)(unsigned __int8)(*(_BYTE *)(v1 + 48))-- - 1;
v1 = *(_QWORD *)(v1 + 432);
if ( (char)result > 0 )
break;
result = nu_del(i, v2);
if ( !v1 )
goto LABEL_6;
}
}
LABEL_6:
;
}
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)
{
const char *v1; // rbp
char *v2; // rax
char v3; // bl
__int64 v4; // r12
__int64 v5; // r13
__int64 v6; // r13
int v7; // esi

v1 = (const char *)(a1 + 509);
LODWORD(v2) = sprintf(whobuf, "MODE %s ", *(const char **)a1);
v3 = *(_BYTE *)(a1 + 509);
v4 = *(_QWORD *)(a1 + 672);
if ( !v3 )
{
LABEL_11:
v7 = *(char *)(v4 + 107);
v6 = v4 + 107;
if ( *(_BYTE *)(v4 + 107) )
goto LABEL_8;
return (int)v2;
}
v5 = a1 + 509;
while ( 1 )
{
v2 = strchr((const char *)(v4 + 139), v3);
if ( v2 )
break;
v3 = *(_BYTE *)++v5;
if ( !v3 )
goto LABEL_11;
}
v3 = 1;
strcat(whobuf, (const char *)(v4 + 139));
v4 = *(_QWORD *)(a1 + 672);
v6 = v4 + 107;
if ( !*(_BYTE *)(v4 + 107) )
{
LABEL_10:
LODWORD(v2) = lowMsg(whobuf);
return (int)v2;
}
v2 = strchr(v1, *(char *)(v4 + 107));
if ( !v2 )
{
LABEL_9:
strcat(whobuf, (const char *)(v4 + 106));
goto LABEL_10;
}
while ( 1 )
{
v7 = *(char *)++v6;
if ( !(_BYTE)v7 )
break;
LABEL_8:
v2 = strchr(v1, v7);
if ( !v2 )
goto LABEL_9;
}
if ( v3 )
goto LABEL_10;
return (int)v2;
}

canonical_decompiled_code:
int __fastcall func4(__int64 a1)
{
const char *v1; // rbp
char *v2; // rax
char v3; // bl
__int64 v4; // r12
__int64 v5; // r13
__int64 v6; // r13
int v7; // esi

v1 = (const char *)(a1 + 509);
LODWORD(v2) = sprintf(whobuf, "MODE %s ", *(const char **)a1);
v3 = *(_BYTE *)(a1 + 509);
v4 = *(_QWORD *)(a1 + 672);
if ( !v3 )
{
LABEL_11:
v7 = *(char *)(v4 + 107);
v6 = v4 + 107;
if ( *(_BYTE *)(v4 + 107) )
goto LABEL_8;
return (int)v2;
}
v5 = a1 + 509;
while ( 1 )
{
v2 = strchr((const char *)(v4 + 139), v3);
if ( v2 )
break;
v3 = *(_BYTE *)++v5;
if ( !v3 )
goto LABEL_11;
}
v3 = 1;
strcat(whobuf, (const char *)(v4 + 139));
v4 = *(_QWORD *)(a1 + 672);
v6 = v4 + 107;
if ( !*(_BYTE *)(v4 + 107) )
{
LABEL_10:
LODWORD(v2) = lowMsg(whobuf);
return (int)v2;
}
v2 = strchr(v1, *(char *)(v4 + 107));
if ( !v2 )
{
LABEL_9:
strcat(whobuf, (const char *)(v4 + 106));
goto LABEL_10;
}
while ( 1 )
{
v7 = *(char *)++v6;
if ( !(_BYTE)v7 )
break;
LABEL_8:
v2 = strchr(v1, v7);
if ( !v2 )
goto LABEL_9;
}
if ( v3 )
goto LABEL_10;
return (int)v2;
}

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; // eax
const char *v3; // rdx
int v4; // ecx
int v5; // edx
int v6; // eax
const char *v7; // rdx
int v8; // ecx

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

canonical_decompiled_code:
time_t __fastcall func5(__int64 a1)
{
time_t result; // rax
int v2; // eax
const char *v3; // rdx
int v4; // ecx
int v5; // edx
int v6; // eax
const char *v7; // rdx
int v8; // ecx

result = check_dependants();
if ( !(_DWORD)result )
{
if ( *(_DWORD *)(a1 + 640) < *(_DWORD *)(a1 + 608) )
{
result = time(0LL) - *(int *)(a1 + 612);
if ( result > *((int *)&config + 257) )
{
v5 = *(_DWORD *)(a1 + 640);
if ( v5 > *(_DWORD *)(a1 + 608) - *((_DWORD *)&config + 259)
|| (result = (unsigned int)(*(_DWORD *)(a1 + 608) - *((_DWORD *)&config + 260)), v5 < (int)result) )
{
v6 = time(0LL);
v7 = *(const char **)a1;
v8 = *((_DWORD *)&config + 258);
*(_DWORD *)(a1 + 612) = v6;
sprintf(whobuf, "MODE %s +l %d", v7, (unsigned int)(*(_DWORD *)(a1 + 640) + v8));
result = highMsg(whobuf);
}
}
}
else
{
v2 = time(0LL);
v3 = *(const char **)a1;
v4 = *((_DWORD *)&config + 258);
*(_DWORD *)(a1 + 612) = v2;
sprintf(whobuf, "MODE %s +l %d", v3, (unsigned int)(*(_DWORD *)(a1 + 640) + v4));
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 )
goto LABEL_11;
}
else
{
v2 = *((unsigned int *)&config + 274);
if ( (int)v2 <= 0 )
goto LABEL_11;
}
if ( 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));
LABEL_11:
while ( v0 )
{
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);
}
v0 = (const char **)v0[24];
}
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 )
goto LABEL_11;
}
else
{
v2 = *((unsigned int *)&config + 274);
if ( (int)v2 <= 0 )
goto LABEL_11;
}
if ( 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));
LABEL_11:
while ( v0 )
{
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);
}
v0 = (const char **)v0[24];
}
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 result; // rax
time_t v2; // rbx
time_t v3; // rbx

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

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

v0 = timer1;
if ( v0 > time(0LL) )
{
func2();
v0 = timer1;
}
result = time(0LL) - 60;
if ( result > v0 )
{
timer1 = time(0LL);
expireBans();
if ( time(0LL) - timer5 > 1000 )
func2();
checkNeedCon();
v2 = timer5;
if ( v2 < time(0LL) - 300 )
{
timer5 = time(0LL);
func6();
}
v3 = timer60;
result = time(0LL) - 3600;
if ( v3 < 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 );
}
v2 = (void **)vhostlist;
wordlist = 0LL;
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 );
}
v2 = (void **)vhostlist;
wordlist = 0LL;
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; // rbx
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);
v4 = wordlist;
v1[1] = 0LL;
if ( v4 )
{
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; // rbx
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);
v4 = wordlist;
v1[1] = 0LL;
if ( v4 )
{
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; // rbx
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);
v4 = vhostlist;
v1[1] = 0LL;
if ( v4 )
{
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; // rbx
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);
v4 = vhostlist;
v1[1] = 0LL;
if ( v4 )
{
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()
{
__int64 v0; // rbx
time_t v2; // rdx
__int64 v3; // rcx
_QWORD *v4; // rax
_QWORD *v5; // rsi

v0 = vcount;
vhost_1 = 0;
if ( !vcount )
return &vhost_1;
v2 = (count_main_in + time(0LL) + bper) % v0;
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()
{
__int64 v0; // rbx
time_t v2; // rdx
__int64 v3; // rcx
_QWORD *v4; // rax
_QWORD *v5; // rsi

v0 = vcount;
vhost_1 = 0;
if ( !vcount )
return &vhost_1;
v2 = (count_main_in + time(0LL) + bper) % v0;
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


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

v1 = wcount;
strcpy((char *)&word_0, "none");
if ( !wcount )
return &word_0;
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)
{
__int64 v1; // rbp
time_t v3; // rdx
__int64 v4; // rcx
_QWORD *v5; // rax
_QWORD *v6; // rsi

v1 = wcount;
strcpy((char *)&word_0, "none");
if ( !wcount )
return &word_0;
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;
 }
}