decompiled_code:
_BOOL8 __fastcall probe_udf(__int64 a1, unsigned int a2, unsigned int a3)
{
_BOOL4 v4; // ebp
unsigned __int64 v6; // rbp
unsigned __int64 v7; // r15
__int64 v8; // rax
__int64 v9; // r13
unsigned __int64 v10; // r12
char v11; // dl
__int16 v12; // ax
__int64 v13; // r14
__int64 v14; // [rsp+8h] [rbp-160h]
__int64 v15; // [rsp+10h] [rbp-158h]
int v16; // [rsp+18h] [rbp-150h]
unsigned int v17; // [rsp+1Ch] [rbp-14Ch]
char v18[264]; // [rsp+20h] [rbp-148h] BYREF
__int64 v19[8]; // [rsp+128h] [rbp-40h] BYREF

v4 = 0;
if ( (unsigned __int64)get_buffer(a1, (int)(a3 << 8), 512LL, v19) > 0x1FF )
{
v4 = validate_tag(v19[0], 256LL);
if ( v4 )
{
v4 = 0;
if ( (unsigned __int16)get_le_short(v19[0]) == 2 )
{
print_line(a2, "UDF file system");
v17 = a2 + 1;
print_line(a2 + 1, "Sector size %d bytes", a3);
v6 = get_le_long(v19[0] + 16);
v15 = (int)a3;
v7 = v6 / (int)a3;
v8 = get_le_long(v19[0] + 20);
v14 = v8;
if ( v6 < (int)a3 )
goto LABEL_23;
v9 = v8 * (int)a3;
v10 = 0LL;
v16 = 0;
v4 = 0;
do
{
if ( (unsigned __int64)get_buffer(a1, v9, 512LL, v19) <= 0x1FF )
break;
if ( validate_tag(v19[0], v10 + v14) )
{
v12 = get_le_short(v19[0]);
if ( v12 == 1 )
{
if ( !v4 )
{
v11 = *(_BYTE *)(v19[0] + 24);
if ( v11 == 8 )
{
get_string(v19[0] + 25, 30LL, v18);
print_line(v17, "Volume name \"%s\"", v18);
v4 = 1;
}
else
{
if ( v11 == 16 )
{
format_utf16_le(v19[0] + 25, 30LL, v18);
print_line(v17, "Volume name \"%s\"", v18);
}
else
{
print_line(v17, "Volume name encoding not supported");
}
v4 = 1;
}
}
}
else if ( v12 == 6 && !v16 )
{
v13 = v19[0];
v16 = 1;
if ( !memcmp((const void *)(v19[0] + 217), "*OSTA UDF Compliant", 0x13uLL) )
{
print_line(v17, "UDF version %x.%02x", *(unsigned __int8 *)(v13 + 241), *(unsigned __int8 *)(v13 + 240));
v16 = 1;
}
}
}
++v10;
v9 += v15;
}
while ( v7 > v10 );
if ( !v4 )
{
LABEL_23:
print_line(v17, "Primary Volume Descriptor missing");
v4 = 1;
}
}
}
}
return v4;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1, unsigned int a2, unsigned int a3)
{
_BOOL4 v4; // ebp
unsigned __int64 v6; // rbp
unsigned __int64 v7; // r15
__int64 v8; // rax
__int64 v9; // r13
unsigned __int64 v10; // r12
char v11; // dl
__int16 v12; // ax
__int64 v13; // r14
__int64 v14; // [rsp+8h] [rbp-160h]
__int64 v15; // [rsp+10h] [rbp-158h]
int v16; // [rsp+18h] [rbp-150h]
unsigned int v17; // [rsp+1Ch] [rbp-14Ch]
char v18[264]; // [rsp+20h] [rbp-148h] BYREF
__int64 v19[8]; // [rsp+128h] [rbp-40h] BYREF

v4 = 0;
if ( (unsigned __int64)get_buffer(a1, (int)(a3 << 8), 512LL, v19) > 0x1FF )
{
v4 = func0(v19[0], 256LL);
if ( v4 )
{
v4 = 0;
if ( (unsigned __int16)get_le_short(v19[0]) == 2 )
{
print_line(a2, "UDF file system");
v17 = a2 + 1;
print_line(a2 + 1, "Sector size %d bytes", a3);
v6 = get_le_long(v19[0] + 16);
v15 = (int)a3;
v7 = v6 / (int)a3;
v8 = get_le_long(v19[0] + 20);
v14 = v8;
if ( v6 < (int)a3 )
goto LABEL_23;
v9 = v8 * (int)a3;
v10 = 0LL;
v16 = 0;
v4 = 0;
do
{
if ( (unsigned __int64)get_buffer(a1, v9, 512LL, v19) <= 0x1FF )
break;
if ( func0(v19[0], v10 + v14) )
{
v12 = get_le_short(v19[0]);
if ( v12 == 1 )
{
if ( !v4 )
{
v11 = *(_BYTE *)(v19[0] + 24);
if ( v11 == 8 )
{
get_string(v19[0] + 25, 30LL, v18);
print_line(v17, "Volume name \"%s\"", v18);
v4 = 1;
}
else
{
if ( v11 == 16 )
{
format_utf16_le(v19[0] + 25, 30LL, v18);
print_line(v17, "Volume name \"%s\"", v18);
}
else
{
print_line(v17, "Volume name encoding not supported");
}
v4 = 1;
}
}
}
else if ( v12 == 6 && !v16 )
{
v13 = v19[0];
v16 = 1;
if ( !memcmp((const void *)(v19[0] + 217), "*OSTA UDF Compliant", 0x13uLL) )
{
print_line(v17, "UDF version %x.%02x", *(unsigned __int8 *)(v13 + 241), *(unsigned __int8 *)(v13 + 240));
v16 = 1;
}
}
}
++v10;
v9 += v15;
}
while ( v7 > v10 );
if ( !v4 )
{
LABEL_23:
print_line(v17, "Primary Volume Descriptor missing");
v4 = 1;
}
}
}
}
return v4;
}

original_code:
static int probe_udf(SECTION *section, int level, int sector_size)
{
  unsigned char *buffer;
  u4 count, addr, sect;
  int seen_primary = 0;
  int seen_logical = 0;
  int i;
  char s[256];
  if (get_buffer(section, 256 * sector_size, 512, (void **)&buffer) < 512)
    return 0;
  if (!validate_tag(buffer, 256))
    return 0;
  if (get_le_short(buffer) != 2)
    return 0;
  print_line(level, "UDF file system");
  print_line(level + 1, "Sector size %d bytes", sector_size);
  count = get_le_long(buffer + 16) / sector_size;
  addr = get_le_long(buffer + 20);
  for (i = 0; i < count; i++) {
    sect = addr + i;
    if (get_buffer(section, (u8)sect * sector_size, 512, (void **)&buffer) < 512)
      break;
    if (!validate_tag(buffer, sect))
      continue;
    switch (get_le_short(buffer)) {
    case 1:
      if (!seen_primary) {
 seen_primary = 1;
 if (buffer[24] == 8) {
   get_string(buffer + 25, 30, s);
   print_line(level+1, "Volume name \"%s\"", s);
 } else if (buffer[24] == 16) {
   format_utf16_le(buffer + 25, 30, s);
   print_line(level+1, "Volume name \"%s\"", s);
 } else {
   print_line(level+1, "Volume name encoding not supported");
 }
      }
      break;
    case 6:
      if (!seen_logical) {
 seen_logical = 1;
 if (memcmp(buffer + 216+1, "*OSTA UDF Compliant", 19) == 0) {
   print_line(level+1, "UDF version %x.%02x",
       (int)buffer[216+25], (int)buffer[216+24]);
 }
      }
      break;
    }
  }
  if (!seen_primary) {
    print_line(level + 1, "Primary Volume Descriptor missing");
  }
  return 1;
}

canonical_original_code:
static int probe_udf(struct section *section, int level, int sector_size)
{
  unsigned char *buffer;
  unsigned long count; unsigned long addr; unsigned long sect;
  int seen_primary = 0;
  int seen_logical = 0;
  int i;
  char s[256];
  if (get_buffer(section, 256 * sector_size, 512, (void **)&buffer) < 512)
    return 0;
  if (!validate_tag(buffer, 256))
    return 0;
  if (get_le_short(buffer) != 2)
    return 0;
  print_line(level, "UDF file system");
  print_line(level + 1, "Sector size %d bytes", sector_size);
  count = get_le_long(buffer + 16) / sector_size;
  addr = get_le_long(buffer + 20);
  for (i = 0; i < count; i++) {
    sect = addr + i;
    if (get_buffer(section, (unsigned long long)sect * sector_size, 512, (void **)&buffer) < 512)
      break;
    if (!validate_tag(buffer, sect))
      continue;
    switch (get_le_short(buffer)) {
    case 1:
      if (!seen_primary) {
 seen_primary = 1;
 if (buffer[24] == 8) {
   get_string(buffer + 25, 30, s);
   print_line(level+1, "Volume name \"%s\"", s);
 } else if (buffer[24] == 16) {
   format_utf16_le(buffer + 25, 30, s);
   print_line(level+1, "Volume name \"%s\"", s);
 } else {
   print_line(level+1, "Volume name encoding not supported");
 }
      }
      break;
    case 6:
      if (!seen_logical) {
 seen_logical = 1;
 if (memcmp(buffer + 216+1, "*OSTA UDF Compliant", 19) == 0) {
   print_line(level+1, "UDF version %x.%02x",
       (int)buffer[216+25], (int)buffer[216+24]);
 }
      }
      break;
    }
  }
  if (!seen_primary) {
    print_line(level + 1, "Primary Volume Descriptor missing");
  }
  return 1;
}

variable_types:
buffer
unsigned char *

variable_types:
count
unsigned long

variable_types:
addr
unsigned long

variable_types:
sect
unsigned long

variable_types:
s
char [256]


repo: rumca-js/disktype

original_code:
void detect_udf(SECTION *section, int level)
{
  unsigned char *buffer;
  unsigned char sig_bea[7] = {0x00, 0x42, 0x45, 0x41, 0x30, 0x31, 0x01};
  unsigned char sig_nsr2[7] = {0x00, 0x4e, 0x53, 0x52, 0x30, 0x32, 0x01};
  unsigned char sig_nsr3[7] = {0x00, 0x4e, 0x53, 0x52, 0x30, 0x33, 0x01};
  unsigned char sig_tea[7] = {0x00, 0x54, 0x45, 0x41, 0x30, 0x31, 0x01};
  int recog_state, sector;
  int detected = 0;
  int probe_result;
  int sizes[] = { 2048, 512, 1024, 4096, -1 };
  int i;
  recog_state = 0;
  for (sector = 16; sector < 64; sector++) {
    if (get_buffer(section, sector * 2048, 2048, (void **)&buffer) < 2048)
      return;
    if (buffer[2] == buffer[1] &&
 buffer[3] == buffer[1] &&
 buffer[4] == buffer[1] &&
 buffer[5] == buffer[1])
      break;
    if (recog_state == 0 && memcmp(buffer, sig_bea, 7) == 0)
      recog_state = 1;
    if (recog_state == 1 && memcmp(buffer, sig_tea, 7) == 0)
      recog_state = 0;
    if (recog_state == 1 && (memcmp(buffer, sig_nsr2, 7) == 0 ||
        memcmp(buffer, sig_nsr3, 7) == 0)) {
      detected = 1;
      break;
    }
  }
  if (!detected)
    return;
  for (i = 0; sizes[i] > 0; i++) {
    probe_result = probe_udf(section, level, sizes[i]);
    if (probe_result > 0)
      return;
  }
  print_line(level, "UDF recognition sequence, unable to locate anchor descriptor");
}

canonical_original_code:
void detect_udf(struct section *section, int level)
{
  unsigned char *buffer;
  unsigned char sig_bea[7] = {0x00, 0x42, 0x45, 0x41, 0x30, 0x31, 0x01};
  unsigned char sig_nsr2[7] = {0x00, 0x4e, 0x53, 0x52, 0x30, 0x32, 0x01};
  unsigned char sig_nsr3[7] = {0x00, 0x4e, 0x53, 0x52, 0x30, 0x33, 0x01};
  unsigned char sig_tea[7] = {0x00, 0x54, 0x45, 0x41, 0x30, 0x31, 0x01};
  int recog_state; int sector;
  int detected = 0;
  int probe_result;
  int sizes[] = { 2048, 512, 1024, 4096, -1 };
  int i;
  recog_state = 0;
  for (sector = 16; sector < 64; sector++) {
    if (get_buffer(section, sector * 2048, 2048, (void **)&buffer) < 2048)
      return;
    if (buffer[2] == buffer[1] &&
 buffer[3] == buffer[1] &&
 buffer[4] == buffer[1] &&
 buffer[5] == buffer[1])
      break;
    if (recog_state == 0 && memcmp(buffer, sig_bea, 7) == 0)
      recog_state = 1;
    if (recog_state == 1 && memcmp(buffer, sig_tea, 7) == 0)
      recog_state = 0;
    if (recog_state == 1 && (memcmp(buffer, sig_nsr2, 7) == 0 ||
        memcmp(buffer, sig_nsr3, 7) == 0)) {
      detected = 1;
      break;
    }
  }
  if (!detected)
    return;
  for (i = 0; sizes[i] > 0; i++) {
    probe_result = probe_udf(section, level, sizes[i]);
    if (probe_result > 0)
      return;
  }
  print_line(level, "UDF recognition sequence, unable to locate anchor descriptor");
}

variable_types: struct section { unsigned long long pos; int flags; struct source { unsigned long long size; int size_known; void *cache_head; int sequential; unsigned long long seq_pos; int blocksize; struct source *foundation; int (*analyze)(struct source *s, int level); unsigned long long (*read_bytes)(struct source *s, unsigned long long pos, unsigned long long len, void *buf); int (*read_block)(struct source *s, unsigned long long pos, void *buf); void (*close)(struct source *s); } *source; } *

variable_types: level int

variable_types: sector int

variable_types: detected int

variable_types:
sizes
int []

variable_types: i int

return_type: void

user_defined_types: struct section { unsigned long long pos; int flags; struct source *source; }


original_code:
static void close_vhd(SOURCE *s)
{
  VHD_SOURCE *vs = (VHD_SOURCE *)s;
  u4 chunk;
  if (vs->raw_map != ((void *)0))
    free(vs->raw_map);
  if (vs->chunks != ((void *)0)) {
    for (chunk = 0; chunk < vs->chunk_count; chunk++) {
      if (vs->chunks[chunk] != ((void *)0))
 free(vs->chunks[chunk]);
    }
    free(vs->chunks);
  }
}

canonical_original_code:
static void close_vhd(struct source *s)
{
  struct vhd_source *vs = (VHD_SOURCE *)s;
  unsigned long chunk;
  if (vs->raw_map != ((void *)0))
    free(vs->raw_map);
  if (vs->chunks != ((void *)0)) {
    for (chunk = 0; chunk < vs->chunk_count; chunk++) {
      if (vs->chunks[chunk] != ((void *)0))
 free(vs->chunks[chunk]);
    }
    free(vs->chunks);
  }
}

variable_types: struct source { unsigned long long size; int size_known; void *cache_head; int sequential; unsigned long long seq_pos; int blocksize; struct source *foundation; int (*analyze)(struct source *s, int level); unsigned long long (*read_bytes)(struct source *s, unsigned long long pos, unsigned long long len, void *buf); int (*read_block)(struct source *s, unsigned long long pos, void *buf); void (*close)(struct source *s); } *

variable_types: struct vhd_source { struct source { unsigned long long size; int size_known; void *cache_head; int sequential; unsigned long long seq_pos; int blocksize; struct source *foundation; int (*analyze)(struct source *s, int level); unsigned long long (*read_bytes)(struct source *s, unsigned long long pos, unsigned long long len, void *buf); int (*read_block)(struct source *s, unsigned long long pos, void *buf); void (*close)(struct source *s); } c; unsigned long long off; unsigned long chunk_size; unsigned long chunk_count; unsigned long *raw_map; struct vhd_chunk { int present; unsigned long long off; unsigned char bitmap[1]; } **chunks; } *

variable_types:
chunk
unsigned long

user_defined_types: struct vhd_source { struct source c; unsigned long long off; unsigned long chunk_size; unsigned long chunk_count; unsigned long *raw_map; struct vhd_chunk **chunks; }


decompiled_code:
char *__fastcall init_vhd_source(_QWORD *a1, int a2, unsigned __int64 a3, __int64 a4)
{
char *v6; // rbx
__int64 v7; // r14
__int64 v8; // rax
unsigned int v9; // er12
__int64 v10; // rax
unsigned __int64 v11; // rdx
unsigned __int64 v12; // r13
void *v13; // rax
void *v14; // rax
char v16[264]; // [rsp+0h] [rbp-138h] BYREF
__int64 v17[6]; // [rsp+108h] [rbp-30h] BYREF

v6 = (char *)malloc(0x80uLL);
if ( !v6 )
bailout("Out of memory");
memset(v6 + 8, 0, 0x78uLL);
*((_DWORD *)v6 + 2) = 1;
*(_QWORD *)v6 = a3;
*((_DWORD *)v6 + 10) = 512;
*((_QWORD *)v6 + 6) = a1[3];
*((_QWORD *)v6 + 9) = read_block_vhd;
*((_QWORD *)v6 + 10) = close_vhd;
*((_QWORD *)v6 + 11) = *a1;
if ( (unsigned __int64)get_buffer(a1, a4, 512LL, v17) <= 0x1FF )
{
print_line((unsigned int)(a2 + 1), "Error reading the sparse image info block");
LABEL_14:
close_vhd((__int64)v6);
free(v6);
return 0LL;
}
v7 = get_be_quad(v17[0] + 16);
*((_QWORD *)v6 + 13) = get_be_long(v17[0] + 28);
v8 = get_be_long(v17[0] + 32);
*((_QWORD *)v6 + 12) = v8;
format_size(v16, v8);
v9 = a2 + 1;
print_line((unsigned int)(a2 + 1), "Dynamic sizing uses %lu chunks of %s", *((_QWORD *)v6 + 13), v16);
v10 = *((_QWORD *)v6 + 13);
v11 = *((_QWORD *)v6 + 12);
if ( v11 * v10 < a3 )
{
print_line(v9, "Error: Sparse parameters don't match total size");
goto LABEL_14;
}
if ( v11 <= 0xFFF )
{
print_line(v9, "Error: Sparse chunk size too small (%lu bytes)", v11);
goto LABEL_14;
}
if ( v11 > 0x200000 )
{
print_line(v9, "Error: Sparse chunk size too large (%lu bytes)", v11);
goto LABEL_14;
}
v12 = 4 * v10;
v13 = malloc(4 * v10);
*((_QWORD *)v6 + 14) = v13;
if ( !v13 )
bailout("Out of memory");
v14 = malloc(8LL * *((_QWORD *)v6 + 13));
*((_QWORD *)v6 + 15) = v14;
if ( !v14 )
bailout("Out of memory");
memset(*((void **)v6 + 15), 0, 8LL * *((_QWORD *)v6 + 13));
if ( get_buffer_real(a1[3], *((_QWORD *)v6 + 11) + v7, v12, *((_QWORD *)v6 + 14), 0LL) < v12 )
{
print_line(v9, "Error reading the sparse image map");
goto LABEL_14;
}
return v6;
}

canonical_decompiled_code:
char *__fastcall func1(_QWORD *a1, int a2, unsigned __int64 a3, __int64 a4)
{
char *v6; // rbx
__int64 v7; // r14
__int64 v8; // rax
unsigned int v9; // er12
__int64 v10; // rax
unsigned __int64 v11; // rdx
unsigned __int64 v12; // r13
void *v13; // rax
void *v14; // rax
char v16[264]; // [rsp+0h] [rbp-138h] BYREF
__int64 v17[6]; // [rsp+108h] [rbp-30h] BYREF

v6 = (char *)malloc(0x80uLL);
if ( !v6 )
bailout("Out of memory");
memset(v6 + 8, 0, 0x78uLL);
*((_DWORD *)v6 + 2) = 1;
*(_QWORD *)v6 = a3;
*((_DWORD *)v6 + 10) = 512;
*((_QWORD *)v6 + 6) = a1[3];
*((_QWORD *)v6 + 9) = read_block_vhd;
*((_QWORD *)v6 + 10) = close_vhd;
*((_QWORD *)v6 + 11) = *a1;
if ( (unsigned __int64)get_buffer(a1, a4, 512LL, v17) <= 0x1FF )
{
print_line((unsigned int)(a2 + 1), "Error reading the sparse image info block");
LABEL_14:
func0((__int64)v6);
free(v6);
return 0LL;
}
v7 = get_be_quad(v17[0] + 16);
*((_QWORD *)v6 + 13) = get_be_long(v17[0] + 28);
v8 = get_be_long(v17[0] + 32);
*((_QWORD *)v6 + 12) = v8;
format_size(v16, v8);
v9 = a2 + 1;
print_line((unsigned int)(a2 + 1), "Dynamic sizing uses %lu chunks of %s", *((_QWORD *)v6 + 13), v16);
v10 = *((_QWORD *)v6 + 13);
v11 = *((_QWORD *)v6 + 12);
if ( v11 * v10 < a3 )
{
print_line(v9, "Error: Sparse parameters don't match total size");
goto LABEL_14;
}
if ( v11 <= 0xFFF )
{
print_line(v9, "Error: Sparse chunk size too small (%lu bytes)", v11);
goto LABEL_14;
}
if ( v11 > 0x200000 )
{
print_line(v9, "Error: Sparse chunk size too large (%lu bytes)", v11);
goto LABEL_14;
}
v12 = 4 * v10;
v13 = malloc(4 * v10);
*((_QWORD *)v6 + 14) = v13;
if ( !v13 )
bailout("Out of memory");
v14 = malloc(8LL * *((_QWORD *)v6 + 13));
*((_QWORD *)v6 + 15) = v14;
if ( !v14 )
bailout("Out of memory");
memset(*((void **)v6 + 15), 0, 8LL * *((_QWORD *)v6 + 13));
if ( get_buffer_real(a1[3], *((_QWORD *)v6 + 11) + v7, v12, *((_QWORD *)v6 + 14), 0LL) < v12 )
{
print_line(v9, "Error reading the sparse image map");
goto LABEL_14;
}
return v6;
}

original_code:
static SOURCE *init_vhd_source(SECTION *section, int level,
          u8 total_size, u8 sparse_offset)
{
  VHD_SOURCE *vs;
  unsigned char *buf;
  u8 map_offset;
  u4 map_size;
  char s[256];
  vs = (VHD_SOURCE *)malloc(sizeof(VHD_SOURCE));
  if (vs == ((void *)0))
    bailout("Out of memory");
  memset(vs, 0, sizeof(VHD_SOURCE));
  vs->c.size_known = 1;
  vs->c.size = total_size;
  vs->c.blocksize = 512;
  vs->c.foundation = section->source;
  vs->c.read_block = read_block_vhd;
  vs->c.close = close_vhd;
  vs->off = section->pos;
  if (get_buffer(section, sparse_offset, 512, (void **)&buf) < 512) {
    print_line(level + 1, "Error reading the sparse image info block");
    goto errorexit;
  }
  map_offset = get_be_quad(buf + 16);
  vs->chunk_count = get_be_long(buf + 28);
  vs->chunk_size = get_be_long(buf + 32);
  format_size(s, vs->chunk_size);
  print_line(level + 1, "Dynamic sizing uses %lu chunks of %s",
      vs->chunk_count, s);
  if ((u8)vs->chunk_count * vs->chunk_size < total_size) {
    print_line(level + 1, "Error: Sparse parameters don't match total size");
    goto errorexit;
  }
  if (vs->chunk_size < 4096) {
    print_line(level + 1, "Error: Sparse chunk size too small (%lu bytes)",
        vs->chunk_size);
    goto errorexit;
  }
  if (vs->chunk_size > 2*1024*1024) {
    print_line(level + 1, "Error: Sparse chunk size too large (%lu bytes)",
        vs->chunk_size);
    goto errorexit;
  }
  map_size = vs->chunk_count * 4;
  vs->raw_map = (u4 *)malloc(map_size);
  if (vs->raw_map == ((void *)0))
    bailout("Out of memory");
  vs->chunks = (VHD_CHUNK **)malloc(vs->chunk_count * sizeof(VHD_CHUNK *));
  if (vs->chunks == ((void *)0))
    bailout("Out of memory");
  memset(vs->chunks, 0, vs->chunk_count * sizeof(VHD_CHUNK *));
  if (get_buffer_real(section->source, vs->off + map_offset, map_size,
        (void *)vs->raw_map, ((void *)0)) < map_size) {
    print_line(level + 1, "Error reading the sparse image map");
    goto errorexit;
  }
  return (SOURCE *)vs;
errorexit:
  close_vhd((SOURCE *)vs);
  free(vs);
  return ((void *)0);
}

canonical_original_code:
static struct source *init_vhd_source(struct section *section, int level, unsigned long long total_size, unsigned long long sparse_offset)
{
  struct vhd_source *vs;
  unsigned char *buf;
  unsigned long long map_offset;
  unsigned long map_size;
  char s[256];
  vs = (struct vhd_source *)malloc(sizeof(VHD_SOURCE));
  if (vs == ((void *)0))
    bailout("Out of memory");
  memset(vs, 0, sizeof(VHD_SOURCE));
  vs->c.size_known = 1;
  vs->c.size = total_size;
  vs->c.blocksize = 512;
  vs->c.foundation = section->source;
  vs->c.read_block = read_block_vhd;
  vs->c.close = close_vhd;
  vs->off = section->pos;
  if (get_buffer(section, sparse_offset, 512, (void **)&buf) < 512) {
    print_line(level + 1, "Error reading the sparse image info block");
    goto errorexit;
  }
  map_offset = get_be_quad(buf + 16);
  vs->chunk_count = get_be_long(buf + 28);
  vs->chunk_size = get_be_long(buf + 32);
  format_size(s, vs->chunk_size);
  print_line(level + 1, "Dynamic sizing uses %lu chunks of %s",
      vs->chunk_count, s);
  if ((unsigned long long)vs->chunk_count * vs->chunk_size < total_size) {
    print_line(level + 1, "Error: Sparse parameters don't match total size");
    goto errorexit;
  }
  if (vs->chunk_size < 4096) {
    print_line(level + 1, "Error: Sparse chunk size too small (%lu bytes)",
        vs->chunk_size);
    goto errorexit;
  }
  if (vs->chunk_size > 2*1024*1024) {
    print_line(level + 1, "Error: Sparse chunk size too large (%lu bytes)",
        vs->chunk_size);
    goto errorexit;
  }
  map_size = vs->chunk_count * 4;
  vs->raw_map = (unsigned long *)malloc(map_size);
  if (vs->raw_map == ((void *)0))
    bailout("Out of memory");
  vs->chunks = (struct vhd_chunk **)malloc(vs->chunk_count * sizeof(struct vhd_chunk *));
  if (vs->chunks == ((void *)0))
    bailout("Out of memory");
  memset(vs->chunks, 0, vs->chunk_count * sizeof(struct vhd_chunk *));
  if (get_buffer_real(section->source, vs->off + map_offset, map_size,
        (void *)vs->raw_map, ((void *)0)) < map_size) {
    print_line(level + 1, "Error reading the sparse image map");
    goto errorexit;
  }
  return (struct source *)vs;
errorexit:
  close_vhd((struct source *)vs);
  free(vs);
  return ((void *)0);
}

variable_types: struct section { unsigned long long pos; int flags; struct source *source; } *

variable_types:
buf
unsigned char *

return_type: struct source { unsigned long long size; int size_known; void *cache_head; int sequential; unsigned long long seq_pos; int blocksize; struct source *foundation; int (*analyze)(struct source *s, int level); unsigned long long (*read_bytes)(struct source *s, unsigned long long pos, unsigned long long len, void *buf); int (*read_block)(struct source *s, unsigned long long pos, void *buf); void (*close)(struct source *s); } *

user_defined_types: struct vhd_chunk { int present; unsigned long long off; unsigned char bitmap[1]; }


original_code:
static int read_block_vhd(SOURCE *s, u8 pos, void *buf)
{
  VHD_SOURCE *vs = (VHD_SOURCE *)s;
  SOURCE *fs = s->foundation;
  u4 chunk, chunk_start_sector, sector;
  u8 chunk_disk_off, sector_pos;
  unsigned char *filebuf;
  int present;
  chunk = (u4)(pos / vs->chunk_size);
  if (chunk >= vs->chunk_count)
    return 0;
  if (vs->chunks[chunk] == ((void *)0)) {
    chunk_start_sector = get_be_long(vs->raw_map + chunk);
    if (chunk_start_sector == 0xffffffff) {
      present = 0;
    } else {
      chunk_disk_off = vs->off + (u8)chunk_start_sector * 512;
      if (get_buffer_real(fs, chunk_disk_off, 512,
     ((void *)0), (void **)&filebuf) < 512)
 present = 0;
      else
 present = 1;
    }
    if (!present) {
      vs->chunks[chunk] = (VHD_CHUNK *)malloc(sizeof(VHD_CHUNK));
      if (vs->chunks[chunk] == ((void *)0))
 bailout("Out of memory");
      vs->chunks[chunk]->present = 0;
    } else {
      vs->chunks[chunk] = (VHD_CHUNK *)malloc(sizeof(VHD_CHUNK) + 512);
      if (vs->chunks[chunk] == ((void *)0))
 bailout("Out of memory");
      vs->chunks[chunk]->present = 1;
      vs->chunks[chunk]->off = chunk_disk_off + 512;
      memcpy(vs->chunks[chunk]->bitmap, filebuf, 512);
    }
  }
  if (!vs->chunks[chunk]->present) {
    memset(buf, 0, 512);
    return 1;
  }
  sector = (u4)((pos - (u8)chunk * vs->chunk_size) / 512);
  if (vs->chunks[chunk]->bitmap[sector >> 3] & (128 >> (sector & 7))) {
    sector_pos = vs->chunks[chunk]->off + (u8)sector * 512;
    if (get_buffer_real(fs, sector_pos, 512, buf, ((void *)0)) < 512)
      return 0;
  } else {
    memset(buf, 0, 512);
  }
  return 1;
}

canonical_original_code:
static int read_block_vhd(struct source *s, unsigned long long pos, void *buf)
{
  struct vhd_source *vs = (VHD_SOURCE *)s;
  struct source *fs = s->foundation;
  unsigned long chunk; unsigned long chunk_start_sector; unsigned long sector;
  unsigned long long chunk_disk_off; unsigned long long sector_pos;
  unsigned char *filebuf;
  int present;
  chunk = (u4)(pos / vs->chunk_size);
  if (chunk >= vs->chunk_count)
    return 0;
  if (vs->chunks[chunk] == ((void *)0)) {
    chunk_start_sector = get_be_long(vs->raw_map + chunk);
    if (chunk_start_sector == 0xffffffff) {
      present = 0;
    } else {
      chunk_disk_off = vs->off + (unsigned long long)chunk_start_sector * 512;
      if (get_buffer_real(fs, chunk_disk_off, 512,
     ((void *)0), (void **)&filebuf) < 512)
 present = 0;
      else
 present = 1;
    }
    if (!present) {
      vs->chunks[chunk] = (struct vhd_chunk *)malloc(sizeof(VHD_CHUNK));
      if (vs->chunks[chunk] == ((void *)0))
 bailout("Out of memory");
      vs->chunks[chunk]->present = 0;
    } else {
      vs->chunks[chunk] = (struct vhd_chunk *)malloc(sizeof(VHD_CHUNK) + 512);
      if (vs->chunks[chunk] == ((void *)0))
 bailout("Out of memory");
      vs->chunks[chunk]->present = 1;
      vs->chunks[chunk]->off = chunk_disk_off + 512;
      memcpy(vs->chunks[chunk]->bitmap, filebuf, 512);
    }
  }
  if (!vs->chunks[chunk]->present) {
    memset(buf, 0, 512);
    return 1;
  }
  sector = (u4)((pos - (unsigned long long)chunk * vs->chunk_size) / 512);
  if (vs->chunks[chunk]->bitmap[sector >> 3] & (128 >> (sector & 7))) {
    sector_pos = vs->chunks[chunk]->off + (unsigned long long)sector * 512;
    if (get_buffer_real(fs, sector_pos, 512, buf, ((void *)0)) < 512)
      return 0;
  } else {
    memset(buf, 0, 512);
  }
  return 1;
}

variable_types:
pos
unsigned long long

variable_types:
buf
void *

variable_types:
sector
unsigned long

variable_types:
filebuf
unsigned char *

variable_types: present int

return_type: int

user_defined_types: struct source { unsigned long long size; int size_known; void *cache_head; int sequential; unsigned long long seq_pos; int blocksize; struct source *foundation; int (*analyze)(struct source *s, int level); unsigned long long (*read_bytes)(struct source *s, unsigned long long pos, unsigned long long len, void *buf); int (*read_block)(struct source *s, unsigned long long pos, void *buf); void (*close)(struct source *s); }


decompiled_code:
int __fastcall detect_vhd(_QWORD *a1, unsigned int a2)
{
char *v3; // rax
unsigned __int64 v4; // rsi
unsigned int v5; // ebp
unsigned __int64 v6; // r13
__int64 v7; // rax
char *v8; // r12
char v10[264]; // [rsp+0h] [rbp-138h] BYREF
void *s1[6]; // [rsp+108h] [rbp-30h] BYREF

v3 = (char *)get_buffer(a1, 0LL, 511LL, s1);
if ( (unsigned __int64)v3 <= 0x1FE )
return (int)v3;
LODWORD(v3) = memcmp(s1[0], "conectix", 8uLL);
if ( (_DWORD)v3 )
{
v4 = a1[1];
if ( v4 <= 0x400 )
return (int)v3;
v3 = (char *)a1[3];
if ( *((_DWORD *)v3 + 6) )
return (int)v3;
v3 = (char *)get_buffer(a1, v4 - 511, 511LL, s1);
if ( (unsigned __int64)v3 <= 0x1FE )
return (int)v3;
LODWORD(v3) = memcmp(s1[0], "conectix", 8uLL);
if ( (_DWORD)v3 )
return (int)v3;
}
v5 = get_be_long((char *)s1[0] + 60);
v6 = get_be_quad((char *)s1[0] + 40);
switch ( v5 )
{
case 2u:
print_line(a2, "Connectix Virtual PC hard disk image, fixed size");
break;
case 3u:
print_line(a2, "Connectix Virtual PC hard disk image, dynamic size");
format_size_verbose(v10, v6);
print_line(a2 + 1, "Disk size %s", v10);
v7 = get_be_quad((char *)s1[0] + 16);
v3 = init_vhd_source(a1, a2, v6, v7);
v8 = v3;
if ( v3 )
{
analyze_source(v3, a2);
LODWORD(v3) = close_source(v8);
}
goto LABEL_12;
case 4u:
print_line(a2, "Connectix Virtual PC hard disk image, differential");
break;
default:
print_line(a2, "Connectix Virtual PC hard disk image, unknown type %d", v5);
break;
}
format_size_verbose(v10, v6);
LODWORD(v3) = print_line(a2 + 1, "Disk size %s", v10);
LABEL_12:
if ( v5 - 3 <= 1 )
LODWORD(v3) = stop_detect();
return (int)v3;
}

canonical_decompiled_code:
int __fastcall func3(_QWORD *a1, unsigned int a2)
{
char *v3; // rax
unsigned __int64 v4; // rsi
unsigned int v5; // ebp
unsigned __int64 v6; // r13
__int64 v7; // rax
char *v8; // r12
char v10[264]; // [rsp+0h] [rbp-138h] BYREF
void *s1[6]; // [rsp+108h] [rbp-30h] BYREF

v3 = (char *)get_buffer(a1, 0LL, 511LL, s1);
if ( (unsigned __int64)v3 <= 0x1FE )
return (int)v3;
LODWORD(v3) = memcmp(s1[0], "conectix", 8uLL);
if ( (_DWORD)v3 )
{
v4 = a1[1];
if ( v4 <= 0x400 )
return (int)v3;
v3 = (char *)a1[3];
if ( *((_DWORD *)v3 + 6) )
return (int)v3;
v3 = (char *)get_buffer(a1, v4 - 511, 511LL, s1);
if ( (unsigned __int64)v3 <= 0x1FE )
return (int)v3;
LODWORD(v3) = memcmp(s1[0], "conectix", 8uLL);
if ( (_DWORD)v3 )
return (int)v3;
}
v5 = get_be_long((char *)s1[0] + 60);
v6 = get_be_quad((char *)s1[0] + 40);
switch ( v5 )
{
case 2u:
print_line(a2, "Connectix Virtual PC hard disk image, fixed size");
break;
case 3u:
print_line(a2, "Connectix Virtual PC hard disk image, dynamic size");
format_size_verbose(v10, v6);
print_line(a2 + 1, "Disk size %s", v10);
v7 = get_be_quad((char *)s1[0] + 16);
v3 = func1(a1, a2, v6, v7);
v8 = v3;
if ( v3 )
{
analyze_source(v3, a2);
LODWORD(v3) = close_source(v8);
}
goto LABEL_12;
case 4u:
print_line(a2, "Connectix Virtual PC hard disk image, differential");
break;
default:
print_line(a2, "Connectix Virtual PC hard disk image, unknown type %d", v5);
break;
}
format_size_verbose(v10, v6);
LODWORD(v3) = print_line(a2 + 1, "Disk size %s", v10);
LABEL_12:
if ( v5 - 3 <= 1 )
LODWORD(v3) = stop_detect();
return (int)v3;
}

original_code:
void detect_vhd(SECTION *section, int level)
{
  unsigned char *buf;
  int found, type;
  u8 sparse_offset, total_size;
  char s[256];
  SOURCE *src;
  found = 0;
  if (get_buffer(section, 0, 511, (void **)&buf) < 511)
    return;
  if (memcmp(buf, "conectix", 8) == 0) {
    found = 1;
  }
  if (!found && section->size > 1024 && !section->source->sequential) {
    if (get_buffer(section, section->size - 511, 511, (void **)&buf) < 511)
      return;
    if (memcmp(buf, "conectix", 8) == 0) {
      found = 1;
    }
  }
  if (!found)
    return;
  type = get_be_long(buf + 0x3c);
  total_size = get_be_quad(buf + 0x28);
  if (type == 2) {
    print_line(level, "Connectix Virtual PC hard disk image, fixed size");
  } else if (type == 3) {
    print_line(level, "Connectix Virtual PC hard disk image, dynamic size");
  } else if (type == 4) {
    print_line(level, "Connectix Virtual PC hard disk image, differential");
  } else {
    print_line(level, "Connectix Virtual PC hard disk image, unknown type %d",
        type);
  }
  format_size_verbose(s, total_size);
  print_line(level + 1, "Disk size %s", s);
  if (type == 3) {
    sparse_offset = get_be_quad(buf + 16);
    src = init_vhd_source(section, level, total_size, sparse_offset);
    if (src != ((void *)0)) {
      analyze_source(src, level);
      close_source(src);
    }
  }
  if (type == 3 || type == 4)
    stop_detect();
}

canonical_original_code:
void detect_vhd(struct section *section, int level)
{
  unsigned char *buf;
  int found; int type;
  unsigned long long sparse_offset; unsigned long long total_size;
  char s[256];
  struct source *src;
  found = 0;
  if (get_buffer(section, 0, 511, (void **)&buf) < 511)
    return;
  if (memcmp(buf, "conectix", 8) == 0) {
    found = 1;
  }
  if (!found && section->size > 1024 && !section->source->sequential) {
    if (get_buffer(section, section->size - 511, 511, (void **)&buf) < 511)
      return;
    if (memcmp(buf, "conectix", 8) == 0) {
      found = 1;
    }
  }
  if (!found)
    return;
  type = get_be_long(buf + 0x3c);
  total_size = get_be_quad(buf + 0x28);
  if (type == 2) {
    print_line(level, "Connectix Virtual PC hard disk image, fixed size");
  } else if (type == 3) {
    print_line(level, "Connectix Virtual PC hard disk image, dynamic size");
  } else if (type == 4) {
    print_line(level, "Connectix Virtual PC hard disk image, differential");
  } else {
    print_line(level, "Connectix Virtual PC hard disk image, unknown type %d",
        type);
  }
  format_size_verbose(s, total_size);
  print_line(level + 1, "Disk size %s", s);
  if (type == 3) {
    sparse_offset = get_be_quad(buf + 16);
    src = init_vhd_source(section, level, total_size, sparse_offset);
    if (src != ((void *)0)) {
      analyze_source(src, level);
      close_source(src);
    }
  }
  if (type == 3 || type == 4)
    stop_detect();
}

variable_types: found int

variable_types: type int

variable_types:
s
char [256]


decompiled_code:
__int64 __fastcall cddb_sum(int a1)
{
unsigned int v1; // ecx
int v2; // edx

if ( a1 <= 0 )
return 0;
v1 = 0;
do
{
v1 += a1 % 10;
v2 = a1;
a1 /= 10;
}
while ( v2 > 9 );
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
unsigned int v1; // ecx
int v2; // edx

if ( a1 <= 0 )
return 0;
v1 = 0;
do
{
v1 += a1 % 10;
v2 = a1;
a1 /= 10;
}
while ( v2 > 9 );
return v1;
}

original_code:
static int cddb_sum(int n)
{
  int ret = 0;
  while (n > 0) {
    ret = ret + (n % 10);
    n = n / 10;
  }
  return ret;
}

variable_types: n int

variable_types: ret int


original_code:
int analyze_cdaccess(int fd, SOURCE *s, int level)
{
  int i;
  int first, last, ntracks;
  int cksum, totaltime, seconds;
  u4 diskid;
  u1 ctrl[100];
  u4 lba[100], length;
  char human_readable_size[256];
  struct cdrom_tochdr tochdr;
  struct cdrom_tocentry tocentry;
  if (ioctl(fd, 0x5305, &tochdr) < 0) {
    return 0;
  }
  first = tochdr.cdth_trk0;
  last = tochdr.cdth_trk1;
  ntracks = last + 1 - first;
  if (ntracks > 99)
    return 0;
  for (i = 0; i <= ntracks; i++) {
    if (i == ntracks)
      tocentry.cdte_track = 0xAA;
    else
      tocentry.cdte_track = first + i;
    tocentry.cdte_format = 0x01;
    if (ioctl(fd, 0x5306, &tocentry) < 0) {
      return 0;
    }
    ctrl[i] = tocentry.cdte_ctrl;
    lba[i] = tocentry.cdte_addr.lba;
  }
  cksum = 0;
  for (i = 0; i < ntracks; i++) {
    cksum += cddb_sum((((lba[i]) + 150) / 75));
  }
  totaltime = (((lba[ntracks]) + 150) / 75) - (((lba[0]) + 150) / 75);
  diskid = (u4)(cksum % 0xff) << 24 | (u4)totaltime << 8 | (u4)ntracks;
  print_line(level, "CD-ROM, %d track%s, CDDB disk ID %08lX",
      ntracks, (ntracks != 1) ? "s" : "", diskid);
  for (i = 0; i < ntracks; i++) {
    length = lba[i+1] - lba[i];
    if ((ctrl[i] & 0x4) == 0) {
      seconds = length / 75;
      format_size(human_readable_size, (u8)length * 2352);
      print_line(level, "Track %d: Audio track, %s, %3d min %02d sec",
   first + i, human_readable_size,
   seconds / 60, seconds % 60);
    } else {
      format_size(human_readable_size, length * 2048);
      print_line(level, "Track %d: Data track, %s",
   first + i, human_readable_size);
      analyze_source_special(s, level + 1,
        (u8)lba[i] * 2048, (u8)(length - 250) * 2048);
    }
  }
  return 1;
}

canonical_original_code:
int analyze_cdaccess(int fd, struct source *s, int level)
{
  int i;
  int first; int last; int ntracks;
  int cksum; int totaltime; int seconds;
  unsigned long diskid;
  unsigned char ctrl[100];
  unsigned long lba[100]; unsigned long length;
  char human_readable_size[256];
  struct cdrom_tochdr tochdr;
  struct cdrom_tocentry tocentry;
  if (ioctl(fd, 0x5305, &tochdr) < 0) {
    return 0;
  }
  first = tochdr.cdth_trk0;
  last = tochdr.cdth_trk1;
  ntracks = last + 1 - first;
  if (ntracks > 99)
    return 0;
  for (i = 0; i <= ntracks; i++) {
    if (i == ntracks)
      tocentry.cdte_track = 0xAA;
    else
      tocentry.cdte_track = first + i;
    tocentry.cdte_format = 0x01;
    if (ioctl(fd, 0x5306, &tocentry) < 0) {
      return 0;
    }
    ctrl[i] = tocentry.cdte_ctrl;
    lba[i] = tocentry.cdte_addr.lba;
  }
  cksum = 0;
  for (i = 0; i < ntracks; i++) {
    cksum += cddb_sum((((lba[i]) + 150) / 75));
  }
  totaltime = (((lba[ntracks]) + 150) / 75) - (((lba[0]) + 150) / 75);
  diskid = (u4)(cksum % 0xff) << 24 | (unsigned long)totaltime << 8 | (unsigned long)ntracks;
  print_line(level, "CD-ROM, %d track%s, CDDB disk ID %08lX",
      ntracks, (ntracks != 1) ? "s" : "", diskid);
  for (i = 0; i < ntracks; i++) {
    length = lba[i+1] - lba[i];
    if ((ctrl[i] & 0x4) == 0) {
      seconds = length / 75;
      format_size(human_readable_size, (unsigned long long)length * 2352);
      print_line(level, "Track %d: Audio track, %s, %3d min %02d sec",
   first + i, human_readable_size,
   seconds / 60, seconds % 60);
    } else {
      format_size(human_readable_size, length * 2048);
      print_line(level, "Track %d: Data track, %s",
   first + i, human_readable_size);
      analyze_source_special(s, level + 1,
        (unsigned long long)lba[i] * 2048, (u8)(length - 250) * 2048);
    }
  }
  return 1;
}

variable_types: fd int

variable_types: level int

variable_types: first int

variable_types: last int

variable_types: ntracks int

variable_types: cksum int

variable_types: totaltime int

variable_types: seconds int

variable_types:
diskid
unsigned long

variable_types:
ctrl
unsigned char [100]

variable_types:
lba
unsigned long [100]

variable_types:
length
unsigned long

variable_types: struct cdrom_tochdr { unsigned char cdth_trk0; unsigned char cdth_trk1; }

variable_types: struct cdrom_tocentry { unsigned char cdte_track; unsigned char cdte_adr; unsigned char cdte_ctrl; unsigned char cdte_format; union cdrom_addr { struct cdrom_msf0 { unsigned char minute; unsigned char second; unsigned char frame; } msf; int lba; } cdte_addr; unsigned char cdte_datamode; }

user_defined_types: struct cdrom_tocentry { unsigned char cdte_track; unsigned char cdte_adr; unsigned char cdte_ctrl; unsigned char cdte_format; union cdrom_addr cdte_addr; unsigned char cdte_datamode; }

user_defined_types: union cdrom_addr { struct cdrom_msf0 msf; int lba; }


decompiled_code:
unsigned __int64 __fastcall detect_bfs(__int64 a1, unsigned int a2)
{
__int64 v2; // rbx
unsigned __int64 result; // rax
const char *v4; // rcx
const char *v5; // rdx
__int64 v6; // rbx
__int64 v7; // rax
unsigned int v8; // ebp
char v9[264]; // [rsp+0h] [rbp-148h] BYREF
__int64 v10[8]; // [rsp+108h] [rbp-40h] BYREF

v2 = 0LL;
while ( 1 )
{
result = get_buffer(a1, v2, 512LL, v10);
if ( result > 0x1FF )
break;
LABEL_11:
v2 += 512LL;
if ( v2 == 1024 )
return result;
}
v8 = 0;
while ( 1 )
{
result = get_ve_long(v8, v10[0] + 32);
if ( result == 1111905073 )
{
result = get_ve_long(v8, v10[0] + 36);
if ( result == 1112098629 )
{
result = get_ve_long(v8, v10[0] + 68);
if ( result == 3708948529 )
{
result = get_ve_long(v8, v10[0] + 112);
if ( result == 364282638 )
break;
}
}
}
if ( ++v8 == 2 )
goto LABEL_11;
}
v4 = (const char *)get_ve_name(v8);
v5 = "Apple";
if ( (_DWORD)v2 )
v5 = "Intel";
print_line(a2, "BeOS BFS (BeFS) file system, %s placement, %s", v5, v4);
get_string(v10[0], 32LL, v9);
if ( v9[0] )
print_line(a2 + 1, "Volume name \"%s\"", v9);
v6 = get_ve_long(v8, v10[0] + 40);
v7 = get_ve_quad(v8, v10[0] + 48);
format_blocky_size(v9, v7, v6, "blocks", 0LL);
return print_line(a2 + 1, "Volume size %s", v9);
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1, unsigned int a2)
{
__int64 v2; // rbx
unsigned __int64 result; // rax
const char *v4; // rcx
const char *v5; // rdx
__int64 v6; // rbx
__int64 v7; // rax
unsigned int v8; // ebp
char v9[264]; // [rsp+0h] [rbp-148h] BYREF
__int64 v10[8]; // [rsp+108h] [rbp-40h] BYREF

v2 = 0LL;
while ( 1 )
{
result = get_buffer(a1, v2, 512LL, v10);
if ( result > 0x1FF )
break;
LABEL_11:
v2 += 512LL;
if ( v2 == 1024 )
return result;
}
v8 = 0;
while ( 1 )
{
result = get_ve_long(v8, v10[0] + 32);
if ( result == 1111905073 )
{
result = get_ve_long(v8, v10[0] + 36);
if ( result == 1112098629 )
{
result = get_ve_long(v8, v10[0] + 68);
if ( result == 3708948529 )
{
result = get_ve_long(v8, v10[0] + 112);
if ( result == 364282638 )
break;
}
}
}
if ( ++v8 == 2 )
goto LABEL_11;
}
v4 = (const char *)get_ve_name(v8);
v5 = "Apple";
if ( (_DWORD)v2 )
v5 = "Intel";
print_line(a2, "BeOS BFS (BeFS) file system, %s placement, %s", v5, v4);
get_string(v10[0], 32LL, v9);
if ( v9[0] )
print_line(a2 + 1, "Volume name \"%s\"", v9);
v6 = get_ve_long(v8, v10[0] + 40);
v7 = get_ve_quad(v8, v10[0] + 48);
format_blocky_size(v9, v7, v6, "blocks", 0LL);
return print_line(a2 + 1, "Volume size %s", v9);
}

original_code:
void detect_bfs(SECTION *section, int level)
{
  unsigned char *buf;
  char s[256];
  int off, en;
  u4 blocksize;
  u8 blockcount;
  for (off = 0; off <= 512; off += 512) {
    if (get_buffer(section, off, 512, (void **)&buf) < 512)
      continue;
    for (en = 0; en < 2; en++) {
      if (get_ve_long(en, buf + 32) == 0x42465331 &&
   get_ve_long(en, buf + 36) == 0x42494745 &&
   get_ve_long(en, buf + 68) == 0xdd121031 &&
   get_ve_long(en, buf + 112) == 0x15b6830e) {
 print_line(level, "BeOS BFS (BeFS) file system, %s placement, %s",
     (off == 0) ? "Apple" : "Intel",
     get_ve_name(en));
 get_string(buf, 32, s);
 if (s[0])
   print_line(level + 1, "Volume name \"%s\"", s);
 blocksize = get_ve_long(en, buf + 40);
 blockcount = get_ve_quad(en, buf + 48);
 format_blocky_size(s, blockcount, blocksize, "blocks", ((void *)0));
 print_line(level + 1, "Volume size %s", s);
 return;
      }
    }
  }
}

canonical_original_code:
void detect_bfs(struct section *section, int level)
{
  unsigned char *buf;
  char s[256];
  int off; int en;
  unsigned long blocksize;
  unsigned long long blockcount;
  for (off = 0; off <= 512; off += 512) {
    if (get_buffer(section, off, 512, (void **)&buf) < 512)
      continue;
    for (en = 0; en < 2; en++) {
      if (get_ve_long(en, buf + 32) == 0x42465331 &&
   get_ve_long(en, buf + 36) == 0x42494745 &&
   get_ve_long(en, buf + 68) == 0xdd121031 &&
   get_ve_long(en, buf + 112) == 0x15b6830e) {
 print_line(level, "BeOS BFS (BeFS) file system, %s placement, %s",
     (off == 0) ? "Apple" : "Intel",
     get_ve_name(en));
 get_string(buf, 32, s);
 if (s[0])
   print_line(level + 1, "Volume name \"%s\"", s);
 blocksize = get_ve_long(en, buf + 40);
 blockcount = get_ve_quad(en, buf + 48);
 format_blocky_size(s, blockcount, blocksize, "blocks", ((void *)0));
 print_line(level + 1, "Volume size %s", s);
 return;
      }
    }
  }
}

variable_types: struct section { unsigned long long pos; int flags; struct source { unsigned long long size; int size_known; void *cache_head; int sequential; unsigned long long seq_pos; int blocksize; struct source *foundation; int (*analyze)(struct source *s, int level); unsigned long long (*read_bytes)(struct source *s, unsigned long long pos, unsigned long long len, void *buf); int (*read_block)(struct source *s, unsigned long long pos, void *buf); void (*close)(struct source *s); } *source; } *

variable_types:
buf
unsigned char *

variable_types:
s
char [256]

variable_types: off int

variable_types: en int

variable_types:
blocksize
unsigned long

variable_types:
blockcount
unsigned long long


decompiled_code:
void __fastcall detect_beos_loader(__int64 a1, unsigned int a2)
{
__int64 v2; // [rsp+0h] [rbp-10h] BYREF

if ( (*(_BYTE *)(a1 + 16) & 1) == 0 && (unsigned __int64)get_buffer(a1, 0LL, 512LL, &v2) > 0x1FF )
{
if ( (int)find_memory(v2, 512LL, "Be Boot Loader", 14LL) >= 0 )
print_line(a2, "BeOS boot loader");
if ( (int)find_memory(v2, 512LL, "yT Boot Loader", 14LL) >= 0 )
print_line(a2, "ZETA/yellowTab boot loader");
if ( (int)find_memory(v2, 512LL, &unk_2EE, 18LL) >= 0 )
print_line(a2, "Haiku boot loader");
}
}

canonical_decompiled_code:
void __fastcall func1(__int64 a1, unsigned int a2)
{
__int64 v2; // [rsp+0h] [rbp-10h] BYREF

if ( (*(_BYTE *)(a1 + 16) & 1) == 0 && (unsigned __int64)get_buffer(a1, 0LL, 512LL, &v2) > 0x1FF )
{
if ( (int)find_memory(v2, 512LL, "Be Boot Loader", 14LL) >= 0 )
print_line(a2, "BeOS boot loader");
if ( (int)find_memory(v2, 512LL, "yT Boot Loader", 14LL) >= 0 )
print_line(a2, "ZETA/yellowTab boot loader");
if ( (int)find_memory(v2, 512LL, &unk_2EE, 18LL) >= 0 )
print_line(a2, "Haiku boot loader");
}
}

original_code:
void detect_beos_loader(SECTION *section, int level)
{
  unsigned char *buf;
  if (section->flags & (0x0001))
    return;
  if (get_buffer(section, 0, 512, (void **)&buf) < 512)
    return;
  if (find_memory(buf, 512, "Be Boot Loader", 14) >= 0)
    print_line(level, "BeOS boot loader");
  if (find_memory(buf, 512, "yT Boot Loader", 14) >= 0)
    print_line(level, "ZETA/yellowTab boot loader");
  if (find_memory(buf, 512, "\x04" "beos\x06" "system\x05" "zbeos", 18) >= 0)
    print_line(level, "Haiku boot loader");
}

canonical_original_code:
void detect_beos_loader(struct section *section, int level)
{
  unsigned char *buf;
  if (section->flags & (0x0001))
    return;
  if (get_buffer(section, 0, 512, (void **)&buf) < 512)
    return;
  if (find_memory(buf, 512, "Be Boot Loader", 14) >= 0)
    print_line(level, "BeOS boot loader");
  if (find_memory(buf, 512, "yT Boot Loader", 14) >= 0)
    print_line(level, "ZETA/yellowTab boot loader");
  if (find_memory(buf, 512, "\x04" "beos\x06" "system\x05" "zbeos", 18) >= 0)
    print_line(level, "Haiku boot loader");
}

variable_types: level int


decompiled_code:
__int64 __fastcall handle_compressed(_QWORD *a1, int a2, int a3, const char *a4)
{
__int64 v4; // rax
unsigned int *v5; // rbp

v4 = a1[1];
if ( v4 )
v4 = a1[1] - a3;
v5 = init_compressed_source(a1[3], *a1 + a3, v4, a4);
analyze_source(v5, (unsigned int)(a2 + 1));
return close_source(v5);
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1, int a2, int a3, const char *a4)
{
__int64 v4; // rax
unsigned int *v5; // rbp

v4 = a1[1];
if ( v4 )
v4 = a1[1] - a3;
v5 = func0(a1[3], *a1 + a3, v4, a4);
analyze_source(v5, (unsigned int)(a2 + 1));
return close_source(v5);
}

original_code:
static void handle_compressed(SECTION *section, int level,
         int off, const char *program)
{
  SOURCE *s;
  u8 size;
  size = section->size;
  if (size > 0)
    size -= off;
  s = init_compressed_source(section->source,
        section->pos + off, size, program);
  analyze_source(s, level + 1);
  close_source(s);
}

canonical_original_code:
static void handle_compressed(struct section *section, int level, int off, char *program)
{
  struct source *s;
  unsigned long long size;
  size = section->size;
  if (size > 0)
    size -= off;
  s = init_compressed_source(section->source,
        section->pos + off, size, program);
  analyze_source(s, level + 1);
  close_source(s);
}

variable_types:
program
char *

variable_types: struct source { unsigned long long size; int size_known; void *cache_head; int sequential; unsigned long long seq_pos; int blocksize; struct source *foundation; int (*analyze)(struct source *s, int level); unsigned long long (*read_bytes)(struct source *s, unsigned long long pos, unsigned long long len, void *buf); int (*read_block)(struct source *s, unsigned long long pos, void *buf); void (*close)(struct source *s); } *

variable_types:
size
unsigned long long


decompiled_code:
__pid_t __fastcall close_compressed(_DWORD *a1)
{
int v2; // edi
int v3; // edi
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = a1[28];
if ( v2 >= 0 )
close(v2);
v3 = a1[29];
if ( v3 >= 0 )
close(v3);
kill(a1[31], 1);
return waitpid(a1[31], stat_loc, 0);
}

canonical_decompiled_code:
__pid_t __fastcall func2(_DWORD *a1)
{
int v2; // edi
int v3; // edi
int stat_loc[3]; // [rsp+Ch] [rbp-Ch] BYREF

v2 = a1[28];
if ( v2 >= 0 )
close(v2);
v3 = a1[29];
if ( v3 >= 0 )
close(v3);
kill(a1[31], 1);
return waitpid(a1[31], stat_loc, 0);
}

original_code:
static void close_compressed(SOURCE *s)
{
  COMPRESSED_SOURCE *cs = (COMPRESSED_SOURCE *)s;
  int status;
  if (cs->write_pipe >= 0)
    close(cs->write_pipe);
  if (cs->read_pipe >= 0)
    close(cs->read_pipe);
  kill(cs->pid, 1);
  waitpid(cs->pid, &status, 0);
}

canonical_original_code:
static void close_compressed(struct source *s)
{
  struct compressed_source *cs = (COMPRESSED_SOURCE *)s;
  int status;
  if (cs->write_pipe >= 0)
    close(cs->write_pipe);
  if (cs->read_pipe >= 0)
    close(cs->read_pipe);
  kill(cs->pid, 1);
  waitpid(cs->pid, &status, 0);
}

variable_types: struct compressed_source { struct source { unsigned long long size; int size_known; void *cache_head; int sequential; unsigned long long seq_pos; int blocksize; struct source *foundation; int (*analyze)(struct source *s, int level); unsigned long long (*read_bytes)(struct source *s, unsigned long long pos, unsigned long long len, void *buf); int (*read_block)(struct source *s, unsigned long long pos, void *buf); void (*close)(struct source *s); } c; unsigned long long offset; int write_pipe; int pid; } *

variable_types: status int

user_defined_types: struct compressed_source { struct source c; unsigned long long offset; int write_pipe; int pid; }


original_code:
static u8 read_compressed(SOURCE *s, u8 pos, u8 len, void *buf)
{
  COMPRESSED_SOURCE *cs = (COMPRESSED_SOURCE *)s;
  SOURCE *fs = s->foundation;
  char *p, *filebuf;
  u8 got, fill;
  int askfor, selresult;
  ssize_t result;
  fd_set read_set;
  fd_set write_set;
  p = (char *)buf;
  got = 0;
  if (cs->read_pipe < 0)
    return got;
  while (got < len) {
    result = read(cs->read_pipe, p, len - got);
    if (result == 0) {
      s->size_known = 1;
      s->size = s->seq_pos + got;
      close(cs->read_pipe);
      cs->read_pipe = -1;
      break;
    } else if (result > 0) {
      p += result;
      got += result;
      continue;
    } else {
      if ((*__errno_location ()) == 4)
 continue;
      if ((*__errno_location ()) != 11) {
 errore("read from pipe");
 break;
      }
    }
    askfor = 4096;
    if (cs->write_max && cs->write_pos + askfor > cs->write_max)
      askfor = cs->write_max - cs->write_pos;
    if (askfor <= 0 && cs->write_pipe >= 0) {
      close(cs->write_pipe);
      cs->write_pipe = -1;
    }
    if (cs->write_pipe < 0) {
      do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_set)->__fds_bits)[0]) : "memory"); } while (0);
      ((void) (((&read_set)->__fds_bits)[((cs->read_pipe) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cs->read_pipe) % (8 * (int) sizeof (__fd_mask)))))));
      selresult = select(cs->nfds, &read_set, ((void *)0), ((void *)0), ((void *)0));
      if (selresult < 0 && (*__errno_location ()) != 4) {
 errore("select");
 break;
      }
      continue;
    }
    fill = get_buffer_real(fs, cs->offset + cs->write_pos, askfor,
      ((void *)0), (void **)&filebuf);
    if (fill < askfor) {
      cs->write_max = cs->write_pos + fill;
    }
    if (fill <= 0) {
      continue;
    }
    result = write(cs->write_pipe, filebuf, fill);
    if (result >= 0) {
      cs->write_pos += result;
      continue;
    } else {
      if ((*__errno_location ()) == 4)
 continue;
      if ((*__errno_location ()) != 11) {
 errore("write to pipe");
 break;
      }
    }
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_set)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0, __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&write_set)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&read_set)->__fds_bits)[((cs->read_pipe) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cs->read_pipe) % (8 * (int) sizeof (__fd_mask)))))));
    ((void) (((&write_set)->__fds_bits)[((cs->write_pipe) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cs->write_pipe) % (8 * (int) sizeof (__fd_mask)))))));
    selresult = select(cs->nfds, &read_set, &write_set, ((void *)0), ((void *)0));
    if (selresult < 0 && (*__errno_location ()) != 4) {
      errore("select");
      break;
    }
  }
  return got;
}

canonical_original_code:
static unsigned long long read_compressed(struct source *s, unsigned long long pos, unsigned long long len, void *buf)
{
  struct compressed_source *cs = (COMPRESSED_SOURCE *)s;
  struct source *fs = s->foundation;
  char *p; char *filebuf;
  unsigned long long got; unsigned long long fill;
  int askfor; int selresult;
  long result;
  struct fd_set read_set;
  struct fd_set write_set;
  p = (char *)buf;
  got = 0;
  if (cs->read_pipe < 0)
    return got;
  while (got < len) {
    result = read(cs->read_pipe, p, len - got);
    if (result == 0) {
      s->size_known = 1;
      s->size = s->seq_pos + got;
      close(cs->read_pipe);
      cs->read_pipe = -1;
      break;
    } else if (result > 0) {
      p += result;
      got += result;
      continue;
    } else {
      if ((*__errno_location ()) == 4)
 continue;
      if ((*__errno_location ()) != 11) {
 errore("read from pipe");
 break;
      }
    }
    askfor = 4096;
    if (cs->write_max && cs->write_pos + askfor > cs->write_max)
      askfor = cs->write_max - cs->write_pos;
    if (askfor <= 0 && cs->write_pipe >= 0) {
      close(cs->write_pipe);
      cs->write_pipe = -1;
    }
    if (cs->write_pipe < 0) {
      do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_set)->__fds_bits)[0]) : "memory"); } while (0);
      ((void) (((&read_set)->__fds_bits)[((cs->read_pipe) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cs->read_pipe) % (8 * (int) sizeof (__fd_mask)))))));
      selresult = select(cs->nfds, &read_set, ((void *)0), ((void *)0), ((void *)0));
      if (selresult < 0 && (*__errno_location ()) != 4) {
 errore("select");
 break;
      }
      continue;
    }
    fill = get_buffer_real(fs, cs->offset + cs->write_pos, askfor,
      ((void *)0), (void **)&filebuf);
    if (fill < askfor) {
      cs->write_max = cs->write_pos + fill;
    }
    if (fill <= 0) {
      continue;
    }
    result = write(cs->write_pipe, filebuf, fill);
    if (result >= 0) {
      cs->write_pos += result;
      continue;
    } else {
      if ((*__errno_location ()) == 4)
 continue;
      if ((*__errno_location ()) != 11) {
 errore("write to pipe");
 break;
      }
    }
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&read_set)->__fds_bits)[0]) : "memory"); } while (0);
    do { int __d0; int __d1; __asm__ __volatile__ ("cld; rep; " "stosq" : "=c" (__d0), "=D" (__d1) : "a" (0), "0" (sizeof (fd_set) / sizeof (__fd_mask)), "1" (&((&write_set)->__fds_bits)[0]) : "memory"); } while (0);
    ((void) (((&read_set)->__fds_bits)[((cs->read_pipe) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cs->read_pipe) % (8 * (int) sizeof (__fd_mask)))))));
    ((void) (((&write_set)->__fds_bits)[((cs->write_pipe) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((cs->write_pipe) % (8 * (int) sizeof (__fd_mask)))))));
    selresult = select(cs->nfds, &read_set, &write_set, ((void *)0), ((void *)0));
    if (selresult < 0 && (*__errno_location ()) != 4) {
      errore("select");
      break;
    }
  }
  return got;
}

variable_types:
pos
unsigned long long

variable_types:
len
unsigned long long

variable_types:
buf
void *

variable_types:
p
char *

variable_types:
filebuf
char *

variable_types:
got
unsigned long long

variable_types:
fill
unsigned long long

variable_types: askfor int

variable_types: selresult int

variable_types: result long

return_type: unsigned long long


decompiled_code:
int __fastcall detect_cloop(__int64 a1, unsigned int a2)
{
unsigned __int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // rax
char v6[264]; // [rsp+0h] [rbp-128h] BYREF
void *s1; // [rsp+108h] [rbp-20h] BYREF

v2 = get_buffer(a1, 0LL, "e size %s", (const char *)&s1);
if ( v2 > 0xFF )
{
LODWORD(v2) = memcmp(s1, "#!/bin/sh\n#V2.0 Format\nmodprobe cloop", 0x25uLL);
if ( !(_DWORD)v2 )
{
print_line(a2, "Linux cloop 2.0 image");
v3 = get_be_long((char *)s1 + 128);
v4 = get_be_long((char *)s1 + 132);
format_blocky_size(v6, v4, v3, "blocks", 0LL);
LODWORD(v2) = print_line(a2 + 1, "Volume size %s", v6);
}
}
return v2;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, unsigned int a2)
{
unsigned __int64 v2; // rax
__int64 v3; // rbp
__int64 v4; // rax
char v6[264]; // [rsp+0h] [rbp-128h] BYREF
void *s1; // [rsp+108h] [rbp-20h] BYREF

v2 = get_buffer(a1, 0LL, "e size %s", (const char *)&s1);
if ( v2 > 0xFF )
{
LODWORD(v2) = memcmp(s1, "#!/bin/sh\n#V2.0 Format\nmodprobe cloop", 0x25uLL);
if ( !(_DWORD)v2 )
{
print_line(a2, "Linux cloop 2.0 image");
v3 = get_be_long((char *)s1 + 128);
v4 = get_be_long((char *)s1 + 132);
format_blocky_size(v6, v4, v3, "blocks", 0LL);
LODWORD(v2) = print_line(a2 + 1, "Volume size %s", v6);
}
}
return v2;
}

original_code:
void detect_cloop(SECTION *section, int level)
{
  unsigned char *buf;
  u4 blocksize, blockcount;
  char s[256];
  const char *sig_20 = "#!/bin/sh\n#V2.0 Format\nmodprobe cloop";
  if (get_buffer(section, 0, 256, (void **)&buf) < 256)
    return;
  if (memcmp(buf, sig_20, strlen(sig_20)) != 0)
    return;
  print_line(level, "Linux cloop 2.0 image");
  blocksize = get_be_long(buf + 128);
  blockcount = get_be_long(buf + 132);
  format_blocky_size(s, blockcount, blocksize, "blocks", ((void *)0));
  print_line(level + 1, "Volume size %s", s);
}

canonical_original_code:
void detect_cloop(struct section *section, int level)
{
  unsigned char *buf;
  unsigned long blocksize; unsigned long blockcount;
  char s[256];
  char *sig_20 = "#!/bin/sh\n#V2.0 Format\nmodprobe cloop";
  if (get_buffer(section, 0, 256, (void **)&buf) < 256)
    return;
  if (memcmp(buf, sig_20, strlen(sig_20)) != 0)
    return;
  print_line(level, "Linux cloop 2.0 image");
  blocksize = get_be_long(buf + 128);
  blockcount = get_be_long(buf + 132);
  format_blocky_size(s, blockcount, blocksize, "blocks", ((void *)0));
  print_line(level + 1, "Volume size %s", s);
}

variable_types: struct section { unsigned long long pos; int flags; struct source { unsigned long long size; int size_known; void *cache_head; int sequential; unsigned long long seq_pos; int blocksize; struct source *foundation; int (*analyze)(struct source *s, int level); unsigned long long (*read_bytes)(struct source *s, unsigned long long pos, unsigned long long len, void *buf); int (*read_block)(struct source *s, unsigned long long pos, void *buf); void (*close)(struct source *s); } *source; } *

variable_types:
buf
unsigned char *

variable_types:
blocksize
unsigned long

variable_types:
blockcount
unsigned long

variable_types:
s
char [256]


chmod

repo: russdill/ncsvc-socks-wrapper

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

if ( !orig_chmod_4 )
orig_chmod_4 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "chmod");
result = 0LL;
if ( !ignore_fs )
result = orig_chmod_4(a1, a2);
return result;
}

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

if ( !orig_chmod_4 )
orig_chmod_4 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "chmod");
result = 0LL;
if ( !ignore_fs )
result = orig_chmod_4(a1, a2);
return result;
}

original_code:
int chmod(const char *file, mode_t mode)
{
 static int (*orig_chmod)(const char *file, mode_t mode);
 do { if (!orig_chmod) orig_chmod = dlsym(((void *) -1l), "chmod"); } while (0);
 do {} while(0);
 return ignore_fs ? 0 : orig_chmod(file, mode);
}

canonical_original_code:
int chmod(char *file, unsigned int mode)
{
 static int (*orig_chmod)(char *file, unsigned int mode);
 do { if (!orig_chmod) orig_chmod = dlsym(((void *) -1l), "chmod"); } while (0);
 do {} while(0);
 return ignore_fs ? 0 : orig_chmod(file, mode);
}

variable_types:
file
char *

variable_types:
mode
unsigned int


chown

decompiled_code:
__int64 __fastcall chown(__int64 a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax

if ( !orig_chown_3 )
orig_chown_3 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "chown");
result = 0LL;
if ( !ignore_fs )
result = orig_chown_3(a1, a2, a3);
return result;
}

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

if ( !orig_chown_3 )
orig_chown_3 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "chown");
result = 0LL;
if ( !ignore_fs )
result = orig_chown_3(a1, a2, a3);
return result;
}

original_code:
int chown(const char *file, uid_t owner, gid_t group)
{
 static int (*orig_chown)(const char *file, uid_t owner, gid_t group);
 do { if (!orig_chown) orig_chown = dlsym(((void *) -1l), "chown"); } while (0);
 do {} while(0);
 return ignore_fs ? 0 : orig_chown(file, owner, group);
}

canonical_original_code:
int chown(char *file, unsigned int owner, unsigned int group)
{
 static int (*orig_chown)(char *file, unsigned int owner, unsigned int group);
 do { if (!orig_chown) orig_chown = dlsym(((void *) -1l), "chown"); } while (0);
 do {} while(0);
 return ignore_fs ? 0 : orig_chown(file, owner, group);
}

variable_types:
owner
unsigned int

variable_types:
group
unsigned int

variable_types: int (*)(char *file, unsigned int owner, unsigned int group)


mkdir

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

if ( !orig_mkdir_2 )
orig_mkdir_2 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "mkdir");
result = 0LL;
if ( !ignore_fs )
result = orig_mkdir_2(a1, a2);
return result;
}

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

if ( !orig_mkdir_2 )
orig_mkdir_2 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "mkdir");
result = 0LL;
if ( !ignore_fs )
result = orig_mkdir_2(a1, a2);
return result;
}

original_code:
int mkdir(const char *path, mode_t mode)
{
 static int (*orig_mkdir)(const char *path, mode_t mode);
 do { if (!orig_mkdir) orig_mkdir = dlsym(((void *) -1l), "mkdir"); } while (0);
 do {} while(0);
 return ignore_fs ? 0 : orig_mkdir(path, mode);
}

canonical_original_code:
int mkdir(char *path, unsigned int mode)
{
 static int (*orig_mkdir)(char *path, unsigned int mode);
 do { if (!orig_mkdir) orig_mkdir = dlsym(((void *) -1l), "mkdir"); } while (0);
 do {} while(0);
 return ignore_fs ? 0 : orig_mkdir(path, mode);
}

variable_types:
path
char *


unlink

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

if ( !orig_unlink_1 )
orig_unlink_1 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "unlink");
result = 0LL;
if ( !ignore_fs )
result = orig_unlink_1(a1);
return result;
}

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

if ( !orig_unlink_1 )
orig_unlink_1 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "unlink");
result = 0LL;
if ( !ignore_fs )
result = orig_unlink_1(a1);
return result;
}

original_code:
int unlink(const char *name)
{
 static int (*orig_unlink)(const char *name);
 do { if (!orig_unlink) orig_unlink = dlsym(((void *) -1l), "unlink"); } while (0);
 do {} while(0);
 return ignore_fs ? 0 : orig_unlink(name);
}

canonical_original_code:
int unlink(char *name)
{
 static int (*orig_unlink)(char *name);
 do { if (!orig_unlink) orig_unlink = dlsym(((void *) -1l), "unlink"); } while (0);
 do {} while(0);
 return ignore_fs ? 0 : orig_unlink(name);
}

variable_types:
name
char *


rename

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

if ( !orig_rename_0 )
orig_rename_0 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "rename");
result = 0LL;
if ( !ignore_fs )
result = orig_rename_0(a1, a2);
return result;
}

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

if ( !orig_rename_0 )
orig_rename_0 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "rename");
result = 0LL;
if ( !ignore_fs )
result = orig_rename_0(a1, a2);
return result;
}

original_code:
int rename(const char *old, const char *_new)
{
 static int (*orig_rename)(const char *old, const char *_new);
 do { if (!orig_rename) orig_rename = dlsym(((void *) -1l), "rename"); } while (0);
 return ignore_fs ? 0 : orig_rename(old, _new);
}

canonical_original_code:
int rename(char *old, char *_new)
{
 static int (*orig_rename)(char *old, char *_new);
 do { if (!orig_rename) orig_rename = dlsym(((void *) -1l), "rename"); } while (0);
 return ignore_fs ? 0 : orig_rename(old, _new);
}

variable_types:
old
char *


decompiled_code:
void set_ignore_fs()
{
ignore_fs = 1;
}

canonical_decompiled_code:
void func5()
{
ignore_fs = 1;
}

original_code:
void set_ignore_fs(void)
{
 ignore_fs = 1;
}

canonical_original_code:
void set_ignore_fs()
{
 ignore_fs = 1;
}


sigaddset

decompiled_code:
__int64 __fastcall sigaddset(__int64 a1, unsigned int a2)
{
if ( !orig_sigaddset_5 )
orig_sigaddset_5 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sigaddset");
return orig_sigaddset_5(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, unsigned int a2)
{
if ( !orig_sigaddset_5 )
orig_sigaddset_5 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sigaddset");
return orig_sigaddset_5(a1, a2);
}

original_code:
int sigaddset(sigset_t *set, int signo)
{
 static int (*orig_sigaddset)(sigset_t *set, int signo);
 do { if (!orig_sigaddset) orig_sigaddset = dlsym(((void *) -1l), "sigaddset"); } while (0);
 return orig_sigaddset(set, signo);
}

canonical_original_code:
int sigaddset(struct __sigset_t *set, int signo)
{
 static int (*orig_sigaddset)(struct __sigset_t *set, int signo);
 do { if (!orig_sigaddset) orig_sigaddset = dlsym(((void *) -1l), "sigaddset"); } while (0);
 return orig_sigaddset(set, signo);
}

variable_types: signo int

variable_types: int (*)(struct __sigset_t { unsigned long __val[-1]; } *set, int signo)


sigdelset

decompiled_code:
__int64 __fastcall sigdelset(__int64 a1, unsigned int a2)
{
if ( !orig_sigdelset_4 )
orig_sigdelset_4 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sigdelset");
return orig_sigdelset_4(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, unsigned int a2)
{
if ( !orig_sigdelset_4 )
orig_sigdelset_4 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sigdelset");
return orig_sigdelset_4(a1, a2);
}

original_code:
int sigdelset(sigset_t *set, int signo)
{
 static int (*orig_sigdelset)(sigset_t *set, int signo);
 do { if (!orig_sigdelset) orig_sigdelset = dlsym(((void *) -1l), "sigdelset"); } while (0);
 return orig_sigdelset(set, signo);
}

canonical_original_code:
int sigdelset(struct __sigset_t *set, int signo)
{
 static int (*orig_sigdelset)(struct __sigset_t *set, int signo);
 do { if (!orig_sigdelset) orig_sigdelset = dlsym(((void *) -1l), "sigdelset"); } while (0);
 return orig_sigdelset(set, signo);
}

variable_types: struct __sigset_t { unsigned long __val[-1]; } *


sigemptyset

decompiled_code:
__int64 __fastcall sigemptyset(__int64 a1)
{
if ( !orig_sigemptyset_3 )
orig_sigemptyset_3 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sigemptyset");
return orig_sigemptyset_3(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
if ( !orig_sigemptyset_3 )
orig_sigemptyset_3 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sigemptyset");
return orig_sigemptyset_3(a1);
}

original_code:
int sigemptyset(sigset_t *set)
{
 static int (*orig_sigemptyset)(sigset_t *set);
 do { if (!orig_sigemptyset) orig_sigemptyset = dlsym(((void *) -1l), "sigemptyset"); } while (0);
 return orig_sigemptyset(set);
}

canonical_original_code:
int sigemptyset(struct __sigset_t *set)
{
 static int (*orig_sigemptyset)(struct __sigset_t *set);
 do { if (!orig_sigemptyset) orig_sigemptyset = dlsym(((void *) -1l), "sigemptyset"); } while (0);
 return orig_sigemptyset(set);
}

variable_types: int (*)(struct __sigset_t { unsigned long __val[-1]; } *set)


sigismember

decompiled_code:
__int64 __fastcall sigismember(__int64 a1, unsigned int a2)
{
if ( !orig_sigismember_2 )
orig_sigismember_2 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sigismember");
return orig_sigismember_2(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, unsigned int a2)
{
if ( !orig_sigismember_2 )
orig_sigismember_2 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sigismember");
return orig_sigismember_2(a1, a2);
}

original_code:
int sigismember(const sigset_t *set, int signo)
{
 static int (*orig_sigismember)(const sigset_t *set, int signo);
 do { if (!orig_sigismember) orig_sigismember = dlsym(((void *) -1l), "sigismember"); } while (0);
 return orig_sigismember(set, signo);
}

canonical_original_code:
int sigismember(struct __sigset_t *set, int signo)
{
 static int (*orig_sigismember)(struct __sigset_t *set, int signo);
 do { if (!orig_sigismember) orig_sigismember = dlsym(((void *) -1l), "sigismember"); } while (0);
 return orig_sigismember(set, signo);
}

user_defined_types: struct __sigset_t { unsigned long __val[-1]; }


signal

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

if ( !orig_signal_1 )
orig_signal_1 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "signal");
result = 0LL;
if ( !sig_ignore )
result = orig_signal_1(a1, a2);
return result;
}

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

if ( !orig_signal_1 )
orig_signal_1 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "signal");
result = 0LL;
if ( !sig_ignore )
result = orig_signal_1(a1, a2);
return result;
}

original_code:
sighandler_t signal(int sig, sighandler_t handler)
{
 static sighandler_t (*orig_signal)(int sig, sighandler_t handler);
 do { if (!orig_signal) orig_signal = dlsym(((void *) -1l), "signal"); } while (0);
 do {} while(0);
 return sig_ignore ? 0 : orig_signal(sig, handler);
}

canonical_original_code:
void (*signal(int sig, void (*handler)(int)))(int)
{
 static void (*(*orig_signal)(int sig, void (*handler)(int)))(int);
 do { if (!orig_signal) orig_signal = dlsym(((void *) -1l), "signal"); } while (0);
 do {} while(0);
 return sig_ignore ? 0 : orig_signal(sig, handler);
}

variable_types: sig int

variable_types:
handler
void (*)(int)

variable_types: void (*(*)(int sig, void (*handler)(int)))(int)

return_type: void (*)(int)


sleep

decompiled_code:
__int64 __fastcall sleep(unsigned int a1)
{
if ( !orig_sleep_0 )
orig_sleep_0 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sleep");
return orig_sleep_0(a1);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1)
{
if ( !orig_sleep_0 )
orig_sleep_0 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "sleep");
return orig_sleep_0(a1);
}

original_code:
unsigned int sleep(unsigned int seconds)
{
 static unsigned int (*orig_sleep)(unsigned int seconds);
 do { if (!orig_sleep) orig_sleep = dlsym(((void *) -1l), "sleep"); } while (0);
 do {} while(0);
 return orig_sleep(seconds);
}

variable_types:
seconds
unsigned int

return_type: unsigned int


decompiled_code:
void signal_ignore_all()
{
sig_ignore = 1;
}

canonical_decompiled_code:
void func7()
{
sig_ignore = 1;
}

original_code:
void signal_ignore_all(void)
{
 sig_ignore = 1;
}


decompiled_code:
__int64 __fastcall real_socket(unsigned int a1, unsigned int a2, unsigned int a3)
{
if ( !orig_socket_10 )
orig_socket_10 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "socket");
return orig_socket_10(a1, a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, unsigned int a2, unsigned int a3)
{
if ( !orig_socket_10 )
orig_socket_10 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "socket");
return orig_socket_10(a1, a2, a3);
}

original_code:
int real_socket(int domain, int type, int protocol)
{
 static int (*orig_socket)(int domain, int type, int protocol);
 do { if (!orig_socket) orig_socket = dlsym(((void *) -1l), "socket"); } while (0);
 return orig_socket(domain, type, protocol);
}

variable_types: domain int

variable_types: type int

variable_types: protocol int

variable_types: int (*)(int domain, int type, int protocol)


accept

decompiled_code:
__int64 __fastcall accept(unsigned int a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( !orig_accept_9 )
orig_accept_9 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "accept");
result = fd_accept(a1, a2, a3);
if ( (_DWORD)result == -5555 )
result = orig_accept_9(a1, a2, a3);
return result;
}

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

if ( !orig_accept_9 )
orig_accept_9 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "accept");
result = fd_accept(a1, a2, a3);
if ( (_DWORD)result == -5555 )
result = orig_accept_9(a1, a2, a3);
return result;
}

original_code:
int accept(int fd, struct sockaddr *addr, socklen_t *addr_len)
{
 static int (*orig_accept)(int fd, struct sockaddr *addr, socklen_t*);
 int ret;
 do { if (!orig_accept) orig_accept = dlsym(((void *) -1l), "accept"); } while (0);
 ret = fd_accept(fd, addr, addr_len);
 if (ret == -5555)
  ret = orig_accept(fd, addr, addr_len);
 do {} while(0);
 return ret;
}

canonical_original_code:
int accept(int fd, struct sockaddr *addr, unsigned int *addr_len)
{
 static int (*orig_accept)(int fd, struct sockaddr *addr, unsigned int *);
 int ret;
 do { if (!orig_accept) orig_accept = dlsym(((void *) -1l), "accept"); } while (0);
 ret = fd_accept(fd, addr, addr_len);
 if (ret == -5555)
  ret = orig_accept(fd, addr, addr_len);
 do {} while(0);
 return ret;
}

variable_types: fd int

variable_types: int (*)(int fd, struct sockaddr { unsigned short sa_family; char sa_data[14]; } *addr, unsigned int *)

variable_types: ret int


bind

decompiled_code:
__int64 __fastcall bind(unsigned int a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax

if ( !orig_bind_8 )
orig_bind_8 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "bind");
result = fd_bind(a1, a2, a3);
if ( (_DWORD)result == -5555 )
result = orig_bind_8(a1, a2, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax

if ( !orig_bind_8 )
orig_bind_8 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "bind");
result = fd_bind(a1, a2, a3);
if ( (_DWORD)result == -5555 )
result = orig_bind_8(a1, a2, a3);
return result;
}

original_code:
int bind(int fd, const struct sockaddr *addr, socklen_t len)
{
 static int (*orig_bind)(int fd, const struct sockaddr *addr, socklen_t);
 int ret;
 do { if (!orig_bind) orig_bind = dlsym(((void *) -1l), "bind"); } while (0);
 ret = fd_bind(fd, addr, len);
 if (ret == -5555)
  ret = orig_bind(fd, addr, len);
 do {} while(0);
 return ret;
}

canonical_original_code:
int bind(int fd, struct sockaddr *addr, unsigned int len)
{
 static int (*orig_bind)(int fd, struct sockaddr *addr, unsigned int);
 int ret;
 do { if (!orig_bind) orig_bind = dlsym(((void *) -1l), "bind"); } while (0);
 ret = fd_bind(fd, addr, len);
 if (ret == -5555)
  ret = orig_bind(fd, addr, len);
 do {} while(0);
 return ret;
}

variable_types:
len
unsigned int

variable_types: int (*)(int fd, struct sockaddr { unsigned short sa_family; char sa_data[14]; } *addr, unsigned int)


connect

decompiled_code:
__int64 __fastcall connect(unsigned int a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax

if ( !orig_connect_7 )
orig_connect_7 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "connect");
result = fd_connect(a1, a2, a3);
if ( (_DWORD)result == -5555 )
result = orig_connect_7(a1, a2, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1, __int64 a2, unsigned int a3)
{
__int64 result; // rax

if ( !orig_connect_7 )
orig_connect_7 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "connect");
result = fd_connect(a1, a2, a3);
if ( (_DWORD)result == -5555 )
result = orig_connect_7(a1, a2, a3);
return result;
}

original_code:
int connect(int fd, const struct sockaddr *addr, socklen_t len)
{
 static int (*orig_connect)(int fd, const struct sockaddr*, socklen_t);
 int ret;
 do { if (!orig_connect) orig_connect = dlsym(((void *) -1l), "connect"); } while (0);
 ret = fd_connect(fd, addr, len);
 if (ret == -5555)
  ret = orig_connect(fd, addr, len);
 do {} while(0);
 return ret;
}

canonical_original_code:
int connect(int fd, struct sockaddr *addr, unsigned int len)
{
 static int (*orig_connect)(int fd, struct sockaddr *, unsigned int);
 int ret;
 do { if (!orig_connect) orig_connect = dlsym(((void *) -1l), "connect"); } while (0);
 ret = fd_connect(fd, addr, len);
 if (ret == -5555)
  ret = orig_connect(fd, addr, len);
 do {} while(0);
 return ret;
}

variable_types: int (*)(int fd, struct sockaddr { unsigned short sa_family; char sa_data[14]; } *, unsigned int)


listen

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

if ( !orig_listen_6 )
orig_listen_6 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "listen");
result = fd_listen(a1, a2);
if ( (_DWORD)result == -5555 )
result = orig_listen_6(a1, a2);
return result;
}

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

if ( !orig_listen_6 )
orig_listen_6 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "listen");
result = fd_listen(a1, a2);
if ( (_DWORD)result == -5555 )
result = orig_listen_6(a1, a2);
return result;
}

original_code:
int listen(int fd, int n)
{
 static int (*orig_listen)(int fd, int n);
 int ret;
 do { if (!orig_listen) orig_listen = dlsym(((void *) -1l), "listen"); } while (0);
 ret = fd_listen(fd, n);
 if (ret == -5555)
  ret = orig_listen(fd, n);
 do {} while(0);
 return ret;
}

variable_types: n int


socket

decompiled_code:
__int64 __fastcall socket(unsigned int a1, unsigned int a2, unsigned int a3)
{
__int64 result; // rax

result = fd_socket();
if ( (_DWORD)result == -5555 )
result = real_socket(a1, a2, a3);
return result;
}

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

result = fd_socket();
if ( (_DWORD)result == -5555 )
result = func0(a1, a2, a3);
return result;
}

original_code:
int socket(int domain, int type, int protocol)
{
 int ret;
 ret = fd_socket(domain, type, protocol);
 if (ret == -5555)
  ret = real_socket(domain, type, protocol);
 do {} while(0);
 return ret;
}


getsockopt

decompiled_code:
__int64 __fastcall getsockopt(unsigned int a1, unsigned int a2, unsigned int a3, __int64 a4, __int64 a5)
{
__int64 result; // rax

if ( !orig_getsockopt_5 )
orig_getsockopt_5 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD))dlsym(
(void *)0xFFFFFFFFFFFFFFFFLL,
"getsockopt");
result = fd_getsockopt(a1, a2, a3, a4, a5);
if ( (_DWORD)result == -5555 )
result = orig_getsockopt_5(a1, a2, a3, a4, a5);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, unsigned int a2, unsigned int a3, __int64 a4, __int64 a5)
{
__int64 result; // rax

if ( !orig_getsockopt_5 )
orig_getsockopt_5 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD))dlsym(
(void *)0xFFFFFFFFFFFFFFFFLL,
"getsockopt");
result = fd_getsockopt(a1, a2, a3, a4, a5);
if ( (_DWORD)result == -5555 )
result = orig_getsockopt_5(a1, a2, a3, a4, a5);
return result;
}

original_code:
int getsockopt(int fd, int level, int name, void *val, socklen_t *len)
{
 static int (*orig_getsockopt)(int, int, int, void*, socklen_t*);
 int ret;
 do { if (!orig_getsockopt) orig_getsockopt = dlsym(((void *) -1l), "getsockopt"); } while (0);
 ret = fd_getsockopt(fd, level, name, val, len);
 if (ret == -5555)
  ret = orig_getsockopt(fd, level, name, val, len);
 return ret;
}

canonical_original_code:
int getsockopt(int fd, int level, int name, void *val, unsigned int *len)
{
 static int (*orig_getsockopt)(int, int, int, void *, unsigned int *);
 int ret;
 do { if (!orig_getsockopt) orig_getsockopt = dlsym(((void *) -1l), "getsockopt"); } while (0);
 ret = fd_getsockopt(fd, level, name, val, len);
 if (ret == -5555)
  ret = orig_getsockopt(fd, level, name, val, len);
 return ret;
}

variable_types: level int

variable_types: name int

variable_types:
val
void *

variable_types:
len
unsigned int *

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


setsockopt

decompiled_code:
__int64 __fastcall setsockopt(unsigned int a1, unsigned int a2, unsigned int a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax

if ( !orig_setsockopt_4 )
orig_setsockopt_4 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD))dlsym(
(void *)0xFFFFFFFFFFFFFFFFLL,
"setsockopt");
result = fd_setsockopt(a1, a2, a3, a4, a5);
if ( (_DWORD)result == -5555 )
result = orig_setsockopt_4(a1, a2, a3, a4, a5);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned int a1, unsigned int a2, unsigned int a3, __int64 a4, unsigned int a5)
{
__int64 result; // rax

if ( !orig_setsockopt_4 )
orig_setsockopt_4 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD))dlsym(
(void *)0xFFFFFFFFFFFFFFFFLL,
"setsockopt");
result = fd_setsockopt(a1, a2, a3, a4, a5);
if ( (_DWORD)result == -5555 )
result = orig_setsockopt_4(a1, a2, a3, a4, a5);
return result;
}

original_code:
int setsockopt(int fd, int level, int name, const void *val, socklen_t len)
{
 static int (*orig_setsockopt)(int, int, int, const void*, socklen_t);
 int ret;
 do { if (!orig_setsockopt) orig_setsockopt = dlsym(((void *) -1l), "setsockopt"); } while (0);
 ret = fd_setsockopt(fd, level, name, val, len);
 if (ret == -5555)
  ret = orig_setsockopt(fd, level, name, val, len);
 return ret;
}

canonical_original_code:
int setsockopt(int fd, int level, int name, void *val, unsigned int len)
{
 static int (*orig_setsockopt)(int, int, int, void *, unsigned int);
 int ret;
 do { if (!orig_setsockopt) orig_setsockopt = dlsym(((void *) -1l), "setsockopt"); } while (0);
 ret = fd_setsockopt(fd, level, name, val, len);
 if (ret == -5555)
  ret = orig_setsockopt(fd, level, name, val, len);
 return ret;
}

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


getsockname

decompiled_code:
__int64 __fastcall getsockname(unsigned int a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( !orig_getsockname_3 )
orig_getsockname_3 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))dlsym(
(void *)0xFFFFFFFFFFFFFFFFLL,
"getsockname");
result = fd_getsockname(a1, a2, a3);
if ( (_DWORD)result == -5555 )
result = orig_getsockname_3(a1, a2, a3);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned int a1, __int64 a2, __int64 a3)
{
__int64 result; // rax

if ( !orig_getsockname_3 )
orig_getsockname_3 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD))dlsym(
(void *)0xFFFFFFFFFFFFFFFFLL,
"getsockname");
result = fd_getsockname(a1, a2, a3);
if ( (_DWORD)result == -5555 )
result = orig_getsockname_3(a1, a2, a3);
return result;
}

original_code:
int getsockname(int fd, struct sockaddr *addr, socklen_t *len)
{
 static int (*orig_getsockname)(int, struct sockaddr*, socklen_t*);
 int ret;
 do { if (!orig_getsockname) orig_getsockname = dlsym(((void *) -1l), "getsockname"); } while (0);
 ret = fd_getsockname(fd, addr, len);
 if (ret == -5555)
  ret = orig_getsockname(fd, addr, len);
 return ret;
}

canonical_original_code:
int getsockname(int fd, struct sockaddr *addr, unsigned int *len)
{
 static int (*orig_getsockname)(int, struct sockaddr *, unsigned int *);
 int ret;
 do { if (!orig_getsockname) orig_getsockname = dlsym(((void *) -1l), "getsockname"); } while (0);
 ret = fd_getsockname(fd, addr, len);
 if (ret == -5555)
  ret = orig_getsockname(fd, addr, len);
 return ret;
}

variable_types: int (*)(int, struct sockaddr { unsigned short sa_family; char sa_data[14]; } *, unsigned int *)


recvfrom

decompiled_code:
__int64 __fastcall recvfrom(unsigned int a1, __int64 a2, __int64 a3, unsigned int a4, __int64 a5, __int64 a6)
{
__int64 result; // rax

if ( !orig_recvfrom_2 )
orig_recvfrom_2 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD))dlsym(
(void *)0xFFFFFFFFFFFFFFFFLL,
"recvfrom");
LODWORD(result) = fd_recvfrom(a1, a2, a3, a4, a5, a6);
if ( (_DWORD)result == -5555 )
LODWORD(result) = orig_recvfrom_2(a1, a2, a3, a4, a5, a6);
return (int)result;
}

canonical_decompiled_code:
__int64 __fastcall func9(unsigned int a1, __int64 a2, __int64 a3, unsigned int a4, __int64 a5, __int64 a6)
{
__int64 result; // rax

if ( !orig_recvfrom_2 )
orig_recvfrom_2 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD, _QWORD, _QWORD))dlsym(
(void *)0xFFFFFFFFFFFFFFFFLL,
"recvfrom");
LODWORD(result) = fd_recvfrom(a1, a2, a3, a4, a5, a6);
if ( (_DWORD)result == -5555 )
LODWORD(result) = orig_recvfrom_2(a1, a2, a3, a4, a5, a6);
return (int)result;
}

original_code:
ssize_t recvfrom(int sockfd, void *buf, size_t len, int flags,
   struct sockaddr *src_addr, socklen_t *addrlen)
{
 static ssize_t (*orig_recvfrom)(int, void*, size_t, int,
    struct sockaddr*, socklen_t*);
 int ret;
 do { if (!orig_recvfrom) orig_recvfrom = dlsym(((void *) -1l), "recvfrom"); } while (0);
 ret = fd_recvfrom(sockfd, buf, len, flags, src_addr, addrlen);
 if (ret == -5555)
  ret = orig_recvfrom(sockfd, buf, len, flags, src_addr, addrlen);
 do {} while(0);
 return ret;
}

canonical_original_code:
long recvfrom(int sockfd, void *buf, unsigned long len, int flags, struct sockaddr *src_addr, unsigned int *addrlen)
{
 static long (*orig_recvfrom)(int, void *, unsigned long, int, struct sockaddr *, unsigned int *);
 int ret;
 do { if (!orig_recvfrom) orig_recvfrom = dlsym(((void *) -1l), "recvfrom"); } while (0);
 ret = fd_recvfrom(sockfd, buf, len, flags, src_addr, addrlen);
 if (ret == -5555)
  ret = orig_recvfrom(sockfd, buf, len, flags, src_addr, addrlen);
 do {} while(0);
 return ret;
}

variable_types: sockfd int

variable_types:
buf
void *

variable_types:
len
unsigned long

variable_types: flags int

variable_types:
addrlen
unsigned int *

variable_types: long (*)(int, void *, unsigned long, int, struct sockaddr { unsigned short sa_family; char sa_data[14]; } *, unsigned int *)

return_type: long


recv

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

if ( !orig_recv_1 )
orig_recv_1 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "recv");
LODWORD(result) = fd_recv(a1, a2, a3, a4);
if ( (_DWORD)result == -5555 )
LODWORD(result) = orig_recv_1(a1, a2, a3, a4);
return (int)result;
}

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

if ( !orig_recv_1 )
orig_recv_1 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "recv");
LODWORD(result) = fd_recv(a1, a2, a3, a4);
if ( (_DWORD)result == -5555 )
LODWORD(result) = orig_recv_1(a1, a2, a3, a4);
return (int)result;
}

original_code:
ssize_t recv(int sockfd, void *buf, size_t len, int flags)
{
 static ssize_t (*orig_recv)(int, void*, size_t, int);
 int ret;
 do { if (!orig_recv) orig_recv = dlsym(((void *) -1l), "recv"); } while (0);
 ret = fd_recv(sockfd, buf, len, flags);
 if (ret == -5555)
  ret = orig_recv(sockfd, buf, len, flags);
 do {} while(0);
 return ret;
}

canonical_original_code:
long recv(int sockfd, void *buf, unsigned long len, int flags)
{
 static long (*orig_recv)(int, void *, unsigned long, int);
 int ret;
 do { if (!orig_recv) orig_recv = dlsym(((void *) -1l), "recv"); } while (0);
 ret = fd_recv(sockfd, buf, len, flags);
 if (ret == -5555)
  ret = orig_recv(sockfd, buf, len, flags);
 do {} while(0);
 return ret;
}

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

variable_types: ret int


send

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

if ( !orig_send_0 )
orig_send_0 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "send");
LODWORD(result) = fd_send(a1, a2, a3, a4);
if ( (_DWORD)result == -5555 )
LODWORD(result) = orig_send_0(a1, a2, a3, a4);
return (int)result;
}

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

if ( !orig_send_0 )
orig_send_0 = (__int64 (__fastcall *)(_QWORD, _QWORD, _QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "send");
LODWORD(result) = fd_send(a1, a2, a3, a4);
if ( (_DWORD)result == -5555 )
LODWORD(result) = orig_send_0(a1, a2, a3, a4);
return (int)result;
}

original_code:
ssize_t send(int sockfd, const void *buf, size_t len, int flags)
{
 static ssize_t (*orig_send)(int, const void*, size_t, int);
 int ret;
 do { if (!orig_send) orig_send = dlsym(((void *) -1l), "send"); } while (0);
 ret = fd_send(sockfd, buf, len, flags);
 if (ret == -5555)
  ret = orig_send(sockfd, buf, len, flags);
 do {} while(0);
 return ret;
}

canonical_original_code:
long send(int sockfd, void *buf, unsigned long len, int flags)
{
 static long (*orig_send)(int, void *, unsigned long, int);
 int ret;
 do { if (!orig_send) orig_send = dlsym(((void *) -1l), "send"); } while (0);
 ret = fd_send(sockfd, buf, len, flags);
 if (ret == -5555)
  ret = orig_send(sockfd, buf, len, flags);
 do {} while(0);
 return ret;
}


setuid

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

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

original_code:
int setuid(uid_t uid)
{
 do {} while(0);
 return 0;
}

canonical_original_code:
int setuid(unsigned int uid)
{
 do {} while(0);
 return 0;
}

variable_types:
uid
unsigned int


decompiled_code:
__int64 tncc_init()
{
fd_grab(0LL, &stdin_listener);
return fd_listener_add(&tncc_listener);
}

canonical_decompiled_code:
__int64 func8()
{
fd_grab(0LL, &stdin_listener);
return fd_listener_add(&tncc_listener);
}

original_code:
__attribute__((constructor))
static void tncc_init(void)
{
 fd_grab(0, &stdin_listener);
 fd_listener_add(&tncc_listener);
}

canonical_original_code:
static void tncc_init()
{
 fd_grab(0, &stdin_listener);
 fd_listener_add(&tncc_listener);
}


open

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

if ( !orig_open_4 )
orig_open_4 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "open");
if ( (a2 & 0x40) != 0 )
{
result = fd_open(a1);
if ( (_DWORD)result != -5555 )
return result;
return orig_open_4(a1, a2);
}
result = fd_open(a1);
if ( (_DWORD)result == -5555 )
return orig_open_4(a1, a2);
return result;
}

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

if ( !orig_open_4 )
orig_open_4 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "open");
if ( (a2 & 0x40) != 0 )
{
result = fd_open(a1);
if ( (_DWORD)result != -5555 )
return result;
return orig_open_4(a1, a2);
}
result = fd_open(a1);
if ( (_DWORD)result == -5555 )
return orig_open_4(a1, a2);
return result;
}

original_code:
int open(const char *file, int oflag, ...)
{
 static int (*orig_open)(const char *file, int oflag, ...);
 int ret;
 do { if (!orig_open) orig_open = dlsym(((void *) -1l), "open"); } while (0);
 if (oflag & 0100) {
  mode_t mode;
  va_list ap;
  __builtin_va_start(ap,oflag);
  mode = __builtin_va_arg(ap,mode_t);
  __builtin_va_end(ap);
  ret = fd_open(file);
  if (ret == -5555)
   ret = orig_open(file, oflag, mode);
  do {} while(0);
 } else {
  ret = fd_open(file);
  if (ret == -5555)
   ret = orig_open(file, oflag);
  do {} while(0);
 }
 return ret;
}

canonical_original_code:
int open(char *file, int oflag, ...)
{
 static int (*orig_open)(char *file, int oflag, ...);
 int ret;
 do { if (!orig_open) orig_open = dlsym(((void *) -1l), "open"); } while (0);
 if (oflag & 0100) {
  unsigned int mode;
  __builtin_va_list ap;
  __builtin_va_start(ap,oflag);
  mode = __builtin_va_arg(ap,mode_t);
  __builtin_va_end(ap);
  ret = fd_open(file);
  if (ret == -5555)
   ret = orig_open(file, oflag, mode);
  do {} while(0);
 } else {
  ret = fd_open(file);
  if (ret == -5555)
   ret = orig_open(file, oflag);
  do {} while(0);
 }
 return ret;
}

variable_types:
file
char *

variable_types: oflag int

variable_types:
mode
unsigned int


decompiled_code:
__int64 __fastcall real_close(unsigned int a1)
{
if ( !orig_close_3 )
orig_close_3 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "close");
return orig_close_3(a1);
}

canonical_decompiled_code:
__int64 __fastcall func3(unsigned int a1)
{
if ( !orig_close_3 )
orig_close_3 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "close");
return orig_close_3(a1);
}

original_code:
int real_close(int fd)
{
 static int (*orig_close)(int fd);
 do { if (!orig_close) orig_close = dlsym(((void *) -1l), "close"); } while (0);
 return orig_close(fd);
}

variable_types: fd int


close

decompiled_code:
__int64 __fastcall close(unsigned int a1)
{
fd_close();
return real_close(a1);
}

canonical_decompiled_code:
__int64 __fastcall func4(unsigned int a1)
{
fd_close();
return func3(a1);
}

original_code:
int close(int fd)
{
 do {} while(0);
 fd_close(fd);
 return real_close(fd);
}


decompiled_code:
__int64 __fastcall real_dup2(unsigned int a1, unsigned int a2)
{
if ( !orig_dup2_2 )
orig_dup2_2 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "dup2");
return orig_dup2_2(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned int a1, unsigned int a2)
{
if ( !orig_dup2_2 )
orig_dup2_2 = (__int64 (__fastcall *)(_QWORD, _QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "dup2");
return orig_dup2_2(a1, a2);
}

original_code:
int real_dup2(int old, int _new)
{
 static int (*orig_dup2)(int, int);
 do { if (!orig_dup2) orig_dup2 = dlsym(((void *) -1l), "dup2"); } while (0);
 return orig_dup2(old, _new);
}

variable_types: old int


decompiled_code:
__int64 __fastcall dup2(unsigned int a1, unsigned int a2)
{
fd_close(a2);
return real_dup2(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func6(unsigned int a1, unsigned int a2)
{
fd_close(a2);
return func5(a1, a2);
}

original_code:
int dup2(int old, int _new)
{
 fd_close(_new);
 return real_dup2(old, _new);
}


decompiled_code:
void __fastcall system_set_intercept(__int64 a1)
{
system_intercept = a1;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1)
{
system_intercept = a1;
}

original_code:
void system_set_intercept(int (*_system)(const char *command))
{
 system_intercept = _system;
}

canonical_original_code:
void system_set_intercept(int (*_system)(char *command))
{
 system_intercept = _system;
}


system

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

if ( !orig_system_0 )
orig_system_0 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "system");
if ( system_intercept )
result = system_intercept(a1);
else
result = orig_system_0(a1);
return result;
}

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

if ( !orig_system_0 )
orig_system_0 = (__int64 (__fastcall *)(_QWORD))dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "system");
if ( system_intercept )
result = system_intercept(a1);
else
result = orig_system_0(a1);
return result;
}

original_code:
int system(const char *command)
{
 static int (*orig_system)(const char *command);
 do { if (!orig_system) orig_system = dlsym(((void *) -1l), "system"); } while (0);
 do {} while(0);
 if (system_intercept)
  return system_intercept(command);
 else
  return orig_system(command);
}

canonical_original_code:
int system(char *command)
{
 static int (*orig_system)(char *command);
 do { if (!orig_system) orig_system = dlsym(((void *) -1l), "system"); } while (0);
 do {} while(0);
 if (system_intercept)
  return system_intercept(command);
 else
  return orig_system(command);
}

variable_types:
command
char *