bread

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

result = bavail_read(a1);
if ( (_DWORD)result )
{
result = read(a2, *(void **)(a1 + 16), (int)result);
if ( (int)result <= 0 )
result = 0xFFFFFFFFLL;
else
*(_QWORD *)(a1 + 16) += (int)result;
}
return result;
}

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

result = func1(a1);
if ( (_DWORD)result )
{
result = read(a2, *(void **)(a1 + 16), (int)result);
if ( (int)result <= 0 )
result = 0xFFFFFFFFLL;
else
*(_QWORD *)(a1 + 16) += (int)result;
}
return result;
}

original_code:
int bread(struct buffer *b, int fd)
{
 int size;
 int n;
 size = bavail_read(b);
 if (size == 0)
  return 0;
 n = read(fd, b->end, size);
 if (n < 1)
  return -1;
 b->end += n;
 return n;
}

variable_types: fd int

variable_types: size int

variable_types: n int


bwrite

repo: mykmo/tcpproxy

decompiled_code:
__int64 __fastcall bwrite(__int64 a1, int a2)
{
signed int v2; // eax
unsigned int v3; // ebx
int v5; // eax

v2 = bavail_write(a1);
v3 = v2;
if ( v2 )
{
v5 = write(a2, *(const void **)(a1 + 8), v2);
v3 = v5;
if ( v5 <= 0 )
{
v3 = -1;
}
else
{
*(_QWORD *)(a1 + 8) += v5;
bcheck_empty((__int64 *)a1);
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, int a2)
{
signed int v2; // eax
unsigned int v3; // ebx
int v5; // eax

v2 = func0(a1);
v3 = v2;
if ( v2 )
{
v5 = write(a2, *(const void **)(a1 + 8), v2);
v3 = v5;
if ( v5 <= 0 )
{
v3 = -1;
}
else
{
*(_QWORD *)(a1 + 8) += v5;
func2((__int64 *)a1);
}
}
return v3;
}

original_code:
int bwrite(struct buffer *b, int fd)
{
 int size;
 int n;
 size = bavail_write(b);
 if (size == 0)
  return 0;
 n = write(fd, b->begin, size);
 if (n < 1)
  return -1;
 b->begin += n;
 bcheck_empty(b);
 return n;
}

variable_types: struct buffer { char *addr; char *begin; char *end; int size; } *

return_type: int


bgets

decompiled_code:
__int64 __fastcall bgets(__int64 *a1, void *a2, size_t a3)
{
__int64 result; // rax
size_t v4; // rbx
const void *v5; // r13
void *v6; // rdx
int v7; // edx

result = 0LL;
if ( a3 )
{
v4 = a3;
result = bavail_write((__int64)a1);
if ( (_DWORD)result )
{
v5 = (const void *)a1[1];
v6 = memchr(v5, 10, (int)result);
result = 0LL;
if ( v6 )
{
v7 = (_DWORD)v6 - (_DWORD)v5;
if ( v7 + 1 <= v4 )
v4 = v7 + 1;
memcpy(a2, v5, v4);
a1[1] += v4;
bcheck_empty(a1);
result = (unsigned int)v4;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 *a1, void *a2, size_t a3)
{
__int64 result; // rax
size_t v4; // rbx
const void *v5; // r13
void *v6; // rdx
int v7; // edx

result = 0LL;
if ( a3 )
{
v4 = a3;
result = func0((__int64)a1);
if ( (_DWORD)result )
{
v5 = (const void *)a1[1];
v6 = memchr(v5, 10, (int)result);
result = 0LL;
if ( v6 )
{
v7 = (_DWORD)v6 - (_DWORD)v5;
if ( v7 + 1 <= v4 )
v4 = v7 + 1;
memcpy(a2, v5, v4);
a1[1] += v4;
func2(a1);
result = (unsigned int)v4;
}
}
}
return result;
}

original_code:
int bgets(struct buffer *b, char *s, size_t len)
{
 int size;
 char *p;
 int n;
 if (len == 0)
  return 0;
 size = bavail_write(b);
 if (size == 0)
  return 0;
 if ((p = memchr(b->begin, '\n', size)) == ((void *)0))
  return 0;
 n = p - b->begin + 1;
 if (len > n)
  len = n;
 memcpy(s, b->begin, len);
 b->begin += len;
 bcheck_empty(b);
 return len;
}

canonical_original_code:
int bgets(struct buffer *b, char *s, unsigned long len)
{
 int size;
 char *p;
 int n;
 if (len == 0)
  return 0;
 size = bavail_write(b);
 if (size == 0)
  return 0;
 if ((p = memchr(b->begin, '\n', size)) == ((void *)0))
  return 0;
 n = p - b->begin + 1;
 if (len > n)
  len = n;
 memcpy(s, b->begin, len);
 b->begin += len;
 bcheck_empty(b);
 return len;
}

variable_types:
s
char *

variable_types:
len
unsigned long

variable_types:
p
char *

user_defined_types: struct buffer { char *addr; char *begin; char *end; int size; }


bputs

decompiled_code:
__int64 __fastcall bputs(__int64 a1, const void *a2, size_t a3)
{
__int64 result; // rax
size_t v4; // rbx

result = 0LL;
if ( a3 )
{
v4 = a3;
result = bavail_read(a1);
if ( (_DWORD)result )
{
if ( (int)result <= v4 )
v4 = (int)result;
memcpy(*(void **)(a1 + 16), a2, v4);
*(_QWORD *)(a1 + 16) += v4;
result = (unsigned int)v4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const void *a2, size_t a3)
{
__int64 result; // rax
size_t v4; // rbx

result = 0LL;
if ( a3 )
{
v4 = a3;
result = func1(a1);
if ( (_DWORD)result )
{
if ( (int)result <= v4 )
v4 = (int)result;
memcpy(*(void **)(a1 + 16), a2, v4);
*(_QWORD *)(a1 + 16) += v4;
result = (unsigned int)v4;
}
}
return result;
}

original_code:
int bputs(struct buffer *b, char *s, size_t len)
{
 int size;
 if (len == 0)
  return 0;
 size = bavail_read(b);
 if (size == 0)
  return 0;
 if (len > size)
  len = size;
 memcpy(b->end, s, len);
 b->end += len;
 return len;
}

canonical_original_code:
int bputs(struct buffer *b, char *s, unsigned long len)
{
 int size;
 if (len == 0)
  return 0;
 size = bavail_read(b);
 if (size == 0)
  return 0;
 if (len > size)
  len = size;
 memcpy(b->end, s, len);
 b->end += len;
 return len;
}


bcanfill

decompiled_code:
_BOOL8 __fastcall bcanfill(__int64 a1)
{
return (int)bavail_read(a1) > 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func9(__int64 a1)
{
return (int)func1(a1) > 0;
}

original_code:
int bcanfill(struct buffer *b)
{
 return bavail_read(b) > 0;
}


bhasdata

decompiled_code:
_BOOL8 __fastcall bhasdata(__int64 a1)
{
return (int)bavail_write(a1) > 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func10(__int64 a1)
{
return (int)func0(a1) > 0;
}

original_code:
int bhasdata(struct buffer *b)
{
 return bavail_write(b) > 0;
}


xmalloc

decompiled_code:
void *__fastcall xmalloc(size_t a1)
{
void *result; // rax
int *v2; // rax
char *v3; // rax

result = malloc(a1);
if ( !result )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "%s:%d: malloc %zd bytes: %s\n", "xwrap.c", 12LL, a1, v3);
exit(1);
}
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t a1)
{
void *result; // rax
int *v2; // rax
char *v3; // rax

result = malloc(a1);
if ( !result )
{
v2 = _errno_location();
v3 = strerror(*v2);
fprintf(stderr, "%s:%d: malloc %zd bytes: %s\n", "xwrap.c", 12LL, a1, v3);
exit(1);
}
return result;
}

original_code:
void *xmalloc(size_t size)
{
 void *p;
 p = malloc(size);
 if (p == ((void *)0))
  do { fprintf(stderr, "%s" ":" "%d" ": " "malloc %zd bytes" ": " "%s" "\n", "xwrap.c", 12, size, strerror((*__errno_location ()))); exit(1); } while (0);
 return p;
}

canonical_original_code:
void *xmalloc(unsigned long size)
{
 void *p;
 p = malloc(size);
 if (p == ((void *)0))
  do { fprintf(stderr, "%s" ":" "%d" ": " "malloc %zd bytes" ": " "%s" "\n", "xwrap.c", 12, size, strerror((*__errno_location ()))); exit(1); } while (0);
 return p;
}

variable_types:
size
unsigned long

variable_types:
p
void *

return_type: void *


xstrdup

decompiled_code:
void *__fastcall xstrdup(void *src)
{
size_t v1; // rbp
void *v2; // rax

if ( !src )
return 0LL;
v1 = (int)(strlen((const char *)src) + 1);
v2 = xmalloc(v1);
return memcpy(v2, src, v1);
}

canonical_decompiled_code:
void *__fastcall func1(void *src)
{
size_t v1; // rbp
void *v2; // rax

if ( !src )
return 0LL;
v1 = (int)(strlen((const char *)src) + 1);
v2 = func0(v1);
return memcpy(v2, src, v1);
}

original_code:
char *xstrdup(const char *s)
{
 int len;
 if (s == ((void *)0))
  return ((void *)0);
 len = strlen(s) + 1;
 return memcpy(xmalloc(len), s, len);
}

canonical_original_code:
char *xstrdup(char *s)
{
 int len;
 if (s == ((void *)0))
  return ((void *)0);
 len = strlen(s) + 1;
 return memcpy(xmalloc(len), s, len);
}

variable_types: len int

return_type: char *


unitBitcount

original_code:
int unitBitcount(unsigned char* d, int cnum){
  int i;
  int b, s, n;
  b = (int)ceil((double)cnum / (sizeof(unsigned char)*8));
  s = 0;
  for(i=b-1;i>=0;i--){
    n = d[i];
    n = (unsigned char)( ((n & 0xAA) >> 1) + (n & 0x55) );
    n = (unsigned char)( ((n & 0xCC) >> 2) + (n & 0x33) );
    n = (unsigned char)( ((n & 0xF0) >> 4) + (n & 0x0F) );
    s += n;
  }
  return s;
}

canonical_original_code:
int unitBitcount(unsigned char *d, int cnum){
  int i;
  int b; int s; int n;
  b = (int)ceil((double)cnum / (sizeof(unsigned char)*8));
  s = 0;
  for(i=b-1;i>=0;i--){
    n = d[i];
    n = (unsigned char)( ((n & 0xAA) >> 1) + (n & 0x55) );
    n = (unsigned char)( ((n & 0xCC) >> 2) + (n & 0x33) );
    n = (unsigned char)( ((n & 0xF0) >> 4) + (n & 0x0F) );
    s += n;
  }
  return s;
}

variable_types:
d
unsigned char *

variable_types: cnum int

variable_types: i int

variable_types: b int

variable_types: s int


original_code:
unsigned int udata2uint(unsigned char* a, int n){
  int i;
  int b;
  unsigned int ret;
  b = (int)ceil((double)n / (sizeof(unsigned char)*8));
  ret = 0;
  for(i=b-1;i>=0;i--){
    ret *= 256;
    ret += a[i];
  }
  return ret;
}

canonical_original_code:
unsigned int udata2uint(unsigned char *a, int n){
  int i;
  int b;
  unsigned int ret;
  b = (int)ceil((double)n / (sizeof(unsigned char)*8));
  ret = 0;
  for(i=b-1;i>=0;i--){
    ret *= 256;
    ret += a[i];
  }
  return ret;
}

variable_types:
a
unsigned char *

variable_types:
ret
unsigned int

return_type: unsigned int


unitFree

decompiled_code:
void __fastcall unitFree(void *ptr)
{
__int64 v1; // rbx

if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 1) + 8 * v1++));
while ( *(_DWORD *)ptr > (int)v1 );
}
free(*((void **)ptr + 1));
free(ptr);
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
__int64 v1; // rbx

if ( *(int *)ptr > 0 )
{
v1 = 0LL;
do
free(*(void **)(*((_QWORD *)ptr + 1) + 8 * v1++));
while ( *(_DWORD *)ptr > (int)v1 );
}
free(*((void **)ptr + 1));
free(ptr);
}

original_code:
void unitFree(unit* u){
  int i;
  for(i=0;i<u->num;i++) free(u->array[i]);
  free(u->array);
  free(u);
}

canonical_original_code:
void unitFree(struct _unit *u){
  int i;
  for(i=0;i<u->num;i++) free(u->array[i]);
  free(u->array);
  free(u);
}

variable_types: struct _unit { int num; unsigned char **array; } *

return_type: void


uintCmp

decompiled_code:
__int64 __fastcall uintCmp(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rax
int v5; // edx
bool v6; // si
bool v7; // cl
__int64 result; // rax

if ( a3 < 0 )
return 0LL;
v4 = a3 - 1;
do
{
v5 = *(unsigned __int8 *)(a1 + v4 + 1) - *(unsigned __int8 *)(a2 + v4 + 1);
v6 = *(unsigned __int8 *)(a1 + v4 + 1) == *(unsigned __int8 *)(a2 + v4 + 1);
v7 = (int)v4-- >= 0;
}
while ( v7 && v6 );
result = 1LL;
if ( v5 >= 0 )
result = 2 * (unsigned int)(v5 > 0);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2, int a3)
{
__int64 v4; // rax
int v5; // edx
bool v6; // si
bool v7; // cl
__int64 result; // rax

if ( a3 < 0 )
return 0LL;
v4 = a3 - 1;
do
{
v5 = *(unsigned __int8 *)(a1 + v4 + 1) - *(unsigned __int8 *)(a2 + v4 + 1);
v6 = *(unsigned __int8 *)(a1 + v4 + 1) == *(unsigned __int8 *)(a2 + v4 + 1);
v7 = (int)v4-- >= 0;
}
while ( v7 && v6 );
result = 1LL;
if ( v5 >= 0 )
result = 2 * (unsigned int)(v5 > 0);
return result;
}

original_code:
int uintCmp(unsigned char* a1, unsigned char* a2, int b){
  int i;
  int t=0;
  int ret=0;
  t=0; i=b;
  while((t == 0) & (i>=0)){
    t = (int)(a1[i] - a2[i]);
    i--;
  };
  if(t<0) ret = 1;
  else if(t>0) ret = 2;
  else ret = 0;
  return ret;
}

canonical_original_code:
int uintCmp(unsigned char *a1, unsigned char *a2, int b){
  int i;
  int t = 0;
  int ret = 0;
  t=0; i=b;
  while((t == 0) & (i>=0)){
    t = (int)(a1[i] - a2[i]);
    i--;
  };
  if(t<0) ret = 1;
  else if(t>0) ret = 2;
  else ret = 0;
  return ret;
}

variable_types: t int

variable_types: ret int


decompiled_code:
__int64 __fastcall uintMed3(__int64 a1, __int64 a2, __int64 a3, int a4)
{
int v6; // edx
__int64 result; // rax
bool v8; // zf
int v9; // edx

if ( (unsigned int)uintCmp(a1, a2, a4) == 1 )
{
v9 = uintCmp(a2, a3, a4);
result = a2;
if ( v9 != 1 )
{
v8 = (unsigned int)uintCmp(a3, a1, a4) == 1;
result = a3;
if ( v8 )
result = a1;
}
}
else
{
v6 = uintCmp(a3, a2, a4);
result = a3;
if ( v6 != 1 )
{
v8 = (unsigned int)uintCmp(a1, a3, a4) == 1;
result = a2;
if ( v8 )
result = a1;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2, __int64 a3, int a4)
{
int v6; // edx
__int64 result; // rax
bool v8; // zf
int v9; // edx

if ( (unsigned int)func3(a1, a2, a4) == 1 )
{
v9 = func3(a2, a3, a4);
result = a2;
if ( v9 != 1 )
{
v8 = (unsigned int)func3(a3, a1, a4) == 1;
result = a3;
if ( v8 )
result = a1;
}
}
else
{
v6 = func3(a3, a2, a4);
result = a3;
if ( v6 != 1 )
{
v8 = (unsigned int)func3(a1, a3, a4) == 1;
result = a2;
if ( v8 )
result = a1;
}
}
return result;
}

original_code:
unsigned char* uintMed3(unsigned char* x, unsigned char* y, unsigned char* z, int b){
  unsigned char* ret;
  if(uintCmp(x, y, b) == 1){
    if(uintCmp(y, z, b) == 1) ret = y;
    else if(uintCmp(z, x, b) == 1) ret = x;
    else ret = z;
  }
  else{
    if(uintCmp(z, y, b) == 1) ret = z;
    else if(uintCmp(x, z, b) == 1) ret = x;
    else ret = y;
  }
  return ret;
}

canonical_original_code:
unsigned char *uintMed3(unsigned char *x, unsigned char *y, unsigned char *z, int b){
  unsigned char *ret;
  if(uintCmp(x, y, b) == 1){
    if(uintCmp(y, z, b) == 1) ret = y;
    else if(uintCmp(z, x, b) == 1) ret = x;
    else ret = z;
  }
  else{
    if(uintCmp(z, y, b) == 1) ret = z;
    else if(uintCmp(x, z, b) == 1) ret = x;
    else ret = y;
  }
  return ret;
}

variable_types:
x
unsigned char *

variable_types:
y
unsigned char *

variable_types:
z
unsigned char *

variable_types:
ret
unsigned char *

return_type: unsigned char *


uintQuicksort

original_code:
void uintQuicksort(unsigned char** a, int left, int right, int b){
  int i, j;
  unsigned char *tmp, *pivot;
  if(left < right){
    i = left; j = right;
    pivot = uintMed3(a[i], a[i+(j-i)/2], a[j], b);
    while(1){
      while(uintCmp(a[i], pivot, b) == 1) i++;
      while(uintCmp(pivot, a[j], b) == 1) j--;
      if(i>=j) break;
      tmp = a[i];
      a[i] = a[j];
      a[j] = tmp;
      i++; j--;
    }
    uintQuicksort(a, left, i-1, b);
    uintQuicksort(a, j+1, right, b);
  }
}

canonical_original_code:
void uintQuicksort(unsigned char **a, int left, int right, int b){
  int i; int j;
  unsigned char *tmp; unsigned char *pivot;
  if(left < right){
    i = left; j = right;
    pivot = uintMed3(a[i], a[i+(j-i)/2], a[j], b);
    while(1){
      while(uintCmp(a[i], pivot, b) == 1) i++;
      while(uintCmp(pivot, a[j], b) == 1) j--;
      if(i>=j) break;
      tmp = a[i];
      a[i] = a[j];
      a[j] = tmp;
      i++; j--;
    }
    uintQuicksort(a, left, i-1, b);
    uintQuicksort(a, j+1, right, b);
  }
}

variable_types:
a
unsigned char **

variable_types: left int

variable_types: right int

variable_types: j int

variable_types:
tmp
unsigned char *

variable_types:
pivot
unsigned char *


uintSort

decompiled_code:
void __fastcall uintSort(__int64 a1, int a2, unsigned int a3)
{
uintQuicksort(a1, 0, a2 - 1, a3);
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1, int a2, unsigned int a3)
{
func5(a1, 0, a2 - 1, a3);
}

original_code:
void uintSort(unsigned char** array, int num, int b){
  uintQuicksort(array, 0, num-1, b);
}

canonical_original_code:
void uintSort(unsigned char **array, int num, int b){
  uintQuicksort(array, 0, num-1, b);
}

variable_types:
array
unsigned char **

variable_types: num int

variable_types: b int


uintCpy

decompiled_code:
__int64 __fastcall uintCpy(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rdx
__int64 result; // rax

LODWORD(v3) = a3 - 1;
if ( (int)v3 >= 0 )
{
v3 = (int)v3;
do
{
result = *(unsigned __int8 *)(a2 + v3);
*(_BYTE *)(a1 + v3--) = result;
}
while ( (int)v3 >= 0 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1, __int64 a2, int a3)
{
__int64 v3; // rdx
__int64 result; // rax

LODWORD(v3) = a3 - 1;
if ( (int)v3 >= 0 )
{
v3 = (int)v3;
do
{
result = *(unsigned __int8 *)(a2 + v3);
*(_BYTE *)(a1 + v3--) = result;
}
while ( (int)v3 >= 0 );
}
return result;
}

original_code:
void uintCpy(unsigned char* d, unsigned char* s, int b){
  int i;
  for(i=b-1;i>=0;i--) d[i] = s[i];
}

canonical_original_code:
void uintCpy(unsigned char *d, unsigned char *s, int b){
  int i;
  for(i=b-1;i>=0;i--) d[i] = s[i];
}

variable_types:
d
unsigned char *

variable_types:
s
unsigned char *

variable_types: i int


hammingView

decompiled_code:
int __fastcall hammingView(unsigned int *a1, __int64 a2)
{
int result; // eax
__int64 i; // rbp
__int64 j; // rbx

result = printf(" n: %d \n", *a1);
for ( i = *((_QWORD *)a1 + 1); i; i = *(_QWORD *)(i + 24) )
{
for ( j = 0LL; *(_DWORD *)(i + 8) > (int)j; ++j )
printf(
"[%d] %04X ",
*(unsigned int *)(*(_QWORD *)(i + 16) + 4 * j),
*(unsigned int *)(a2 + 4LL * *(unsigned int *)(*(_QWORD *)(i + 16) + 4 * j)));
result = putchar(10);
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(unsigned int *a1, __int64 a2)
{
int result; // eax
__int64 i; // rbp
__int64 j; // rbx

result = printf(" n: %d \n", *a1);
for ( i = *((_QWORD *)a1 + 1); i; i = *(_QWORD *)(i + 24) )
{
for ( j = 0LL; *(_DWORD *)(i + 8) > (int)j; ++j )
printf(
"[%d] %04X ",
*(unsigned int *)(*(_QWORD *)(i + 16) + 4 * j),
*(unsigned int *)(a2 + 4LL * *(unsigned int *)(*(_QWORD *)(i + 16) + 4 * j)));
result = putchar(10);
}
return result;
}

original_code:
void hammingView(hamming* h, unsigned int* term){
  hammingData *lp;
  int i;
  printf(" n: %d \n", h->len);
  lp = h->head;
  while(lp != ((void *)0)){
    for(i=0;i<lp->arraysize;i++){
      printf("[%d] %04X ", lp->array[i], term[lp->array[i]]);
    }
    printf("\n");
    lp = lp->next;
  }
}

canonical_original_code:
void hammingView(struct _hamming *h, unsigned int *term){
  struct _hammingData *lp;
  int i;
  printf(" n: %d \n", h->len);
  lp = h->head;
  while(lp != ((void *)0)){
    for(i=0;i<lp->arraysize;i++){
      printf("[%d] %04X ", lp->array[i], term[lp->array[i]]);
    }
    printf("\n");
    lp = lp->next;
  }
}

variable_types: struct _hamming { int len; struct _hammingData { int flag; unsigned int mask; int arraysize; unsigned int *array; struct _hammingData *next; } *head; } *

variable_types:
term
unsigned int *

user_defined_types: struct _hamming { int len; struct _hammingData *head; }


hammingNew

decompiled_code:
_QWORD *hammingNew()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

original_code:
hamming* hammingNew(){
  hamming* h;
  h = (hamming*)malloc(sizeof(hamming));
  h->len = 0;
  h->head = ((void *)0);
  h->tail = ((void *)0);
  return h;
}

canonical_original_code:
struct _hamming *hammingNew(){
  struct _hamming *h;
  h = (struct _hamming *)malloc(sizeof(hamming));
  h->len = 0;
  h->head = ((void *)0);
  h->tail = ((void *)0);
  return h;
}

return_type: struct _hamming { int len; struct _hammingData { int flag; unsigned int mask; int arraysize; unsigned int *array; struct _hammingData *next; } *head; } *


hammingFree

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

v1 = *((_QWORD *)ptr + 1);
while ( v1 )
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 24);
free(v2[2]);
free(v2);
}
free(ptr);
}

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

v1 = *((_QWORD *)ptr + 1);
while ( v1 )
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 24);
free(v2[2]);
free(v2);
}
free(ptr);
}

original_code:
void hammingFree(hamming* h){
  hammingData *p, *d;
  p = h->head;
  while(p != ((void *)0)){
    d = p;
    p = p->next;
    free(d->array);
    free(d);
  }
  free(h);
}

canonical_original_code:
void hammingFree(struct _hamming *h){
  struct _hammingData *p; struct _hammingData *d;
  p = h->head;
  while(p != ((void *)0)){
    d = p;
    p = p->next;
    free(d->array);
    free(d);
  }
  free(h);
}

variable_types: struct _hammingData { int flag; unsigned int mask; int arraysize; unsigned int *array; struct _hammingData *next; } *


hammingDistance

decompiled_code:
__int64 __fastcall hammingDistance(int a1, int a2, unsigned int a3, int a4)
{
int v4; // ebp
int v5; // ebx

v4 = a4 ^ a3;
v5 = bitcount((a3 | a2 | a4) ^ (a1 | a4 | a3));
return v5 + (unsigned int)bitcount(v4);
}

canonical_decompiled_code:
__int64 __fastcall func4(int a1, int a2, unsigned int a3, int a4)
{
int v4; // ebp
int v5; // ebx

v4 = a4 ^ a3;
v5 = func3((a3 | a2 | a4) ^ (a1 | a4 | a3));
return v5 + (unsigned int)func3(v4);
}

original_code:
int hammingDistance(unsigned int a, unsigned int b, unsigned int ma, unsigned int mb){
  unsigned int d, dm;
  d = (a|ma|mb) ^ (b|ma|mb);
  dm = ma ^ mb;
  return bitcount(d)+bitcount(dm);
}

canonical_original_code:
int hammingDistance(unsigned int a, unsigned int b, unsigned int ma, unsigned int mb){
  unsigned int d; unsigned int dm;
  d = (a|ma|mb) ^ (b|ma|mb);
  dm = ma ^ mb;
  return bitcount(d)+bitcount(dm);
}

variable_types:
a
unsigned int

variable_types:
b
unsigned int

variable_types:
ma
unsigned int

variable_types:
mb
unsigned int

variable_types:
d
unsigned int

variable_types:
dm
unsigned int


bitExpression

decompiled_code:
void __fastcall bitExpression(__int64 a1, __int64 a2, int a3)
{
unsigned int v4; // er13
unsigned int v5; // ebp
char *v6; // rax
char *v7; // r12
char *v8; // rcx
__int64 v9; // rbx

v4 = *(_DWORD *)(a1 + 4LL * **(unsigned int **)(a2 + 16));
v5 = *(_DWORD *)(a2 + 4);
v6 = (char *)malloc(a3);
if ( !v6 )
{
puts("memory Allocation Error.");
exit(1);
}
v7 = v6;
v8 = &v6[a3];
if ( a3 > 0 )
{
do
{
if ( (v5 & 1) != 0 )
*v6 = 88;
else
*v6 = (v4 & 1) + 48;
v5 >>= 1;
v4 >>= 1;
++v6;
}
while ( v6 != v8 );
v9 = a3 - 1;
do
putchar(v7[v9--]);
while ( (int)v9 >= 0 );
}
free(v7);
}

original_code:
void bitExpression(unsigned int* term, hammingData* hd, int blen){
  int i;
  unsigned int d;
  unsigned int m;
  char *c;
  d = term[hd->array[0]];
  m = hd->mask;
  c = ((void *)0);
  c = (char*)malloc(sizeof(char)*(blen));
  if(c == ((void *)0)){
    printf("memory Allocation Error.\n");
    exit(1);
  }
  for(i=0;i<blen;i++){
    if(m % 2) c[i] = 'X';
    else c[i] = '0'+(d%2);
    m /= 2;
    d /= 2;
  }
  for(i=blen-1;i>=0;i--) printf("%c", c[i]);
  free(c);
  c = ((void *)0);
}

canonical_original_code:
void bitExpression(unsigned int *term, struct _hammingData *hd, int blen){
  int i;
  unsigned int d;
  unsigned int m;
  char *c;
  d = term[hd->array[0]];
  m = hd->mask;
  c = ((void *)0);
  c = (char *)malloc(sizeof(char)*(blen));
  if(c == ((void *)0)){
    printf("memory Allocation Error.\n");
    exit(1);
  }
  for(i=0;i<blen;i++){
    if(m % 2) c[i] = 'X';
    else c[i] = '0'+(d%2);
    m /= 2;
    d /= 2;
  }
  for(i=blen-1;i>=0;i--) printf("%c", c[i]);
  free(c);
  c = ((void *)0);
}

variable_types: blen int

variable_types:
m
unsigned int

variable_types:
c
char *

user_defined_types: struct _hammingData { int flag; unsigned int mask; int arraysize; unsigned int *array; struct _hammingData *next; }


hammingMatch

original_code:
void hammingMatch(hamming* h, hammingData *a, hammingData *b, unsigned int *term){
  int i;
  int midx, nidx;
  unsigned int m, n;
  int dist;
  unsigned int dc, cb;
  hammingData *hd;
  hammingData *p;
  unsigned int diff;
  int flag;
  dist = hammingDistance(term[a->array[0]], term[b->array[0]],
                         a->mask, b->mask);
  printf("dist: %d  a:[%4d]%04X b:[%4d]%04X\n",
         dist, a->array[0], term[a->array[0]],
         b->array[0], term[b->array[0]]);
  if(dist == 1){
    dc = ((term[a->array[0]]|a->mask) ^ (term[b->array[0]]|b->mask))
      | a->mask | b->mask;
    cb = bitcount(term[a->array[0]]|dc)-bitcount(dc);
    printf("  DC:%04X, cb:%d\n",dc, cb);
    hd = (hammingData*)malloc(sizeof(hammingData));
    hd->flag = 0; hd->mask = dc; hd->next=((void *)0);
    hd->arraysize = a->arraysize + b->arraysize;
    hd->array = (unsigned int*)malloc(sizeof(unsigned int)*hd->arraysize);
    printf("  ArraySize : %d\n", hd->arraysize);
    midx=0; nidx=0;
    for(i=0;i<hd->arraysize;i++){
      if(midx < a->arraysize) m = a->array[midx];
      else m = (0x7fffffff * 2U + 1U);
      if(nidx < b->arraysize) n = b->array[nidx];
      else n = (0x7fffffff * 2U + 1U);
      if(m < n){ hd->array[i] = m; midx++; }
      else{ hd->array[i] = n; nidx++; }
    }
    flag=0; p=h->head;
    while((p != ((void *)0)) && (flag == 0)){
      if((p->mask == hd->mask) && (hd->arraysize == p->arraysize)){
        diff = 0;
        for(i=0;i<hd->arraysize;i++){
          diff += p->array[i] - hd->array[i];
          if(diff != 0) break;
        }
        if(diff == 0) flag = 1;
      }
      p=p->next;
    }
    if(flag == 0) printf("  Unique: true\n");
    else printf("  Unique: false\n");
    if(flag == 0){
      if(h->len == 0) h->tail = hd;
      else hd->next = h->head;
      h->head = hd;
      h->len++;
    }
    a->flag++; b->flag++;
  }
}

canonical_original_code:
void hammingMatch(struct _hamming *h, struct _hammingData *a, struct _hammingData *b, unsigned int *term){
  int i;
  int midx; int nidx;
  unsigned int m; unsigned int n;
  int dist;
  unsigned int dc; unsigned int cb;
  struct _hammingData *hd;
  struct _hammingData *p;
  unsigned int diff;
  int flag;
  dist = hammingDistance(term[a->array[0]], term[b->array[0]],
                         a->mask, b->mask);
  printf("dist: %d  a:[%4d]%04X b:[%4d]%04X\n",
         dist, a->array[0], term[a->array[0]],
         b->array[0], term[b->array[0]]);
  if(dist == 1){
    dc = ((term[a->array[0]]|a->mask) ^ (term[b->array[0]]|b->mask))
      | a->mask | b->mask;
    cb = bitcount(term[a->array[0]]|dc)-bitcount(dc);
    printf("  DC:%04X, cb:%d\n",dc, cb);
    hd = (struct _hammingData *)malloc(sizeof(hammingData));
    hd->flag = 0; hd->mask = dc; hd->next=((void *)0);
    hd->arraysize = a->arraysize + b->arraysize;
    hd->array = (unsigned int *)malloc(sizeof(unsigned int)*hd->arraysize);
    printf("  ArraySize : %d\n", hd->arraysize);
    midx=0; nidx=0;
    for(i=0;i<hd->arraysize;i++){
      if(midx < a->arraysize) m = a->array[midx];
      else m = (0x7fffffff * 2U + 1U);
      if(nidx < b->arraysize) n = b->array[nidx];
      else n = (0x7fffffff * 2U + 1U);
      if(m < n){ hd->array[i] = m; midx++; }
      else{ hd->array[i] = n; nidx++; }
    }
    flag=0; p=h->head;
    while((p != ((void *)0)) && (flag == 0)){
      if((p->mask == hd->mask) && (hd->arraysize == p->arraysize)){
        diff = 0;
        for(i=0;i<hd->arraysize;i++){
          diff += p->array[i] - hd->array[i];
          if(diff != 0) break;
        }
        if(diff == 0) flag = 1;
      }
      p=p->next;
    }
    if(flag == 0) printf("  Unique: true\n");
    else printf("  Unique: false\n");
    if(flag == 0){
      if(h->len == 0) h->tail = hd;
      else hd->next = h->head;
      h->head = hd;
      h->len++;
    }
    a->flag++; b->flag++;
  }
}

variable_types:
a
struct _hammingData *

variable_types:
b
struct _hammingData *

variable_types: midx int

variable_types: nidx int

variable_types:
n
unsigned int

variable_types: dist int

variable_types:
dc
unsigned int

variable_types:
cb
unsigned int

variable_types:
diff
unsigned int

variable_types: flag int


decompiled_code:
__int64 __fastcall send_to_serv(const char *a1, const char *a2)
{
unsigned int v2; // er12
unsigned int v3; // eax
char *v4; // r14
unsigned int v5; // eax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
const char *v11; // rbx
__pid_t v12; // er13
char *v13; // [rsp+18h] [rbp-40h]

v2 = ftok("/item/platform/route/etc/SHMKEY", 11);
if ( v2 == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
printf(&byte_2020, "comm.c", 18LL, v8);
return v2;
}
printf(&format, "comm.c", 21LL);
v3 = shmget(v2, 0x283C0uLL, 1024);
v2 = v3;
if ( v3 == -1 )
goto LABEL_13;
printf("shmget ok shmid is [%d]\n", v3);
v4 = (char *)shmat(v2, 0LL, 0);
if ( v4 == (char *)-1LL )
{
LABEL_14:
perror("shmat error");
return (unsigned int)-1;
}
v2 = ftok("/item/platform/route/etc/SHMKEY", 14);
if ( v2 == -1 )
{
v9 = __errno_location();
v10 = strerror(*v9);
printf(&byte_2020, "comm.c", 38LL, v10);
return v2;
}
printf(&format, "comm.c", 41LL);
v5 = shmget(v2, 0x3E8uLL, 1024);
v2 = v5;
if ( v5 == -1 )
{
LABEL_13:
perror("shm get error");
return v2;
}
printf("shmget ok shmid is [%d]\n", v5);
v13 = (char *)shmat(v2, 0LL, 0);
if ( v13 == (char *)-1LL )
goto LABEL_14;
v2 = 0;
while ( *(_QWORD *)v4 )
{
LABEL_9:
++v2;
v4 += 16480;
if ( v2 == 10 )
{
puts(&s);
return (unsigned int)-1;
}
}
memset(v4, 0, 0x4060uLL);
*(_QWORD *)v4 = getpid();
strcpy(v4 + 24, "QDTX");
strcpy(v4 + 39, a2);
*((_WORD *)v4 + 8232) = 87;
*((_WORD *)v4 + 8233) = 81;
v11 = v13 + 6;
while ( 1 )
{
printf("%ld %s %s\n", *(unsigned int *)(v11 - 6), v11, v11 - 2);
v12 = *(_DWORD *)(v11 - 6);
if ( v12 && !strcmp(v11, a1) && !strcmp(v11 - 2, "S") )
{
kill(v12, 12);
return v2;
}
if ( v11 == v13 + 986 )
break;
v11 += 20;
if ( v11 == v13 + 1006 )
goto LABEL_9;
}
puts(&byte_2040);
return (unsigned int)-1;
}

canonical_decompiled_code:
__int64 __fastcall func6(const char *a1, const char *a2)
{
unsigned int v2; // er12
unsigned int v3; // eax
char *v4; // r14
unsigned int v5; // eax
int *v7; // rax
char *v8; // rax
int *v9; // rax
char *v10; // rax
const char *v11; // rbx
__pid_t v12; // er13
char *v13; // [rsp+18h] [rbp-40h]

v2 = ftok("/item/platform/route/etc/SHMKEY", 11);
if ( v2 == -1 )
{
v7 = __errno_location();
v8 = strerror(*v7);
printf(&byte_2020, "comm.c", 18LL, v8);
return v2;
}
printf(&format, "comm.c", 21LL);
v3 = shmget(v2, 0x283C0uLL, 1024);
v2 = v3;
if ( v3 == -1 )
goto LABEL_13;
printf("shmget ok shmid is [%d]\n", v3);
v4 = (char *)shmat(v2, 0LL, 0);
if ( v4 == (char *)-1LL )
{
LABEL_14:
perror("shmat error");
return (unsigned int)-1;
}
v2 = ftok("/item/platform/route/etc/SHMKEY", 14);
if ( v2 == -1 )
{
v9 = __errno_location();
v10 = strerror(*v9);
printf(&byte_2020, "comm.c", 38LL, v10);
return v2;
}
printf(&format, "comm.c", 41LL);
v5 = shmget(v2, 0x3E8uLL, 1024);
v2 = v5;
if ( v5 == -1 )
{
LABEL_13:
perror("shm get error");
return v2;
}
printf("shmget ok shmid is [%d]\n", v5);
v13 = (char *)shmat(v2, 0LL, 0);
if ( v13 == (char *)-1LL )
goto LABEL_14;
v2 = 0;
while ( *(_QWORD *)v4 )
{
LABEL_9:
++v2;
v4 += 16480;
if ( v2 == 10 )
{
puts(&s);
return (unsigned int)-1;
}
}
memset(v4, 0, 0x4060uLL);
*(_QWORD *)v4 = getpid();
strcpy(v4 + 24, "QDTX");
strcpy(v4 + 39, a2);
*((_WORD *)v4 + 8232) = 87;
*((_WORD *)v4 + 8233) = 81;
v11 = v13 + 6;
while ( 1 )
{
printf("%ld %s %s\n", *(unsigned int *)(v11 - 6), v11, v11 - 2);
v12 = *(_DWORD *)(v11 - 6);
if ( v12 && !strcmp(v11, a1) && !strcmp(v11 - 2, "S") )
{
kill(v12, 12);
return v2;
}
if ( v11 == v13 + 986 )
break;
v11 += 20;
if ( v11 == v13 + 1006 )
goto LABEL_9;
}
puts(&byte_2040);
return (unsigned int)-1;
}

original_code:
int send_to_serv(char *servtype,char *buffer)
{
    int shmid = 0,i=0;
    key_t key;
 _transhm *trandata=((void *)0);
 _servershm *server=((void *)0);
 int maxtran = 10;
 int maxserver = 50;
    key = ftok("/item/platform/route/etc/SHMKEY",11);
    if(key == (key_t)-1)
    {
        printf("获取主键错误[%s][%d][%s]","comm.c",18,strerror((*__errno_location ())));
        return -1;
    }
    printf("获取主键成功[%s][%d]","comm.c",21);
    shmid = shmget(key,maxtran*sizeof(_transhm),02000);
    if(shmid == -1)
    {
        perror("shm get error");
        return -1;
    }
    printf("shmget ok shmid is [%d]\n",shmid);
 if((trandata=shmat(shmid,((void *)0),0))==(void *)-1)
 {
  perror("shmat error");
  return -1;
 }
    key = ftok("/item/platform/route/etc/SHMKEY",14);
    if(key == (key_t)-1)
    {
        printf("获取主键错误[%s][%d][%s]","comm.c",38,strerror((*__errno_location ())));
        return -1;
    }
    printf("获取主键成功[%s][%d]","comm.c",41);
    shmid = shmget(key,maxserver*sizeof(_servershm),02000);
    if(shmid == -1)
    {
        perror("shm get error");
        return -1;
    }
    printf("shmget ok shmid is [%d]\n",shmid);
 if((server=shmat(shmid,((void *)0),0))==(void *)-1)
 {
  perror("shmat error");
  return -1;
 }
 for(i=0;i<maxtran;i++)
 {
  if((trandata+i)->s_pid==0)
  {
   memset(trandata+i,0X00,sizeof(_transhm));
   (trandata+i)->s_pid = (pid_t)getpid();
   strcpy((trandata+i)->send_chnl,"QDTX");
   strcpy((trandata+i)->chnl_data,buffer);
   strcpy((trandata+i)->cur_stat,"W");
   strcpy((trandata+i)->require_serv,"Q");
   for(int j=0;j<50;j++)
   {
    printf("%ld %s %s\n",(server+j)->serverpid,(server+j)->require_serv,(server+j)->servtype);
    if((server+j)->serverpid!=0&&!strcmp((server+j)->require_serv,servtype)&&!strcmp((server+j)->servtype,"S"))
    {
     kill((server+j)->serverpid,12);
     return i;
     break;
    }
    if(j==49)
    {
     printf("该交易没有对应核心服务\n");
     return -1;
    }
   }
  }
 }
 printf("共享内存全部在使用中...\n");
 return -1;
}

canonical_original_code:
int send_to_serv(char *servtype, char *buffer)
{
    int shmid = 0; int i = 0;
    int key;
 struct TRANSHM *trandata = ((void *)0);
 struct SERVERSHM *server = ((void *)0);
 int maxtran = 10;
 int maxserver = 50;
    key = ftok("/item/platform/route/etc/SHMKEY",11);
    if(key == (key_t)-1)
    {
        printf("获取主键错误[%s][%d][%s]","comm.c",18,strerror((*__errno_location ())));
        return -1;
    }
    printf("获取主键成功[%s][%d]","comm.c",21);
    shmid = shmget(key,maxtran*sizeof(_transhm),02000);
    if(shmid == -1)
    {
        perror("shm get error");
        return -1;
    }
    printf("shmget ok shmid is [%d]\n",shmid);
 if((trandata=shmat(shmid,((void *)0),0))==(void *)-1)
 {
  perror("shmat error");
  return -1;
 }
    key = ftok("/item/platform/route/etc/SHMKEY",14);
    if(key == (key_t)-1)
    {
        printf("获取主键错误[%s][%d][%s]","comm.c",38,strerror((*__errno_location ())));
        return -1;
    }
    printf("获取主键成功[%s][%d]","comm.c",41);
    shmid = shmget(key,maxserver*sizeof(_servershm),02000);
    if(shmid == -1)
    {
        perror("shm get error");
        return -1;
    }
    printf("shmget ok shmid is [%d]\n",shmid);
 if((server=shmat(shmid,((void *)0),0))==(void *)-1)
 {
  perror("shmat error");
  return -1;
 }
 for(i=0;i<maxtran;i++)
 {
  if((trandata+i)->s_pid==0)
  {
   memset(trandata+i,0X00,sizeof(_transhm));
   (trandata+i)->s_pid = (int)getpid();
   strcpy((trandata+i)->send_chnl,"QDTX");
   strcpy((trandata+i)->chnl_data,buffer);
   strcpy((trandata+i)->cur_stat,"W");
   strcpy((trandata+i)->require_serv,"Q");
   for(int j = 0;j<50;j++)
   {
    printf("%ld %s %s\n",(server+j)->serverpid,(server+j)->require_serv,(server+j)->servtype);
    if((server+j)->serverpid!=0&&!strcmp((server+j)->require_serv,servtype)&&!strcmp((server+j)->servtype,"S"))
    {
     kill((server+j)->serverpid,12);
     return i;
     break;
    }
    if(j==49)
    {
     printf("该交易没有对应核心服务\n");
     return -1;
    }
   }
  }
 }
 printf("共享内存全部在使用中...\n");
 return -1;
}

variable_types:
servtype
char *

variable_types:
buffer
char *

variable_types: shmid int

variable_types: i int

variable_types: key int

variable_types: struct TRANSHM { unsigned long s_pid; unsigned long a_pid; unsigned long r_pid; char send_chnl[5]; char serv_name[5]; char recv_chnl[5]; char chnl_data[4096]; char senv_data[4096]; struct FLOW { int flowid; char flow_mark[60]; char func_name[20]; char dl_name[10]; char flow_type[2]; char errflow[60]; char timeoutflow[60]; } *do_flow; struct DATA { char varname[10]; char value[100]; } *do_data; char return_serv[4096]; char return_chnl[4096]; long stime; long dtime; long etime; char cur_stat[2]; char require_serv[3]; char xxx1[1]; char xxx2[1]; char xxx3[1]; char xxx4[1]; } *

variable_types: struct SERVERSHM { int serverpid; char servtype[2]; char require_serv[3]; char chnlid[5]; int cnt; } *

variable_types: maxtran int

variable_types: maxserver int

variable_types: j int

user_defined_types: struct TRANSHM { unsigned long s_pid; unsigned long a_pid; unsigned long r_pid; char send_chnl[5]; char serv_name[5]; char recv_chnl[5]; char chnl_data[4096]; char senv_data[4096]; struct FLOW *do_flow; struct DATA *do_data; char return_serv[4096]; char return_chnl[4096]; long stime; long dtime; long etime; char cur_stat[2]; char require_serv[3]; char xxx1[1]; char xxx2[1]; char xxx3[1]; char xxx4[1]; }


repo: n-west/udev-hso

decompiled_code:
void release_usb_device()
{
usb_release_interface(usb_hd, 0LL);
usb_close(usb_hd);
}

canonical_decompiled_code:
void func0()
{
usb_release_interface(usb_hd, 0LL);
usb_close(usb_hd);
}

original_code:
void release_usb_device(int param) {
 (void)usb_release_interface(usb_hd, 0);
 (void)usb_close(usb_hd);
}

variable_types: param int


decompiled_code:
int print_usage()
{
puts("Usage: ozerocdoff [-hqwqv] -i <DeviceID> [-f <name>] [-n <len>]\n");
puts(" -h, --help this help");
puts(" -i, --device_id <n> target USB device id, required option");
puts(" -f, --usb_filename <str> target USB file name");
printf(" -n, --namelen <n> target USB file name len (default %d)\n", (unsigned int)namelength);
puts(" -w, --warn_only print warnings instead of errors without program abort");
puts(" -q, --quiet don't show messages");
puts(" -t, --test test only, nothing send");
puts(" -l, --log write message into log file instead of stderr");
puts(" -s, --searchtime <n> ms tries to search at least <n> ms for the Zero-CD device");
puts(" -d, --debug output some debug messages");
puts(" -v, --version show version string\n");
puts("Examples:");
puts(" ozerocdoff -i 0xc031");
return puts(" ozerocdoff -i 0xc031 -f usbdev5.28 -n 2");
}

canonical_decompiled_code:
int func1()
{
puts("Usage: ozerocdoff [-hqwqv] -i <DeviceID> [-f <name>] [-n <len>]\n");
puts(" -h, --help this help");
puts(" -i, --device_id <n> target USB device id, required option");
puts(" -f, --usb_filename <str> target USB file name");
printf(" -n, --namelen <n> target USB file name len (default %d)\n", (unsigned int)namelength);
puts(" -w, --warn_only print warnings instead of errors without program abort");
puts(" -q, --quiet don't show messages");
puts(" -t, --test test only, nothing send");
puts(" -l, --log write message into log file instead of stderr");
puts(" -s, --searchtime <n> ms tries to search at least <n> ms for the Zero-CD device");
puts(" -d, --debug output some debug messages");
puts(" -v, --version show version string\n");
puts("Examples:");
puts(" ozerocdoff -i 0xc031");
return puts(" ozerocdoff -i 0xc031 -f usbdev5.28 -n 2");
}

original_code:
void print_usage(void) {
        printf ("Usage: ozerocdoff [-hqwqv] -i <DeviceID> [-f <name>] [-n <len>]\n\n");
 printf (" -h, --help               this help\n");
 printf (" -i, --device_id <n>      target USB device id, required option\n");
 printf (" -f, --usb_filename <str> target USB file name\n");
 printf (" -n, --namelen <n>        target USB file name len (default %d)\n", namelength);
 printf (" -w, --warn_only          print warnings instead of errors without program abort\n");
 printf (" -q, --quiet              don't show messages\n");
 printf (" -t, --test               test only, nothing send\n");
 printf (" -l, --log                write message into log file instead of stderr\n");
 printf (" -s, --searchtime <n> ms  tries to search at least <n> ms for the Zero-CD device\n");
 printf (" -d, --debug              output some debug messages\n");
 printf (" -v, --version            show version string\n\n");
 printf ("Examples:\n");
 printf ("   ozerocdoff -i 0xc031\n");
 printf ("   ozerocdoff -i 0xc031 -f usbdev5.28 -n 2\n");
}

canonical_original_code:
void print_usage() {
        printf ("Usage: ozerocdoff [-hqwqv] -i <DeviceID> [-f <name>] [-n <len>]\n\n");
 printf (" -h, --help               this help\n");
 printf (" -i, --device_id <n>      target USB device id, required option\n");
 printf (" -f, --usb_filename <str> target USB file name\n");
 printf (" -n, --namelen <n>        target USB file name len (default %d)\n", namelength);
 printf (" -w, --warn_only          print warnings instead of errors without program abort\n");
 printf (" -q, --quiet              don't show messages\n");
 printf (" -t, --test               test only, nothing send\n");
 printf (" -l, --log                write message into log file instead of stderr\n");
 printf (" -s, --searchtime <n> ms  tries to search at least <n> ms for the Zero-CD device\n");
 printf (" -d, --debug              output some debug messages\n");
 printf (" -v, --version            show version string\n\n");
 printf ("Examples:\n");
 printf ("   ozerocdoff -i 0xc031\n");
 printf ("   ozerocdoff -i 0xc031 -f usbdev5.28 -n 2\n");
}


strrcut

decompiled_code:
const char *__fastcall strrcut(const char *a1, int a2)
{
size_t v2; // rax
const char *v3; // rbx
bool v4; // cf
const char *result; // rax

v2 = strlen(a1);
v3 = &a1[v2 - a2];
v4 = v2 < a2;
result = (const char *)&unk_1559;
if ( !v4 )
result = v3;
return result;
}

canonical_decompiled_code:
const char *__fastcall func2(const char *a1, int a2)
{
size_t v2; // rax
const char *v3; // rbx
bool v4; // cf
const char *result; // rax

v2 = strlen(a1);
v3 = &a1[v2 - a2];
v4 = v2 < a2;
result = (const char *)&unk_1559;
if ( !v4 )
result = v3;
return result;
}

original_code:
const char *strrcut(const char *s, int n) {
        if (strlen(s)>=n) {
         return &(s[strlen(s)-n]);
 } else {
         return "";
 }
}

canonical_original_code:
char *strrcut(char *s, int n) {
        if (strlen(s)>=n) {
         return &(s[strlen(s)-n]);
 } else {
         return "";
 }
}

variable_types:
s
char *

variable_types: n int


strrcmp

decompiled_code:
int __fastcall strrcmp(char *s1, char *s2)
{
size_t v2; // r12
size_t v3; // rax
const char *v4; // rax
int result; // eax
const char *v6; // rax

v2 = strlen(s1);
v3 = strlen(s2);
if ( v2 > v3 )
{
v6 = strrcut(s1, v3);
result = strcmp(v6, s2);
}
else
{
v4 = strrcut(s2, v2);
result = strcmp(s1, v4);
}
return result;
}

canonical_decompiled_code:
int __fastcall func3(char *s1, char *s2)
{
size_t v2; // r12
size_t v3; // rax
const char *v4; // rax
int result; // eax
const char *v6; // rax

v2 = strlen(s1);
v3 = strlen(s2);
if ( v2 > v3 )
{
v6 = func2(s1, v3);
result = strcmp(v6, s2);
}
else
{
v4 = func2(s2, v2);
result = strcmp(s1, v4);
}
return result;
}

original_code:
int strrcmp(const char *s1, const char *s2) {
      if (strlen(s1)<=strlen(s2)) {
       return strcmp(s1,strrcut(s2,strlen(s1)));
      } else {
       return strcmp(strrcut(s1,strlen(s2)),s2);
      }
}

canonical_original_code:
int strrcmp(char *s1, char *s2) {
      if (strlen(s1)<=strlen(s2)) {
       return strcmp(s1,strrcut(s2,strlen(s1)));
      } else {
       return strcmp(strrcut(s1,strlen(s2)),s2);
      }
}


decompiled_code:
__int64 __fastcall search_message_endp(__int64 a1)
{
_BYTE *v1; // rdx
__int64 result; // rax
char v3; // dl

v1 = *(_BYTE **)(**(_QWORD **)(*(_QWORD *)(a1 + 4152) + 16LL) + 16LL);
if ( (v1[3] & 3) == 2 )
{
LOBYTE(result) = v1[2];
if ( (result & 0x80u) == 0LL )
return (unsigned __int8)result;
}
result = 0LL;
if ( (v1[35] & 3) == 2 )
{
v3 = v1[34];
result = (unsigned __int8)v3;
if ( v3 < 0 )
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
_BYTE *v1; // rdx
__int64 result; // rax
char v3; // dl

v1 = *(_BYTE **)(**(_QWORD **)(*(_QWORD *)(a1 + 4152) + 16LL) + 16LL);
if ( (v1[3] & 3) == 2 )
{
LOBYTE(result) = v1[2];
if ( (result & 0x80u) == 0LL )
return (unsigned __int8)result;
}
result = 0LL;
if ( (v1[35] & 3) == 2 )
{
v3 = v1[34];
result = (unsigned __int8)v3;
if ( v3 < 0 )
result = 0LL;
}
return result;
}

original_code:
int search_message_endp(struct usb_device *dev) {
        if ( ((dev->config[0].interface[0].altsetting[0].endpoint[0].bmAttributes & 0x03) == 2)
     &&((dev->config[0].interface[0].altsetting[0].endpoint[0].bEndpointAddress & 0x80) == 0)) {
         return dev->config[0].interface[0].altsetting[0].endpoint[0].bEndpointAddress;
 } else
         if ( ((dev->config[0].interface[0].altsetting[0].endpoint[1].bmAttributes & 0x03) == 2)
             &&((dev->config[0].interface[0].altsetting[0].endpoint[1].bEndpointAddress & 0x80) == 0)) {
                 return dev->config[0].interface[0].altsetting[0].endpoint[1].bEndpointAddress;
 }
 return 0;
}

variable_types: struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device *devices; unsigned int location; struct usb_device *root_dev; } *bus; struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; } descriptor; struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface { struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; } *endpoint; unsigned char *extra; int extralen; } *altsetting; int num_altsetting; } *interface; unsigned char *extra; int extralen; } *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; } *

user_defined_types: struct usb_device { struct usb_device *next; char filename[-1]; struct usb_bus *bus; struct usb_device_descriptor descriptor; struct usb_config_descriptor *config; void *dev; unsigned char devnum; unsigned char num_children; struct usb_device **children; }

user_defined_types: struct usb_config_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short wTotalLength; unsigned char bNumInterfaces; unsigned char bConfigurationValue; unsigned char iConfiguration; unsigned char bmAttributes; unsigned char MaxPower; struct usb_interface *interface; unsigned char *extra; int extralen; }

user_defined_types: struct usb_interface { struct usb_interface_descriptor *altsetting; int num_altsetting; }

user_defined_types: struct usb_interface_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bInterfaceNumber; unsigned char bAlternateSetting; unsigned char bNumEndpoints; unsigned char bInterfaceClass; unsigned char bInterfaceSubClass; unsigned char bInterfaceProtocol; unsigned char iInterface; struct usb_endpoint_descriptor *endpoint; unsigned char *extra; int extralen; }


decompiled_code:
__int64 __fastcall search_response_endp(__int64 a1)
{
_BYTE *v1; // rcx
__int64 result; // rax
char v3; // dl

v1 = *(_BYTE **)(**(_QWORD **)(*(_QWORD *)(a1 + 4152) + 16LL) + 16LL);
if ( (v1[3] & 3) == 2 )
{
LOBYTE(result) = v1[2];
if ( (result & 0x80u) != 0LL )
return (unsigned __int8)result;
}
result = 0LL;
if ( (v1[35] & 3) == 2 )
{
v3 = v1[34];
result = (unsigned __int8)v3;
if ( v3 >= 0 )
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
_BYTE *v1; // rcx
__int64 result; // rax
char v3; // dl

v1 = *(_BYTE **)(**(_QWORD **)(*(_QWORD *)(a1 + 4152) + 16LL) + 16LL);
if ( (v1[3] & 3) == 2 )
{
LOBYTE(result) = v1[2];
if ( (result & 0x80u) != 0LL )
return (unsigned __int8)result;
}
result = 0LL;
if ( (v1[35] & 3) == 2 )
{
v3 = v1[34];
result = (unsigned __int8)v3;
if ( v3 >= 0 )
result = 0LL;
}
return result;
}

original_code:
int search_response_endp(struct usb_device *dev) {
        if ( ((dev->config[0].interface[0].altsetting[0].endpoint[0].bmAttributes & 0x03) == 2)
     &&((dev->config[0].interface[0].altsetting[0].endpoint[0].bEndpointAddress & 0x80) == 0x80)) {
         return dev->config[0].interface[0].altsetting[0].endpoint[0].bEndpointAddress;
 } else
         if ( ((dev->config[0].interface[0].altsetting[0].endpoint[1].bmAttributes & 0x03) == 2)
             &&((dev->config[0].interface[0].altsetting[0].endpoint[1].bEndpointAddress & 0x80) == 0x80)) {
                 return dev->config[0].interface[0].altsetting[0].endpoint[1].bEndpointAddress;
 }
 return 0;
}

user_defined_types: struct usb_device_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned short bcdUSB; unsigned char bDeviceClass; unsigned char bDeviceSubClass; unsigned char bDeviceProtocol; unsigned char bMaxPacketSize0; unsigned short idVendor; unsigned short idProduct; unsigned short bcdDevice; unsigned char iManufacturer; unsigned char iProduct; unsigned char iSerialNumber; unsigned char bNumConfigurations; }

user_defined_types: struct usb_bus { struct usb_bus *next; char dirname[-1]; struct usb_device *devices; unsigned int location; struct usb_device *root_dev; }

user_defined_types: struct usb_endpoint_descriptor { unsigned char bLength; unsigned char bDescriptorType; unsigned char bEndpointAddress; unsigned char bmAttributes; unsigned short wMaxPacketSize; unsigned char bInterval; unsigned char bRefresh; unsigned char bSynchAddress; unsigned char *extra; int extralen; }


version

decompiled_code:
void __noreturn version()
{
printf("racker-%.2f, © 2009-2010 Matthias Fassl\n\n", *(double *)&LC0);
printf("build machine: %s\nbuild date: %s\n", "5.15.0-139-generic x86_64 GNU/Linux", "2025-05-23");
exit(0);
}

canonical_decompiled_code:
void __noreturn func0()
{
printf("racker-%.2f, © 2009-2010 Matthias Fassl\n\n", *(double *)&LC0);
printf("build machine: %s\nbuild date: %s\n", "5.15.0-139-generic x86_64 GNU/Linux", "2025-05-23");
exit(0);
}

original_code:
void version() {
        printf("racker-%.2f, © 2009-2010 Matthias Fassl\n\n",0.2);
 printf("build machine: %s\nbuild date: %s\n","5.15.0-100-generic x86_64 GNU/Linux","2024-04-20");
 exit(0);
}


usage

decompiled_code:
void __noreturn usage()
{
puts("Usage:");
puts("\t-v for version information");
puts("\t-f \"FILE\" specify which configuration file to use (necessary)");
puts("\t-d debug mode");
exit(1);
}

canonical_decompiled_code:
void __noreturn func1()
{
puts("Usage:");
puts("\t-v for version information");
puts("\t-f \"FILE\" specify which configuration file to use (necessary)");
puts("\t-d debug mode");
exit(1);
}

original_code:
void usage() {
 printf("Usage:\n");
 printf("\t-v for version information\n");
 printf("\t-f \"FILE\" specify which configuration file to use (necessary)\n");
 printf("\t-d debug mode\n");
 exit(1);
}


main

canonical_name: main

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

debug = 0;
v3 = 0LL;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "dvf:");
if ( v4 == -1 )
break;
if ( v4 == 102 )
{
v3 = optarg;
}
else if ( v4 > 102 )
{
if ( v4 == 118 )
version();
}
else
{
if ( v4 == 63 )
usage();
if ( v4 == 100 )
debug = 1;
}
}
if ( !v3 )
{
if ( debug )
fwrite("You need to specify a configuration file\n", 1uLL, 0x29uLL, stderr);
else
syslog(3, "You need to specify a configuration file\n");
usage();
}
if ( debug || (openlog(*argv, 3, 24), debug) )
printf("----- racker is starting -----");
else
syslog(6, "----- racker is starting -----");
v5 = config_initialize(v3);
config_other(v5);
if ( !debug )
daemonize();
signal(15, (__sighandler_t)&sig_handler);
config_listeners(v5);
return 0;
}

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

debug = 0;
v3 = 0LL;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "dvf:");
if ( v4 == -1 )
break;
if ( v4 == 102 )
{
v3 = optarg;
}
else if ( v4 > 102 )
{
if ( v4 == 118 )
func0();
}
else
{
if ( v4 == 63 )
func1();
if ( v4 == 100 )
debug = 1;
}
}
if ( !v3 )
{
if ( debug )
fwrite("You need to specify a configuration file\n", 1uLL, 0x29uLL, stderr);
else
syslog(3, "You need to specify a configuration file\n");
func1();
}
if ( debug || (openlog(*argv, 3, 24), debug) )
printf("----- racker is starting -----");
else
syslog(6, "----- racker is starting -----");
v5 = config_initialize(v3);
config_other(v5);
if ( !debug )
daemonize();
signal(15, (__sighandler_t)&sig_handler);
config_listeners(v5);
return 0;
}

original_code:
int main(int argc, char *argv[]) {
 int c;
 char* configfile = ((void *)0);
 extern char *optarg;
 debug = 0;
 while ((c = getopt(argc, argv, "dvf:")) != -1) {
      switch(c) {
       case 'v':
    version();
    break;
       case 'f':
    configfile = optarg;
    break;
   case 'd':
    debug = 1;
    break;
       case '?':
    usage();
      }
 }
 if(configfile == ((void *)0)) {
  if(debug) { if(3 == 3) { fprintf(stderr,"You need to specify a configuration file\n"); } else { printf("You need to specify a configuration file\n"); } } else { syslog(3,"You need to specify a configuration file\n"); };
  usage();
 }
 if(!debug) {
  openlog(argv[0], 0x01|0x02, (3<<3));
 }
 if(debug) { if(6 == 3) { fprintf(stderr,"----- racker is starting -----"); } else { printf("----- racker is starting -----"); } } else { syslog(6,"----- racker is starting -----"); };
 config_t *cfg = config_initialize(configfile);
 config_other(cfg);
 if(!debug) {
  daemonize();
 }
 signal(15,sig_handler);
 config_listeners(cfg);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[]) {
 int c;
 char *configfile = ((void *)0);
 extern char *optarg;
 debug = 0;
 while ((c = getopt(argc, argv, "dvf:")) != -1) {
      switch(c) {
       case 'v':
    version();
    break;
       case 'f':
    configfile = optarg;
    break;
   case 'd':
    debug = 1;
    break;
       case '?':
    usage();
      }
 }
 if(configfile == ((void *)0)) {
  if(debug) { if(3 == 3) { fprintf(stderr,"You need to specify a configuration file\n"); } else { printf("You need to specify a configuration file\n"); } } else { syslog(3,"You need to specify a configuration file\n"); };
  usage();
 }
 if(!debug) {
  openlog(argv[0], 0x01|0x02, (3<<3));
 }
 if(debug) { if(6 == 3) { fprintf(stderr,"----- racker is starting -----"); } else { printf("----- racker is starting -----"); } } else { syslog(6,"----- racker is starting -----"); };
 struct config_t *cfg = config_initialize(configfile);
 config_other(cfg);
 if(!debug) {
  daemonize();
 }
 signal(15,sig_handler);
 config_listeners(cfg);
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types:
configfile
char *

variable_types:
optarg
char *

variable_types: struct config_t { struct config_setting_t { char *name; short type; short format; union config_value_t { int ival; long long llval; double fval; char *sval; struct config_list_t { unsigned int length; struct config_setting_t **elements; } *list; } value; struct config_setting_t *parent; struct config_t *config; void *hook; unsigned int line; char *file; } *root; void (*destructor)(void *); int options; unsigned short tab_width; short default_format; char *include_dir; char *error_text; char *error_file; int error_line; enum config_error_t { CONFIG_ERR_NONE=0, CONFIG_ERR_FILE_IO=1, CONFIG_ERR_PARSE=2 } error_type; char **filenames; unsigned int num_filenames; } *

user_defined_types: struct config_t { struct config_setting_t *root; void (*destructor)(void *); int options; unsigned short tab_width; short default_format; char *include_dir; char *error_text; char *error_file; int error_line; enum config_error_t error_type; char **filenames; unsigned int num_filenames; }

user_defined_types: struct config_setting_t { char *name; short type; short format; union config_value_t value; struct config_setting_t *parent; struct config_t *config; void *hook; unsigned int line; char *file; }

user_defined_types: union config_value_t { int ival; long long llval; double fval; char *sval; struct config_list_t *list; }


decompiled_code:
__int64 __fastcall bind4(char *cp, __int16 a2)
{
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-18h] BYREF

v4.sa_family = 2;
*(_WORD *)v4.sa_data = _bswap_16(a2);
inet_pton(2, cp, &v4.sa_data[2]);
v2 = socket(2, 2, 0);
if ( bind(v2, &v4, 0x10u) == -1 )
{
if ( debug )
fwrite("couldn't bind to interface", 1uLL, 0x1AuLL, stderr);
else
syslog(3, "couldn't bind to interface");
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *cp, __int16 a2)
{
unsigned int v2; // ebx
struct sockaddr v4; // [rsp+0h] [rbp-18h] BYREF

v4.sa_family = 2;
*(_WORD *)v4.sa_data = func0(a2);
inet_pton(2, cp, &v4.sa_data[2]);
v2 = socket(2, 2, 0);
if ( bind(v2, &v4, 0x10u) == -1 )
{
if ( debug )
fwrite("couldn't bind to interface", 1uLL, 0x1AuLL, stderr);
else
syslog(3, "couldn't bind to interface");
}
return v2;
}

original_code:
int bind4(const char* host, int port) {
 struct sockaddr_in ip4addr;
 int s;
 ip4addr.sin_family = 2;
 ip4addr.sin_port = htons(port);
 inet_pton(2, host, &ip4addr.sin_addr);
 s = socket(2, SOCK_DGRAM, 0);
 if(bind(s, (struct sockaddr*)&ip4addr, sizeof ip4addr) == -1) {
  if(debug) { if(3 == 3) { fprintf(stderr,"couldn't bind to interface"); } else { printf("couldn't bind to interface"); } } else { syslog(3,"couldn't bind to interface"); };
 }
 return s;
}

canonical_original_code:
int bind4(char *host, int port) {
 struct sockaddr_in ip4addr;
 int s;
 ip4addr.sin_family = 2;
 ip4addr.sin_port = htons(port);
 inet_pton(2, host, &ip4addr.sin_addr);
 s = socket(2, SOCK_DGRAM, 0);
 if(bind(s, (struct sockaddr *)&ip4addr, sizeof ip4addr) == -1) {
  if(debug) { if(3 == 3) { fprintf(stderr,"couldn't bind to interface"); } else { printf("couldn't bind to interface"); } } else { syslog(3,"couldn't bind to interface"); };
 }
 return s;
}

variable_types:
host
char *

variable_types: port 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: s int

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

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


decompiled_code:
__int64 __fastcall bind6(char *cp, __int16 a2)
{
unsigned int v2; // ebx
struct sockaddr v4[2]; // [rsp+0h] [rbp-28h] BYREF

v4[0].sa_family = 10;
*(_WORD *)v4[0].sa_data = _bswap_16(a2);
inet_pton(10, cp, &v4[0].sa_data[6]);
v2 = socket(10, 2, 0);
if ( bind(v2, v4, 0x1Cu) == -1 )
{
if ( debug )
fwrite("couldn't bind to interface", 1uLL, 0x1AuLL, stderr);
else
syslog(3, "couldn't bind to interface");
}
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func4(char *cp, __int16 a2)
{
unsigned int v2; // ebx
struct sockaddr v4[2]; // [rsp+0h] [rbp-28h] BYREF

v4[0].sa_family = 10;
*(_WORD *)v4[0].sa_data = func0(a2);
inet_pton(10, cp, &v4[0].sa_data[6]);
v2 = socket(10, 2, 0);
if ( bind(v2, v4, 0x1Cu) == -1 )
{
if ( debug )
fwrite("couldn't bind to interface", 1uLL, 0x1AuLL, stderr);
else
syslog(3, "couldn't bind to interface");
}
return v2;
}

original_code:
int bind6(const char* host, int port) {
 struct sockaddr_in6 ip6addr;
 int s;
 ip6addr.sin6_family = 10;
 ip6addr.sin6_port = htons(port);
 inet_pton(10, host, &ip6addr.sin6_addr);
 s = socket(10, SOCK_DGRAM, 0);
 if(bind(s, (struct sockaddr*)&ip6addr, sizeof ip6addr) == -1) {
  if(debug) { if(3 == 3) { fprintf(stderr,"couldn't bind to interface"); } else { printf("couldn't bind to interface"); } } else { syslog(3,"couldn't bind to interface"); };
 }
 return s;
}

canonical_original_code:
int bind6(char *host, int port) {
 struct sockaddr_in6 ip6addr;
 int s;
 ip6addr.sin6_family = 10;
 ip6addr.sin6_port = htons(port);
 inet_pton(10, host, &ip6addr.sin6_addr);
 s = socket(10, SOCK_DGRAM, 0);
 if(bind(s, (struct sockaddr *)&ip6addr, sizeof ip6addr) == -1) {
  if(debug) { if(3 == 3) { fprintf(stderr,"couldn't bind to interface"); } else { printf("couldn't bind to interface"); } } else { syslog(3,"couldn't bind to interface"); };
 }
 return s;
}

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; }

user_defined_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr sin6_addr; unsigned int sin6_scope_id; }


decompiled_code:
__int64 pack_announce4()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func5()
{
return 0LL;
}

original_code:
char* pack_announce4(int *msgLen, struct bt_announce4_reply *reply) {
 return ((void *)0);
}

canonical_original_code:
char *pack_announce4(int *msgLen, struct bt_announce4_reply *reply) {
 return ((void *)0);
}

variable_types:
msgLen
int *

variable_types: struct bt_announce4_reply { int action; int transaction_id; int interval; int leechers; int seeders; struct bt_peer4 { unsigned int ipv4; unsigned short port; struct bt_peer4 *next; } *list; } *

user_defined_types: struct bt_announce4_reply { int action; int transaction_id; int interval; int leechers; int seeders; struct bt_peer4 *list; }


decompiled_code:
void __fastcall send_receive(int fd)
{
void *v1; // rsp
unsigned int v2; // ebx
_DWORD *v3; // r12
int v4; // eax
__m128i *v5; // r15
void *v6; // r14
__m128i *v7; // rbx
__m128i *v8; // r14
__m128i v9; // [rsp+0h] [rbp-50h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-40h] BYREF

v1 = alloca(mtu);
memset(&v9, 0, mtu);
*_errno_location() = 0;
v9.m128i_i32[3] = 16;
v2 = recvfrom(fd, &v9, mtu, 0, &addr, &v9.m128i_u32[3]);
if ( v2 == -1 )
perror("couldn't receive data");
if ( debug )
printf("Received %d Bytes of Data\n", v2);
else
syslog(7, "Received %d Bytes of Data\n", v2);
v3 = unpack_connect(v2, (unsigned __int64 *)&v9);
v4 = v3[2];
if ( v4 == 2 )
{
puts("SCRAPE");
v7 = (__m128i *)(int)scrape(&v9.m128i_u64[1], *(_QWORD *)v3, (unsigned int)v3[3], &v9, v2);
}
else
{
if ( v4 > 2 )
{
if ( v4 == 4 )
{
puts("ANNOUNCE IPv6");
v7 = (__m128i *)(int)announce6(&v9.m128i_u64[1], *(_QWORD *)v3, (unsigned int)v3[3], &v9);
goto LABEL_14;
}
}
else
{
if ( !v4 )
{
puts("CONNECT REQUEST");
v8 = (__m128i *)(int)connect_request(v3);
v7 = pack_connect(&v9.m128i_i32[2], v8);
free(v8);
goto LABEL_14;
}
if ( v4 == 1 )
{
puts("ANNOUNCE IPv4");
v5 = unpack_announce4(v2, &v9);
v6 = (void *)(int)announce4(v5);
v7 = (__m128i *)pack_announce4(&v9.m128i_u64[1], v6);
free(v5);
free(v6);
goto LABEL_14;
}
}
v7 = (__m128i *)(int)errormsg(&v9.m128i_u64[1], (unsigned int)v3[3], "Unkown action");
}
LABEL_14:
if ( sendto(fd, v7, v9.m128i_i32[2], 0, &addr, v9.m128i_u32[3]) == -1 )
{
if ( debug )
fwrite("Couldn't send Data", 1uLL, 0x12uLL, stderr);
else
syslog(3, "Couldn't send Data");
}
free(v7);
free(v3);
}

canonical_decompiled_code:
void __fastcall func6(int fd)
{
void *v1; // rsp
unsigned int v2; // ebx
_DWORD *v3; // r12
int v4; // eax
__m128i *v5; // r15
void *v6; // r14
__m128i *v7; // rbx
__m128i *v8; // r14
__m128i v9; // [rsp+0h] [rbp-50h] BYREF
struct sockaddr addr; // [rsp+10h] [rbp-40h] BYREF

v1 = alloca(mtu);
memset(&v9, 0, mtu);
*_errno_location() = 0;
v9.m128i_i32[3] = 16;
v2 = recvfrom(fd, &v9, mtu, 0, &addr, &v9.m128i_u32[3]);
if ( v2 == -1 )
perror("couldn't receive data");
if ( debug )
printf("Received %d Bytes of Data\n", v2);
else
syslog(7, "Received %d Bytes of Data\n", v2);
v3 = unpack_connect(v2, (unsigned __int64 *)&v9);
v4 = v3[2];
if ( v4 == 2 )
{
puts("SCRAPE");
v7 = (__m128i *)(int)scrape(&v9.m128i_u64[1], *(_QWORD *)v3, (unsigned int)v3[3], &v9, v2);
}
else
{
if ( v4 > 2 )
{
if ( v4 == 4 )
{
puts("ANNOUNCE IPv6");
v7 = (__m128i *)(int)announce6(&v9.m128i_u64[1], *(_QWORD *)v3, (unsigned int)v3[3], &v9);
goto LABEL_14;
}
}
else
{
if ( !v4 )
{
puts("CONNECT REQUEST");
v8 = (__m128i *)(int)connect_request(v3);
v7 = pack_connect(&v9.m128i_i32[2], v8);
free(v8);
goto LABEL_14;
}
if ( v4 == 1 )
{
puts("ANNOUNCE IPv4");
v5 = unpack_announce4(v2, &v9);
v6 = (void *)(int)announce4(v5);
v7 = (__m128i *)func5(&v9.m128i_u64[1], v6);
free(v5);
free(v6);
goto LABEL_14;
}
}
v7 = (__m128i *)(int)errormsg(&v9.m128i_u64[1], (unsigned int)v3[3], "Unkown action");
}
LABEL_14:
if ( sendto(fd, v7, v9.m128i_i32[2], 0, &addr, v9.m128i_u32[3]) == -1 )
{
if ( debug )
fwrite("Couldn't send Data", 1uLL, 0x12uLL, stderr);
else
syslog(3, "Couldn't send Data");
}
free(v7);
free(v3);
}

original_code:
void send_receive(int sock) {
 char msg[mtu], *sbuffer;
 struct sockaddr_in cliAddr;
 int cliLen, msgLen, sbufLen;
 uint64_t connection_id;
 int32_t action;
 uint32_t transaction_id;
 memset(msg,0x0,mtu);
 (*__errno_location ()) = 0;
 cliLen = sizeof(struct sockaddr_in);
 msgLen = recvfrom(sock, msg, mtu, 0, (struct sockaddr *) &cliAddr, &cliLen);
 if(msgLen == -1) {
  perror("couldn't receive data");
 }
 if(debug) { if(7 == 3) { fprintf(stderr,"Received %d Bytes of Data\n",msgLen); } else { printf("Received %d Bytes of Data\n",msgLen); } } else { syslog(7,"Received %d Bytes of Data\n",msgLen); };
 struct bt_connect_request *request = unpack_connect(msgLen,msg);
 switch(request->action) {
  case 0:
   printf("CONNECT REQUEST\n");
   struct bt_connect_reply *reply_connect = (struct bt_connect_reply*) connect_request(request);
   sbuffer = (char*) pack_connect(&sbufLen,reply_connect);
   free(reply_connect);
   break;
  case 1:
   printf("ANNOUNCE IPv4\n");
   struct bt_announce4_request *request_announce4 = (struct bt_announce4_request*) unpack_announce4(msgLen,msg);
   struct bt_announce4_reply *reply_announce4 = (struct bt_announce4_reply*) announce4(request_announce4);
   sbuffer = (char*) pack_announce4(&sbufLen, reply_announce4);
   free(request_announce4);
   free(reply_announce4);
   break;
  case 2:
   printf("SCRAPE\n");
   sbuffer = (char*)scrape(&sbufLen,request->connection_id,request->transaction_id,msg,msgLen);
   break;
  case 4:
   printf("ANNOUNCE IPv6\n");
   sbuffer = (char*)announce6(&sbufLen,request->connection_id,request->transaction_id,msg);
   break;
  default:
   sbuffer = (char*)errormsg(&sbufLen,request->transaction_id,"Unkown action");
 }
 if(sendto(sock,sbuffer,sbufLen,0,(struct sockaddr*) &cliAddr,(socklen_t) cliLen) == -1) {
  if(debug) { if(3 == 3) { fprintf(stderr,"Couldn't send Data"); } else { printf("Couldn't send Data"); } } else { syslog(3,"Couldn't send Data"); };
 }
 free(sbuffer);
 free(request);
}

canonical_original_code:
void send_receive(int sock) {
 char msg[-1]; char *sbuffer;
 struct sockaddr_in cliAddr;
 int cliLen; int msgLen; int sbufLen;
 unsigned long connection_id;
 int action;
 unsigned int transaction_id;
 memset(msg,0x0,mtu);
 (*__errno_location ()) = 0;
 cliLen = sizeof(struct sockaddr_in);
 msgLen = recvfrom(sock, msg, mtu, 0, (struct sockaddr *) &cliAddr, &cliLen);
 if(msgLen == -1) {
  perror("couldn't receive data");
 }
 if(debug) { if(7 == 3) { fprintf(stderr,"Received %d Bytes of Data\n",msgLen); } else { printf("Received %d Bytes of Data\n",msgLen); } } else { syslog(7,"Received %d Bytes of Data\n",msgLen); };
 struct bt_connect_request *request = unpack_connect(msgLen,msg);
 switch(request->action) {
  case 0:
   printf("CONNECT REQUEST\n");
   struct bt_connect_reply *reply_connect = (struct bt_connect_reply*) connect_request(request);
   sbuffer = (char *) pack_connect(&sbufLen,reply_connect);
   free(reply_connect);
   break;
  case 1:
   printf("ANNOUNCE IPv4\n");
   struct bt_announce4_request *request_announce4 = (struct bt_announce4_request*) unpack_announce4(msgLen,msg);
   struct bt_announce4_reply *reply_announce4 = (struct bt_announce4_reply*) announce4(request_announce4);
   sbuffer = (char *) pack_announce4(&sbufLen, reply_announce4);
   free(request_announce4);
   free(reply_announce4);
   break;
  case 2:
   printf("SCRAPE\n");
   sbuffer = (char *)scrape(&sbufLen,request->connection_id,request->transaction_id,msg,msgLen);
   break;
  case 4:
   printf("ANNOUNCE IPv6\n");
   sbuffer = (char *)announce6(&sbufLen,request->connection_id,request->transaction_id,msg);
   break;
  default:
   sbuffer = (char *)errormsg(&sbufLen,request->transaction_id,"Unkown action");
 }
 if(sendto(sock,sbuffer,sbufLen,0,(struct sockaddr *) &cliAddr,(unsigned int) cliLen) == -1) {
  if(debug) { if(3 == 3) { fprintf(stderr,"Couldn't send Data"); } else { printf("Couldn't send Data"); } } else { syslog(3,"Couldn't send Data"); };
 }
 free(sbuffer);
 free(request);
}

variable_types: sock int

variable_types:
msg
char [-1]

variable_types:
sbuffer
char *

variable_types: cliLen int

variable_types: msgLen int

variable_types: sbufLen int

variable_types: action int

variable_types: struct bt_connect_request { long connection_id; int action; int transaction_id; } *

variable_types: struct bt_connect_reply { int action; int transaction_id; long connection_id; } *

variable_types: struct bt_announce4_request { long connection_id; int action; int transaction_id; char info_hash[20]; char peer_id[20]; long downloaded; long left; long uploaded; int event; unsigned int ip; unsigned int key; int num_want; unsigned short port; unsigned short extensions; } *

user_defined_types: struct bt_peer4 { unsigned int ipv4; unsigned short port; struct bt_peer4 *next; }


decompiled_code:
void __noreturn check_readable_socket()
{
int v0; // edi
int *v1; // rdx
__int64 v2; // r8
int v3; // eax
__int64 v4; // rbp
unsigned __int64 v5; // r13
int v6; // edi
fd_set v7; // [rsp+0h] [rbp-A8h] BYREF

while ( 1 )
{
memset(&v7, 0, sizeof(v7));
v0 = num_sockets;
if ( num_sockets )
{
v1 = (int *)(sockets + 4LL * (num_sockets - 1));
v2 = (__int64)&v1[-(num_sockets - 1) - 1];
v0 = 0;
do
{
v3 = *v1 + 63;
if ( *v1 >= 0 )
v3 = *v1;
v7.fds_bits[v3 >> 6] |= 1LL << (*v1 % 64);
if ( v0 < *v1 )
v0 = *v1;
--v1;
}
while ( v1 != (int *)v2 );
}
select(v0 + 1, &v7, 0LL, 0LL, 0LL);
if ( num_sockets )
{
v4 = 4LL * (num_sockets - 1);
v5 = 4 * (num_sockets - (unsigned __int64)(unsigned int)(num_sockets - 1)) - 8;
do
{
v6 = *(_DWORD *)(sockets + v4);
if ( (v7.fds_bits[v6 / 64] & (1LL << (v6 % 64))) != 0 )
send_receive(v6);
v4 -= 4LL;
}
while ( v4 != v5 );
}
}
}

canonical_decompiled_code:
void __noreturn func7()
{
int v0; // edi
int *v1; // rdx
__int64 v2; // r8
int v3; // eax
__int64 v4; // rbp
unsigned __int64 v5; // r13
int v6; // edi
fd_set v7; // [rsp+0h] [rbp-A8h] BYREF

while ( 1 )
{
memset(&v7, 0, sizeof(v7));
v0 = num_sockets;
if ( num_sockets )
{
v1 = (int *)(sockets + 4LL * (num_sockets - 1));
v2 = (__int64)&v1[-(num_sockets - 1) - 1];
v0 = 0;
do
{
v3 = *v1 + 63;
if ( *v1 >= 0 )
v3 = *v1;
v7.fds_bits[v3 >> 6] |= 1LL << (*v1 % 64);
if ( v0 < *v1 )
v0 = *v1;
--v1;
}
while ( v1 != (int *)v2 );
}
select(v0 + 1, &v7, 0LL, 0LL, 0LL);
if ( num_sockets )
{
v4 = 4LL * (num_sockets - 1);
v5 = 4 * (num_sockets - (unsigned __int64)(unsigned int)(num_sockets - 1)) - 8;
do
{
v6 = *(_DWORD *)(sockets + v4);
if ( (v7.fds_bits[v6 / 64] & (1LL << (v6 % 64))) != 0 )
func6(v6);
v4 -= 4LL;
}
while ( v4 != v5 );
}
}
}

original_code:
void check_readable_socket() {
 fd_set fds;
 int numfds, maxfd;
 while(1) {
  do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  numfds = num_sockets;
  maxfd = 0;
  while(numfds--) {
   ((void) (((&fds)->__fds_bits)[((sockets[numfds]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockets[numfds]) % (8 * (int) sizeof (__fd_mask)))))));
   if(sockets[numfds] > maxfd) {
    maxfd = sockets[numfds];
   }
  }
  select(maxfd+1,&fds,((void *)0),((void *)0),((void *)0));
  numfds = num_sockets;
  while(numfds--) {
   if(((((&fds)->__fds_bits)[((sockets[numfds]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockets[numfds]) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    send_receive(sockets[numfds]);
   }
  }
 }
}

canonical_original_code:
void check_readable_socket() {
 struct fd_set fds;
 int numfds; int maxfd;
 while(1) {
  do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&fds)->__fds_bits)[0]) : "memory"); } while (0);
  numfds = num_sockets;
  maxfd = 0;
  while(numfds--) {
   ((void) (((&fds)->__fds_bits)[((sockets[numfds]) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sockets[numfds]) % (8 * (int) sizeof (__fd_mask)))))));
   if(sockets[numfds] > maxfd) {
    maxfd = sockets[numfds];
   }
  }
  select(maxfd+1,&fds,((void *)0),((void *)0),((void *)0));
  numfds = num_sockets;
  while(numfds--) {
   if(((((&fds)->__fds_bits)[((sockets[numfds]) / (8 * (int) sizeof (__fd_mask)))] & ((__fd_mask) (1UL << ((sockets[numfds]) % (8 * (int) sizeof (__fd_mask)))))) != 0)) {
    send_receive(sockets[numfds]);
   }
  }
 }
}

variable_types:
fds
struct fd_set { long __fds_bits[-1]; }

variable_types: numfds int

variable_types: maxfd int


decompiled_code:
__int64 announce4()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func1()
{
return 0LL;
}

original_code:
struct bt_announce4_reply* announce4(struct bt_announce4_request *request) {
 return ((void *)0);
}

canonical_original_code:
struct bt_announce4_reply *announce4(struct bt_announce4_request *request) {
 return ((void *)0);
}

return_type: struct bt_announce4_reply { int action; int transaction_id; int interval; int leechers; int seeders; struct bt_peer4 { unsigned int ipv4; unsigned short port; struct bt_peer4 *next; } *list; } *

user_defined_types: struct bt_announce4_request { long connection_id; int action; int transaction_id; char info_hash[20]; char peer_id[20]; long downloaded; long left; long uploaded; int event; unsigned int ip; unsigned int key; int num_want; unsigned short port; unsigned short extensions; }


scrape

decompiled_code:
__int64 __fastcall scrape(_DWORD *a1, __int64 a2, __int64 a3, __int64 a4, int a5)
{
unsigned int v5; // ebx

v5 = (a5 - 16) / 20;
if ( debug )
printf("Number of Requested Hashes: %u", v5);
else
syslog(7, "Number of Requested Hashes: %u", v5);
*a1 = 12 * v5 + 8;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_DWORD *a1, __int64 a2, __int64 a3, __int64 a4, int a5)
{
unsigned int v5; // ebx

v5 = (a5 - 16) / 20;
if ( debug )
printf("Number of Requested Hashes: %u", v5);
else
syslog(7, "Number of Requested Hashes: %u", v5);
*a1 = 12 * v5 + 8;
return 0LL;
}

original_code:
char* scrape(int* sbufLen,uint64_t connection_id, uint32_t transaction_id, char msg[],int msgLen) {
 int action = 2;
 int request_num;
 request_num =(msgLen-16)/20;
 if(debug) { if(7 == 3) { fprintf(stderr,"Number of Requested Hashes: %u",request_num); } else { printf("Number of Requested Hashes: %u",request_num); } } else { syslog(7,"Number of Requested Hashes: %u",request_num); };
 *sbufLen = 8+request_num*12;
 char* sbuffer = malloc(*sbufLen);
 action = __bswap_32 (action);
 transaction_id = __bswap_32 (transaction_id);
 memcpy(sbuffer,&action,4);
 memcpy(sbuffer+4,&transaction_id,4);
 return ((void *)0);
}

canonical_original_code:
char *scrape(int *sbufLen, unsigned long connection_id, unsigned int transaction_id, char msg[], int msgLen) {
 int action = 2;
 int request_num;
 request_num =(msgLen-16)/20;
 if(debug) { if(7 == 3) { fprintf(stderr,"Number of Requested Hashes: %u",request_num); } else { printf("Number of Requested Hashes: %u",request_num); } } else { syslog(7,"Number of Requested Hashes: %u",request_num); };
 *sbufLen = 8+request_num*12;
 char *sbuffer = malloc(*sbufLen);
 action = __bswap_32 (action);
 transaction_id = __bswap_32 (transaction_id);
 memcpy(sbuffer,&action,4);
 memcpy(sbuffer+4,&transaction_id,4);
 return ((void *)0);
}

variable_types:
sbufLen
int *

variable_types:
msg
char []


decompiled_code:
__int64 announce6()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func3()
{
return 0LL;
}

original_code:
char* announce6(int* sbufLen,struct sockaddr_in6 cliAddr,uint64_t connection_id, uint32_t transaction_id, char msg[]) {
 char info_hash[20], peer_id[20];
 char *info_hash_hex, *peer_id_hex,*ip=malloc(16);
 int64_t downloaded,left,uploaded;
 int32_t event,num_want,num_peers,action;
 uint32_t key, seeders, leechers;
 uint16_t port, extensions;
 memcpy(&info_hash,msg+16,20);
 memcpy(&peer_id,msg+36,20);
 memcpy(&downloaded,msg+56,8);
 memcpy(&left,msg+64,8);
 memcpy(&uploaded,msg+72,8);
 memcpy(&event,msg+80,4);
 memcpy(&ip,msg+84,16);
 memcpy(&key,msg+100,4);
 memcpy(&num_want,msg+104,4);
 memcpy(&port,msg+108,2);
 memcpy(&extensions,msg+110,2);
 if(strcmp(ip,"")==0) {
  ip = cliAddr.sin6_addr.__in6_u.__u6_addr8;
 }
 downloaded = __bswap_64 (downloaded);
 left = __bswap_64 (left);
 uploaded = __bswap_64 (uploaded);
 event = __bswap_32 (event);
 key = __bswap_32 (key);
 num_want = __bswap_32 (num_want);
 port = __bswap_16 (port);
 extensions = __bswap_16 (extensions);
 return ((void *)0);
}

canonical_original_code:
char *announce6(int *sbufLen, struct sockaddr_in6 cliAddr, unsigned long connection_id, unsigned int transaction_id, char msg[]) {
 char info_hash[20]; char peer_id[20];
 char *info_hash_hex; char *peer_id_hex; char *ip = malloc(16);
 long downloaded; long left; long uploaded;
 int event; int num_want; int num_peers; int action;
 unsigned int key; unsigned int seeders; unsigned int leechers;
 unsigned short port; unsigned short extensions;
 memcpy(&info_hash,msg+16,20);
 memcpy(&peer_id,msg+36,20);
 memcpy(&downloaded,msg+56,8);
 memcpy(&left,msg+64,8);
 memcpy(&uploaded,msg+72,8);
 memcpy(&event,msg+80,4);
 memcpy(&ip,msg+84,16);
 memcpy(&key,msg+100,4);
 memcpy(&num_want,msg+104,4);
 memcpy(&port,msg+108,2);
 memcpy(&extensions,msg+110,2);
 if(strcmp(ip,"")==0) {
  ip = cliAddr.sin6_addr.__in6_u.__u6_addr8;
 }
 downloaded = __bswap_64 (downloaded);
 left = __bswap_64 (left);
 uploaded = __bswap_64 (uploaded);
 event = __bswap_32 (event);
 key = __bswap_32 (key);
 num_want = __bswap_32 (num_want);
 port = __bswap_16 (port);
 extensions = __bswap_16 (extensions);
 return ((void *)0);
}

variable_types: struct sockaddr_in6 { unsigned short sin6_family; unsigned short sin6_port; unsigned int sin6_flowinfo; struct in6_addr { union { unsigned char __u6_addr8[16]; unsigned short __u6_addr16[8]; unsigned int __u6_addr32[4]; } __in6_u; } sin6_addr; unsigned int sin6_scope_id; }

variable_types:
ip
char *

variable_types: downloaded long

variable_types: left long

variable_types: uploaded long

variable_types: event int

variable_types:
key
unsigned int

variable_types:
seeders
unsigned int

variable_types:
leechers
unsigned int

variable_types:
port
unsigned short

variable_types:
extensions
unsigned short


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

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

original_code:
void bt_free_node(struct bt_node *node) {
 free(node);
}

variable_types: struct bt_node { void *data; struct bt_node *left; } *


original_code:
void bt_delete(struct bt_node **node) {
 struct bt_node *old_node = *node;
 if((*node)->left == ((void *)0) && (*node)->right == ((void *)0)) {
  bt_free_node(old_node);
  return;
 }
 if((*node)->left == ((void *)0)) {
  *node = (*node)->right;
  bt_free_node(old_node);
  return;
 } else if((*node)->right == ((void *)0)) {
  *node = (*node)->left;
  bt_free_node(old_node);
  return;
 }
 struct bt_node **pred = &(*node)->left;
 while((*pred)->right != ((void *)0)) {
  pred = &(*pred)->right;
 }
 void *tmp = (*node)->data;
 (*node)->data = (*pred)->data;
 (*pred)->data = tmp;
 bt_delete(pred);
}

variable_types: struct bt_node { void *data; struct bt_node *left; } **

variable_types:
tmp
void *


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

v1 = (const char **)malloc(0x48uLL);
v2 = v1;
if ( v1 )
{
config_init(v1);
if ( !(unsigned int)config_read_file(v2, a1) )
{
if ( debug )
fprintf(stderr, "%s on line %d\n", v2[4], *((unsigned int *)v2 + 12));
else
syslog(3, "%s on line %d\n", v2[4], *((unsigned int *)v2 + 12));
config_destroy(v2);
exit(1);
}
}
return v2;
}

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

v1 = (const char **)malloc(0x48uLL);
v2 = v1;
if ( v1 )
{
config_init(v1);
if ( !(unsigned int)config_read_file(v2, a1) )
{
if ( debug )
fprintf(stderr, "%s on line %d\n", v2[4], *((unsigned int *)v2 + 12));
else
syslog(3, "%s on line %d\n", v2[4], *((unsigned int *)v2 + 12));
config_destroy(v2);
exit(1);
}
}
return v2;
}

original_code:
config_t* config_initialize(char* filename) {
 config_t *config = malloc(sizeof(config_t));
 if(config != ((void *)0)) {
  config_init(config);
  if(config_read_file(config,filename) == (0)) {
   if(debug) { if(3 == 3) { fprintf(stderr,"%s on line %d\n",((config)->error_text),((config)->error_line)); } else { printf("%s on line %d\n",((config)->error_text),((config)->error_line)); } } else { syslog(3,"%s on line %d\n",((config)->error_text),((config)->error_line)); };
   config_destroy(config);
   exit(1);
  }
 }
 return config;
}

canonical_original_code:
struct config_t *config_initialize(char *filename) {
 struct config_t *config = malloc(sizeof(config_t));
 if(config != ((void *)0)) {
  config_init(config);
  if(config_read_file(config,filename) == (0)) {
   if(debug) { if(3 == 3) { fprintf(stderr,"%s on line %d\n",((config)->error_text),((config)->error_line)); } else { printf("%s on line %d\n",((config)->error_text),((config)->error_line)); } } else { syslog(3,"%s on line %d\n",((config)->error_text),((config)->error_line)); };
   config_destroy(config);
   exit(1);
  }
 }
 return config;
}

variable_types:
filename
char *

variable_types: struct config_t { struct config_setting_t { char *name; short type; short format; union config_value_t { int ival; long long llval; double fval; char *sval; struct config_list_t { unsigned int length; struct config_setting_t **elements; } *list; } value; struct config_setting_t *parent; struct config_t *config; void *hook; unsigned int line; char *file; } *root; void (*destructor)(void *); int options; unsigned short tab_width; short default_format; char *include_dir; char *error_text; char *error_file; int error_line; enum config_error_t { CONFIG_ERR_NONE=0, CONFIG_ERR_FILE_IO=1, CONFIG_ERR_PARSE=2 } error_type; char **filenames; unsigned int num_filenames; } *


decompiled_code:
__int64 __fastcall config_listeners(__int64 a1)
{
int v1; // er13
__int64 v2; // r12
int v3; // ebx
unsigned int v4; // ebp
__int64 v6; // rbx
bool v7; // al
bool v8; // cf
bool v9; // zf
const char *v10; // rdi
__int64 v11; // rcx
const char *v12; // rsi
unsigned int v13; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v14; // [rsp+10h] [rbp-38h] BYREF
const char *v15; // [rsp+18h] [rbp-30h] BYREF

v2 = config_lookup(a1, "interfaces");
if ( !v2 )
{
if ( debug )
fwrite("Couldn't read Interfaces\n", 1uLL, 0x19uLL, stderr);
else
syslog(3, "Couldn't read Interfaces\n");
}
v3 = config_setting_length(v2);
sockets = (__int64)malloc(4LL * v3);
num_sockets = 0;
v4 = v3 - 1;
if ( v3 )
{
while ( 1 )
{
v6 = config_setting_get_elem(v2, v4);
if ( (unsigned int)config_setting_lookup_string(v6, "type", &v15)
&& (unsigned int)config_setting_lookup_string(v6, "hostname", &v14)
&& (unsigned int)config_setting_lookup_int(v6, "port", &v13) )
{
v7 = strcmp(v15, "IPv4") != 0;
v8 = 0;
v9 = !v7;
if ( v7 )
{
v10 = "IPv6";
v11 = 5LL;
v12 = v15;
do
{
if ( !v11 )
break;
v8 = *v12 < (unsigned int)*v10;
v9 = *v12++ == *v10++;
--v11;
}
while ( v9 );
if ( (!v8 && !v9) == v8 )
v1 = bind6(v14, v13, v15, v11);
}
else
{
v1 = bind4(v14, v13);
}
*(_DWORD *)(sockets + 4LL * num_sockets++) = v1;
}
if ( !v4 )
break;
--v4;
}
}
return check_readable_socket();
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
int v1; // er13
__int64 v2; // r12
int v3; // ebx
unsigned int v4; // ebp
__int64 v6; // rbx
bool v7; // al
bool v8; // cf
bool v9; // zf
const char *v10; // rdi
__int64 v11; // rcx
const char *v12; // rsi
unsigned int v13; // [rsp+Ch] [rbp-3Ch] BYREF
__int64 v14; // [rsp+10h] [rbp-38h] BYREF
const char *v15; // [rsp+18h] [rbp-30h] BYREF

v2 = config_lookup(a1, "interfaces");
if ( !v2 )
{
if ( debug )
fwrite("Couldn't read Interfaces\n", 1uLL, 0x19uLL, stderr);
else
syslog(3, "Couldn't read Interfaces\n");
}
v3 = config_setting_length(v2);
sockets = (__int64)malloc(4LL * v3);
num_sockets = 0;
v4 = v3 - 1;
if ( v3 )
{
while ( 1 )
{
v6 = config_setting_get_elem(v2, v4);
if ( (unsigned int)config_setting_lookup_string(v6, "type", &v15)
&& (unsigned int)config_setting_lookup_string(v6, "hostname", &v14)
&& (unsigned int)config_setting_lookup_int(v6, "port", &v13) )
{
v7 = strcmp(v15, "IPv4") != 0;
v8 = 0;
v9 = !v7;
if ( v7 )
{
v10 = "IPv6";
v11 = 5LL;
v12 = v15;
do
{
if ( !v11 )
break;
v8 = *v12 < (unsigned int)*v10;
v9 = *v12++ == *v10++;
--v11;
}
while ( v9 );
if ( (!v8 && !v9) == v8 )
v1 = bind6(v14, v13, v15, v11);
}
else
{
v1 = bind4(v14, v13);
}
*(_DWORD *)(sockets + 4LL * num_sockets++) = v1;
}
if ( !v4 )
break;
--v4;
}
}
return check_readable_socket();
}

original_code:
void config_listeners(config_t *config) {
 config_setting_t *interfaces,*interface;
 const char *type,*hostname;
 int portnr, interface_num, sock;
 if((interfaces = config_lookup(config,"interfaces")) == ((void *)0)) {
  if(debug) { if(3 == 3) { fprintf(stderr,"Couldn't read Interfaces\n"); } else { printf("Couldn't read Interfaces\n"); } } else { syslog(3,"Couldn't read Interfaces\n"); };
 }
 interface_num = config_setting_length(interfaces);
 sockets = malloc(sizeof(int)*interface_num);
 num_sockets = 0;
 while(interface_num--) {
  interface = config_setting_get_elem(interfaces,interface_num);
  if(!(config_setting_lookup_string(interface,"type",&type) &&
  config_setting_lookup_string(interface,"hostname",&hostname) &&
  config_setting_lookup_int(interface,"port",(long*) &portnr))) {
   continue;
  }
  if(strcmp(type,"IPv4") == 0) {
   sock = bind4(hostname,portnr);
  } else if(strcmp(type,"IPv6") == 0) {
   sock = bind6(hostname,portnr);
  }
  sockets[num_sockets] = sock;
  num_sockets++;
 }
 check_readable_socket();
}

canonical_original_code:
void config_listeners(struct config_t *config) {
 struct config_setting_t *interfaces; struct config_setting_t *interface;
 char *type; char *hostname;
 int portnr; int interface_num; int sock;
 if((interfaces = config_lookup(config,"interfaces")) == ((void *)0)) {
  if(debug) { if(3 == 3) { fprintf(stderr,"Couldn't read Interfaces\n"); } else { printf("Couldn't read Interfaces\n"); } } else { syslog(3,"Couldn't read Interfaces\n"); };
 }
 interface_num = config_setting_length(interfaces);
 sockets = malloc(sizeof(int)*interface_num);
 num_sockets = 0;
 while(interface_num--) {
  interface = config_setting_get_elem(interfaces,interface_num);
  if(!(config_setting_lookup_string(interface,"type",&type) &&
  config_setting_lookup_string(interface,"hostname",&hostname) &&
  config_setting_lookup_int(interface,"port",(long *) &portnr))) {
   continue;
  }
  if(strcmp(type,"IPv4") == 0) {
   sock = bind4(hostname,portnr);
  } else if(strcmp(type,"IPv6") == 0) {
   sock = bind6(hostname,portnr);
  }
  sockets[num_sockets] = sock;
  num_sockets++;
 }
 check_readable_socket();
}

variable_types: struct config_setting_t { char *name; short type; short format; union config_value_t { int ival; long long llval; double fval; char *sval; struct config_list_t { unsigned int length; struct config_setting_t **elements; } *list; } value; struct config_setting_t *parent; struct config_t { struct config_setting_t *root; void (*destructor)(void *); int options; unsigned short tab_width; short default_format; char *include_dir; char *error_text; char *error_file; int error_line; enum config_error_t { CONFIG_ERR_NONE=0, CONFIG_ERR_FILE_IO=1, CONFIG_ERR_PARSE=2 } error_type; char **filenames; unsigned int num_filenames; } *config; void *hook; unsigned int line; char *file; } *

variable_types:
type
char *

variable_types:
hostname
char *

variable_types: portnr int

variable_types: sock int


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

if ( !(unsigned int)config_lookup_int(a1, "others.interval", &interval)
|| !(unsigned int)config_lookup_int(a1, "others.mtu", &mtu)
|| !(unsigned int)config_lookup_string(a1, "others.user", &user)
|| (result = config_lookup_string(a1, "others.pidfile", &pidfile), !(_DWORD)result) )
{
if ( debug )
fwrite(aCouldnTReadMis, 1uLL, 0x2EuLL, stderr);
else
syslog(3, aCouldnTReadMis);
exit(1);
}
return result;
}

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

if ( !(unsigned int)config_lookup_int(a1, "others.interval", &interval)
|| !(unsigned int)config_lookup_int(a1, "others.mtu", &mtu)
|| !(unsigned int)config_lookup_string(a1, "others.user", &user)
|| (result = config_lookup_string(a1, "others.pidfile", &pidfile), !(_DWORD)result) )
{
if ( debug )
fwrite(aCouldnTReadMis, 1uLL, 0x2EuLL, stderr);
else
syslog(3, aCouldnTReadMis);
exit(1);
}
return result;
}

original_code:
void config_other(config_t *config) {
 if(!(config_lookup_int(config,"others.interval",(long*)&interval) &&
 config_lookup_int(config,"others.mtu",(long*)&mtu) &&
 config_lookup_string(config,"others.user",&user) &&
 config_lookup_string(config,"others.pidfile",&pidfile))) {
  if(debug) { if(3 == 3) { fprintf(stderr,"couldn't read miscoptions from config file\n"); } else { printf("couldn't read miscoptions from config file\n"); } } else { syslog(3,"couldn't read miscoptions from config file\n"); };
  exit(1);
 }
}

canonical_original_code:
void config_other(struct config_t *config) {
 if(!(config_lookup_int(config,"others.interval",(long *)&interval) &&
 config_lookup_int(config,"others.mtu",(long *)&mtu) &&
 config_lookup_string(config,"others.user",&user) &&
 config_lookup_string(config,"others.pidfile",&pidfile))) {
  if(debug) { if(3 == 3) { fprintf(stderr,"couldn't read miscoptions from config file\n"); } else { printf("couldn't read miscoptions from config file\n"); } } else { syslog(3,"couldn't read miscoptions from config file\n"); };
  exit(1);
 }
}

user_defined_types: enum config_error_t { CONFIG_ERR_NONE=0, CONFIG_ERR_FILE_IO=1, CONFIG_ERR_PARSE=2 }

user_defined_types: struct config_list_t { unsigned int length; struct config_setting_t **elements; }


decompiled_code:
__int64 generate_connection_id()
{
unsigned int v0; // eax
__int64 v2; // [rsp+8h] [rbp-10h]

v0 = time(0LL);
srand(v0);
LODWORD(v2) = rand();
HIDWORD(v2) = rand();
return v2;
}

canonical_decompiled_code:
__int64 func0()
{
unsigned int v0; // eax
__int64 v2; // [rsp+8h] [rbp-10h]

v0 = time(0LL);
srand(v0);
LODWORD(v2) = rand();
HIDWORD(v2) = rand();
return v2;
}

original_code:
uint64_t generate_connection_id() {
        uint64_t connection_id;
        uint32_t tmp;
        srand((unsigned) time(((void *)0)));
        tmp = rand();
        memcpy(&connection_id,&tmp,4);
        tmp = rand();
        memcpy(((char*)(&connection_id))+4,&tmp,4);
        return connection_id;
}

canonical_original_code:
unsigned long generate_connection_id() {
        unsigned long connection_id;
        unsigned int tmp;
        srand((unsigned int) time(((void *)0)));
        tmp = rand();
        memcpy(&connection_id,&tmp,4);
        tmp = rand();
        memcpy(((char *)(&connection_id))+4,&tmp,4);
        return connection_id;
}

variable_types:
tmp
unsigned int

return_type: unsigned long


decompiled_code:
__int64 sig_handler()
{
int v0; // edx
__int64 result; // rax
int v2; // edx

if ( debug )
printf("----- racker is stopping -----");
else
syslog(6, "----- racker is stopping -----");
if ( !debug )
closelog();
v0 = num_sockets;
result = (unsigned int)--num_sockets;
if ( v0 )
{
do
{
shutdown(*(_DWORD *)(sockets + 4LL * (int)result), 2);
v2 = num_sockets;
result = (unsigned int)--num_sockets;
}
while ( v2 );
}
return result;
}

canonical_decompiled_code:
__int64 func2()
{
int v0; // edx
__int64 result; // rax
int v2; // edx

if ( debug )
printf("----- racker is stopping -----");
else
syslog(6, "----- racker is stopping -----");
if ( !debug )
closelog();
v0 = num_sockets;
result = (unsigned int)--num_sockets;
if ( v0 )
{
do
{
shutdown(*(_DWORD *)(sockets + 4LL * (int)result), 2);
v2 = num_sockets;
result = (unsigned int)--num_sockets;
}
while ( v2 );
}
return result;
}

original_code:
void sig_handler(int signal) {
 if(debug) { if(6 == 3) { fprintf(stderr,"----- racker is stopping -----"); } else { printf("----- racker is stopping -----"); } } else { syslog(6,"----- racker is stopping -----"); };
 if(!debug) {
  closelog();
 }
 while(num_sockets--) {
  shutdown(sockets[num_sockets],2);
 }
}

variable_types: signal int


decompiled_code:
void __fastcall drop_root_rights(const char *a1)
{
struct passwd *v1; // rax

v1 = getpwnam(a1);
setuid(v1->pw_uid);
if ( debug )
printf("Changed executing User to %s", a1);
else
syslog(7, "Changed executing User to %s", a1);
}

canonical_decompiled_code:
void __fastcall func4(const char *a1)
{
struct passwd *v1; // rax

v1 = getpwnam(a1);
setuid(v1->pw_uid);
if ( debug )
printf("Changed executing User to %s", a1);
else
syslog(7, "Changed executing User to %s", a1);
}

original_code:
void drop_root_rights(char* username) {
        struct passwd *user;
        user = getpwnam(username);
        setuid(user->pw_uid);
        if(debug) { if(7 == 3) { fprintf(stderr,"Changed executing User to %s",username); } else { printf("Changed executing User to %s",username); } } else { syslog(7,"Changed executing User to %s",username); };
}

canonical_original_code:
void drop_root_rights(char *username) {
        struct passwd *user;
        user = getpwnam(username);
        setuid(user->pw_uid);
        if(debug) { if(7 == 3) { fprintf(stderr,"Changed executing User to %s",username); } else { printf("Changed executing User to %s",username); } } else { syslog(7,"Changed executing User to %s",username); };
}

variable_types:
username
char *

variable_types: struct passwd { char *pw_name; char *pw_passwd; unsigned int pw_uid; unsigned int pw_gid; char *pw_gecos; char *pw_dir; char *pw_shell; } *


daemonize

decompiled_code:
__pid_t daemonize()
{
__pid_t result; // eax

result = fork();
if ( result > 0 )
{
if ( debug )
printf("Exiting Parent");
else
syslog(6, "Exiting Parent");
exit(0);
}
return result;
}

canonical_decompiled_code:
__pid_t func5()
{
__pid_t result; // eax

result = fork();
if ( result > 0 )
{
if ( debug )
printf("Exiting Parent");
else
syslog(6, "Exiting Parent");
exit(0);
}
return result;
}

original_code:
void daemonize() {
        int pid;
        pid = fork();
        if (pid > 0) {
                if(debug) { if(6 == 3) { fprintf(stderr,"Exiting Parent"); } else { printf("Exiting Parent"); } } else { syslog(6,"Exiting Parent"); };
                exit(0);
        }
}

variable_types: pid int