print

decompiled_code:
int print(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return do_print(a1, va);
}

canonical_decompiled_code:
int func3(const char *a1, ...)
{
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a1);
return func0(a1, va);
}

original_code:
void
print(const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    do_print(fmt, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void print(char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    do_print(fmt, ap);
    __builtin_va_end(ap);
}


printo

repo: agalakhov/lr-experiments

decompiled_code:
int printo(unsigned int a1, const char *a2, ...)
{
int result; // eax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
result = print_opt(a1);
if ( (_BYTE)result )
result = do_print(a2, va);
return result;
}

canonical_decompiled_code:
int func4(unsigned int a1, const char *a2, ...)
{
int result; // eax
gcc_va_list va; // [rsp+8h] [rbp-D0h] BYREF

va_start(va, a2);
result = func2(a1);
if ( (_BYTE)result )
result = func0(a2, va);
return result;
}

original_code:
void
printo(enum print opt, const char *fmt, ...)
{
    va_list ap;
    __builtin_va_start(ap,fmt);
    if (print_opt(opt))
        do_print(fmt, ap);
    __builtin_va_end(ap);
}

canonical_original_code:
void printo(enum print opt, char *fmt, ...)
{
    __builtin_va_list ap;
    __builtin_va_start(ap,fmt);
    if (print_opt(opt))
        do_print(fmt, ap);
    __builtin_va_end(ap);
}

variable_types: enum print { P_GRAMMAR=0, P_SYMBOLS=1, P_NULLABLE=2, P_LR0_KERNELS=3, P_LR0_CLOSURES=4, P_LR0_GOTO=5, P_LR_REDUCE=6, P_MAX_=7 }

variable_types:
fmt
char *

return_type: void


decompiled_code:
__int64 __fastcall print_options(char *s)
{
char *v1; // rbp
unsigned int i; // ebx
unsigned int j; // ebx
char **v4; // rbx
char *v5; // r13
unsigned __int64 v6; // rcx
__int64 result; // rax
__int64 k; // rsi

v1 = s;
if ( options )
set_free(options);
options = set_alloc(7LL);
if ( !options )
abort();
atexit(print_options_free);
if ( *s )
{
while ( 1 )
{
v5 = strchr(v1, 44);
if ( !v5 )
v5 = &v1[strlen(v1)];
v6 = 4LL;
if ( (unsigned __int64)(v5 - v1) <= 4 )
v6 = v5 - v1;
if ( !memcmp(&unk_2F8, v1, v6) )
break;
v4 = &propts;
do
{
if ( !strncmp(*v4, v1, v5 - v1) )
set_add(options, *((unsigned int *)v4 + 2));
v4 += 2;
}
while ( &unk_410 != (_UNKNOWN *)v4 );
if ( *v5 )
{
v1 = v5 + 1;
if ( v5[1] )
continue;
}
goto LABEL_9;
}
for ( i = 0; i != 7; ++i )
set_add(options, i);
}
LABEL_9:
for ( j = 0; j <= 8; ++j )
{
result = set_has(options, (unsigned int)prdepends[j]);
if ( (_BYTE)result )
{
result = ++j;
for ( k = (unsigned int)prdepends[j]; (_DWORD)k != 7; k = (unsigned int)prdepends[j] )
{
set_add(options, k);
result = ++j;
}
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s)
{
char *v1; // rbp
unsigned int i; // ebx
unsigned int j; // ebx
char **v4; // rbx
char *v5; // r13
unsigned __int64 v6; // rcx
__int64 result; // rax
__int64 k; // rsi

v1 = s;
if ( options )
set_free(options);
options = set_alloc(7LL);
if ( !options )
abort();
atexit(print_options_free);
if ( *s )
{
while ( 1 )
{
v5 = strchr(v1, 44);
if ( !v5 )
v5 = &v1[strlen(v1)];
v6 = 4LL;
if ( (unsigned __int64)(v5 - v1) <= 4 )
v6 = v5 - v1;
if ( !memcmp(&unk_2F8, v1, v6) )
break;
v4 = &propts;
do
{
if ( !strncmp(*v4, v1, v5 - v1) )
set_add(options, *((unsigned int *)v4 + 2));
v4 += 2;
}
while ( &unk_410 != (_UNKNOWN *)v4 );
if ( *v5 )
{
v1 = v5 + 1;
if ( v5[1] )
continue;
}
goto LABEL_9;
}
for ( i = 0; i != 7; ++i )
set_add(options, i);
}
LABEL_9:
for ( j = 0; j <= 8; ++j )
{
result = set_has(options, (unsigned int)prdepends[j]);
if ( (_BYTE)result )
{
result = ++j;
for ( k = (unsigned int)prdepends[j]; (_DWORD)k != 7; k = (unsigned int)prdepends[j] )
{
set_add(options, k);
result = ++j;
}
}
}
return result;
}

original_code:
void
print_options(const char *opts)
{
    if (options)
        set_free(options);
    options = set_alloc(P_MAX_);
    if (! options)
        abort();
    atexit(print_options_free);
    const char *end;
    while (*opts) {
        end = strchr(opts, ',');
        if (! end)
            end = opts + strlen(opts);
        if (! strncmp("all", opts, end - opts)) {
            for (unsigned i = 0; i < P_MAX_; ++i)
                set_add(options, i);
            break;
        }
        for (unsigned i = 0; i < (sizeof(propts)/sizeof(propts[0])); ++i) {
            if (! strncmp(propts[i].name, opts, end - opts))
                set_add(options, propts[i].flag);
        }
        opts = end;
        if (*opts)
            ++opts;
    }
    for (unsigned i = 0; i < (sizeof(prdepends)/sizeof(prdepends[0])); ++i) {
        if (set_has(options, prdepends[i])) {
            for (++i; prdepends[i] != P_MAX_; ++i)
                set_add(options, prdepends[i]);
        }
    }
}

canonical_original_code:
void print_options(char *opts)
{
    if (options)
        set_free(options);
    options = set_alloc(P_MAX_);
    if (! options)
        abort();
    atexit(print_options_free);
    char *end;
    while (*opts) {
        end = strchr(opts, ',');
        if (! end)
            end = opts + strlen(opts);
        if (! strncmp("all", opts, end - opts)) {
            for (unsigned int i = 0; i < P_MAX_; ++i)
                set_add(options, i);
            break;
        }
        for (unsigned int i = 0; i < (sizeof(propts)/sizeof(propts[0])); ++i) {
            if (! strncmp(propts[i].name, opts, end - opts))
                set_add(options, propts[i].flag);
        }
        opts = end;
        if (*opts)
            ++opts;
    }
    for (unsigned int i = 0; i < (sizeof(prdepends)/sizeof(prdepends[0])); ++i) {
        if (set_has(options, prdepends[i])) {
            for (++i; prdepends[i] != P_MAX_; ++i)
                set_add(options, prdepends[i]);
        }
    }
}

variable_types:
opts
char *

variable_types:
end
char *

variable_types:
i
unsigned int


decompiled_code:
__int64 __fastcall sizeof_struct_bucket(__int64 a1)
{
return a1 + 17;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return a1 + 17;
}

original_code:
static inline size_t sizeof_struct_bucket(size_t len) {
    return sizeof(struct bucket) + len + 1;
}

canonical_original_code:
static inline unsigned long sizeof_struct_bucket(unsigned long len) {
    return sizeof(struct bucket) + len + 1;
}

variable_types:
len
unsigned long

return_type: unsigned long

user_defined_types: struct bucket { struct bucket *next; void *payload; char key[]; }


hashfunc

original_code:
static unsigned
hashfunc(const char *str)
{
    uint32_t hsh = 2166136261;
    for (; *str; ++str) {
        hsh ^= *str;
        hsh *= 16777619;
    }
    hsh ^= (hsh >> 16);
    hsh &= 0xFFFF;
    hsh ^= (hsh >> 8);
    return hsh % 256;
}

canonical_original_code:
static unsigned int hashfunc(char *str)
{
    unsigned int hsh = 2166136261;
    for (; *str; ++str) {
        hsh ^= *str;
        hsh *= 16777619;
    }
    hsh ^= (hsh >> 16);
    hsh &= 0xFFFF;
    hsh ^= (hsh >> 8);
    return hsh % 256;
}

variable_types:
str
char *

variable_types:
hsh
unsigned int

return_type: unsigned int


equals

decompiled_code:
_BOOL8 __fastcall equals(const char *a1, const char *a2)
{
_BOOL8 result; // rax

if ( a1 == a2 )
result = 1LL;
else
result = strcmp(a1, a2) == 0;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(const char *a1, const char *a2)
{
_BOOL8 result; // rax

if ( a1 == a2 )
result = 1LL;
else
result = strcmp(a1, a2) == 0;
return result;
}

original_code:
static _Bool
equals(const char *s1, const char *s2)
{
    return (s1 == s2) || (strcmp(s1, s2) == 0);
}

canonical_original_code:
static _Bool equals(char *s1, char *s2)
{
    return (s1 == s2) || (strcmp(s1, s2) == 0);
}


decompiled_code:
void *strhash_alloc()
{
return calloc(1uLL, 0x800uLL);
}

canonical_decompiled_code:
void *func3()
{
return calloc(1uLL, 0x800uLL);
}

original_code:
strhash_t
strhash_alloc(void)
{
    return (strhash_t)calloc(1, sizeof(struct strhash));
}

canonical_original_code:
struct strhash *strhash_alloc()
{
    return (struct strhash *)calloc(1, sizeof(struct strhash));
}

return_type: struct strhash { struct bucket { struct bucket *next; void *payload; char key[]; } *buckets[256]; } *

user_defined_types: struct strhash { struct bucket *buckets[256]; }


decompiled_code:
void __fastcall strhash_free(char *a1, void (__fastcall *a2)(_QWORD))
{
char *v2; // r13
_QWORD *v3; // rbp
_QWORD *v4; // rbx

v2 = a1;
do
{
v4 = *(_QWORD **)v2;
if ( *(_QWORD *)v2 )
{
do
{
v3 = v4;
v4 = (_QWORD *)*v4;
if ( a2 )
a2(v3[1]);
free(v3);
}
while ( v4 );
}
v2 += 8;
}
while ( v2 != a1 + 2048 );
free(a1);
}

canonical_decompiled_code:
void __fastcall func4(char *a1, void (__fastcall *a2)(_QWORD))
{
char *v2; // r13
_QWORD *v3; // rbp
_QWORD *v4; // rbx

v2 = a1;
do
{
v4 = *(_QWORD **)v2;
if ( *(_QWORD *)v2 )
{
do
{
v3 = v4;
v4 = (_QWORD *)*v4;
if ( a2 )
a2(v3[1]);
free(v3);
}
while ( v4 );
}
v2 += 8;
}
while ( v2 != a1 + 2048 );
free(a1);
}

original_code:
void
strhash_free(strhash_t hash, hash_free_func_t freefunc)
{
    for (unsigned i = 0; i < 256; ++i) {
        struct bucket *b = hash->buckets[i];
        while (b) {
            struct bucket *n = b->next;
            if (freefunc)
                freefunc(b->payload);
            free(b);
            b = n;
        }
    }
    free(hash);
}

canonical_original_code:
void strhash_free(struct strhash *hash, void (*freefunc)(void *))
{
    for (unsigned int i = 0; i < 256; ++i) {
        struct bucket *b = hash->buckets[i];
        while (b) {
            struct bucket *n = b->next;
            if (freefunc)
                freefunc(b->payload);
            free(b);
            b = n;
        }
    }
    free(hash);
}

variable_types: struct strhash { struct bucket { struct bucket *next; void *payload; char key[]; } *buckets[256]; } *

variable_types:
freefunc
void (*)(void *)


decompiled_code:
char *__fastcall strhash_find(__int64 a1, char *a2)
{
unsigned int v2; // er12
char *v3; // r14
char *v4; // rbx
__int64 v5; // rax
__int64 v6; // rax
char *v7; // rax

v2 = hashfunc(a2);
v3 = *(char **)(a1 + 8LL * v2);
v4 = v3;
if ( v3 )
{
while ( !equals(a2, v4 + 16) )
{
v4 = *(char **)v4;
if ( !v4 )
goto LABEL_4;
}
if ( v4 )
goto LABEL_7;
}
LABEL_4:
v5 = strlen(a2);
v6 = sizeof_struct_bucket(v5);
v7 = (char *)calloc(1uLL, v6);
v4 = v7;
if ( v7 )
{
strcpy(v7 + 16, a2);
*(_QWORD *)v4 = v3;
*(_QWORD *)(a1 + 8LL * v2) = v4;
LABEL_7:
v4 += 8;
}
return v4;
}

canonical_decompiled_code:
char *__fastcall func6(__int64 a1, char *a2)
{
unsigned int v2; // er12
char *v3; // r14
char *v4; // rbx
__int64 v5; // rax
__int64 v6; // rax
char *v7; // rax

v2 = func1(a2);
v3 = *(char **)(a1 + 8LL * v2);
v4 = v3;
if ( v3 )
{
while ( !func2(a2, v4 + 16) )
{
v4 = *(char **)v4;
if ( !v4 )
goto LABEL_4;
}
if ( v4 )
goto LABEL_7;
}
LABEL_4:
v5 = strlen(a2);
v6 = func0(v5);
v7 = (char *)calloc(1uLL, v6);
v4 = v7;
if ( v7 )
{
strcpy(v7 + 16, a2);
*(_QWORD *)v4 = v3;
*(_QWORD *)(a1 + 8LL * v2) = v4;
LABEL_7:
v4 += 8;
}
return v4;
}

original_code:
void **
strhash_find(strhash_t hash, const char *key)
{
    unsigned hsh = hashfunc(key);
    struct bucket * b = hash->buckets[hsh];
    for ( ; b && ! equals(key, b->key); b = b->next)
        ;
    if (! b) {
        b = calloc(1, sizeof_struct_bucket(strlen(key)));
        if (! b)
            return ((void *)0);
        strcpy(b->key, key);
        b->next = hash->buckets[hsh];
        hash->buckets[hsh] = b;
    }
    return &b->payload;
}

canonical_original_code:
void **strhash_find(struct strhash *hash, char *key)
{
    unsigned int hsh = hashfunc(key);
    struct bucket *b = hash->buckets[hsh];
    for ( ; b && ! equals(key, b->key); b = b->next)
        ;
    if (! b) {
        b = calloc(1, sizeof_struct_bucket(strlen(key)));
        if (! b)
            return ((void *)0);
        strcpy(b->key, key);
        b->next = hash->buckets[hsh];
        hash->buckets[hsh] = b;
    }
    return &b->payload;
}

variable_types:
key
char *

variable_types: struct bucket { struct bucket *next; void *payload; char key[]; } *

return_type: void **


decompiled_code:
__int64 __fastcall sizeof_struct_bitset(__int64 a1)
{
return 8 * a1 + 8;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1)
{
return 8 * a1 + 8;
}

original_code:
static inline size_t sizeof_struct_bitset(size_t max) {
    return sizeof(struct bitset) + max * sizeof(unsigned long);
}

canonical_original_code:
static inline unsigned long sizeof_struct_bitset(unsigned long max) {
    return sizeof(struct bitset) + max * sizeof(unsigned long);
}

variable_types:
max
unsigned long

user_defined_types: struct bitset { unsigned long max; unsigned long data[]; }


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

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

original_code:
void
set_free(bitset_t set)
{
    free(set);
}

canonical_original_code:
void set_free(struct bitset *set)
{
    free(set);
}

variable_types: struct bitset { unsigned long max; unsigned long data[]; } *


decompiled_code:
__int64 __fastcall set_has(_QWORD *a1, unsigned int a2)
{
__int64 v2; // rdx

LODWORD(v2) = 0;
if ( (unsigned __int64)a2 < *a1 << 6 )
{
v2 = a2 >> 6;
LOBYTE(v2) = (a1[v2 + 1] & (1 << a2)) != 0LL;
}
return (unsigned int)v2;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1, unsigned int a2)
{
__int64 v2; // rdx

LODWORD(v2) = 0;
if ( (unsigned __int64)a2 < *a1 << 6 )
{
v2 = a2 >> 6;
LOBYTE(v2) = (a1[v2 + 1] & (1 << a2)) != 0LL;
}
return (unsigned int)v2;
}

original_code:
_Bool
set_has(bitset_t set, unsigned x)
{
    if (x >= set->max * (8 * sizeof(unsigned long)))
        return 0;
    size_t idx = x / (8 * sizeof(unsigned long));
    size_t bit = x % (8 * sizeof(unsigned long));
    return !! (set->data[idx] & (1 << bit));
}

canonical_original_code:
_Bool set_has(struct bitset *set, unsigned int x)
{
    if (x >= set->max * (8 * sizeof(unsigned long)))
        return 0;
    unsigned long idx = x / (8 * sizeof(unsigned long));
    unsigned long bit = x % (8 * sizeof(unsigned long));
    return !! (set->data[idx] & (1 << bit));
}

variable_types:
x
unsigned int

variable_types:
idx
unsigned long

variable_types:
bit
unsigned long


decompiled_code:
__int64 __fastcall set_add(_QWORD *a1, unsigned int a2)
{
char v2; // cl
__int64 v3; // rdx
__int64 v4; // rsi
__int64 v5; // rax

v2 = a2;
LODWORD(v3) = 0;
if ( (unsigned __int64)a2 < *a1 << 6 )
{
v3 = a2 >> 6;
v4 = a1[v3 + 1];
v5 = v4 | (1 << v2);
a1[v3 + 1] = v5;
LOBYTE(v3) = v5 != v4;
}
return (unsigned int)v3;
}

canonical_decompiled_code:
__int64 __fastcall func3(_QWORD *a1, unsigned int a2)
{
char v2; // cl
__int64 v3; // rdx
__int64 v4; // rsi
__int64 v5; // rax

v2 = a2;
LODWORD(v3) = 0;
if ( (unsigned __int64)a2 < *a1 << 6 )
{
v3 = a2 >> 6;
v4 = a1[v3 + 1];
v5 = v4 | (1 << v2);
a1[v3 + 1] = v5;
LOBYTE(v3) = v5 != v4;
}
return (unsigned int)v3;
}

original_code:
_Bool
set_add(bitset_t set, unsigned x)
{
    if (x >= set->max * (8 * sizeof(unsigned long)))
        return 0;
    size_t idx = x / (8 * sizeof(unsigned long));
    size_t bit = x % (8 * sizeof(unsigned long));
    unsigned long old = set->data[idx];
    set->data[idx] |= (1 << bit);
    return (set->data[idx] != old);
}

canonical_original_code:
_Bool set_add(struct bitset *set, unsigned int x)
{
    if (x >= set->max * (8 * sizeof(unsigned long)))
        return 0;
    unsigned long idx = x / (8 * sizeof(unsigned long));
    unsigned long bit = x % (8 * sizeof(unsigned long));
    unsigned long old = set->data[idx];
    set->data[idx] |= (1 << bit);
    return (set->data[idx] != old);
}

variable_types:
old
unsigned long


original_code:
_Bool
set_union(bitset_t set, bitset_t xs)
{
    _Bool ret = 0;
    for (size_t i = 0; i < set->max && i < xs->max; ++i) {
        unsigned long old = set->data[i];
        set->data[i] |= xs->data[i];
        ret = ret || (set->data[i] != old);
    }
    return ret;
}

canonical_original_code:
_Bool set_union(struct bitset *set, struct bitset *xs)
{
    _Bool ret = 0;
    for (unsigned long i = 0; i < set->max && i < xs->max; ++i) {
        unsigned long old = set->data[i];
        set->data[i] |= xs->data[i];
        ret = ret || (set->data[i] != old);
    }
    return ret;
}

variable_types:
xs
struct bitset *

variable_types:
i
unsigned long


original_code:
size_t
set_size(bitset_t set)
{
    static const unsigned long mask[] = {
        (unsigned long) 0x5555555555555555,
        (unsigned long) 0x3333333333333333,
        (unsigned long) 0x0F0F0F0F0F0F0F0F,
        (unsigned long) 0x00FF00FF00FF00FF,
        (unsigned long) 0x0000FFFF0000FFFF,
        (unsigned long) 0x00000000FFFFFFFF,
    };
    size_t ret = 0;
    for (size_t i = 0; i < set->max; ++i) {
        unsigned long cnt = set->data[i];
        for (unsigned j = 0; (1u << j) < (8 * sizeof(unsigned long)); ++j)
            cnt = (cnt & mask[j]) + ((cnt >> (1u << j)) & mask[j]);
        ret += cnt;
    }
    return ret;
}

canonical_original_code:
unsigned long set_size(struct bitset *set)
{
    static unsigned long mask[] = {
        (unsigned long) 0x5555555555555555,
        (unsigned long) 0x3333333333333333,
        (unsigned long) 0x0F0F0F0F0F0F0F0F,
        (unsigned long) 0x00FF00FF00FF00FF,
        (unsigned long) 0x0000FFFF0000FFFF,
        (unsigned long) 0x00000000FFFFFFFF,
    };
    unsigned long ret = 0;
    for (unsigned long i = 0; i < set->max; ++i) {
        unsigned long cnt = set->data[i];
        for (unsigned int j = 0; (1u << j) < (8 * sizeof(unsigned long)); ++j)
            cnt = (cnt & mask[j]) + ((cnt >> (1u << j)) & mask[j]);
        ret += cnt;
    }
    return ret;
}

variable_types:
mask
unsigned long []

variable_types:
ret
unsigned long

variable_types:
cnt
unsigned long

variable_types:
j
unsigned int


decompiled_code:
__int64 __fastcall sizeof_struct_array(__int64 a1, __int64 a2)
{
return a2 * a1 + 32;
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
return a2 * a1 + 32;
}

original_code:
static inline size_t sizeof_struct_array(size_t size, size_t elem_size) {
    return sizeof(struct array) + size * elem_size;
}

canonical_original_code:
static inline unsigned long sizeof_struct_array(unsigned long size, unsigned long elem_size) {
    return sizeof(struct array) + size * elem_size;
}

variable_types:
size
unsigned long

user_defined_types: struct array { void (*freefunc)(void *); unsigned long elem_size; unsigned long space; unsigned long size; char data[]; }


decompiled_code:
__int64 __fastcall array_push(size_t *a1, const void *a2)
{
size_t *v2; // rbx
unsigned __int64 v3; // rax
unsigned __int64 v4; // rdi
__int64 v5; // rdi
__int64 v6; // rax
__int64 result; // rax

v2 = a1;
v3 = a1[3] + 1;
a1[3] = v3;
v4 = a1[2];
if ( v3 <= v4
|| (v5 = 2 * v4,
v2[2] = v5,
v6 = sizeof_struct_array(v5, v2[1]),
result = rcrealloc_free(v2, v6, array_destroy),
(v2 = (size_t *)result) != 0LL) )
{
memcpy((char *)v2 + v2[1] * (v2[3] - 1) + 32, a2, v2[1]);
result = (__int64)v2;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(size_t *a1, const void *a2)
{
size_t *v2; // rbx
unsigned __int64 v3; // rax
unsigned __int64 v4; // rdi
__int64 v5; // rdi
__int64 v6; // rax
__int64 result; // rax

v2 = a1;
v3 = a1[3] + 1;
a1[3] = v3;
v4 = a1[2];
if ( v3 <= v4
|| (v5 = 2 * v4,
v2[2] = v5,
v6 = func0(v5, v2[1]),
result = rcrealloc_free(v2, v6, array_destroy),
(v2 = (size_t *)result) != 0LL) )
{
memcpy((char *)v2 + v2[1] * (v2[3] - 1) + 32, a2, v2[1]);
result = (__int64)v2;
}
return result;
}

original_code:
array_t
array_push(array_t array, void *elem)
{
    ++(array->size);
    if (array->size > array->space) {
        array->space *= 2;
        array = rcrealloc_free(array, sizeof_struct_array(array->space, array->elem_size), array_destroy);
        if (! array)
            return ((void *)0);
    }
    memcpy(array->data + ((array->size - 1) * array->elem_size), elem, array->elem_size);
    return array;
}

canonical_original_code:
struct array *array_push(struct array *array, void *elem)
{
    ++(array->size);
    if (array->size > array->space) {
        array->space *= 2;
        array = rcrealloc_free(array, sizeof_struct_array(array->space, array->elem_size), array_destroy);
        if (! array)
            return ((void *)0);
    }
    memcpy(array->data + ((array->size - 1) * array->elem_size), elem, array->elem_size);
    return array;
}

variable_types:
array
struct array *

variable_types:
elem
void *

return_type: struct array { void (*freefunc)(void *); unsigned long elem_size; unsigned long space; unsigned long size; char data[]; } *


decompiled_code:
__int64 __fastcall array_data(__int64 a1)
{
return a1 + 32;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return a1 + 32;
}

original_code:
void *
array_data(array_t array)
{
    return array->data;
}

canonical_original_code:
void *array_data(struct array *array)
{
    return array->data;
}

variable_types: struct array { void (*freefunc)(void *); unsigned long elem_size; unsigned long space; unsigned long size; char data[]; } *

return_type: void *


decompiled_code:
__int64 __fastcall array_size(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
size_t
array_size(array_t array)
{
    return array->size;
}

canonical_original_code:
unsigned long array_size(struct array *array)
{
    return array->size;
}


decompiled_code:
__int64 array_ref()
{
return rcref();
}

canonical_decompiled_code:
__int64 func5()
{
return rcref();
}

original_code:
void
array_ref(array_t array)
{
    rcref(array);
}

canonical_original_code:
void array_ref(struct array *array)
{
    rcref(array);
}


decompiled_code:
__int64 __fastcall array_unref(__int64 a1)
{
return rcunref_free(a1, array_destroy);
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
return rcunref_free(a1, array_destroy);
}

original_code:
void
array_unref(array_t array)
{
    rcunref_free(array, array_destroy);
}

canonical_original_code:
void array_unref(struct array *array)
{
    rcunref_free(array, array_destroy);
}


rcunref

decompiled_code:
void __fastcall rcunref(__int64 a1)
{
rcunref_free(a1, 0LL);
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1)
{
func1(a1, 0LL);
}

original_code:
void
rcunref(void *ptr)
{
    rcunref_free(ptr, ((void *)0));
}

variable_types:
ptr
void *


rcrealloc

decompiled_code:
char *__fastcall rcrealloc(__int64 a1, __int64 a2)
{
return rcrealloc_free(a1, a2, 0LL);
}

canonical_decompiled_code:
char *__fastcall func4(__int64 a1, __int64 a2)
{
return func3(a1, a2, 0LL);
}

original_code:
void *
rcrealloc(void *ptr, size_t size)
{
    return rcrealloc_free(ptr, size, ((void *)0));
}

canonical_original_code:
void *rcrealloc(void *ptr, unsigned long size)
{
    return rcrealloc_free(ptr, size, ((void *)0));
}


usage

decompiled_code:
__int64 __fastcall usage(const char *a1)
{
fprintf(
stderr,
"Usage: %s [OPTION]... FILE\n"
"Generate *.c and *.h constant array file from an arbitrary text file.\n"
"\n"
"Options:\n"
" -H FILE.h header file to generate\n"
" -o FILE.c source file to generate\n"
" -s SYMBOL C symbol name\n",
a1);
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1)
{
fprintf(
stderr,
"Usage: %s [OPTION]... FILE\n"
"Generate *.c and *.h constant array file from an arbitrary text file.\n"
"\n"
"Options:\n"
" -H FILE.h header file to generate\n"
" -o FILE.c source file to generate\n"
" -s SYMBOL C symbol name\n",
a1);
return 1LL;
}

original_code:
static int
usage(const char *name)
{
    fprintf(stderr, ""
"Usage: %s [OPTION]... FILE\n"
"Generate *.c and *.h constant array file from an arbitrary text file.\n"
"\n"
"Options:\n"
"  -H FILE.h  header file to generate\n"
"  -o FILE.c  source file to generate\n"
"  -s SYMBOL  C symbol name\n"
            "", name);
    return 1;
}

canonical_original_code:
static int usage(char *name)
{
    fprintf(stderr, ""
"Usage: %s [OPTION]... FILE\n"
"Generate *.c and *.h constant array file from an arbitrary text file.\n"
"\n"
"Options:\n"
"  -H FILE.h  header file to generate\n"
"  -o FILE.c  source file to generate\n"
"  -s SYMBOL  C symbol name\n"
            "", name);
    return 1;
}

variable_types:
name
char *

return_type: int


svgIsCommand

decompiled_code:
__int64 __fastcall svgIsCommand(char a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = g_atPathCommandFormat;
if ( g_atPathCommandFormat )
{
v2 = (unsigned int)((_DWORD)&g_atPathCommandFormat + 8);
while ( a1 != (_BYTE)result )
{
v2 += 8LL;
result = *(unsigned __int8 *)(v2 - 8);
if ( !(_BYTE)result )
return result;
}
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(char a1)
{
__int64 result; // rax
__int64 v2; // rdx

result = g_atPathCommandFormat;
if ( g_atPathCommandFormat )
{
v2 = (unsigned int)((_DWORD)&g_atPathCommandFormat + 8);
while ( a1 != (_BYTE)result )
{
v2 += 8LL;
result = *(unsigned __int8 *)(v2 - 8);
if ( !(_BYTE)result )
return result;
}
result = 1LL;
}
return result;
}

original_code:
char svgIsCommand( char c )
{
 int i;
 for( i = 0; g_atPathCommandFormat[ i ].cCommand!='\0'; i ++ ) {
  if( g_atPathCommandFormat[ i].cCommand==c )
   return 1;
 }
 return 0;
}

canonical_original_code:
char svgIsCommand(char c)
{
 int i;
 for( i = 0; g_atPathCommandFormat[ i ].cCommand!='\0'; i ++ ) {
  if( g_atPathCommandFormat[ i].cCommand==c )
   return 1;
 }
 return 0;
}

variable_types: c char

variable_types: i int

return_type: char


svgGetNextPathField

decompiled_code:
const char *__fastcall svgGetNextPathField(char *a1, char *a2, int a3)
{
char *v3; // r14
char *v5; // rax
const char *v6; // rbx
char v7; // r13
char *v8; // rdi
char *v9; // rax
char *v10; // r13
signed __int64 v11; // r13
char *v13; // rax

v3 = &a1[a3 - 1];
if ( !a1 || !a2 )
return 0LL;
*a2 = 0;
v5 = svgSkipWS(a1, &a1[a3 - 1]);
v6 = v5;
if ( v3 == v5 )
return 0LL;
v7 = *v5;
if ( !*v5 )
return 0LL;
if ( v7 == 44 )
{
v13 = svgSkipWS(v5 + 1, v3);
v6 = v13;
if ( v3 == v13 )
return 0LL;
if ( !*v13 )
return 0LL;
}
else if ( (unsigned __int8)svgIsCommand(v7) )
{
*a2 = v7;
a2[1] = 0;
return v6;
}
v8 = (char *)(v6 + 1);
if ( ((*v6 - 43) & 0xFD) != 0 )
v8 = (char *)v6;
v9 = svgSkipDigits(v8, v3);
v10 = v9;
if ( v3 != v9 && *v9 == 46 )
v10 = svgSkipDigits(v9 + 1, v3);
v11 = v10 - v6;
if ( v11 >= a3 )
_assert_fail("szEnd - szStart < n", "svg_string.c", 0x32u, "svgGetNextPathField");
strncpy(a2, v6, v11);
a2[v11] = 0;
return v6;
}

canonical_decompiled_code:
const char *__fastcall func3(char *a1, char *a2, int a3)
{
char *v3; // r14
char *v5; // rax
const char *v6; // rbx
char v7; // r13
char *v8; // rdi
char *v9; // rax
char *v10; // r13
signed __int64 v11; // r13
char *v13; // rax

v3 = &a1[a3 - 1];
if ( !a1 || !a2 )
return 0LL;
*a2 = 0;
v5 = func1(a1, &a1[a3 - 1]);
v6 = v5;
if ( v3 == v5 )
return 0LL;
v7 = *v5;
if ( !*v5 )
return 0LL;
if ( v7 == 44 )
{
v13 = func1(v5 + 1, v3);
v6 = v13;
if ( v3 == v13 )
return 0LL;
if ( !*v13 )
return 0LL;
}
else if ( (unsigned __int8)func0(v7) )
{
*a2 = v7;
a2[1] = 0;
return v6;
}
v8 = (char *)(v6 + 1);
if ( ((*v6 - 43) & 0xFD) != 0 )
v8 = (char *)v6;
v9 = func2(v8, v3);
v10 = v9;
if ( v3 != v9 && *v9 == 46 )
v10 = func2(v9 + 1, v3);
v11 = v10 - v6;
if ( v11 >= a3 )
_assert_fail("szEnd - szStart < n", "svg_string.c", 0x32u, "svgGetNextPathField");
strncpy(a2, v6, v11);
a2[v11] = 0;
return v6;
}

original_code:
const char* svgGetNextPathField( const char *szData, char *szField, int n )
{
 const char *szStart = ((void *)0), *szEnd = ((void *)0), *szEOF = szData + n - 1;
 if( szData==((void *)0) || szField==((void *)0) )
  return ((void *)0);
 szField[ 0 ] = '\0';
 szStart = szData;
 szStart = svgSkipWS(szStart, szEOF);
 if( szStart==szEOF || *szStart=='\0' )
  return ((void *)0);
 if ( *szStart==',' ) {
  szStart ++;
  szStart = svgSkipWS(szStart, szEOF);
  if( szStart==szEOF || *szStart=='\0' )
   return ((void *)0);
 } else if ( svgIsCommand( *szStart ) ) {
  szField[ 0 ] = *szStart;
  szField[ 1 ] = 0;
  return szStart;
 }
 szEnd = szStart;
 if (szEnd != szEOF && ( *szEnd=='-' || *szEnd =='+' ) )
  szEnd ++;
 szEnd = svgSkipDigits( szEnd, szEOF );
 if (szEnd != szEOF && *szEnd == '.') {
  szEnd ++;
  szEnd = svgSkipDigits( szEnd, szEOF );
 }
 ((void) sizeof ((szEnd - szStart < n) ? 1 : 0), __extension__ ({ if (szEnd - szStart < n) ; else __assert_fail ("szEnd - szStart < n", "svg_string.c", 50, __extension__ __PRETTY_FUNCTION__); }));
 strncpy( szField, szStart, ( size_t )( szEnd - szStart ) );
 szField[ szEnd - szStart ] = 0;
 return szStart;
}

canonical_original_code:
char *svgGetNextPathField(char *szData, char *szField, int n)
{
 char *szStart = ((void *)0); char *szEnd = ((void *)0); char *szEOF = szData + n - 1;
 if( szData==((void *)0) || szField==((void *)0) )
  return ((void *)0);
 szField[ 0 ] = '\0';
 szStart = szData;
 szStart = svgSkipWS(szStart, szEOF);
 if( szStart==szEOF || *szStart=='\0' )
  return ((void *)0);
 if ( *szStart==',' ) {
  szStart ++;
  szStart = svgSkipWS(szStart, szEOF);
  if( szStart==szEOF || *szStart=='\0' )
   return ((void *)0);
 } else if ( svgIsCommand( *szStart ) ) {
  szField[ 0 ] = *szStart;
  szField[ 1 ] = 0;
  return szStart;
 }
 szEnd = szStart;
 if (szEnd != szEOF && ( *szEnd=='-' || *szEnd =='+' ) )
  szEnd ++;
 szEnd = svgSkipDigits( szEnd, szEOF );
 if (szEnd != szEOF && *szEnd == '.') {
  szEnd ++;
  szEnd = svgSkipDigits( szEnd, szEOF );
 }
 ((void) sizeof ((szEnd - szStart < n) ? 1 : 0), __extension__ ({ if (szEnd - szStart < n) ; else __assert_fail ("szEnd - szStart < n", "svg_string.c", 50, __extension__ __PRETTY_FUNCTION__); }));
 strncpy( szField, szStart, ( unsigned long )( szEnd - szStart ) );
 szField[ szEnd - szStart ] = 0;
 return szStart;
}

variable_types:
szData
char *

variable_types:
szField
char *

variable_types: n int

variable_types:
szStart
char *

variable_types:
szEnd
char *

variable_types:
szEOF
char *

return_type: char *


svgGetNextPointField

decompiled_code:
char *__fastcall svgGetNextPointField(char *a1, char *a2, int a3)
{
char *v3; // r14
char *v5; // rax
char *v6; // rbx
char v7; // al
char *v8; // rdi
char *v9; // rax
char *v10; // r13
signed __int64 v11; // r13
char *v13; // rax

v3 = &a1[a3 - 1];
if ( !a1 || !a2 )
return 0LL;
*a2 = 0;
v5 = svgSkipWS(a1, &a1[a3 - 1]);
v6 = v5;
if ( v3 == v5 )
return 0LL;
v7 = *v5;
if ( !v7 )
return 0LL;
if ( v7 != 44 )
goto LABEL_6;
v13 = svgSkipWS(v6 + 1, v3);
v6 = v13;
if ( v3 == v13 )
return 0LL;
if ( !*v13 )
return 0LL;
LABEL_6:
v8 = v6 + 1;
if ( ((*v6 - 43) & 0xFD) != 0 )
v8 = v6;
v9 = svgSkipDigits(v8, v3);
v10 = v9;
if ( v3 != v9 && *v9 == 46 )
v10 = svgSkipDigits(v9 + 1, v3);
v11 = v10 - v6;
if ( v11 >= a3 )
_assert_fail("szEnd - szStart < n", "svg_string.c", 0x5Au, "svgGetNextPointField");
strncpy(a2, v6, v11);
a2[v11] = 0;
return v6;
}

canonical_decompiled_code:
char *__fastcall func4(char *a1, char *a2, int a3)
{
char *v3; // r14
char *v5; // rax
char *v6; // rbx
char v7; // al
char *v8; // rdi
char *v9; // rax
char *v10; // r13
signed __int64 v11; // r13
char *v13; // rax

v3 = &a1[a3 - 1];
if ( !a1 || !a2 )
return 0LL;
*a2 = 0;
v5 = func1(a1, &a1[a3 - 1]);
v6 = v5;
if ( v3 == v5 )
return 0LL;
v7 = *v5;
if ( !v7 )
return 0LL;
if ( v7 != 44 )
goto LABEL_6;
v13 = func1(v6 + 1, v3);
v6 = v13;
if ( v3 == v13 )
return 0LL;
if ( !*v13 )
return 0LL;
LABEL_6:
v8 = v6 + 1;
if ( ((*v6 - 43) & 0xFD) != 0 )
v8 = v6;
v9 = func2(v8, v3);
v10 = v9;
if ( v3 != v9 && *v9 == 46 )
v10 = func2(v9 + 1, v3);
v11 = v10 - v6;
if ( v11 >= a3 )
_assert_fail("szEnd - szStart < n", "svg_string.c", 0x5Au, "svgGetNextPointField");
strncpy(a2, v6, v11);
a2[v11] = 0;
return v6;
}

original_code:
const char* svgGetNextPointField( const char *szData, char *szField, int n )
{
 const char *szStart = ((void *)0), *szEnd = ((void *)0), *szEOF = szData + n - 1;
 if( szData==((void *)0) || szField==((void *)0) )
  return ((void *)0);
 szField[ 0 ] = '\0';
 szStart = szData;
 szStart = svgSkipWS(szStart, szEOF);
 if( szStart==szEOF || *szStart=='\0' )
  return ((void *)0);
 if ( *szStart==',' ) {
  szStart ++;
  szStart = svgSkipWS(szStart, szEOF);
  if( szStart==szEOF || *szStart=='\0' )
   return ((void *)0);
 }
 szEnd = szStart;
 if (szEnd != szEOF && ( *szEnd=='-' || *szEnd =='+' ) )
  szEnd ++;
 szEnd = svgSkipDigits( szEnd, szEOF );
 if (szEnd != szEOF && *szEnd == '.') {
  szEnd ++;
  szEnd = svgSkipDigits( szEnd, szEOF );
 }
 ((void) sizeof ((szEnd - szStart < n) ? 1 : 0), __extension__ ({ if (szEnd - szStart < n) ; else __assert_fail ("szEnd - szStart < n", "svg_string.c", 90, __extension__ __PRETTY_FUNCTION__); }));
 strncpy( szField, szStart, ( size_t )( szEnd - szStart ) );
 szField[ szEnd - szStart ] = 0;
 return szStart;
}

canonical_original_code:
char *svgGetNextPointField(char *szData, char *szField, int n)
{
 char *szStart = ((void *)0); char *szEnd = ((void *)0); char *szEOF = szData + n - 1;
 if( szData==((void *)0) || szField==((void *)0) )
  return ((void *)0);
 szField[ 0 ] = '\0';
 szStart = szData;
 szStart = svgSkipWS(szStart, szEOF);
 if( szStart==szEOF || *szStart=='\0' )
  return ((void *)0);
 if ( *szStart==',' ) {
  szStart ++;
  szStart = svgSkipWS(szStart, szEOF);
  if( szStart==szEOF || *szStart=='\0' )
   return ((void *)0);
 }
 szEnd = szStart;
 if (szEnd != szEOF && ( *szEnd=='-' || *szEnd =='+' ) )
  szEnd ++;
 szEnd = svgSkipDigits( szEnd, szEOF );
 if (szEnd != szEOF && *szEnd == '.') {
  szEnd ++;
  szEnd = svgSkipDigits( szEnd, szEOF );
 }
 ((void) sizeof ((szEnd - szStart < n) ? 1 : 0), __extension__ ({ if (szEnd - szStart < n) ; else __assert_fail ("szEnd - szStart < n", "svg_string.c", 90, __extension__ __PRETTY_FUNCTION__); }));
 strncpy( szField, szStart, ( unsigned long )( szEnd - szStart ) );
 szField[ szEnd - szStart ] = 0;
 return szStart;
}


svgIsRealNumber

decompiled_code:
bool __fastcall svgIsRealNumber(_BYTE *a1)
{
char *v1; // rax

if ( !a1 )
return 0;
v1 = svgSkipDigits(&a1[((*a1 - 43) & 0xFD) == 0], 0LL);
if ( *v1 == 46 )
v1 = svgSkipDigits(v1 + 1, 0LL);
return *v1 == 0;
}

original_code:
char svgIsRealNumber( const char *szString )
{
 if( szString==((void *)0) )
  return 0;
 if ( *szString=='-' || *szString =='+' )
  szString ++;
 szString = svgSkipDigits( szString, ((void *)0) );
 if (*szString == '.') {
  szString ++;
  szString = svgSkipDigits( szString, ((void *)0) );
 }
 if( *szString=='\0' )
  return 1;
 return 0;
}

canonical_original_code:
char svgIsRealNumber(char *szString)
{
 if( szString==((void *)0) )
  return 0;
 if ( *szString=='-' || *szString =='+' )
  szString ++;
 szString = svgSkipDigits( szString, ((void *)0) );
 if (*szString == '.') {
  szString ++;
  szString = svgSkipDigits( szString, ((void *)0) );
 }
 if( *szString=='\0' )
  return 1;
 return 0;
}

variable_types:
szString
char *


svgSetLastError

decompiled_code:
__int64 svgSetLastError(unsigned int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( a2 )
{
va_start(arg, a2);
vsprintf(g_szLastErrorDesc, a2, arg);
}
else
{
g_szLastErrorDesc[0] = 0;
}
g_tLastError = a1;
return a1;
}

canonical_decompiled_code:
__int64 func0(unsigned int a1, const char *a2, ...)
{
gcc_va_list arg; // [rsp+8h] [rbp-D0h] BYREF

if ( a2 )
{
va_start(arg, a2);
vsprintf(g_szLastErrorDesc, a2, arg);
}
else
{
g_szLastErrorDesc[0] = 0;
}
g_tLastError = a1;
return a1;
}

original_code:
svgError svgSetLastError( svgError tError, const char *szDesc, ... )
{
 va_list tVaList;
 if( szDesc!=((void *)0) ) {
  __builtin_va_start(tVaList,szDesc);
  vsprintf( g_szLastErrorDesc, szDesc, tVaList );
  __builtin_va_end(tVaList);
 }
 else
  g_szLastErrorDesc[ 0 ] = '\0';
 g_tLastError = tError;
 return tError;
}

canonical_original_code:
enum _svgError svgSetLastError(enum _svgError tError, char *szDesc, ...)
{
 __builtin_va_list tVaList;
 if( szDesc!=((void *)0) ) {
  __builtin_va_start(tVaList,szDesc);
  vsprintf( g_szLastErrorDesc, szDesc, tVaList );
  __builtin_va_end(tVaList);
 }
 else
  g_szLastErrorDesc[ 0 ] = '\0';
 g_tLastError = tError;
 return tError;
}

variable_types: enum _svgError { SVG_ERR_SUCCESS=0, SVG_ERR_INVALID_PARAMETER=1, SVG_ERR_NO_SUCH_FILE=2, SVG_ERR_BAD_FILE_FORMAT=3, SVG_ERR_NOT_ENOUGH_RAM=4 }

variable_types:
szDesc
char *


svgGetLastError

decompiled_code:
__int64 svgGetLastError()
{
return (unsigned int)g_tLastError;
}

canonical_decompiled_code:
__int64 func1()
{
return (unsigned int)g_tLastError;
}

original_code:
svgError svgGetLastError( void )
{
 return g_tLastError;
}

canonical_original_code:
enum _svgError svgGetLastError()
{
 return g_tLastError;
}

return_type: enum _svgError { SVG_ERR_SUCCESS=0, SVG_ERR_INVALID_PARAMETER=1, SVG_ERR_NO_SUCH_FILE=2, SVG_ERR_BAD_FILE_FORMAT=3, SVG_ERR_NOT_ENOUGH_RAM=4 }


svgGetLastErrorDescription

decompiled_code:
char *svgGetLastErrorDescription()
{
return g_szLastErrorDesc;
}

canonical_decompiled_code:
char *func2()
{
return g_szLastErrorDesc;
}

original_code:
char* svgGetLastErrorDescription( void )
{
 return g_szLastErrorDesc;
}


svgFreeItem

decompiled_code:
void __fastcall svgFreeItem(void *ptr)
{
void *v2; // rdi
_QWORD *v3; // rbp
void *v4; // rdi
_QWORD *v5; // rbp
void *v6; // rdi
_QWORD *v7; // rbp
void *v8; // rdi
void *v9; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
switch ( *(_DWORD *)ptr )
{
case 1:
v3 = (_QWORD *)*((_QWORD *)ptr + 7);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[8];
free(v4);
}
break;
case 6:
v5 = (_QWORD *)*((_QWORD *)ptr + 9);
while ( v5 )
{
v6 = v5;
v5 = (_QWORD *)v5[2];
free(v6);
}
break;
case 7:
v7 = (_QWORD *)*((_QWORD *)ptr + 9);
while ( v7 )
{
v8 = v7;
v7 = (_QWORD *)v7[2];
free(v8);
}
break;
case 8:
v9 = (void *)*((_QWORD *)ptr + 7);
if ( v9 )
goto LABEL_15;
break;
case 9:
v9 = (void *)*((_QWORD *)ptr + 7);
if ( v9 )
LABEL_15:
free(v9);
break;
default:
break;
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
void *v2; // rdi
_QWORD *v3; // rbp
void *v4; // rdi
_QWORD *v5; // rbp
void *v6; // rdi
_QWORD *v7; // rbp
void *v8; // rdi
void *v9; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
switch ( *(_DWORD *)ptr )
{
case 1:
v3 = (_QWORD *)*((_QWORD *)ptr + 7);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[8];
free(v4);
}
break;
case 6:
v5 = (_QWORD *)*((_QWORD *)ptr + 9);
while ( v5 )
{
v6 = v5;
v5 = (_QWORD *)v5[2];
free(v6);
}
break;
case 7:
v7 = (_QWORD *)*((_QWORD *)ptr + 9);
while ( v7 )
{
v8 = v7;
v7 = (_QWORD *)v7[2];
free(v8);
}
break;
case 8:
v9 = (void *)*((_QWORD *)ptr + 7);
if ( v9 )
goto LABEL_15;
break;
case 9:
v9 = (void *)*((_QWORD *)ptr + 7);
if ( v9 )
LABEL_15:
free(v9);
break;
default:
break;
}
free(ptr);
}
}

original_code:
void svgFreeItem( svgItem *ptItem )
{
 svgPathCommand *ptPathCmd, *ptNextPathCmd;
 svgPoint *ptPoint, *ptNextPoint;
 if( ptItem==((void *)0) )
  return;
 if( ptItem->szId!=((void *)0) )
  free( ptItem->szId );
 switch( ptItem->tKind )
 {
  case SVG_ITEM_KIND_GROUP:
   break;
  case SVG_ITEM_KIND_PATH:
   ptPathCmd = ptItem->tParameters.tPath.ptFirstCommand;
   while( ptPathCmd!=((void *)0) ) {
    ptNextPathCmd = ptPathCmd->ptNextCommand;
    free( ptPathCmd );
    ptPathCmd = ptNextPathCmd;
   }
   break;
  case SVG_ITEM_KIND_RECT:
   break;
  case SVG_ITEM_KIND_CIRCLE:
   break;
  case SVG_ITEM_KIND_ELLIPSE:
   break;
  case SVG_ITEM_KIND_LINE:
   break;
  case SVG_ITEM_KIND_POLYLINE:
   ptPoint = ptItem->tParameters.tPolyline.tFirstPoint.ptNextPoint;
   while( ptPoint!=((void *)0) ) {
    ptNextPoint = ptPoint->ptNextPoint;
    free( ptPoint );
    ptPoint = ptNextPoint;
   }
   break;
  case SVG_ITEM_KIND_POLYGON:
   ptPoint = ptItem->tParameters.tPolygon.tFirstPoint.ptNextPoint;
   while( ptPoint!=((void *)0) ) {
    ptNextPoint = ptPoint->ptNextPoint;
    free( ptPoint );
    ptPoint = ptNextPoint;
   }
   break;
  case SVG_ITEM_KIND_TITLE:
   if( ptItem->tParameters.tTitle.szText!=((void *)0) )
    free( ptItem->tParameters.tTitle.szText );
   break;
  case SVG_ITEM_KIND_DESC:
   if( ptItem->tParameters.tTitle.szText!=((void *)0) )
    free( ptItem->tParameters.tDesc.szText );
   break;
 }
 free( ptItem );
}

canonical_original_code:
void svgFreeItem(struct _svgItem *ptItem)
{
 struct _svgPathCommand *ptPathCmd; struct _svgPathCommand *ptNextPathCmd;
 struct _svgPoint *ptPoint; struct _svgPoint *ptNextPoint;
 if( ptItem==((void *)0) )
  return;
 if( ptItem->szId!=((void *)0) )
  free( ptItem->szId );
 switch( ptItem->tKind )
 {
  case SVG_ITEM_KIND_GROUP:
   break;
  case SVG_ITEM_KIND_PATH:
   ptPathCmd = ptItem->tParameters.tPath.ptFirstCommand;
   while( ptPathCmd!=((void *)0) ) {
    ptNextPathCmd = ptPathCmd->ptNextCommand;
    free( ptPathCmd );
    ptPathCmd = ptNextPathCmd;
   }
   break;
  case SVG_ITEM_KIND_RECT:
   break;
  case SVG_ITEM_KIND_CIRCLE:
   break;
  case SVG_ITEM_KIND_ELLIPSE:
   break;
  case SVG_ITEM_KIND_LINE:
   break;
  case SVG_ITEM_KIND_POLYLINE:
   ptPoint = ptItem->tParameters.tPolyline.tFirstPoint.ptNextPoint;
   while( ptPoint!=((void *)0) ) {
    ptNextPoint = ptPoint->ptNextPoint;
    free( ptPoint );
    ptPoint = ptNextPoint;
   }
   break;
  case SVG_ITEM_KIND_POLYGON:
   ptPoint = ptItem->tParameters.tPolygon.tFirstPoint.ptNextPoint;
   while( ptPoint!=((void *)0) ) {
    ptNextPoint = ptPoint->ptNextPoint;
    free( ptPoint );
    ptPoint = ptNextPoint;
   }
   break;
  case SVG_ITEM_KIND_TITLE:
   if( ptItem->tParameters.tTitle.szText!=((void *)0) )
    free( ptItem->tParameters.tTitle.szText );
   break;
  case SVG_ITEM_KIND_DESC:
   if( ptItem->tParameters.tTitle.szText!=((void *)0) )
    free( ptItem->tParameters.tDesc.szText );
   break;
 }
 free( ptItem );
}

variable_types: struct _svgItem { enum _svgItemKind { SVG_ITEM_KIND_GROUP=0, SVG_ITEM_KIND_PATH=1, SVG_ITEM_KIND_RECT=2, SVG_ITEM_KIND_CIRCLE=3, SVG_ITEM_KIND_ELLIPSE=4, SVG_ITEM_KIND_LINE=5, SVG_ITEM_KIND_POLYLINE=6, SVG_ITEM_KIND_POLYGON=7, SVG_ITEM_KIND_TITLE=8, SVG_ITEM_KIND_DESC=9 } tKind; char *szId; struct _svgItem *ptParent; struct _svgItem *ptFirstChild; struct _svgItem *ptLastChild; struct _svgItem *ptNextItem; struct _svgItem *ptNextUnsortedItem; union { struct _svgTitle { char *szText; } tTitle; struct _svgDesc { char *szText; } tDesc; struct _svgLine { struct _svgLength { enum _svgLengthUnit { SVG_LENGTH_UNIT_NONE=0, SVG_LENGTH_UNIT_PX=1, SVG_LENGTH_UNIT_EM=2, SVG_LENGTH_UNIT_EX=3, SVG_LENGTH_UNIT_IN=4, SVG_LENGTH_UNIT_CM=5, SVG_LENGTH_UNIT_MM=6, SVG_LENGTH_UNIT_PT=7, SVG_LENGTH_UNIT_PC=8, SVG_LENGTH_UNIT_PERCENT=9 } tUnit; float fValue; } tX1; struct _svgLength tY1; struct _svgLength tX2; struct _svgLength tY2; } tLine; struct _svgRect { struct _svgLength tX; struct _svgLength tY; struct _svgLength tWidth; struct _svgLength tHeight; struct _svgLength tRadiusX; struct _svgLength tRadiusY; } tRect; struct _svgCircle { struct _svgLength tX; struct _svgLength tY; struct _svgLength tRadius; } tCircle; struct _svgPath { struct _svgPathCommand { enum _svgPathCommandId { SVG_PATH_CMD_ID_MOVETO_ABS=0, SVG_PATH_CMD_ID_MOVETO_REL=1, SVG_PATH_CMD_ID_LINETO_ABS=2, SVG_PATH_CMD_ID_LINETO_REL=3, SVG_PATH_CMD_ID_VERTICAL_LINETO_ABS=4, SVG_PATH_CMD_ID_VERTICAL_LINETO_REL=5, SVG_PATH_CMD_ID_HORIZONTAL_LINETO_ABS=6, SVG_PATH_CMD_ID_HORIZONTAL_LINETO_REL=7, SVG_PATH_CMD_ID_CUBIC_CURVETO_ABS=8, SVG_PATH_CMD_ID_CUBIC_CURVETO_REL=9, SVG_PATH_CMD_ID_SMOOTH_CUBIC_CURVETO_ABS=10, SVG_PATH_CMD_ID_SMOOTH_CUBIC_CURVETO_REL=11, SVG_PATH_CMD_ID_QUADRATIC_CURVETO_ABS=12, SVG_PATH_CMD_ID_QUADRATIC_CURVETO_REL=13, SVG_PATH_CMD_ID_SMOOTH_QUADRATIC_CURVETO_ABS=14, SVG_PATH_CMD_ID_SMOOTH_QUADRATIC_CURVETO_REL=15, SVG_PATH_CMD_ID_ARCTO_ABS=16, SVG_PATH_CMD_ID_ARCTO_REL=17, SVG_PATH_CMD_ID_CLOSEPATH=18, SVG_PATH_CMD_ID_END_OF_ENUM=19 } tId; union { struct _svgPathCommand_MoveTo { struct _svgLength tX; struct _svgLength tY; } tMoveTo; struct _svgPathCommand_Lineto { struct _svgLength tX; struct _svgLength tY; } tLineTo; struct _svgPathCommand_CubicCurveTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tX1; struct _svgLength tY1; struct _svgLength tX2; struct _svgLength tY2; } tCubicCurveTo; struct _svgPathCommand_SmoothCubicCurveTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tX2; struct _svgLength tY2; } tSmoothCubicCurveTo; struct _svgPathCommand_QuadraticCurveTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tX1; struct _svgLength tY1; } tQuadraticCurveTo; struct _svgPathCommand_SmoothQuadraticCurveTo { struct _svgLength tX; struct _svgLength tY; } tSmoothQuadraticCurveTo; struct _svgPathCommand_ArcTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tRadiusX; struct _svgLength tRadiusY; struct _svgLength tXAxisAngle; struct _svgLength tLargeArcFlag; struct _svgLength tSweepFlag; } tArcTo; } tParameters; struct _svgPathCommand *ptNextCommand; } *ptFirstCommand; } tPath; struct _svgEllipse { struct _svgLength tX; struct _svgLength tY; struct _svgLength tRadiusX; struct _svgLength tRadiusY; } tEllipse; struct _svgPolyline { struct _svgPoint { struct _svgLength tX; struct _svgLength tY; struct _svgPoint *ptNextPoint; } tFirstPoint; } tPolyline; struct _svgPolygon { struct _svgPoint tFirstPoint; } tPolygon; } tParameters; } *

variable_types: struct _svgPathCommand { enum _svgPathCommandId { SVG_PATH_CMD_ID_MOVETO_ABS=0, SVG_PATH_CMD_ID_MOVETO_REL=1, SVG_PATH_CMD_ID_LINETO_ABS=2, SVG_PATH_CMD_ID_LINETO_REL=3, SVG_PATH_CMD_ID_VERTICAL_LINETO_ABS=4, SVG_PATH_CMD_ID_VERTICAL_LINETO_REL=5, SVG_PATH_CMD_ID_HORIZONTAL_LINETO_ABS=6, SVG_PATH_CMD_ID_HORIZONTAL_LINETO_REL=7, SVG_PATH_CMD_ID_CUBIC_CURVETO_ABS=8, SVG_PATH_CMD_ID_CUBIC_CURVETO_REL=9, SVG_PATH_CMD_ID_SMOOTH_CUBIC_CURVETO_ABS=10, SVG_PATH_CMD_ID_SMOOTH_CUBIC_CURVETO_REL=11, SVG_PATH_CMD_ID_QUADRATIC_CURVETO_ABS=12, SVG_PATH_CMD_ID_QUADRATIC_CURVETO_REL=13, SVG_PATH_CMD_ID_SMOOTH_QUADRATIC_CURVETO_ABS=14, SVG_PATH_CMD_ID_SMOOTH_QUADRATIC_CURVETO_REL=15, SVG_PATH_CMD_ID_ARCTO_ABS=16, SVG_PATH_CMD_ID_ARCTO_REL=17, SVG_PATH_CMD_ID_CLOSEPATH=18, SVG_PATH_CMD_ID_END_OF_ENUM=19 } tId; union { struct _svgPathCommand_MoveTo { struct _svgLength { enum _svgLengthUnit { SVG_LENGTH_UNIT_NONE=0, SVG_LENGTH_UNIT_PX=1, SVG_LENGTH_UNIT_EM=2, SVG_LENGTH_UNIT_EX=3, SVG_LENGTH_UNIT_IN=4, SVG_LENGTH_UNIT_CM=5, SVG_LENGTH_UNIT_MM=6, SVG_LENGTH_UNIT_PT=7, SVG_LENGTH_UNIT_PC=8, SVG_LENGTH_UNIT_PERCENT=9 } tUnit; float fValue; } tX; struct _svgLength tY; } tMoveTo; struct _svgPathCommand_Lineto { struct _svgLength tX; struct _svgLength tY; } tLineTo; struct _svgPathCommand_CubicCurveTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tX1; struct _svgLength tY1; struct _svgLength tX2; struct _svgLength tY2; } tCubicCurveTo; struct _svgPathCommand_SmoothCubicCurveTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tX2; struct _svgLength tY2; } tSmoothCubicCurveTo; struct _svgPathCommand_QuadraticCurveTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tX1; struct _svgLength tY1; } tQuadraticCurveTo; struct _svgPathCommand_SmoothQuadraticCurveTo { struct _svgLength tX; struct _svgLength tY; } tSmoothQuadraticCurveTo; struct _svgPathCommand_ArcTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tRadiusX; struct _svgLength tRadiusY; struct _svgLength tXAxisAngle; struct _svgLength tLargeArcFlag; struct _svgLength tSweepFlag; } tArcTo; } tParameters; struct _svgPathCommand *ptNextCommand; } *

variable_types: struct _svgPoint { struct _svgLength { enum _svgLengthUnit { SVG_LENGTH_UNIT_NONE=0, SVG_LENGTH_UNIT_PX=1, SVG_LENGTH_UNIT_EM=2, SVG_LENGTH_UNIT_EX=3, SVG_LENGTH_UNIT_IN=4, SVG_LENGTH_UNIT_CM=5, SVG_LENGTH_UNIT_MM=6, SVG_LENGTH_UNIT_PT=7, SVG_LENGTH_UNIT_PC=8, SVG_LENGTH_UNIT_PERCENT=9 } tUnit; float fValue; } tX; struct _svgLength tY; struct _svgPoint *ptNextPoint; } *

user_defined_types: struct _svgItem { enum _svgItemKind tKind; char *szId; struct _svgItem *ptParent; struct _svgItem *ptFirstChild; struct _svgItem *ptLastChild; struct _svgItem *ptNextItem; struct _svgItem *ptNextUnsortedItem; union { struct _svgTitle tTitle; struct _svgDesc tDesc; struct _svgLine tLine; struct _svgRect tRect; struct _svgCircle tCircle; struct _svgPath tPath; struct _svgEllipse tEllipse; struct _svgPolyline tPolyline; struct _svgPolygon tPolygon; } tParameters; }

user_defined_types: struct _svgPathCommand { enum _svgPathCommandId tId; union { struct _svgPathCommand_MoveTo tMoveTo; struct _svgPathCommand_Lineto tLineTo; struct _svgPathCommand_CubicCurveTo tCubicCurveTo; struct _svgPathCommand_SmoothCubicCurveTo tSmoothCubicCurveTo; struct _svgPathCommand_QuadraticCurveTo tQuadraticCurveTo; struct _svgPathCommand_SmoothQuadraticCurveTo tSmoothQuadraticCurveTo; struct _svgPathCommand_ArcTo tArcTo; } tParameters; struct _svgPathCommand *ptNextCommand; }

user_defined_types: struct _svgLength { enum _svgLengthUnit tUnit; float fValue; }

user_defined_types: struct _svgLine { struct _svgLength tX1; struct _svgLength tY1; struct _svgLength tX2; struct _svgLength tY2; }

user_defined_types: struct _svgPath { struct _svgPathCommand *ptFirstCommand; }

user_defined_types: struct _svgPolyline { struct _svgPoint tFirstPoint; }


svgFreeDrawing

decompiled_code:
void __fastcall svgFreeDrawing(void *ptr)
{
void *v2; // rdi
_QWORD *v3; // rbx
void *v4; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
v3 = (_QWORD *)*((_QWORD *)ptr + 6);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[6];
svgFreeItem(v4);
}
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func2(void *ptr)
{
void *v2; // rdi
_QWORD *v3; // rbx
void *v4; // rdi

if ( ptr )
{
v2 = (void *)*((_QWORD *)ptr + 1);
if ( v2 )
free(v2);
if ( *(_QWORD *)ptr )
free(*(void **)ptr);
v3 = (_QWORD *)*((_QWORD *)ptr + 6);
while ( v3 )
{
v4 = v3;
v3 = (_QWORD *)v3[6];
func1(v4);
}
free(ptr);
}
}

original_code:
void svgFreeDrawing( svgDrawing *ptDrawing )
{
 svgItem *ptItem, *ptNextItem;
 if( ptDrawing==((void *)0) )
  return;
 if( ptDrawing->szId!=((void *)0) )
  free( ptDrawing->szId );
 if( ptDrawing->szVersion!=((void *)0) )
  free( ptDrawing->szVersion );
 ptItem = ptDrawing->tItemList.ptItem;
 while( ptItem!=((void *)0) ){
  ptNextItem = ptItem->ptNextUnsortedItem;
  svgFreeItem( ptItem );
  ptItem = ptNextItem;
 }
 free( ptDrawing );
}

canonical_original_code:
void svgFreeDrawing(struct _svgDrawing *ptDrawing)
{
 struct _svgItem *ptItem; struct _svgItem *ptNextItem;
 if( ptDrawing==((void *)0) )
  return;
 if( ptDrawing->szId!=((void *)0) )
  free( ptDrawing->szId );
 if( ptDrawing->szVersion!=((void *)0) )
  free( ptDrawing->szVersion );
 ptItem = ptDrawing->tItemList.ptItem;
 while( ptItem!=((void *)0) ){
  ptNextItem = ptItem->ptNextUnsortedItem;
  svgFreeItem( ptItem );
  ptItem = ptNextItem;
 }
 free( ptDrawing );
}

variable_types: struct _svgDrawing { char *szVersion; char *szId; struct _svgLength { enum _svgLengthUnit { SVG_LENGTH_UNIT_NONE=0, SVG_LENGTH_UNIT_PX=1, SVG_LENGTH_UNIT_EM=2, SVG_LENGTH_UNIT_EX=3, SVG_LENGTH_UNIT_IN=4, SVG_LENGTH_UNIT_CM=5, SVG_LENGTH_UNIT_MM=6, SVG_LENGTH_UNIT_PT=7, SVG_LENGTH_UNIT_PC=8, SVG_LENGTH_UNIT_PERCENT=9 } tUnit; float fValue; } tX; struct _svgLength tY; struct _svgLength tWidth; struct _svgLength tHeight; struct _svgItemList { struct _svgItem { enum _svgItemKind { SVG_ITEM_KIND_GROUP=0, SVG_ITEM_KIND_PATH=1, SVG_ITEM_KIND_RECT=2, SVG_ITEM_KIND_CIRCLE=3, SVG_ITEM_KIND_ELLIPSE=4, SVG_ITEM_KIND_LINE=5, SVG_ITEM_KIND_POLYLINE=6, SVG_ITEM_KIND_POLYGON=7, SVG_ITEM_KIND_TITLE=8, SVG_ITEM_KIND_DESC=9 } tKind; char *szId; struct _svgItem *ptParent; struct _svgItem *ptFirstChild; struct _svgItem *ptLastChild; struct _svgItem *ptNextItem; struct _svgItem *ptNextUnsortedItem; union { struct _svgTitle { char *szText; } tTitle; struct _svgDesc { char *szText; } tDesc; struct _svgLine { struct _svgLength tX1; struct _svgLength tY1; struct _svgLength tX2; struct _svgLength tY2; } tLine; struct _svgRect { struct _svgLength tX; struct _svgLength tY; struct _svgLength tWidth; struct _svgLength tHeight; struct _svgLength tRadiusX; struct _svgLength tRadiusY; } tRect; struct _svgCircle { struct _svgLength tX; struct _svgLength tY; struct _svgLength tRadius; } tCircle; struct _svgPath { struct _svgPathCommand { enum _svgPathCommandId { SVG_PATH_CMD_ID_MOVETO_ABS=0, SVG_PATH_CMD_ID_MOVETO_REL=1, SVG_PATH_CMD_ID_LINETO_ABS=2, SVG_PATH_CMD_ID_LINETO_REL=3, SVG_PATH_CMD_ID_VERTICAL_LINETO_ABS=4, SVG_PATH_CMD_ID_VERTICAL_LINETO_REL=5, SVG_PATH_CMD_ID_HORIZONTAL_LINETO_ABS=6, SVG_PATH_CMD_ID_HORIZONTAL_LINETO_REL=7, SVG_PATH_CMD_ID_CUBIC_CURVETO_ABS=8, SVG_PATH_CMD_ID_CUBIC_CURVETO_REL=9, SVG_PATH_CMD_ID_SMOOTH_CUBIC_CURVETO_ABS=10, SVG_PATH_CMD_ID_SMOOTH_CUBIC_CURVETO_REL=11, SVG_PATH_CMD_ID_QUADRATIC_CURVETO_ABS=12, SVG_PATH_CMD_ID_QUADRATIC_CURVETO_REL=13, SVG_PATH_CMD_ID_SMOOTH_QUADRATIC_CURVETO_ABS=14, SVG_PATH_CMD_ID_SMOOTH_QUADRATIC_CURVETO_REL=15, SVG_PATH_CMD_ID_ARCTO_ABS=16, SVG_PATH_CMD_ID_ARCTO_REL=17, SVG_PATH_CMD_ID_CLOSEPATH=18, SVG_PATH_CMD_ID_END_OF_ENUM=19 } tId; union { struct _svgPathCommand_MoveTo { struct _svgLength tX; struct _svgLength tY; } tMoveTo; struct _svgPathCommand_Lineto { struct _svgLength tX; struct _svgLength tY; } tLineTo; struct _svgPathCommand_CubicCurveTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tX1; struct _svgLength tY1; struct _svgLength tX2; struct _svgLength tY2; } tCubicCurveTo; struct _svgPathCommand_SmoothCubicCurveTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tX2; struct _svgLength tY2; } tSmoothCubicCurveTo; struct _svgPathCommand_QuadraticCurveTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tX1; struct _svgLength tY1; } tQuadraticCurveTo; struct _svgPathCommand_SmoothQuadraticCurveTo { struct _svgLength tX; struct _svgLength tY; } tSmoothQuadraticCurveTo; struct _svgPathCommand_ArcTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tRadiusX; struct _svgLength tRadiusY; struct _svgLength tXAxisAngle; struct _svgLength tLargeArcFlag; struct _svgLength tSweepFlag; } tArcTo; } tParameters; struct _svgPathCommand *ptNextCommand; } *ptFirstCommand; } tPath; struct _svgEllipse { struct _svgLength tX; struct _svgLength tY; struct _svgLength tRadiusX; struct _svgLength tRadiusY; } tEllipse; struct _svgPolyline { struct _svgPoint { struct _svgLength tX; struct _svgLength tY; struct _svgPoint *ptNextPoint; } tFirstPoint; } tPolyline; struct _svgPolygon { struct _svgPoint tFirstPoint; } tPolygon; } tParameters; } *ptItem; unsigned int ui32Count; } tItemList; } *

user_defined_types: struct _svgDrawing { char *szVersion; char *szId; struct _svgLength tX; struct _svgLength tY; struct _svgLength tWidth; struct _svgLength tHeight; struct _svgItemList tItemList; }

user_defined_types: struct _svgItemList { struct _svgItem *ptItem; unsigned int ui32Count; }


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rax
__int64 v4; // r13
__int64 v5; // r12
int v6; // ebp
const char *v7; // rbx
unsigned int v8; // eax
int result; // eax
int v10; // ebx
__int64 v11; // rax

if ( argc <= 1 )
return -1;
v3 = svgOpenFile(argv[1]);
v4 = v3;
if ( v3 )
{
printf("Nbr of items : %d\n", *(unsigned int *)(v3 + 56));
v5 = *(_QWORD *)(v4 + 48);
if ( v5 )
{
putchar(124);
v6 = 0;
while ( 1 )
{
printf("-%s\n", *(const char **)(v5 + 8));
if ( *(_QWORD *)(v5 + 24) )
{
++v6;
v5 = *(_QWORD *)(v5 + 24);
goto LABEL_8;
}
if ( *(_QWORD *)(v5 + 40) )
break;
v11 = *(_QWORD *)(v5 + 16);
if ( !v11 )
goto LABEL_15;
v5 = *(_QWORD *)(v11 + 40);
if ( v6 <= 0 )
{
if ( !v5 )
goto LABEL_15;
putchar(124);
}
else
{
--v6;
if ( !v5 )
goto LABEL_15;
LABEL_8:
putchar(124);
v10 = 0;
if ( v6 > 0 )
{
do
{
printf(" |");
++v10;
}
while ( v10 != v6 );
}
}
}
v5 = *(_QWORD *)(v5 + 40);
goto LABEL_8;
}
LABEL_15:
svgFreeDrawing(v4);
result = 0;
}
else
{
v7 = (const char *)svgGetLastErrorDescription();
v8 = svgGetLastError();
printf("ERROR(%d): %s.\n", v8, v7);
result = -1;
}
return result;
}

original_code:
int main( int iargc, char **argv )
{
 svgDrawing *ptSvg;
 svgItem *ptItem;
 int iLevel,j;
 if( iargc<2 )
  return -1;
 ptSvg = svgOpenFile( argv[ 1 ] );
 if( ptSvg==((void *)0) ) {
  printf( "ERROR(%d): %s.\n", svgGetLastError(), svgGetLastErrorDescription() );
  return -1;
 }
 printf( "Nbr of items : %d\n", ptSvg->tItemList.ui32Count );
 iLevel = 0;
 ptItem = ptSvg->tItemList.ptItem;
 while( ptItem!=((void *)0) )
 {
  printf( "|" );
  for( j=0; j<iLevel; j++ )
   printf( "  |" );
  printf( "-%s\n", ptItem->szId );
  if( ptItem->ptFirstChild!=((void *)0) ) {
   ptItem = ptItem->ptFirstChild;
   iLevel ++;
  }
  else {
   if( ptItem->ptNextItem!=((void *)0) )
    ptItem = ptItem->ptNextItem;
   else if( ptItem->ptParent!=((void *)0) ) {
    ptItem = ptItem->ptParent->ptNextItem;
    if( iLevel > 0 )
     iLevel --;
   }
   else
    ptItem = ((void *)0);
  }
 }
 svgFreeDrawing( ptSvg );
 return 0;
}

canonical_original_code:
int main(int iargc, char **argv)
{
 struct _svgDrawing *ptSvg;
 struct _svgItem *ptItem;
 int iLevel; int j;
 if( iargc<2 )
  return -1;
 ptSvg = svgOpenFile( argv[ 1 ] );
 if( ptSvg==((void *)0) ) {
  printf( "ERROR(%d): %s.\n", svgGetLastError(), svgGetLastErrorDescription() );
  return -1;
 }
 printf( "Nbr of items : %d\n", ptSvg->tItemList.ui32Count );
 iLevel = 0;
 ptItem = ptSvg->tItemList.ptItem;
 while( ptItem!=((void *)0) )
 {
  printf( "|" );
  for( j=0; j<iLevel; j++ )
   printf( "  |" );
  printf( "-%s\n", ptItem->szId );
  if( ptItem->ptFirstChild!=((void *)0) ) {
   ptItem = ptItem->ptFirstChild;
   iLevel ++;
  }
  else {
   if( ptItem->ptNextItem!=((void *)0) )
    ptItem = ptItem->ptNextItem;
   else if( ptItem->ptParent!=((void *)0) ) {
    ptItem = ptItem->ptParent->ptNextItem;
    if( iLevel > 0 )
     iLevel --;
   }
   else
    ptItem = ((void *)0);
  }
 }
 svgFreeDrawing( ptSvg );
 return 0;
}

variable_types: iargc int

variable_types:
argv
char **

variable_types: iLevel int

variable_types: j int

user_defined_types: enum _svgItemKind { SVG_ITEM_KIND_GROUP=0, SVG_ITEM_KIND_PATH=1, SVG_ITEM_KIND_RECT=2, SVG_ITEM_KIND_CIRCLE=3, SVG_ITEM_KIND_ELLIPSE=4, SVG_ITEM_KIND_LINE=5, SVG_ITEM_KIND_POLYLINE=6, SVG_ITEM_KIND_POLYGON=7, SVG_ITEM_KIND_TITLE=8, SVG_ITEM_KIND_DESC=9 }

user_defined_types: enum _svgLengthUnit { SVG_LENGTH_UNIT_NONE=0, SVG_LENGTH_UNIT_PX=1, SVG_LENGTH_UNIT_EM=2, SVG_LENGTH_UNIT_EX=3, SVG_LENGTH_UNIT_IN=4, SVG_LENGTH_UNIT_CM=5, SVG_LENGTH_UNIT_MM=6, SVG_LENGTH_UNIT_PT=7, SVG_LENGTH_UNIT_PC=8, SVG_LENGTH_UNIT_PERCENT=9 }

user_defined_types: struct _svgRect { struct _svgLength tX; struct _svgLength tY; struct _svgLength tWidth; struct _svgLength tHeight; struct _svgLength tRadiusX; struct _svgLength tRadiusY; }

user_defined_types: struct _svgCircle { struct _svgLength tX; struct _svgLength tY; struct _svgLength tRadius; }

user_defined_types: struct _svgEllipse { struct _svgLength tX; struct _svgLength tY; struct _svgLength tRadiusX; struct _svgLength tRadiusY; }

user_defined_types: struct _svgPolygon { struct _svgPoint tFirstPoint; }

user_defined_types: struct _svgPoint { struct _svgLength tX; struct _svgLength tY; struct _svgPoint *ptNextPoint; }

user_defined_types: enum _svgPathCommandId { SVG_PATH_CMD_ID_MOVETO_ABS=0, SVG_PATH_CMD_ID_MOVETO_REL=1, SVG_PATH_CMD_ID_LINETO_ABS=2, SVG_PATH_CMD_ID_LINETO_REL=3, SVG_PATH_CMD_ID_VERTICAL_LINETO_ABS=4, SVG_PATH_CMD_ID_VERTICAL_LINETO_REL=5, SVG_PATH_CMD_ID_HORIZONTAL_LINETO_ABS=6, SVG_PATH_CMD_ID_HORIZONTAL_LINETO_REL=7, SVG_PATH_CMD_ID_CUBIC_CURVETO_ABS=8, SVG_PATH_CMD_ID_CUBIC_CURVETO_REL=9, SVG_PATH_CMD_ID_SMOOTH_CUBIC_CURVETO_ABS=10, SVG_PATH_CMD_ID_SMOOTH_CUBIC_CURVETO_REL=11, SVG_PATH_CMD_ID_QUADRATIC_CURVETO_ABS=12, SVG_PATH_CMD_ID_QUADRATIC_CURVETO_REL=13, SVG_PATH_CMD_ID_SMOOTH_QUADRATIC_CURVETO_ABS=14, SVG_PATH_CMD_ID_SMOOTH_QUADRATIC_CURVETO_REL=15, SVG_PATH_CMD_ID_ARCTO_ABS=16, SVG_PATH_CMD_ID_ARCTO_REL=17, SVG_PATH_CMD_ID_CLOSEPATH=18, SVG_PATH_CMD_ID_END_OF_ENUM=19 }

user_defined_types: struct _svgPathCommand_MoveTo { struct _svgLength tX; struct _svgLength tY; }

user_defined_types: struct _svgPathCommand_Lineto { struct _svgLength tX; struct _svgLength tY; }

user_defined_types: struct _svgPathCommand_CubicCurveTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tX1; struct _svgLength tY1; struct _svgLength tX2; struct _svgLength tY2; }

user_defined_types: struct _svgPathCommand_SmoothCubicCurveTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tX2; struct _svgLength tY2; }

user_defined_types: struct _svgPathCommand_QuadraticCurveTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tX1; struct _svgLength tY1; }

user_defined_types: struct _svgPathCommand_SmoothQuadraticCurveTo { struct _svgLength tX; struct _svgLength tY; }

user_defined_types: struct _svgPathCommand_ArcTo { struct _svgLength tX; struct _svgLength tY; struct _svgLength tRadiusX; struct _svgLength tRadiusY; struct _svgLength tXAxisAngle; struct _svgLength tLargeArcFlag; struct _svgLength tSweepFlag; }


svgStringToLength

decompiled_code:
char __fastcall svgStringToLength(__int64 a1, _QWORD *a2)
{
char result; // al
bool v3; // zf
__int64 v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = 0LL;
if ( a1 )
{
if ( a2 )
{
*a2 = 0LL;
result = _isoc99_sscanf(a1, "%f%s", (char *)a2 + 4, v4);
*(_DWORD *)a2 = 0;
if ( LOBYTE(v4[0]) )
{
v3 = strcmp((const char *)v4, "em") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 2;
}
else
{
v3 = strcmp((const char *)v4, "ex") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 3;
}
else
{
v3 = strcmp((const char *)v4, "in") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 4;
}
else
{
v3 = strcmp((const char *)v4, "cm") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 5;
}
else
{
v3 = strcmp((const char *)v4, "mm") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 6;
}
else
{
v3 = strcmp((const char *)v4, "pt") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 7;
}
else
{
v3 = strcmp((const char *)v4, "pc") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 8;
}
else
{
v3 = strcmp((const char *)v4, "%") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 9;
}
else
{
v3 = strcmp((const char *)v4, "px") == 0;
result = !v3;
if ( v3 )
*(_DWORD *)a2 = 1;
}
}
}
}
}
}
}
}
}
}
}
return result;
}

canonical_decompiled_code:
char __fastcall func0(__int64 a1, _QWORD *a2)
{
char result; // al
bool v3; // zf
__int64 v4[2]; // [rsp+8h] [rbp-10h] BYREF

v4[0] = 0LL;
if ( a1 )
{
if ( a2 )
{
*a2 = 0LL;
result = _isoc99_sscanf(a1, "%f%s", (char *)a2 + 4, v4);
*(_DWORD *)a2 = 0;
if ( LOBYTE(v4[0]) )
{
v3 = strcmp((const char *)v4, "em") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 2;
}
else
{
v3 = strcmp((const char *)v4, "ex") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 3;
}
else
{
v3 = strcmp((const char *)v4, "in") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 4;
}
else
{
v3 = strcmp((const char *)v4, "cm") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 5;
}
else
{
v3 = strcmp((const char *)v4, "mm") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 6;
}
else
{
v3 = strcmp((const char *)v4, "pt") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 7;
}
else
{
v3 = strcmp((const char *)v4, "pc") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 8;
}
else
{
v3 = strcmp((const char *)v4, "%") == 0;
result = !v3;
if ( v3 )
{
*(_DWORD *)a2 = 9;
}
else
{
v3 = strcmp((const char *)v4, "px") == 0;
result = !v3;
if ( v3 )
*(_DWORD *)a2 = 1;
}
}
}
}
}
}
}
}
}
}
}
return result;
}

original_code:
void svgStringToLength( const char *szValue, svgLength *ptLength )
{
 char szUnit[ 8 ] = "";
 if( szValue==((void *)0) || ptLength==((void *)0) )
  return;
 memset( ptLength, 0, sizeof( *ptLength ) );
 sscanf( szValue, "%f%s", &ptLength->fValue, szUnit );
 ptLength->tUnit = SVG_LENGTH_UNIT_NONE;
 if( szUnit[ 0 ]=='\0' )
  return;
 if( strcmp( szUnit, "em" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_EM;
 else if( strcmp( szUnit, "ex" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_EX;
 else if( strcmp( szUnit, "in" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_IN;
 else if( strcmp( szUnit, "cm" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_CM;
 else if( strcmp( szUnit, "mm" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_MM;
 else if( strcmp( szUnit, "pt" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_PT;
 else if( strcmp( szUnit, "pc" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_PC;
 else if( strcmp( szUnit, "%" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_PERCENT;
 else if( strcmp( szUnit, "px" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_PX;
}

canonical_original_code:
void svgStringToLength(char *szValue, struct _svgLength *ptLength)
{
 char szUnit[8] = "";
 if( szValue==((void *)0) || ptLength==((void *)0) )
  return;
 memset( ptLength, 0, sizeof( *ptLength ) );
 sscanf( szValue, "%f%s", &ptLength->fValue, szUnit );
 ptLength->tUnit = SVG_LENGTH_UNIT_NONE;
 if( szUnit[ 0 ]=='\0' )
  return;
 if( strcmp( szUnit, "em" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_EM;
 else if( strcmp( szUnit, "ex" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_EX;
 else if( strcmp( szUnit, "in" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_IN;
 else if( strcmp( szUnit, "cm" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_CM;
 else if( strcmp( szUnit, "mm" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_MM;
 else if( strcmp( szUnit, "pt" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_PT;
 else if( strcmp( szUnit, "pc" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_PC;
 else if( strcmp( szUnit, "%" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_PERCENT;
 else if( strcmp( szUnit, "px" )==0 )
  ptLength->tUnit = SVG_LENGTH_UNIT_PX;
}

variable_types:
szValue
char *

variable_types: struct _svgLength { enum _svgLengthUnit { SVG_LENGTH_UNIT_NONE=0, SVG_LENGTH_UNIT_PX=1, SVG_LENGTH_UNIT_EM=2, SVG_LENGTH_UNIT_EX=3, SVG_LENGTH_UNIT_IN=4, SVG_LENGTH_UNIT_CM=5, SVG_LENGTH_UNIT_MM=6, SVG_LENGTH_UNIT_PT=7, SVG_LENGTH_UNIT_PC=8, SVG_LENGTH_UNIT_PERCENT=9 } tUnit; float fValue; } *

variable_types:
szUnit
char [8]

user_defined_types: struct _svgLength { enum _svgLengthUnit tUnit; float fValue; }


aggancia

repo: agentOfChaos/chaos-controller

decompiled_code:
__int64 __fastcall aggancia(unsigned int a1)
{
unsigned int v1; // ebx

v1 = ptrace(PTRACE_ATTACH, a1, 0LL, 0LL);
if ( v1 != -1 )
wait(0LL);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
unsigned int v1; // ebx

v1 = ptrace(PTRACE_ATTACH, a1, 0LL, 0LL);
if ( v1 != -1 )
wait(0LL);
return v1;
}

original_code:
int aggancia(pid_t pid)
{
    int ret;
    ret=ptrace(PTRACE_ATTACH,pid,((void *)0),((void *)0));
    if (ret!=-1)
        {
        wait(((void *)0));
        }
    return ret;
}

canonical_original_code:
int aggancia(int pid)
{
    int ret;
    ret=ptrace(PTRACE_ATTACH,pid,((void *)0),((void *)0));
    if (ret!=-1)
        {
        wait(((void *)0));
        }
    return ret;
}

variable_types: pid int

variable_types: ret int


decompiled_code:
void *self_discover()
{
return dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "rand");
}

canonical_decompiled_code:
void *func2()
{
return dlsym((void *)0xFFFFFFFFFFFFFFFFLL, "rand");
}

original_code:
unsigned long long int self_discover()
{
    void *altro;
    altro=dlsym(((void *) -1l),"rand");
    return (unsigned long long int)altro;
}

canonical_original_code:
unsigned long long self_discover()
{
    void *altro;
    altro=dlsym(((void *) -1l),"rand");
    return (unsigned long long)altro;
}

variable_types:
altro
void *

return_type: unsigned long long


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rbx
__int64 v7; // rbp
void *v8; // rax
unsigned int v10; // [rsp+10h] [rbp-30h] BYREF
int v11; // [rsp+14h] [rbp-2Ch] BYREF
int v12; // [rsp+18h] [rbp-28h] BYREF
char v13; // [rsp+1Fh] [rbp-21h] BYREF
int v14; // [rsp+20h] [rbp-20h] BYREF
__pid_t pid[7]; // [rsp+24h] [rbp-1Ch] BYREF

v12 = 0;
v11 = 0;
parse_cmdline(argc, argv, &v14, &v12, pid, &v11, &v10);
v3 = getpid();
v4 = libc_posiz(v3);
if ( v11 )
{
v7 = v4;
v8 = self_discover();
printf("%lx +4 - %lx = ", v8, v7);
offset = (__int64)self_discover() - v7 + 4;
}
else
{
offset = 233044LL;
}
printf("Function offset: %lx\n", offset);
if ( v12 )
{
if ( (unsigned int)spawn(argv[2], pid) == -1 )
{
puts("Cannot spawn the process.");
exit(-3);
}
printf("Spawned process with pid=%d\n", (unsigned int)pid[0]);
}
if ( !(unsigned int)controlla_pid((unsigned int)pid[0]) )
{
puts("unexistent process.");
exit(-4);
}
v5 = libc_posiz(pid[0]);
printf("Process' base (libc): %lx\n", v5);
v6 = offset + v5;
printf("Injection target: %lx\n", v6);
if ( (unsigned int)aggancia(pid[0]) == -1 )
{
puts("Cannot attach the process. Try running in as sudo.");
exit(-5);
}
puts("Process successfully attached.");
if ( !(unsigned int)safecheck((unsigned int)pid[0], v6) && v14 != 2 )
{
puts("Unexpected result! Recognitions report a target memory word that does not match the expected one.");
printf("Do you wish to continue, my master? (y/n) ");
scanf("%c", &v13);
getchar();
if ( (v13 & 0xDF) != 89 )
exit(-3);
}
do
{
v13 = 110;
if ( v14 )
{
if ( v14 == 1 )
customnum((unsigned int)pid[0], v6, v10);
else
restore((unsigned int)pid[0], v6);
}
else
{
nopmode((unsigned int)pid[0], v6);
}
puts("Done injection!");
if ( v12 )
{
ptrace(PTRACE_DETACH, (unsigned int)pid[0], 0LL, 0LL);
printf("inject again? (y/n) ");
scanf("%c", &v13);
getchar();
if ( (v13 & 0xDF) == 89 )
{
printf("mode? 0=nop 1=num 2=fix : ");
scanf("%d", &v14);
if ( v14 == 1 )
{
printf("Return value? ");
scanf("%d", &v10);
getchar();
}
}
if ( (unsigned int)aggancia(pid[0]) == -1 )
{
puts("Cannot attach the process. (Did it terminate?).");
exit(-5);
}
}
}
while ( (v13 & 0xDF) == 89 );
if ( v12 )
{
printf("Kill the child process on exit? (y/n) ");
scanf("%c", &v13);
getchar();
if ( (v13 & 0xDF) == 89 )
{
ptrace(PTRACE_DETACH, (unsigned int)pid[0], 0LL, 0LL);
kill(pid[0], 9);
puts("Done!");
}
else
{
puts("Init will do it for you.");
ptrace(PTRACE_DETACH, (unsigned int)pid[0], 0LL, 0LL);
}
}
else
{
ptrace(PTRACE_DETACH, (unsigned int)pid[0], 0LL, 0LL);
}
printf("Process %d detached. Exiting.\n", (unsigned int)pid[0]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax
__int64 v4; // rax
__int64 v5; // rbx
__int64 v6; // rbx
__int64 v7; // rbp
void *v8; // rax
unsigned int v10; // [rsp+10h] [rbp-30h] BYREF
int v11; // [rsp+14h] [rbp-2Ch] BYREF
int v12; // [rsp+18h] [rbp-28h] BYREF
char v13; // [rsp+1Fh] [rbp-21h] BYREF
int v14; // [rsp+20h] [rbp-20h] BYREF
__pid_t pid[7]; // [rsp+24h] [rbp-1Ch] BYREF

v12 = 0;
v11 = 0;
parse_cmdline(argc, argv, &v14, &v12, pid, &v11, &v10);
v3 = getpid();
v4 = func0(v3);
if ( v11 )
{
v7 = v4;
v8 = func2();
printf("%lx +4 - %lx = ", v8, v7);
offset = (__int64)func2() - v7 + 4;
}
else
{
offset = 233044LL;
}
printf("Function offset: %lx\n", offset);
if ( v12 )
{
if ( (unsigned int)spawn(argv[2], pid) == -1 )
{
puts("Cannot spawn the process.");
exit(-3);
}
printf("Spawned process with pid=%d\n", (unsigned int)pid[0]);
}
if ( !(unsigned int)controlla_pid((unsigned int)pid[0]) )
{
puts("unexistent process.");
exit(-4);
}
v5 = func0(pid[0]);
printf("Process' base (libc): %lx\n", v5);
v6 = offset + v5;
printf("Injection target: %lx\n", v6);
if ( (unsigned int)func1(pid[0]) == -1 )
{
puts("Cannot attach the process. Try running in as sudo.");
exit(-5);
}
puts("Process successfully attached.");
if ( !(unsigned int)safecheck((unsigned int)pid[0], v6) && v14 != 2 )
{
puts("Unexpected result! Recognitions report a target memory word that does not match the expected one.");
printf("Do you wish to continue, my master? (y/n) ");
scanf("%c", &v13);
getchar();
if ( (v13 & 0xDF) != 89 )
exit(-3);
}
do
{
v13 = 110;
if ( v14 )
{
if ( v14 == 1 )
customnum((unsigned int)pid[0], v6, v10);
else
restore((unsigned int)pid[0], v6);
}
else
{
nopmode((unsigned int)pid[0], v6);
}
puts("Done injection!");
if ( v12 )
{
ptrace(PTRACE_DETACH, (unsigned int)pid[0], 0LL, 0LL);
printf("inject again? (y/n) ");
scanf("%c", &v13);
getchar();
if ( (v13 & 0xDF) == 89 )
{
printf("mode? 0=nop 1=num 2=fix : ");
scanf("%d", &v14);
if ( v14 == 1 )
{
printf("Return value? ");
scanf("%d", &v10);
getchar();
}
}
if ( (unsigned int)func1(pid[0]) == -1 )
{
puts("Cannot attach the process. (Did it terminate?).");
exit(-5);
}
}
}
while ( (v13 & 0xDF) == 89 );
if ( v12 )
{
printf("Kill the child process on exit? (y/n) ");
scanf("%c", &v13);
getchar();
if ( (v13 & 0xDF) == 89 )
{
ptrace(PTRACE_DETACH, (unsigned int)pid[0], 0LL, 0LL);
kill(pid[0], 9);
puts("Done!");
}
else
{
puts("Init will do it for you.");
ptrace(PTRACE_DETACH, (unsigned int)pid[0], 0LL, 0LL);
}
}
else
{
ptrace(PTRACE_DETACH, (unsigned int)pid[0], 0LL, 0LL);
}
printf("Process %d detached. Exiting.\n", (unsigned int)pid[0]);
return 0;
}

original_code:
int main(int argc, char *argv[])
{
    pid_t pid;
    int mode;
    char ans;
    int forkmode=0;
    int offsetmode=0;
    unsigned long long int libc_addr,bersaglio,my_libc,recalc;
    int valore_eax;
    parse_cmdline(argc,argv,&mode,&forkmode,&pid,&offsetmode,&valore_eax);
    my_libc=libc_posiz(getpid());
    if (offsetmode==0)offset=0x38E54;
    else
        {
        printf("%lx +4 - %lx = ",self_discover(),my_libc);
        recalc=(self_discover()+4)-my_libc;
        offset=(long)recalc;
        }
    printf("Function offset: %lx\n",offset);
    if (forkmode)
        {
        if (spawn(argv[2],&pid)==-1)
            {
            printf("Cannot spawn the process.\n");
            exit(-3);
            }
        printf("Spawned process with pid=%d\n",pid);
        }
    if (controlla_pid(pid)==0)
        {
        printf("unexistent process.\n");
        exit(-4);
        }
    libc_addr=libc_posiz(pid);
    printf("Process' base (libc): %lx\n",libc_addr);
    bersaglio=libc_addr+offset;
    printf("Injection target: %lx\n",bersaglio);
    if (aggancia(pid)==-1)
        {
        printf("Cannot attach the process. Try running in as sudo.\n");
        exit(-5);
        }
    else printf("Process successfully attached.\n");
    if (!safecheck(pid,bersaglio) && (mode!=2))
        {
        printf("Unexpected result! Recognitions report a target memory word that does not match the expected one.\n");
        printf("Do you wish to continue, my master? (y/n) ");
        scanf("%c",&ans);
        getchar();
        if (ans!='y' && ans!='Y')exit(-3);
        }
    do
        {
        ans='n';
        switch (mode)
            {
            case 0: nopmode(pid,bersaglio); break;
            case 1: customnum(pid,bersaglio,valore_eax); break;
            default: restore(pid,bersaglio);
            }
        printf("Done injection!\n");
        if (forkmode)
            {
            ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
            printf("inject again? (y/n) ");
            scanf("%c",&ans); getchar();
            if (ans=='y' || ans=='Y')
                {
                printf("mode? 0=nop 1=num 2=fix : ");
                scanf("%d",&mode);
                if (mode==1)
                    {
                    printf("Return value? ");
                    scanf("%d",&valore_eax); getchar();
                    }
                }
            if (aggancia(pid)==-1)
                {
                printf("Cannot attach the process. (Did it terminate?).\n");
                exit(-5);
                }
            }
        } while (ans=='y' || ans=='Y');
    if (forkmode)
        {
        printf("Kill the child process on exit? (y/n) ");
        scanf("%c",&ans);
        getchar();
        if (ans=='y' || ans=='Y')
            {
            ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
            kill(pid,9);
            printf("Done!\n");
            }
        else
            {
            printf("Init will do it for you.\n");
            ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
            }
        }
    else ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
    printf("Process %d detached. Exiting.\n",pid);
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    int pid;
    int mode;
    char ans;
    int forkmode = 0;
    int offsetmode = 0;
    unsigned long long libc_addr; unsigned long long bersaglio; unsigned long long my_libc; unsigned long long recalc;
    int valore_eax;
    parse_cmdline(argc,argv,&mode,&forkmode,&pid,&offsetmode,&valore_eax);
    my_libc=libc_posiz(getpid());
    if (offsetmode==0)offset=0x38E54;
    else
        {
        printf("%lx +4 - %lx = ",self_discover(),my_libc);
        recalc=(self_discover()+4)-my_libc;
        offset=(long)recalc;
        }
    printf("Function offset: %lx\n",offset);
    if (forkmode)
        {
        if (spawn(argv[2],&pid)==-1)
            {
            printf("Cannot spawn the process.\n");
            exit(-3);
            }
        printf("Spawned process with pid=%d\n",pid);
        }
    if (controlla_pid(pid)==0)
        {
        printf("unexistent process.\n");
        exit(-4);
        }
    libc_addr=libc_posiz(pid);
    printf("Process' base (libc): %lx\n",libc_addr);
    bersaglio=libc_addr+offset;
    printf("Injection target: %lx\n",bersaglio);
    if (aggancia(pid)==-1)
        {
        printf("Cannot attach the process. Try running in as sudo.\n");
        exit(-5);
        }
    else printf("Process successfully attached.\n");
    if (!safecheck(pid,bersaglio) && (mode!=2))
        {
        printf("Unexpected result! Recognitions report a target memory word that does not match the expected one.\n");
        printf("Do you wish to continue, my master? (y/n) ");
        scanf("%c",&ans);
        getchar();
        if (ans!='y' && ans!='Y')exit(-3);
        }
    do
        {
        ans='n';
        switch (mode)
            {
            case 0: nopmode(pid,bersaglio); break;
            case 1: customnum(pid,bersaglio,valore_eax); break;
            default: restore(pid,bersaglio);
            }
        printf("Done injection!\n");
        if (forkmode)
            {
            ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
            printf("inject again? (y/n) ");
            scanf("%c",&ans); getchar();
            if (ans=='y' || ans=='Y')
                {
                printf("mode? 0=nop 1=num 2=fix : ");
                scanf("%d",&mode);
                if (mode==1)
                    {
                    printf("Return value? ");
                    scanf("%d",&valore_eax); getchar();
                    }
                }
            if (aggancia(pid)==-1)
                {
                printf("Cannot attach the process. (Did it terminate?).\n");
                exit(-5);
                }
            }
        } while (ans=='y' || ans=='Y');
    if (forkmode)
        {
        printf("Kill the child process on exit? (y/n) ");
        scanf("%c",&ans);
        getchar();
        if (ans=='y' || ans=='Y')
            {
            ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
            kill(pid,9);
            printf("Done!\n");
            }
        else
            {
            printf("Init will do it for you.\n");
            ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
            }
        }
    else ptrace(PTRACE_DETACH,pid,((void *)0),((void *)0));
    printf("Process %d detached. Exiting.\n",pid);
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: mode int

variable_types: ans char

variable_types: forkmode int

variable_types: offsetmode int

variable_types:
bersaglio
unsigned long long

variable_types:
recalc
unsigned long long


isname

decompiled_code:
int __fastcall isname(const char *a1)
{
int v1; // eax
const char *v2; // rbx
__int64 v3; // rbp
int result; // eax

v1 = strlen(a1);
if ( v1 <= 0 )
return 0;
v2 = a1;
v3 = (__int64)&a1[v1 - 1 + 1];
while ( 1 )
{
result = isalpha(*v2);
if ( result )
break;
if ( ++v2 == (const char *)v3 )
return result;
}
return 1;
}

canonical_decompiled_code:
int __fastcall func0(const char *a1)
{
int v1; // eax
const char *v2; // rbx
__int64 v3; // rbp
int result; // eax

v1 = strlen(a1);
if ( v1 <= 0 )
return 0;
v2 = a1;
v3 = (__int64)&a1[v1 - 1 + 1];
while ( 1 )
{
result = isalpha(*v2);
if ( result )
break;
if ( ++v2 == (const char *)v3 )
return result;
}
return 1;
}

original_code:
int isname(char *text)
{
    int l=strlen(text);
    int z;
    for (z=0; z<l; z++)
        {
        if (isalpha(text[z]))return 1;
        }
    return 0;
}

canonical_original_code:
int isname(char *text)
{
    int l = strlen(text);
    int z;
    for (z=0; z<l; z++)
        {
        if (isalpha(text[z]))return 1;
        }
    return 0;
}

variable_types:
text
char *

variable_types: l int

variable_types: z int


spawn

decompiled_code:
__int64 __fastcall spawn(char *arg, __pid_t *a2)
{
__pid_t v2; // eax
__int64 result; // rax

v2 = fork();
if ( v2 < 0 )
{
puts("Fork error.");
result = 0xFFFFFFFFLL;
}
else
{
if ( !v2 )
{
execl(arg, arg, 0LL);
puts("Exec error.");
exit(-1);
}
*a2 = v2;
result = 1LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *arg, __pid_t *a2)
{
__pid_t v2; // eax
__int64 result; // rax

v2 = fork();
if ( v2 < 0 )
{
puts("Fork error.");
result = 0xFFFFFFFFLL;
}
else
{
if ( !v2 )
{
execl(arg, arg, 0LL);
puts("Exec error.");
exit(-1);
}
*a2 = v2;
result = 1LL;
}
return result;
}

original_code:
int spawn(char *nomefile,pid_t *pid)
{
    pid_t child=fork();
    if (child<0)
        {
        printf("Fork error.\n");
        return -1;
        }
    if (child==0)
        {
        execl(nomefile,nomefile,((void *)0));
        printf("Exec error.\n");
        exit(-1);
        }
    else
        {
        *pid=child;
        return 1;
        }
}

canonical_original_code:
int spawn(char *nomefile, int *pid)
{
    int child = fork();
    if (child<0)
        {
        printf("Fork error.\n");
        return -1;
        }
    if (child==0)
        {
        execl(nomefile,nomefile,((void *)0));
        printf("Exec error.\n");
        exit(-1);
        }
    else
        {
        *pid=child;
        return 1;
        }
}

variable_types:
nomefile
char *

variable_types:
pid
int *

variable_types: child int


putdata

decompiled_code:
__int64 __fastcall putdata(unsigned int a1, __int64 a2, char *a3, int a4)
{
char *v4; // r12
size_t v5; // r14
signed __int64 v6; // rax
void *v7; // rsp
__int64 v8; // rbx
__int64 result; // rax
unsigned __int64 v10; // [rsp+0h] [rbp-60h] BYREF
__int64 v11; // [rsp+8h] [rbp-58h]
int v12; // [rsp+14h] [rbp-4Ch]
unsigned int v13; // [rsp+18h] [rbp-48h]
int v14; // [rsp+1Ch] [rbp-44h]
void *src; // [rsp+20h] [rbp-40h]
__int64 v16; // [rsp+28h] [rbp-38h]

v11 = a2;
v4 = a3;
src = a3;
v14 = a4;
v5 = long_size;
v6 = 8LL;
if ( (unsigned __int64)long_size >= 8 )
v6 = long_size;
v7 = alloca(v6);
v10 = ((unsigned __int64)&v10 + 7) >> 3;
v13 = a4 / long_size;
v12 = a4 / long_size;
if ( a4 / long_size <= 0 )
{
v12 = 0;
}
else
{
v8 = a2;
v16 = a2 + 4LL * (unsigned int)(a4 / long_size - 1) + 4;
do
{
memcpy(&v10, v4, v5);
ptrace(PTRACE_POKEDATA, a1, v8, v10);
v4 += v5;
v8 += 4LL;
}
while ( v8 != v16 );
src = (char *)src + v13 * v5;
}
result = (unsigned int)(v14 / long_size);
if ( v14 % long_size )
{
memcpy(&v10, src, v14 % long_size);
result = ptrace(PTRACE_POKEDATA, a1, v11 + 4 * v12, *(_QWORD *)(8 * v10));
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2, char *a3, int a4)
{
char *v4; // r12
size_t v5; // r14
signed __int64 v6; // rax
void *v7; // rsp
__int64 v8; // rbx
__int64 result; // rax
unsigned __int64 v10; // [rsp+0h] [rbp-60h] BYREF
__int64 v11; // [rsp+8h] [rbp-58h]
int v12; // [rsp+14h] [rbp-4Ch]
unsigned int v13; // [rsp+18h] [rbp-48h]
int v14; // [rsp+1Ch] [rbp-44h]
void *src; // [rsp+20h] [rbp-40h]
__int64 v16; // [rsp+28h] [rbp-38h]

v11 = a2;
v4 = a3;
src = a3;
v14 = a4;
v5 = long_size;
v6 = 8LL;
if ( (unsigned __int64)long_size >= 8 )
v6 = long_size;
v7 = alloca(v6);
v10 = ((unsigned __int64)&v10 + 7) >> 3;
v13 = a4 / long_size;
v12 = a4 / long_size;
if ( a4 / long_size <= 0 )
{
v12 = 0;
}
else
{
v8 = a2;
v16 = a2 + 4LL * (unsigned int)(a4 / long_size - 1) + 4;
do
{
memcpy(&v10, v4, v5);
ptrace(PTRACE_POKEDATA, a1, v8, v10);
v4 += v5;
v8 += 4LL;
}
while ( v8 != v16 );
src = (char *)src + v13 * v5;
}
result = (unsigned int)(v14 / long_size);
if ( v14 % long_size )
{
memcpy(&v10, src, v14 % long_size);
result = ptrace(PTRACE_POKEDATA, a1, v11 + 4 * v12, *(_QWORD *)(8 * v10));
}
return result;
}

original_code:
void putdata(pid_t child, long addr,
             char *str, int len)
{ char *laddr;
    int i, j;
    union u {
            long val;
            char chars[long_size];
    }data;
    i = 0;
    j = len / long_size;
    laddr = str;
    while(i < j) {
        memcpy(data.chars, laddr, long_size);
        ptrace(PTRACE_POKEDATA, child,
               addr + i * 4, data.val);
        ++i;
        laddr += long_size;
    }
    j = len % long_size;
    if(j != 0) {
        memcpy(data.chars, laddr, j);
        ptrace(PTRACE_POKEDATA, child,
               addr + i * 4, data.val);
    }
}

canonical_original_code:
void putdata(int child, long addr, char *str, int len)
{ char *laddr;
    int i; int j;
    union u data;
    i = 0;
    j = len / long_size;
    laddr = str;
    while(i < j) {
        memcpy(data.chars, laddr, long_size);
        ptrace(PTRACE_POKEDATA, child,
               addr + i * 4, data.val);
        ++i;
        laddr += long_size;
    }
    j = len % long_size;
    if(j != 0) {
        memcpy(data.chars, laddr, j);
        ptrace(PTRACE_POKEDATA, child,
               addr + i * 4, data.val);
    }
}

variable_types: addr long

variable_types:
str
char *

variable_types: len int

variable_types:
laddr
char *

variable_types: i int

variable_types: j int

variable_types:
data
union u { long val; char chars[-1]; }


customnum

decompiled_code:
__int64 __fastcall customnum(unsigned int a1, __int64 a2, int a3)
{
int v4; // er12
signed __int64 v5; // rax
void *v6; // rsp
char *v7; // rbx
__int64 v8; // rax
__int64 v9; // rbx
char v10; // si
unsigned __int64 v12; // [rsp+0h] [rbp-50h] BYREF
int v13; // [rsp+8h] [rbp-48h]
unsigned int v14; // [rsp+Ch] [rbp-44h]
char v15; // [rsp+11h] [rbp-3Fh]
char v16[5]; // [rsp+12h] [rbp-3Eh]
char v17[8]; // [rsp+17h] [rbp-39h] BYREF
char v18; // [rsp+1Fh] [rbp-31h] BYREF

v14 = a1;
v13 = a3;
printf(" ---> %lx\n", a2);
v4 = int_size;
v5 = int_size;
if ( (unsigned __int64)int_size < 4 )
v5 = 4LL;
v6 = alloca(v5);
v12 = ((unsigned __int64)&v12 + 3) >> 2;
getdata(a1, a2, v17, 8LL);
printf("prima: ");
v7 = v17;
do
printf("%x ", (unsigned int)*v7++);
while ( v7 != &v18 );
*(_DWORD *)(4 * v12) = v13;
v15 = -72;
if ( v4 <= 0 )
{
v16[0] = 0;
printf("\n(custom mode) dopo: ");
if ( !v4 )
{
v17[0] = v15;
printf("%x ", (unsigned int)v15);
}
}
else
{
v8 = 0LL;
do
{
v16[v8] = *((_BYTE *)&v12 + v8);
++v8;
}
while ( v4 > (int)v8 );
*(&v15 + v4 + 1) = 0;
printf("\n(custom mode) dopo: ");
v9 = 0LL;
do
{
v10 = *(&v15 + v9);
v17[v9] = v10;
printf("%x ", (unsigned int)v10);
++v9;
}
while ( v4 >= (int)v9 );
}
putchar(10);
return putdata(v14, a2, v17, 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func0(unsigned int a1, __int64 a2, int a3)
{
int v4; // er12
signed __int64 v5; // rax
void *v6; // rsp
char *v7; // rbx
__int64 v8; // rax
__int64 v9; // rbx
char v10; // si
unsigned __int64 v12; // [rsp+0h] [rbp-50h] BYREF
int v13; // [rsp+8h] [rbp-48h]
unsigned int v14; // [rsp+Ch] [rbp-44h]
char v15; // [rsp+11h] [rbp-3Fh]
char v16[5]; // [rsp+12h] [rbp-3Eh]
char v17[8]; // [rsp+17h] [rbp-39h] BYREF
char v18; // [rsp+1Fh] [rbp-31h] BYREF

v14 = a1;
v13 = a3;
printf(" ---> %lx\n", a2);
v4 = int_size;
v5 = int_size;
if ( (unsigned __int64)int_size < 4 )
v5 = 4LL;
v6 = alloca(v5);
v12 = ((unsigned __int64)&v12 + 3) >> 2;
getdata(a1, a2, v17, 8LL);
printf("prima: ");
v7 = v17;
do
printf("%x ", (unsigned int)*v7++);
while ( v7 != &v18 );
*(_DWORD *)(4 * v12) = v13;
v15 = -72;
if ( v4 <= 0 )
{
v16[0] = 0;
printf("\n(custom mode) dopo: ");
if ( !v4 )
{
v17[0] = v15;
printf("%x ", (unsigned int)v15);
}
}
else
{
v8 = 0LL;
do
{
v16[v8] = *((_BYTE *)&v12 + v8);
++v8;
}
while ( v4 > (int)v8 );
*(&v15 + v4 + 1) = 0;
printf("\n(custom mode) dopo: ");
v9 = 0LL;
do
{
v10 = *(&v15 + v9);
v17[v9] = v10;
printf("%x ", (unsigned int)v10);
++v9;
}
while ( v4 >= (int)v9 );
}
putchar(10);
return putdata(v14, a2, v17, 8LL);
}

original_code:
void customnum(pid_t pid,unsigned long long int bersaglio, int valore_eax)
{
    printf(" ---> %lx\n",bersaglio);
    union u {
            int val;
            char chars[int_size];
    }data;
    char salvato[9];
    char iniettando[6];
    int i;
    char opcode=0xb8;
    getdata(pid, bersaglio, salvato, 8);
    printf("prima: ");
    for (i=0; i<8; i++)printf("%x ",(int)salvato[i]);
    data.val=valore_eax;
    iniettando[0]=opcode;
    for (i=0; i<int_size; i++)iniettando[i+1]=data.chars[i];
    iniettando[i+1]=0;
    printf("\n(custom mode) dopo: ");
    for (i=0; i<int_size+1; i++){salvato[i]=iniettando[i]; printf("%x ",(int)iniettando[i]);}
    printf("\n");
    putdata(pid,bersaglio,salvato,8);
}

canonical_original_code:
void customnum(int pid, unsigned long long bersaglio, int valore_eax)
{
    printf(" ---> %lx\n",bersaglio);
    union u data;
    char salvato[9];
    char iniettando[6];
    int i;
    char opcode = 0xb8;
    getdata(pid, bersaglio, salvato, 8);
    printf("prima: ");
    for (i=0; i<8; i++)printf("%x ",(int)salvato[i]);
    data.val=valore_eax;
    iniettando[0]=opcode;
    for (i=0; i<int_size; i++)iniettando[i+1]=data.chars[i];
    iniettando[i+1]=0;
    printf("\n(custom mode) dopo: ");
    for (i=0; i<int_size+1; i++){salvato[i]=iniettando[i]; printf("%x ",(int)iniettando[i]);}
    printf("\n");
    putdata(pid,bersaglio,salvato,8);
}

variable_types: pid int

variable_types:
data
union u { int val; char chars[-1]; }

variable_types:
salvato
char [9]

variable_types:
iniettando
char [6]

variable_types: opcode char


restore

decompiled_code:
__int64 __fastcall restore(__int64 a1, __int64 a2)
{
char *v3; // rbx
__int64 i; // rbx
char v5; // si
char v7[8]; // [rsp+2h] [rbp-36h] BYREF
char v8; // [rsp+Ah] [rbp-2Eh] BYREF
int v9; // [rsp+Bh] [rbp-2Dh]
char v10; // [rsp+Fh] [rbp-29h]

v9 = -346136;
v10 = -1;
getdata(a1, a2, v7, 8LL);
printf("prima: ");
v3 = v7;
do
printf("%x ", (unsigned int)*v3++);
while ( v3 != &v8 );
printf("\n (restore mode)dopo: ");
for ( i = 0LL; i != 5; ++i )
{
v5 = *((_BYTE *)&v9 + i);
v7[i] = v5;
printf("%x ", (unsigned int)v5);
}
putchar(10);
return putdata((unsigned int)a1, a2, v7, 8LL);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
char *v3; // rbx
__int64 i; // rbx
char v5; // si
char v7[8]; // [rsp+2h] [rbp-36h] BYREF
char v8; // [rsp+Ah] [rbp-2Eh] BYREF
int v9; // [rsp+Bh] [rbp-2Dh]
char v10; // [rsp+Fh] [rbp-29h]

v9 = -346136;
v10 = -1;
getdata(a1, a2, v7, 8LL);
printf("prima: ");
v3 = v7;
do
printf("%x ", (unsigned int)*v3++);
while ( v3 != &v8 );
printf("\n (restore mode)dopo: ");
for ( i = 0LL; i != 5; ++i )
{
v5 = *((_BYTE *)&v9 + i);
v7[i] = v5;
printf("%x ", (unsigned int)v5);
}
putchar(10);
return putdata((unsigned int)a1, a2, v7, 8LL);
}

original_code:
void restore(pid_t pid,unsigned long long int bersaglio)
{
    char iniettando[]={0xe8,0xb7,0xfa,0xff,0xff};
    int i;
    char salvato[9];
    getdata(pid, bersaglio, salvato, 8);
    printf("prima: ");
    for (i=0; i<8; i++)printf("%x ",salvato[i]);
    printf("\n (restore mode)dopo: ");
    for (i=0; i<5; i++){salvato[i]=iniettando[i]; printf("%x ",iniettando[i]);}
    printf("\n");
    putdata(pid,bersaglio,salvato,8);
}

canonical_original_code:
void restore(int pid, unsigned long long bersaglio)
{
    char iniettando[] = {0xe8,0xb7,0xfa,0xff,0xff};
    int i;
    char salvato[9];
    getdata(pid, bersaglio, salvato, 8);
    printf("prima: ");
    for (i=0; i<8; i++)printf("%x ",salvato[i]);
    printf("\n (restore mode)dopo: ");
    for (i=0; i<5; i++){salvato[i]=iniettando[i]; printf("%x ",iniettando[i]);}
    printf("\n");
    putdata(pid,bersaglio,salvato,8);
}

variable_types:
bersaglio
unsigned long long

variable_types:
iniettando
char []


safecheck

decompiled_code:
_BOOL8 __fastcall safecheck(__int64 a1, __int64 a2)
{
char s2[6]; // [rsp+4h] [rbp-14h] BYREF
char s1[4]; // [rsp+Ah] [rbp-Eh] BYREF
__int16 v5; // [rsp+Eh] [rbp-Ah]

*(_DWORD *)s1 = -346136;
v5 = 255;
getdata(a1, a2, s2, 5LL);
return strcmp(s1, s2) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(__int64 a1, __int64 a2)
{
char s2[6]; // [rsp+4h] [rbp-14h] BYREF
char s1[4]; // [rsp+Ah] [rbp-Eh] BYREF
__int16 v5; // [rsp+Eh] [rbp-Ah]

*(_DWORD *)s1 = -346136;
v5 = 255;
getdata(a1, a2, s2, 5LL);
return strcmp(s1, s2) == 0;
}

original_code:
int safecheck(pid_t pid,unsigned long long int bersaglio)
{
    char normale[]={0xe8,0xb7,0xfa,0xff,0xff,'\0'};
    char leggi[6];
    getdata(pid, bersaglio, leggi, 5);
    if (strcmp(normale,leggi)!=0) return 0;
    return 1;
}

canonical_original_code:
int safecheck(int pid, unsigned long long bersaglio)
{
    char normale[] = {0xe8,0xb7,0xfa,0xff,0xff,'\0'};
    char leggi[6];
    getdata(pid, bersaglio, leggi, 5);
    if (strcmp(normale,leggi)!=0) return 0;
    return 1;
}

variable_types:
normale
char []

variable_types:
leggi
char [6]


printhelpNquit

decompiled_code:
void __fastcall __noreturn printhelpNquit(const char *a1)
{
puts("Chaos controller v1.3 by agentOfChaos informaniac99<AT>gmail<DOT>com");
puts(
"Small linux utility that lets you hack the libc random number generator, bypassing the C random() function and alter"
"ing the rand()'s return value.");
puts("In layman terms: if random number is god, you can be god too!\n");
printf("Usage: %s [arguments]\n", a1);
puts("Mandatory arguments: offset_mode target inject_mode");
printf("--help -h -?\tprint this help screen\n.");
puts("[offset_mode]\t\"auto\" OR \"preset\"");
puts("How the program will know the memory offset (from libc beginning) where to find rand() entry point.");
puts("\tpreset will use the value defined at compile time.");
puts("\tauto will guess it based on it's location in the current program.");
puts("[target]\tpid OR absolute_path");
puts("The target process to manipulate");
puts("\tpid of a running process. keep in mind however that you might require root privilege for that");
puts("\tabsolute_path of a child process to spawn");
puts("[inject_mode]\tnop OR num OR fix");
puts("How the program will alterate target's memory");
puts("\tnop will replace the call-to-random with NOPs (assembly opcode that does nothing)");
puts("\tfix will restore the default value (a call to the random subroutine)");
puts(
"\tnum [my_number] will replace the call-to-random with MOV [my_number] to eax, basically making rand return your own"
" number of choice.");
printf("\nExample usage (sudo may be required):\n\t%s auto $(pidof killbots) num 4\n", a1);
printf("Then, to restore the program's unaltered memory: \n\t%s auto $(pidof killbots) fix\n", a1);
exit(0);
}

canonical_decompiled_code:
void __fastcall __noreturn func0(const char *a1)
{
puts("Chaos controller v1.3 by agentOfChaos informaniac99<AT>gmail<DOT>com");
puts(
"Small linux utility that lets you hack the libc random number generator, bypassing the C random() function and alter"
"ing the rand()'s return value.");
puts("In layman terms: if random number is god, you can be god too!\n");
printf("Usage: %s [arguments]\n", a1);
puts("Mandatory arguments: offset_mode target inject_mode");
printf("--help -h -?\tprint this help screen\n.");
puts("[offset_mode]\t\"auto\" OR \"preset\"");
puts("How the program will know the memory offset (from libc beginning) where to find rand() entry point.");
puts("\tpreset will use the value defined at compile time.");
puts("\tauto will guess it based on it's location in the current program.");
puts("[target]\tpid OR absolute_path");
puts("The target process to manipulate");
puts("\tpid of a running process. keep in mind however that you might require root privilege for that");
puts("\tabsolute_path of a child process to spawn");
puts("[inject_mode]\tnop OR num OR fix");
puts("How the program will alterate target's memory");
puts("\tnop will replace the call-to-random with NOPs (assembly opcode that does nothing)");
puts("\tfix will restore the default value (a call to the random subroutine)");
puts(
"\tnum [my_number] will replace the call-to-random with MOV [my_number] to eax, basically making rand return your own"
" number of choice.");
printf("\nExample usage (sudo may be required):\n\t%s auto $(pidof killbots) num 4\n", a1);
printf("Then, to restore the program's unaltered memory: \n\t%s auto $(pidof killbots) fix\n", a1);
exit(0);
}

original_code:
void printhelpNquit(char *name)
{
    printf("Chaos controller  v1.3  by agentOfChaos  informaniac99<AT>gmail<DOT>com\n");
    printf("Small linux utility that lets you hack the libc random number generator, bypassing the C random() function and altering the rand()'s return value.\n");
    printf("In layman terms: if random number is god, you can be god too!\n\n");
    printf("Usage: %s [arguments]\n",name);
    printf("Mandatory arguments: offset_mode target inject_mode\n");
    printf("--help -h -?\tprint this help screen\n.");
    printf("[offset_mode]\t\"auto\" OR \"preset\"\n");
    printf("How the program will know the memory offset (from libc beginning) where to find rand() entry point.\n");
    printf("\tpreset will use the value defined at compile time.\n");
    printf("\tauto will guess it based on it's location in the current program.\n");
    printf("[target]\tpid OR absolute_path\n");
    printf("The target process to manipulate\n");
    printf("\tpid of a running process. keep in mind however that you might require root privilege for that\n");
    printf("\tabsolute_path of a child process to spawn\n");
    printf("[inject_mode]\tnop OR num OR fix\n");
    printf("How the program will alterate target's memory\n");
    printf("\tnop will replace the call-to-random with NOPs (assembly opcode that does nothing)\n");
    printf("\tfix will restore the default value (a call to the random subroutine)\n");
    printf("\tnum [my_number] will replace the call-to-random with MOV [my_number] to eax, basically making rand return your own number of choice.\n");
    printf("\nExample usage (sudo may be required):\n\t%s auto $(pidof killbots) num 4\n",name);
    printf("Then, to restore the program's unaltered memory: \n\t%s auto $(pidof killbots) fix\n",name);
    exit(0);
}

variable_types:
name
char *


decompiled_code:
_BOOL8 __fastcall opt_help(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-h") )
{
v1 = 1;
if ( strcmp(a1, "--help") )
v1 = strcmp(a1, "-?") == 0;
}
return v1;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(const char *a1)
{
_BOOL4 v1; // ecx

v1 = 1;
if ( strcmp(a1, "-h") )
{
v1 = 1;
if ( strcmp(a1, "--help") )
v1 = strcmp(a1, "-?") == 0;
}
return v1;
}

original_code:
int opt_help(char *opt)
{
    if (strcmp(opt,"-h")==0) return 1;
    if (strcmp(opt,"--help")==0) return 1;
    if (strcmp(opt,"-?")==0) return 1;
    return 0;
}

variable_types:
opt
char *