decompiled_code:
ssize_t __fastcall dump_raw(unsigned int a1, unsigned int a2)
{
unsigned int v3; // ebp
ssize_t result; // rax
const void *v5; // r12
unsigned int v6; // ebx
__int64 v7; // rsi

v3 = a2;
result = (ssize_t)malloc(0x20000uLL);
if ( a2 )
{
v5 = (const void *)result;
do
{
v6 = 256;
v7 = a1;
if ( v3 <= 0x100 )
v6 = v3;
a1 += v6;
mfs_read_sectors(v5, v7, v6);
result = write(1, v5, (int)(v6 << 9));
v3 -= v6;
}
while ( v3 );
}
return result;
}

canonical_decompiled_code:
ssize_t __fastcall func1(unsigned int a1, unsigned int a2)
{
unsigned int v3; // ebp
ssize_t result; // rax
const void *v5; // r12
unsigned int v6; // ebx
__int64 v7; // rsi

v3 = a2;
result = (ssize_t)malloc(0x20000uLL);
if ( a2 )
{
v5 = (const void *)result;
do
{
v6 = 256;
v7 = a1;
if ( v3 <= 0x100 )
v6 = v3;
a1 += v6;
mfs_read_sectors(v5, v7, v6);
result = write(1, v5, (int)(v6 << 9));
v3 -= v6;
}
while ( v3 );
}
return result;
}

original_code:
static void dump_raw(u32 start, u32 count)
{
 int chunk = 256;
 void *buf = malloc(chunk*512);
 while (count) {
  int n = ((count)<(chunk)?(count):(chunk));
  mfs_read_sectors(buf, start, n);
  write(1, buf, n*512);
  start += n;
  count -= n;
 }
}

canonical_original_code:
static void dump_raw(unsigned int start, unsigned int count)
{
 int chunk = 256;
 void *buf = malloc(chunk*512);
 while (count) {
  int n = ((count)<(chunk)?(count):(chunk));
  mfs_read_sectors(buf, start, n);
  write(1, buf, n*512);
  start += n;
  count -= n;
 }
}

variable_types:
start
unsigned int

variable_types:
count
unsigned int

variable_types: chunk int

variable_types: n int


usage

decompiled_code:
void __noreturn usage()
{
puts("\nusage: mfs_dump [options] <sector> <count>\n\noptions:\n -R raw data");
credits();
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts("\nusage: mfs_dump [options] <sector> <count>\n\noptions:\n -R raw data");
credits();
exit(1);
}

original_code:
static void usage(void)
{
 printf("\nusage: mfs_dump [options] <sector> <count>\n\noptions:\n        -R            raw data\n");
 credits();
 exit(1);
}

canonical_original_code:
static void usage()
{
 printf("\nusage: mfs_dump [options] <sector> <count>\n\noptions:\n        -R            raw data\n");
 credits();
 exit(1);
}

return_type: void


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
const char **v5; // r13
unsigned int v6; // ebp
unsigned int v7; // ebx
void *v8; // r12

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "R");
if ( v4 == -1 )
break;
v3 = 1;
if ( v4 != 82 )
goto LABEL_9;
}
v5 = &argv[optind];
if ( argc - optind <= 1 )
LABEL_9:
usage();
v6 = strtol(*v5, 0LL, 0);
v7 = strtol(v5[1], 0LL, 0);
mfs_init();
if ( v3 )
{
dump_raw(v6, v7);
}
else
{
v8 = malloc(v7 << 9);
mfs_read_sectors(v8, v6, v7);
dump_sectors(v8, v7);
free(v8);
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
const char **v5; // r13
unsigned int v6; // ebp
unsigned int v7; // ebx
void *v8; // r12

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "R");
if ( v4 == -1 )
break;
v3 = 1;
if ( v4 != 82 )
goto LABEL_9;
}
v5 = &argv[optind];
if ( argc - optind <= 1 )
LABEL_9:
func0();
v6 = strtol(*v5, 0LL, 0);
v7 = strtol(v5[1], 0LL, 0);
mfs_init();
if ( v3 )
{
func1(v6, v7);
}
else
{
v8 = malloc(v7 << 9);
mfs_read_sectors(v8, v6, v7);
dump_sectors(v8, v7);
free(v8);
}
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 u32 start;
 u32 count;
 int c;
 int raw=0;
 while ((c = getopt(argc, argv, "R")) != -1 ){
  switch (c) {
  case 'R':
   raw=1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc < 2) {
  usage();
 }
 start = strtol(argv[0], ((void *)0), 0);
 count = strtol(argv[1], ((void *)0), 0);
 mfs_init();
 if (raw) {
  dump_raw(start, count);
 } else {
  void *buf = malloc(count*512);
  mfs_read_sectors(buf, start, count);
  dump_sectors(buf, count);
  free(buf);
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 unsigned int start;
 unsigned int count;
 int c;
 int raw = 0;
 while ((c = getopt(argc, argv, "R")) != -1 ){
  switch (c) {
  case 'R':
   raw=1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc < 2) {
  usage();
 }
 start = strtol(argv[0], ((void *)0), 0);
 count = strtol(argv[1], ((void *)0), 0);
 mfs_init();
 if (raw) {
  dump_raw(start, count);
 } else {
  void *buf = malloc(count*512);
  mfs_read_sectors(buf, start, count);
  dump_sectors(buf, count);
  free(buf);
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types: raw int

variable_types:
buf
void *

return_type: int


credits

decompiled_code:
size_t credits()
{
return fwrite(
"\n"
"Released under the Gnu GPL v2\n"
"Original mfs_* package by tridge at samba.org, January 2001\n"
"Modifications by:\n"
"\tadh, jamie, jbuehl, jdiner, jonbig, mbm, musclenerd, ppchacker\n"
"\tDaniel Gimpelevich (aka sn9), maxwells_daemon, JB6783,\n"
" and possibly others...\n"
"\n"
"\tA support thread is in the forums at dealdatabase.com\n",
1uLL,
0x13CuLL,
stderr);
}

canonical_decompiled_code:
size_t func0()
{
return fwrite(
"\n"
"Released under the Gnu GPL v2\n"
"Original mfs_* package by tridge at samba.org, January 2001\n"
"Modifications by:\n"
"\tadh, jamie, jbuehl, jdiner, jonbig, mbm, musclenerd, ppchacker\n"
"\tDaniel Gimpelevich (aka sn9), maxwells_daemon, JB6783,\n"
" and possibly others...\n"
"\n"
"\tA support thread is in the forums at dealdatabase.com\n",
1uLL,
0x13CuLL,
stderr);
}

original_code:
void credits(void)
{
 fprintf(stderr, "\nReleased under the Gnu GPL v2\nOriginal mfs_* package by tridge at samba.org, January 2001\nModifications by:\n	adh, jamie, jbuehl, jdiner, jonbig, mbm, musclenerd, ppchacker\n	Daniel Gimpelevich (aka sn9), maxwells_daemon, JB6783,\n        and possibly others...\n\n	A support thread is in the forums at dealdatabase.com\n");
}

canonical_original_code:
void credits()
{
 fprintf(stderr, "\nReleased under the Gnu GPL v2\nOriginal mfs_* package by tridge at samba.org, January 2001\nModifications by:\n	adh, jamie, jbuehl, jdiner, jonbig, mbm, musclenerd, ppchacker\n	Daniel Gimpelevich (aka sn9), maxwells_daemon, JB6783,\n        and possibly others...\n\n	A support thread is in the forums at dealdatabase.com\n");
}


decompiled_code:
int __fastcall dir_list(__int64 a1, int a2)
{
__int64 v2; // r12
int result; // eax
unsigned int v4; // ebp
__int64 v5; // r15
const char *v6; // rax
unsigned int *v7; // rbx
const char *v8; // r14
const char *v9; // rax
unsigned int v10; // ebp
const char **v11; // rbx
unsigned int v12[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v2 = mfs_dir(a1, v12);
printf("dir: fsid=%d count=%d\n", (unsigned int)a1, v12[0]);
if ( long_list )
result = puts(" fsid type size name\n -----------------------------------");
else
result = puts(" fsid type name\n -----------------------------------");
v4 = 0;
if ( v12[0] )
{
do
{
while ( 1 )
{
v7 = (unsigned int *)(v2 + 16LL * v4);
v8 = (const char *)*((_QWORD *)v7 + 1);
if ( !long_list )
break;
++v4;
v5 = mfs_fsid_size(*v7);
v6 = (const char *)mfs_type_string(*((unsigned __int8 *)v7 + 4));
printf(" %7d %-8s %10lld %s\n", *v7, v6, v5, v8);
result = v12[0];
if ( v12[0] <= v4 )
goto LABEL_8;
}
++v4;
v9 = (const char *)mfs_type_string(*((unsigned __int8 *)v7 + 4));
printf(" %7d %-8s %s\n", *v7, v9, v8);
result = v12[0];
}
while ( v12[0] > v4 );
LABEL_8:
if ( a2 && result )
{
v10 = 0;
do
{
v11 = (const char **)(v2 + 16LL * v10);
if ( *((_BYTE *)v11 + 4) == 4 )
{
printf("\n%s[%d]:\n", v11[1], *(unsigned int *)v11);
result = dir_list(*(unsigned int *)v11, 1LL);
}
++v10;
}
while ( v12[0] > v10 );
}
}
if ( v2 )
result = mfs_dir_free(v2);
return result;
}

canonical_decompiled_code:
int __fastcall func1(__int64 a1, int a2)
{
__int64 v2; // r12
int result; // eax
unsigned int v4; // ebp
__int64 v5; // r15
const char *v6; // rax
unsigned int *v7; // rbx
const char *v8; // r14
const char *v9; // rax
unsigned int v10; // ebp
const char **v11; // rbx
unsigned int v12[15]; // [rsp+Ch] [rbp-3Ch] BYREF

v2 = mfs_dir(a1, v12);
printf("dir: fsid=%d count=%d\n", (unsigned int)a1, v12[0]);
if ( long_list )
result = puts(" fsid type size name\n -----------------------------------");
else
result = puts(" fsid type name\n -----------------------------------");
v4 = 0;
if ( v12[0] )
{
do
{
while ( 1 )
{
v7 = (unsigned int *)(v2 + 16LL * v4);
v8 = (const char *)*((_QWORD *)v7 + 1);
if ( !long_list )
break;
++v4;
v5 = mfs_fsid_size(*v7);
v6 = (const char *)mfs_type_string(*((unsigned __int8 *)v7 + 4));
printf(" %7d %-8s %10lld %s\n", *v7, v6, v5, v8);
result = v12[0];
if ( v12[0] <= v4 )
goto LABEL_8;
}
++v4;
v9 = (const char *)mfs_type_string(*((unsigned __int8 *)v7 + 4));
printf(" %7d %-8s %s\n", *v7, v9, v8);
result = v12[0];
}
while ( v12[0] > v4 );
LABEL_8:
if ( a2 && result )
{
v10 = 0;
do
{
v11 = (const char **)(v2 + 16LL * v10);
if ( *((_BYTE *)v11 + 4) == 4 )
{
printf("\n%s[%d]:\n", v11[1], *(unsigned int *)v11);
result = func1(*(unsigned int *)v11, 1LL);
}
++v10;
}
while ( v12[0] > v10 );
}
}
if ( v2 )
result = mfs_dir_free(v2);
return result;
}

original_code:
static void dir_list(int fsid, int recurse)
{
 struct mfs_dirent *dir;
 u32 count, i;
 dir = mfs_dir(fsid, &count);
 printf("dir: fsid=%d count=%d\n", fsid, count);
 if (long_list) {
  printf("      fsid   type           size     name\n      -----------------------------------\n");
 } else {
  printf("      fsid   type     name\n      -----------------------------------\n");
 }
 for (i=0;i<count;i++) {
  if (long_list) {
   printf("   %7d   %-8s %10lld     %s\n",
          dir[i].fsid,
          mfs_type_string(dir[i].type),
          mfs_fsid_size(dir[i].fsid),
          dir[i].name);
  } else {
   printf("   %7d   %-8s %s\n",
          dir[i].fsid,
          mfs_type_string(dir[i].type),
          dir[i].name);
  }
 }
 if (recurse) {
  for (i=0;i<count;i++) {
   if (dir[i].type == 4) {
    printf("\n%s[%d]:\n",
           dir[i].name, dir[i].fsid);
    dir_list(dir[i].fsid, 1);
   }
  }
 }
 if (dir) mfs_dir_free(dir);
}

canonical_original_code:
static void dir_list(int fsid, int recurse)
{
 struct mfs_dirent *dir;
 unsigned int count; unsigned int i;
 dir = mfs_dir(fsid, &count);
 printf("dir: fsid=%d count=%d\n", fsid, count);
 if (long_list) {
  printf("      fsid   type           size     name\n      -----------------------------------\n");
 } else {
  printf("      fsid   type     name\n      -----------------------------------\n");
 }
 for (i=0;i<count;i++) {
  if (long_list) {
   printf("   %7d   %-8s %10lld     %s\n",
          dir[i].fsid,
          mfs_type_string(dir[i].type),
          mfs_fsid_size(dir[i].fsid),
          dir[i].name);
  } else {
   printf("   %7d   %-8s %s\n",
          dir[i].fsid,
          mfs_type_string(dir[i].type),
          dir[i].name);
  }
 }
 if (recurse) {
  for (i=0;i<count;i++) {
   if (dir[i].type == 4) {
    printf("\n%s[%d]:\n",
           dir[i].name, dir[i].fsid);
    dir_list(dir[i].fsid, 1);
   }
  }
 }
 if (dir) mfs_dir_free(dir);
}

variable_types: fsid int

variable_types: recurse int

variable_types: struct mfs_dirent { unsigned int fsid; unsigned char type; char *name; } *

variable_types:
i
unsigned int


usage

decompiled_code:
void __noreturn usage()
{
puts(
"\n"
"usage: mfs_ls [options] <path|fsid>\n"
"\n"
" -R recurse\n"
" -l long list (with size)");
credits();
exit(1);
}

canonical_decompiled_code:
void __noreturn func0()
{
puts(
"\n"
"usage: mfs_ls [options] <path|fsid>\n"
"\n"
" -R recurse\n"
" -l long list (with size)");
credits();
exit(1);
}

original_code:
static void usage(void)
{
 printf("\nusage: mfs_ls [options] <path|fsid>\n\n      -R                             recurse\n      -l                             long list (with size)\n");
 credits();
 exit(1);
}

canonical_original_code:
static void usage()
{
 printf("\nusage: mfs_ls [options] <path|fsid>\n\n      -R                             recurse\n      -l                             long list (with size)\n");
 credits();
 exit(1);
}


main

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

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "Rl");
if ( v4 == -1 )
break;
if ( v4 == 82 )
{
v3 = 1;
}
else
{
if ( v4 != 108 )
goto LABEL_9;
long_list = 1;
}
}
v5 = &argv[optind];
if ( argc - optind <= 0 )
LABEL_9:
usage();
mfs_init();
v6 = mfs_resolve(*v5);
dir_list(v6, v3);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // er12
int v4; // eax
const char **v5; // rbp
unsigned int v6; // eax

v3 = 0;
while ( 1 )
{
v4 = getopt(argc, (char *const *)argv, "Rl");
if ( v4 == -1 )
break;
if ( v4 == 82 )
{
v3 = 1;
}
else
{
if ( v4 != 108 )
goto LABEL_9;
long_list = 1;
}
}
v5 = &argv[optind];
if ( argc - optind <= 0 )
LABEL_9:
func0();
mfs_init();
v6 = mfs_resolve(*v5);
func1(v6, v3);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
 int fsid;
 int c;
 int recurse=0;
 while ((c = getopt(argc, argv, "Rl")) != -1 ){
  switch (c) {
  case 'R':
   recurse=1;
   break;
  case 'l':
   long_list=1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc < 1) {
  usage();
 }
 mfs_init();
 fsid = mfs_resolve(argv[0]);
 dir_list(fsid, recurse);
 return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
 int fsid;
 int c;
 int recurse = 0;
 while ((c = getopt(argc, argv, "Rl")) != -1 ){
  switch (c) {
  case 'R':
   recurse=1;
   break;
  case 'l':
   long_list=1;
   break;
  default:
   usage();
  }
 }
 argc -= optind;
 argv += optind;
 if (argc < 1) {
  usage();
 }
 mfs_init();
 fsid = mfs_resolve(argv[0]);
 dir_list(fsid, recurse);
 return 0;
}


decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebp
const char **v5; // r12
int v6; // er15
int v7; // ebx
unsigned int v8; // eax
int v9; // er14
__int64 v10; // rax
char v11; // cl
const char *v12; // r10
char v13; // cl
const char ***v14; // rbx
const char **v16; // r15
const char *v17; // r10
char v18; // dl
char v19; // cl
unsigned int v20; // er14
int v21; // ebx
const char **v22; // r15
const char *v23; // rcx
__int64 v24; // rdx
const char *v25; // rdi
const char **v26; // r15
int v27; // er14
unsigned int v28; // ebx
int v29; // eax
int v30; // ebx
const char *v31; // rbx
const char *v32; // rsi
bool v33; // zf
int v34; // eax
const char **v35; // r15
__int64 v36; // rbx
unsigned int v37; // er9
int v38; // edi
int v39; // eax
unsigned int v40; // [rsp+0h] [rbp-1048h]
unsigned int v41; // [rsp+8h] [rbp-1040h]
unsigned int v42; // [rsp+Ch] [rbp-103Ch]
char dest[4152]; // [rsp+10h] [rbp-1038h] BYREF

DEXUXDEBUGMODE = 0;
dest[0] = 0;
if ( argc <= 1 )
{
LABEL_28:
dexuxclose(v3, argv, envp);
return 0;
}
v42 = 0;
v5 = argv;
v6 = 1;
v41 = 0;
v7 = 1;
while ( 1 )
{
envp = (const char **)v7;
v12 = v5[v7];
v10 = v7;
if ( *v12 != 45 )
goto LABEL_3;
v13 = v12[1];
if ( !v13 )
{
v9 = v7 + 1;
if ( !v6 )
goto LABEL_14;
if ( DEXUXDEBUGMODE )
goto LABEL_33;
goto LABEL_5;
}
if ( v13 != 68 )
break;
DEXUXDEBUGMODE = 1;
if ( v6 )
goto LABEL_33;
argv = &v5[v10];
v9 = v7 + 1;
v11 = *v5[v7];
if ( v11 == 108 )
goto LABEL_56;
LABEL_10:
if ( v11 == 119 )
{
if ( argc == v9 )
{
v6 = 0;
v9 = argc + 1;
fwrite("Please specify save image filename to", 1uLL, 0x25uLL, stderr);
argv = (const char **)&algn_1;
fwrite(" be written to card\n", 1uLL, 0x14uLL, stderr);
goto LABEL_14;
}
v14 = (const char ***)&v5[v10 + 1];
if ( DEXUXDEBUGMODE )
fprintf(stderr, "dexwrite(%s)\n", (const char *)*v14);
argv = *v14;
v6 = 0;
v7 = v9 + 1;
dexwrite(v3, argv);
if ( argc <= v9 + 1 )
goto LABEL_26;
}
else
{
if ( v11 == 114 )
{
if ( argc == v9 )
goto LABEL_61;
v16 = &v5[v10 + 1];
v17 = *v16;
v18 = **v16;
if ( (unsigned __int8)(v18 - 49) > 8u )
{
LABEL_51:
if ( DEXUXDEBUGMODE )
{
fprintf(stderr, "dexreadfull(%d, %s)\n", v41, *v16);
v17 = *v16;
}
argv = (const char **)v41;
v6 = 0;
++v9;
dexreadfull(v3, v41, v17);
goto LABEL_14;
}
v19 = v17[1];
if ( v19 )
{
if ( (unsigned __int8)(v19 - 48) > 5u || v18 != 49 || v17[2] )
goto LABEL_51;
v20 = (char)(v19 - 38);
}
else
{
v20 = (char)(v18 - 48);
}
v21 = v7 + 2;
if ( argc == v21 )
{
LABEL_61:
v6 = 0;
v9 = argc + 1;
fwrite("Please specify filename to save the", 1uLL, 0x23uLL, stderr);
argv = (const char **)&algn_1;
fwrite(" image too\n", 1uLL, 0xBuLL, stderr);
goto LABEL_14;
}
v22 = &v5[v10 + 2];
if ( DEXUXDEBUGMODE )
fprintf(stderr, "dexreadsingle(%d, %d, %s)\n", v42, v20, *v22);
v23 = *v22;
argv = (const char **)v42;
v24 = v20;
v6 = 0;
v9 = v21 + 1;
dexreadsingle(v3, v42, v24, v23);
}
else
{
if ( v11 != 100 )
{
v6 = 0;
if ( v11 != 117 )
goto LABEL_14;
if ( argc != v9 )
{
v27 = v7;
v35 = argv;
v36 = (__int64)&v5[(_QWORD)envp + (unsigned int)(argc - 2 - v7) + 1];
while ( 1 )
{
argv = (const char **)v35[1];
v38 = v27++;
v39 = *(unsigned __int8 *)argv;
envp = (const char **)(unsigned int)(v39 - 49);
if ( (unsigned __int8)(v39 - 49) > 8u )
{
LABEL_101:
v6 = 0;
v9 = v38 + 1;
goto LABEL_14;
}
envp = (const char **)*((unsigned __int8 *)argv + 1);
if ( (_BYTE)envp )
{
if ( (unsigned __int8)((_BYTE)envp - 48) > 5u || (_BYTE)v39 != 49 || *((_BYTE *)argv + 2) )
goto LABEL_101;
v37 = (char)((_BYTE)envp - 38);
if ( DEXUXDEBUGMODE )
{
LABEL_95:
v40 = v37;
fprintf(stderr, "dexdelete(%d, 1)\n", v37);
v37 = v40;
goto LABEL_88;
}
}
else
{
v37 = (char)(v39 - 48);
if ( DEXUXDEBUGMODE )
goto LABEL_95;
}
LABEL_88:
argv = (const char **)v37;
++v35;
dexdelete(v3, v37, 1LL);
if ( v35 == (const char **)v36 )
goto LABEL_102;
}
}
LABEL_26:
if ( DEXUXDEBUGMODE )
{
argv = (const char **)&algn_1;
fwrite("dexuxclose()\n", 1uLL, 0xDuLL, stderr);
}
goto LABEL_28;
}
v25 = v5[v10 + 1];
if ( v25 )
{
v26 = argv;
v27 = v7;
while ( 1 )
{
v29 = *(unsigned __int8 *)v25;
v30 = v27++;
envp = (const char **)(unsigned int)(v29 - 49);
if ( (unsigned __int8)(v29 - 49) > 8u )
{
LABEL_100:
v6 = 0;
v9 = v30 + 1;
goto LABEL_14;
}
envp = (const char **)*((unsigned __int8 *)v25 + 1);
if ( (_BYTE)envp )
break;
v28 = (char)(v29 - 48);
if ( DEXUXDEBUGMODE )
goto LABEL_72;
LABEL_65:
argv = (const char **)v28;
++v26;
dexdelete(v3, v28, 0LL);
v25 = v26[1];
if ( !v25 )
{
LABEL_102:
v6 = 0;
v9 = v27 + 1;
goto LABEL_14;
}
}
argv = (const char **)(unsigned int)((_DWORD)envp - 48);
if ( (unsigned __int8)((_BYTE)envp - 48) > 5u || (_BYTE)v29 != 49 || v25[2] )
goto LABEL_100;
v28 = (char)((_BYTE)envp - 38);
if ( !DEXUXDEBUGMODE )
goto LABEL_65;
LABEL_72:
fprintf(stderr, "dexdelete(%d, 0)\n", v28);
goto LABEL_65;
}
v6 = 0;
}
LABEL_14:
v7 = v9;
if ( argc <= v9 )
goto LABEL_26;
}
}
v9 = v7 + 1;
if ( v13 == 100 )
{
if ( !v12[2] )
{
if ( argc != v9 )
{
argv = (const char **)v5[v10 + 1];
v9 = v7 + 2;
strncpy(dest, (const char *)argv, 0x1000uLL);
goto LABEL_14;
}
LABEL_60:
v9 = v7 + 2;
goto LABEL_14;
}
argv = (const char **)(v12 + 2);
strncpy(dest, v12 + 2, 0x1000uLL);
goto LABEL_14;
}
if ( v13 != 102 )
{
if ( v13 == 104 )
{
fprintf(stderr, "DEXUX client version %s\n", "0.5beta");
fprintf(stderr, "Written by %s\n", "William Ono and Ben Galliart");
fprintf(stderr, "Copyright %s\n", "2000");
fwrite("This program is covered by the General Public License\n\n", 1uLL, 0x37uLL, stderr);
fwrite("Command line options:\n", 1uLL, 0x16uLL, stderr);
fwrite(" -D -- debug messages (very messy)\n", 1uLL, 0x2FuLL, stderr);
fwrite(" -d [device] -- port that the card reader is connected\n", 1uLL, 0x3AuLL, stderr);
fwrite(" -f [format] -- format to save files blocks/cards which have been read\n", 1uLL, 0x4AuLL, stderr);
fwrite(" Formats available:\n", 1uLL, 0x17uLL, stderr);
fwrite(" Single game formats: psx, mcs, xpm\n", 1uLL, 0x28uLL, stderr);
fwrite(" NOTE: XPM is an image format\n", 1uLL, 0x21uLL, stderr);
fwrite(" Entire game card image formats: mcs, mc, ddf, vgs, gme\n\n", 1uLL, 0x3DuLL, stderr);
fwrite(" l[ist]\n", 1uLL, 9uLL, stderr);
fwrite(" r[ead] [block#] filename\n", 1uLL, 0x1BuLL, stderr);
fwrite(" w[rite] filename\n", 1uLL, 0x13uLL, stderr);
fwrite(" d[elete] block# [additional block#s]\n", 1uLL, 0x29uLL, stderr);
argv = (const char **)&algn_1;
fwrite(" u[ndelete] block# [addtional block#s]\n", 1uLL, 0x28uLL, stderr);
}
else
{
argv = (const char **)"Unknown option skipped: %s, -h to get help\n";
fprintf(stderr, "Unknown option skipped: %s, -h to get help\n", v5[v7]);
}
goto LABEL_14;
}
if ( argc == v9 )
goto LABEL_60;
v31 = v5[v10 + 1];
if ( !strcmp("mcd", v31) || !strcmp("mc", v31) || !strcmp("ddf", v31) )
{
v41 = 0;
v7 = v9;
}
else if ( !strcmp("vgs", v31) )
{
v41 = 1;
v7 = v9;
}
else if ( !strcmp("gme", v31) )
{
v41 = 2;
v7 = v9;
}
else if ( !strcmp("psx", v31) )
{
v42 = 0;
v7 = v9;
}
else if ( !strcmp("mcs", v31) )
{
v42 = 1;
v7 = v9;
}
else
{
v32 = v31;
v7 = v9;
v33 = strcmp("xpm", v32) == 0;
v34 = 2;
if ( !v33 )
v34 = v42;
v42 = v34;
}
LABEL_3:
if ( !v6 )
goto LABEL_9;
if ( !DEXUXDEBUGMODE )
goto LABEL_5;
LABEL_33:
fprintf(stderr, "dexuxopen(%s)\n", dest);
LABEL_5:
v8 = dexuxopen(dest);
v3 = v8;
if ( !DEXUXDEBUGMODE )
{
if ( (unsigned int)dexuxwake(v8) )
goto LABEL_43;
goto LABEL_7;
}
fwrite("dexuxwake()\n", 1uLL, 0xCuLL, stderr);
if ( !(unsigned int)dexuxwake(v3) )
{
LABEL_7:
if ( DEXUXDEBUGMODE )
{
fwrite("dexuxstatus()\n", 1uLL, 0xEuLL, stderr);
if ( !(unsigned int)dexuxstatus(v3) )
goto LABEL_9;
}
else if ( !(unsigned int)dexuxstatus(v3) )
{
goto LABEL_9;
}
fwrite("Please insert memory card\n", 1uLL, 0x1AuLL, stderr);
while ( (unsigned int)dexuxstatus(v3) )
usleep(0xC350u);
LABEL_9:
envp = (const char **)v7;
v9 = v7 + 1;
v10 = v7;
argv = &v5[v10];
v11 = *v5[v10];
if ( v11 == 108 )
{
if ( DEXUXDEBUGMODE )
{
LABEL_56:
argv = (const char **)&algn_1;
fwrite("dexlist()\n", 1uLL, 0xAuLL, stderr);
}
v6 = 0;
dexlist(v3);
goto LABEL_14;
}
goto LABEL_10;
}
LABEL_43:
fwrite("Fatal error: Could not find the DexDrive\n", 1uLL, 0x29uLL, stderr);
return 1;
}

original_code:
int main (int argc, char **argv) {
  char devport[4096];
  int argcnt, dexuxfd;
  int dexclosed = 1, fullsaveformat = 0, singlesaveformat = 0;
  DEXUXDEBUGMODE = 0;
  devport[0] = 0;
  for (argcnt = 1; argcnt < argc; argcnt++) {
    if ((argv[argcnt][0] == '-') && (argv[argcnt][1] != '\0')) {
      if (argv[argcnt][1] == 'D') {
        DEXUXDEBUGMODE = 1;
      } else if (argv[argcnt][1] == 'd') {
        if (argv[argcnt][2] == '\0') {
          argcnt++;
          if (argcnt == argc) continue;
          strncpy(devport, argv[argcnt], 4096);
          continue;
        } else {
          char *pargv;
          pargv = argv[argcnt];
          pargv++; pargv++;
          strncpy(devport, pargv, 4096);
          continue;
        }
      } else if (argv[argcnt][1] == 'f') {
        argcnt++;
        if (argcnt == argc) continue;
        if (strcmp("mcd", argv[argcnt]) == 0) {
          fullsaveformat=0;
        } else if (strcmp("mc", argv[argcnt]) == 0) {
          fullsaveformat=0;
        } else if (strcmp("ddf", argv[argcnt]) == 0) {
          fullsaveformat=0;
        } else if (strcmp("vgs", argv[argcnt]) == 0) {
          fullsaveformat=1;
        } else if (strcmp("gme", argv[argcnt]) == 0) {
          fullsaveformat=2;
        } else if (strcmp("psx", argv[argcnt]) == 0) {
          singlesaveformat=0;
        } else if (strcmp("mcs", argv[argcnt]) == 0) {
          singlesaveformat=1;
        } else if (strcmp("xpm", argv[argcnt]) == 0) {
          singlesaveformat=2;
        }
      } else if (argv[argcnt][1] == 'h') {
        fprintf(stderr, "DEXUX client version %s\n", "0.5beta");
        fprintf(stderr, "Written by %s\n", "William Ono and Ben Galliart");
        fprintf(stderr, "Copyright %s\n", "2000");
        fprintf(stderr, "This program is covered by the General Public License\n\n");
 fprintf(stderr, "Command line options:\n");
        fprintf(stderr, "  -D            -- debug messages (very messy)\n");
        fprintf(stderr, "  -d [device]   -- port that the card reader is connected\n");
 fprintf(stderr, "  -f [format]   -- format to save files blocks/cards which have been read\n");
        fprintf(stderr, "    Formats available:\n");
        fprintf(stderr, "    Single game formats:  psx, mcs, xpm\n");
        fprintf(stderr, "    NOTE: XPM is an image format\n");
        fprintf(stderr, "    Entire game card image formats:  mcs, mc, ddf, vgs, gme\n\n");
        fprintf(stderr, "  l[ist]\n");
        fprintf(stderr, "  r[ead] [block#] filename\n");
        fprintf(stderr, "  w[rite] filename\n");
        fprintf(stderr, "  d[elete]   block# [additional block#s]\n");
        fprintf(stderr, "  u[ndelete] block# [addtional block#s]\n");
        continue;
      } else {
        fprintf(stderr, "Unknown option skipped: %s, -h to get help\n", argv[argcnt]);
        continue;
      }
    }
    if (dexclosed) {
 if (DEXUXDEBUGMODE) fprintf(stderr, "dexuxopen(%s)\n", devport);
        dexuxfd = dexuxopen(devport);
        if (DEXUXDEBUGMODE) fprintf(stderr, "dexuxwake()\n");
        if (dexuxwake(dexuxfd)) {
          fprintf(stderr, "Fatal error: Could not find the DexDrive\n");
          return(1);
        }
        if (DEXUXDEBUGMODE) fprintf(stderr, "dexuxstatus()\n");
        if (dexuxstatus(dexuxfd)) {
          fprintf(stderr, "Please insert memory card\n");
          while (dexuxstatus(dexuxfd)) { usleep(50000); }
        }
 dexclosed = 0;
    }
    if (argv[argcnt][0] == 'l') {
      if (DEXUXDEBUGMODE) fprintf(stderr, "dexlist()\n");
      dexlist(dexuxfd);
      continue;
    } else if (argv[argcnt][0] == 'w') {
      argcnt++;
      if (argcnt == argc) {
        fprintf(stderr, "Please specify save image filename to");
        fprintf(stderr, " be written to card\n");
        continue;
      }
      if (DEXUXDEBUGMODE) fprintf(stderr, "dexwrite(%s)\n", argv[argcnt]);
      dexwrite(dexuxfd, argv[argcnt]);
      continue;
    } else if (argv[argcnt][0] == 'r') {
      int blocknum = 0;
      argcnt++;
      if (argcnt == argc) {
        fprintf(stderr, "Please specify filename to save the");
        fprintf(stderr, " image too\n");
        continue;
      }
      if ((argv[argcnt][0] >= '1') && (argv[argcnt][0] <= '9')) {
        if (argv[argcnt][1] == '\0') {
          blocknum = argv[argcnt][0] - '0';
        } else if ((argv[argcnt][0] == '1') &&
                   (argv[argcnt][1] >= '0') &&
                   (argv[argcnt][1] <= '5') &&
                   (argv[argcnt][2] == '\0')) {
          blocknum = 10 + argv[argcnt][1] - '0';
        }
      }
      if (blocknum == 0) {
 if (DEXUXDEBUGMODE) fprintf(stderr, "dexreadfull(%d, %s)\n",
   fullsaveformat, argv[argcnt]);
        dexreadfull(dexuxfd, fullsaveformat, argv[argcnt]);
      } else {
        argcnt++;
        if (argcnt == argc) {
          fprintf(stderr, "Please specify filename to save the");
          fprintf(stderr, " image too\n");
          continue;
        }
 if (DEXUXDEBUGMODE) fprintf(stderr, "dexreadsingle(%d, %d, %s)\n",
          singlesaveformat, blocknum, argv[argcnt]);
        dexreadsingle(dexuxfd, singlesaveformat, blocknum, argv[argcnt]);
      }
      continue;
    } else if (argv[argcnt][0] == 'd') {
      int blocknum = 16;
      while ((blocknum > 0) && (argv[argcnt + 1] != ((void *)0))) {
        if ((argv[argcnt + 1][0] >= '1') &&
            (argv[argcnt + 1][0] <= '9')) {
          if (argv[argcnt + 1][1] == '\0') {
            argcnt++;
            blocknum = argv[argcnt][0] - '0';
     if (DEXUXDEBUGMODE) fprintf(stderr, "dexdelete(%d, 0)\n", blocknum);
            dexdelete(dexuxfd, blocknum, 0);
          } else if ((argv[argcnt + 1][0] == '1') &&
                     (argv[argcnt + 1][1] >= '0') &&
                     (argv[argcnt + 1][1] <= '5') &&
                     (argv[argcnt + 1][2] == '\0')) {
            argcnt++;
            blocknum = 10 + argv[argcnt][1] - '0';
     if (DEXUXDEBUGMODE) fprintf(stderr, "dexdelete(%d, 0)\n", blocknum);
            dexdelete(dexuxfd, blocknum, 0);
          } else {
            blocknum = 0;
          }
        } else blocknum = 0;
      }
      continue;
    } else if (argv[argcnt][0] == 'u') {
      int blocknum = 16;
      while ((blocknum > 0) && (argcnt + 1 != argc)) {
        if ((argv[argcnt + 1][0] >= '1') &&
            (argv[argcnt + 1][0] <= '9')) {
          if (argv[argcnt + 1][1] == '\0') {
            argcnt++;
            blocknum = argv[argcnt][0] - '0';
     if (DEXUXDEBUGMODE) fprintf(stderr, "dexdelete(%d, 1)\n", blocknum);
            dexdelete(dexuxfd, blocknum, 1);
          } else if ((argv[argcnt + 1][0] == '1') &&
                     (argv[argcnt + 1][1] >= '0') &&
                     (argv[argcnt + 1][1] <= '5') &&
                     (argv[argcnt + 1][2] == '\0')) {
            argcnt++;
            blocknum = 10 + argv[argcnt][1] - '0';
     if (DEXUXDEBUGMODE) fprintf(stderr, "dexdelete(%d, 1)\n", blocknum);
            dexdelete(dexuxfd, blocknum, 1);
          } else {
            blocknum = 0;
          }
        } else blocknum = 0;
      }
      continue;
    }
  }
  if (DEXUXDEBUGMODE) fprintf(stderr, "dexuxclose()\n");
  dexuxclose(dexuxfd);
  return(0);
}

canonical_original_code:
int main(int argc, char **argv) {
  char devport[4096];
  int argcnt; int dexuxfd;
  int dexclosed = 1; int fullsaveformat = 0; int singlesaveformat = 0;
  DEXUXDEBUGMODE = 0;
  devport[0] = 0;
  for (argcnt = 1; argcnt < argc; argcnt++) {
    if ((argv[argcnt][0] == '-') && (argv[argcnt][1] != '\0')) {
      if (argv[argcnt][1] == 'D') {
        DEXUXDEBUGMODE = 1;
      } else if (argv[argcnt][1] == 'd') {
        if (argv[argcnt][2] == '\0') {
          argcnt++;
          if (argcnt == argc) continue;
          strncpy(devport, argv[argcnt], 4096);
          continue;
        } else {
          char *pargv;
          pargv = argv[argcnt];
          pargv++; pargv++;
          strncpy(devport, pargv, 4096);
          continue;
        }
      } else if (argv[argcnt][1] == 'f') {
        argcnt++;
        if (argcnt == argc) continue;
        if (strcmp("mcd", argv[argcnt]) == 0) {
          fullsaveformat=0;
        } else if (strcmp("mc", argv[argcnt]) == 0) {
          fullsaveformat=0;
        } else if (strcmp("ddf", argv[argcnt]) == 0) {
          fullsaveformat=0;
        } else if (strcmp("vgs", argv[argcnt]) == 0) {
          fullsaveformat=1;
        } else if (strcmp("gme", argv[argcnt]) == 0) {
          fullsaveformat=2;
        } else if (strcmp("psx", argv[argcnt]) == 0) {
          singlesaveformat=0;
        } else if (strcmp("mcs", argv[argcnt]) == 0) {
          singlesaveformat=1;
        } else if (strcmp("xpm", argv[argcnt]) == 0) {
          singlesaveformat=2;
        }
      } else if (argv[argcnt][1] == 'h') {
        fprintf(stderr, "DEXUX client version %s\n", "0.5beta");
        fprintf(stderr, "Written by %s\n", "William Ono and Ben Galliart");
        fprintf(stderr, "Copyright %s\n", "2000");
        fprintf(stderr, "This program is covered by the General Public License\n\n");
 fprintf(stderr, "Command line options:\n");
        fprintf(stderr, "  -D            -- debug messages (very messy)\n");
        fprintf(stderr, "  -d [device]   -- port that the card reader is connected\n");
 fprintf(stderr, "  -f [format]   -- format to save files blocks/cards which have been read\n");
        fprintf(stderr, "    Formats available:\n");
        fprintf(stderr, "    Single game formats:  psx, mcs, xpm\n");
        fprintf(stderr, "    NOTE: XPM is an image format\n");
        fprintf(stderr, "    Entire game card image formats:  mcs, mc, ddf, vgs, gme\n\n");
        fprintf(stderr, "  l[ist]\n");
        fprintf(stderr, "  r[ead] [block#] filename\n");
        fprintf(stderr, "  w[rite] filename\n");
        fprintf(stderr, "  d[elete]   block# [additional block#s]\n");
        fprintf(stderr, "  u[ndelete] block# [addtional block#s]\n");
        continue;
      } else {
        fprintf(stderr, "Unknown option skipped: %s, -h to get help\n", argv[argcnt]);
        continue;
      }
    }
    if (dexclosed) {
 if (DEXUXDEBUGMODE) fprintf(stderr, "dexuxopen(%s)\n", devport);
        dexuxfd = dexuxopen(devport);
        if (DEXUXDEBUGMODE) fprintf(stderr, "dexuxwake()\n");
        if (dexuxwake(dexuxfd)) {
          fprintf(stderr, "Fatal error: Could not find the DexDrive\n");
          return(1);
        }
        if (DEXUXDEBUGMODE) fprintf(stderr, "dexuxstatus()\n");
        if (dexuxstatus(dexuxfd)) {
          fprintf(stderr, "Please insert memory card\n");
          while (dexuxstatus(dexuxfd)) { usleep(50000); }
        }
 dexclosed = 0;
    }
    if (argv[argcnt][0] == 'l') {
      if (DEXUXDEBUGMODE) fprintf(stderr, "dexlist()\n");
      dexlist(dexuxfd);
      continue;
    } else if (argv[argcnt][0] == 'w') {
      argcnt++;
      if (argcnt == argc) {
        fprintf(stderr, "Please specify save image filename to");
        fprintf(stderr, " be written to card\n");
        continue;
      }
      if (DEXUXDEBUGMODE) fprintf(stderr, "dexwrite(%s)\n", argv[argcnt]);
      dexwrite(dexuxfd, argv[argcnt]);
      continue;
    } else if (argv[argcnt][0] == 'r') {
      int blocknum = 0;
      argcnt++;
      if (argcnt == argc) {
        fprintf(stderr, "Please specify filename to save the");
        fprintf(stderr, " image too\n");
        continue;
      }
      if ((argv[argcnt][0] >= '1') && (argv[argcnt][0] <= '9')) {
        if (argv[argcnt][1] == '\0') {
          blocknum = argv[argcnt][0] - '0';
        } else if ((argv[argcnt][0] == '1') &&
                   (argv[argcnt][1] >= '0') &&
                   (argv[argcnt][1] <= '5') &&
                   (argv[argcnt][2] == '\0')) {
          blocknum = 10 + argv[argcnt][1] - '0';
        }
      }
      if (blocknum == 0) {
 if (DEXUXDEBUGMODE) fprintf(stderr, "dexreadfull(%d, %s)\n",
   fullsaveformat, argv[argcnt]);
        dexreadfull(dexuxfd, fullsaveformat, argv[argcnt]);
      } else {
        argcnt++;
        if (argcnt == argc) {
          fprintf(stderr, "Please specify filename to save the");
          fprintf(stderr, " image too\n");
          continue;
        }
 if (DEXUXDEBUGMODE) fprintf(stderr, "dexreadsingle(%d, %d, %s)\n",
          singlesaveformat, blocknum, argv[argcnt]);
        dexreadsingle(dexuxfd, singlesaveformat, blocknum, argv[argcnt]);
      }
      continue;
    } else if (argv[argcnt][0] == 'd') {
      int blocknum = 16;
      while ((blocknum > 0) && (argv[argcnt + 1] != ((void *)0))) {
        if ((argv[argcnt + 1][0] >= '1') &&
            (argv[argcnt + 1][0] <= '9')) {
          if (argv[argcnt + 1][1] == '\0') {
            argcnt++;
            blocknum = argv[argcnt][0] - '0';
     if (DEXUXDEBUGMODE) fprintf(stderr, "dexdelete(%d, 0)\n", blocknum);
            dexdelete(dexuxfd, blocknum, 0);
          } else if ((argv[argcnt + 1][0] == '1') &&
                     (argv[argcnt + 1][1] >= '0') &&
                     (argv[argcnt + 1][1] <= '5') &&
                     (argv[argcnt + 1][2] == '\0')) {
            argcnt++;
            blocknum = 10 + argv[argcnt][1] - '0';
     if (DEXUXDEBUGMODE) fprintf(stderr, "dexdelete(%d, 0)\n", blocknum);
            dexdelete(dexuxfd, blocknum, 0);
          } else {
            blocknum = 0;
          }
        } else blocknum = 0;
      }
      continue;
    } else if (argv[argcnt][0] == 'u') {
      int blocknum = 16;
      while ((blocknum > 0) && (argcnt + 1 != argc)) {
        if ((argv[argcnt + 1][0] >= '1') &&
            (argv[argcnt + 1][0] <= '9')) {
          if (argv[argcnt + 1][1] == '\0') {
            argcnt++;
            blocknum = argv[argcnt][0] - '0';
     if (DEXUXDEBUGMODE) fprintf(stderr, "dexdelete(%d, 1)\n", blocknum);
            dexdelete(dexuxfd, blocknum, 1);
          } else if ((argv[argcnt + 1][0] == '1') &&
                     (argv[argcnt + 1][1] >= '0') &&
                     (argv[argcnt + 1][1] <= '5') &&
                     (argv[argcnt + 1][2] == '\0')) {
            argcnt++;
            blocknum = 10 + argv[argcnt][1] - '0';
     if (DEXUXDEBUGMODE) fprintf(stderr, "dexdelete(%d, 1)\n", blocknum);
            dexdelete(dexuxfd, blocknum, 1);
          } else {
            blocknum = 0;
          }
        } else blocknum = 0;
      }
      continue;
    }
  }
  if (DEXUXDEBUGMODE) fprintf(stderr, "dexuxclose()\n");
  dexuxclose(dexuxfd);
  return(0);
}

variable_types:
argv
char **

variable_types:
devport
char [4096]

variable_types: argcnt int

variable_types: dexuxfd int

variable_types: dexclosed int

variable_types: fullsaveformat int

variable_types: singlesaveformat int

variable_types:
pargv
char *

variable_types: blocknum int


dexuxbinreverse

original_code:
int dexuxbinreverse(int inbyte) {
  int outbyte;
  outbyte = (inbyte & 1) << 7;
  outbyte = outbyte + ((inbyte & 2) << 5);
  outbyte = outbyte + ((inbyte & 4) << 3);
  outbyte = outbyte + ((inbyte & 8) << 1);
  outbyte = outbyte + ((inbyte & 16) >> 1);
  outbyte = outbyte + ((inbyte & 32) >> 3);
  outbyte = outbyte + ((inbyte & 64) >> 5);
  outbyte = outbyte + ((inbyte & 128) >> 7);
  return(outbyte);
}

variable_types: inbyte int

variable_types: outbyte int


dexuxwake

decompiled_code:
__int64 __fastcall dexuxwake(int fd)
{
int v3; // ebx
char v4[8]; // [rsp+0h] [rbp-118h] BYREF
char v5; // [rsp+8h] [rbp-110h]

write(fd, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0x20uLL);
v4[(int)read(fd, v4, 4uLL)] = 0;
if ( memcmp(v4, "IAI!", 4uLL) )
return 1LL;
write(fd, &unk_248, 0x15uLL);
v4[(int)read(fd, v4, 9uLL)] = 0;
if ( DEXUXDEBUGMODE )
fprintf(
stderr,
"dexuxwake(): version responce: %.2x %.2x %.2x %.2x %.2x %.2x (firmware version 1.%d)\n",
(unsigned int)v4[3],
(unsigned int)v4[4],
(unsigned int)v4[5],
(unsigned int)v4[6],
(unsigned int)v4[7],
(unsigned int)v5,
(unsigned int)(v5 - 58));
if ( memcmp(v4, "IAI@\x1BPSXF", 8uLL) )
return 1LL;
v3 = 10;
do
{
write(fd, "IAI'", 4uLL);
tcdrain(fd);
usleep(0x3E8u);
dexuxclear((unsigned int)fd);
--v3;
}
while ( v3 );
write(fd, &unk_242, 5uLL);
v4[(int)read(fd, v4, 0xFEuLL)] = 0;
if ( v4[0] != 73 || v4[1] != 65 || v4[2] != 73 )
return 1LL;
dexuxclear((unsigned int)fd);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
int v3; // ebx
char v4[8]; // [rsp+0h] [rbp-118h] BYREF
char v5; // [rsp+8h] [rbp-110h]

write(fd, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 0x20uLL);
v4[(int)read(fd, v4, 4uLL)] = 0;
if ( memcmp(v4, "IAI!", 4uLL) )
return 1LL;
write(fd, &unk_248, 0x15uLL);
v4[(int)read(fd, v4, 9uLL)] = 0;
if ( DEXUXDEBUGMODE )
fprintf(
stderr,
"dexuxwake(): version responce: %.2x %.2x %.2x %.2x %.2x %.2x (firmware version 1.%d)\n",
(unsigned int)v4[3],
(unsigned int)v4[4],
(unsigned int)v4[5],
(unsigned int)v4[6],
(unsigned int)v4[7],
(unsigned int)v5,
(unsigned int)(v5 - 58));
if ( memcmp(v4, "IAI@\x1BPSXF", 8uLL) )
return 1LL;
v3 = 10;
do
{
write(fd, "IAI'", 4uLL);
tcdrain(fd);
usleep(0x3E8u);
dexuxclear((unsigned int)fd);
--v3;
}
while ( v3 );
write(fd, &unk_242, 5uLL);
v4[(int)read(fd, v4, 0xFEuLL)] = 0;
if ( v4[0] != 73 || v4[1] != 65 || v4[2] != 73 )
return 1LL;
dexuxclear((unsigned int)fd);
return 0LL;
}

original_code:
int dexuxwake(int fd) {
  char buffer[255];
  int readlength;
  int i;
  write(fd, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", 32);
  readlength = read(fd, &buffer, 4);
  buffer[readlength]='\0';
  if (strncmp(buffer, "IAI!", 4)) {
          return(1);
  }
  write(fd, "IAI\x00\x10\x29\x23\xBE\x84\xE1\x6C\xD6\xAE\x52\x90\x49\xF1\xF1\xBB\xE9\xEB", 21);
  readlength = read(fd, &buffer, 9);
  buffer[readlength]='\0';
  if (DEXUXDEBUGMODE) fprintf(stderr, "dexuxwake(): version responce: %.2x %.2x %.2x %.2x %.2x %.2x (firmware version 1.%d)\n", buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], buffer[8], buffer[8] - 58);
  if (strncmp(buffer, "IAI\x40\x1B\x50\x53\x58\x46",8)) {
          return(1);
  }
  for (i=0; i<10; i++) {
    write(fd, "IAI\x27",4);
    tcdrain(fd);
    usleep(1000);
    dexuxclear(fd);
  }
  write(fd, "IAI\x07\x01",5);
  readlength = read(fd, &buffer, 254);
  buffer[readlength]='\0';
  if (strncmp(buffer, "IAI",3)) {
          return(1);
  }
  dexuxclear(fd);
  return(0);
}

variable_types: fd int

variable_types:
buffer
char [255]

variable_types: readlength int

variable_types: i int


dexwrite

decompiled_code:
__int64 __fastcall dexwrite(unsigned int a1, const char *a2)
{
unsigned int v2; // er12
char v4[3]; // [rsp+5h] [rbp-40033h] BYREF
unsigned int v5; // [rsp+8h] [rbp-40030h] BYREF
unsigned int v6; // [rsp+Ch] [rbp-4002Ch] BYREF
char v7[262184]; // [rsp+10h] [rbp-40028h] BYREF

v2 = 1;
v5 = 0;
v6 = 0;
if ( (unsigned int)dexreadfile(a2, v7, v4, &v6, &v5) )
return v2;
v2 = 0;
if ( DEXUXDEBUGMODE )
{
fprintf(stderr, " dexreadfile -> %s, %s, %u, %u, %u\n", a2, v4, v6, v7, v5);
if ( v6 != 16 )
goto LABEL_4;
}
else if ( v6 != 16 )
{
LABEL_4:
dexwritesingle(a1, a2, v4, v7);
return v2;
}
dexwritefull(a1, a2, v4, &v7[v5]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, const char *a2)
{
unsigned int v2; // er12
char v4[3]; // [rsp+5h] [rbp-40033h] BYREF
unsigned int v5; // [rsp+8h] [rbp-40030h] BYREF
unsigned int v6; // [rsp+Ch] [rbp-4002Ch] BYREF
char v7[262184]; // [rsp+10h] [rbp-40028h] BYREF

v2 = 1;
v5 = 0;
v6 = 0;
if ( (unsigned int)dexreadfile(a2, v7, v4, &v6, &v5) )
return v2;
v2 = 0;
if ( DEXUXDEBUGMODE )
{
fprintf(stderr, " dexreadfile -> %s, %s, %u, %u, %u\n", a2, v4, v6, v7, v5);
if ( v6 != 16 )
goto LABEL_4;
}
else if ( v6 != 16 )
{
LABEL_4:
dexwritesingle(a1, a2, v4, v7);
return v2;
}
dexwritefull(a1, a2, v4, &v7[v5]);
return 0LL;
}

original_code:
int dexwrite(int dexuxfd, char *fname) {
  int offset=0, imagesize=0;
  char fileformat[3];
  unsigned char inputbuffer[262145], *pblock;
  if (dexreadfile(fname, inputbuffer, fileformat, &imagesize, &offset)) {
    return(1);
  }
  if (DEXUXDEBUGMODE) fprintf(stderr, "  dexreadfile -> %s, %s, %u, %u, %u\n", fname, fileformat, imagesize, inputbuffer, offset);
  if (imagesize == 16) {
    pblock = inputbuffer + offset;
    dexwritefull(dexuxfd, fname, fileformat, pblock);
  } else {
    dexwritesingle(dexuxfd, fname, fileformat, inputbuffer, imagesize);
  }
  return(0);
}

canonical_original_code:
int dexwrite(int dexuxfd, char *fname) {
  int offset = 0; int imagesize = 0;
  char fileformat[3];
  unsigned char inputbuffer[262145]; unsigned char *pblock;
  if (dexreadfile(fname, inputbuffer, fileformat, &imagesize, &offset)) {
    return(1);
  }
  if (DEXUXDEBUGMODE) fprintf(stderr, "  dexreadfile -> %s, %s, %u, %u, %u\n", fname, fileformat, imagesize, inputbuffer, offset);
  if (imagesize == 16) {
    pblock = inputbuffer + offset;
    dexwritefull(dexuxfd, fname, fileformat, pblock);
  } else {
    dexwritesingle(dexuxfd, fname, fileformat, inputbuffer, imagesize);
  }
  return(0);
}

variable_types:
fname
char *

variable_types: offset int

variable_types: imagesize int

variable_types:
fileformat
char [3]

variable_types:
inputbuffer
unsigned char [262145]

variable_types:
pblock
unsigned char *


dexuxclear

decompiled_code:
__int64 __fastcall dexuxclear(int a1)
{
tcflush(a1, 0);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int a1)
{
tcflush(a1, 0);
return 0LL;
}

original_code:
int dexuxclear(int fd) {
  tcflush(fd, 0);
  return(0);
}


dexuxputblock

decompiled_code:
__int64 __fastcall dexuxputblock(unsigned int a1, int a2, __int64 a3)
{
int v3; // er13
__int64 v4; // rbp
__int64 i; // rax
char v8[2]; // [rsp+Eh] [rbp-BAh] BYREF
char v9[184]; // [rsp+10h] [rbp-B8h] BYREF

v3 = 0;
v4 = a2 << 6;
do
{
v8[0] = dexuxframetop(v4);
v8[1] = dexuxframebottom(v4);
for ( i = 0LL; i != 128; ++i )
v9[i] = *(_BYTE *)(a3 + i);
v3 += 128;
++v4;
a3 += 128LL;
dexuxputframe(a1, v8, v9);
}
while ( v3 != 0x2000 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2, __int64 a3)
{
int v3; // er13
__int64 v4; // rbp
__int64 i; // rax
char v8[2]; // [rsp+Eh] [rbp-BAh] BYREF
char v9[184]; // [rsp+10h] [rbp-B8h] BYREF

v3 = 0;
v4 = a2 << 6;
do
{
v8[0] = dexuxframetop(v4);
v8[1] = dexuxframebottom(v4);
for ( i = 0LL; i != 128; ++i )
v9[i] = *(_BYTE *)(a3 + i);
v3 += 128;
++v4;
a3 += 128LL;
dexuxputframe(a1, v8, v9);
}
while ( v3 != 0x2000 );
return 0LL;
}

original_code:
int dexuxputblock(int fd, int blocknumber, char *blockdata) {
  char frametoput[2], *pframetoput, framedata[129], *pframedata;
  long frameaddress;
  int framenum, charnum;
  pframetoput = frametoput;
  pframedata = framedata;
  for (framenum = 0; framenum <= 63; framenum++) {
    frameaddress = (blocknumber * 0x40) + framenum;
    *(pframetoput + 0) = dexuxframetop(frameaddress);
    *(pframetoput + 1) = dexuxframebottom(frameaddress);
    for (charnum = 0; charnum <= 127; charnum++) {
      *(pframedata + charnum) = blockdata[ (framenum * 128) + charnum ];
    }
    dexuxputframe(fd, frametoput, framedata);
  }
  return(0);
}

canonical_original_code:
int dexuxputblock(int fd, int blocknumber, char *blockdata) {
  char frametoput[2]; char *pframetoput; char framedata[129]; char *pframedata;
  long frameaddress;
  int framenum; int charnum;
  pframetoput = frametoput;
  pframedata = framedata;
  for (framenum = 0; framenum <= 63; framenum++) {
    frameaddress = (blocknumber * 0x40) + framenum;
    *(pframetoput + 0) = dexuxframetop(frameaddress);
    *(pframetoput + 1) = dexuxframebottom(frameaddress);
    for (charnum = 0; charnum <= 127; charnum++) {
      *(pframedata + charnum) = blockdata[ (framenum * 128) + charnum ];
    }
    dexuxputframe(fd, frametoput, framedata);
  }
  return(0);
}

variable_types: blocknumber int

variable_types:
blockdata
char *

variable_types:
frametoput
char [2]

variable_types:
pframetoput
char *

variable_types:
framedata
char [129]

variable_types:
pframedata
char *

variable_types: frameaddress long

variable_types: framenum int

variable_types: charnum int


dexuxjistoascii

original_code:
int dexuxjistoascii(unsigned char *shiftjis, unsigned char *ascii) {
  unsigned char *pascii;
  int i, asciipos = 0;
  pascii = ascii;
  memset(ascii, 0, 65);
  for (i = 0; i <= 63; i++) {
    if (shiftjis[i] > 0x00 && shiftjis[i] <= 0x7F) {
      *(pascii+asciipos++) = shiftjis[i];
    } else if (shiftjis[i] >= 0xA0 && shiftjis[i] <= 0xDF) {
      *(pascii+asciipos++) = '.';
    } else if (shiftjis[i] == 0x81) {
      switch(shiftjis[++i]) {
          case 0x40: *(pascii+asciipos++) = ' '; break;
          case 0x43: *(pascii+asciipos++) = ','; break;
          case 0x44: *(pascii+asciipos++) = '.'; break;
          case 0x46: *(pascii+asciipos++) = ':'; break;
          case 0x47: *(pascii+asciipos++) = ';'; break;
          case 0x48: *(pascii+asciipos++) = '?'; break;
          case 0x49: *(pascii+asciipos++) = '!'; break;
          case 0x5E: *(pascii+asciipos++) = '/'; break;
          case 0x6D: *(pascii+asciipos++) = '['; break;
          case 0x6E: *(pascii+asciipos++) = ']'; break;
          default: *(pascii+asciipos++) = '.'; break;
      }
    } else if (shiftjis[i] == 0x82) {
      i++;
      if (shiftjis[i] < 0x40) {
          *(pascii+asciipos++) = '!';
      } else if (shiftjis[i] >= 0x40 && shiftjis[i] <= 0x4E) {
          *(pascii+asciipos++) = '.';
      } else if (shiftjis[i] >= 0x4F && shiftjis[i] <= 0x58) {
          *(pascii+asciipos++) = shiftjis[i] - 0x1F;
      } else if (shiftjis[i] >= 0x60 && shiftjis[i] <= 0x79) {
          *(pascii+asciipos++) = shiftjis[i] - 0x1F;
      } else if (shiftjis[i] >= 0x7A && shiftjis[i] <= 0x7E) {
          *(pascii+asciipos++) = '.';
      } else if (shiftjis[i] == 0x7F) {
          *(pascii+asciipos++) = '!';
      }
      else if (shiftjis[i] >= 0x81 && shiftjis[i] <= 0xA6)
          *(pascii+asciipos++) = shiftjis[i] - 0x20;
      else switch(shiftjis[i]) {
          default: *(pascii+asciipos++) = '.'; break;
      }
    } else if (shiftjis[i] >= 0x83 && shiftjis[i] <= 0x9F) {
      i++; *(pascii+asciipos++) = '?';
    } else if (shiftjis[i] >= 0xE0 && shiftjis[i] <= 0xFC) {
      i++; *(pascii+asciipos++) = '?';
    } else if (shiftjis[i] != 0) {
      *(pascii+asciipos++) = '?';
    }
  }
  return(0);
}

canonical_original_code:
int dexuxjistoascii(unsigned char *shiftjis, unsigned char *ascii) {
  unsigned char *pascii;
  int i; int asciipos = 0;
  pascii = ascii;
  memset(ascii, 0, 65);
  for (i = 0; i <= 63; i++) {
    if (shiftjis[i] > 0x00 && shiftjis[i] <= 0x7F) {
      *(pascii+asciipos++) = shiftjis[i];
    } else if (shiftjis[i] >= 0xA0 && shiftjis[i] <= 0xDF) {
      *(pascii+asciipos++) = '.';
    } else if (shiftjis[i] == 0x81) {
      switch(shiftjis[++i]) {
          case 0x40: *(pascii+asciipos++) = ' '; break;
          case 0x43: *(pascii+asciipos++) = ','; break;
          case 0x44: *(pascii+asciipos++) = '.'; break;
          case 0x46: *(pascii+asciipos++) = ':'; break;
          case 0x47: *(pascii+asciipos++) = ';'; break;
          case 0x48: *(pascii+asciipos++) = '?'; break;
          case 0x49: *(pascii+asciipos++) = '!'; break;
          case 0x5E: *(pascii+asciipos++) = '/'; break;
          case 0x6D: *(pascii+asciipos++) = '['; break;
          case 0x6E: *(pascii+asciipos++) = ']'; break;
          default: *(pascii+asciipos++) = '.'; break;
      }
    } else if (shiftjis[i] == 0x82) {
      i++;
      if (shiftjis[i] < 0x40) {
          *(pascii+asciipos++) = '!';
      } else if (shiftjis[i] >= 0x40 && shiftjis[i] <= 0x4E) {
          *(pascii+asciipos++) = '.';
      } else if (shiftjis[i] >= 0x4F && shiftjis[i] <= 0x58) {
          *(pascii+asciipos++) = shiftjis[i] - 0x1F;
      } else if (shiftjis[i] >= 0x60 && shiftjis[i] <= 0x79) {
          *(pascii+asciipos++) = shiftjis[i] - 0x1F;
      } else if (shiftjis[i] >= 0x7A && shiftjis[i] <= 0x7E) {
          *(pascii+asciipos++) = '.';
      } else if (shiftjis[i] == 0x7F) {
          *(pascii+asciipos++) = '!';
      }
      else if (shiftjis[i] >= 0x81 && shiftjis[i] <= 0xA6)
          *(pascii+asciipos++) = shiftjis[i] - 0x20;
      else switch(shiftjis[i]) {
          default: *(pascii+asciipos++) = '.'; break;
      }
    } else if (shiftjis[i] >= 0x83 && shiftjis[i] <= 0x9F) {
      i++; *(pascii+asciipos++) = '?';
    } else if (shiftjis[i] >= 0xE0 && shiftjis[i] <= 0xFC) {
      i++; *(pascii+asciipos++) = '?';
    } else if (shiftjis[i] != 0) {
      *(pascii+asciipos++) = '?';
    }
  }
  return(0);
}

variable_types:
shiftjis
unsigned char *

variable_types:
ascii
unsigned char *

variable_types:
pascii
unsigned char *

variable_types: asciipos int


dexuxgetblock

decompiled_code:
__int64 __fastcall dexuxgetblock(unsigned int a1, int a2, __int64 a3)
{
__int64 v3; // r13
__int64 v5; // rbp
__int64 v6; // rbx
char v7; // al
__int64 v8; // rdi
char v9; // al
__int64 v10; // rdx
char v12[42]; // [rsp+Eh] [rbp-2Ah] BYREF

v3 = a3 + 0x2000;
v5 = a3;
v6 = a2 << 6;
do
{
v7 = dexuxframetop(v6);
v8 = v6++;
v12[0] = v7;
v9 = dexuxframebottom(v8);
v10 = v5;
v5 += 128LL;
v12[1] = v9;
dexuxgetframe(a1, v12, v10);
}
while ( v5 != v3 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, int a2, __int64 a3)
{
__int64 v3; // r13
__int64 v5; // rbp
__int64 v6; // rbx
char v7; // al
__int64 v8; // rdi
char v9; // al
__int64 v10; // rdx
char v12[42]; // [rsp+Eh] [rbp-2Ah] BYREF

v3 = a3 + 0x2000;
v5 = a3;
v6 = a2 << 6;
do
{
v7 = dexuxframetop(v6);
v8 = v6++;
v12[0] = v7;
v9 = dexuxframebottom(v8);
v10 = v5;
v5 += 128LL;
v12[1] = v9;
dexuxgetframe(a1, v12, v10);
}
while ( v5 != v3 );
return 0LL;
}

original_code:
int dexuxgetblock(int fd, int blocknumber, char *blockdata) {
  char *pblockdata, *pframetoget, frametoget[2], framebuf[129];
  long frameaddress;
  int framenum;
  pblockdata = blockdata; pframetoget = frametoget;
  for (framenum = 0; framenum <= 63; framenum++) {
    frameaddress = (blocknumber * 0x40) + framenum;
    *(pframetoget + 0) = dexuxframetop(frameaddress);
    *(pframetoget + 1) = dexuxframebottom(frameaddress);
    dexuxgetframe(fd, frametoget, pblockdata);
    pblockdata += 128;
  }
  return(0);
}

canonical_original_code:
int dexuxgetblock(int fd, int blocknumber, char *blockdata) {
  char *pblockdata; char *pframetoget; char frametoget[2]; char framebuf[129];
  long frameaddress;
  int framenum;
  pblockdata = blockdata; pframetoget = frametoget;
  for (framenum = 0; framenum <= 63; framenum++) {
    frameaddress = (blocknumber * 0x40) + framenum;
    *(pframetoget + 0) = dexuxframetop(frameaddress);
    *(pframetoget + 1) = dexuxframebottom(frameaddress);
    dexuxgetframe(fd, frametoget, pblockdata);
    pblockdata += 128;
  }
  return(0);
}

variable_types: fd int

variable_types:
pblockdata
char *

variable_types:
pframetoget
char *

variable_types:
frametoget
char [2]

variable_types:
framebuf
char [129]


dexuxframetop

decompiled_code:
__int64 __fastcall dexuxframetop(__int64 a1)
{
return a1 / 256;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1 / 256;
}

original_code:
int dexuxframetop(long frameaddress) {
  return(frameaddress / 256);
}


dexlist

decompiled_code:
__int64 __fastcall dexlist(unsigned int a1)
{
__int64 v1; // r13
unsigned int v2; // er12
int v3; // ebx
char *v4; // rbx
int v5; // ebp
__m128i v6; // xmm1
__m128i v7; // xmm2
__m128i v8; // xmm3
int v9; // er14
unsigned __int8 v10; // al
unsigned int v11; // er15
int v12; // eax
FILE *v13; // rbx
unsigned int v14; // ebp
int v15; // ebp
char *v16; // rbx
int v17; // er15
int v18; // ebp
int v19; // er15
__int64 v21; // rdx
__int64 v22; // rcx
unsigned int v23; // [rsp+8h] [rbp-210h]
unsigned int v24; // [rsp+Ch] [rbp-20Ch]
char v25; // [rsp+1Eh] [rbp-1FAh] BYREF
char v26; // [rsp+1Fh] [rbp-1F9h]
char v27; // [rsp+20h] [rbp-1F8h] BYREF
__m128i v28; // [rsp+21h] [rbp-1F7h]
__m128i v29; // [rsp+31h] [rbp-1E7h]
__m128i v30; // [rsp+41h] [rbp-1D7h]
__m128i v31; // [rsp+51h] [rbp-1C7h]
char v32[32]; // [rsp+70h] [rbp-1A8h] BYREF
char v33[48]; // [rsp+90h] [rbp-188h] BYREF
char v34[5]; // [rsp+C0h] [rbp-158h] BYREF
unsigned __int8 v35; // [rsp+C5h] [rbp-153h]
char v36; // [rsp+C6h] [rbp-152h]
unsigned __int8 v37; // [rsp+CAh] [rbp-14Eh]
unsigned __int8 v38; // [rsp+CBh] [rbp-14Dh]
char v39; // [rsp+CCh] [rbp-14Ch] BYREF
char v40; // [rsp+D6h] [rbp-142h] BYREF
char v41[114]; // [rsp+DEh] [rbp-13Ah] BYREF
char v42[4]; // [rsp+150h] [rbp-C8h] BYREF
__m128i v43; // [rsp+154h] [rbp-C4h] BYREF
__m128i v44; // [rsp+164h] [rbp-B4h] BYREF
__m128i v45; // [rsp+174h] [rbp-A4h] BYREF
__m128i v46[9]; // [rsp+184h] [rbp-94h] BYREF

v1 = 64LL;
v2 = 1;
v3 = 0;
v24 = 0;
v23 = 15;
do
{
while ( 1 )
{
v25 = 0;
v26 = v2;
if ( DEXUXDEBUGMODE )
fprintf(stderr, "Getting address %d %d\n", 0LL, v2);
dexuxgetframe(a1, &v25, v34);
if ( (v34[0] & 0xF0) != 0xA0 )
{
--v23;
v24 += (v34[0] & 0xF0) == 80;
}
if ( (v34[0] & 0xF) == 1 )
break;
++v2;
v1 += 64LL;
if ( v2 == 16 )
goto LABEL_35;
}
if ( !v3 )
{
fwrite("# Title ", 1uLL, 0x24uLL, stderr);
fwrite("Size Del Product Code ID Frames\n", 1uLL, 0x27uLL, stderr);
}
if ( (int)v2 > 9 )
fprintf(stderr, "%d ", v2);
else
fprintf(stderr, "%d ", v2);
v4 = v32;
v5 = 1;
v25 = dexuxframetop(v1);
v26 = dexuxframebottom(v1);
dexuxgetframe(a1, &v25, v42);
v6 = _mm_loadu_si128(&v44);
v7 = _mm_loadu_si128(&v45);
v8 = _mm_loadu_si128(v46);
v28 = _mm_loadu_si128(&v43);
v29 = v6;
v30 = v7;
v31 = v8;
dexuxjistoascii(&v27, v32);
do
{
while ( 1 )
{
v9 = (unsigned __int8)*v4;
if ( isprint(v9) )
{
if ( v5 )
break;
}
++v4;
v5 = 0;
fputc(32, stderr);
if ( v33 == v4 )
goto LABEL_17;
}
++v4;
v5 = 1;
fputc(v9, stderr);
}
while ( v33 != v4 );
LABEL_17:
v10 = v35 >> 5;
if ( v36 == 1 )
{
v21 = (unsigned __int8)(v10 + 8);
if ( v35 > 0x3Fu )
fprintf(stderr, " %d ", v21);
else
fprintf(stderr, " %d ", v21);
}
else
{
fprintf(stderr, " %d ", v10);
}
if ( (v34[0] & 0xF0) == 80 )
fwrite(" N ", 1uLL, 4uLL, stderr);
else
fwrite(" Y ", 1uLL, 4uLL, stderr);
v11 = v37;
v12 = isprint(v37);
v13 = stderr;
if ( v12 && (v14 = v38, isprint(v38)) )
{
v22 = v14;
v15 = 1;
fprintf(v13, "%c%c-", v11, v22);
}
else
{
v15 = 0;
fwrite(" ", 1uLL, 3uLL, v13);
}
v16 = &v39;
do
{
while ( 1 )
{
v17 = (unsigned __int8)*v16;
if ( isprint(v17) )
{
if ( v15 )
break;
}
++v16;
v15 = 0;
fputc(32, stderr);
if ( v16 == &v40 )
goto LABEL_29;
}
++v16;
v15 = 1;
fputc(v17, stderr);
}
while ( v16 != &v40 );
LABEL_29:
v18 = 1;
fputc(32, stderr);
do
{
while ( 1 )
{
v19 = (unsigned __int8)*v16;
if ( isprint(v19) )
{
if ( v18 )
break;
}
++v16;
v18 = 0;
fputc(32, stderr);
if ( v41 == v16 )
goto LABEL_34;
}
++v16;
v18 = 1;
fputc(v19, stderr);
}
while ( v41 != v16 );
LABEL_34:
++v2;
v3 = 1;
v1 += 64LL;
fprintf(stderr, " %d\n", v42[2] & 3);
}
while ( v2 != 16 );
LABEL_35:
if ( v3 )
fprintf(stderr, " Blocks in use: %d Blocks available: %d\n", v24, v23);
else
fprintf(stderr, " Blocks in use: None Blocks available: %d\n", v23);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1)
{
__int64 v1; // r13
unsigned int v2; // er12
int v3; // ebx
char *v4; // rbx
int v5; // ebp
__m128i v6; // xmm1
__m128i v7; // xmm2
__m128i v8; // xmm3
int v9; // er14
unsigned __int8 v10; // al
unsigned int v11; // er15
int v12; // eax
FILE *v13; // rbx
unsigned int v14; // ebp
int v15; // ebp
char *v16; // rbx
int v17; // er15
int v18; // ebp
int v19; // er15
__int64 v21; // rdx
__int64 v22; // rcx
unsigned int v23; // [rsp+8h] [rbp-210h]
unsigned int v24; // [rsp+Ch] [rbp-20Ch]
char v25; // [rsp+1Eh] [rbp-1FAh] BYREF
char v26; // [rsp+1Fh] [rbp-1F9h]
char v27; // [rsp+20h] [rbp-1F8h] BYREF
__m128i v28; // [rsp+21h] [rbp-1F7h]
__m128i v29; // [rsp+31h] [rbp-1E7h]
__m128i v30; // [rsp+41h] [rbp-1D7h]
__m128i v31; // [rsp+51h] [rbp-1C7h]
char v32[32]; // [rsp+70h] [rbp-1A8h] BYREF
char v33[48]; // [rsp+90h] [rbp-188h] BYREF
char v34[5]; // [rsp+C0h] [rbp-158h] BYREF
unsigned __int8 v35; // [rsp+C5h] [rbp-153h]
char v36; // [rsp+C6h] [rbp-152h]
unsigned __int8 v37; // [rsp+CAh] [rbp-14Eh]
unsigned __int8 v38; // [rsp+CBh] [rbp-14Dh]
char v39; // [rsp+CCh] [rbp-14Ch] BYREF
char v40; // [rsp+D6h] [rbp-142h] BYREF
char v41[114]; // [rsp+DEh] [rbp-13Ah] BYREF
char v42[4]; // [rsp+150h] [rbp-C8h] BYREF
__m128i v43; // [rsp+154h] [rbp-C4h] BYREF
__m128i v44; // [rsp+164h] [rbp-B4h] BYREF
__m128i v45; // [rsp+174h] [rbp-A4h] BYREF
__m128i v46[9]; // [rsp+184h] [rbp-94h] BYREF

v1 = 64LL;
v2 = 1;
v3 = 0;
v24 = 0;
v23 = 15;
do
{
while ( 1 )
{
v25 = 0;
v26 = v2;
if ( DEXUXDEBUGMODE )
fprintf(stderr, "Getting address %d %d\n", 0LL, v2);
dexuxgetframe(a1, &v25, v34);
if ( (v34[0] & 0xF0) != 0xA0 )
{
--v23;
v24 += (v34[0] & 0xF0) == 80;
}
if ( (v34[0] & 0xF) == 1 )
break;
++v2;
v1 += 64LL;
if ( v2 == 16 )
goto LABEL_35;
}
if ( !v3 )
{
fwrite("# Title ", 1uLL, 0x24uLL, stderr);
fwrite("Size Del Product Code ID Frames\n", 1uLL, 0x27uLL, stderr);
}
if ( (int)v2 > 9 )
fprintf(stderr, "%d ", v2);
else
fprintf(stderr, "%d ", v2);
v4 = v32;
v5 = 1;
v25 = dexuxframetop(v1);
v26 = dexuxframebottom(v1);
dexuxgetframe(a1, &v25, v42);
v6 = _mm_loadu_si128(&v44);
v7 = _mm_loadu_si128(&v45);
v8 = _mm_loadu_si128(v46);
v28 = _mm_loadu_si128(&v43);
v29 = v6;
v30 = v7;
v31 = v8;
dexuxjistoascii(&v27, v32);
do
{
while ( 1 )
{
v9 = (unsigned __int8)*v4;
if ( isprint(v9) )
{
if ( v5 )
break;
}
++v4;
v5 = 0;
fputc(32, stderr);
if ( v33 == v4 )
goto LABEL_17;
}
++v4;
v5 = 1;
fputc(v9, stderr);
}
while ( v33 != v4 );
LABEL_17:
v10 = v35 >> 5;
if ( v36 == 1 )
{
v21 = (unsigned __int8)(v10 + 8);
if ( v35 > 0x3Fu )
fprintf(stderr, " %d ", v21);
else
fprintf(stderr, " %d ", v21);
}
else
{
fprintf(stderr, " %d ", v10);
}
if ( (v34[0] & 0xF0) == 80 )
fwrite(" N ", 1uLL, 4uLL, stderr);
else
fwrite(" Y ", 1uLL, 4uLL, stderr);
v11 = v37;
v12 = isprint(v37);
v13 = stderr;
if ( v12 && (v14 = v38, isprint(v38)) )
{
v22 = v14;
v15 = 1;
fprintf(v13, "%c%c-", v11, v22);
}
else
{
v15 = 0;
fwrite(" ", 1uLL, 3uLL, v13);
}
v16 = &v39;
do
{
while ( 1 )
{
v17 = (unsigned __int8)*v16;
if ( isprint(v17) )
{
if ( v15 )
break;
}
++v16;
v15 = 0;
fputc(32, stderr);
if ( v16 == &v40 )
goto LABEL_29;
}
++v16;
v15 = 1;
fputc(v17, stderr);
}
while ( v16 != &v40 );
LABEL_29:
v18 = 1;
fputc(32, stderr);
do
{
while ( 1 )
{
v19 = (unsigned __int8)*v16;
if ( isprint(v19) )
{
if ( v18 )
break;
}
++v16;
v18 = 0;
fputc(32, stderr);
if ( v41 == v16 )
goto LABEL_34;
}
++v16;
v18 = 1;
fputc(v19, stderr);
}
while ( v41 != v16 );
LABEL_34:
++v2;
v3 = 1;
v1 += 64LL;
fprintf(stderr, " %d\n", v42[2] & 3);
}
while ( v2 != 16 );
LABEL_35:
if ( v3 )
fprintf(stderr, " Blocks in use: %d Blocks available: %d\n", v24, v23);
else
fprintf(stderr, " Blocks in use: None Blocks available: %d\n", v23);
return 0LL;
}

original_code:
int dexlist(int dexuxfd) {
  int blockcnt, titlecnt, productcnt, idcnt, printable;
  int foundentry=0, blocksavailable=15, blocksused=0;
  unsigned char headerdata[129], blockdata[129];
  unsigned char title_shiftjis[65], *ptitle_shiftjis, title_ascii[65];
  char chunkrequest[2], *pchunkrequest;
  pchunkrequest = chunkrequest;
  ptitle_shiftjis = title_shiftjis;
  for (blockcnt=1; blockcnt<=15; blockcnt++) {
    *(pchunkrequest+0) = 0;
    *(pchunkrequest+1) = blockcnt;
    if (DEXUXDEBUGMODE) fprintf(stderr, "Getting address %d %d\n", *(pchunkrequest+0), *(pchunkrequest+1));
    dexuxgetframe(dexuxfd, chunkrequest, headerdata);
    if ((headerdata[0] & 240) != 0xA0) blocksavailable--;
    if ((headerdata[0] & 240) == 0x50) blocksused++;
    if ((headerdata[0] & 15) == 0x01) {
      if (foundentry == 0) {
        foundentry = 1;
        fprintf(stderr, "#  Title                            ");
        fprintf(stderr, "Size Del Product Code     ID    Frames\n");
      }
      if (blockcnt < 10) {
        fprintf(stderr, "%d  ", blockcnt);
      } else {
        fprintf(stderr, "%d ", blockcnt);
      }
      *(pchunkrequest+0) = dexuxframetop(blockcnt * 0x40);
      *(pchunkrequest+1) = dexuxframebottom(blockcnt * 0x40);
      dexuxgetframe(dexuxfd, chunkrequest, blockdata);
      for (titlecnt=0x04; titlecnt <= 0x43;
           *(ptitle_shiftjis+titlecnt-4) = blockdata[titlecnt++]) ;
      dexuxjistoascii(title_shiftjis, title_ascii);
      printable=1;
      for (titlecnt=0; titlecnt < 32; titlecnt++)
        if (isprint(title_ascii[titlecnt]) && printable) {
          fprintf(stderr, "%c", title_ascii[titlecnt]);
        } else {
          printable=0;
          fprintf(stderr, " ");
        }
      if (headerdata[6] != 0x01) {
        fprintf(stderr, "   %d  ", headerdata[5] >> 5);
      } else if (headerdata[5] < 0x40) {
        fprintf(stderr, "   %d  ", (headerdata[5] >> 5) + 8);
      } else {
        fprintf(stderr, "  %d  ", (headerdata[5] >> 5) + 8);
      }
      if ((headerdata[0] & 240) == 0x50) {
        fprintf(stderr, " N  ");
      } else {
        fprintf(stderr, " Y  ");
      }
      printable=1;
      if (isprint(headerdata[0x0A]) && isprint(headerdata[0x0B])) {
        fprintf(stderr, "%c%c-",
                headerdata[0x0A], headerdata[0x0B]);
      } else {
        printable=0;
        fprintf(stderr, "   ");
      }
      for (productcnt = 0x0C; productcnt <= 0x15; productcnt++) {
        if (isprint(headerdata[productcnt]) && printable) {
          fprintf(stderr, "%c", headerdata[productcnt]);
        } else {
          printable=0;
          fprintf(stderr, " ");
        }
      }
      fprintf(stderr, " ");
      printable=1;
      for (idcnt = 0x16; idcnt <= 0x1D; idcnt++) {
        if (isprint(headerdata[idcnt]) && printable) {
          fprintf(stderr, "%c", headerdata[idcnt]);
        } else {
          printable=0;
          fprintf(stderr, " ");
        }
      }
      fprintf(stderr, "    %d\n", blockdata[0x02] & 3);
    }
  }
  if (foundentry) {
    fprintf(stderr, "      Blocks in use:  %d     Blocks available:  %d\n",
            blocksused, blocksavailable);
  } else {
    fprintf(stderr, "      Blocks in use: None    Blocks available:  %d\n",
            blocksavailable);
  }
  return(0);
}

canonical_original_code:
int dexlist(int dexuxfd) {
  int blockcnt; int titlecnt; int productcnt; int idcnt; int printable;
  int foundentry = 0; int blocksavailable = 15; int blocksused = 0;
  unsigned char headerdata[129]; unsigned char blockdata[129];
  unsigned char title_shiftjis[65]; unsigned char *ptitle_shiftjis; unsigned char title_ascii[65];
  char chunkrequest[2]; char *pchunkrequest;
  pchunkrequest = chunkrequest;
  ptitle_shiftjis = title_shiftjis;
  for (blockcnt=1; blockcnt<=15; blockcnt++) {
    *(pchunkrequest+0) = 0;
    *(pchunkrequest+1) = blockcnt;
    if (DEXUXDEBUGMODE) fprintf(stderr, "Getting address %d %d\n", *(pchunkrequest+0), *(pchunkrequest+1));
    dexuxgetframe(dexuxfd, chunkrequest, headerdata);
    if ((headerdata[0] & 240) != 0xA0) blocksavailable--;
    if ((headerdata[0] & 240) == 0x50) blocksused++;
    if ((headerdata[0] & 15) == 0x01) {
      if (foundentry == 0) {
        foundentry = 1;
        fprintf(stderr, "#  Title                            ");
        fprintf(stderr, "Size Del Product Code     ID    Frames\n");
      }
      if (blockcnt < 10) {
        fprintf(stderr, "%d  ", blockcnt);
      } else {
        fprintf(stderr, "%d ", blockcnt);
      }
      *(pchunkrequest+0) = dexuxframetop(blockcnt * 0x40);
      *(pchunkrequest+1) = dexuxframebottom(blockcnt * 0x40);
      dexuxgetframe(dexuxfd, chunkrequest, blockdata);
      for (titlecnt=0x04; titlecnt <= 0x43;
           *(ptitle_shiftjis+titlecnt-4) = blockdata[titlecnt++]) ;
      dexuxjistoascii(title_shiftjis, title_ascii);
      printable=1;
      for (titlecnt=0; titlecnt < 32; titlecnt++)
        if (isprint(title_ascii[titlecnt]) && printable) {
          fprintf(stderr, "%c", title_ascii[titlecnt]);
        } else {
          printable=0;
          fprintf(stderr, " ");
        }
      if (headerdata[6] != 0x01) {
        fprintf(stderr, "   %d  ", headerdata[5] >> 5);
      } else if (headerdata[5] < 0x40) {
        fprintf(stderr, "   %d  ", (headerdata[5] >> 5) + 8);
      } else {
        fprintf(stderr, "  %d  ", (headerdata[5] >> 5) + 8);
      }
      if ((headerdata[0] & 240) == 0x50) {
        fprintf(stderr, " N  ");
      } else {
        fprintf(stderr, " Y  ");
      }
      printable=1;
      if (isprint(headerdata[0x0A]) && isprint(headerdata[0x0B])) {
        fprintf(stderr, "%c%c-",
                headerdata[0x0A], headerdata[0x0B]);
      } else {
        printable=0;
        fprintf(stderr, "   ");
      }
      for (productcnt = 0x0C; productcnt <= 0x15; productcnt++) {
        if (isprint(headerdata[productcnt]) && printable) {
          fprintf(stderr, "%c", headerdata[productcnt]);
        } else {
          printable=0;
          fprintf(stderr, " ");
        }
      }
      fprintf(stderr, " ");
      printable=1;
      for (idcnt = 0x16; idcnt <= 0x1D; idcnt++) {
        if (isprint(headerdata[idcnt]) && printable) {
          fprintf(stderr, "%c", headerdata[idcnt]);
        } else {
          printable=0;
          fprintf(stderr, " ");
        }
      }
      fprintf(stderr, "    %d\n", blockdata[0x02] & 3);
    }
  }
  if (foundentry) {
    fprintf(stderr, "      Blocks in use:  %d     Blocks available:  %d\n",
            blocksused, blocksavailable);
  } else {
    fprintf(stderr, "      Blocks in use: None    Blocks available:  %d\n",
            blocksavailable);
  }
  return(0);
}

variable_types: dexuxfd int

variable_types: blockcnt int

variable_types: titlecnt int

variable_types: productcnt int

variable_types: idcnt int

variable_types: printable int

variable_types: foundentry int

variable_types: blocksavailable int

variable_types: blocksused int

variable_types:
headerdata
unsigned char [129]

variable_types:
blockdata
unsigned char [129]

variable_types:
chunkrequest
char [2]

variable_types:
pchunkrequest
char *


dexuxframebottom

decompiled_code:
__int64 __fastcall dexuxframebottom(__int64 a1)
{
return a1 % 256;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1 % 256;
}

original_code:
int dexuxframebottom(long frameaddress) {
  return(frameaddress % 256);
}

variable_types: frameaddress long


dexuxgetframe

decompiled_code:
ssize_t __fastcall dexuxgetframe(int fd, void *buf, void *a3)
{
int v5; // [rsp+8h] [rbp-20h] BYREF
char bufa[28]; // [rsp+Ch] [rbp-1Ch] BYREF

dexuxclear();
write(fd, &unk_D8, 4uLL);
write(fd, (char *)buf + 1, 1uLL);
write(fd, buf, 1uLL);
do
{
while ( 1 )
{
usleep(0x3E8u);
ioctl(fd, 0x541BuLL, &v5);
if ( DEXUXDEBUGMODE )
break;
if ( v5 > 131 )
goto LABEL_5;
}
fprintf(stderr, " available = %d\n", (unsigned int)v5);
}
while ( v5 <= 131 );
LABEL_5:
read(fd, bufa, 4uLL);
return read(fd, a3, 0x80uLL);
}

canonical_decompiled_code:
ssize_t __fastcall func0(int fd, void *buf, void *a3)
{
int v5; // [rsp+8h] [rbp-20h] BYREF
char bufa[28]; // [rsp+Ch] [rbp-1Ch] BYREF

dexuxclear();
write(fd, &unk_D8, 4uLL);
write(fd, (char *)buf + 1, 1uLL);
write(fd, buf, 1uLL);
do
{
while ( 1 )
{
usleep(0x3E8u);
ioctl(fd, 0x541BuLL, &v5);
if ( DEXUXDEBUGMODE )
break;
if ( v5 > 131 )
goto LABEL_5;
}
fprintf(stderr, " available = %d\n", (unsigned int)v5);
}
while ( v5 <= 131 );
LABEL_5:
read(fd, bufa, 4uLL);
return read(fd, a3, 0x80uLL);
}

original_code:
int dexuxgetframe(int fd, unsigned char *address, char *data) {
  int available, readlength;
  char trashdata[4];
  dexuxclear(fd);
  write(fd, "IAI\x02", 4);
  write(fd, address+1, 1);
  write(fd, address+0, 1);
  usleep(1000);
  ioctl(fd, 0x541B, &available);
  if (DEXUXDEBUGMODE) fprintf(stderr, "  available = %d\n", available);
  while (available < 132) {
    usleep(1000);
    ioctl(fd, 0x541B, &available);
    if (DEXUXDEBUGMODE) fprintf(stderr, "  available = %d\n", available);
  }
  read(fd, trashdata, 4);
  readlength = read(fd, data, 128);
  return(readlength);
}

canonical_original_code:
int dexuxgetframe(int fd, unsigned char *address, char *data) {
  int available; int readlength;
  char trashdata[4];
  dexuxclear(fd);
  write(fd, "IAI\x02", 4);
  write(fd, address+1, 1);
  write(fd, address+0, 1);
  usleep(1000);
  ioctl(fd, 0x541B, &available);
  if (DEXUXDEBUGMODE) fprintf(stderr, "  available = %d\n", available);
  while (available < 132) {
    usleep(1000);
    ioctl(fd, 0x541B, &available);
    if (DEXUXDEBUGMODE) fprintf(stderr, "  available = %d\n", available);
  }
  read(fd, trashdata, 4);
  readlength = read(fd, data, 128);
  return(readlength);
}

variable_types: fd int

variable_types:
address
unsigned char *

variable_types:
data
char *

variable_types: available int

variable_types: readlength int

variable_types:
trashdata
char [4]


dexuxopen

decompiled_code:
__int64 __fastcall dexuxopen(char *a1)
{
unsigned int v1; // er12
__int64 result; // rax
struct termios v3; // [rsp+0h] [rbp-48h] BYREF

if ( *a1 )
goto LABEL_4;
if ( getenv("DEXUXPORT") )
{
a1 = getenv("DEXUXPORT");
LABEL_4:
v1 = open(a1, 2306);
goto LABEL_5;
}
v1 = open("/dev/ttyS1", 2306);
LABEL_5:
if ( v1 == -1 )
{
perror("open_port: unable to open device for dex drive\n");
result = 0xFFFFFFFFLL;
}
else
{
fcntl(v1, 4, 0LL);
tcgetattr(v1, &v3);
cfsetispeed(&v3, 0xFu);
cfsetospeed(&v3, 0xFu);
v3.c_lflag &= 0xFFFFFFE4;
v3.c_oflag &= 0xFFFFFFFE;
v3.c_cc[5] = 10;
v3.c_cflag = v3.c_cflag & 0x7FFFFE8F | 0x8B0;
v3.c_iflag = v3.c_iflag & 0xFFFFE3E7 | 4;
tcsetattr(v1, 2, &v3);
result = v1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char *a1)
{
unsigned int v1; // er12
__int64 result; // rax
struct termios v3; // [rsp+0h] [rbp-48h] BYREF

if ( *a1 )
goto LABEL_4;
if ( getenv("DEXUXPORT") )
{
a1 = getenv("DEXUXPORT");
LABEL_4:
v1 = open(a1, 2306);
goto LABEL_5;
}
v1 = open("/dev/ttyS1", 2306);
LABEL_5:
if ( v1 == -1 )
{
perror("open_port: unable to open device for dex drive\n");
result = 0xFFFFFFFFLL;
}
else
{
fcntl(v1, 4, 0LL);
tcgetattr(v1, &v3);
cfsetispeed(&v3, 0xFu);
cfsetospeed(&v3, 0xFu);
v3.c_lflag &= 0xFFFFFFE4;
v3.c_oflag &= 0xFFFFFFFE;
v3.c_cc[5] = 10;
v3.c_cflag = v3.c_cflag & 0x7FFFFE8F | 0x8B0;
v3.c_iflag = v3.c_iflag & 0xFFFFE3E7 | 4;
tcsetattr(v1, 2, &v3);
result = v1;
}
return result;
}

original_code:
int dexuxopen(char *devname) {
  int fd;
  struct termios options;
  if (devname[0] != 0) {
    fd = open(devname, 02 | 0400 | 04000);
  } else if (getenv("DEXUXPORT") != ((void *)0)) {
    fd = open(getenv("DEXUXPORT"), 02 | 0400 | 04000);
  } else {
    fd = open("/dev/ttyS1", 02 | 0400 | 04000);
  }
  if (fd == -1) {
    perror("open_port: unable to open device for dex drive\n");
    return(fd);
  }
  fcntl(fd, 4, 0);
  tcgetattr(fd, &options);
  cfsetispeed(&options, 0000017);
  cfsetospeed(&options, 0000017);
  options.c_cflag |= (0004000 | 0000200);
  options.c_cflag &= ~0000060;
  options.c_cflag |= 0000060;
  options.c_cflag &= ~0000400;
  options.c_cflag &= ~0000100;
  options.c_cflag &= ~020000000000;
  options.c_lflag &= ~(0000002|0000010|0000020|0000001);
  options.c_iflag &= ~0000020;
  options.c_iflag |= 0000004;
  options.c_iflag &= ~0000010;
  options.c_iflag &= ~(0002000 | 0010000 | 0004000);
  options.c_oflag &= ~0000001;
  options.c_cc[5] = 10;
  tcsetattr(fd, 2, &options);
  return(fd);
}

variable_types:
devname
char *

variable_types: struct termios { unsigned int c_iflag; unsigned int c_oflag; unsigned int c_cflag; unsigned int c_lflag; unsigned char c_line; unsigned char c_cc[32]; unsigned int c_ispeed; unsigned int c_ospeed; }


dexwritefull

decompiled_code:
__int64 __fastcall dexwritefull(unsigned int a1, const char *a2, const char *a3, __int64 a4)
{
int i; // ebx
int v7; // ebx
unsigned int v8; // ebx
__int64 v9; // rsi
char v11[2]; // [rsp+Eh] [rbp-BAh] BYREF
char v12[184]; // [rsp+10h] [rbp-B8h] BYREF

for ( i = 1; i != 16; ++i )
{
v11[1] = i;
v11[0] = 0;
dexuxgetframe(a1, v11, v12);
if ( (v12[0] & 0xF0) != 0xA0 )
{
fprintf(stderr, "Detected file format %s which contains", a3);
fwrite(" a full memorycard image\n", 1uLL, 0x19uLL, stderr);
fwrite("But the card in the drive still has data which", 1uLL, 0x2EuLL, stderr);
fwrite(" has not been deleted\n", 1uLL, 0x16uLL, stderr);
fprintf(stderr, "Skipping file: %s\n", a2);
return 1LL;
}
}
v7 = 64;
fprintf(stderr, "Progress for: %s\n", a2);
fputc(124, stderr);
do
{
fputc(45, stderr);
--v7;
}
while ( v7 );
v8 = 0;
fwrite("|\n ", 1uLL, 3uLL, stderr);
do
{
v9 = v8++;
dexuxputblock(a1, v9, a4);
a4 += 0x2000LL;
fwrite("****", 1uLL, 4uLL, stderr);
}
while ( v8 != 16 );
fputc(10, stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, const char *a2, const char *a3, __int64 a4)
{
int i; // ebx
int v7; // ebx
unsigned int v8; // ebx
__int64 v9; // rsi
char v11[2]; // [rsp+Eh] [rbp-BAh] BYREF
char v12[184]; // [rsp+10h] [rbp-B8h] BYREF

for ( i = 1; i != 16; ++i )
{
v11[1] = i;
v11[0] = 0;
dexuxgetframe(a1, v11, v12);
if ( (v12[0] & 0xF0) != 0xA0 )
{
fprintf(stderr, "Detected file format %s which contains", a3);
fwrite(" a full memorycard image\n", 1uLL, 0x19uLL, stderr);
fwrite("But the card in the drive still has data which", 1uLL, 0x2EuLL, stderr);
fwrite(" has not been deleted\n", 1uLL, 0x16uLL, stderr);
fprintf(stderr, "Skipping file: %s\n", a2);
return 1LL;
}
}
v7 = 64;
fprintf(stderr, "Progress for: %s\n", a2);
fputc(124, stderr);
do
{
fputc(45, stderr);
--v7;
}
while ( v7 );
v8 = 0;
fwrite("|\n ", 1uLL, 3uLL, stderr);
do
{
v9 = v8++;
dexuxputblock(a1, v9, a4);
a4 += 0x2000LL;
fwrite("****", 1uLL, 4uLL, stderr);
}
while ( v8 != 16 );
fputc(10, stderr);
return 0LL;
}

original_code:
int dexwritefull(int dexuxfd, char *fname, char *fileformat, unsigned char *pblock) {
  int progresscnt, blockcnt;
  unsigned char headerdata[129];
  unsigned char framerequest[2], *pframerequest;
    pframerequest = framerequest;
    for (blockcnt = 1; blockcnt <= 15; blockcnt++) {
      *(pframerequest+0) = 0;
      *(pframerequest+1) = blockcnt;
      dexuxgetframe(dexuxfd, framerequest, headerdata);
      if ((headerdata[0] & 240) != 0xA0) {
 fprintf(stderr, "Detected file format %s which contains", fileformat);
        fprintf(stderr, " a full memorycard image\n");
        fprintf(stderr, "But the card in the drive still has data which");
        fprintf(stderr, " has not been deleted\n");
        fprintf(stderr, "Skipping file: %s\n", fname);
        return(1);
      }
    }
    fprintf(stderr, "Progress for: %s\n", fname);
    fprintf(stderr, "|");
    for (progresscnt = 0; progresscnt < 64; progresscnt++) {
      fprintf(stderr, "-");
    }
    fprintf(stderr, "|\n ");
    for (blockcnt = 0; blockcnt <= 15; blockcnt++) {
      dexuxputblock(dexuxfd, blockcnt, pblock);
      pblock += 8192;
      fprintf(stderr, "****");
    }
    fprintf(stderr, "\n");
  return(0);
}

canonical_original_code:
int dexwritefull(int dexuxfd, char *fname, char *fileformat, unsigned char *pblock) {
  int progresscnt; int blockcnt;
  unsigned char headerdata[129];
  unsigned char framerequest[2]; unsigned char *pframerequest;
    pframerequest = framerequest;
    for (blockcnt = 1; blockcnt <= 15; blockcnt++) {
      *(pframerequest+0) = 0;
      *(pframerequest+1) = blockcnt;
      dexuxgetframe(dexuxfd, framerequest, headerdata);
      if ((headerdata[0] & 240) != 0xA0) {
 fprintf(stderr, "Detected file format %s which contains", fileformat);
        fprintf(stderr, " a full memorycard image\n");
        fprintf(stderr, "But the card in the drive still has data which");
        fprintf(stderr, " has not been deleted\n");
        fprintf(stderr, "Skipping file: %s\n", fname);
        return(1);
      }
    }
    fprintf(stderr, "Progress for: %s\n", fname);
    fprintf(stderr, "|");
    for (progresscnt = 0; progresscnt < 64; progresscnt++) {
      fprintf(stderr, "-");
    }
    fprintf(stderr, "|\n ");
    for (blockcnt = 0; blockcnt <= 15; blockcnt++) {
      dexuxputblock(dexuxfd, blockcnt, pblock);
      pblock += 8192;
      fprintf(stderr, "****");
    }
    fprintf(stderr, "\n");
  return(0);
}

variable_types: dexuxfd int

variable_types:
fname
char *

variable_types:
fileformat
char *

variable_types:
pblock
unsigned char *

variable_types: progresscnt int

variable_types: blockcnt int

variable_types:
framerequest
unsigned char [2]

variable_types:
pframerequest
unsigned char *


dexdelete

decompiled_code:
__int64 __fastcall dexdelete(__int64 a1, char a2, unsigned int a3)
{
char v5[2]; // [rsp+Eh] [rbp-AAh] BYREF
char v6[8]; // [rsp+10h] [rbp-A8h] BYREF
char v7; // [rsp+18h] [rbp-A0h]
char v8; // [rsp+8Fh] [rbp-29h]

v5[1] = a2;
v5[0] = 0;
dexuxgetframe(a1, v5, v6);
if ( (v6[0] & 0xF0) != 0xA0 )
{
if ( !a3 )
{
v6[0] = (v6[0] & 0xF) - 96;
LABEL_8:
v8 = dexuxstrxor(v6, 127LL);
dexuxputframe((unsigned int)a1, v5, v6);
goto LABEL_4;
}
if ( (v6[0] & 0xF0) == 80 )
goto LABEL_4;
}
if ( a3 == 1 )
{
v6[0] = (v6[0] & 0xF) + 80;
goto LABEL_8;
}
LABEL_4:
if ( v7 != -1 )
dexdelete((unsigned int)a1, (unsigned __int8)(v7 + 1), a3);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, char a2, unsigned int a3)
{
char v5[2]; // [rsp+Eh] [rbp-AAh] BYREF
char v6[8]; // [rsp+10h] [rbp-A8h] BYREF
char v7; // [rsp+18h] [rbp-A0h]
char v8; // [rsp+8Fh] [rbp-29h]

v5[1] = a2;
v5[0] = 0;
dexuxgetframe(a1, v5, v6);
if ( (v6[0] & 0xF0) != 0xA0 )
{
if ( !a3 )
{
v6[0] = (v6[0] & 0xF) - 96;
LABEL_8:
v8 = dexuxstrxor(v6, 127LL);
dexuxputframe((unsigned int)a1, v5, v6);
goto LABEL_4;
}
if ( (v6[0] & 0xF0) == 80 )
goto LABEL_4;
}
if ( a3 == 1 )
{
v6[0] = (v6[0] & 0xF) + 80;
goto LABEL_8;
}
LABEL_4:
if ( v7 != -1 )
func0((unsigned int)a1, (unsigned __int8)(v7 + 1), a3);
return 0LL;
}

original_code:
int dexdelete(int dexuxfd, int blocknum, int undeleteflag) {
  unsigned char headerdata[129];
  char chunkrequest[2], *pchunkrequest;
  pchunkrequest = chunkrequest;
  *(pchunkrequest+0) = 0;
  *(pchunkrequest+1) = blocknum;
  dexuxgetframe(dexuxfd, chunkrequest, headerdata);
  if ((((headerdata[0] & 240) != 0xA0) && (undeleteflag == 0)) ||
      (((headerdata[0] & 240) != 0x50) && (undeleteflag == 1))) {
    if (undeleteflag == 0) {
      headerdata[0] = (headerdata[0] & 15) + 0xA0;
    } else {
      headerdata[0] = (headerdata[0] & 15) + 0x50;
    }
    headerdata[127] = dexuxstrxor(headerdata, 127);
    dexuxputframe(dexuxfd, chunkrequest, headerdata);
  }
  if (headerdata[8] != 0xFF) {
    dexdelete(dexuxfd, headerdata[8] + 1, undeleteflag);
  }
  return(0);
}

canonical_original_code:
int dexdelete(int dexuxfd, int blocknum, int undeleteflag) {
  unsigned char headerdata[129];
  char chunkrequest[2]; char *pchunkrequest;
  pchunkrequest = chunkrequest;
  *(pchunkrequest+0) = 0;
  *(pchunkrequest+1) = blocknum;
  dexuxgetframe(dexuxfd, chunkrequest, headerdata);
  if ((((headerdata[0] & 240) != 0xA0) && (undeleteflag == 0)) ||
      (((headerdata[0] & 240) != 0x50) && (undeleteflag == 1))) {
    if (undeleteflag == 0) {
      headerdata[0] = (headerdata[0] & 15) + 0xA0;
    } else {
      headerdata[0] = (headerdata[0] & 15) + 0x50;
    }
    headerdata[127] = dexuxstrxor(headerdata, 127);
    dexuxputframe(dexuxfd, chunkrequest, headerdata);
  }
  if (headerdata[8] != 0xFF) {
    dexdelete(dexuxfd, headerdata[8] + 1, undeleteflag);
  }
  return(0);
}

variable_types: blocknum int

variable_types: undeleteflag int

variable_types:
headerdata
unsigned char [129]

variable_types:
chunkrequest
char [2]

variable_types:
pchunkrequest
char *


dexuxstrxor

variable_types:
instring
char *

variable_types: stringlength long

variable_types: outbyte int

variable_types: i long


dexuxputframe

original_code:
int dexuxputframe(int fd, char *address, char *data) {
  char buffer[5];
  char sendstring[133], *psendstring;
  char checkbyte;
  int readlength;
  int i;
  psendstring = sendstring;
  *(psendstring+132) = 0;
  *(psendstring+0) = *(address+0);
  *(psendstring+1) = *(address+1);
  *(psendstring+2) = dexuxbinreverse( *(address+0) );
  *(psendstring+3) = dexuxbinreverse( *(address+1) );
  for (i = 0; i <= 127; i++) {
    *(psendstring+4+i) = *(data+i);
  }
  dexuxclear(fd);
  checkbyte = dexuxstrxor(sendstring, 132);
  write(fd, "IAI\x04", 4);
  write(fd, sendstring, 132);
  write(fd, &checkbyte, 1);
  readlength = read(fd, buffer, 4);
  if (strncmp(buffer, "IAI\x29", 4)) {
          buffer[readlength] = 0;
          return(1);
  }
  return(readlength);
}

canonical_original_code:
int dexuxputframe(int fd, char *address, char *data) {
  char buffer[5];
  char sendstring[133]; char *psendstring;
  char checkbyte;
  int readlength;
  int i;
  psendstring = sendstring;
  *(psendstring+132) = 0;
  *(psendstring+0) = *(address+0);
  *(psendstring+1) = *(address+1);
  *(psendstring+2) = dexuxbinreverse( *(address+0) );
  *(psendstring+3) = dexuxbinreverse( *(address+1) );
  for (i = 0; i <= 127; i++) {
    *(psendstring+4+i) = *(data+i);
  }
  dexuxclear(fd);
  checkbyte = dexuxstrxor(sendstring, 132);
  write(fd, "IAI\x04", 4);
  write(fd, sendstring, 132);
  write(fd, &checkbyte, 1);
  readlength = read(fd, buffer, 4);
  if (strncmp(buffer, "IAI\x29", 4)) {
          buffer[readlength] = 0;
          return(1);
  }
  return(readlength);
}

variable_types: fd int

variable_types:
address
char *

variable_types:
data
char *

variable_types:
buffer
char [5]

variable_types:
sendstring
char [133]

variable_types:
psendstring
char *

variable_types: checkbyte char

variable_types: readlength int

variable_types: i int


dexuxclose

decompiled_code:
__int64 __fastcall dexuxclose(int fd)
{
write(fd, "IAI\a", 5uLL);
close(fd);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
write(fd, "IAI\a", 5uLL);
close(fd);
return 0LL;
}

original_code:
int dexuxclose(int fd) {
  write(fd, "IAI\x07\x00", 5);
  close(fd);
  return(0);
}


dexuxstatus

decompiled_code:
__int64 __fastcall dexuxstatus(int fd)
{
int v1; // eax
unsigned __int64 v2; // rcx
unsigned int v3; // er8
unsigned __int64 v4; // rcx
bool v5; // zf
unsigned __int64 v6; // rcx
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

dexuxclear();
write(fd, &unk_DC, 4uLL);
v1 = read(fd, v8, 0xFEuLL);
v2 = 5LL;
v3 = 1;
v8[v1] = 0;
if ( (unsigned __int64)v1 <= 5 )
v2 = v1;
if ( memcmp(v8, "IAI\"", v2) )
{
v4 = 6LL;
if ( (unsigned __int64)v1 <= 6 )
v4 = v1;
v5 = memcmp(v8, &unk_E6, v4) == 0;
v3 = !v5;
if ( !v5 )
{
v6 = 5LL;
if ( (unsigned __int64)v1 <= 5 )
v6 = v1;
v5 = memcmp(v8, "IAI#", v6) == 0;
v3 = !v5;
if ( !v5 )
v3 = 2;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func0(int fd)
{
int v1; // eax
unsigned __int64 v2; // rcx
unsigned int v3; // er8
unsigned __int64 v4; // rcx
bool v5; // zf
unsigned __int64 v6; // rcx
char v8[280]; // [rsp+0h] [rbp-118h] BYREF

dexuxclear();
write(fd, &unk_DC, 4uLL);
v1 = read(fd, v8, 0xFEuLL);
v2 = 5LL;
v3 = 1;
v8[v1] = 0;
if ( (unsigned __int64)v1 <= 5 )
v2 = v1;
if ( memcmp(v8, "IAI\"", v2) )
{
v4 = 6LL;
if ( (unsigned __int64)v1 <= 6 )
v4 = v1;
v5 = memcmp(v8, &unk_E6, v4) == 0;
v3 = !v5;
if ( !v5 )
{
v6 = 5LL;
if ( (unsigned __int64)v1 <= 5 )
v6 = v1;
v5 = memcmp(v8, "IAI#", v6) == 0;
v3 = !v5;
if ( !v5 )
v3 = 2;
}
}
return v3;
}

original_code:
int dexuxstatus(int fd) {
  char buffer[255];
  int readlength;
  dexuxclear(fd);
  write(fd, "IAI\x01",4);
  readlength = read(fd, &buffer, 254);
  buffer[readlength]='\0';
  if (!strncmp(buffer, "IAI\x22",readlength)) {
    return(1);
  } else if (!strncmp(buffer, "IAI\x23\x10",readlength)) {
    return(0);
  } else if (!strncmp(buffer, "IAI\x23\x00",readlength)) {
    return(0);
  } else {
    return(2);
  }
}

variable_types:
buffer
char [255]


dexwritesingle

original_code:
int dexwritesingle(int dexuxfd, char *fname, char *fileformat, unsigned char *pblock, int imagesize) {
  int copycnt, progresscnt;
  int blockcnt, offset=0, blocksavailable=0, blocksavaillist[15];
  unsigned char headerdata[129], headerdatain[129], framerequest[2], *pframerequest;
    pframerequest = framerequest;
    if (DEXUXDEBUGMODE) fprintf(stderr, "dexwritesingle()\n  Creating TOC entry...\n");
    if (strcmp(fileformat, "PSX") == 0) {
      if (DEXUXDEBUGMODE) fprintf(stderr, "  File is in PSX format with imagesize of %d\n", imagesize);
      headerdata[0] = 0x51;
      headerdata[1] = 0;
      headerdata[2] = 0;
      headerdata[3] = 0;
      headerdata[4] = 0;
      if (imagesize < 8) {
        headerdata[5] = imagesize << 5;
        headerdata[6] = 0;
      } else {
        headerdata[5] = (imagesize - 8) << 5;
        headerdata[6] = 1;
      }
      headerdata[7] = 0;
      headerdata[9] = 0;
      for (copycnt = 0; copycnt <= 20; copycnt++) {
        headerdata[copycnt + 10] = pblock[copycnt];
      }
      for (copycnt = 0x1E; copycnt < 0x7F; copycnt++) {
        headerdata[copycnt] = 0;
      }
      headerdata[127] = dexuxstrxor(headerdata, 127);
      pblock += 74;
    } else {
      if (DEXUXDEBUGMODE) fprintf(stderr, "  File is in MCS format with imagesize of %d\n", imagesize);
      for (copycnt = 0; copycnt < 128; copycnt++) {
        headerdata[copycnt] = pblock[copycnt];
      }
      pblock += 128;
    }
    for (blockcnt = 1; blockcnt <= 15; blockcnt++) {
      *(pframerequest+0) = 0;
      *(pframerequest+1) = blockcnt;
      dexuxgetframe(dexuxfd, framerequest, headerdatain);
      if ((headerdatain[0] & 240) == 0xA0) {
        blocksavaillist[blocksavailable] = blockcnt;
        blocksavailable++;
        if (DEXUXDEBUGMODE) fprintf(stderr, "  Available block found: #%d\n", blockcnt);
      }
      if (imagesize == blocksavailable) break;
    }
    if (imagesize > blocksavailable) {
      fprintf(stderr, "File requires %d block(s) but only", imagesize);
      fprintf(stderr, " %d block(s) available on the card\n", blocksavailable);
      fprintf(stderr, "Skipping file: %s\n", fname);
      return(1);
    }
    fprintf(stderr, "Progress for %s (%d blocks in size):\n", fname, imagesize);
    for (blockcnt = 0; blockcnt < imagesize; blockcnt++) {
      fprintf(stderr, "  Writting block #%d\n", blockcnt + 1);
      if (blockcnt != (imagesize - 1)) {
 if (DEXUXDEBUGMODE) fprintf(stderr, "  blockcnt != (imagesize -1)\n");
        if (blockcnt > 0) {
          if (DEXUXDEBUGMODE) fprintf(stderr, "  blockcnt > 0\n");
          headerdata[0] = 0x52;
        }
        headerdata[8] = blocksavaillist[blockcnt + 1] - 1;
        headerdata[9] = 0;
      } else {
        if (DEXUXDEBUGMODE) fprintf(stderr, "  blockcnt == (imagesize - 1)\n");
        if (blockcnt > 0) {
          if (DEXUXDEBUGMODE) fprintf(stderr, "  blockcnt > 0\n");
          headerdata[0] = 0x53;
        }
        headerdata[8] = 0xFF;
        headerdata[9] = 0xFF;
      }
      if (DEXUXDEBUGMODE) fprintf(stderr, "  headerdata\n");
      if (DEXUXDEBUGMODE) fprintf(stderr, "    00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15\n");
      if (DEXUXDEBUGMODE) fprintf(stderr, "    %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c\n",
        headerdata[ 0], headerdata[ 1], headerdata[ 2], headerdata[ 3],
        headerdata[ 4], headerdata[ 5], headerdata[ 6], headerdata[ 7],
        headerdata[ 8], headerdata[ 9], headerdata[10], headerdata[11],
        headerdata[12], headerdata[13], headerdata[14], headerdata[15],
        headerdata[16], headerdata[17], headerdata[18], headerdata[19],
        headerdata[20], headerdata[21]);
      headerdata[127] = dexuxstrxor(headerdata, 127);
      *(pframerequest+0) = 0;
      *(pframerequest+1) = blocksavaillist[blockcnt];
      if (DEXUXDEBUGMODE) fprintf(stderr, "  Writting to block #%d\n", blocksavaillist[blockcnt]);
      if (DEXUXDEBUGMODE) fprintf(stderr, "  Address %d %d\n", *(pframerequest+0), *(pframerequest+1));
      dexuxputframe(dexuxfd, framerequest, headerdata);
      dexuxputblock(dexuxfd, blocksavaillist[blockcnt], pblock);
      pblock += 8192;
    }
  return(0);
}

canonical_original_code:
int dexwritesingle(int dexuxfd, char *fname, char *fileformat, unsigned char *pblock, int imagesize) {
  int copycnt; int progresscnt;
  int blockcnt; int offset = 0; int blocksavailable = 0; int blocksavaillist[15];
  unsigned char headerdata[129]; unsigned char headerdatain[129]; unsigned char framerequest[2]; unsigned char *pframerequest;
    pframerequest = framerequest;
    if (DEXUXDEBUGMODE) fprintf(stderr, "dexwritesingle()\n  Creating TOC entry...\n");
    if (strcmp(fileformat, "PSX") == 0) {
      if (DEXUXDEBUGMODE) fprintf(stderr, "  File is in PSX format with imagesize of %d\n", imagesize);
      headerdata[0] = 0x51;
      headerdata[1] = 0;
      headerdata[2] = 0;
      headerdata[3] = 0;
      headerdata[4] = 0;
      if (imagesize < 8) {
        headerdata[5] = imagesize << 5;
        headerdata[6] = 0;
      } else {
        headerdata[5] = (imagesize - 8) << 5;
        headerdata[6] = 1;
      }
      headerdata[7] = 0;
      headerdata[9] = 0;
      for (copycnt = 0; copycnt <= 20; copycnt++) {
        headerdata[copycnt + 10] = pblock[copycnt];
      }
      for (copycnt = 0x1E; copycnt < 0x7F; copycnt++) {
        headerdata[copycnt] = 0;
      }
      headerdata[127] = dexuxstrxor(headerdata, 127);
      pblock += 74;
    } else {
      if (DEXUXDEBUGMODE) fprintf(stderr, "  File is in MCS format with imagesize of %d\n", imagesize);
      for (copycnt = 0; copycnt < 128; copycnt++) {
        headerdata[copycnt] = pblock[copycnt];
      }
      pblock += 128;
    }
    for (blockcnt = 1; blockcnt <= 15; blockcnt++) {
      *(pframerequest+0) = 0;
      *(pframerequest+1) = blockcnt;
      dexuxgetframe(dexuxfd, framerequest, headerdatain);
      if ((headerdatain[0] & 240) == 0xA0) {
        blocksavaillist[blocksavailable] = blockcnt;
        blocksavailable++;
        if (DEXUXDEBUGMODE) fprintf(stderr, "  Available block found: #%d\n", blockcnt);
      }
      if (imagesize == blocksavailable) break;
    }
    if (imagesize > blocksavailable) {
      fprintf(stderr, "File requires %d block(s) but only", imagesize);
      fprintf(stderr, " %d block(s) available on the card\n", blocksavailable);
      fprintf(stderr, "Skipping file: %s\n", fname);
      return(1);
    }
    fprintf(stderr, "Progress for %s (%d blocks in size):\n", fname, imagesize);
    for (blockcnt = 0; blockcnt < imagesize; blockcnt++) {
      fprintf(stderr, "  Writting block #%d\n", blockcnt + 1);
      if (blockcnt != (imagesize - 1)) {
 if (DEXUXDEBUGMODE) fprintf(stderr, "  blockcnt != (imagesize -1)\n");
        if (blockcnt > 0) {
          if (DEXUXDEBUGMODE) fprintf(stderr, "  blockcnt > 0\n");
          headerdata[0] = 0x52;
        }
        headerdata[8] = blocksavaillist[blockcnt + 1] - 1;
        headerdata[9] = 0;
      } else {
        if (DEXUXDEBUGMODE) fprintf(stderr, "  blockcnt == (imagesize - 1)\n");
        if (blockcnt > 0) {
          if (DEXUXDEBUGMODE) fprintf(stderr, "  blockcnt > 0\n");
          headerdata[0] = 0x53;
        }
        headerdata[8] = 0xFF;
        headerdata[9] = 0xFF;
      }
      if (DEXUXDEBUGMODE) fprintf(stderr, "  headerdata\n");
      if (DEXUXDEBUGMODE) fprintf(stderr, "    00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15\n");
      if (DEXUXDEBUGMODE) fprintf(stderr, "    %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x %.2x  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c  %c\n",
        headerdata[ 0], headerdata[ 1], headerdata[ 2], headerdata[ 3],
        headerdata[ 4], headerdata[ 5], headerdata[ 6], headerdata[ 7],
        headerdata[ 8], headerdata[ 9], headerdata[10], headerdata[11],
        headerdata[12], headerdata[13], headerdata[14], headerdata[15],
        headerdata[16], headerdata[17], headerdata[18], headerdata[19],
        headerdata[20], headerdata[21]);
      headerdata[127] = dexuxstrxor(headerdata, 127);
      *(pframerequest+0) = 0;
      *(pframerequest+1) = blocksavaillist[blockcnt];
      if (DEXUXDEBUGMODE) fprintf(stderr, "  Writting to block #%d\n", blocksavaillist[blockcnt]);
      if (DEXUXDEBUGMODE) fprintf(stderr, "  Address %d %d\n", *(pframerequest+0), *(pframerequest+1));
      dexuxputframe(dexuxfd, framerequest, headerdata);
      dexuxputblock(dexuxfd, blocksavaillist[blockcnt], pblock);
      pblock += 8192;
    }
  return(0);
}

variable_types: dexuxfd int

variable_types:
fname
char *

variable_types:
fileformat
char *

variable_types:
pblock
unsigned char *

variable_types: imagesize int

variable_types: copycnt int

variable_types: progresscnt int

variable_types: blockcnt int

variable_types: offset int

variable_types: blocksavailable int

variable_types:
blocksavaillist
int [15]

variable_types:
headerdata
unsigned char [129]

variable_types:
headerdatain
unsigned char [129]

variable_types:
framerequest
unsigned char [2]

variable_types:
pframerequest
unsigned char *


repo: mikestaub/Pascal-Compiler

decompiled_code:
__int64 __fastcall init_stack(__int64 a1)
{
*(_QWORD *)(a1 + 800) = a1;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
*(_QWORD *)(a1 + 800) = a1;
return 0LL;
}

original_code:
extern status init_stack ( stack *p_S ) {
  p_S -> top = p_S -> base ;
  return OK ;
}

canonical_original_code:
extern enum status init_stack(struct stack *p_S) {
  p_S -> top = p_S -> base ;
  return OK ;
}

variable_types: struct stack { void *base[100]; void **top; } *

return_type: enum status { OK=0, ERROR=1 }


pop

decompiled_code:
_BOOL8 __fastcall pop(__int64 a1, _QWORD *a2)
{
_BOOL8 result; // rax
_QWORD *v3; // rdx

result = empty_stack(a1);
if ( !result )
{
v3 = (_QWORD *)(*(_QWORD *)(a1 + 800) - 8LL);
*(_QWORD *)(a1 + 800) = v3;
*a2 = *v3;
result = 0LL;
}
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, _QWORD *a2)
{
_BOOL8 result; // rax
_QWORD *v3; // rdx

result = func1(a1);
if ( !result )
{
v3 = (_QWORD *)(*(_QWORD *)(a1 + 800) - 8LL);
*(_QWORD *)(a1 + 800) = v3;
*a2 = *v3;
result = 0LL;
}
return result;
}

original_code:
extern status pop( stack *p_S , generic_ptr *p_data ) {
  if ( empty_stack ( p_S ) == TRUE ) return ERROR ;
  p_S -> top-- ;
  *p_data = *p_S->top ;
  return OK ;
}

canonical_original_code:
extern enum status pop(struct stack *p_S, void **p_data) {
  if ( empty_stack ( p_S ) == TRUE ) return ERROR ;
  p_S -> top-- ;
  *p_data = *p_S->top ;
  return OK ;
}

user_defined_types: struct stack { void *base[100]; void **top; }


push

original_code:
extern status push ( stack *p_S , generic_ptr data ) {
  if ( ( (p_S) -> top - (p_S) -> base ) == 100 )
    return ERROR ;
  *p_S -> top = data ;
  p_S -> top++ ;
  return OK ;
}

canonical_original_code:
extern enum status push(struct stack *p_S, void *data) {
  if ( ( (p_S) -> top - (p_S) -> base ) == 100 )
    return ERROR ;
  *p_S -> top = data ;
  p_S -> top++ ;
  return OK ;
}

variable_types:
data
void *


top

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

if ( pop(a1, a2) )
result = 1LL;
else
result = push(a1, *a2);
return result;
}

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

if ( func2(a1, a2) )
result = 1LL;
else
result = func3(a1, *a2);
return result;
}

original_code:
extern status top ( stack *p_S , generic_ptr *p_data ) {
  if ( pop ( p_S , p_data ) == ERROR ) return ERROR ;
       return push ( p_S , *p_data ) ;
}

canonical_original_code:
extern enum status top(struct stack *p_S, void **p_data) {
  if ( pop ( p_S , p_data ) == ERROR ) return ERROR ;
       return push ( p_S , *p_data ) ;
}


main

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

v3 = argv[1];
yydebug = 0;
yyin = fopen(v3, "r");
v4 = safe_malloc(1LL);
v5 = argv[1];
input_file_name = v4;
strcpy((char *)v4, v5);
if ( (unsigned int)yyparse() )
puts("The file fails to parse.");
else
cg(program_tac);
fclose(yyin);
return 0;
}

original_code:
int main(int argc, char* argv[]){
  yydebug = 0;
  yyin = fopen(argv[1], "r");
  int len = strlen(argv[1]);
  input_file_name = (char*)safe_malloc(sizeof(char));
  strcpy(input_file_name, argv[1]);
  if(!yyparse()){
     cg(program_tac);
  }
  else
     printf("The file fails to parse.\n");
  fclose(yyin);
  return 0;
}

canonical_original_code:
int main(int argc, char *argv[]){
  yydebug = 0;
  yyin = fopen(argv[1], "r");
  int len = strlen(argv[1]);
  input_file_name = (char *)safe_malloc(sizeof(char));
  strcpy(input_file_name, argv[1]);
  if(!yyparse()){
     cg(program_tac);
  }
  else
     printf("The file fails to parse.\n");
  fclose(yyin);
  return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: len int


yyerror

decompiled_code:
int __fastcall yyerror(const char *a1)
{
return printf("Error parsing, %s\n", a1);
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
return printf("Error parsing, %s\n", a1);
}

original_code:
void yyerror(char* text){
  printf("Error parsing, %s\n", text);
}

canonical_original_code:
void yyerror(char *text){
  printf("Error parsing, %s\n", text);
}

variable_types:
text
char *


decompiled_code:
__int64 __fastcall push_offset(__int64 a1, int a2)
{
_DWORD *v2; // rax
void *v3; // rbp

v2 = malloc(4uLL);
if ( !v2 )
return 1LL;
*v2 = a2;
v3 = v2;
if ( (unsigned int)push(a1, v2) != 1 )
return 0LL;
free(v3);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, int a2)
{
_DWORD *v2; // rax
void *v3; // rbp

v2 = malloc(4uLL);
if ( !v2 )
return 1LL;
*v2 = a2;
v3 = v2;
if ( (unsigned int)push(a1, v2) != 1 )
return 0LL;
free(v3);
return 1LL;
}

original_code:
status push_offset ( stack *p_S , int offset ) {
  int *p_c = (int *) malloc (sizeof(int)) ;
  if ( p_c == ((void *)0) ) return ERROR ;
  *p_c = offset ;
  if ( push(p_S, (generic_ptr) p_c) == ERROR ) {
    free (p_c); return ERROR ;
  }
  return OK ;
}

canonical_original_code:
enum status push_offset(struct stack *p_S, int offset) {
  int *p_c = (int *) malloc (sizeof(int));
  if ( p_c == ((void *)0) ) return ERROR ;
  *p_c = offset ;
  if ( push(p_S, (void *) p_c) == ERROR ) {
    free (p_c); return ERROR ;
  }
  return OK ;
}