original_code:
static void SymTable_rehash(SymTable_t oSymTable)
{
    int i, hashCode;
    struct Bind *oldBind = oSymTable->bind;
    struct Bind *tmpBind, *newBind, *bind;
    int oldBucketCounts = oSymTable->bucketCounts[0];
    ++(oSymTable->bucketCounts);
    oSymTable->bind = (struct Bind *)malloc(oSymTable->bucketCounts[0]*sizeof(struct Bind));
    if(!(oSymTable->bind))
    {
        oSymTable->bind = oldBind;
        --(oSymTable->bucketCounts);
        return ;
    }
    for(i = 0; i < oSymTable->bucketCounts[0]; ++i)
    {
        oSymTable->bind[i].next = ((void *)0);
        oSymTable->bind[i].key = ((void *)0);
    }
    for(i = 0; i < oldBucketCounts; ++i)
    {
        bind = oldBind[i].next;
        while(bind)
        {
            tmpBind=bind->next;
            hashCode = SymTable_hash(bind->key, oSymTable->bucketCounts[0]);
            newBind = &(oSymTable->bind[hashCode]);
            while(newBind->next)
                newBind = newBind->next;
            newBind->next = bind;
            bind->next = ((void *)0);
            bind = tmpBind;
        }
    }
    free(oldBind);
}

canonical_original_code:
static void SymTable_rehash(struct SymTable *oSymTable)
{
    int i; int hashCode;
    struct Bind *oldBind = oSymTable->bind;
    struct Bind *tmpBind; struct Bind *newBind; struct Bind *bind;
    int oldBucketCounts = oSymTable->bucketCounts[0];
    ++(oSymTable->bucketCounts);
    oSymTable->bind = (struct Bind *)malloc(oSymTable->bucketCounts[0]*sizeof(struct Bind));
    if(!(oSymTable->bind))
    {
        oSymTable->bind = oldBind;
        --(oSymTable->bucketCounts);
        return ;
    }
    for(i = 0; i < oSymTable->bucketCounts[0]; ++i)
    {
        oSymTable->bind[i].next = ((void *)0);
        oSymTable->bind[i].key = ((void *)0);
    }
    for(i = 0; i < oldBucketCounts; ++i)
    {
        bind = oldBind[i].next;
        while(bind)
        {
            tmpBind=bind->next;
            hashCode = SymTable_hash(bind->key, oSymTable->bucketCounts[0]);
            newBind = &(oSymTable->bind[hashCode]);
            while(newBind->next)
                newBind = newBind->next;
            newBind->next = bind;
            bind->next = ((void *)0);
            bind = tmpBind;
        }
    }
    free(oldBind);
}

variable_types: struct SymTable { struct Bind { char *key; void *val; struct Bind *next; } *bind; int numBinds; int *bucketCounts; } *

variable_types: hashCode int

variable_types: oldBucketCounts int

user_defined_types: struct SymTable { struct Bind *bind; int numBinds; int *bucketCounts; }


repo: ytHu/symtable

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

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

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

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

original_code:
int SymTable_getLength(SymTable_t oSymTable)
{
    if(!oSymTable)
        return -1;
    return oSymTable->numBinds;
}

canonical_original_code:
int SymTable_getLength(struct SymTable *oSymTable)
{
    if(!oSymTable)
        return -1;
    return oSymTable->numBinds;
}

variable_types: struct SymTable { struct Bind { char *key; void *val; struct Bind *next; } *bind; int numBinds; } *

return_type: int

user_defined_types: struct SymTable { struct Bind *bind; int numBinds; }


decompiled_code:
__int64 log_print(int a1, const char *a2, ...)
{
unsigned int v3; // er12
char *v4; // r12
struct tm *v5; // rax
int v6; // ebx
size_t v7; // rsi
unsigned int v8; // er12
int *v9; // rax
int v10; // edx
int v11; // ecx
int v12; // er8
int v13; // er9
int *v14; // r13
FILE *v15; // rdi
char *v17; // rbx
char *v18; // rax
gcc_va_list timer; // [rsp+8h] [rbp-F0h] BYREF
__int64 v20; // [rsp+30h] [rbp-C8h]
__int64 v21; // [rsp+38h] [rbp-C0h]
__int64 v22; // [rsp+40h] [rbp-B8h]
__int64 v23; // [rsp+48h] [rbp-B0h]

va_start(timer, a2);
v20 = va_arg(timer, _QWORD);
v21 = va_arg(timer, _QWORD);
v22 = va_arg(timer, _QWORD);
v23 = va_arg(timer, _QWORD);
va_end(timer);
v3 = 0;
if ( log_prio <= a1 )
{
v4 = buffer;
if ( buffer || (buffer = (char *)malloc(0x2000uLL), (v4 = buffer) != 0LL) )
{
if ( log_fd )
{
time((time_t *)timer);
v5 = localtime((const time_t *)timer);
v6 = strftime(v4, 0x2000uLL, "%b %d %H:%M:%S :", v5);
v7 = 0x2000 - v6;
v4 += v6;
}
else
{
v7 = 0x2000LL;
v6 = 0;
}
va_start(timer, a2);
v8 = v6 + vsnprintf(v4, v7, a2, timer);
v9 = _errno_location();
v14 = v9;
if ( v8 > 0x1FFF )
{
*v9 = 0;
v3 = log_print(1, (unsigned int)"log_print: arguments too long", v10, v11, v12, v13);
}
else
{
if ( *v9 )
{
v17 = buffer;
v18 = strerror(*v9);
snprintf(&v17[v8], (int)(0x2000 - v8), ": %s", v18);
*v14 = 0;
}
v15 = log_fd;
if ( !log_fd )
v15 = stderr;
v3 = fprintf(v15, "%s\n", buffer);
fflush(log_fd);
}
}
else
{
v3 = -1;
fwrite("log_print(): out of memory\n", 1uLL, 0x1BuLL, stderr);
}
}
return v3;
}

canonical_decompiled_code:
__int64 func0(int a1, const char *a2, ...)
{
unsigned int v3; // er12
char *v4; // r12
struct tm *v5; // rax
int v6; // ebx
size_t v7; // rsi
unsigned int v8; // er12
int *v9; // rax
int v10; // edx
int v11; // ecx
int v12; // er8
int v13; // er9
int *v14; // r13
FILE *v15; // rdi
char *v17; // rbx
char *v18; // rax
gcc_va_list timer; // [rsp+8h] [rbp-F0h] BYREF
__int64 v20; // [rsp+30h] [rbp-C8h]
__int64 v21; // [rsp+38h] [rbp-C0h]
__int64 v22; // [rsp+40h] [rbp-B8h]
__int64 v23; // [rsp+48h] [rbp-B0h]

va_start(timer, a2);
v20 = va_arg(timer, _QWORD);
v21 = va_arg(timer, _QWORD);
v22 = va_arg(timer, _QWORD);
v23 = va_arg(timer, _QWORD);
va_end(timer);
v3 = 0;
if ( log_prio <= a1 )
{
v4 = buffer;
if ( buffer || (buffer = (char *)malloc(0x2000uLL), (v4 = buffer) != 0LL) )
{
if ( log_fd )
{
time((time_t *)timer);
v5 = localtime((const time_t *)timer);
v6 = strftime(v4, 0x2000uLL, "%b %d %H:%M:%S :", v5);
v7 = 0x2000 - v6;
v4 += v6;
}
else
{
v7 = 0x2000LL;
v6 = 0;
}
va_start(timer, a2);
v8 = v6 + vsnprintf(v4, v7, a2, timer);
v9 = _errno_location();
v14 = v9;
if ( v8 > 0x1FFF )
{
*v9 = 0;
v3 = func0(1, (unsigned int)"log_print: arguments too long", v10, v11, v12, v13);
}
else
{
if ( *v9 )
{
v17 = buffer;
v18 = strerror(*v9);
snprintf(&v17[v8], (int)(0x2000 - v8), ": %s", v18);
*v14 = 0;
}
v15 = log_fd;
if ( !log_fd )
v15 = stderr;
v3 = fprintf(v15, "%s\n", buffer);
fflush(log_fd);
}
}
else
{
v3 = -1;
fwrite("log_print(): out of memory\n", 1uLL, 0x1BuLL, stderr);
}
}
return v3;
}

original_code:
int log_print(int prio, const char *fmt, ...)
{
 va_list az;
 int len = 0, retval;
 if (prio < log_prio)
  return 0;
 if (buffer == ((void *)0)) {
  buffer = malloc(8192);
  if (buffer == ((void *)0)) {
   fprintf(stderr, "log_print(): out of memory\n");
   return -1;
  }
 }
 if (log_fd != ((void *)0)) {
  time_t tzgr;
  time(&tzgr);
  len += strftime(buffer, 8192, "%b %d %H:%M:%S :", localtime(&tzgr));
 }
 __builtin_va_start(az,fmt);
 len += vsnprintf(buffer + len, 8192 - len, fmt, az);
 __builtin_va_end(az);
 if (len < 0 || len >= 8192) {
  (*__errno_location ()) = 0;
  return log_print(1, "log_print: arguments too long");
 }
 if ((*__errno_location ())) {
  len += snprintf(buffer + len, 8192 - len, ": %s", strerror((*__errno_location ())));
  (*__errno_location ()) = 0;
 }
 retval = fprintf((log_fd ? log_fd : stderr), "%s\n", buffer);
 fflush(log_fd);
 return retval;
}

canonical_original_code:
int log_print(int prio, char *fmt, ...)
{
 __builtin_va_list az;
 int len = 0; int retval;
 if (prio < log_prio)
  return 0;
 if (buffer == ((void *)0)) {
  buffer = malloc(8192);
  if (buffer == ((void *)0)) {
   fprintf(stderr, "log_print(): out of memory\n");
   return -1;
  }
 }
 if (log_fd != ((void *)0)) {
  long tzgr;
  time(&tzgr);
  len += strftime(buffer, 8192, "%b %d %H:%M:%S :", localtime(&tzgr));
 }
 __builtin_va_start(az,fmt);
 len += vsnprintf(buffer + len, 8192 - len, fmt, az);
 __builtin_va_end(az);
 if (len < 0 || len >= 8192) {
  (*__errno_location ()) = 0;
  return log_print(1, "log_print: arguments too long");
 }
 if ((*__errno_location ())) {
  len += snprintf(buffer + len, 8192 - len, ": %s", strerror((*__errno_location ())));
  (*__errno_location ()) = 0;
 }
 retval = fprintf((log_fd ? log_fd : stderr), "%s\n", buffer);
 fflush(log_fd);
 return retval;
}

variable_types: prio int

variable_types:
fmt
char *

variable_types: len int

variable_types: retval int

variable_types: tzgr long


decompiled_code:
void log_close()
{
FILE *v0; // rdi

if ( !buffer )
{
v0 = log_fd;
if ( !log_fd )
return;
goto LABEL_5;
}
free(buffer);
v0 = log_fd;
if ( log_fd )
LABEL_5:
fclose(v0);
}

canonical_decompiled_code:
void func1()
{
FILE *v0; // rdi

if ( !buffer )
{
v0 = log_fd;
if ( !log_fd )
return;
goto LABEL_5;
}
free(buffer);
v0 = log_fd;
if ( log_fd )
LABEL_5:
fclose(v0);
}

original_code:
void log_close(void)
{
 if (buffer)
  free(buffer);
 if (log_fd)
  fclose(log_fd);
}

canonical_original_code:
void log_close()
{
 if (buffer)
  free(buffer);
 if (log_fd)
  fclose(log_fd);
}

return_type: void


decompiled_code:
__int64 __fastcall log_init(char *filename)
{
if ( log_fd )
log_close();
log_fd = fopen(filename, "a");
if ( log_fd )
return 0LL;
fwrite("log_init(): can not open logfile", 1uLL, 0x20uLL, stderr);
return 0xFFFFFFFFLL;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *filename)
{
if ( log_fd )
func1();
log_fd = fopen(filename, "a");
if ( log_fd )
return 0LL;
fwrite("log_init(): can not open logfile", 1uLL, 0x20uLL, stderr);
return 0xFFFFFFFFLL;
}

original_code:
int log_init(const char *logfile)
{
 if (log_fd != ((void *)0))
  log_close();
 log_fd = fopen(logfile, "a");
 if (log_fd == ((void *)0)) {
  fprintf(stderr, "log_init(): can not open logfile");
  return -1;
 }
 return 0;
}

canonical_original_code:
int log_init(char *logfile)
{
 if (log_fd != ((void *)0))
  log_close();
 log_fd = fopen(logfile, "a");
 if (log_fd == ((void *)0)) {
  fprintf(stderr, "log_init(): can not open logfile");
  return -1;
 }
 return 0;
}

variable_types:
logfile
char *


decompiled_code:
void __fastcall log_setprio(int a1)
{
log_prio = a1;
}

canonical_decompiled_code:
void __fastcall func3(int a1)
{
log_prio = a1;
}

original_code:
void log_setprio(int prio)
{
 log_prio = prio;
}


decompiled_code:
__int64 __fastcall linebuffer_read(int *a1, int a2)
{
int v3; // eax
int v4; // ecx
int v5; // edi
int v6; // edx
char *v7; // rax
char *v8; // r8
char v9; // cl
_BYTE v11[40]; // [rsp+0h] [rbp-28h] BYREF

v3 = read(a2, v11, 0x20uLL);
if ( v3 <= 0 )
return 0xFFFFFFFFLL;
v4 = v3;
v5 = *a1;
v6 = a1[1];
v7 = v11;
v8 = &v11[v4 - 1 + 1];
do
{
v9 = *v7;
if ( *v7 != 8 )
{
if ( v9 > 31 || v9 == 13 )
{
a1[1] = v6 + 1;
*((_BYTE *)a1 + v6++ + 8) = v9;
}
LABEL_5:
if ( v5 < v6 )
return 0xFFFFFFFFLL;
goto LABEL_6;
}
if ( v6 <= 0 )
goto LABEL_5;
a1[1] = --v6;
if ( v5 < v6 )
return 0xFFFFFFFFLL;
LABEL_6:
++v7;
}
while ( v7 != v8 );
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func0(int *a1, int a2)
{
int v3; // eax
int v4; // ecx
int v5; // edi
int v6; // edx
char *v7; // rax
char *v8; // r8
char v9; // cl
_BYTE v11[40]; // [rsp+0h] [rbp-28h] BYREF

v3 = read(a2, v11, 0x20uLL);
if ( v3 <= 0 )
return 0xFFFFFFFFLL;
v4 = v3;
v5 = *a1;
v6 = a1[1];
v7 = v11;
v8 = &v11[v4 - 1 + 1];
do
{
v9 = *v7;
if ( *v7 != 8 )
{
if ( v9 > 31 || v9 == 13 )
{
a1[1] = v6 + 1;
*((_BYTE *)a1 + v6++ + 8) = v9;
}
LABEL_5:
if ( v5 < v6 )
return 0xFFFFFFFFLL;
goto LABEL_6;
}
if ( v6 <= 0 )
goto LABEL_5;
a1[1] = --v6;
if ( v5 < v6 )
return 0xFFFFFFFFLL;
LABEL_6:
++v7;
}
while ( v7 != v8 );
return 0LL;
}

original_code:
int linebuffer_read(struct linebuffer *lbuf, int fd)
{
 char buf[32];
 int len = read(fd, buf, sizeof(buf));
 if (len <= 0)
  return -1;
 int i;
 for (i = 0; i < len; i++) {
  if (buf[i] == 0x08 && lbuf->pos > 0) {
   lbuf->pos--;
  } else if (buf[i] >= ' ' || buf[i] == '\r') {
   lbuf->data[lbuf->pos++] = buf[i];
  }
  if (lbuf->pos > lbuf->size)
   return -1;
 }
 return 0;
}

variable_types: struct linebuffer { int size; int pos; char data[]; } *

variable_types: fd int

variable_types:
buf
char [32]

variable_types: i int


decompiled_code:
char *__fastcall linebuffer_get(__int64 a1)
{
char *v1; // r13
_BYTE *v2; // rax
_BYTE *v3; // rbp
char *v4; // r14
int v5; // ebx
int v6; // ebx

v1 = (char *)(a1 + 8);
v2 = memchr((const void *)(a1 + 8), 13, *(int *)(a1 + 4));
if ( !v2 )
return 0LL;
*v2 = 0;
v3 = v2;
v4 = 0LL;
v5 = (_DWORD)v2 - (_DWORD)v1;
if ( (int)v2 - (int)v1 > 0 )
v4 = strdup(v1);
v6 = *(_DWORD *)(a1 + 4) + ~v5;
*(_DWORD *)(a1 + 4) = v6;
memmove(v1, v3 + 1, v6);
return v4;
}

original_code:
char * linebuffer_get(struct linebuffer *lbuf)
{
 char *newline = memchr(lbuf->data, '\r', lbuf->pos);
 if (newline == ((void *)0))
  return ((void *)0);
 char *retval = ((void *)0);
 *newline = '\0';
 int len = newline - lbuf->data;
 if (len > 0)
  retval = strdup(lbuf->data);
 lbuf->pos -= len +1;
 memmove(lbuf->data, newline +1, lbuf->pos);
 return retval;
}

canonical_original_code:
char *linebuffer_get(struct linebuffer *lbuf)
{
 char *newline = memchr(lbuf->data, '\r', lbuf->pos);
 if (newline == ((void *)0))
  return ((void *)0);
 char *retval = ((void *)0);
 *newline = '\0';
 int len = newline - lbuf->data;
 if (len > 0)
  retval = strdup(lbuf->data);
 lbuf->pos -= len +1;
 memmove(lbuf->data, newline +1, lbuf->pos);
 return retval;
}

variable_types:
newline
char *

variable_types:
retval
char *

return_type: char *

user_defined_types: struct linebuffer { int size; int pos; char data[]; }


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

result = *(unsigned int *)(a1 + 4);
*(_DWORD *)(a1 + 4) = 0;
return result;
}

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

result = *(unsigned int *)(a1 + 4);
*(_DWORD *)(a1 + 4) = 0;
return result;
}

original_code:
int linebuffer_clear(struct linebuffer *lbuf)
{
 int oldpos = lbuf->pos;
 lbuf->pos = 0;
 return oldpos;
}

variable_types: oldpos int


decompiled_code:
__int64 patch_dot1qvlan()
{
return 0xFFFFFFFFLL;
}

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

original_code:
static int patch_dot1qvlan(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 return -1;
 int id = code - patch->code;
 if (id < 1 || id > 32)
  return -1;
 char *tmp, *buf = strdup(parameter);
 int vlanid = atoi(strtok_r(buf, ":", &tmp));
 char *name = strtok_r(((void *)0), ":", &tmp);
 strncpy(config + 0x63e8 + (id -1) * 0xd0, name, 12);
 *((uint16_t *)(config + 0x64b4 + (id -1) * 0xd0)) = htons(vlanid);
 *((uint8_t *)(config + 0x64b6 + (id -1) * 0xd0)) = 0x03;
 *((uint32_t *)(config + 0x63f4 + (id -1) * 0xd0)) = 0x03FFFFFF;
 *((uint32_t *)(config + 0x6434 + (id -1) * 0xd0)) = 0x03FFFFFF;
 *((uint32_t *)(config + 0x6474 + (id -1) * 0xd0)) = 0;
 free(buf);
 return 0;
}

canonical_original_code:
static int patch_dot1qvlan(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 return -1;
 int id = code - patch->code;
 if (id < 1 || id > 32)
  return -1;
 char *tmp; char *buf = strdup(parameter);
 int vlanid = atoi(strtok_r(buf, ":", &tmp));
 char *name = strtok_r(((void *)0), ":", &tmp);
 strncpy(config + 0x63e8 + (id -1) * 0xd0, name, 12);
 *((unsigned short *)(config + 0x64b4 + (id -1) * 0xd0)) = htons(vlanid);
 *((unsigned char *)(config + 0x64b6 + (id -1) * 0xd0)) = 0x03;
 *((unsigned int *)(config + 0x63f4 + (id -1) * 0xd0)) = 0x03FFFFFF;
 *((unsigned int *)(config + 0x6434 + (id -1) * 0xd0)) = 0x03FFFFFF;
 *((unsigned int *)(config + 0x6474 + (id -1) * 0xd0)) = 0;
 free(buf);
 return 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 *

variable_types: id int

variable_types:
tmp
char *

variable_types:
buf
char *

variable_types: vlanid int

variable_types:
name
char *


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

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

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

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

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

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

variable_types: value int

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; }


original_code:
static int patch_portenable(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 int port = code - patch->code;
 if (port < 1 || port > 26)
  return -1;
 int status = (strcmp(parameter, "on") == 0);
 *((uint8_t *)(config + 0x336b + (port -1) * 0x70)) = (status ? 0x03 : 0x01);
 return 0;
}

canonical_original_code:
static int patch_portenable(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 int port = code - patch->code;
 if (port < 1 || port > 26)
  return -1;
 int status = (strcmp(parameter, "on") == 0);
 *((unsigned char *)(config + 0x336b + (port -1) * 0x70)) = (status ? 0x03 : 0x01);
 return 0;
}

variable_types: port int

variable_types: status int


decompiled_code:
__int64 __fastcall patch_portvlan(__int64 a1, _DWORD *a2, int a3, const char *a4)
{
unsigned int v4; // ebx
char *v5; // r14
char *v6; // rax
unsigned int v7; // er15
bool v8; // bp
_BOOL4 v9; // er13
char *save_ptr[8]; // [rsp+8h] [rbp-40h] BYREF

v4 = a3 - *a2 - 1;
if ( v4 > 0x19 )
return 0xFFFFFFFFLL;
v5 = strdup(a4);
v6 = strtok_r(v5, ":", save_ptr);
v7 = atoi(v6);
v8 = strcmp(strtok_r(0LL, ":", save_ptr), "check") == 0;
v9 = strcmp(strtok_r(0LL, ":", save_ptr), "all") != 0;
free(v5);
if ( v7 > 0xFF )
return 0xFFFFFFFFLL;
*(_BYTE *)(a1 + (int)(48 * v4 + 24319)) = v7;
*(_BYTE *)(a1 + (int)(48 * v4 + 24320)) = v9;
*(_BYTE *)(a1 + (int)(48 * v4 + 24321)) = v8;
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, _DWORD *a2, int a3, const char *a4)
{
unsigned int v4; // ebx
char *v5; // r14
char *v6; // rax
unsigned int v7; // er15
bool v8; // bp
_BOOL4 v9; // er13
char *save_ptr[8]; // [rsp+8h] [rbp-40h] BYREF

v4 = a3 - *a2 - 1;
if ( v4 > 0x19 )
return 0xFFFFFFFFLL;
v5 = strdup(a4);
v6 = strtok_r(v5, ":", save_ptr);
v7 = atoi(v6);
v8 = strcmp(strtok_r(0LL, ":", save_ptr), "check") == 0;
v9 = strcmp(strtok_r(0LL, ":", save_ptr), "all") != 0;
free(v5);
if ( v7 > 0xFF )
return 0xFFFFFFFFLL;
*(_BYTE *)(a1 + (int)(48 * v4 + 24319)) = v7;
*(_BYTE *)(a1 + (int)(48 * v4 + 24320)) = v9;
*(_BYTE *)(a1 + (int)(48 * v4 + 24321)) = v8;
return 0LL;
}

original_code:
static int patch_portvlan(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 int port = code - patch->code;
 if (port < 1 || port > 26)
  return -1;
 char *tmp, *buf = strdup(parameter);
 int vlanid = atoi(strtok_r(buf, ":", &tmp));
 int check_ingress = (strcmp(strtok_r(((void *)0), ":", &tmp), "check") == 0);
 int accept_all = (strcmp(strtok_r(((void *)0), ":", &tmp), "all") == 0);
 free(buf);
 if (vlanid < 0 || vlanid > 255)
  return -1;
 *((uint8_t *)(config + 0x5eff + (port -1) * 0x30)) = vlanid;
 *((uint8_t *)(config + 0x5f00 + (port -1) * 0x30)) = accept_all ? 0x00 : 0x01;
 *((uint8_t *)(config + 0x5f01 + (port -1) * 0x30)) = check_ingress ? 0x01 : 0x00;
 return 0;
}

canonical_original_code:
static int patch_portvlan(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 int port = code - patch->code;
 if (port < 1 || port > 26)
  return -1;
 char *tmp; char *buf = strdup(parameter);
 int vlanid = atoi(strtok_r(buf, ":", &tmp));
 int check_ingress = (strcmp(strtok_r(((void *)0), ":", &tmp), "check") == 0);
 int accept_all = (strcmp(strtok_r(((void *)0), ":", &tmp), "all") == 0);
 free(buf);
 if (vlanid < 0 || vlanid > 255)
  return -1;
 *((unsigned char *)(config + 0x5eff + (port -1) * 0x30)) = vlanid;
 *((unsigned char *)(config + 0x5f00 + (port -1) * 0x30)) = accept_all ? 0x00 : 0x01;
 *((unsigned char *)(config + 0x5f01 + (port -1) * 0x30)) = check_ingress ? 0x01 : 0x00;
 return 0;
}


decompiled_code:
__int64 __fastcall patch_portname(__int64 a1, _DWORD *a2, int a3, const char *a4)
{
unsigned int v4; // edx

v4 = a3 - *a2 - 1;
if ( v4 > 0x19 )
return 0xFFFFFFFFLL;
strncpy((char *)(a1 + (int)(112 * v4 + 13164)), a4, (int)a2[5]);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _DWORD *a2, int a3, const char *a4)
{
unsigned int v4; // edx

v4 = a3 - *a2 - 1;
if ( v4 > 0x19 )
return 0xFFFFFFFFLL;
strncpy((char *)(a1 + (int)(112 * v4 + 13164)), a4, (int)a2[5]);
return 0LL;
}

original_code:
static int patch_portname(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 int port = code - patch->code;
 if (port < 1 || port > 26)
  return -1;
 strncpy(config + 0x336c + (port -1) * 0x70, parameter, patch->size);
 return 0;
}

canonical_original_code:
static int patch_portname(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 int port = code - patch->code;
 if (port < 1 || port > 26)
  return -1;
 strncpy(config + 0x336c + (port -1) * 0x70, parameter, patch->size);
 return 0;
}


original_code:
static int patch_snmp_community(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 strncpy(config + 0x00A0 + patch->offset, parameter, patch->size);
 *((uint8_t *)(config + 0x0101)) = 0x01;
 strncpy(config + 0x9914 + patch->offset, parameter, patch->size);
 *((uint8_t *)(config + 0x9975)) = 0x01;
 strncpy(config + 0x9984 + patch->offset, parameter, patch->size);
 *((uint8_t *)(config + 0x99e5)) = 0x01;
 strncpy(config + 0x99f4 + patch->offset, parameter, patch->size);
 *((uint8_t *)(config + 0x9a55)) = 0x01;
 return 0;
}

canonical_original_code:
static int patch_snmp_community(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 strncpy(config + 0x00A0 + patch->offset, parameter, patch->size);
 *((unsigned char *)(config + 0x0101)) = 0x01;
 strncpy(config + 0x9914 + patch->offset, parameter, patch->size);
 *((unsigned char *)(config + 0x9975)) = 0x01;
 strncpy(config + 0x9984 + patch->offset, parameter, patch->size);
 *((unsigned char *)(config + 0x99e5)) = 0x01;
 strncpy(config + 0x99f4 + patch->offset, parameter, patch->size);
 *((unsigned char *)(config + 0x9a55)) = 0x01;
 return 0;
}


decompiled_code:
__int64 __fastcall patch_string(__int64 a1, __int64 a2, __int64 a3, const char *a4)
{
strncpy((char *)(*(int *)(a2 + 16) + a1), a4, *(int *)(a2 + 20));
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1, __int64 a2, __int64 a3, const char *a4)
{
strncpy((char *)(*(int *)(a2 + 16) + a1), a4, *(int *)(a2 + 20));
return 0LL;
}

original_code:
static int patch_string(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 strncpy(config + patch->offset, parameter, patch->size);
 return 0;
}

canonical_original_code:
static int patch_string(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 strncpy(config + patch->offset, parameter, patch->size);
 return 0;
}


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 || a2[7] < v4 )
return 0xFFFFFFFFLL;
v5 = (__int16 *)(a2[4] + a1);
*v5 = _bswap_16(v4);
return 0LL;
}

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

v4 = atoi(a4);
if ( a2[6] > v4 || a2[7] < v4 )
return 0xFFFFFFFFLL;
v5 = (__int16 *)(a2[4] + a1);
*v5 = func7(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 func9(__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;
}


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);
}


decompiled_code:
// attributes: thunk
__int64 patch_dot1qport()
{
return patch_dot1qvlan_constprop_0();
}

canonical_decompiled_code:
__int64 func12()
{
return func11();
}

original_code:
static int patch_dot1qport(void *config, struct cfg_patch *patch, int code, const char *parameter)
{
 return -1;
 int id = code - patch->code;
 if (id < 1 || id > 32)
  return -1;
 char *tmp, *buf = strdup(parameter);
 int port = atoi(strtok_r(buf, ":", &tmp));
 char *control = strtok_r(((void *)0), ":", &tmp);
 char *tagging = strtok_r(((void *)0), ":", &tmp);
 if (port < 1 || port > 26) {
  free(buf);
  return -1;
 }
 uint32_t *a = (uint32_t *)(config + 0x63f4 + (id -1) * 0xd0);
 uint32_t *b = (uint32_t *)(config + 0x6434 + (id -1) * 0xd0);
 uint32_t *c = (uint32_t *)(config + 0x6474 + (id -1) * 0xd0);
 uint32_t value = (1 << (port -1));
 if (strcmp(control, "normal") == 0) {
  *a &= ~value;
  *b &= ~value;
 } else if (strcmp(control, "fixed") == 0) {
  *a &= ~value;
  *b |= value;
 } else if (strcmp(control, "forbidden") == 0) {
  *a |= value;
  *b |= value;
 } else {
  free(buf);
  return -1;
 }
 if (strcmp(tagging, "tagging") == 0)
  *c |= value;
 else
  *c &= ~value;
 free(buf);
 return 0;
}

canonical_original_code:
static int patch_dot1qport(void *config, struct cfg_patch *patch, int code, char *parameter)
{
 return -1;
 int id = code - patch->code;
 if (id < 1 || id > 32)
  return -1;
 char *tmp; char *buf = strdup(parameter);
 int port = atoi(strtok_r(buf, ":", &tmp));
 char *control = strtok_r(((void *)0), ":", &tmp);
 char *tagging = strtok_r(((void *)0), ":", &tmp);
 if (port < 1 || port > 26) {
  free(buf);
  return -1;
 }
 unsigned int *a = (uint32_t *)(config + 0x63f4 + (id -1) * 0xd0);
 unsigned int *b = (uint32_t *)(config + 0x6434 + (id -1) * 0xd0);
 unsigned int *c = (uint32_t *)(config + 0x6474 + (id -1) * 0xd0);
 unsigned int value = (1 << (port -1));
 if (strcmp(control, "normal") == 0) {
  *a &= ~value;
  *b &= ~value;
 } else if (strcmp(control, "fixed") == 0) {
  *a &= ~value;
  *b |= value;
 } else if (strcmp(control, "forbidden") == 0) {
  *a |= value;
  *b |= value;
 } else {
  free(buf);
  return -1;
 }
 if (strcmp(tagging, "tagging") == 0)
  *c |= value;
 else
  *c &= ~value;
 free(buf);
 return 0;
}

variable_types:
control
char *

variable_types:
tagging
char *

variable_types:
a
unsigned int *

variable_types:
b
unsigned int *

variable_types:
c
unsigned int *

variable_types:
value
unsigned int


decompiled_code:
__int64 __fastcall config_patch(__int64 a1, unsigned int a2, const char *a3)
{
_DWORD *v3; // rax
int v4; // ecx
int v6; // edx
unsigned int v7; // er13

v3 = &patcharr;
v4 = 0;
while ( 1 )
{
v6 = a2 & v3[1];
if ( !v3[1] )
v6 = a2;
if ( *v3 == v6 )
break;
++v4;
v3 += 8;
if ( v4 == 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 * v4 + 1))(
a1,
(char *)&patcharr + 32 * v4,
a2,
a3);
if ( v7 )
{
printf("failed to patch code=0x%x parameter='%s'\n", a2, a3);
return v7;
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, unsigned int a2, const char *a3)
{
_DWORD *v3; // rax
int v4; // ecx
int v6; // edx
unsigned int v7; // er13

v3 = &patcharr;
v4 = 0;
while ( 1 )
{
v6 = a2 & v3[1];
if ( !v3[1] )
v6 = a2;
if ( *v3 == v6 )
break;
++v4;
v3 += 8;
if ( v4 == 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 * v4 + 1))(
a1,
(char *)&patcharr + 32 * v4,
a2,
a3);
if ( v7 )
{
printf("failed to patch code=0x%x parameter='%s'\n", a2, a3);
return v7;
}
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:
config
void *

variable_types: i int

variable_types: mask int

variable_types: retval int


decompiled_code:
void __fastcall list_del(__int64 a1)
{
_QWORD *v1; // rax

_list_del(*(_QWORD **)(a1 + 8), *(_QWORD *)a1);
*v1 = 0LL;
v1[1] = 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; } *


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

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

canonical_decompiled_code:
__int64 __fastcall func4(_QWORD *a1, _QWORD *a2)
{
__int64 result; // rax
__int64 v3; // rax
bool v4; // cc

result = 0xFFFFFFFFLL;
if ( *a1 <= *a2 )
{
result = 1LL;
if ( *a1 >= *a2 )
{
v3 = a2[1];
v4 = a1[1] <= v3;
result = a1[1] < v3;
if ( !v4 )
result = 0xFFFFFFFFLL;
}
}
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; // rbp

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; // rbp

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

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

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

if ( *(_WORD *)(a1 + 2) )
{
v1 = 0;
do
{
v2 = (unsigned int)v1++;
func11(a1, v2);
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(_DWORD *a1, unsigned int a2)
{
__int64 result; // rax
__int64 v3; // rdx

result = a2 >> 2;
if ( a2 >> 2 )
{
v3 = (__int64)&a1[(unsigned int)(result - 1) + 1];
LODWORD(result) = 0;
do
result = (unsigned int)(*a1++ + result);
while ( a1 != (_DWORD *)v3 );
}
return result;
}

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

result = a2 >> 2;
if ( a2 >> 2 )
{
v3 = (__int64)&a1[(unsigned int)(result - 1) + 1];
LODWORD(result) = 0;
do
result = (unsigned int)(*a1++ + result);
while ( a1 != (_DWORD *)v3 );
}
return result;
}

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
int v5[2051]; // [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(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
int v5[2051]; // [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(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

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; // er15
int v5; // eax
int v6; // er13
unsigned int v7; // er15
int v8; // ebx
int v9; // er15
int v10; // ebx
__int64 result; // rax
__int16 v12; // [rsp+Ch] [rbp-83Ch]
char buf[2104]; // [rsp+10h] [rbp-838h] BYREF

v4 = *(_DWORD *)(*(_QWORD *)a2 + 108LL);
v12 = v4;
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);
v7 = v4 >> 11;
lseek(fd, *(unsigned int *)(*(_QWORD *)a2 + 104LL), 0);
printf("%s part ddress is :%x\n", a3, *(unsigned int *)(*(_QWORD *)a2 + 104LL));
v8 = 0;
printf("%s part size is :%d\n", a3, *(unsigned int *)(*(_QWORD *)a2 + 108LL));
if ( v7 )
{
do
{
while ( read(fd, buf, 0x800uLL) < 0 || write(v6, buf, 0x800uLL) >= 0 )
{
if ( ++v8 == v7 )
goto LABEL_8;
}
++v8;
printf("unpack %s part is Error!\n", a3);
}
while ( v8 != v7 );
}
LABEL_8:
v9 = v12 & 0x7FF;
if ( (v12 & 0x7FF) != 0 )
{
v10 = 0;
do
{
while ( read(fd, buf, 1uLL) < 0 || write(v6, buf, 1uLL) >= 0 )
{
if ( ++v10 == v9 )
goto LABEL_14;
}
++v10;
printf("unpack %s part is Error!\n", a3);
}
while ( v10 != v9 );
}
LABEL_14:
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; // er15
int v5; // eax
int v6; // er13
unsigned int v7; // er15
int v8; // ebx
int v9; // er15
int v10; // ebx
__int64 result; // rax
__int16 v12; // [rsp+Ch] [rbp-83Ch]
char buf[2104]; // [rsp+10h] [rbp-838h] BYREF

v4 = *(_DWORD *)(*(_QWORD *)a2 + 108LL);
v12 = v4;
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);
v7 = v4 >> 11;
lseek(fd, *(unsigned int *)(*(_QWORD *)a2 + 104LL), 0);
printf("%s part ddress is :%x\n", a3, *(unsigned int *)(*(_QWORD *)a2 + 104LL));
v8 = 0;
printf("%s part size is :%d\n", a3, *(unsigned int *)(*(_QWORD *)a2 + 108LL));
if ( v7 )
{
do
{
while ( read(fd, buf, 0x800uLL) < 0 || write(v6, buf, 0x800uLL) >= 0 )
{
if ( ++v8 == v7 )
goto LABEL_8;
}
++v8;
printf("unpack %s part is Error!\n", a3);
}
while ( v8 != v7 );
}
LABEL_8:
v9 = v12 & 0x7FF;
if ( (v12 & 0x7FF) != 0 )
{
v10 = 0;
do
{
while ( read(fd, buf, 1uLL) < 0 || write(v6, buf, 1uLL) >= 0 )
{
if ( ++v10 == v9 )
goto LABEL_14;
}
++v10;
printf("unpack %s part is Error!\n", a3);
}
while ( v10 != v9 );
}
LABEL_14:
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 v5; // rsi
unsigned int v6; // ecx
unsigned int v7; // er12
unsigned int v8; // ebx
int *v9; // rax
unsigned int v11; // [rsp+0h] [rbp-828h] BYREF
char v12; // [rsp+4h] [rbp-824h] BYREF

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

canonical_decompiled_code:
__int64 __fastcall func4(int fd, __int64 *a2, const char *a3)
{
__int64 v5; // rsi
unsigned int v6; // ecx
unsigned int v7; // er12
unsigned int v8; // ebx
int *v9; // rax
unsigned int v11; // [rsp+0h] [rbp-828h] BYREF
char v12; // [rsp+4h] [rbp-824h] BYREF

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

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

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; // ebp
__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 func7(char *file)
{
int v1; // eax
int v2; // ebp
__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]);
func6(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
const char *v2; // rdi
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);
v2 = v1 + 64;
v1 += 108;
result = puts(v2);
}
while ( *((_DWORD *)v1 - 1) == 1 );
}
return result;
}

canonical_decompiled_code:
int __fastcall func2(_DWORD *a1)
{
const char *v1; // rbx
const char *v2; // rdi
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);
v2 = v1 + 64;
v1 += 108;
result = puts(v2);
}
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; // ebp
char v5; // sp
char v6; // al
unsigned int v7; // er14
const char *v8; // rcx
__int64 v9; // rdi
char v11[32]; // [rsp+0h] [rbp-15A8h] BYREF
char v12[1632]; // [rsp+20h] [rbp-1588h] BYREF

v3 = 0;
disp_aut_info();
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(v11, optarg, 0x20uLL);
continue;
case 'b':
v7 = v3 + 1;
v8 = "bootloader";
goto LABEL_5;
case 'c':
v7 = v3 + 1;
v8 = "cpimage";
goto LABEL_5;
case 'd':
v7 = v3 + 1;
v8 = "userdata";
goto LABEL_5;
case 'e':
v7 = v3 + 1;
v8 = "cache";
goto LABEL_5;
case 'h':
disp_help_info();
continue;
case 'i':
get_szb_info(optarg, 0LL, 0LL);
continue;
case 'k':
v7 = v3 + 1;
v8 = "boot";
goto LABEL_5;
case 'l':
continue;
case 'p':
v7 = v3 + 1;
v8 = "preload";
goto LABEL_5;
case 's':
v7 = v3 + 1;
v8 = "system";
goto LABEL_5;
case 'v':
puts("start pack new szbpack!!");
puts("lephone.cc provide !!");
pack_main(0LL, 0LL, v12, (unsigned int)(char)(v5 + 0x80), optarg, v11);
puts("pack szb is end!");
continue;
case 'x':
unpack_main(optarg, 0LL, 0LL);
continue;
case 'y':
v7 = v3 + 1;
v8 = "recovery";
LABEL_5:
v9 = v3;
v3 = v7;
create_chain(v9, v12, optarg, v8);
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; // ebp
char v5; // sp
char v6; // al
unsigned int v7; // er14
const char *v8; // rcx
__int64 v9; // rdi
char v11[32]; // [rsp+0h] [rbp-15A8h] BYREF
char v12[1632]; // [rsp+20h] [rbp-1588h] BYREF

v3 = 0;
func0();
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(v11, optarg, 0x20uLL);
continue;
case 'b':
v7 = v3 + 1;
v8 = "bootloader";
goto LABEL_5;
case 'c':
v7 = v3 + 1;
v8 = "cpimage";
goto LABEL_5;
case 'd':
v7 = v3 + 1;
v8 = "userdata";
goto LABEL_5;
case 'e':
v7 = v3 + 1;
v8 = "cache";
goto LABEL_5;
case 'h':
func1();
continue;
case 'i':
get_szb_info(optarg, 0LL, 0LL);
continue;
case 'k':
v7 = v3 + 1;
v8 = "boot";
goto LABEL_5;
case 'l':
continue;
case 'p':
v7 = v3 + 1;
v8 = "preload";
goto LABEL_5;
case 's':
v7 = v3 + 1;
v8 = "system";
goto LABEL_5;
case 'v':
puts("start pack new szbpack!!");
puts("lephone.cc provide !!");
pack_main(0LL, 0LL, v12, (unsigned int)(char)(v5 + 0x80), optarg, v11);
puts("pack szb is end!");
continue;
case 'x':
unpack_main(optarg, 0LL, 0LL);
continue;
case 'y':
v7 = v3 + 1;
v8 = "recovery";
LABEL_5:
v9 = v3;
v3 = v7;
create_chain(v9, v12, optarg, v8);
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;
*(_QWORD *)(v5 + 100) = 0x100000001LL;
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; // er12
unsigned int v6; // ecx
unsigned int v7; // er15
unsigned int v8; // ebx
int *v9; // rax
unsigned int v11; // [rsp+0h] [rbp-838h] BYREF
char v12; // [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, &v11, 0x800uLL) < 0 )
{
LABEL_12:
puts("read fail!");
exit(1);
}
if ( write(fd, &v11, 0x800uLL) < 0 )
{
LABEL_13:
printf("pack %s part is Error!\n", a3);
exit(1);
}
v6 = *((_DWORD *)*a2 + 27);
v7 = v6 >> 2;
if ( v6 >> 2 )
{
v7 = v11;
v8 = 1;
v9 = (int *)&v12;
while ( v6 >> 2 > v8 )
{
while ( 1 )
{
++v8;
v7 += *v9++;
if ( (v8 & 0x1FF) != 0 )
break;
if ( read(v5, &v11, 0x800uLL) < 0 )
goto LABEL_12;
if ( write(fd, &v11, 0x800uLL) < 0 )
goto LABEL_13;
v6 = *((_DWORD *)*a2 + 27);
v9 = (int *)&v11;
if ( v6 >> 2 <= v8 )
goto LABEL_11;
}
}
}
LABEL_11:
close(v5);
strncpy((char *)*a2, a3, 0x20uLL);
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func3(int fd, const char **a2, const char *a3)
{
int v4; // eax
int v5; // er12
unsigned int v6; // ecx
unsigned int v7; // er15
unsigned int v8; // ebx
int *v9; // rax
unsigned int v11; // [rsp+0h] [rbp-838h] BYREF
char v12; // [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, &v11, 0x800uLL) < 0 )
{
LABEL_12:
puts("read fail!");
exit(1);
}
if ( write(fd, &v11, 0x800uLL) < 0 )
{
LABEL_13:
printf("pack %s part is Error!\n", a3);
exit(1);
}
v6 = *((_DWORD *)*a2 + 27);
v7 = v6 >> 2;
if ( v6 >> 2 )
{
v7 = v11;
v8 = 1;
v9 = (int *)&v12;
while ( v6 >> 2 > v8 )
{
while ( 1 )
{
++v8;
v7 += *v9++;
if ( (v8 & 0x1FF) != 0 )
break;
if ( read(v5, &v11, 0x800uLL) < 0 )
goto LABEL_12;
if ( write(fd, &v11, 0x800uLL) < 0 )
goto LABEL_13;
v6 = *((_DWORD *)*a2 + 27);
v9 = (int *)&v11;
if ( v6 >> 2 <= v8 )
goto LABEL_11;
}
}
}
LABEL_11:
close(v5);
strncpy((char *)*a2, a3, 0x20uLL);
return v7;
}

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, int a3)
{
unsigned int v4; // er12
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 )
{
LABEL_10:
puts("read fail!");
exit(1);
}
v4 = 0;
if ( a3 )
{
v4 = v8;
v5 = 1;
v6 = (int *)&v9;
while ( a3 != v5 )
{
while ( 1 )
{
++v5;
v4 += *v6++;
if ( (v5 & 0x1FF) != 0 )
break;
if ( read(fd, &v8, 0x800uLL) < 0 )
goto LABEL_10;
v6 = (int *)&v8;
if ( a3 == v5 )
return v4;
}
}
}
return v4;
}

canonical_decompiled_code:
__int64 __fastcall func4(int fd, __off_t offset, int a3)
{
unsigned int v4; // er12
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 )
{
LABEL_10:
puts("read fail!");
exit(1);
}
v4 = 0;
if ( a3 )
{
v4 = v8;
v5 = 1;
v6 = (int *)&v9;
while ( a3 != v5 )
{
while ( 1 )
{
++v5;
v4 += *v6++;
if ( (v5 & 0x1FF) != 0 )
break;
if ( read(fd, &v8, 0x800uLL) < 0 )
goto LABEL_10;
v6 = (int *)&v8;
if ( a3 == v5 )
return v4;
}
}
}
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