decompiled_code:
__int64 __fastcall patch_16bit(__int64 a1, int *a2, __int64 a3, const char *a4)
{
int v4; // eax
__int16 *v5; // rbp

v4 = atoi(a4);
if ( a2[6] > v4 )
return 0xFFFFFFFFLL;
if ( a2[7] < v4 )
return 0xFFFFFFFFLL;
v5 = (__int16 *)(a2[4] + a1);
*v5 = _bswap_16(v4);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func16(__int64 a1, int *a2, __int64 a3, const char *a4)
{
int v4; // eax
__int16 *v5; // rbp

v4 = atoi(a4);
if ( a2[6] > v4 )
return 0xFFFFFFFFLL;
if ( a2[7] < v4 )
return 0xFFFFFFFFLL;
v5 = (__int16 *)(a2[4] + a1);
*v5 = func15(v4);
return 0LL;
}

original_code:
static int patch_16bit(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 int value = atoi(parameter);
 if (value < patch->min || value > patch->max)
  return -1;
 *((uint16_t *)(config + patch->offset)) = htons(value);
 return 0;
}

canonical_original_code:
static int patch_16bit(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 int value = atoi(parameter);
 if (value < patch->min || value > patch->max)
  return -1;
 *((unsigned short *)(config + patch->offset)) = htons(value);
 return 0;
}


decompiled_code:
__int64 __fastcall patch_ip(__int64 a1, __int64 a2, __int64 a3, const char *a4)
{
return (unsigned int)-(inet_pton(2, a4, (void *)(a1 + *(int *)(a2 + 16))) <= 0);
}

canonical_decompiled_code:
__int64 __fastcall func17(__int64 a1, __int64 a2, __int64 a3, const char *a4)
{
return (unsigned int)-(inet_pton(2, a4, (void *)(a1 + *(int *)(a2 + 16))) <= 0);
}

original_code:
static int patch_ip(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 return (inet_pton(2, parameter, config + patch->offset) <= 0) ? -1 : 0;
}

canonical_original_code:
static int patch_ip(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 return (inet_pton(2, parameter, config + patch->offset) <= 0) ? -1 : 0;
}

variable_types:
config
void *

variable_types: struct cfg_patch { int code; int mask; int (*patch)(void *config, struct cfg_patch *patch, int code, char *parameter); int offset; int size; int min; int max; } *

variable_types: code int

variable_types:
parameter
char *

return_type: int


decompiled_code:
__int64 __fastcall patch_defaultgw(__int64 a1, __int64 a2, __int64 a3, const char *a4)
{
*(_BYTE *)(a1 + 4365) = 2;
return patch_ip(a1, a2, a3, a4);
}

original_code:
static int patch_defaultgw(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 *((uint8_t *)(config + 0x110d)) = 0x02;
 return patch_ip(config, patch, code, parameter);
}

canonical_original_code:
static int patch_defaultgw(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 *((unsigned char *)(config + 0x110d)) = 0x02;
 return patch_ip(config, patch, code, parameter);
}

user_defined_types: struct cfg_patch { int code; int mask; int (*patch)(void *config, struct cfg_patch *patch, int code, char *parameter); int offset; int size; int min; int max; }


decompiled_code:
__int64 __fastcall config_patch(__int64 a1, unsigned int a2, const char *a3)
{
_DWORD *v4; // rdx
int v5; // ecx
int v6; // eax
unsigned int v7; // er12

v4 = &patcharr;
v5 = 0;
while ( 1 )
{
v6 = v4[1];
if ( !v6 )
v6 = -1;
if ( (a2 & v6) == *v4 )
break;
++v5;
v4 += 8;
if ( v5 == 17 )
{
printf("nothing found to patch code=0x%x parameter='%s'\n", a2, a3);
return (unsigned int)-1;
}
}
v7 = (*((__int64 (__fastcall **)(__int64, char *, _QWORD, const char *))&patcharr + 4 * v5 + 1))(
a1,
(char *)&patcharr + 32 * v5,
a2,
a3);
if ( v7 )
printf("failed to patch code=0x%x parameter='%s'\n", a2, a3);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func19(__int64 a1, unsigned int a2, const char *a3)
{
_DWORD *v4; // rdx
int v5; // ecx
int v6; // eax
unsigned int v7; // er12

v4 = &patcharr;
v5 = 0;
while ( 1 )
{
v6 = v4[1];
if ( !v6 )
v6 = -1;
if ( (a2 & v6) == *v4 )
break;
++v5;
v4 += 8;
if ( v5 == 17 )
{
printf("nothing found to patch code=0x%x parameter='%s'\n", a2, a3);
return (unsigned int)-1;
}
}
v7 = (*((__int64 (__fastcall **)(__int64, char *, _QWORD, const char *))&patcharr + 4 * v5 + 1))(
a1,
(char *)&patcharr + 32 * v5,
a2,
a3);
if ( v7 )
printf("failed to patch code=0x%x parameter='%s'\n", a2, a3);
return v7;
}

original_code:
int config_patch(void *config, int code, const char *parameter)
{
 int i;
 for (i = 0; i < (sizeof(patcharr) / sizeof(struct cfg_patch)); i++) {
  int mask = (patcharr[i].mask != 0) ? patcharr[i].mask : ~0;
  if ((code & mask) == patcharr[i].code) {
   int retval = patcharr[i].patch(config, &patcharr[i], code, parameter);
   if (retval != 0)
    printf("failed to patch code=0x%x parameter='%s'\n", code, parameter);
   return retval;
  }
 }
 printf("nothing found to patch code=0x%x parameter='%s'\n", code, parameter);
 return -1;
}

canonical_original_code:
int config_patch(void *config, int code, char *parameter)
{
 int i;
 for (i = 0; i < (sizeof(patcharr) / sizeof(struct cfg_patch)); i++) {
  int mask = (patcharr[i].mask != 0) ? patcharr[i].mask : ~0;
  if ((code & mask) == patcharr[i].code) {
   int retval = patcharr[i].patch(config, &patcharr[i], code, parameter);
   if (retval != 0)
    printf("failed to patch code=0x%x parameter='%s'\n", code, parameter);
   return retval;
  }
 }
 printf("nothing found to patch code=0x%x parameter='%s'\n", code, parameter);
 return -1;
}

variable_types: i int

variable_types: mask int

variable_types: retval int


decompiled_code:
void __fastcall list_del(__int64 a1)
{
_list_del(*(_QWORD **)(a1 + 8), *(_QWORD *)a1);
*(_QWORD *)a1 = 0LL;
*(_QWORD *)(a1 + 8) = 0LL;
}

original_code:
static inline void list_del(struct list_head *entry)
{
 __list_del(entry->prev, entry->next);
 entry->next = ((void *)0);
 entry->prev = ((void *)0);
}

variable_types: struct list_head { struct list_head *next; } *

return_type: void


decompiled_code:
__int64 __fastcall cmp_timeval(_QWORD *a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rcx
__int64 v4; // rdx

result = 0xFFFFFFFFLL;
if ( *a1 <= *a2 )
{
result = 1LL;
if ( *a1 >= *a2 )
{
v3 = a1[1];
v4 = a2[1];
result = 0xFFFFFFFFLL;
if ( v3 <= v4 )
result = v3 < v4;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rcx
__int64 v4; // rdx

result = 0xFFFFFFFFLL;
if ( *a1 <= *a2 )
{
result = 1LL;
if ( *a1 >= *a2 )
{
v3 = a1[1];
v4 = a2[1];
result = 0xFFFFFFFFLL;
if ( v3 <= v4 )
result = v3 < v4;
}
}
return result;
}

original_code:
static int cmp_timeval(struct timeval *a, struct timeval *b)
{
 if (a->tv_sec > b->tv_sec)
  return -1;
 if (a->tv_sec < b->tv_sec)
  return 1;
 if (a->tv_usec > b->tv_usec)
  return -1;
 if (a->tv_usec < b->tv_usec)
  return 1;
 return 0;
}

variable_types: struct timeval { long tv_sec; long tv_usec; } *

variable_types:
b
struct timeval *


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

if ( a1 )
result = *(unsigned int *)(a1 + 20);
else
result = 0xFFFFFFFFLL;
return result;
}

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

if ( a1 )
result = *(unsigned int *)(a1 + 20);
else
result = 0xFFFFFFFFLL;
return result;
}

original_code:
int event_get_fd(struct event_fd *entry)
{
 return (entry != ((void *)0)) ? entry->fd: -1;
}

variable_types: struct event_fd { struct list_head { struct list_head *next; } list; unsigned int flags; int fd; int (*read_cb)(int fd, void *privdata); int (*write_cb)(int fd, void *privdata); void *read_priv; void *write_priv; } *

user_defined_types: struct event_fd { struct list_head list; unsigned int flags; int fd; int (*read_cb)(int fd, void *privdata); int (*write_cb)(int fd, void *privdata); void *read_priv; void *write_priv; }


decompiled_code:
void __fastcall event_remove_fd(__int64 a1)
{
*(_DWORD *)(a1 + 16) |= 0x2000u;
}

original_code:
void event_remove_fd(struct event_fd *entry)
{
 entry->flags |= 0x2000;
}

user_defined_types: struct list_head { struct list_head *next; }


decompiled_code:
void __fastcall event_remove_timeout(__int64 a1)
{
*(_DWORD *)(a1 + 16) |= 0x2000u;
}

original_code:
void event_remove_timeout(struct event_timeout *entry)
{
 entry->flags |= 0x2000;
}

variable_types: struct event_timeout { struct list_head { struct list_head *next; } list; unsigned int flags; struct timeval { long tv_sec; long tv_usec; } intervall; struct timeval nextrun; int (*callback)(void *privdata); void *privdata; } *

user_defined_types: struct event_timeout { struct list_head list; unsigned int flags; struct timeval intervall; struct timeval nextrun; int (*callback)(void *privdata); void *privdata; }


decompiled_code:
int print_version()
{
return printf("%s version %s\n", prog_name, prog_version_str);
}

canonical_decompiled_code:
int func7()
{
return printf("%s version %s\n", prog_name, prog_version_str);
}

original_code:
void
print_version ()
{
 printf ("%s version %s\n", prog_name, prog_version_str);
}

canonical_original_code:
void print_version()
{
 printf ("%s version %s\n", prog_name, prog_version_str);
}


decompiled_code:
int print_usage()
{
return printf(
"%s version %s\n"
"Usage: \n"
" %s [options] <source file> <destination file>\n"
"\n"
" General options\n"
" -h, --help Show this help\n"
" -o, --offset Set offset\n"
"\n"
" Example\n"
" %s --offset=0x2000 spt.dat\n",
prog_name,
prog_version_str,
prog_name,
prog_name);
}

canonical_decompiled_code:
int func8()
{
return printf(
"%s version %s\n"
"Usage: \n"
" %s [options] <source file> <destination file>\n"
"\n"
" General options\n"
" -h, --help Show this help\n"
" -o, --offset Set offset\n"
"\n"
" Example\n"
" %s --offset=0x2000 spt.dat\n",
prog_name,
prog_version_str,
prog_name,
prog_name);
}

original_code:
void
print_usage ()
{
 printf ("%s version %s\n"
   "Usage: \n"
   "      %s [options] <source file> <destination file>\n"
   "\n"
   "      General options\n"
   "        -h, --help      Show this help\n"
   "        -o, --offset    Set offset\n"
   "\n"
   "      Example\n"
   "           %s --offset=0x2000 spt.dat\n"
   , prog_name, prog_version_str
   , prog_name
   , prog_name);
}

canonical_original_code:
void print_usage()
{
 printf ("%s version %s\n"
   "Usage: \n"
   "      %s [options] <source file> <destination file>\n"
   "\n"
   "      General options\n"
   "        -h, --help      Show this help\n"
   "        -o, --offset    Set offset\n"
   "\n"
   "      Example\n"
   "           %s --offset=0x2000 spt.dat\n"
   , prog_name, prog_version_str
   , prog_name
   , prog_name);
}


decompiled_code:
int __fastcall print_object(__int64 a1)
{
printf("\tName: %s\n", (const char *)a1);
printf("\tUncompressed size: 0x%04x\n", *(unsigned int *)(a1 + 16));
printf("\tCompressed size: 0x%04x\n", *(unsigned int *)(a1 + 20));
return printf("\tOffset: 0x%04x\n", *(unsigned int *)(a1 + 24));
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1)
{
printf("\tName: %s\n", (const char *)a1);
printf("\tUncompressed size: 0x%04x\n", *(unsigned int *)(a1 + 16));
printf("\tCompressed size: 0x%04x\n", *(unsigned int *)(a1 + 20));
return printf("\tOffset: 0x%04x\n", *(unsigned int *)(a1 + 24));
}

original_code:
void print_object (Block_Object* obj)
{
 printf ("\tName: %s\n", obj->name);
 printf ("\tUncompressed size: 0x%04x\n", obj->uncomp_size);
 printf ("\tCompressed size:   0x%04x\n", obj->comp_size);
 printf ("\tOffset:  0x%04x\n", obj->offset);
}

canonical_original_code:
void print_object(struct _block_object *obj)
{
 printf ("\tName: %s\n", obj->name);
 printf ("\tUncompressed size: 0x%04x\n", obj->uncomp_size);
 printf ("\tCompressed size:   0x%04x\n", obj->comp_size);
 printf ("\tOffset:  0x%04x\n", obj->offset);
}

variable_types: struct _block_object { unsigned char name[-1]; unsigned int uncomp_size; unsigned int comp_size; unsigned int offset; } *


decompiled_code:
int __fastcall print_block_header(unsigned __int8 *a1)
{
printf("Block #%d\n", *a1);
printf("\tMagic number %x\n", a1[1]);
printf("\tObject count %d\n", *((unsigned __int16 *)a1 + 1));
return printf("\tBlock size %x\n", *((unsigned __int16 *)a1 + 2));
}

canonical_decompiled_code:
int __fastcall func10(unsigned __int8 *a1)
{
printf("Block #%d\n", *a1);
printf("\tMagic number %x\n", a1[1]);
printf("\tObject count %d\n", *((unsigned __int16 *)a1 + 1));
return printf("\tBlock size %x\n", *((unsigned __int16 *)a1 + 2));
}

original_code:
void print_block_header (Block* b)
{
 printf ("Block #%d\n", b->id);
 printf ("\tMagic number %x\n", b->magic_number);
 printf ("\tObject count %d\n", b->obj_count);
 printf ("\tBlock size %x\n", b->size);
}

canonical_original_code:
void print_block_header(struct _block *b)
{
 printf ("Block #%d\n", b->id);
 printf ("\tMagic number %x\n", b->magic_number);
 printf ("\tObject count %d\n", b->obj_count);
 printf ("\tBlock size %x\n", b->size);
}

variable_types: struct _block { unsigned char id; unsigned char magic_number; unsigned short obj_count; unsigned short size; struct _block_object { unsigned char name[-1]; unsigned int uncomp_size; unsigned int comp_size; unsigned int offset; } *object_v; } *

user_defined_types: struct _block { unsigned char id; unsigned char magic_number; unsigned short obj_count; unsigned short size; struct _block_object *object_v; }


decompiled_code:
int __fastcall print_block_obj(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = *(_QWORD *)(a1 + 8) + 28LL * (int)a2;
printf("Object index #%d\n", a2);
return print_object(v2);
}

canonical_decompiled_code:
int __fastcall func11(__int64 a1, __int64 a2)
{
__int64 v2; // rbx

v2 = *(_QWORD *)(a1 + 8) + 28LL * (int)a2;
printf("Object index #%d\n", a2);
return func9(v2);
}

original_code:
void print_block_obj (Block* b, int index)
{
 Block_Object* obj_p = &(b->object_v[index]);
 printf ("Object index #%d\n", index);
 print_object (obj_p);
}

canonical_original_code:
void print_block_obj(struct _block *b, int index)
{
 struct _block_object *obj_p = &(b->object_v[index]);
 printf ("Object index #%d\n", index);
 print_object (obj_p);
}

variable_types: index int

user_defined_types: struct _block_object { unsigned char name[-1]; unsigned int uncomp_size; unsigned int comp_size; unsigned int offset; }


decompiled_code:
__int64 __fastcall print_block_all_obj(__int64 a1)
{
int v1; // ebx
__int64 result; // rax

if ( *(_WORD *)(a1 + 2) )
{
v1 = 0;
do
{
print_block_obj(a1, (unsigned int)v1++);
result = *(unsigned __int16 *)(a1 + 2);
}
while ( (int)result > v1 );
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1)
{
int v1; // ebx
__int64 result; // rax

if ( *(_WORD *)(a1 + 2) )
{
v1 = 0;
do
{
func11(a1, (unsigned int)v1++);
result = *(unsigned __int16 *)(a1 + 2);
}
while ( (int)result > v1 );
}
return result;
}

original_code:
void print_block_all_obj (Block* b)
{
 int i = 0;
 for (; i < b->obj_count; i++) {
  print_block_obj (b, i);
 }
}

canonical_original_code:
void print_block_all_obj(struct _block *b)
{
 int i = 0;
 for (; i < b->obj_count; i++) {
  print_block_obj (b, i);
 }
}


decompiled_code:
__int64 __fastcall print_block(unsigned __int8 *a1)
{
print_block_header(a1);
return print_block_all_obj((__int64)a1);
}

canonical_decompiled_code:
__int64 __fastcall func13(unsigned __int8 *a1)
{
func10(a1);
return func12((__int64)a1);
}

original_code:
void print_block (Block* b)
{
 print_block_header(b);
 print_block_all_obj (b);
}

canonical_original_code:
void print_block(struct _block *b)
{
 print_block_header(b);
 print_block_all_obj (b);
}


canonical_original_code:
static inline void list_del(struct list_head *entry)
{
 __list_del(entry->prev, entry->next);
 entry->next = ((void *)0);
 entry->prev = ((void *)0);
}


original_code:
static int hash_key_calc(uint8_t *data)
{
 int key = 0x456789AB;
 key = (key << 5) ^ (key >> 27) ^ data[0];
 key = (key << 5) ^ (key >> 27) ^ data[1];
 return key % 127;
}

canonical_original_code:
static int hash_key_calc(unsigned char *data)
{
 int key = 0x456789AB;
 key = (key << 5) ^ (key >> 27) ^ data[0];
 key = (key << 5) ^ (key >> 27) ^ data[1];
 return key % 127;
}

variable_types:
data
unsigned char *

variable_types: key int


getMatchLen

original_code:
static int getMatchLen(uint8_t *a, uint8_t *b, uint32_t maxlen)
{
 if ((a[0] ^ b[0]) | (a[1] ^ b[1]))
  return 0;
 a += 2;
 b += 2;
 maxlen -= 2;
 int retval = 2;
 while ((*a++ == *b++) && maxlen--)
  retval++;
 return retval;
}

canonical_original_code:
static int getMatchLen(unsigned char *a, unsigned char *b, unsigned int maxlen)
{
 if ((a[0] ^ b[0]) | (a[1] ^ b[1]))
  return 0;
 a += 2;
 b += 2;
 maxlen -= 2;
 int retval = 2;
 while ((*a++ == *b++) && maxlen--)
  retval++;
 return retval;
}

variable_types:
a
unsigned char *

variable_types:
b
unsigned char *

variable_types:
maxlen
unsigned int


original_code:
int put_romfile(const char *filename, struct romfile *romfile)
{
 struct romfile_header header;
 memcpy(&header, (void *)(romfile->file->data) + romfile->baseoffset, sizeof(header));
 header.size = htons(romfile->size);
 memcpy((void *)(romfile->file->data) + romfile->baseoffset, &header, sizeof(header));
 return put_filedata(filename, romfile->file);
}

canonical_original_code:
int put_romfile(char *filename, struct romfile *romfile)
{
 struct romfile_header header;
 memcpy(&header, (void *)(romfile->file->data) + romfile->baseoffset, sizeof(header));
 header.size = htons(romfile->size);
 memcpy((void *)(romfile->file->data) + romfile->baseoffset, &header, sizeof(header));
 return put_filedata(filename, romfile->file);
}

variable_types:
filename
char *

variable_types: struct romfile { struct filedata { int size; void *data[]; } *file; unsigned int baseoffset; unsigned char *data; unsigned short size; } *

variable_types: struct romfile_header { unsigned short version; unsigned short size; unsigned short offset; char name[14]; }

user_defined_types: struct romfile { struct filedata *file; unsigned int baseoffset; unsigned char *data; unsigned short size; }


calcChecksum

decompiled_code:
__int64 __fastcall calcChecksum(__int64 a1, unsigned int a2)
{
__int64 v2; // rax
unsigned int v3; // edx

if ( a2 <= 3 )
return 0;
v2 = 0LL;
v3 = 0;
do
v3 += *(_DWORD *)(a1 + 4 * v2++);
while ( a2 >> 2 > (unsigned int)v2 );
return v3;
}

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

if ( a2 <= 3 )
return 0;
v2 = 0LL;
v3 = 0;
do
v3 += *(_DWORD *)(a1 + 4 * v2++);
while ( a2 >> 2 > (unsigned int)v2 );
return v3;
}

original_code:
unsigned int calcChecksum(unsigned int *data,unsigned int size)
{
 unsigned int i,checksum=0;
 for (i = 0; i < size/sizeof(unsigned int); i++)
 {
  checksum+=*(data+i);
 }
 return checksum;
}

canonical_original_code:
unsigned int calcChecksum(unsigned int *data, unsigned int size)
{
 unsigned int i; unsigned int checksum = 0;
 for (i = 0; i < size/sizeof(unsigned int); i++)
 {
  checksum+=*(data+i);
 }
 return checksum;
}

variable_types:
data
unsigned int *

variable_types:
size
unsigned int

variable_types:
i
unsigned int

variable_types:
checksum
unsigned int

return_type: unsigned int


displayInfo

decompiled_code:
int __fastcall displayInfo(int fd, unsigned int *a2)
{
unsigned int v2; // eax
__int64 v4; // [rsp+0h] [rbp-2018h] BYREF
char v5[8204]; // [rsp+Ch] [rbp-200Ch] BYREF

lseek(fd, 0LL, 0);
read(fd, &v4, 0x2000uLL);
printf("checksum is :%x\n", a2[2]);
printf("%d\n", a2[3]);
printf("%x\n", a2[20]);
printf("%d\n", a2[21]);
v2 = calcChecksum((__int64)v5, 0x1FF4u);
printf("%x\n", v2);
return printf("%d\n", 320LL);
}

canonical_decompiled_code:
int __fastcall func1(int fd, unsigned int *a2)
{
unsigned int v2; // eax
__int64 v4; // [rsp+0h] [rbp-2018h] BYREF
char v5[8204]; // [rsp+Ch] [rbp-200Ch] BYREF

lseek(fd, 0LL, 0);
read(fd, &v4, 0x2000uLL);
printf("checksum is :%x\n", a2[2]);
printf("%d\n", a2[3]);
printf("%x\n", a2[20]);
printf("%d\n", a2[21]);
v2 = func0((__int64)v5, 0x1FF4u);
printf("%x\n", v2);
return printf("%d\n", 320LL);
}

original_code:
int displayInfo(int szb_path,szb_header_t *szb_header)
{
  char str[8192];
  lseek(szb_path,0,0);
  read(szb_path,str,8192);
  printf("checksum is :%x\n",szb_header->checksum);
  printf("%d\n",szb_header->filesize);
  printf("%x\n",szb_header->timestamp);
  printf("%d\n",szb_header->imagecount);
  int off_set=(0x40000000);
  printf("%x\n",calcChecksum((unsigned int *)(str+12),8192-12));
  printf("%d\n",sizeof(szb_header_t));
}

canonical_original_code:
int displayInfo(int szb_path, struct szb_header_t *szb_header)
{
  char str[8192];
  lseek(szb_path,0,0);
  read(szb_path,str,8192);
  printf("checksum is :%x\n",szb_header->checksum);
  printf("%d\n",szb_header->filesize);
  printf("%x\n",szb_header->timestamp);
  printf("%d\n",szb_header->imagecount);
  int off_set = (0x40000000);
  printf("%x\n",calcChecksum((unsigned int *)(str+12),8192-12));
  printf("%d\n",sizeof(szb_header_t));
}

variable_types: struct szb_header_t { unsigned char magic[8]; unsigned int checksum; unsigned int filesize; unsigned char author[32]; unsigned char version[32]; unsigned int timestamp; unsigned int imagecount; unsigned char tools[32]; unsigned char reserve[-1]; } *

variable_types:
str
char [8192]


display

decompiled_code:
int __fastcall display(_QWORD *a1)
{
_QWORD *i; // rbx

for ( i = a1; i[1]; i = (_QWORD *)i[1] )
{
puts("..............................................");
printf("%s.img infmation:\n", (const char *)(*i + 64LL));
printf(aCrc, *(unsigned int *)(*i + 96LL));
printf(&byte_8BB, *(unsigned int *)(*i + 104LL));
printf(&byte_8D1, *(unsigned int *)(*i + 108LL));
printf(&byte_8E6, *(unsigned int *)(*i + 112LL));
}
return putchar(10);
}

canonical_decompiled_code:
int __fastcall func2(_QWORD *a1)
{
_QWORD *i; // rbx

for ( i = a1; i[1]; i = (_QWORD *)i[1] )
{
puts("..............................................");
printf("%s.img infmation:\n", (const char *)(*i + 64LL));
printf(aCrc, *(unsigned int *)(*i + 96LL));
printf(&byte_8BB, *(unsigned int *)(*i + 104LL));
printf(&byte_8D1, *(unsigned int *)(*i + 108LL));
printf(&byte_8E6, *(unsigned int *)(*i + 112LL));
}
return putchar(10);
}

original_code:
void display(image_node *header)
{
 image_node *prefix=header;
 while(prefix->next!=((void *)0))
 {
  printf("..............................................\n");
  printf("%s.img infmation:\n", prefix->data->partname);
  printf("CRC校验码  :%x\n", prefix->data->checksum);
  printf("偏移位置   :ox%x\n", prefix->data->imageoffset);
  printf("分区大小   :%dB\n", prefix->data->imagesize);
  printf("是否擦除   :%d\n", prefix->data->eraseflag);
  prefix=prefix->next;
 }
 printf("\n");
}

canonical_original_code:
void display(struct image_node *header)
{
 struct image_node *prefix = header;
 while(prefix->next!=((void *)0))
 {
  printf("..............................................\n");
  printf("%s.img infmation:\n", prefix->data->partname);
  printf("CRC校验码  :%x\n", prefix->data->checksum);
  printf("偏移位置   :ox%x\n", prefix->data->imageoffset);
  printf("分区大小   :%dB\n", prefix->data->imagesize);
  printf("是否擦除   :%d\n", prefix->data->eraseflag);
  prefix=prefix->next;
 }
 printf("\n");
}

variable_types: struct image_node { struct szb_images_t { unsigned char filename[64]; unsigned char partname[32]; unsigned int checksum; unsigned int timestamp; unsigned int imageoffset; unsigned int imagesize; unsigned int eraseflag; unsigned int writeflag; unsigned char reserve[-1]; } *data; struct image_node *next; } *

user_defined_types: struct image_node { struct szb_images_t *data; struct image_node *next; }


decompiled_code:
__int64 __fastcall unpack_image(int fd, __int64 a2, const char *a3)
{
unsigned int v4; // er14
int v5; // eax
int v6; // er12
unsigned int v7; // ebx
int v8; // er14
int i; // ebx
__int64 result; // rax
_BYTE v11[2104]; // [rsp+0h] [rbp-838h] BYREF

v4 = *(_DWORD *)(*(_QWORD *)a2 + 108LL);
v5 = open(a3, 577, 384LL);
if ( v5 < 0 )
{
printf("creat %s fail \n", a3);
result = 1LL;
}
else
{
v6 = v5;
printf("%s creat is successed \n", a3);
lseek(fd, *(unsigned int *)(*(_QWORD *)a2 + 104LL), 0);
printf("%s part ddress is :%x\n", a3, *(unsigned int *)(*(_QWORD *)a2 + 104LL));
printf("%s part size is :%d\n", a3, *(unsigned int *)(*(_QWORD *)a2 + 108LL));
v7 = 0;
if ( v4 > 0x7FF )
{
do
{
if ( read(fd, v11, 0x800uLL) >= 0 && write(v6, v11, 0x800uLL) < 0 )
printf("unpack %s part is Error!\n", a3);
++v7;
}
while ( v7 < v4 >> 11 );
}
v8 = v4 & 0x7FF;
if ( v8 )
{
for ( i = 0; i != v8; ++i )
{
if ( read(fd, v11, 1uLL) >= 0 && write(v6, v11, 1uLL) < 0 )
printf("unpack %s part is Error!\n", a3);
}
}
printf("%s part unpack is successed!\n", a3);
close(v6);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, __int64 a2, const char *a3)
{
unsigned int v4; // er14
int v5; // eax
int v6; // er12
unsigned int v7; // ebx
int v8; // er14
int i; // ebx
__int64 result; // rax
_BYTE v11[2104]; // [rsp+0h] [rbp-838h] BYREF

v4 = *(_DWORD *)(*(_QWORD *)a2 + 108LL);
v5 = open(a3, 577, 384LL);
if ( v5 < 0 )
{
printf("creat %s fail \n", a3);
result = 1LL;
}
else
{
v6 = v5;
printf("%s creat is successed \n", a3);
lseek(fd, *(unsigned int *)(*(_QWORD *)a2 + 104LL), 0);
printf("%s part ddress is :%x\n", a3, *(unsigned int *)(*(_QWORD *)a2 + 104LL));
printf("%s part size is :%d\n", a3, *(unsigned int *)(*(_QWORD *)a2 + 108LL));
v7 = 0;
if ( v4 > 0x7FF )
{
do
{
if ( read(fd, v11, 0x800uLL) >= 0 && write(v6, v11, 0x800uLL) < 0 )
printf("unpack %s part is Error!\n", a3);
++v7;
}
while ( v7 < v4 >> 11 );
}
v8 = v4 & 0x7FF;
if ( v8 )
{
for ( i = 0; i != v8; ++i )
{
if ( read(fd, v11, 1uLL) >= 0 && write(v6, v11, 1uLL) < 0 )
printf("unpack %s part is Error!\n", a3);
}
}
printf("%s part unpack is successed!\n", a3);
close(v6);
result = 0LL;
}
return result;
}

original_code:
int unpack_image(int szb_path,image_node *temp_header,char *partname)
{
 int image_part=0,i=0;
 char str_buff[2048];
 unsigned int image_tail=(temp_header->data->imagesize)%2048;
 unsigned int image_size=(temp_header->data->imagesize)/2048;
 off_t set;
 if((image_part=open(partname,01|0100|01000,0400|0200))>=0){
  printf("%s creat is successed \n", partname);
 }
 else
 {
  printf("creat %s fail \n",partname);
  return 1;
 }
 set=lseek(szb_path,temp_header->data->imageoffset,0);
 printf("%s part ddress is :%x\n",partname,temp_header->data->imageoffset);
 printf("%s part size is :%d\n",partname,temp_header->data->imagesize);
 for(i=0;i<image_size;i++)
 {
  if(read(szb_path,str_buff,2048)>=0)
   {
    if(write(image_part,str_buff,2048)<0)
     {
      printf("unpack %s part is Error!\n",partname);
     };
   };
 }
 for (i = 0; i < image_tail; i++)
 {
  if(read(szb_path,str_buff,1)>=0)
   {
    if(write(image_part,str_buff,1)<0)
     {
      printf("unpack %s part is Error!\n",partname);
     };
   };
 }
 printf("%s part unpack is successed!\n", partname);
 close(image_part);
 return 0;
}

canonical_original_code:
int unpack_image(int szb_path, struct image_node *temp_header, char *partname)
{
 int image_part = 0; int i = 0;
 char str_buff[2048];
 unsigned int image_tail = (temp_header->data->imagesize)%2048;
 unsigned int image_size = (temp_header->data->imagesize)/2048;
 long set;
 if((image_part=open(partname,01|0100|01000,0400|0200))>=0){
  printf("%s creat is successed \n", partname);
 }
 else
 {
  printf("creat %s fail \n",partname);
  return 1;
 }
 set=lseek(szb_path,temp_header->data->imageoffset,0);
 printf("%s part ddress is :%x\n",partname,temp_header->data->imageoffset);
 printf("%s part size is :%d\n",partname,temp_header->data->imagesize);
 for(i=0;i<image_size;i++)
 {
  if(read(szb_path,str_buff,2048)>=0)
   {
    if(write(image_part,str_buff,2048)<0)
     {
      printf("unpack %s part is Error!\n",partname);
     };
   };
 }
 for (i = 0; i < image_tail; i++)
 {
  if(read(szb_path,str_buff,1)>=0)
   {
    if(write(image_part,str_buff,1)<0)
     {
      printf("unpack %s part is Error!\n",partname);
     };
   };
 }
 printf("%s part unpack is successed!\n", partname);
 close(image_part);
 return 0;
}

variable_types:
partname
char *

variable_types: i int

variable_types: set long

user_defined_types: struct szb_images_t { unsigned char filename[64]; unsigned char partname[32]; unsigned int checksum; unsigned int timestamp; unsigned int imageoffset; unsigned int imagesize; unsigned int eraseflag; unsigned int writeflag; unsigned char reserve[-1]; }


decompiled_code:
__int64 __fastcall crc_checksum(int fd, __int64 *a2, const char *a3)
{
__int64 v4; // rcx
unsigned int v5; // ebp
unsigned int v6; // ebx
int *v7; // rdx
unsigned int v9; // [rsp+0h] [rbp-828h] BYREF
char v10; // [rsp+4h] [rbp-824h] BYREF

if ( (int)lseek(fd, *(unsigned int *)(*a2 + 104), 0) < 0 )
{
puts("read fail!!");
exit(1);
}
if ( read(fd, &v9, 0x800uLL) < 0 )
{
puts("read fail!");
exit(1);
}
v4 = *a2;
v5 = 0;
if ( *(_DWORD *)(*a2 + 108) > 3u )
{
v5 = v9;
v6 = 1;
v7 = (int *)&v10;
while ( 1 )
{
v4 = *a2;
if ( *(_DWORD *)(*a2 + 108) >> 2 <= v6 )
break;
v5 += *v7;
++v6;
++v7;
if ( (v6 & 0x1FF) == 0 )
{
if ( read(fd, &v9, 0x800uLL) < 0 )
{
puts("read fail!");
exit(1);
}
v7 = (int *)&v9;
}
}
}
if ( *(_DWORD *)(v4 + 96) != v5 )
{
printf("%s CRC check is fail !\n", a3);
exit(1);
}
printf("%s CRC check is OK !\n", a3);
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, __int64 *a2, const char *a3)
{
__int64 v4; // rcx
unsigned int v5; // ebp
unsigned int v6; // ebx
int *v7; // rdx
unsigned int v9; // [rsp+0h] [rbp-828h] BYREF
char v10; // [rsp+4h] [rbp-824h] BYREF

if ( (int)lseek(fd, *(unsigned int *)(*a2 + 104), 0) < 0 )
{
puts("read fail!!");
exit(1);
}
if ( read(fd, &v9, 0x800uLL) < 0 )
{
puts("read fail!");
exit(1);
}
v4 = *a2;
v5 = 0;
if ( *(_DWORD *)(*a2 + 108) > 3u )
{
v5 = v9;
v6 = 1;
v7 = (int *)&v10;
while ( 1 )
{
v4 = *a2;
if ( *(_DWORD *)(*a2 + 108) >> 2 <= v6 )
break;
v5 += *v7;
++v6;
++v7;
if ( (v6 & 0x1FF) == 0 )
{
if ( read(fd, &v9, 0x800uLL) < 0 )
{
puts("read fail!");
exit(1);
}
v7 = (int *)&v9;
}
}
}
if ( *(_DWORD *)(v4 + 96) != v5 )
{
printf("%s CRC check is fail !\n", a3);
exit(1);
}
printf("%s CRC check is OK !\n", a3);
return v5;
}

original_code:
unsigned int crc_checksum(int szb_path,image_node *temp_header,char *partname)
{
 unsigned int checksum=0,i;
 char str_buff[2048];
 unsigned int *temp_buff;
 int set;
 if((set=lseek(szb_path,temp_header->data->imageoffset,0))<0)
  {
   printf("read fail!!\n");
   exit(1);
  };
 if((read(szb_path,str_buff,2048)<0))
  {
   printf("read fail!\n");
   exit(1);
  }
 temp_buff=(unsigned int *)str_buff;
 for (i = 0; i <temp_header->data->imagesize/sizeof(unsigned int); i++)
 {
  checksum+=*(temp_buff);
  temp_buff++;
  if((i+1)%(2048/sizeof(unsigned int ))==0)
  {
   if(read(szb_path,str_buff,2048)<0)
   {
   printf("read fail!\n");
   exit(1);
   }
  temp_buff=(unsigned int *)str_buff;
  }
 }
 if (checksum==temp_header->data->checksum)
   {
    printf("%s CRC check is OK !\n",partname);
   }
  else
  {
   printf("%s CRC check is fail !\n",partname);
   exit(1);
  }
 return checksum;
}

canonical_original_code:
unsigned int crc_checksum(int szb_path, struct image_node *temp_header, char *partname)
{
 unsigned int checksum = 0; unsigned int i;
 char str_buff[2048];
 unsigned int *temp_buff;
 int set;
 if((set=lseek(szb_path,temp_header->data->imageoffset,0))<0)
  {
   printf("read fail!!\n");
   exit(1);
  };
 if((read(szb_path,str_buff,2048)<0))
  {
   printf("read fail!\n");
   exit(1);
  }
 temp_buff=(unsigned int *)str_buff;
 for (i = 0; i <temp_header->data->imagesize/sizeof(unsigned int); i++)
 {
  checksum+=*(temp_buff);
  temp_buff++;
  if((i+1)%(2048/sizeof(unsigned int ))==0)
  {
   if(read(szb_path,str_buff,2048)<0)
   {
   printf("read fail!\n");
   exit(1);
   }
  temp_buff=(unsigned int *)str_buff;
  }
 }
 if (checksum==temp_header->data->checksum)
   {
    printf("%s CRC check is OK !\n",partname);
   }
  else
  {
   printf("%s CRC check is fail !\n",partname);
   exit(1);
  }
 return checksum;
}

variable_types: set int


unpack

decompiled_code:
__int64 __fastcall unpack(int fd, __int64 a2, __int64 *a3)
{
unsigned int v4; // er12
const void *v5; // rbx

if ( !*(_DWORD *)(a2 + 84) )
return 0LL;
v4 = 0;
do
{
v5 = (const void *)(*a3 + 64);
if ( !memcmp(v5, "bootloader", 0xAuLL) )
{
puts("start unpack uboot.bin......");
crc_checksum(fd, a3, "uboot.img");
unpack_image(fd, (__int64)a3, "uboot.bin");
a3 = (__int64 *)a3[1];
}
else if ( !memcmp(v5, "boot", 4uLL) )
{
puts("start unpack boot.img......");
crc_checksum(fd, a3, "boot.img");
unpack_image(fd, (__int64)a3, "boot.img");
a3 = (__int64 *)a3[1];
}
else if ( !memcmp(v5, "recovery", 8uLL) )
{
puts("start unpack recovery.img......");
crc_checksum(fd, a3, "recovery.img");
unpack_image(fd, (__int64)a3, "recovery.img");
a3 = (__int64 *)a3[1];
}
else if ( !memcmp(v5, "system", 6uLL) )
{
puts("start unpack system.img");
crc_checksum(fd, a3, "system.img");
unpack_image(fd, (__int64)a3, "system.img");
a3 = (__int64 *)a3[1];
}
else if ( !memcmp(v5, "cpimage", 7uLL) )
{
puts("start unpack cpimage.img ......");
crc_checksum(fd, a3, "cpimage.img");
unpack_image(fd, (__int64)a3, "cpimage.img");
a3 = (__int64 *)a3[1];
}
else if ( !memcmp(v5, "preload", 7uLL) )
{
puts("start unpack preload.img......");
crc_checksum(fd, a3, "preload.img");
unpack_image(fd, (__int64)a3, "preload.img");
a3 = (__int64 *)a3[1];
}
else if ( !memcmp(v5, "userdata", 8uLL) )
{
puts("start analysis userdata.img......");
unpack_image(fd, (__int64)a3, "userdata.img");
a3 = (__int64 *)a3[1];
}
else if ( !memcmp(v5, "cache", 5uLL) )
{
puts("start analysis cache.img...... ");
unpack_image(fd, (__int64)a3, "cache.img");
a3 = (__int64 *)a3[1];
}
++v4;
}
while ( *(_DWORD *)(a2 + 84) > v4 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, __int64 a2, __int64 *a3)
{
unsigned int v4; // er12
const void *v5; // rbx

if ( !*(_DWORD *)(a2 + 84) )
return 0LL;
v4 = 0;
do
{
v5 = (const void *)(*a3 + 64);
if ( !memcmp(v5, "bootloader", 0xAuLL) )
{
puts("start unpack uboot.bin......");
func4(fd, a3, "uboot.img");
func3(fd, (__int64)a3, "uboot.bin");
a3 = (__int64 *)a3[1];
}
else if ( !memcmp(v5, "boot", 4uLL) )
{
puts("start unpack boot.img......");
func4(fd, a3, "boot.img");
func3(fd, (__int64)a3, "boot.img");
a3 = (__int64 *)a3[1];
}
else if ( !memcmp(v5, "recovery", 8uLL) )
{
puts("start unpack recovery.img......");
func4(fd, a3, "recovery.img");
func3(fd, (__int64)a3, "recovery.img");
a3 = (__int64 *)a3[1];
}
else if ( !memcmp(v5, "system", 6uLL) )
{
puts("start unpack system.img");
func4(fd, a3, "system.img");
func3(fd, (__int64)a3, "system.img");
a3 = (__int64 *)a3[1];
}
else if ( !memcmp(v5, "cpimage", 7uLL) )
{
puts("start unpack cpimage.img ......");
func4(fd, a3, "cpimage.img");
func3(fd, (__int64)a3, "cpimage.img");
a3 = (__int64 *)a3[1];
}
else if ( !memcmp(v5, "preload", 7uLL) )
{
puts("start unpack preload.img......");
func4(fd, a3, "preload.img");
func3(fd, (__int64)a3, "preload.img");
a3 = (__int64 *)a3[1];
}
else if ( !memcmp(v5, "userdata", 8uLL) )
{
puts("start analysis userdata.img......");
func3(fd, (__int64)a3, "userdata.img");
a3 = (__int64 *)a3[1];
}
else if ( !memcmp(v5, "cache", 5uLL) )
{
puts("start analysis cache.img...... ");
func3(fd, (__int64)a3, "cache.img");
a3 = (__int64 *)a3[1];
}
++v4;
}
while ( *(_DWORD *)(a2 + 84) > v4 );
return 0LL;
}

original_code:
int unpack(int szb_path,szb_header_t *szb_header,image_node *header)
{
 unsigned int i;
 image_node *prefix=header;
 for (i = 0; i <szb_header->imagecount; ++i)
 {
  if (memcmp(prefix->data->partname,"bootloader",10)==0)
  {
   printf("start unpack uboot.bin......\n");
   crc_checksum(szb_path,prefix,"uboot.img");
   unpack_image(szb_path,prefix,"uboot.bin");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"boot",4)==0)
  {
   printf("start unpack boot.img......\n");
   crc_checksum(szb_path,prefix,"boot.img");
   unpack_image(szb_path,prefix,"boot.img");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"recovery",8)==0)
  {
   printf("start unpack recovery.img......\n");
   crc_checksum(szb_path,prefix,"recovery.img");
   unpack_image(szb_path,prefix,"recovery.img");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"system",6)==0)
  {
   printf("start unpack system.img\n");
   crc_checksum(szb_path,prefix,"system.img");
   unpack_image(szb_path,prefix,"system.img");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"cpimage",7)==0)
  {
   printf("start unpack cpimage.img ......\n");
   crc_checksum(szb_path,prefix,"cpimage.img");
   unpack_image(szb_path,prefix,"cpimage.img");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"preload",7)==0)
  {
   printf("start unpack preload.img......\n");
   crc_checksum(szb_path,prefix,"preload.img");
   unpack_image(szb_path,prefix,"preload.img");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"userdata",8)==0)
  {
   printf("start  analysis userdata.img......\n");
   unpack_image(szb_path,prefix,"userdata.img");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"cache",5)==0)
  {
   printf("start analysis cache.img...... \n");
   unpack_image(szb_path,prefix,"cache.img");
   prefix=prefix->next;
   continue;
  }
 }
 return 0;
}

canonical_original_code:
int unpack(int szb_path, struct szb_header_t *szb_header, struct image_node *header)
{
 unsigned int i;
 struct image_node *prefix = header;
 for (i = 0; i <szb_header->imagecount; ++i)
 {
  if (memcmp(prefix->data->partname,"bootloader",10)==0)
  {
   printf("start unpack uboot.bin......\n");
   crc_checksum(szb_path,prefix,"uboot.img");
   unpack_image(szb_path,prefix,"uboot.bin");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"boot",4)==0)
  {
   printf("start unpack boot.img......\n");
   crc_checksum(szb_path,prefix,"boot.img");
   unpack_image(szb_path,prefix,"boot.img");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"recovery",8)==0)
  {
   printf("start unpack recovery.img......\n");
   crc_checksum(szb_path,prefix,"recovery.img");
   unpack_image(szb_path,prefix,"recovery.img");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"system",6)==0)
  {
   printf("start unpack system.img\n");
   crc_checksum(szb_path,prefix,"system.img");
   unpack_image(szb_path,prefix,"system.img");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"cpimage",7)==0)
  {
   printf("start unpack cpimage.img ......\n");
   crc_checksum(szb_path,prefix,"cpimage.img");
   unpack_image(szb_path,prefix,"cpimage.img");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"preload",7)==0)
  {
   printf("start unpack preload.img......\n");
   crc_checksum(szb_path,prefix,"preload.img");
   unpack_image(szb_path,prefix,"preload.img");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"userdata",8)==0)
  {
   printf("start  analysis userdata.img......\n");
   unpack_image(szb_path,prefix,"userdata.img");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"cache",5)==0)
  {
   printf("start analysis cache.img...... \n");
   unpack_image(szb_path,prefix,"cache.img");
   prefix=prefix->next;
   continue;
  }
 }
 return 0;
}

user_defined_types: struct szb_header_t { unsigned char magic[8]; unsigned int checksum; unsigned int filesize; unsigned char author[32]; unsigned char version[32]; unsigned int timestamp; unsigned int imagecount; unsigned char tools[32]; unsigned char reserve[-1]; }


decompiled_code:
__int64 __fastcall unpack_main(char *file)
{
int v1; // eax
int v2; // ebx
__int64 result; // rax
_DWORD v4[66]; // [rsp+0h] [rbp-108h] BYREF

puts("start unpack szbPack!");
v1 = open(file, 2, 511LL);
v2 = v1;
if ( v1 < 0 )
{
printf("open szbPack is faill!%d\n", (unsigned int)v1);
result = 1LL;
}
else if ( read(v1, v4, 0x100uLL) < 0 )
{
puts("read head fail! exit ");
result = 1LL;
}
else
{
printf("images count is :%d\n", v4[21]);
unpackSzb(v2, (__int64)v4);
puts("unpack is end!!");
close(v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(char *file)
{
int v1; // eax
int v2; // ebx
__int64 result; // rax
_DWORD v4[66]; // [rsp+0h] [rbp-108h] BYREF

puts("start unpack szbPack!");
v1 = open(file, 2, 511LL);
v2 = v1;
if ( v1 < 0 )
{
printf("open szbPack is faill!%d\n", (unsigned int)v1);
result = 1LL;
}
else if ( read(v1, v4, 0x100uLL) < 0 )
{
puts("read head fail! exit ");
result = 1LL;
}
else
{
printf("images count is :%d\n", v4[21]);
unpackSzb(v2, (__int64)v4);
puts("unpack is end!!");
close(v2);
result = 0LL;
}
return result;
}

original_code:
int unpack_main(char *packname,image_node *header,szb_header_t *szb_header)
{
 char head_buff[256];
 int szb_path;
 int i;
 printf("start unpack szbPack!\n");
 if((szb_path=open(packname,02,0777))<0)
 {
  printf("open szbPack is faill!%d\n",szb_path);
  return 1;
 }
 if(read(szb_path,head_buff,256)<0)
 {
  printf("read head fail! exit \n");
  return 1;
 }
 szb_header=(szb_header_t *)head_buff;
 printf("images count is :%d\n",szb_header->imagecount);
 header=unpackSzb(szb_path,szb_header);
 printf("unpack is end!!\n" );
 close(szb_path);
 return 0;
}

canonical_original_code:
int unpack_main(char *packname, struct image_node *header, struct szb_header_t *szb_header)
{
 char head_buff[256];
 int szb_path;
 int i;
 printf("start unpack szbPack!\n");
 if((szb_path=open(packname,02,0777))<0)
 {
  printf("open szbPack is faill!%d\n",szb_path);
  return 1;
 }
 if(read(szb_path,head_buff,256)<0)
 {
  printf("read head fail! exit \n");
  return 1;
 }
 szb_header=(struct szb_header_t *)head_buff;
 printf("images count is :%d\n",szb_header->imagecount);
 header=unpackSzb(szb_path,szb_header);
 printf("unpack is end!!\n" );
 close(szb_path);
 return 0;
}

variable_types:
packname
char *


decompiled_code:
int disp_help_info()
{
puts("............................................................");
puts(".Usage: .");
puts(". leszb -b ubootfile # add uboot partition .");
puts(". leszb -k kernelfile # add kernel partition .");
puts(". leszb -y recoveryfile # add recovery partition .");
puts(". leszb -s systemfile # add system partition .");
puts(". leszb -c cpimagefile # add cpimage partition .");
puts(". leszb -p preloadfile # add preloadfile partition .");
puts(". leszb -d datafile # add userdata .");
puts(". leszb -x szbfile # extract szb file .");
puts(". leszb -i szbfinfo # szbfinfo .");
puts(". leszb -v newpackname # setting Version .");
puts(". leszb -a yourname # yourname .");
puts(". leszb -e # erase cache .");
puts(". leszb -h # help .");
puts(". leszb -l # register .");
return puts("............................................................");
}

canonical_decompiled_code:
int func1()
{
puts("............................................................");
puts(".Usage: .");
puts(". leszb -b ubootfile # add uboot partition .");
puts(". leszb -k kernelfile # add kernel partition .");
puts(". leszb -y recoveryfile # add recovery partition .");
puts(". leszb -s systemfile # add system partition .");
puts(". leszb -c cpimagefile # add cpimage partition .");
puts(". leszb -p preloadfile # add preloadfile partition .");
puts(". leszb -d datafile # add userdata .");
puts(". leszb -x szbfile # extract szb file .");
puts(". leszb -i szbfinfo # szbfinfo .");
puts(". leszb -v newpackname # setting Version .");
puts(". leszb -a yourname # yourname .");
puts(". leszb -e # erase cache .");
puts(". leszb -h # help .");
puts(". leszb -l # register .");
return puts("............................................................");
}

original_code:
void disp_help_info()
{
 printf("............................................................\n");
 printf(".Usage:                                                    .\n");
 printf(".  leszb -b ubootfile        # add uboot partition         .\n");
 printf(".  leszb -k kernelfile       # add kernel partition        .\n");
 printf(".  leszb -y recoveryfile     # add recovery partition      .\n");
 printf(".  leszb -s systemfile       # add system partition        .\n");
 printf(".  leszb -c cpimagefile      # add cpimage partition       .\n");
 printf(".  leszb -p preloadfile      # add preloadfile partition   .\n");
 printf(".  leszb -d datafile         # add userdata                .\n");
 printf(".  leszb -x szbfile          # extract szb file            .\n");
 printf(".  leszb -i szbfinfo         # szbfinfo                    .\n");
 printf(".  leszb -v newpackname      # setting Version             .\n");
 printf(".  leszb -a yourname         # yourname                    .\n");
 printf(".  leszb -e                  # erase cache                 .\n");
 printf(".  leszb -h                  # help                        .\n");
 printf(".  leszb -l                  # register                    .\n");
 printf("............................................................\n");
}


displayhead

decompiled_code:
int __fastcall displayhead(_DWORD *a1)
{
const char *v1; // rbx
int result; // eax

if ( *a1 == 1 )
{
v1 = (const char *)(a1 + 1);
do
{
printf("%d\n", 1LL);
printf("%d\n", *((unsigned int *)v1 + 25));
printf("%d\n", *((unsigned int *)v1 + 24));
puts(v1);
result = puts(v1 + 64);
v1 += 108;
}
while ( *((_DWORD *)v1 - 1) == 1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(_DWORD *a1)
{
const char *v1; // rbx
int result; // eax

if ( *a1 == 1 )
{
v1 = (const char *)(a1 + 1);
do
{
printf("%d\n", 1LL);
printf("%d\n", *((unsigned int *)v1 + 25));
printf("%d\n", *((unsigned int *)v1 + 24));
puts(v1);
result = puts(v1 + 64);
v1 += 108;
}
while ( *((_DWORD *)v1 - 1) == 1 );
}
return result;
}

original_code:
void displayhead(header_temp_t *header_temp)
{
 int i=0;
 for (i = 0;header_temp[i].flag==1; i++)
 {
 printf("%d\n",header_temp[i].flag);
 printf("%d\n",header_temp[i].writeflag);
 printf("%d\n",header_temp[i].eraseflag);
 printf("%s\n",header_temp[i].filename);
 printf("%s\n",header_temp[i].partname);
 }
}

canonical_original_code:
void displayhead(struct header_temp_t *header_temp)
{
 int i = 0;
 for (i = 0;header_temp[i].flag==1; i++)
 {
 printf("%d\n",header_temp[i].flag);
 printf("%d\n",header_temp[i].writeflag);
 printf("%d\n",header_temp[i].eraseflag);
 printf("%s\n",header_temp[i].filename);
 printf("%s\n",header_temp[i].partname);
 }
}

variable_types: struct header_temp_t { unsigned int flag; unsigned char filename[64]; unsigned char partname[32]; unsigned int eraseflag; unsigned int writeflag; } *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
char v4; // sp
char v6; // al
char v7[32]; // [rsp+0h] [rbp-15A8h] BYREF
char v8[1632]; // [rsp+20h] [rbp-1588h] BYREF

disp_aut_info();
v3 = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "hb:k:y:s:c:p:x:d:e:a:v:i:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'a':
strncpy(v7, optarg, 0x20uLL);
break;
case 'b':
create_chain(v3++, v8, optarg, "bootloader");
break;
case 'c':
create_chain(v3++, v8, optarg, "cpimage");
break;
case 'd':
create_chain(v3++, v8, optarg, "userdata");
break;
case 'e':
create_chain(v3++, v8, optarg, "cache");
break;
case 'h':
disp_help_info();
break;
case 'i':
get_szb_info(optarg, 0LL, 0LL);
break;
case 'k':
create_chain(v3++, v8, optarg, "boot");
break;
case 'l':
continue;
case 'p':
create_chain(v3++, v8, optarg, "preload");
break;
case 's':
create_chain(v3++, v8, optarg, "system");
break;
case 'v':
puts("start pack new szbpack!!");
puts("lephone.cc provide !!");
pack_main(0LL, 0LL, v8, (unsigned int)(char)(v4 + 0x80), optarg, v7);
puts("pack szb is end!");
break;
case 'x':
unpack_main(optarg, 0LL, 0LL);
break;
case 'y':
create_chain(v3++, v8, optarg, "recovery");
break;
default:
puts("You enter the parameters error!!please see description:");
disp_help_info();
exit(1);
}
}
if ( argc <= 1 )
{
puts("You enter the parameters error!!please see description:");
disp_help_info();
}
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // ebx
char v4; // sp
char v6; // al
char v7[32]; // [rsp+0h] [rbp-15A8h] BYREF
char v8[1632]; // [rsp+20h] [rbp-1588h] BYREF

func0();
v3 = 0;
while ( 1 )
{
v6 = getopt(argc, (char *const *)argv, "hb:k:y:s:c:p:x:d:e:a:v:i:");
if ( v6 == -1 )
break;
switch ( v6 )
{
case 'a':
strncpy(v7, optarg, 0x20uLL);
break;
case 'b':
create_chain(v3++, v8, optarg, "bootloader");
break;
case 'c':
create_chain(v3++, v8, optarg, "cpimage");
break;
case 'd':
create_chain(v3++, v8, optarg, "userdata");
break;
case 'e':
create_chain(v3++, v8, optarg, "cache");
break;
case 'h':
func1();
break;
case 'i':
get_szb_info(optarg, 0LL, 0LL);
break;
case 'k':
create_chain(v3++, v8, optarg, "boot");
break;
case 'l':
continue;
case 'p':
create_chain(v3++, v8, optarg, "preload");
break;
case 's':
create_chain(v3++, v8, optarg, "system");
break;
case 'v':
puts("start pack new szbpack!!");
puts("lephone.cc provide !!");
pack_main(0LL, 0LL, v8, (unsigned int)(char)(v4 + 0x80), optarg, v7);
puts("pack szb is end!");
break;
case 'x':
unpack_main(optarg, 0LL, 0LL);
break;
case 'y':
create_chain(v3++, v8, optarg, "recovery");
break;
default:
puts("You enter the parameters error!!please see description:");
func1();
exit(1);
}
}
if ( argc <= 1 )
{
puts("You enter the parameters error!!please see description:");
func1();
}
return 0;
}

original_code:
int main(int argc,char *argv)
{
 char c;
 unsigned int location=0;
 image_node *header;
 szb_header_t *szb_header;
 char new_pack_header[256][15];
 header_temp_t header_temp[15];
 char author_name[32];
 disp_aut_info();
 while(1)
 {
  c=getopt(argc,argv,"hb:k:y:s:c:p:x:d:e:a:v:i:");
  if(c==(-1))
  {
   if(argc<2)
   {
   printf("You enter the parameters error!!please see description:\n");
   disp_help_info();
   break;
   }
   else
   {
    break;
   }
  }
  switch(c)
  {
   case 'e':
   create_chain(location++,header_temp,optarg,"cache");
   break;
   case 'a':
   strncpy(author_name,optarg,32);
   break;
   case 'h':
   disp_help_info();
   break;
   case 'l':
   break;
   case 'b':
   create_chain(location++,header_temp,optarg,"bootloader");
   break;
   case 'k':
   create_chain(location++,header_temp,optarg,"boot");
   break;
   case 'y':
   create_chain(location++,header_temp,optarg,"recovery");
   break;
   case 's':
   create_chain(location++,header_temp,optarg,"system");
   break;
   case 'd':
   create_chain(location++,header_temp,optarg,"userdata");
   break;
   case 'c':
   create_chain(location++,header_temp,optarg,"cpimage");
   break;
   case 'p':
   create_chain(location++,header_temp,optarg,"preload");
   break;
   case 'x':
   unpack_main(optarg,header,szb_header);
   break;
   case 'v':
   printf("start pack new szbpack!!\n");
   printf("lephone.cc provide !!\n");
   pack_main(header,szb_header,header_temp,new_pack_header, optarg,author_name);
   printf("pack szb is end!\n");
   break;
   case 'i':
   get_szb_info(optarg,header,szb_header);
   break;
   default:
   printf("You enter the parameters error!!please see description:\n");
   disp_help_info();
   exit(1);
  }
 }
 return 0;
}

canonical_original_code:
int main(int argc, char *argv)
{
 char c;
 unsigned int location = 0;
 struct image_node *header;
 struct szb_header_t *szb_header;
 char new_pack_header[256][15];
 struct header_temp_t header_temp[15];
 char author_name[32];
 disp_aut_info();
 while(1)
 {
  c=getopt(argc,argv,"hb:k:y:s:c:p:x:d:e:a:v:i:");
  if(c==(-1))
  {
   if(argc<2)
   {
   printf("You enter the parameters error!!please see description:\n");
   disp_help_info();
   break;
   }
   else
   {
    break;
   }
  }
  switch(c)
  {
   case 'e':
   create_chain(location++,header_temp,optarg,"cache");
   break;
   case 'a':
   strncpy(author_name,optarg,32);
   break;
   case 'h':
   disp_help_info();
   break;
   case 'l':
   break;
   case 'b':
   create_chain(location++,header_temp,optarg,"bootloader");
   break;
   case 'k':
   create_chain(location++,header_temp,optarg,"boot");
   break;
   case 'y':
   create_chain(location++,header_temp,optarg,"recovery");
   break;
   case 's':
   create_chain(location++,header_temp,optarg,"system");
   break;
   case 'd':
   create_chain(location++,header_temp,optarg,"userdata");
   break;
   case 'c':
   create_chain(location++,header_temp,optarg,"cpimage");
   break;
   case 'p':
   create_chain(location++,header_temp,optarg,"preload");
   break;
   case 'x':
   unpack_main(optarg,header,szb_header);
   break;
   case 'v':
   printf("start pack new szbpack!!\n");
   printf("lephone.cc provide !!\n");
   pack_main(header,szb_header,header_temp,new_pack_header, optarg,author_name);
   printf("pack szb is end!\n");
   break;
   case 'i':
   get_szb_info(optarg,header,szb_header);
   break;
   default:
   printf("You enter the parameters error!!please see description:\n");
   disp_help_info();
   exit(1);
  }
 }
 return 0;
}

variable_types: argc int

variable_types:
argv
char *

variable_types: c char

variable_types:
location
unsigned int

variable_types: struct header_temp_t { unsigned int flag; unsigned char filename[64]; unsigned char partname[32]; unsigned int eraseflag; unsigned int writeflag; } [15]


decompiled_code:
__int64 __fastcall create_chain(unsigned int a1, __int64 a2, const char *a3, const char *a4)
{
__int64 v5; // rbx

v5 = a2 + 108LL * a1;
*(_DWORD *)v5 = 1;
*(_DWORD *)(v5 + 104) = 1;
*(_DWORD *)(v5 + 100) = 1;
strncpy((char *)(v5 + 4), a3, 0x40uLL);
strncpy((char *)(v5 + 68), a4, 0x20uLL);
*(_DWORD *)(a2 + 108LL * (a1 + 1)) = 0;
return 0LL;
}

original_code:
int create_chain(unsigned int location,header_temp_t *header_temp,char *filename,char *partname)
{
 header_temp[location].flag=1;
 header_temp[location].writeflag=1;
 header_temp[location].eraseflag=1;
 strncpy(header_temp[location].filename,filename,64);
 strncpy(header_temp[location].partname,partname,32);
 header_temp[location+1].flag=0;
 return 0;
}

canonical_original_code:
int create_chain(unsigned int location, struct header_temp_t *header_temp, char *filename, char *partname)
{
 header_temp[location].flag=1;
 header_temp[location].writeflag=1;
 header_temp[location].eraseflag=1;
 strncpy(header_temp[location].filename,filename,64);
 strncpy(header_temp[location].partname,partname,32);
 header_temp[location+1].flag=0;
 return 0;
}

variable_types:
filename
char *

user_defined_types: struct header_temp_t { unsigned int flag; unsigned char filename[64]; unsigned char partname[32]; unsigned int eraseflag; unsigned int writeflag; }


decompiled_code:
__int64 __fastcall get_file_size(const char *a1)
{
bool v1; // sf
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3) < 0;
result = 0xFFFFFFFFLL;
if ( !v1 )
result = LODWORD(v3.st_size);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(const char *a1)
{
bool v1; // sf
__int64 result; // rax
struct stat v3; // [rsp+0h] [rbp-98h] BYREF

v1 = stat(a1, &v3) < 0;
result = 0xFFFFFFFFLL;
if ( !v1 )
result = LODWORD(v3.st_size);
return result;
}

original_code:
unsigned int get_file_size(char *file_path)
{
 unsigned int filesize = -1;
 struct stat statbuff;
 if (stat(file_path,&statbuff)<0)
 {
  return filesize;
 }
 else
 {
  filesize=statbuff.st_size;
 }
 return filesize;
}

variable_types:
filesize
unsigned int

variable_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }

user_defined_types: struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; }


decompiled_code:
__int64 get_system_time()
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

return (int)localtime(&timer);
}

canonical_decompiled_code:
__int64 func2()
{
time_t timer; // [rsp+8h] [rbp-10h] BYREF

return (int)localtime(&timer);
}

original_code:
time_t get_system_time()
{
 time_t t,ptr;
 t=localtime(&ptr);
 return t;
}

canonical_original_code:
long get_system_time()
{
 long t; long ptr;
 t=localtime(&ptr);
 return t;
}

variable_types: t long

variable_types: ptr long

return_type: long


decompiled_code:
__int64 __fastcall get_crc_checksum(int fd, const char **a2, const char *a3)
{
int v4; // eax
int v5; // er13
unsigned int v6; // ebp
unsigned int v7; // ebx
int *v8; // rdx
unsigned int v10; // [rsp+0h] [rbp-838h] BYREF
char v11; // [rsp+4h] [rbp-834h] BYREF

v4 = open(*a2, 2, 438LL);
if ( v4 < 0 )
{
printf("creat %s fail!\n", a3);
exit(1);
}
v5 = v4;
lseek(fd, *((unsigned int *)*a2 + 26), 0);
if ( read(v5, &v10, 0x800uLL) < 0 )
{
puts("read fail!");
exit(1);
}
if ( write(fd, &v10, 0x800uLL) < 0 )
{
printf("pack %s part is Error!\n", a3);
exit(1);
}
v6 = 0;
if ( *((_DWORD *)*a2 + 27) > 3u )
{
v6 = v10;
v7 = 1;
v8 = (int *)&v11;
while ( *((_DWORD *)*a2 + 27) >> 2 > v7 )
{
v6 += *v8;
++v7;
++v8;
if ( (v7 & 0x1FF) == 0 )
{
if ( read(v5, &v10, 0x800uLL) < 0 )
{
puts("read fail!");
exit(1);
}
if ( write(fd, &v10, 0x800uLL) < 0 )
{
printf("pack %s part is Error!\n", a3);
exit(1);
}
v8 = (int *)&v10;
}
}
}
close(v5);
strncpy((char *)*a2, a3, 0x20uLL);
return v6;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, const char **a2, const char *a3)
{
int v4; // eax
int v5; // er13
unsigned int v6; // ebp
unsigned int v7; // ebx
int *v8; // rdx
unsigned int v10; // [rsp+0h] [rbp-838h] BYREF
char v11; // [rsp+4h] [rbp-834h] BYREF

v4 = open(*a2, 2, 438LL);
if ( v4 < 0 )
{
printf("creat %s fail!\n", a3);
exit(1);
}
v5 = v4;
lseek(fd, *((unsigned int *)*a2 + 26), 0);
if ( read(v5, &v10, 0x800uLL) < 0 )
{
puts("read fail!");
exit(1);
}
if ( write(fd, &v10, 0x800uLL) < 0 )
{
printf("pack %s part is Error!\n", a3);
exit(1);
}
v6 = 0;
if ( *((_DWORD *)*a2 + 27) > 3u )
{
v6 = v10;
v7 = 1;
v8 = (int *)&v11;
while ( *((_DWORD *)*a2 + 27) >> 2 > v7 )
{
v6 += *v8;
++v7;
++v8;
if ( (v7 & 0x1FF) == 0 )
{
if ( read(v5, &v10, 0x800uLL) < 0 )
{
puts("read fail!");
exit(1);
}
if ( write(fd, &v10, 0x800uLL) < 0 )
{
printf("pack %s part is Error!\n", a3);
exit(1);
}
v8 = (int *)&v10;
}
}
}
close(v5);
strncpy((char *)*a2, a3, 0x20uLL);
return v6;
}

original_code:
unsigned int get_crc_checksum(int new_szb_file,image_node *prefix,char *filename)
{
 int src_path;
 unsigned int checksum=0,i;
 char str_buff[2048];
 unsigned int *temp_buff;
 unsigned int set;
 if((src_path=open(prefix->data->filename,02,0666))<0)
 {
  printf("creat %s fail!\n",filename);
  exit(1);
 }
 if((set=lseek(new_szb_file,prefix->data->imageoffset,0))<0)
 {
  printf("read fail!!\n");
  exit(1);
 }
 if((read(src_path,str_buff,2048)<0))
 {
  printf("read fail!\n");
  exit(1);
 }
 if(write(new_szb_file,str_buff,2048)<0)
 {
  printf("pack %s part is Error!\n",filename);
  exit(1);
 };
 temp_buff=(unsigned int *)str_buff;
 for (i = 0; i <prefix->data->imagesize/sizeof(unsigned int); i++)
 {
  checksum+=*(temp_buff);
  temp_buff++;
  if((i+1)%(2048/sizeof(unsigned int ))==0)
  {
   if(read(src_path,str_buff,2048)<0)
   {
    printf("read fail!\n");
    exit(1);
   }
   if(write(new_szb_file,str_buff,2048)<0)
   {
    printf("pack %s part is Error!\n",filename);
    exit(1);
   };
  temp_buff=(unsigned int *)str_buff;
  }
 }
 close(src_path);
 strncpy(prefix->data->filename,filename,32);
 return checksum;
}

canonical_original_code:
unsigned int get_crc_checksum(int new_szb_file, struct image_node *prefix, char *filename)
{
 int src_path;
 unsigned int checksum = 0; unsigned int i;
 char str_buff[2048];
 unsigned int *temp_buff;
 unsigned int set;
 if((src_path=open(prefix->data->filename,02,0666))<0)
 {
  printf("creat %s fail!\n",filename);
  exit(1);
 }
 if((set=lseek(new_szb_file,prefix->data->imageoffset,0))<0)
 {
  printf("read fail!!\n");
  exit(1);
 }
 if((read(src_path,str_buff,2048)<0))
 {
  printf("read fail!\n");
  exit(1);
 }
 if(write(new_szb_file,str_buff,2048)<0)
 {
  printf("pack %s part is Error!\n",filename);
  exit(1);
 };
 temp_buff=(unsigned int *)str_buff;
 for (i = 0; i <prefix->data->imagesize/sizeof(unsigned int); i++)
 {
  checksum+=*(temp_buff);
  temp_buff++;
  if((i+1)%(2048/sizeof(unsigned int ))==0)
  {
   if(read(src_path,str_buff,2048)<0)
   {
    printf("read fail!\n");
    exit(1);
   }
   if(write(new_szb_file,str_buff,2048)<0)
   {
    printf("pack %s part is Error!\n",filename);
    exit(1);
   };
  temp_buff=(unsigned int *)str_buff;
  }
 }
 close(src_path);
 strncpy(prefix->data->filename,filename,32);
 return checksum;
}

variable_types: struct image_node { struct szb_images_t { unsigned char filename[64]; unsigned char partname[32]; unsigned int checksum; unsigned int timestamp; unsigned int imageoffset; unsigned int imagesize; unsigned int eraseflag; unsigned int writeflag; unsigned char reserve[-1]; } *data; struct image_node *next; } *

variable_types:
checksum
unsigned int

variable_types:
i
unsigned int

variable_types:
set
unsigned int


decompiled_code:
__int64 __fastcall header_crc_checksum(int fd, __off_t offset, unsigned int a3)
{
unsigned int v4; // ebp
int v5; // ebx
int *v6; // rax
unsigned int v8; // [rsp+0h] [rbp-828h] BYREF
char v9; // [rsp+4h] [rbp-824h] BYREF

if ( (int)lseek(fd, (unsigned int)offset, 0) < 0 )
{
puts("read fail!!");
exit(1);
}
if ( read(fd, &v8, 0x800uLL) < 0 )
{
puts("read fail!");
exit(1);
}
v4 = a3;
if ( a3 )
{
v4 = v8;
v5 = 1;
v6 = (int *)&v9;
while ( a3 != v5 )
{
v4 += *v6;
++v5;
++v6;
if ( (v5 & 0x1FF) == 0 )
{
if ( read(fd, &v8, 0x800uLL) < 0 )
{
puts("read fail!");
exit(1);
}
v6 = (int *)&v8;
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, __off_t offset, unsigned int a3)
{
unsigned int v4; // ebp
int v5; // ebx
int *v6; // rax
unsigned int v8; // [rsp+0h] [rbp-828h] BYREF
char v9; // [rsp+4h] [rbp-824h] BYREF

if ( (int)lseek(fd, (unsigned int)offset, 0) < 0 )
{
puts("read fail!!");
exit(1);
}
if ( read(fd, &v8, 0x800uLL) < 0 )
{
puts("read fail!");
exit(1);
}
v4 = a3;
if ( a3 )
{
v4 = v8;
v5 = 1;
v6 = (int *)&v9;
while ( a3 != v5 )
{
v4 += *v6;
++v5;
++v6;
if ( (v5 & 0x1FF) == 0 )
{
if ( read(fd, &v8, 0x800uLL) < 0 )
{
puts("read fail!");
exit(1);
}
v6 = (int *)&v8;
}
}
}
return v4;
}

original_code:
unsigned int header_crc_checksum(int new_szb_file,unsigned int start_offset,unsigned int size)
{
 unsigned int checksum=0,i;
 char str_buff[2048];
 unsigned int *temp_buff;
 int set;
 if((set=lseek(new_szb_file,start_offset,0))<0)
  {
   printf("read fail!!\n");
   exit(1);
  };
 if((read(new_szb_file,str_buff,2048)<0))
  {
   printf("read fail!\n");
   exit(1);
  }
 temp_buff=(unsigned int *)str_buff;
 for (i = 0; i <size; i++)
 {
  checksum+=*(temp_buff);
  temp_buff++;
  if((i+1)%(2048/sizeof(unsigned int ))==0)
  {
   if(read(new_szb_file,str_buff,2048)<0)
   {
   printf("read fail!\n");
   exit(1);
   }
  temp_buff=(unsigned int *)str_buff;
  }
 }
 return checksum;
}

canonical_original_code:
unsigned int header_crc_checksum(int new_szb_file, unsigned int start_offset, unsigned int size)
{
 unsigned int checksum = 0; unsigned int i;
 char str_buff[2048];
 unsigned int *temp_buff;
 int set;
 if((set=lseek(new_szb_file,start_offset,0))<0)
  {
   printf("read fail!!\n");
   exit(1);
  };
 if((read(new_szb_file,str_buff,2048)<0))
  {
   printf("read fail!\n");
   exit(1);
  }
 temp_buff=(unsigned int *)str_buff;
 for (i = 0; i <size; i++)
 {
  checksum+=*(temp_buff);
  temp_buff++;
  if((i+1)%(2048/sizeof(unsigned int ))==0)
  {
   if(read(new_szb_file,str_buff,2048)<0)
   {
   printf("read fail!\n");
   exit(1);
   }
  temp_buff=(unsigned int *)str_buff;
  }
 }
 return checksum;
}

variable_types:
size
unsigned int

variable_types: set int


decompiled_code:
__int64 __fastcall pack_szb_image(int fd, void *buf, const char **a3, const char *a4)
{
const void **v4; // r12
const char **v5; // rbx
int v6; // er15
const char *v7; // rbp
const char *v8; // rbp
const void *v9; // rbp
const char *v10; // rbp
const char *v11; // rbp
const char *v12; // rbp
const char *v13; // rbp
const char *v14; // rbp
const char *v15; // rbp
const char *v16; // rbp
const char *v17; // rbp
const char *v18; // rbp
const char *v19; // rbp
const char *v20; // rbp
const char *v21; // rbp
unsigned int i; // ebx

v4 = (const void **)a3;
if ( a3[1] )
{
v5 = a3;
v6 = 0x2000;
do
{
v9 = *v5 + 64;
if ( !memcmp(v9, "bootloader", 0xAuLL) )
{
puts("start pack uboot.bin......");
*((_DWORD *)*v5 + 26) = v6;
v7 = *v5;
*((_DWORD *)v7 + 27) = get_file_size(*v5);
v8 = *v5;
*((_DWORD *)v8 + 24) = get_crc_checksum(fd, v5, "uboot.bin");
*((_DWORD *)*v5 + 25) = get_system_time();
v6 += (*((_DWORD *)*v5 + 27) & 0xFFFFFFF0) + 80;
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "boot", 4uLL) )
{
puts("start pack boot.img......");
*((_DWORD *)*v5 + 26) = v6;
v10 = *v5;
*((_DWORD *)v10 + 27) = get_file_size(*v5);
v11 = *v5;
*((_DWORD *)v11 + 24) = get_crc_checksum(fd, v5, "boot.img");
*((_DWORD *)*v5 + 25) = get_system_time();
v6 += (*((_DWORD *)*v5 + 27) & 0xFFFFFFF0) + 80;
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "recovery", 8uLL) )
{
puts("start pack recovery.img......");
*((_DWORD *)*v5 + 26) = v6;
v12 = *v5;
*((_DWORD *)v12 + 27) = get_file_size(*v5);
v13 = *v5;
*((_DWORD *)v13 + 24) = get_crc_checksum(fd, v5, "recovery.img");
*((_DWORD *)*v5 + 25) = get_system_time();
v6 += (*((_DWORD *)*v5 + 27) & 0xFFFFFFF0) + 80;
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "system", 6uLL) )
{
puts("start pack system.img");
*((_DWORD *)*v5 + 26) = v6;
v14 = *v5;
*((_DWORD *)v14 + 27) = get_file_size(*v5);
v15 = *v5;
*((_DWORD *)v15 + 24) = get_crc_checksum(fd, v5, "system.img");
*((_DWORD *)*v5 + 25) = get_system_time();
v6 += (*((_DWORD *)*v5 + 27) & 0xFFFFFFF0) + 80;
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "userdata", 8uLL) )
{
puts("start pack userdata.img");
*((_DWORD *)*v5 + 26) = v6;
v16 = *v5;
*((_DWORD *)v16 + 27) = get_file_size(*v5);
v17 = *v5;
*((_DWORD *)v17 + 24) = get_crc_checksum(fd, v5, "userdata.img");
*((_DWORD *)*v5 + 25) = get_system_time();
v6 += (*((_DWORD *)*v5 + 27) & 0xFFFFFFF0) + 80;
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "cpimage", 7uLL) )
{
puts("start pack cpimage.img ......");
*((_DWORD *)*v5 + 26) = v6;
v18 = *v5;
*((_DWORD *)v18 + 27) = get_file_size(*v5);
v19 = *v5;
*((_DWORD *)v19 + 24) = get_crc_checksum(fd, v5, "cpimage.img");
*((_DWORD *)*v5 + 25) = get_system_time();
v6 += (*((_DWORD *)*v5 + 27) & 0xFFFFFFF0) + 80;
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "preload", 7uLL) )
{
puts("start pack preload.img......");
*((_DWORD *)*v5 + 26) = v6;
v20 = *v5;
*((_DWORD *)v20 + 27) = get_file_size(*v5);
v21 = *v5;
*((_DWORD *)v21 + 24) = get_crc_checksum(fd, v5, "preload.img");
*((_DWORD *)*v5 + 25) = get_system_time();
v6 += (*((_DWORD *)*v5 + 27) & 0xFFFFFFF0) + 80;
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "cache", 5uLL) )
{
puts("start pack cache.img...... ");
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "fat", 5uLL) )
{
puts("start pack fat.img...... ");
v5 = (const char **)v5[1];
}
}
while ( v5[1] );
}
*((_DWORD *)buf + 20) = get_system_time();
*((_DWORD *)buf + 3) = get_file_size(a4);
lseek(fd, 0LL, 0);
if ( write(fd, buf, 0x100uLL) < 0 )
{
puts("pack header is Error!");
exit(1);
}
for ( i = 0; *((_DWORD *)buf + 21) > i; ++i )
{
if ( write(fd, *v4, 0x100uLL) < 0 )
{
puts("pack header is Error!");
exit(1);
}
v4 = (const void **)v4[1];
}
*((_DWORD *)buf + 2) = header_crc_checksum(fd, 12LL, 0x7FDu);
lseek(fd, 0LL, 0);
if ( write(fd, buf, 0x100uLL) < 0 )
{
puts("pack header crc is Error!");
exit(1);
}
close(fd);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(int fd, void *buf, const char **a3, const char *a4)
{
const void **v4; // r12
const char **v5; // rbx
int v6; // er15
const char *v7; // rbp
const char *v8; // rbp
const void *v9; // rbp
const char *v10; // rbp
const char *v11; // rbp
const char *v12; // rbp
const char *v13; // rbp
const char *v14; // rbp
const char *v15; // rbp
const char *v16; // rbp
const char *v17; // rbp
const char *v18; // rbp
const char *v19; // rbp
const char *v20; // rbp
const char *v21; // rbp
unsigned int i; // ebx

v4 = (const void **)a3;
if ( a3[1] )
{
v5 = a3;
v6 = 0x2000;
do
{
v9 = *v5 + 64;
if ( !memcmp(v9, "bootloader", 0xAuLL) )
{
puts("start pack uboot.bin......");
*((_DWORD *)*v5 + 26) = v6;
v7 = *v5;
*((_DWORD *)v7 + 27) = func1(*v5);
v8 = *v5;
*((_DWORD *)v8 + 24) = func3(fd, v5, "uboot.bin");
*((_DWORD *)*v5 + 25) = func2();
v6 += (*((_DWORD *)*v5 + 27) & 0xFFFFFFF0) + 80;
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "boot", 4uLL) )
{
puts("start pack boot.img......");
*((_DWORD *)*v5 + 26) = v6;
v10 = *v5;
*((_DWORD *)v10 + 27) = func1(*v5);
v11 = *v5;
*((_DWORD *)v11 + 24) = func3(fd, v5, "boot.img");
*((_DWORD *)*v5 + 25) = func2();
v6 += (*((_DWORD *)*v5 + 27) & 0xFFFFFFF0) + 80;
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "recovery", 8uLL) )
{
puts("start pack recovery.img......");
*((_DWORD *)*v5 + 26) = v6;
v12 = *v5;
*((_DWORD *)v12 + 27) = func1(*v5);
v13 = *v5;
*((_DWORD *)v13 + 24) = func3(fd, v5, "recovery.img");
*((_DWORD *)*v5 + 25) = func2();
v6 += (*((_DWORD *)*v5 + 27) & 0xFFFFFFF0) + 80;
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "system", 6uLL) )
{
puts("start pack system.img");
*((_DWORD *)*v5 + 26) = v6;
v14 = *v5;
*((_DWORD *)v14 + 27) = func1(*v5);
v15 = *v5;
*((_DWORD *)v15 + 24) = func3(fd, v5, "system.img");
*((_DWORD *)*v5 + 25) = func2();
v6 += (*((_DWORD *)*v5 + 27) & 0xFFFFFFF0) + 80;
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "userdata", 8uLL) )
{
puts("start pack userdata.img");
*((_DWORD *)*v5 + 26) = v6;
v16 = *v5;
*((_DWORD *)v16 + 27) = func1(*v5);
v17 = *v5;
*((_DWORD *)v17 + 24) = func3(fd, v5, "userdata.img");
*((_DWORD *)*v5 + 25) = func2();
v6 += (*((_DWORD *)*v5 + 27) & 0xFFFFFFF0) + 80;
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "cpimage", 7uLL) )
{
puts("start pack cpimage.img ......");
*((_DWORD *)*v5 + 26) = v6;
v18 = *v5;
*((_DWORD *)v18 + 27) = func1(*v5);
v19 = *v5;
*((_DWORD *)v19 + 24) = func3(fd, v5, "cpimage.img");
*((_DWORD *)*v5 + 25) = func2();
v6 += (*((_DWORD *)*v5 + 27) & 0xFFFFFFF0) + 80;
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "preload", 7uLL) )
{
puts("start pack preload.img......");
*((_DWORD *)*v5 + 26) = v6;
v20 = *v5;
*((_DWORD *)v20 + 27) = func1(*v5);
v21 = *v5;
*((_DWORD *)v21 + 24) = func3(fd, v5, "preload.img");
*((_DWORD *)*v5 + 25) = func2();
v6 += (*((_DWORD *)*v5 + 27) & 0xFFFFFFF0) + 80;
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "cache", 5uLL) )
{
puts("start pack cache.img...... ");
v5 = (const char **)v5[1];
}
else if ( !memcmp(v9, "fat", 5uLL) )
{
puts("start pack fat.img...... ");
v5 = (const char **)v5[1];
}
}
while ( v5[1] );
}
*((_DWORD *)buf + 20) = func2();
*((_DWORD *)buf + 3) = func1(a4);
lseek(fd, 0LL, 0);
if ( write(fd, buf, 0x100uLL) < 0 )
{
puts("pack header is Error!");
exit(1);
}
for ( i = 0; *((_DWORD *)buf + 21) > i; ++i )
{
if ( write(fd, *v4, 0x100uLL) < 0 )
{
puts("pack header is Error!");
exit(1);
}
v4 = (const void **)v4[1];
}
*((_DWORD *)buf + 2) = func4(fd, 12LL, 0x7FDu);
lseek(fd, 0LL, 0);
if ( write(fd, buf, 0x100uLL) < 0 )
{
puts("pack header crc is Error!");
exit(1);
}
close(fd);
return 0LL;
}

original_code:
int pack_szb_image(int new_szb_file, szb_header_t *szb_header,image_node *header,char *packname)
{
 unsigned int i,set;
 image_node *prefix=header;
 unsigned int start_offset=8192;
 for(i=0;prefix->next!=((void *)0);i++)
 {
  if (memcmp(prefix->data->partname,"bootloader",10)==0)
  {
   printf("start pack uboot.bin......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"uboot.bin");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"boot",4)==0)
  {
   printf("start pack boot.img......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"boot.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"recovery",8)==0)
  {
   printf("start pack recovery.img......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"recovery.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"system",6)==0)
  {
   printf("start pack system.img\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"system.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"userdata",8)==0)
  {
   printf("start pack userdata.img\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"userdata.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"cpimage",7)==0)
  {
   printf("start pack cpimage.img ......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"cpimage.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"preload",7)==0)
  {
   printf("start pack preload.img......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"preload.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"userdata",8)==0)
  {
   printf("start  pack userdata.img......\n");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"cache",5)==0)
  {
   printf("start pack  cache.img...... \n");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"fat",5)==0)
  {
   printf("start pack  fat.img...... \n");
   prefix=prefix->next;
   continue;
  }
 }
 szb_header->timestamp=get_system_time();;
 szb_header->filesize=get_file_size(packname);
 if((set=lseek(new_szb_file,0,0))<0)
 {
  printf("read fail!!\n");
  exit(1);
 }
 if(write(new_szb_file,(char *)szb_header,256)<0)
 {
  printf("pack  header  is Error!\n");
  exit(1);
 };
 prefix=header;
 for (i = 0; i < szb_header->imagecount; i++)
 {
  if(write(new_szb_file,(char *)prefix->data,256)<0)
  {
   printf("pack  header  is Error!\n");
   exit(1);
  };
  prefix=prefix->next;
 }
 szb_header->checksum = header_crc_checksum(new_szb_file,12,(256*32-12)/sizeof(unsigned int));
 if((set=lseek(new_szb_file,0,0))<0)
 {
  printf("read fail!!\n");
  exit(1);
 }
 if(write(new_szb_file,(char *)szb_header,256)<0)
 {
  printf("pack  header crc   is Error!\n");
  exit(1);
 };
 close(new_szb_file);
 return 0;
}

canonical_original_code:
int pack_szb_image(int new_szb_file, struct szb_header_t *szb_header, struct image_node *header, char *packname)
{
 unsigned int i; unsigned int set;
 struct image_node *prefix = header;
 unsigned int start_offset = 8192;
 for(i=0;prefix->next!=((void *)0);i++)
 {
  if (memcmp(prefix->data->partname,"bootloader",10)==0)
  {
   printf("start pack uboot.bin......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"uboot.bin");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"boot",4)==0)
  {
   printf("start pack boot.img......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"boot.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"recovery",8)==0)
  {
   printf("start pack recovery.img......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"recovery.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"system",6)==0)
  {
   printf("start pack system.img\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"system.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"userdata",8)==0)
  {
   printf("start pack userdata.img\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"userdata.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"cpimage",7)==0)
  {
   printf("start pack cpimage.img ......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"cpimage.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"preload",7)==0)
  {
   printf("start pack preload.img......\n");
   prefix->data->imageoffset=start_offset;
   prefix->data->imagesize = get_file_size(prefix->data->filename);
   prefix->data->checksum = get_crc_checksum(new_szb_file,prefix,"preload.img");
   prefix->data->timestamp = get_system_time();
   start_offset +=((prefix->data->imagesize/16)+5)*16;
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"userdata",8)==0)
  {
   printf("start  pack userdata.img......\n");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"cache",5)==0)
  {
   printf("start pack  cache.img...... \n");
   prefix=prefix->next;
   continue;
  }
  if (memcmp(prefix->data->partname,"fat",5)==0)
  {
   printf("start pack  fat.img...... \n");
   prefix=prefix->next;
   continue;
  }
 }
 szb_header->timestamp=get_system_time();;
 szb_header->filesize=get_file_size(packname);
 if((set=lseek(new_szb_file,0,0))<0)
 {
  printf("read fail!!\n");
  exit(1);
 }
 if(write(new_szb_file,(char *)szb_header,256)<0)
 {
  printf("pack  header  is Error!\n");
  exit(1);
 };
 prefix=header;
 for (i = 0; i < szb_header->imagecount; i++)
 {
  if(write(new_szb_file,(char *)prefix->data,256)<0)
  {
   printf("pack  header  is Error!\n");
   exit(1);
  };
  prefix=prefix->next;
 }
 szb_header->checksum = header_crc_checksum(new_szb_file,12,(256*32-12)/sizeof(unsigned int));
 if((set=lseek(new_szb_file,0,0))<0)
 {
  printf("read fail!!\n");
  exit(1);
 }
 if(write(new_szb_file,(char *)szb_header,256)<0)
 {
  printf("pack  header crc   is Error!\n");
  exit(1);
 };
 close(new_szb_file);
 return 0;
}

variable_types: struct szb_header_t { unsigned char magic[8]; unsigned int checksum; unsigned int filesize; unsigned char author[32]; unsigned char version[32]; unsigned int timestamp; unsigned int imagecount; unsigned char tools[32]; unsigned char reserve[-1]; } *

variable_types:
packname
char *


original_code:
int pack_main(image_node *header,szb_header_t *szb_header,header_temp_t *header_temp,char new_pack_header,char *packname,char *author_name)
{
 int i;
 int new_szb_file;
 szb_header=(szb_header_t *)malloc(sizeof(szb_header_t));
 strncpy(szb_header->magic,"LmSzBfMt",8);
 strncpy(szb_header->author,author_name,32);
 strncpy(szb_header->version,"[www.lephone.cc]",16);
 strcat(szb_header->version,packname);
 strncpy(szb_header->tools,"木马男孩leszb 1.0",32);
 szb_header->imagecount=0;
 header=(image_node *)malloc(sizeof(image_node));
 header->data=(szb_images_t *)malloc(sizeof(szb_images_t));
 header->next=((void *)0);
 image_node *prefix=header,*suffix=header;
 for (i = 0; header_temp[i].flag==1; i++)
 {
  strncpy(prefix->data->partname,header_temp[i].partname,32);
  strncpy(prefix->data->filename,header_temp[i].filename,64);
  prefix->data->writeflag=header_temp[i].writeflag;
  prefix->data->eraseflag=header_temp[i].eraseflag;
  prefix=(image_node *)malloc(sizeof(image_node));
  prefix->data=(szb_images_t *)malloc(sizeof(szb_images_t));
  suffix->next=prefix;
  prefix->next=((void *)0);
  suffix=prefix;
 }
 szb_header->imagecount=i;
 if((new_szb_file = open(packname,02|0100|01000,0777))<0)
 {
  printf("%s file creat faill!\n",packname);
  exit(1);
 }
 pack_szb_image(new_szb_file,szb_header,header,packname);
 return 0;
}

canonical_original_code:
int pack_main(struct image_node *header, struct szb_header_t *szb_header, struct header_temp_t *header_temp, char new_pack_header, char *packname, char *author_name)
{
 int i;
 int new_szb_file;
 szb_header=(struct szb_header_t *)malloc(sizeof(szb_header_t));
 strncpy(szb_header->magic,"LmSzBfMt",8);
 strncpy(szb_header->author,author_name,32);
 strncpy(szb_header->version,"[www.lephone.cc]",16);
 strcat(szb_header->version,packname);
 strncpy(szb_header->tools,"木马男孩leszb 1.0",32);
 szb_header->imagecount=0;
 header=(struct image_node *)malloc(sizeof(image_node));
 header->data=(struct szb_images_t *)malloc(sizeof(szb_images_t));
 header->next=((void *)0);
 struct image_node *prefix = header; struct image_node *suffix = header;
 for (i = 0; header_temp[i].flag==1; i++)
 {
  strncpy(prefix->data->partname,header_temp[i].partname,32);
  strncpy(prefix->data->filename,header_temp[i].filename,64);
  prefix->data->writeflag=header_temp[i].writeflag;
  prefix->data->eraseflag=header_temp[i].eraseflag;
  prefix=(struct image_node *)malloc(sizeof(image_node));
  prefix->data=(struct szb_images_t *)malloc(sizeof(szb_images_t));
  suffix->next=prefix;
  prefix->next=((void *)0);
  suffix=prefix;
 }
 szb_header->imagecount=i;
 if((new_szb_file = open(packname,02|0100|01000,0777))<0)
 {
  printf("%s file creat faill!\n",packname);
  exit(1);
 }
 pack_szb_image(new_szb_file,szb_header,header,packname);
 return 0;
}

variable_types: struct header_temp_t { unsigned int flag; unsigned char filename[64]; unsigned char partname[32]; unsigned int eraseflag; unsigned int writeflag; } *

variable_types: i int


original_code:
void display_head(char *packname,szb_header_t *szb_header)
{
 printf("Pack information :!\n");
 printf("..............................................\n");
 printf("CRC校验码  :%x\n",szb_header->checksum);
 printf("szb包大小  :%dB\n",szb_header->filesize);
 printf("szb作者    :%s\n",szb_header->author);
 printf("szb包版本  :%s\n",szb_header->version);
 printf("封包时间   :%x\n",szb_header->timestamp);
 printf("img包数量  :%d\n",szb_header->imagecount);
 printf("打包工具   :%s\n",szb_header->tools);
 printf("..............................................\n");
}

canonical_original_code:
void display_head(char *packname, struct szb_header_t *szb_header)
{
 printf("Pack information :!\n");
 printf("..............................................\n");
 printf("CRC校验码  :%x\n",szb_header->checksum);
 printf("szb包大小  :%dB\n",szb_header->filesize);
 printf("szb作者    :%s\n",szb_header->author);
 printf("szb包版本  :%s\n",szb_header->version);
 printf("封包时间   :%x\n",szb_header->timestamp);
 printf("img包数量  :%d\n",szb_header->imagecount);
 printf("打包工具   :%s\n",szb_header->tools);
 printf("..............................................\n");
}


decompiled_code:
__int64 __fastcall get_szb_info(const char *a1)
{
int v1; // eax
int v2; // ebx
__int64 result; // rax
unsigned int v4[70]; // [rsp+0h] [rbp-118h] BYREF

v1 = open(a1, 2, 511LL);
v2 = v1;
if ( v1 < 0 )
{
printf("open szbPack is faill!%d\n", (unsigned int)v1);
result = 1LL;
}
else if ( read(v1, v4, 0x100uLL) < 0 )
{
puts("read head fail! exit ");
result = 1LL;
}
else
{
display_head((__int64)a1, v4);
show_szb_info(v2, (__int64)v4);
close(v2);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(const char *a1)
{
int v1; // eax
int v2; // ebx
__int64 result; // rax
unsigned int v4[70]; // [rsp+0h] [rbp-118h] BYREF

v1 = open(a1, 2, 511LL);
v2 = v1;
if ( v1 < 0 )
{
printf("open szbPack is faill!%d\n", (unsigned int)v1);
result = 1LL;
}
else if ( read(v1, v4, 0x100uLL) < 0 )
{
puts("read head fail! exit ");
result = 1LL;
}
else
{
func7((__int64)a1, v4);
show_szb_info(v2, (__int64)v4);
close(v2);
result = 0LL;
}
return result;
}

original_code:
int get_szb_info(char *packname,image_node *header,szb_header_t *szb_header)
{
 char head_buff[256];
 int szb_path;
 int i;
 if((szb_path=open(packname,02,0777))<0)
 {
  printf("open szbPack is faill!%d\n",szb_path);
  return 1;
 }
 if(read(szb_path,head_buff,256)<0)
 {
  printf("read head fail! exit \n");
  return 1;
 }
 szb_header=(szb_header_t *)head_buff;
 display_head(packname,szb_header);
 header=show_szb_info(szb_path,szb_header);
 close(szb_path);
 return 0;
}

canonical_original_code:
int get_szb_info(char *packname, struct image_node *header, struct szb_header_t *szb_header)
{
 char head_buff[256];
 int szb_path;
 int i;
 if((szb_path=open(packname,02,0777))<0)
 {
  printf("open szbPack is faill!%d\n",szb_path);
  return 1;
 }
 if(read(szb_path,head_buff,256)<0)
 {
  printf("read head fail! exit \n");
  return 1;
 }
 szb_header=(struct szb_header_t *)head_buff;
 display_head(packname,szb_header);
 header=show_szb_info(szb_path,szb_header);
 close(szb_path);
 return 0;
}


sort

repo: yuanyiyixi/C-program

decompiled_code:
__int64 __fastcall sort(__int64 a1, __int64 a2)
{
bool v3; // cf
bool v4; // zf
const char *v5; // rsi
const char *v6; // rdi
__int64 v7; // rcx
char v8; // al
bool v9; // cf
bool v10; // zf
const char *v11; // rsi
const char *v12; // rdi
__int64 v13; // rcx

puts("sort cmd");
v5 = *(const char **)(a2 + 8);
v6 = "name";
v7 = 5LL;
do
{
if ( !v7 )
break;
v3 = *v5 < (unsigned int)*v6;
v4 = *v5++ == *v6++;
--v7;
}
while ( v4 );
v8 = (!v3 && !v4) - v3;
v9 = 0;
v10 = v8 == 0;
if ( !v8 )
sort_by_name(v6, v5);
v11 = *(const char **)(a2 + 8);
v12 = "age";
v13 = 4LL;
do
{
if ( !v13 )
break;
v9 = *v11 < (unsigned int)*v12;
v10 = *v11++ == *v12++;
--v13;
}
while ( v10 );
if ( (!v9 && !v10) == v9 )
sort_by_age(v12, v11);
return 0LL;
}

variable_types:
a
int []

variable_types: len int

variable_types:
bit
char [-1]

variable_types: pos int

variable_types: j int


main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
unsigned int v4; // [rsp+Ch] [rbp-DCh] BYREF
char *s1[8]; // [rsp+10h] [rbp-D8h] BYREF
char s[152]; // [rsp+50h] [rbp-98h] BYREF

puts(::s);
while ( 1 )
{
v4 = 0;
puts(&byte_402030);
fgets(s, 128, _bss_start);
parse(s, &v4, s1);
v3 = cmds;
do
{
if ( !strcmp(s1[0], v3) )
(*((void (__fastcall **)(_QWORD, char **))v3 + 2))(v4, s1);
v3 += 24;
}
while ( v3 != (char *)&_bss_start );
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
char *v3; // rbx
unsigned int v4; // [rsp+Ch] [rbp-DCh] BYREF
char *s1[8]; // [rsp+10h] [rbp-D8h] BYREF
char s[152]; // [rsp+50h] [rbp-98h] BYREF

puts(::s);
while ( 1 )
{
v4 = 0;
puts(&byte_402030);
fgets(s, 128, _bss_start);
func22(s, &v4, s1);
v3 = cmds;
do
{
if ( !strcmp(s1[0], v3) )
(*((void (__fastcall **)(_QWORD, char **))v3 + 2))(v4, s1);
v3 += 24;
}
while ( v3 != (char *)&_bss_start );
}
}

original_code:
int main(void)
{
 int a[100];
 init_array(a, 100);
 sort(a, 100);
 show(a, 100);
 return 0;
}

canonical_original_code:
int main()
{
 int a[100];
 init_array(a, 100);
 sort(a, 100);
 show(a, 100);
 return 0;
}


repo: yubai/PPNFS

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
ppnfs_client_config_init(argc, argv, envp);
ppnfs_client_net_start();
ppnfs_client_metadata_init();
ppnfs_client_grpir_init();
fuse_main_real((unsigned int)argc, argv, &ppnfs_oper, 360LL, 0LL);
return 0;
}

original_code:
int
main(int argc, char* argv[])
{
    ppnfs_client_config_init();
    ppnfs_client_net_start();
    ppnfs_client_metadata_init();
    ppnfs_client_grpir_init();
    void* user_data = ((void *)0);
    fuse_main_real(argc, argv, &ppnfs_oper, sizeof(*(&ppnfs_oper)), user_data);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    ppnfs_client_config_init();
    ppnfs_client_net_start();
    ppnfs_client_metadata_init();
    ppnfs_client_grpir_init();
    void *user_data = ((void *)0);
    fuse_main_real(argc, argv, &ppnfs_oper, sizeof(*(&ppnfs_oper)), user_data);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]


decompiled_code:
__int64 ppnfs_init()
{
fprintf(stderr, "INF|ppnfs_fuse.c:%d:%s|Filesystem now serving requests...\n", 161LL, "ppnfs_init");
fflush(stderr);
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
fprintf(stderr, "INF|ppnfs_fuse.c:%d:%s|Filesystem now serving requests...\n", 161LL, "ppnfs_init");
fflush(stderr);
return 0LL;
}

original_code:
static void*
ppnfs_init(struct fuse_conn_info *conn)
{
    do { fprintf(stderr, "INF" "|" "ppnfs_fuse.c" ":%d:%s|" "Filesystem now serving requests...\n", 161, __FUNCTION__ ); fflush(stderr); } while(0);
    return ((void *)0);
}

canonical_original_code:
static void *ppnfs_init(struct fuse_conn_info *conn)
{
    do { fprintf(stderr, "INF" "|" "ppnfs_fuse.c" ":%d:%s|" "Filesystem now serving requests...\n", 161, __FUNCTION__ ); fflush(stderr); } while(0);
    return ((void *)0);
}

variable_types: struct fuse_conn_info { unsigned int proto_major; unsigned int proto_minor; unsigned int async_read; unsigned int max_write; unsigned int max_readahead; unsigned int capable; unsigned int want; unsigned int max_background; unsigned int congestion_threshold; unsigned int reserved[23]; } *

return_type: void *


decompiled_code:
__int64 __fastcall ppnfs_readdir(__int64 a1, __int64 a2, __int64 (__fastcall *a3)(__int64, const char *))
{
unsigned int v4; // er12
__int64 v6; // rax
__int64 v7; // r15
__int64 i; // rbx
int v9[48]; // [rsp+0h] [rbp-C0h] BYREF

memset(v9, 0, 0x90uLL);
v9[6] = 0x4000;
v4 = a3(a2, ".");
if ( !v4 )
{
v4 = ((__int64 (__fastcall *)(__int64, const char *, int *, _QWORD))a3)(a2, "..", v9, 0LL);
if ( !v4 )
{
v6 = ppnfs_metadata_find(a1);
v7 = v6;
if ( v6 )
{
for ( i = ppnfs_metadata_get_child(v6); i; i = ppnfs_metadata_get(*(_QWORD *)(i + 288)) )
{
v4 = ((__int64 (__fastcall *)(__int64, __int64, __int64, _QWORD))a3)(a2, i + 8, i + 336, 0LL);
if ( v4 )
break;
}
ppnfs_metadata_release(v7);
}
else
{
v4 = -2;
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2, __int64 (__fastcall *a3)(__int64, const char *))
{
unsigned int v4; // er12
__int64 v6; // rax
__int64 v7; // r15
__int64 i; // rbx
int v9[48]; // [rsp+0h] [rbp-C0h] BYREF

memset(v9, 0, 0x90uLL);
v9[6] = 0x4000;
v4 = a3(a2, ".");
if ( !v4 )
{
v4 = ((__int64 (__fastcall *)(__int64, const char *, int *, _QWORD))a3)(a2, "..", v9, 0LL);
if ( !v4 )
{
v6 = ppnfs_metadata_find(a1);
v7 = v6;
if ( v6 )
{
for ( i = ppnfs_metadata_get_child(v6); i; i = ppnfs_metadata_get(*(_QWORD *)(i + 288)) )
{
v4 = ((__int64 (__fastcall *)(__int64, __int64, __int64, _QWORD))a3)(a2, i + 8, i + 336, 0LL);
if ( v4 )
break;
}
ppnfs_metadata_release(v7);
}
else
{
v4 = -2;
}
}
}
return v4;
}

original_code:
static int
ppnfs_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
     off_t offset, struct fuse_file_info *info)
{
    int res = 0;
    struct ppnfs_metadata_t* mfather, *mchild;
    struct stat st;
    (void) offset;
    (void) info;
    memset(&st, 0, sizeof(struct stat));
    st.st_mode = 0040000;
    res = filler(buf, ".", &st, 0);
    if (res) return res;
    res = filler(buf, "..", &st, 0);
    if (res) return res;
    mfather = ppnfs_metadata_find(path);
    if (!mfather) return -2;
    for (mchild = ppnfs_metadata_get_child(mfather); mchild; mchild
   = ppnfs_metadata_get(mchild->next)) {
        res = filler(buf, mchild->d_name, &(mchild->st), 0);
        if (res) break;
    }
    ppnfs_metadata_release(mfather);
    return res;
}

canonical_original_code:
static int ppnfs_readdir(char *path, void *buf, int (*filler)(void *buf, char *name, struct stat *stbuf, long off), long offset, struct fuse_file_info *info)
{
    int res = 0;
    struct ppnfs_metadata_t *mfather; struct ppnfs_metadata_t *mchild;
    struct stat st;
    (void) offset;
    (void) info;
    memset(&st, 0, sizeof(struct stat));
    st.st_mode = 0040000;
    res = filler(buf, ".", &st, 0);
    if (res) return res;
    res = filler(buf, "..", &st, 0);
    if (res) return res;
    mfather = ppnfs_metadata_find(path);
    if (!mfather) return -2;
    for (mchild = ppnfs_metadata_get_child(mfather); mchild; mchild
   = ppnfs_metadata_get(mchild->next)) {
        res = filler(buf, mchild->d_name, &(mchild->st), 0);
        if (res) break;
    }
    ppnfs_metadata_release(mfather);
    return res;
}

variable_types:
path
char *

variable_types:
buf
void *

variable_types: int (*)(void *buf, char *name, struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } *stbuf, long off)

variable_types: offset long

variable_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; } *

variable_types: res int

variable_types: struct ppnfs_metadata_t { unsigned long long hash; char d_name[-1]; unsigned long long id; unsigned long long father; unsigned long long child; unsigned long long next; unsigned long long up; unsigned long long left; unsigned long long right; unsigned long long collision_next; unsigned long long collision_previous; struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; int __pad0; unsigned long st_rdev; long st_size; long st_blksize; long st_blocks; struct timespec { long tv_sec; long tv_nsec; } st_atim; struct timespec st_mtim; struct timespec st_ctim; long __glibc_reserved[3]; } st; unsigned int prime; unsigned int c; char pi[]; } *

user_defined_types: struct ppnfs_metadata_t { unsigned long long hash; char d_name[-1]; unsigned long long id; unsigned long long father; unsigned long long child; unsigned long long next; unsigned long long up; unsigned long long left; unsigned long long right; unsigned long long collision_next; unsigned long long collision_previous; struct stat st; unsigned int prime; unsigned int c; char pi[]; }


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

v1 = ppnfs_metadata_find(a1);
if ( !v1 )
return 4294967294LL;
if ( (*(_DWORD *)(v1 + 360) & 0xF000) == 0x8000 )
{
ppnfs_metadata_release(v1);
result = 0LL;
}
else
{
ppnfs_metadata_release(v1);
result = 4294967275LL;
}
return result;
}

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

v1 = ppnfs_metadata_find(a1);
if ( !v1 )
return 4294967294LL;
if ( (*(_DWORD *)(v1 + 360) & 0xF000) == 0x8000 )
{
ppnfs_metadata_release(v1);
result = 0LL;
}
else
{
ppnfs_metadata_release(v1);
result = 4294967275LL;
}
return result;
}

original_code:
static int
ppnfs_open(const char *path, struct fuse_file_info* info)
{
    struct ppnfs_metadata_t* mdata = ppnfs_metadata_find(path);
    if (mdata == ((void *)0)) {
        return -2;
    }
    if (!((((mdata->st.st_mode)) & 0170000) == (0100000))) {
        ppnfs_metadata_release(mdata);
        return -21;
    }
    ppnfs_metadata_release(mdata);
    return 0;
}

canonical_original_code:
static int ppnfs_open(char *path, struct fuse_file_info *info)
{
    struct ppnfs_metadata_t *mdata = ppnfs_metadata_find(path);
    if (mdata == ((void *)0)) {
        return -2;
    }
    if (!((((mdata->st.st_mode)) & 0170000) == (0100000))) {
        ppnfs_metadata_release(mdata);
        return -21;
    }
    ppnfs_metadata_release(mdata);
    return 0;
}

user_defined_types: struct fuse_file_info { int flags; unsigned long fh_old; int writepage; unsigned int direct_io; unsigned int keep_cache; unsigned int flush; unsigned int nonseekable; unsigned int flock_release; unsigned int padding; unsigned long fh; unsigned long lock_owner; }

user_defined_types: struct timespec { long tv_sec; long tv_nsec; }