setErrMsg

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

if ( a1 || !g_szVBoxErrMsg )
{
va_start(arg, a2);
result = vsnprintf(&g_szVBoxErrMsg, 0x100uLL, a2, arg);
}
return result;
}

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

if ( a1 || !g_szVBoxErrMsg )
{
va_start(arg, a2);
result = vsnprintf(&g_szVBoxErrMsg, 0x100uLL, a2, arg);
}
return result;
}

original_code:
static void setErrMsg(int fAlways, const char *pszFormat, ...)
{
    if ( fAlways
        || !g_szVBoxErrMsg[0])
    {
        va_list va;
        __builtin_va_start(va,pszFormat);
        vsnprintf(g_szVBoxErrMsg, sizeof(g_szVBoxErrMsg), pszFormat, va);
        __builtin_va_end(va);
    }
}

canonical_original_code:
static void setErrMsg(int fAlways, char *pszFormat, ...)
{
    if ( fAlways
        || !g_szVBoxErrMsg[0])
    {
        __builtin_va_list va;
        __builtin_va_start(va,pszFormat);
        vsnprintf(g_szVBoxErrMsg, sizeof(g_szVBoxErrMsg), pszFormat, va);
        __builtin_va_end(va);
    }
}

variable_types: fAlways int

variable_types:
pszFormat
char *

return_type: void


VBoxCGlueInit

repo: shogsbro/vboxapi

decompiled_code:
__int64 VBoxCGlueInit()
{
char *v0; // rax
__int64 result; // rax

v0 = getenv("VBOX_APP_HOME");
if ( v0 )
return tryLoadOne(v0, 0);
g_szVBoxErrMsg = 0;
if ( (unsigned int)tryLoadOne("/opt/VirtualBox", 1) && (unsigned int)tryLoadOne("/usr/lib/virtualbox", 1) )
result = (unsigned int)-((unsigned int)tryLoadOne(0LL, 1) != 0);
else
result = 0LL;
return result;
}

canonical_decompiled_code:
__int64 func2()
{
char *v0; // rax
__int64 result; // rax

v0 = getenv("VBOX_APP_HOME");
if ( v0 )
return func1(v0, 0);
g_szVBoxErrMsg = 0;
if ( (unsigned int)func1("/opt/VirtualBox", 1) && (unsigned int)func1("/usr/lib/virtualbox", 1) )
result = (unsigned int)-((unsigned int)func1(0LL, 1) != 0);
else
result = 0LL;
return result;
}

original_code:
int VBoxCGlueInit(void)
{
    const char *pszHome = getenv("VBOX_APP_HOME");
    if (pszHome)
        return tryLoadOne(pszHome, 0);
    g_szVBoxErrMsg[0] = '\0';
    if (tryLoadOne("/opt/VirtualBox", 1) == 0)
        return 0;
    if (tryLoadOne("/usr/lib/virtualbox", 1) == 0)
        return 0;
    if (tryLoadOne(((void *)0), 1) == 0)
        return 0;
    return -1;
}

canonical_original_code:
int VBoxCGlueInit()
{
    char *pszHome = getenv("VBOX_APP_HOME");
    if (pszHome)
        return tryLoadOne(pszHome, 0);
    g_szVBoxErrMsg[0] = '\0';
    if (tryLoadOne("/opt/VirtualBox", 1) == 0)
        return 0;
    if (tryLoadOne("/usr/lib/virtualbox", 1) == 0)
        return 0;
    if (tryLoadOne(((void *)0), 1) == 0)
        return 0;
    return -1;
}

variable_types:
pszHome
char *

return_type: int


VBoxCGlueTerm

decompiled_code:
__int64 VBoxCGlueTerm()
{
__int64 result; // rax

if ( g_hVBoxXPCOMC )
g_hVBoxXPCOMC = 0LL;
result = 0LL;
g_pVBoxFuncs = 0LL;
g_pfnGetFunctions = 0LL;
memset(&g_szVBoxErrMsg, 0, 0x100uLL);
return result;
}

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

if ( g_hVBoxXPCOMC )
g_hVBoxXPCOMC = 0LL;
result = 0LL;
g_pVBoxFuncs = 0LL;
g_pfnGetFunctions = 0LL;
memset(&g_szVBoxErrMsg, 0, 0x100uLL);
return result;
}

original_code:
void VBoxCGlueTerm(void)
{
    if (g_hVBoxXPCOMC)
    {
        g_hVBoxXPCOMC = ((void *)0);
    }
    g_pVBoxFuncs = ((void *)0);
    g_pfnGetFunctions = ((void *)0);
    memset(g_szVBoxErrMsg, 0, sizeof(g_szVBoxErrMsg));
}

canonical_original_code:
void VBoxCGlueTerm()
{
    if (g_hVBoxXPCOMC)
    {
        g_hVBoxXPCOMC = ((void *)0);
    }
    g_pVBoxFuncs = ((void *)0);
    g_pfnGetFunctions = ((void *)0);
    memset(g_szVBoxErrMsg, 0, sizeof(g_szVBoxErrMsg));
}


repo: shoki/uftp

decompiled_code:
__int64 __fastcall send_multiple(__int64 a1, _WORD *a2, unsigned int a3, __int64 a4, _DWORD *a5, int a6, __int16 *a7, int a8, __int64 a9, int a10)
{
__int64 v10; // rbx
int v12; // er8
unsigned __int64 v13; // rbp
__int64 v14; // rbx
int v15; // er14
int v16; // eax
int v17; // edx
__int64 v18; // rdx
unsigned int v19; // er12
void *v20; // r15
__int64 v21; // rax
unsigned int v22; // er12
_DWORD *v24; // rdx
__int64 v25; // rcx
const char *v26; // rbx
int *v27; // rax
const char *v28; // rax
int *v29; // rax
int v30; // [rsp+Ch] [rbp-7Ch]
int v32; // [rsp+18h] [rbp-70h]
void *ptr; // [rsp+48h] [rbp-40h] BYREF

v12 = (_DWORD)a5 - ((_DWORD)a2 + 16);
v32 = v12;
if ( a8 )
{
v30 = (unsigned __int64)(encpayloadsize - v12) >> 2;
ptr = calloc(mtu + keylen, 1uLL);
if ( !ptr )
{
v29 = _errno_location();
logfunc(0LL, 0LL, showtime, 1LL, (unsigned int)*v29, 0LL, "calloc failed!", v10);
exit(1);
}
}
else
{
ptr = 0LL;
v30 = (unsigned __int64)(payloadsize - v12) >> 2;
}
if ( destcount > 0 )
{
v13 = (unsigned int)((_DWORD)&destlist + 100);
v14 = 0LL;
v15 = 1;
v16 = 0;
while ( 1 )
{
v17 = *(_DWORD *)(v13 + 2284);
if ( a3 == 4 )
break;
if ( a3 != 13 )
{
if ( a6 == v17 )
{
v18 = v16++;
a5[v18] = *(_DWORD *)v13;
}
goto LABEL_12;
}
if ( a6 == v17 )
{
v24 = (_DWORD *)(*(_QWORD *)(a1 + 80) + 32 * v14);
if ( !*v24 )
goto LABEL_24;
}
LABEL_12:
if ( v16 >= v30 || destcount - 1 == (_DWORD)v14 && v16 > 0 )
{
v19 = v32 + 4 * v16;
*a7 = _bswap_16(v16);
if ( a8 )
{
if ( !(unsigned int)encrypt_and_sign(
a2,
&ptr,
v19,
mtu,
keytype,
&groupkey,
&groupsalt,
ivlen,
hashtype,
&grouphmackey,
hmaclen,
sigtype,
privkey,
rsalen) )
{
v22 = 0;
v28 = (const char *)func_name(a3);
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Error encrypting %s", v28);
free(ptr);
return v22;
}
v20 = ptr;
v19 = (unsigned __int16)_bswap_16(*((_WORD *)ptr + 1));
}
else
{
a2[1] = _bswap_16(v19);
v20 = a2;
}
v21 = func_name(a3);
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Sending %s %d.%d", v21);
if ( (unsigned int)nb_sendto(sock, v20, v19 + 16, 0LL, a9, 16LL) == -1 )
{
v22 = 0;
v26 = (const char *)func_name(a3);
v27 = _errno_location();
logfunc(0LL, 0LL, showtime, 1LL, (unsigned int)*v27, 1LL, "Error sending %s", v26);
sleep(1u);
free(ptr);
return v22;
}
if ( packet_wait )
usleep(packet_wait);
++v14;
++v15;
v13 += 2736LL;
memset(a5, 0, 4LL * v30);
v16 = 0;
if ( destcount <= (int)v14 )
goto LABEL_19;
}
else
{
++v14;
v13 += 2736LL;
if ( destcount <= (int)v14 )
goto LABEL_19;
}
}
if ( a6 != v17 )
goto LABEL_12;
v24 = (_DWORD *)(*(_QWORD *)(a1 + 80) + 32 * v14);
if ( *v24 || !a10 && *(_DWORD *)(v13 + 4) == -1 )
goto LABEL_12;
LABEL_24:
v25 = v16++;
a5[v25] = *(_DWORD *)v13;
*v24 = 1;
goto LABEL_12;
}
LABEL_19:
v22 = 1;
free(ptr);
return v22;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _WORD *a2, unsigned int a3, __int64 a4, _DWORD *a5, int a6, __int16 *a7, int a8, __int64 a9, int a10)
{
__int64 v10; // rbx
int v12; // er8
unsigned __int64 v13; // rbp
__int64 v14; // rbx
int v15; // er14
int v16; // eax
int v17; // edx
__int64 v18; // rdx
unsigned int v19; // er12
void *v20; // r15
__int64 v21; // rax
unsigned int v22; // er12
_DWORD *v24; // rdx
__int64 v25; // rcx
const char *v26; // rbx
int *v27; // rax
const char *v28; // rax
int *v29; // rax
int v30; // [rsp+Ch] [rbp-7Ch]
int v32; // [rsp+18h] [rbp-70h]
void *ptr; // [rsp+48h] [rbp-40h] BYREF

v12 = (_DWORD)a5 - ((_DWORD)a2 + 16);
v32 = v12;
if ( a8 )
{
v30 = (unsigned __int64)(encpayloadsize - v12) >> 2;
ptr = calloc(mtu + keylen, 1uLL);
if ( !ptr )
{
v29 = _errno_location();
logfunc(0LL, 0LL, showtime, 1LL, (unsigned int)*v29, 0LL, "calloc failed!", v10);
exit(1);
}
}
else
{
ptr = 0LL;
v30 = (unsigned __int64)(payloadsize - v12) >> 2;
}
if ( destcount > 0 )
{
v13 = (unsigned int)((_DWORD)&destlist + 100);
v14 = 0LL;
v15 = 1;
v16 = 0;
while ( 1 )
{
v17 = *(_DWORD *)(v13 + 2284);
if ( a3 == 4 )
break;
if ( a3 != 13 )
{
if ( a6 == v17 )
{
v18 = v16++;
a5[v18] = *(_DWORD *)v13;
}
goto LABEL_12;
}
if ( a6 == v17 )
{
v24 = (_DWORD *)(*(_QWORD *)(a1 + 80) + 32 * v14);
if ( !*v24 )
goto LABEL_24;
}
LABEL_12:
if ( v16 >= v30 || destcount - 1 == (_DWORD)v14 && v16 > 0 )
{
v19 = v32 + 4 * v16;
*a7 = func1(v16);
if ( a8 )
{
if ( !(unsigned int)encrypt_and_sign(
a2,
&ptr,
v19,
mtu,
keytype,
&groupkey,
&groupsalt,
ivlen,
hashtype,
&grouphmackey,
hmaclen,
sigtype,
privkey,
rsalen) )
{
v22 = 0;
v28 = (const char *)func_name(a3);
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Error encrypting %s", v28);
free(ptr);
return v22;
}
v20 = ptr;
v19 = (unsigned __int16)func1(*((_WORD *)ptr + 1));
}
else
{
a2[1] = func1(v19);
v20 = a2;
}
v21 = func_name(a3);
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Sending %s %d.%d", v21);
if ( (unsigned int)nb_sendto(sock, v20, v19 + 16, 0LL, a9, 16LL) == -1 )
{
v22 = 0;
v26 = (const char *)func_name(a3);
v27 = _errno_location();
logfunc(0LL, 0LL, showtime, 1LL, (unsigned int)*v27, 1LL, "Error sending %s", v26);
sleep(1u);
free(ptr);
return v22;
}
if ( packet_wait )
usleep(packet_wait);
++v14;
++v15;
v13 += 2736LL;
memset(a5, 0, 4LL * v30);
v16 = 0;
if ( destcount <= (int)v14 )
goto LABEL_19;
}
else
{
++v14;
v13 += 2736LL;
if ( destcount <= (int)v14 )
goto LABEL_19;
}
}
if ( a6 != v17 )
goto LABEL_12;
v24 = (_DWORD *)(*(_QWORD *)(a1 + 80) + 32 * v14);
if ( *v24 || !a10 && *(_DWORD *)(v13 + 4) == -1 )
goto LABEL_12;
LABEL_24:
v25 = v16++;
a5[v25] = *(_DWORD *)v13;
*v24 = 1;
goto LABEL_12;
}
LABEL_19:
v22 = 1;
free(ptr);
return v22;
}

original_code:
int send_multiple(const struct finfo_t *finfo, unsigned char *packet,
                  int message, int attempt, uint32_t *addrlist, int state,
                  uint16_t *mes_destcount, int encrypt,
                  const struct sockaddr_in *destaddr, int regconf)
{
    struct uftp_h *header;
    int hsize, payloadlen;
    int maxdest, packetcnt, dests, i;
    unsigned char *mheader, *encpacket, *outpacket;
    header = (struct uftp_h *)packet;
    mheader = packet + sizeof(struct uftp_h);
    hsize = (unsigned char *)addrlist - mheader;
    maxdest = ((encrypt ? encpayloadsize : payloadsize) - hsize) /
              sizeof(struct in_addr);
    packetcnt = 1;
    if (encrypt) {
        encpacket = calloc(mtu + keylen, 1);
        if (encpacket == ((void *)0)) {
            logfunc(0, 0, showtime, 1, (*__errno_location ()), 0, "calloc failed!");
            exit(1);
        }
    } else {
        encpacket = ((void *)0);
    }
    for (i = 0, dests = 0; i < destcount; i++) {
        if (message == 4) {
            if ((destlist[i].status == state) &&
                    (!finfo->deststate[i].conf_sent) &&
                    (regconf || (destlist[i].proxyidx != -1))) {
                addrlist[dests++] = destlist[i].addr.s_addr;
                finfo->deststate[i].conf_sent = 1;
            }
        } else if (message == 13) {
            if ((destlist[i].status == state) &&
                    (!finfo->deststate[i].conf_sent)) {
                addrlist[dests++] = destlist[i].addr.s_addr;
                finfo->deststate[i].conf_sent = 1;
            }
        } else if (destlist[i].status == state) {
            addrlist[dests++] = destlist[i].addr.s_addr;
        }
        if ((dests >= maxdest) || ((i == destcount - 1) && (dests > 0))) {
            payloadlen = hsize + (dests * sizeof(uint32_t));
            *mes_destcount = htons(dests);
            if (encrypt) {
                if (!encrypt_and_sign(packet, &encpacket, payloadlen, mtu,
                        keytype, groupkey, groupsalt, ivlen, hashtype,
                        grouphmackey, hmaclen, sigtype, privkey, rsalen)) {
                    logfunc(0, 0, showtime, 1, 0, 0, "Error encrypting %s", func_name(message));
                    free(encpacket);
                    return 0;
                }
                outpacket = encpacket;
                payloadlen = ntohs(((struct uftp_h *)outpacket)->blsize);
            } else {
                outpacket = packet;
                header->blsize = htons(payloadlen);
            }
            logfunc(0, 0, showtime, 1, 0, 0, "Sending %s %d.%d", func_name(message), attempt, packetcnt);
            if (nb_sendto(sock, outpacket, payloadlen + sizeof(struct uftp_h),0,
                       (struct sockaddr *)destaddr,
                       sizeof(*destaddr)) == -1) {
                logfunc(0, 0, showtime, 1, (*__errno_location ()), 1, "Error sending %s", func_name(message));
                sleep(1);
                free(encpacket);
                return 0;
            }
            if (packet_wait) usleep(packet_wait);
            memset(addrlist, 0, maxdest * sizeof(uint32_t));
            dests = 0;
            packetcnt++;
        }
    }
    free(encpacket);
    return 1;
}

canonical_original_code:
int send_multiple(struct finfo_t *finfo, unsigned char *packet, int message, int attempt, unsigned int *addrlist, int state, unsigned short *mes_destcount, int encrypt, struct sockaddr_in *destaddr, int regconf)
{
    struct uftp_h *header;
    int hsize; int payloadlen;
    int maxdest; int packetcnt; int dests; int i;
    unsigned char *mheader; unsigned char *encpacket; unsigned char *outpacket;
    header = (struct uftp_h *)packet;
    mheader = packet + sizeof(struct uftp_h);
    hsize = (unsigned char *)addrlist - mheader;
    maxdest = ((encrypt ? encpayloadsize : payloadsize) - hsize) /
              sizeof(struct in_addr);
    packetcnt = 1;
    if (encrypt) {
        encpacket = calloc(mtu + keylen, 1);
        if (encpacket == ((void *)0)) {
            logfunc(0, 0, showtime, 1, (*__errno_location ()), 0, "calloc failed!");
            exit(1);
        }
    } else {
        encpacket = ((void *)0);
    }
    for (i = 0, dests = 0; i < destcount; i++) {
        if (message == 4) {
            if ((destlist[i].status == state) &&
                    (!finfo->deststate[i].conf_sent) &&
                    (regconf || (destlist[i].proxyidx != -1))) {
                addrlist[dests++] = destlist[i].addr.s_addr;
                finfo->deststate[i].conf_sent = 1;
            }
        } else if (message == 13) {
            if ((destlist[i].status == state) &&
                    (!finfo->deststate[i].conf_sent)) {
                addrlist[dests++] = destlist[i].addr.s_addr;
                finfo->deststate[i].conf_sent = 1;
            }
        } else if (destlist[i].status == state) {
            addrlist[dests++] = destlist[i].addr.s_addr;
        }
        if ((dests >= maxdest) || ((i == destcount - 1) && (dests > 0))) {
            payloadlen = hsize + (dests * sizeof(unsigned int));
            *mes_destcount = htons(dests);
            if (encrypt) {
                if (!encrypt_and_sign(packet, &encpacket, payloadlen, mtu,
                        keytype, groupkey, groupsalt, ivlen, hashtype,
                        grouphmackey, hmaclen, sigtype, privkey, rsalen)) {
                    logfunc(0, 0, showtime, 1, 0, 0, "Error encrypting %s", func_name(message));
                    free(encpacket);
                    return 0;
                }
                outpacket = encpacket;
                payloadlen = ntohs(((struct uftp_h *)outpacket)->blsize);
            } else {
                outpacket = packet;
                header->blsize = htons(payloadlen);
            }
            logfunc(0, 0, showtime, 1, 0, 0, "Sending %s %d.%d", func_name(message), attempt, packetcnt);
            if (nb_sendto(sock, outpacket, payloadlen + sizeof(struct uftp_h),0,
                       (struct sockaddr *)destaddr,
                       sizeof(*destaddr)) == -1) {
                logfunc(0, 0, showtime, 1, (*__errno_location ()), 1, "Error sending %s", func_name(message));
                sleep(1);
                free(encpacket);
                return 0;
            }
            if (packet_wait) usleep(packet_wait);
            memset(addrlist, 0, maxdest * sizeof(unsigned int));
            dests = 0;
            packetcnt++;
        }
    }
    free(encpacket);
    return 1;
}

variable_types: struct finfo_t { int ftype; char *basedir; char *filename; char *linkname; char *destfname; long size; unsigned int blocks; unsigned int sections; unsigned int group_id; unsigned short file_id; char *naklist; int partial; struct deststate_t { int conf_sent; struct timeval { long tv_sec; long tv_usec; } time; int naks; } *deststate; } *

variable_types:
packet
unsigned char *

variable_types: message int

variable_types: attempt int

variable_types:
addrlist
unsigned int *

variable_types: state int

variable_types: encrypt int

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types: regconf int

variable_types: struct uftp_h { unsigned char uftp_id; unsigned char func; unsigned short blsize; unsigned int group_id; unsigned int srcaddr; unsigned int destaddr; } *

variable_types: hsize int

variable_types: payloadlen int

variable_types: maxdest int

variable_types: packetcnt int

variable_types: dests int

variable_types: i int

variable_types:
mheader
unsigned char *

variable_types:
encpacket
unsigned char *

variable_types:
outpacket
unsigned char *

user_defined_types: struct finfo_t { int ftype; char *basedir; char *filename; char *linkname; char *destfname; long size; unsigned int blocks; unsigned int sections; unsigned int group_id; unsigned short file_id; char *naklist; int partial; struct deststate_t *deststate; }

user_defined_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr sin_addr; unsigned char sin_zero[-1]; }

user_defined_types: struct sockaddr { unsigned short sa_family; char sa_data[14]; }

user_defined_types: struct deststate_t { int conf_sent; struct timeval time; int naks; }


decompiled_code:
__int64 __fastcall validate_packet(unsigned __int8 *a1, int a2)
{
__int64 v2; // rsi
unsigned __int16 v3; // ax
__int64 v4; // rcx
__int64 v5; // rax
__int64 v6; // rcx
__int64 v7; // rdx
__int64 v8; // rdx
unsigned int v9; // er12
const char *v11; // [rsp-20h] [rbp-28h]
__int64 v12; // [rsp-18h] [rbp-20h]
__int64 v13; // [rsp-10h] [rbp-18h]

if ( *a1 == 48 )
{
v2 = a2 - 16LL;
v3 = _bswap_16(*((_WORD *)a1 + 1));
if ( v2 == v3 )
{
v5 = _bswap_32(*(_DWORD *)(v4 + 4));
v8 = *(unsigned int *)(v7 + 56);
if ( (_DWORD)v5 == (_DWORD)v8 )
{
v9 = 1;
if ( *(_BYTE *)(v6 + 1) == 80 )
{
v9 = keytype;
if ( keytype )
v9 = 1;
else
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Received encrypted packet with encryption disabled");
}
return v9;
}
v13 = v8;
v12 = v5;
v11 = "Invalid group ID %08X, expected %08X";
}
else
{
v13 = v3;
v12 = v2;
v11 = "Invalid packet size %d, expected %d";
}
v9 = 0;
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, v11, v12, v13);
return v9;
}
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Invalid version %02X", *a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int8 *a1, int a2)
{
__int64 v2; // rsi
unsigned __int16 v3; // ax
__int64 v4; // rcx
__int64 v5; // rax
__int64 v6; // rcx
__int64 v7; // rdx
__int64 v8; // rdx
unsigned int v9; // er12
const char *v11; // [rsp-20h] [rbp-28h]
__int64 v12; // [rsp-18h] [rbp-20h]
__int64 v13; // [rsp-10h] [rbp-18h]

if ( *a1 == 48 )
{
v2 = a2 - 16LL;
v3 = func1(*((_WORD *)a1 + 1));
if ( v2 == v3 )
{
v5 = func0(*(_DWORD *)(v4 + 4));
v8 = *(unsigned int *)(v7 + 56);
if ( (_DWORD)v5 == (_DWORD)v8 )
{
v9 = 1;
if ( *(_BYTE *)(v6 + 1) == 80 )
{
v9 = keytype;
if ( keytype )
v9 = 1;
else
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Received encrypted packet with encryption disabled");
}
return v9;
}
v13 = v8;
v12 = v5;
v11 = "Invalid group ID %08X, expected %08X";
}
else
{
v13 = v3;
v12 = v2;
v11 = "Invalid packet size %d, expected %d";
}
v9 = 0;
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, v11, v12, v13);
return v9;
}
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Invalid version %02X", *a1);
return 0LL;
}

original_code:
int validate_packet(const unsigned char *packet, int len,
                    const struct finfo_t *finfo)
{
    struct uftp_h *header;
    header = (struct uftp_h *)packet;
    if (header->uftp_id != 0x30) {
        logfunc(0, 0, showtime, 1, 0, 0, "Invalid version %02X", header->uftp_id);
        return 0;
    }
    if (len - sizeof(struct uftp_h) != ntohs(header->blsize)) {
        logfunc(0, 0, showtime, 1, 0, 0, "Invalid packet size %d, expected %d", len - sizeof(struct uftp_h), ntohs(header->blsize));
        return 0;
    }
    if (ntohl(header->group_id) != finfo->group_id) {
        logfunc(0, 0, showtime, 1, 0, 0, "Invalid group ID %08X, expected %08X", ntohl(header->group_id), finfo->group_id);
        return 0;
    }
    if ((header->func == 80) && (keytype == 0x00)) {
        logfunc(0, 0, showtime, 1, 0, 0, "Received encrypted packet with encryption disabled");
        return 0;
    }
    return 1;
}

canonical_original_code:
int validate_packet(unsigned char *packet, int len, struct finfo_t *finfo)
{
    struct uftp_h *header;
    header = (struct uftp_h *)packet;
    if (header->uftp_id != 0x30) {
        logfunc(0, 0, showtime, 1, 0, 0, "Invalid version %02X", header->uftp_id);
        return 0;
    }
    if (len - sizeof(struct uftp_h) != ntohs(header->blsize)) {
        logfunc(0, 0, showtime, 1, 0, 0, "Invalid packet size %d, expected %d", len - sizeof(struct uftp_h), ntohs(header->blsize));
        return 0;
    }
    if (ntohl(header->group_id) != finfo->group_id) {
        logfunc(0, 0, showtime, 1, 0, 0, "Invalid group ID %08X, expected %08X", ntohl(header->group_id), finfo->group_id);
        return 0;
    }
    if ((header->func == 80) && (keytype == 0x00)) {
        logfunc(0, 0, showtime, 1, 0, 0, "Received encrypted packet with encryption disabled");
        return 0;
    }
    return 1;
}

variable_types:
packet
unsigned char *

variable_types: len int

variable_types: struct finfo_t { int ftype; char *basedir; char *filename; char *linkname; char *destfname; long size; unsigned int blocks; unsigned int sections; unsigned int group_id; unsigned short file_id; char *naklist; int partial; struct deststate_t { int conf_sent; struct timeval { long tv_sec; long tv_usec; } time; int naks; } *deststate; } *

user_defined_types: struct uftp_h { unsigned char uftp_id; unsigned char func; unsigned short blsize; unsigned int group_id; unsigned int srcaddr; unsigned int destaddr; }


decompiled_code:
__int64 __fastcall client_error(int a1)
{
int v1; // edx

v1 = destlist[684 * a1 + 596];
return (v1 == -2) | (unsigned __int8)((unsigned int)(v1 + 4) <= 1);
}

canonical_decompiled_code:
__int64 __fastcall func7(int a1)
{
int v1; // edx

v1 = destlist[684 * a1 + 596];
return (v1 == -2) | (unsigned __int8)((unsigned int)(v1 + 4) <= 1);
}

original_code:
int client_error(int listidx)
{
    return ((destlist[listidx].status == DEST_MUTE) ||
            (destlist[listidx].status == DEST_LOST) ||
            (destlist[listidx].status == DEST_ABORT));
}

variable_types: listidx int


decompiled_code:
__int64 __fastcall set_uftp_header(__int64 a1, char a2, __int64 a3)
{
int v3; // eax
_DWORD *v4; // r8
__int64 v5; // rcx
__int64 result; // rax

*(_BYTE *)a1 = 48;
*(_BYTE *)(a1 + 1) = a2;
*(_WORD *)(a1 + 2) = 0;
v3 = _bswap_32(*(_DWORD *)(a3 + 56));
v4[1] = v3;
v4[2] = out_addr;
result = *(unsigned int *)(v5 + 4);
v4[3] = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, char a2, __int64 a3)
{
int v3; // eax
_DWORD *v4; // r8
__int64 v5; // rcx
__int64 result; // rax

*(_BYTE *)a1 = 48;
*(_BYTE *)(a1 + 1) = a2;
*(_WORD *)(a1 + 2) = 0;
v3 = func0(*(_DWORD *)(a3 + 56));
v4[1] = v3;
v4[2] = out_addr;
result = *(unsigned int *)(v5 + 4);
v4[3] = result;
return result;
}

original_code:
void set_uftp_header(struct uftp_h *header, int func,
                     const struct finfo_t *finfo,
                     const struct sockaddr_in *dest)
{
    header->uftp_id = 0x30;
    header->func = func;
    header->blsize = 0;
    header->group_id = htonl(finfo->group_id);
    header->srcaddr = out_addr.s_addr;
    header->destaddr = dest->sin_addr.s_addr;
}

canonical_original_code:
void set_uftp_header(struct uftp_h *header, int func, struct finfo_t *finfo, struct sockaddr_in *dest)
{
    header->uftp_id = 0x30;
    header->func = func;
    header->blsize = 0;
    header->group_id = htonl(finfo->group_id);
    header->srcaddr = out_addr.s_addr;
    header->destaddr = dest->sin_addr.s_addr;
}

variable_types: func int

user_defined_types: struct timeval { long tv_sec; long tv_usec; }


decompiled_code:
void __fastcall send_abort(__int64 a1, const char *a2, __int64 a3, _DWORD *a4, int a5)
{
_BYTE *v8; // rax
_BYTE *v9; // rbp
void *v10; // rsi
__int64 v11; // rdx
int *v12; // rax
int *v13; // rax
__int64 v14; // rcx
__int64 v15; // [rsp-8h] [rbp-50h]
void *ptr; // [rsp+8h] [rbp-40h] BYREF

v8 = calloc(mtu, 1uLL);
if ( !v8 )
{
v13 = _errno_location();
logfunc(0LL, 0LL, showtime, 1LL, (unsigned int)*v13, 0LL, "calloc failed!", v14);
exit(1);
}
v9 = v8;
set_uftp_header((__int64)v8, 99, a1);
v9[16] = 99;
if ( a4 )
*((_DWORD *)v9 + 5) = *a4;
strncpy(v9 + 24, a2, 0x12BuLL);
ptr = 0LL;
if ( a5 )
{
if ( !(unsigned int)encrypt_and_sign(
v9,
&ptr,
308LL,
mtu,
keytype,
&groupkey,
&groupsalt,
ivlen,
hashtype,
&grouphmackey,
hmaclen,
sigtype,
privkey,
rsalen) )
{
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Error encrypting ABORT", v15);
free(v9);
return;
}
v10 = ptr;
v11 = (unsigned int)(unsigned __int16)_bswap_16(*((_WORD *)ptr + 1)) + 16;
}
else
{
v10 = v9;
*((_WORD *)v9 + 1) = _bswap_16(308);
}
if ( (unsigned int)nb_sendto(sock, v10, v11, 0LL, a3, 16LL) == -1 )
{
v12 = _errno_location();
logfunc(0LL, 0LL, showtime, 1LL, (unsigned int)*v12, 1LL, "Error sending ABORT", v15);
}
free(v9);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func3(__int64 a1, const char *a2, __int64 a3, _DWORD *a4, int a5)
{
_BYTE *v8; // rax
_BYTE *v9; // rbp
void *v10; // rsi
__int64 v11; // rdx
int *v12; // rax
int *v13; // rax
__int64 v14; // rcx
__int64 v15; // [rsp-8h] [rbp-50h]
void *ptr; // [rsp+8h] [rbp-40h] BYREF

v8 = calloc(mtu, 1uLL);
if ( !v8 )
{
v13 = _errno_location();
logfunc(0LL, 0LL, showtime, 1LL, (unsigned int)*v13, 0LL, "calloc failed!", v14);
exit(1);
}
v9 = v8;
func2((__int64)v8, 99, a1);
v9[16] = 99;
if ( a4 )
*((_DWORD *)v9 + 5) = *a4;
strncpy(v9 + 24, a2, 0x12BuLL);
ptr = 0LL;
if ( a5 )
{
if ( !(unsigned int)encrypt_and_sign(
v9,
&ptr,
308LL,
mtu,
keytype,
&groupkey,
&groupsalt,
ivlen,
hashtype,
&grouphmackey,
hmaclen,
sigtype,
privkey,
rsalen) )
{
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Error encrypting ABORT", v15);
free(v9);
return;
}
v10 = ptr;
v11 = (unsigned int)(unsigned __int16)func1(*((_WORD *)ptr + 1)) + 16;
}
else
{
v10 = v9;
*((_WORD *)v9 + 1) = func1(308);
}
if ( (unsigned int)nb_sendto(sock, v10, v11, 0LL, a3, 16LL) == -1 )
{
v12 = _errno_location();
logfunc(0LL, 0LL, showtime, 1LL, (unsigned int)*v12, 1LL, "Error sending ABORT", v15);
}
free(v9);
free(ptr);
}

original_code:
void send_abort(const struct finfo_t *finfo, const char *message,
                const struct sockaddr_in *destaddr,
                const struct in_addr *dest, int encrypt)
{
    unsigned char *buf, *encrypted, *outpacket;
    struct uftp_h *header;
    struct abort_h *abort;
    int payloadlen;
    buf = calloc(mtu, 1);
    if (buf == ((void *)0)) {
        logfunc(0, 0, showtime, 1, (*__errno_location ()), 0, "calloc failed!");
        exit(1);
    }
    header = (struct uftp_h *)buf;
    abort = (struct abort_h *)(buf + sizeof(struct uftp_h));
    set_uftp_header(header, 99, finfo, destaddr);
    abort->func = 99;
    if (dest) {
        abort->host = dest->s_addr;
    }
    strncpy(abort->message, message, sizeof(abort->message) - 1);
    payloadlen = sizeof(struct abort_h);
    if (encrypt) {
        encrypted = ((void *)0);
        if (!encrypt_and_sign(buf, &encrypted, payloadlen, mtu, keytype,
                groupkey, groupsalt, ivlen, hashtype, grouphmackey, hmaclen,
                sigtype, privkey, rsalen)) {
            logfunc(0, 0, showtime, 1, 0, 0, "Error encrypting ABORT");
            free(buf);
            return;
        }
        outpacket = encrypted;
        payloadlen = ntohs(((struct uftp_h *)outpacket)->blsize);
    } else {
        encrypted = ((void *)0);
        outpacket = buf;
        header->blsize = htons(payloadlen);
    }
    if (nb_sendto(sock, outpacket, payloadlen + sizeof(struct uftp_h), 0,
               (struct sockaddr *)destaddr,
               sizeof(struct sockaddr_in)) == -1) {
        logfunc(0, 0, showtime, 1, (*__errno_location ()), 1, "Error sending ABORT");
    }
    free(buf);
    free(encrypted);
}

canonical_original_code:
void send_abort(struct finfo_t *finfo, char *message, struct sockaddr_in *destaddr, struct in_addr *dest, int encrypt)
{
    unsigned char *buf; unsigned char *encrypted; unsigned char *outpacket;
    struct uftp_h *header;
    struct abort_h *abort;
    int payloadlen;
    buf = calloc(mtu, 1);
    if (buf == ((void *)0)) {
        logfunc(0, 0, showtime, 1, (*__errno_location ()), 0, "calloc failed!");
        exit(1);
    }
    header = (struct uftp_h *)buf;
    abort = (struct abort_h *)(buf + sizeof(struct uftp_h));
    set_uftp_header(header, 99, finfo, destaddr);
    abort->func = 99;
    if (dest) {
        abort->host = dest->s_addr;
    }
    strncpy(abort->message, message, sizeof(abort->message) - 1);
    payloadlen = sizeof(struct abort_h);
    if (encrypt) {
        encrypted = ((void *)0);
        if (!encrypt_and_sign(buf, &encrypted, payloadlen, mtu, keytype,
                groupkey, groupsalt, ivlen, hashtype, grouphmackey, hmaclen,
                sigtype, privkey, rsalen)) {
            logfunc(0, 0, showtime, 1, 0, 0, "Error encrypting ABORT");
            free(buf);
            return;
        }
        outpacket = encrypted;
        payloadlen = ntohs(((struct uftp_h *)outpacket)->blsize);
    } else {
        encrypted = ((void *)0);
        outpacket = buf;
        header->blsize = htons(payloadlen);
    }
    if (nb_sendto(sock, outpacket, payloadlen + sizeof(struct uftp_h), 0,
               (struct sockaddr *)destaddr,
               sizeof(struct sockaddr_in)) == -1) {
        logfunc(0, 0, showtime, 1, (*__errno_location ()), 1, "Error sending ABORT");
    }
    free(buf);
    free(encrypted);
}

variable_types:
message
char *

variable_types: struct sockaddr_in { unsigned short sin_family; unsigned short sin_port; struct in_addr { unsigned int s_addr; } sin_addr; unsigned char sin_zero[-1]; } *

variable_types:
dest
struct in_addr *

variable_types: encrypt int

variable_types:
buf
unsigned char *

variable_types:
encrypted
unsigned char *

variable_types: struct abort_h { unsigned char func; unsigned char reserved1; unsigned short reserved2; unsigned int host; char message[300]; } *


decompiled_code:
__int64 __fastcall find_client(int a1)
{
unsigned __int64 v1; // rdx
__int64 result; // rax

if ( destcount <= 0 )
return 0xFFFFFFFFLL;
v1 = (unsigned int)((_DWORD)&destlist + 100);
result = 0LL;
while ( *(_DWORD *)v1 != a1 )
{
result = (unsigned int)(result + 1);
v1 += 2736LL;
if ( (_DWORD)result == destcount )
return 0xFFFFFFFFLL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func6(int a1)
{
unsigned __int64 v1; // rdx
__int64 result; // rax

if ( destcount <= 0 )
return 0xFFFFFFFFLL;
v1 = (unsigned int)((_DWORD)&destlist + 100);
result = 0LL;
while ( *(_DWORD *)v1 != a1 )
{
result = (unsigned int)(result + 1);
v1 += 2736LL;
if ( (_DWORD)result == destcount )
return 0xFFFFFFFFLL;
}
return result;
}

original_code:
int find_client(uint32_t addr)
{
    int i;
    for (i = 0; i < destcount; i++) {
        if (destlist[i].addr.s_addr == addr) {
            return i;
        }
    }
    return -1;
}

canonical_original_code:
int find_client(unsigned int addr)
{
    int i;
    for (i = 0; i < destcount; i++) {
        if (destlist[i].addr.s_addr == addr) {
            return i;
        }
    }
    return -1;
}

variable_types:
addr
unsigned int


decompiled_code:
void __fastcall handle_abort(__int64 a1, int a2, int a3, __int64 a4, struct in_addr *a5)
{
char *v5; // rax
const char *v6; // rbx
int v7; // edi
struct in_addr *v9; // r8
__int64 v10; // rdx
__int64 v11; // rsi
unsigned __int64 v12; // rax
int v13; // edx
char *v14; // rax
char *v15; // [rsp-18h] [rbp-30h]

if ( a2 == 308 )
{
v6 = (const char *)(a1 + 8);
if ( a3 == -1 )
{
v14 = inet_ntoa((struct in_addr)a5->s_addr);
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Transfer aborted by %s: %s", v14, v6);
}
else
{
v7 = *(_DWORD *)(a1 + 4);
if ( v7 && (a3 = find_client(v7), a3 == -1) )
{
v15 = inet_ntoa((struct in_addr)v9->s_addr);
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Transfer aborted by %s: %s", v15, v6);
}
else
{
v10 = 684LL * a3;
destlist[v10 + 596] = -2;
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Transfer aborted by %s: %s", (const char *)&destlist[v10], v6);
}
if ( quit_on_error )
{
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Aboring all clients");
send_abort(a4, "A client aborted, aborting all", (__int64)&receive_dest, 0LL, 0);
if ( keytype )
send_abort(a4, "A client aborted, aborting all", (__int64)&receive_dest, 0LL, 1);
if ( destcount > 0 )
{
v11 = 2736LL * destcount;
v12 = 0LL;
do
{
v13 = destlist[v12 / 4 + 596];
if ( (unsigned int)(v13 + 1) <= 1 || v13 == 1 )
destlist[v12 / 4 + 596] = -2;
v12 += 2736LL;
}
while ( v11 != v12 );
}
}
}
}
else
{
if ( a3 == -1 )
v5 = inet_ntoa((struct in_addr)a5->s_addr);
else
v5 = (char *)&destlist[684 * a3];
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Rejecting ABORT from %s: invalid message size", v5);
}
}

canonical_decompiled_code:
void __fastcall func8(__int64 a1, int a2, int a3, __int64 a4, struct in_addr *a5)
{
char *v5; // rax
const char *v6; // rbx
int v7; // edi
struct in_addr *v9; // r8
__int64 v10; // rdx
__int64 v11; // rsi
unsigned __int64 v12; // rax
int v13; // edx
char *v14; // rax
char *v15; // [rsp-18h] [rbp-30h]

if ( a2 == 308 )
{
v6 = (const char *)(a1 + 8);
if ( a3 == -1 )
{
v14 = inet_ntoa((struct in_addr)a5->s_addr);
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Transfer aborted by %s: %s", v14, v6);
}
else
{
v7 = *(_DWORD *)(a1 + 4);
if ( v7 && (a3 = func6(v7), a3 == -1) )
{
v15 = inet_ntoa((struct in_addr)v9->s_addr);
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Transfer aborted by %s: %s", v15, v6);
}
else
{
v10 = 684LL * a3;
destlist[v10 + 596] = -2;
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Transfer aborted by %s: %s", (const char *)&destlist[v10], v6);
}
if ( quit_on_error )
{
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Aboring all clients");
func3(a4, "A client aborted, aborting all", (__int64)&receive_dest, 0LL, 0);
if ( keytype )
func3(a4, "A client aborted, aborting all", (__int64)&receive_dest, 0LL, 1);
if ( destcount > 0 )
{
v11 = 2736LL * destcount;
v12 = 0LL;
do
{
v13 = destlist[v12 / 4 + 596];
if ( (unsigned int)(v13 + 1) <= 1 || v13 == 1 )
destlist[v12 / 4 + 596] = -2;
v12 += 2736LL;
}
while ( v11 != v12 );
}
}
}
}
else
{
if ( a3 == -1 )
v5 = inet_ntoa((struct in_addr)a5->s_addr);
else
v5 = (char *)&destlist[684 * a3];
logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Rejecting ABORT from %s: invalid message size", v5);
}
}

original_code:
void handle_abort(const unsigned char *message, int meslen, int idx,
                  struct finfo_t *finfo, const struct in_addr *hostaddr)
{
    struct abort_h *abort;
    int i;
    abort = (struct abort_h *)message;
    if (meslen != sizeof(struct abort_h)) {
        logfunc(0, 0, showtime, 1, 0, 0, "Rejecting ABORT from %s: invalid message size", (idx == -1) ? inet_ntoa(*hostaddr) : destlist[idx].name);
        return;
    }
    if (idx == -1) {
        logfunc(0, 0, showtime, 1, 0, 0, "Transfer aborted by %s: %s", inet_ntoa(*hostaddr), abort->message);
        return;
    }
    if (abort->host != 0) {
        idx = find_client(abort->host);
    }
    if (idx == -1) {
        logfunc(0, 0, showtime, 1, 0, 0, "Transfer aborted by %s: %s", inet_ntoa(*hostaddr), abort->message);
    } else {
        destlist[idx].status = DEST_ABORT;
        logfunc(0, 0, showtime, 1, 0, 0, "Transfer aborted by %s: %s", destlist[idx].name, abort->message);
    }
    if (quit_on_error) {
        logfunc(0, 0, showtime, 1, 0, 0, "Aboring all clients");
        send_abort(finfo, "A client aborted, aborting all",
                &receive_dest, ((void *)0), 0);
        if (keytype != 0x00) {
            send_abort(finfo, "A client aborted, aborting all",
                    &receive_dest, ((void *)0), 1);
        }
        for (i = 0; i < destcount; i++) {
            if ((destlist[i].status == DEST_ACTIVE) ||
                    (destlist[i].status == DEST_REGISTERED) ||
                    (destlist[i].status == DEST_STATUS)) {
                destlist[i].status = DEST_ABORT;
            }
        }
    }
}

canonical_original_code:
void handle_abort(unsigned char *message, int meslen, int idx, struct finfo_t *finfo, struct in_addr *hostaddr)
{
    struct abort_h *abort;
    int i;
    abort = (struct abort_h *)message;
    if (meslen != sizeof(struct abort_h)) {
        logfunc(0, 0, showtime, 1, 0, 0, "Rejecting ABORT from %s: invalid message size", (idx == -1) ? inet_ntoa(*hostaddr) : destlist[idx].name);
        return;
    }
    if (idx == -1) {
        logfunc(0, 0, showtime, 1, 0, 0, "Transfer aborted by %s: %s", inet_ntoa(*hostaddr), abort->message);
        return;
    }
    if (abort->host != 0) {
        idx = find_client(abort->host);
    }
    if (idx == -1) {
        logfunc(0, 0, showtime, 1, 0, 0, "Transfer aborted by %s: %s", inet_ntoa(*hostaddr), abort->message);
    } else {
        destlist[idx].status = DEST_ABORT;
        logfunc(0, 0, showtime, 1, 0, 0, "Transfer aborted by %s: %s", destlist[idx].name, abort->message);
    }
    if (quit_on_error) {
        logfunc(0, 0, showtime, 1, 0, 0, "Aboring all clients");
        send_abort(finfo, "A client aborted, aborting all",
                &receive_dest, ((void *)0), 0);
        if (keytype != 0x00) {
            send_abort(finfo, "A client aborted, aborting all",
                    &receive_dest, ((void *)0), 1);
        }
        for (i = 0; i < destcount; i++) {
            if ((destlist[i].status == DEST_ACTIVE) ||
                    (destlist[i].status == DEST_REGISTERED) ||
                    (destlist[i].status == DEST_STATUS)) {
                destlist[i].status = DEST_ABORT;
            }
        }
    }
}

variable_types:
message
unsigned char *

variable_types: meslen int

variable_types: idx int

variable_types: struct in_addr { unsigned int s_addr; } *

variable_types: i int

user_defined_types: struct abort_h { unsigned char func; unsigned char reserved1; unsigned short reserved2; unsigned int host; char message[300]; }


gotpipe

decompiled_code:
__int64 gotpipe()
{
return logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Got SIGPIPE");
}

canonical_decompiled_code:
__int64 func1()
{
return logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Got SIGPIPE");
}

original_code:
void gotpipe(int sig)
{
    logfunc(0, 0, showtime, 1, 0, 0, "Got SIGPIPE");
}

variable_types: sig int


gotsig

decompiled_code:
void __noreturn gotsig()
{
__int64 v0; // [rsp+0h] [rbp-10h]

logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Exiting on signal %d", v0);
exit(0);
}

canonical_decompiled_code:
void __noreturn func2()
{
__int64 v0; // [rsp+0h] [rbp-10h]

logfunc(0LL, 0LL, showtime, 1LL, 0LL, 0LL, "Exiting on signal %d", v0);
exit(0);
}

original_code:
void gotsig(int sig)
{
    logfunc(0, 0, showtime, 1, 0, 0, "Exiting on signal %d", sig);
    exit(0);
}


decompiled_code:
__int64 __fastcall add_server_by_name(char *name, __int64 a2)
{
int v2; // ebx
__int64 v3; // rbp
__int64 result; // rax
struct hostent *v5; // rax
__int64 v6; // rbx

if ( inet_addr(name) == -1 )
{
v5 = gethostbyname(name);
if ( !v5 )
{
fprintf(stderr, "Invalid host name: %s\n", name);
exit(1);
}
v6 = 10LL * server_count;
server_keys[v6] = **(_DWORD **)v5->h_addr_list;
result = parse_fingerprint(&server_keys[v6 + 2], a2);
++server_count;
server_keys[v6 + 1] = result;
}
else
{
v2 = server_count;
server_keys[10 * v2] = inet_addr(name);
v3 = 10LL * server_count;
result = parse_fingerprint(&server_keys[v3 + 2], a2);
++server_count;
server_keys[v3 + 1] = result;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *name, __int64 a2)
{
int v2; // ebx
__int64 v3; // rbp
__int64 result; // rax
struct hostent *v5; // rax
__int64 v6; // rbx

if ( inet_addr(name) == -1 )
{
v5 = gethostbyname(name);
if ( !v5 )
{
fprintf(stderr, "Invalid host name: %s\n", name);
exit(1);
}
v6 = 10LL * server_count;
server_keys[v6] = **(_DWORD **)v5->h_addr_list;
result = parse_fingerprint(&server_keys[v6 + 2], a2);
++server_count;
server_keys[v6 + 1] = result;
}
else
{
v2 = server_count;
server_keys[10 * v2] = inet_addr(name);
v3 = 10LL * server_count;
result = parse_fingerprint(&server_keys[v3 + 2], a2);
++server_count;
server_keys[v3 + 1] = result;
}
return result;
}

original_code:
void add_server_by_name(const char *server, const char *fingerprint)
{
    struct hostent *hp;
    struct in_addr *addr;
    if (inet_addr(server) == ((in_addr_t) 0xffffffff)) {
        if ((hp = gethostbyname(server)) == ((void *)0)) {
            fprintf(stderr, "Invalid host name: %s\n", server);
            exit(1);
        } else {
            addr = (struct in_addr *)hp->h_addr_list[0];
            server_keys[server_count].addr = *addr;
            server_keys[server_count].has_fingerprint =
                    parse_fingerprint(server_keys[server_count].fingerprint,
                                      fingerprint);
            server_count++;
        }
    } else {
        server_keys[server_count].addr.s_addr = inet_addr(server);
        server_keys[server_count].has_fingerprint =
                parse_fingerprint(server_keys[server_count].fingerprint,
                                  fingerprint);
        server_count++;
    }
}

canonical_original_code:
void add_server_by_name(char *server, char *fingerprint)
{
    struct hostent *hp;
    struct in_addr *addr;
    if (inet_addr(server) == ((unsigned int) 0xffffffff)) {
        if ((hp = gethostbyname(server)) == ((void *)0)) {
            fprintf(stderr, "Invalid host name: %s\n", server);
            exit(1);
        } else {
            addr = (struct in_addr *)hp->h_addr_list[0];
            server_keys[server_count].addr = *addr;
            server_keys[server_count].has_fingerprint =
                    parse_fingerprint(server_keys[server_count].fingerprint,
                                      fingerprint);
            server_count++;
        }
    } else {
        server_keys[server_count].addr.s_addr = inet_addr(server);
        server_keys[server_count].has_fingerprint =
                parse_fingerprint(server_keys[server_count].fingerprint,
                                  fingerprint);
        server_count++;
    }
}

variable_types:
server
char *

variable_types:
fingerprint
char *

variable_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; } *


decompiled_code:
__int64 __fastcall process_args(int argc, char **argv)
{
int v3; // eax
char *i; // rsi
int v5; // er12
char *v6; // rax
FILE *v7; // r12
size_t v8; // rax
char v9; // dl
char *v10; // rax
char *v11; // r13
char *v12; // rax
char *v13; // r12
char *v14; // r13
in_addr_t v15; // eax
int v16; // eax
unsigned __int64 v17; // rax
char *v18; // r12
__int64 v19; // r13
__int64 v20; // rdx
const __m128i *v21; // rax
__m128i v22; // xmm3
__m128i v23; // xmm4
__m128i *v24; // rdx
int v25; // eax
in_addr_t *v26; // rax
int v27; // eax
__int64 v28; // rdx
__m128i v29; // xmm1
__m128i v30; // xmm2
struct hostent *v31; // rax
__int64 result; // rax
int v33; // ebx
struct hostent *v34; // rax
char *v35; // rdx
int *v36; // rax
char *v37; // rax
in_addr_t v38; // [rsp+Ch] [rbp-44Ch] BYREF
char shortopts[16]; // [rsp+10h] [rbp-448h] BYREF
__m128i v40; // [rsp+20h] [rbp-438h]
char v41[8]; // [rsp+30h] [rbp-428h] BYREF
char s[1048]; // [rsp+40h] [rbp-418h] BYREF

strcpy(v41, ":m");
*(__m128i *)shortopts = _mm_load_si128((const __m128i *)&LC21);
v40 = _mm_load_si128((const __m128i *)&LC22);
set_defaults();
LABEL_2:
while ( 2 )
{
v3 = getopt(argc, argv, shortopts);
if ( v3 != -1 )
{
switch ( v3 )
{
case '?':
fwrite(
"uftpd [ -d ] [ -n ] [ -p port ] [ -B buf_size ]\n"
" [ -E ] [ -Q dscp ] [ -U UID ] [ -T temp_dir ] [ -D dest_dir ]\n"
" [ -L logfile ] [ -P pidfile ] [ -S serverlist_file ] [ -R proxy[/fp] ]\n"
" [ -k keyfile[,keyfile...] ] [ -K new_key_length ] [ -m ]\n"
" [ -I interface[,interface...] ] [ -M pub_mcast_addr[,pub_mcast_addr...] ]\n",
1uLL,
0x148uLL,
stderr);
exit(1);
case 'B':
buffer = atoi(optarg);
if ( (unsigned int)(buffer - (_DWORD)&unk_10000) > 0x63F0000 )
{
fwrite("Invalid buffer size\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
continue;
case 'D':
strncpy(destdir, optarg, 0xC7uLL);
destdir[199] = 0;
continue;
case 'E':
encrypted_only = 1;
continue;
case 'I':
v13 = strtok(optarg, ",");
LABEL_47:
if ( !v13 )
continue;
v25 = getifbyname(v13, ifl, (unsigned int)ifl_len);
if ( v25 != -1 )
{
v20 = interface_count;
v21 = (const __m128i *)((char *)ifl + 40 * v25);
v22 = _mm_loadu_si128(v21);
++interface_count;
v23 = _mm_loadu_si128(v21 + 1);
v24 = (__m128i *)((char *)m_interface + 40 * v20);
*v24 = v22;
v24[1] = v23;
LABEL_46:
v24[2].m128i_i64[0] = v21[2].m128i_i64[0];
v13 = strtok(0LL, ",");
goto LABEL_47;
}
if ( inet_addr(v13) == -1 )
{
v31 = gethostbyname(v13);
if ( !v31 )
{
LABEL_75:
fprintf(stderr, "Invalid host name: %s\n", v13);
exit(1);
}
v26 = (in_addr_t *)*v31->h_addr_list;
}
else
{
v38 = inet_addr(v13);
v26 = &v38;
}
v27 = getifbyaddr(*v26, ifl, (unsigned int)ifl_len);
if ( v27 != -1 )
{
v28 = interface_count;
v21 = (const __m128i *)((char *)ifl + 40 * v27);
v29 = _mm_loadu_si128(v21);
++interface_count;
v30 = _mm_loadu_si128(v21 + 1);
v24 = (__m128i *)((char *)m_interface + 40 * v28);
*v24 = v29;
v24[1] = v30;
goto LABEL_46;
}
fprintf(stderr, "Interface %s not found\n", v13);
break;
case 'K':
newkeylen = atoi(optarg);
if ( (unsigned int)(newkeylen - 512) > 0x600 )
{
fwrite("Invalid new key length\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
continue;
case 'L':
strncpy(logfile, optarg, 0x12BuLL);
logfile[299] = 0;
continue;
case 'M':
v18 = strtok(optarg, ",");
if ( !v18 )
continue;
while ( 1 )
{
v19 = pub_multi_count;
*(&pub_multi.s_addr + v19) = inet_addr(v18);
if ( *(&pub_multi.s_addr + pub_multi_count) == -1
|| !(unsigned int)is_multicast(*(&pub_multi.s_addr + pub_multi_count), 0LL) )
{
break;
}
++pub_multi_count;
v18 = strtok(0LL, ",");
if ( !v18 )
goto LABEL_2;
}
fprintf(stderr, "Invalid multicast address: %s\n", v18);
break;
case 'P':
strncpy(pidfile, optarg, 0x12BuLL);
pidfile[299] = 0;
continue;
case 'Q':
v17 = strtol(optarg, 0LL, 0);
if ( v17 > 0x3F )
{
fwrite("Invalid dscp\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
dscp = 4 * v17;
continue;
case 'R':
strncpy(s, optarg, 0x3E8uLL);
s[999] = 0;
v13 = strtok(s, "/");
if ( !v13 )
{
fwrite("Invalid host name\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
v14 = strtok(0LL, "/");
if ( inet_addr(v13) == -1 )
{
v34 = gethostbyname(v13);
if ( !v34 )
goto LABEL_75;
v15 = **(_DWORD **)v34->h_addr_list;
}
else
{
v15 = inet_addr(v13);
}
proxy_info[0] = v15;
v16 = parse_fingerprint((unsigned int)((_DWORD)proxy_info + 8), v14);
has_proxy = 1;
proxy_info[1] = v16;
continue;
case 'S':
v7 = fopen(optarg, "r");
if ( !v7 )
{
v36 = _errno_location();
v37 = strerror(*v36);
fprintf(stderr, "Couldn't open server list %s: %s\n", optarg, v37);
exit(1);
}
while ( fgets(s, 1000, v7) )
{
while ( 1 )
{
v8 = strlen(s) - 1;
v9 = s[v8];
if ( v9 != 13 && v9 != 10 )
break;
s[v8] = 0;
}
v10 = strtok(s, " \t");
v11 = v10;
if ( v10 && *v10 != 35 )
{
if ( strlen(v10) > 0x64 )
{
fwrite("Server list: name too long\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
v12 = strtok(0LL, " \t");
add_server_by_name(v11, (__int64)v12);
}
}
if ( !feof(v7) && ferror(v7) )
{
perror("Failed to read from server list file");
exit(1);
}
fclose(v7);
continue;
case 'T':
strncpy(tempdir, optarg, 0xC7uLL);
tempdir[199] = 0;
continue;
case 'U':
uid = inet_addr(optarg);
if ( uid )
{
if ( (unsigned int)_bswap_32(uid) > 0xFFFFFF )
goto LABEL_15;
}
else
{
uid = strtol(optarg, 0LL, 16);
if ( (unsigned int)(uid - 1) > 0xFFFFFE )
{
LABEL_15:
fwrite("Invalid UID\n", 1uLL, 0xCuLL, stderr);
exit(1);
}
uid = _bswap_32(uid);
}
continue;
case 'd':
debug = 1;
continue;
case 'k':
for ( i = strtok(optarg, ","); i; i = strtok(0LL, ",") )
{
v5 = keyfile_count + 1;
v6 = strncpy((char *)&keyfile[75 * keyfile_count], i, 0x12BuLL);
keyfile_count = v5;
v6[299] = 0;
}
continue;
case 'm':
sys_keys = 1;
continue;
case 'n':
noname = 1;
continue;
case 'p':
port = atoi(optarg);
if ( !port )
{
fwrite("Invalid port\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
continue;
case 'v':
verbose = atoi(optarg);
continue;
default:
continue;
}
LABEL_40:
exit(1);
}
break;
}
result = (unsigned int)server_count;
if ( server_count )
{
result = (unsigned int)pub_multi_count;
if ( pub_multi_count > 0 )
{
v33 = 0;
while ( (unsigned int)is_multicast(*(&pub_multi.s_addr + v33), 1LL) )
{
result = (unsigned int)pub_multi_count;
if ( pub_multi_count <= ++v33 )
goto LABEL_67;
}
v35 = inet_ntoa(*(&pub_multi + v33));
fprintf(stderr, "Invalid source specific multicast address: %s\n", v35);
goto LABEL_40;
}
LABEL_67:
if ( !(_DWORD)result )
{
fprintf(stderr, "Default multicast address %s invalid for source specific multicast\n", "230.4.4.1");
exit(1);
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(int argc, char **argv)
{
int v3; // eax
char *i; // rsi
int v5; // er12
char *v6; // rax
FILE *v7; // r12
size_t v8; // rax
char v9; // dl
char *v10; // rax
char *v11; // r13
char *v12; // rax
char *v13; // r12
char *v14; // r13
in_addr_t v15; // eax
int v16; // eax
unsigned __int64 v17; // rax
char *v18; // r12
__int64 v19; // r13
__int64 v20; // rdx
const __m128i *v21; // rax
__m128i v22; // xmm3
__m128i v23; // xmm4
__m128i *v24; // rdx
int v25; // eax
in_addr_t *v26; // rax
int v27; // eax
__int64 v28; // rdx
__m128i v29; // xmm1
__m128i v30; // xmm2
struct hostent *v31; // rax
__int64 result; // rax
int v33; // ebx
struct hostent *v34; // rax
char *v35; // rdx
int *v36; // rax
char *v37; // rax
in_addr_t v38; // [rsp+Ch] [rbp-44Ch] BYREF
char shortopts[16]; // [rsp+10h] [rbp-448h] BYREF
__m128i v40; // [rsp+20h] [rbp-438h]
char v41[8]; // [rsp+30h] [rbp-428h] BYREF
char s[1048]; // [rsp+40h] [rbp-418h] BYREF

strcpy(v41, ":m");
*(__m128i *)shortopts = _mm_load_si128((const __m128i *)&LC21);
v40 = _mm_load_si128((const __m128i *)&LC22);
func2();
LABEL_2:
while ( 2 )
{
v3 = getopt(argc, argv, shortopts);
if ( v3 != -1 )
{
switch ( v3 )
{
case '?':
fwrite(
"uftpd [ -d ] [ -n ] [ -p port ] [ -B buf_size ]\n"
" [ -E ] [ -Q dscp ] [ -U UID ] [ -T temp_dir ] [ -D dest_dir ]\n"
" [ -L logfile ] [ -P pidfile ] [ -S serverlist_file ] [ -R proxy[/fp] ]\n"
" [ -k keyfile[,keyfile...] ] [ -K new_key_length ] [ -m ]\n"
" [ -I interface[,interface...] ] [ -M pub_mcast_addr[,pub_mcast_addr...] ]\n",
1uLL,
0x148uLL,
stderr);
exit(1);
case 'B':
buffer = atoi(optarg);
if ( (unsigned int)(buffer - (_DWORD)&unk_10000) > 0x63F0000 )
{
fwrite("Invalid buffer size\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
continue;
case 'D':
strncpy(destdir, optarg, 0xC7uLL);
destdir[199] = 0;
continue;
case 'E':
encrypted_only = 1;
continue;
case 'I':
v13 = strtok(optarg, ",");
LABEL_47:
if ( !v13 )
continue;
v25 = getifbyname(v13, ifl, (unsigned int)ifl_len);
if ( v25 != -1 )
{
v20 = interface_count;
v21 = (const __m128i *)((char *)ifl + 40 * v25);
v22 = _mm_loadu_si128(v21);
++interface_count;
v23 = _mm_loadu_si128(v21 + 1);
v24 = (__m128i *)((char *)m_interface + 40 * v20);
*v24 = v22;
v24[1] = v23;
LABEL_46:
v24[2].m128i_i64[0] = v21[2].m128i_i64[0];
v13 = strtok(0LL, ",");
goto LABEL_47;
}
if ( inet_addr(v13) == -1 )
{
v31 = gethostbyname(v13);
if ( !v31 )
{
LABEL_75:
fprintf(stderr, "Invalid host name: %s\n", v13);
exit(1);
}
v26 = (in_addr_t *)*v31->h_addr_list;
}
else
{
v38 = inet_addr(v13);
v26 = &v38;
}
v27 = getifbyaddr(*v26, ifl, (unsigned int)ifl_len);
if ( v27 != -1 )
{
v28 = interface_count;
v21 = (const __m128i *)((char *)ifl + 40 * v27);
v29 = _mm_loadu_si128(v21);
++interface_count;
v30 = _mm_loadu_si128(v21 + 1);
v24 = (__m128i *)((char *)m_interface + 40 * v28);
*v24 = v29;
v24[1] = v30;
goto LABEL_46;
}
fprintf(stderr, "Interface %s not found\n", v13);
break;
case 'K':
newkeylen = atoi(optarg);
if ( (unsigned int)(newkeylen - 512) > 0x600 )
{
fwrite("Invalid new key length\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
continue;
case 'L':
strncpy(logfile, optarg, 0x12BuLL);
logfile[299] = 0;
continue;
case 'M':
v18 = strtok(optarg, ",");
if ( !v18 )
continue;
while ( 1 )
{
v19 = pub_multi_count;
*(&pub_multi.s_addr + v19) = inet_addr(v18);
if ( *(&pub_multi.s_addr + pub_multi_count) == -1
|| !(unsigned int)is_multicast(*(&pub_multi.s_addr + pub_multi_count), 0LL) )
{
break;
}
++pub_multi_count;
v18 = strtok(0LL, ",");
if ( !v18 )
goto LABEL_2;
}
fprintf(stderr, "Invalid multicast address: %s\n", v18);
break;
case 'P':
strncpy(pidfile, optarg, 0x12BuLL);
pidfile[299] = 0;
continue;
case 'Q':
v17 = strtol(optarg, 0LL, 0);
if ( v17 > 0x3F )
{
fwrite("Invalid dscp\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
dscp = 4 * v17;
continue;
case 'R':
strncpy(s, optarg, 0x3E8uLL);
s[999] = 0;
v13 = strtok(s, "/");
if ( !v13 )
{
fwrite("Invalid host name\n", 1uLL, 0x12uLL, stderr);
exit(1);
}
v14 = strtok(0LL, "/");
if ( inet_addr(v13) == -1 )
{
v34 = gethostbyname(v13);
if ( !v34 )
goto LABEL_75;
v15 = **(_DWORD **)v34->h_addr_list;
}
else
{
v15 = inet_addr(v13);
}
proxy_info[0] = v15;
v16 = parse_fingerprint((unsigned int)((_DWORD)proxy_info + 8), v14);
has_proxy = 1;
proxy_info[1] = v16;
continue;
case 'S':
v7 = fopen(optarg, "r");
if ( !v7 )
{
v36 = _errno_location();
v37 = strerror(*v36);
fprintf(stderr, "Couldn't open server list %s: %s\n", optarg, v37);
exit(1);
}
while ( fgets(s, 1000, v7) )
{
while ( 1 )
{
v8 = strlen(s) - 1;
v9 = s[v8];
if ( v9 != 13 && v9 != 10 )
break;
s[v8] = 0;
}
v10 = strtok(s, " \t");
v11 = v10;
if ( v10 && *v10 != 35 )
{
if ( strlen(v10) > 0x64 )
{
fwrite("Server list: name too long\n", 1uLL, 0x1BuLL, stderr);
exit(1);
}
v12 = strtok(0LL, " \t");
func1(v11, (__int64)v12);
}
}
if ( !feof(v7) && ferror(v7) )
{
perror("Failed to read from server list file");
exit(1);
}
fclose(v7);
continue;
case 'T':
strncpy(tempdir, optarg, 0xC7uLL);
tempdir[199] = 0;
continue;
case 'U':
uid = inet_addr(optarg);
if ( uid )
{
if ( (unsigned int)func0(uid) > 0xFFFFFF )
goto LABEL_15;
}
else
{
uid = strtol(optarg, 0LL, 16);
if ( (unsigned int)(uid - 1) > 0xFFFFFE )
{
LABEL_15:
fwrite("Invalid UID\n", 1uLL, 0xCuLL, stderr);
exit(1);
}
uid = func0(uid);
}
continue;
case 'd':
debug = 1;
continue;
case 'k':
for ( i = strtok(optarg, ","); i; i = strtok(0LL, ",") )
{
v5 = keyfile_count + 1;
v6 = strncpy((char *)&keyfile[75 * keyfile_count], i, 0x12BuLL);
keyfile_count = v5;
v6[299] = 0;
}
continue;
case 'm':
sys_keys = 1;
continue;
case 'n':
noname = 1;
continue;
case 'p':
port = atoi(optarg);
if ( !port )
{
fwrite("Invalid port\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
continue;
case 'v':
verbose = atoi(optarg);
continue;
default:
continue;
}
LABEL_40:
exit(1);
}
break;
}
result = (unsigned int)server_count;
if ( server_count )
{
result = (unsigned int)pub_multi_count;
if ( pub_multi_count > 0 )
{
v33 = 0;
while ( (unsigned int)is_multicast(*(&pub_multi.s_addr + v33), 1LL) )
{
result = (unsigned int)pub_multi_count;
if ( pub_multi_count <= ++v33 )
goto LABEL_67;
}
v35 = inet_ntoa(*(&pub_multi + v33));
fprintf(stderr, "Invalid source specific multicast address: %s\n", v35);
goto LABEL_40;
}
LABEL_67:
if ( !(_DWORD)result )
{
fprintf(stderr, "Default multicast address %s invalid for source specific multicast\n", "230.4.4.1");
exit(1);
}
}
return result;
}

original_code:
void process_args(int argc, char *argv[])
{
    int c, i, listidx, hbport;
    long tmpval;
    struct hostent *hp;
    struct in_addr *paddr, addr;
    char *p, *p2, *hoststr, *portstr;
    const char opts[] = "s:crdv:np:t:Q:O:U:q:T:mh:H:B:L:P:C:S:k:K:I:M:";
    set_defaults();
    while ((c = getopt(argc, argv, opts)) != (-1)) {
        switch (c) {
        case 's':
            if (proxy_type != UNDEF_PROXY) {
                fprintf(stderr, "Only one of -s, -c, -r may be specified\n");
                exit(1);
            }
            proxy_type = SERVER_PROXY;
            memset(&down_addr, 0, sizeof(down_addr));
            if (!strncmp(optarg, "fp=", 3)) {
                have_down_fingerprint =
                        parse_fingerprint(down_fingerprint, optarg + 3);
                if (!have_down_fingerprint) {
                    fprintf(stderr, "Failed to parse downstream fingerprint\n");
                    exit(1);
                }
                srand((unsigned int)time(((void *)0)) ^ getpid());
                down_nonce = rand();
            } else {
                have_down_fingerprint = 0;
                down_addr.sin_family = 2;
                if (inet_addr(optarg) == ((in_addr_t) 0xffffffff)) {
                    if ((hp = gethostbyname(optarg)) == ((void *)0)) {
                        fprintf(stderr, "Invalid host name: %s\n", optarg);
                        exit(1);
                    } else {
                        paddr = (struct in_addr *)hp->h_addr_list[0];
                        down_addr.sin_addr.s_addr = paddr->s_addr;
                    }
                } else {
                    down_addr.sin_addr.s_addr = inet_addr(optarg);
                }
            }
            break;
        case 'c':
            if (proxy_type != UNDEF_PROXY) {
                fprintf(stderr, "Only one of -s, -c, -r may be specified\n");
                exit(1);
            }
            proxy_type = CLIENT_PROXY;
            break;
        case 'r':
            if (proxy_type != UNDEF_PROXY) {
                fprintf(stderr, "Only one of -s, -c, -r may be specified\n");
                exit(1);
            }
            proxy_type = RESPONSE_PROXY;
            break;
        case 'd':
            debug = 1;
            break;
        case 'n':
            noname = 1;
            break;
        case 'v':
            verbose = atoi(optarg);
            break;
        case 'p':
            port = atoi(optarg);
            if (port == 0) {
                fprintf(stderr, "Invalid port\n");
                exit(1);
            }
            break;
        case 't':
            tmpval = atoi(optarg);
            if ((tmpval <= 0) || (tmpval > 255)) {
                fprintf(stderr, "Invalid ttl\n");
                exit(1);
            }
            ttl = (char)tmpval;
            break;
        case 'Q':
            tmpval = strtol(optarg, ((void *)0), 0);
            if ((tmpval < 0) || (tmpval > 63)) {
                fprintf(stderr, "Invalid dscp\n");
                exit(1);
            }
            dscp = (tmpval & 0xFF) << 2;
            break;
        case 'O':
            if ((listidx = getifbyname(optarg, ifl, ifl_len)) != -1) {
                out_addr = ifl[listidx].addr;
                break;
            }
            if (inet_addr(optarg) == ((in_addr_t) 0xffffffff)) {
                if ((hp = gethostbyname(optarg)) == ((void *)0)) {
                    fprintf(stderr, "Invalid host name: %s\n", optarg);
                    exit(1);
                } else {
                    paddr = (struct in_addr *)hp->h_addr_list[0];
                }
            } else {
                addr.s_addr = inet_addr(optarg);
                paddr = &addr;
            }
            if ((listidx = getifbyaddr(*paddr, ifl, ifl_len)) != -1) {
                out_addr = ifl[listidx].addr;
            } else {
                fprintf(stderr, "Interface %s not found\n", optarg);
                exit(1);
            }
            break;
        case 'U':
            if ((uid = inet_addr(optarg)) != 0) {
                if (ntohl(uid) > 0xffffff) {
                    fprintf(stderr, "Invalid UID\n");
                    exit(1);
                }
            } else {
                uid = strtol(optarg, ((void *)0), 16);
                if ((uid > 0xffffff) || (uid <= 0)) {
                    fprintf(stderr, "Invalid UID\n");
                    exit(1);
                }
                uid = htonl(uid);
            }
            break;
        case 'q':
            out_port = atoi(optarg);
            if (out_port == 0) {
                fprintf(stderr, "Invalid outgoing port\n");
                exit(1);
            }
            break;
        case 'T':
            proxy_int = atoi(optarg);
            if ((proxy_int < 10) || (proxy_int >= 100)) {
                fprintf(stderr, "Invalid interval percentage\n");
                exit(1);
            }
            break;
        case 'm':
            sys_keys = 1;
            break;
        case 'H':
            p = strtok(optarg, ",");
            while (p != ((void *)0)) {
                p2 = strchr(p, ':');
                if (p2) {
                    hoststr = strdup(p);
                    hoststr[p2 - p] = '\x0';
                    portstr = p2 + 1;
                } else {
                    hoststr = p;
                    portstr = ((void *)0);
                }
                hb_hosts[hbhost_count].sin_family = 2;
                if (inet_addr(hoststr) == ((in_addr_t) 0xffffffff)) {
                    if ((hp = gethostbyname(hoststr)) == ((void *)0)) {
                        fprintf(stderr, "Invalid host name: %s\n", hoststr);
                        exit(1);
                    } else {
                        paddr = (struct in_addr *)hp->h_addr_list[0];
                        hb_hosts[hbhost_count].sin_addr.s_addr = paddr->s_addr;
                    }
                } else {
                    hb_hosts[hbhost_count].sin_addr.s_addr = inet_addr(hoststr);
                }
                if (portstr) {
                    free(hoststr);
                    hbport = atoi(portstr);
                    if ((hbport <= 0) || (hbport > 65535)) {
                        hbport = 1044;
                    }
                } else {
                    hbport = 1044;
                }
                hb_hosts[hbhost_count++].sin_port = htons(hbport);
                p = strtok(((void *)0), ",");
            }
            break;
        case 'h':
            hb_interval = atoi(optarg);
            if ((hb_interval <= 0) || (hb_interval > 3600)) {
                fprintf(stderr, "Invalid hearbeat interval\n");
                exit(1);
            }
            break;
        case 'B':
            buffer = atoi(optarg);
            if ((buffer < 65536) || (buffer > 104857600)) {
                fprintf(stderr, "Invalid buffer size\n");
                exit(1);
            }
            break;
        case 'L':
            strncpy(logfile, optarg, sizeof(logfile)-1);
            logfile[sizeof(logfile)-1] = '\x0';
            break;
        case 'P':
            strncpy(pidfile, optarg, sizeof(pidfile)-1);
            pidfile[sizeof(pidfile)-1] = '\x0';
            break;
        case 'C':
            add_hosts_by_name(client_fp, &client_fp_count, optarg);
            break;
        case 'S':
            add_hosts_by_name(server_fp, &server_fp_count, optarg);
            break;
        case 'k':
            p = strtok(optarg, ",");
            while (p != ((void *)0)) {
                strncpy(keyfile[keyfile_count], p, sizeof(keyfile[0])-1);
                keyfile[keyfile_count][sizeof(keyfile[0])-1] = '\x0';
                keyfile_count++;
                p = strtok(((void *)0), ",");
            }
            break;
        case 'K':
            newkeylen = atoi(optarg);
            if ((newkeylen < 512) || (newkeylen > 2048)) {
                fprintf(stderr, "Invalid new key length\n");
                exit(1);
            }
            break;
        case 'I':
            p = strtok(optarg, ",");
            while (p != ((void *)0)) {
                if ((listidx = getifbyname(p, ifl, ifl_len)) != -1) {
                    m_interface[interface_count++] = ifl[listidx];
                    p = strtok(((void *)0), ",");
                    continue;
                }
                if (inet_addr(p) == ((in_addr_t) 0xffffffff)) {
                    if ((hp = gethostbyname(p)) == ((void *)0)) {
                        fprintf(stderr, "Invalid host name: %s\n", p);
                        exit(1);
                    } else {
                        paddr = (struct in_addr *)hp->h_addr_list[0];
                    }
                } else {
                    addr.s_addr = inet_addr(p);
                    paddr = &addr;
                }
                if ((listidx = getifbyaddr(*paddr, ifl, ifl_len)) != -1) {
                    m_interface[interface_count++] = ifl[listidx];
                } else {
                    fprintf(stderr, "Interface %s not found\n", p);
                    exit(1);
                }
                p = strtok(((void *)0), ",");
            }
            break;
        case 'M':
            p = strtok(optarg, ",");
            while (p != ((void *)0)) {
                pub_multi[pub_multi_count].s_addr = inet_addr(p);
                if ((pub_multi[pub_multi_count].s_addr == ((in_addr_t) 0xffffffff)) ||
                        (!is_multicast(pub_multi[pub_multi_count], 0))) {
                    fprintf(stderr, "Invalid multicast address: %s\n", p);
                    exit(1);
                }
                pub_multi_count++;
                p = strtok(((void *)0), ",");
            }
            break;
        case '?':
            fprintf(stderr, "uftpproxyd { -s { dest | fp=fingerprint } | -c | -r } [ -d ] [ -n ]\n    [ -p port ] [ -t ttl ] [ -Q dscp ] [ -O out_multi_interface ]\n    [ -U UID ] [ -q dest_port ] [ -T interval_pct ] [ -m ]\n    [ -H hb_server[:port][,hb_server[:port]...] ] [ -h hb_interval ]\n    [ -B udp_buf_size ] [ -L logfile ] [ -P pidfile ] [ -C clientlist_file ]\n    [ -S serverlist_file ] [ -k keyfile[,keyfile...] ] [ -K new_key_length ]\n    [ -I interface[,interface...] ] [ -M pub_mcast_addr[,pub_mcast_addr...] ]\n");
            exit(1);
        }
    }
    if (proxy_type == UNDEF_PROXY) {
        fprintf(stderr, "Either -s, -c, or -r must be specified\n");
        fprintf(stderr, "uftpproxyd { -s { dest | fp=fingerprint } | -c | -r } [ -d ] [ -n ]\n    [ -p port ] [ -t ttl ] [ -Q dscp ] [ -O out_multi_interface ]\n    [ -U UID ] [ -q dest_port ] [ -T interval_pct ] [ -m ]\n    [ -H hb_server[:port][,hb_server[:port]...] ] [ -h hb_interval ]\n    [ -B udp_buf_size ] [ -L logfile ] [ -P pidfile ] [ -C clientlist_file ]\n    [ -S serverlist_file ] [ -k keyfile[,keyfile...] ] [ -K new_key_length ]\n    [ -I interface[,interface...] ] [ -M pub_mcast_addr[,pub_mcast_addr...] ]\n");
        exit(1);
    }
    if (proxy_type != CLIENT_PROXY) {
        down_addr.sin_port = htons(out_port);
        if (server_fp_count) {
            for (i = 0; i < pub_multi_count; i++) {
                if (!is_multicast(pub_multi[i], 1)) {
                    fprintf(stderr, "Invalid source specific "
                            "multicast address: %s\n", inet_ntoa(pub_multi[i]));
                    exit(1);
                }
            }
            if (pub_multi_count == 0) {
                fprintf(stderr, "Default multicast address %s invalid "
                        "for source specific multicast\n", "230.4.4.1");
                exit(1);
            }
        }
    }
    if (proxy_type == RESPONSE_PROXY) {
        out_port = port;
    }
}

canonical_original_code:
void process_args(int argc, char *argv[])
{
    int c; int i; int listidx; int hbport;
    long tmpval;
    struct hostent *hp;
    struct in_addr *paddr; struct in_addr addr;
    char *p; char *p2; char *hoststr; char *portstr;
    char opts[] = "s:crdv:np:t:Q:O:U:q:T:mh:H:B:L:P:C:S:k:K:I:M:";
    set_defaults();
    while ((c = getopt(argc, argv, opts)) != (-1)) {
        switch (c) {
        case 's':
            if (proxy_type != UNDEF_PROXY) {
                fprintf(stderr, "Only one of -s, -c, -r may be specified\n");
                exit(1);
            }
            proxy_type = SERVER_PROXY;
            memset(&down_addr, 0, sizeof(down_addr));
            if (!strncmp(optarg, "fp=", 3)) {
                have_down_fingerprint =
                        parse_fingerprint(down_fingerprint, optarg + 3);
                if (!have_down_fingerprint) {
                    fprintf(stderr, "Failed to parse downstream fingerprint\n");
                    exit(1);
                }
                srand((unsigned int)time(((void *)0)) ^ getpid());
                down_nonce = rand();
            } else {
                have_down_fingerprint = 0;
                down_addr.sin_family = 2;
                if (inet_addr(optarg) == ((unsigned int) 0xffffffff)) {
                    if ((hp = gethostbyname(optarg)) == ((void *)0)) {
                        fprintf(stderr, "Invalid host name: %s\n", optarg);
                        exit(1);
                    } else {
                        paddr = (struct in_addr *)hp->h_addr_list[0];
                        down_addr.sin_addr.s_addr = paddr->s_addr;
                    }
                } else {
                    down_addr.sin_addr.s_addr = inet_addr(optarg);
                }
            }
            break;
        case 'c':
            if (proxy_type != UNDEF_PROXY) {
                fprintf(stderr, "Only one of -s, -c, -r may be specified\n");
                exit(1);
            }
            proxy_type = CLIENT_PROXY;
            break;
        case 'r':
            if (proxy_type != UNDEF_PROXY) {
                fprintf(stderr, "Only one of -s, -c, -r may be specified\n");
                exit(1);
            }
            proxy_type = RESPONSE_PROXY;
            break;
        case 'd':
            debug = 1;
            break;
        case 'n':
            noname = 1;
            break;
        case 'v':
            verbose = atoi(optarg);
            break;
        case 'p':
            port = atoi(optarg);
            if (port == 0) {
                fprintf(stderr, "Invalid port\n");
                exit(1);
            }
            break;
        case 't':
            tmpval = atoi(optarg);
            if ((tmpval <= 0) || (tmpval > 255)) {
                fprintf(stderr, "Invalid ttl\n");
                exit(1);
            }
            ttl = (char)tmpval;
            break;
        case 'Q':
            tmpval = strtol(optarg, ((void *)0), 0);
            if ((tmpval < 0) || (tmpval > 63)) {
                fprintf(stderr, "Invalid dscp\n");
                exit(1);
            }
            dscp = (tmpval & 0xFF) << 2;
            break;
        case 'O':
            if ((listidx = getifbyname(optarg, ifl, ifl_len)) != -1) {
                out_addr = ifl[listidx].addr;
                break;
            }
            if (inet_addr(optarg) == ((unsigned int) 0xffffffff)) {
                if ((hp = gethostbyname(optarg)) == ((void *)0)) {
                    fprintf(stderr, "Invalid host name: %s\n", optarg);
                    exit(1);
                } else {
                    paddr = (struct in_addr *)hp->h_addr_list[0];
                }
            } else {
                addr.s_addr = inet_addr(optarg);
                paddr = &addr;
            }
            if ((listidx = getifbyaddr(*paddr, ifl, ifl_len)) != -1) {
                out_addr = ifl[listidx].addr;
            } else {
                fprintf(stderr, "Interface %s not found\n", optarg);
                exit(1);
            }
            break;
        case 'U':
            if ((uid = inet_addr(optarg)) != 0) {
                if (ntohl(uid) > 0xffffff) {
                    fprintf(stderr, "Invalid UID\n");
                    exit(1);
                }
            } else {
                uid = strtol(optarg, ((void *)0), 16);
                if ((uid > 0xffffff) || (uid <= 0)) {
                    fprintf(stderr, "Invalid UID\n");
                    exit(1);
                }
                uid = htonl(uid);
            }
            break;
        case 'q':
            out_port = atoi(optarg);
            if (out_port == 0) {
                fprintf(stderr, "Invalid outgoing port\n");
                exit(1);
            }
            break;
        case 'T':
            proxy_int = atoi(optarg);
            if ((proxy_int < 10) || (proxy_int >= 100)) {
                fprintf(stderr, "Invalid interval percentage\n");
                exit(1);
            }
            break;
        case 'm':
            sys_keys = 1;
            break;
        case 'H':
            p = strtok(optarg, ",");
            while (p != ((void *)0)) {
                p2 = strchr(p, ':');
                if (p2) {
                    hoststr = strdup(p);
                    hoststr[p2 - p] = '\x0';
                    portstr = p2 + 1;
                } else {
                    hoststr = p;
                    portstr = ((void *)0);
                }
                hb_hosts[hbhost_count].sin_family = 2;
                if (inet_addr(hoststr) == ((unsigned int) 0xffffffff)) {
                    if ((hp = gethostbyname(hoststr)) == ((void *)0)) {
                        fprintf(stderr, "Invalid host name: %s\n", hoststr);
                        exit(1);
                    } else {
                        paddr = (struct in_addr *)hp->h_addr_list[0];
                        hb_hosts[hbhost_count].sin_addr.s_addr = paddr->s_addr;
                    }
                } else {
                    hb_hosts[hbhost_count].sin_addr.s_addr = inet_addr(hoststr);
                }
                if (portstr) {
                    free(hoststr);
                    hbport = atoi(portstr);
                    if ((hbport <= 0) || (hbport > 65535)) {
                        hbport = 1044;
                    }
                } else {
                    hbport = 1044;
                }
                hb_hosts[hbhost_count++].sin_port = htons(hbport);
                p = strtok(((void *)0), ",");
            }
            break;
        case 'h':
            hb_interval = atoi(optarg);
            if ((hb_interval <= 0) || (hb_interval > 3600)) {
                fprintf(stderr, "Invalid hearbeat interval\n");
                exit(1);
            }
            break;
        case 'B':
            buffer = atoi(optarg);
            if ((buffer < 65536) || (buffer > 104857600)) {
                fprintf(stderr, "Invalid buffer size\n");
                exit(1);
            }
            break;
        case 'L':
            strncpy(logfile, optarg, sizeof(logfile)-1);
            logfile[sizeof(logfile)-1] = '\x0';
            break;
        case 'P':
            strncpy(pidfile, optarg, sizeof(pidfile)-1);
            pidfile[sizeof(pidfile)-1] = '\x0';
            break;
        case 'C':
            add_hosts_by_name(client_fp, &client_fp_count, optarg);
            break;
        case 'S':
            add_hosts_by_name(server_fp, &server_fp_count, optarg);
            break;
        case 'k':
            p = strtok(optarg, ",");
            while (p != ((void *)0)) {
                strncpy(keyfile[keyfile_count], p, sizeof(keyfile[0])-1);
                keyfile[keyfile_count][sizeof(keyfile[0])-1] = '\x0';
                keyfile_count++;
                p = strtok(((void *)0), ",");
            }
            break;
        case 'K':
            newkeylen = atoi(optarg);
            if ((newkeylen < 512) || (newkeylen > 2048)) {
                fprintf(stderr, "Invalid new key length\n");
                exit(1);
            }
            break;
        case 'I':
            p = strtok(optarg, ",");
            while (p != ((void *)0)) {
                if ((listidx = getifbyname(p, ifl, ifl_len)) != -1) {
                    m_interface[interface_count++] = ifl[listidx];
                    p = strtok(((void *)0), ",");
                    continue;
                }
                if (inet_addr(p) == ((unsigned int) 0xffffffff)) {
                    if ((hp = gethostbyname(p)) == ((void *)0)) {
                        fprintf(stderr, "Invalid host name: %s\n", p);
                        exit(1);
                    } else {
                        paddr = (struct in_addr *)hp->h_addr_list[0];
                    }
                } else {
                    addr.s_addr = inet_addr(p);
                    paddr = &addr;
                }
                if ((listidx = getifbyaddr(*paddr, ifl, ifl_len)) != -1) {
                    m_interface[interface_count++] = ifl[listidx];
                } else {
                    fprintf(stderr, "Interface %s not found\n", p);
                    exit(1);
                }
                p = strtok(((void *)0), ",");
            }
            break;
        case 'M':
            p = strtok(optarg, ",");
            while (p != ((void *)0)) {
                pub_multi[pub_multi_count].s_addr = inet_addr(p);
                if ((pub_multi[pub_multi_count].s_addr == ((unsigned int) 0xffffffff)) ||
                        (!is_multicast(pub_multi[pub_multi_count], 0))) {
                    fprintf(stderr, "Invalid multicast address: %s\n", p);
                    exit(1);
                }
                pub_multi_count++;
                p = strtok(((void *)0), ",");
            }
            break;
        case '?':
            fprintf(stderr, "uftpproxyd { -s { dest | fp=fingerprint } | -c | -r } [ -d ] [ -n ]\n    [ -p port ] [ -t ttl ] [ -Q dscp ] [ -O out_multi_interface ]\n    [ -U UID ] [ -q dest_port ] [ -T interval_pct ] [ -m ]\n    [ -H hb_server[:port][,hb_server[:port]...] ] [ -h hb_interval ]\n    [ -B udp_buf_size ] [ -L logfile ] [ -P pidfile ] [ -C clientlist_file ]\n    [ -S serverlist_file ] [ -k keyfile[,keyfile...] ] [ -K new_key_length ]\n    [ -I interface[,interface...] ] [ -M pub_mcast_addr[,pub_mcast_addr...] ]\n");
            exit(1);
        }
    }
    if (proxy_type == UNDEF_PROXY) {
        fprintf(stderr, "Either -s, -c, or -r must be specified\n");
        fprintf(stderr, "uftpproxyd { -s { dest | fp=fingerprint } | -c | -r } [ -d ] [ -n ]\n    [ -p port ] [ -t ttl ] [ -Q dscp ] [ -O out_multi_interface ]\n    [ -U UID ] [ -q dest_port ] [ -T interval_pct ] [ -m ]\n    [ -H hb_server[:port][,hb_server[:port]...] ] [ -h hb_interval ]\n    [ -B udp_buf_size ] [ -L logfile ] [ -P pidfile ] [ -C clientlist_file ]\n    [ -S serverlist_file ] [ -k keyfile[,keyfile...] ] [ -K new_key_length ]\n    [ -I interface[,interface...] ] [ -M pub_mcast_addr[,pub_mcast_addr...] ]\n");
        exit(1);
    }
    if (proxy_type != CLIENT_PROXY) {
        down_addr.sin_port = htons(out_port);
        if (server_fp_count) {
            for (i = 0; i < pub_multi_count; i++) {
                if (!is_multicast(pub_multi[i], 1)) {
                    fprintf(stderr, "Invalid source specific "
                            "multicast address: %s\n", inet_ntoa(pub_multi[i]));
                    exit(1);
                }
            }
            if (pub_multi_count == 0) {
                fprintf(stderr, "Default multicast address %s invalid "
                        "for source specific multicast\n", "230.4.4.1");
                exit(1);
            }
        }
    }
    if (proxy_type == RESPONSE_PROXY) {
        out_port = port;
    }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: c int

variable_types: listidx int

variable_types: hbport int

variable_types: tmpval long

variable_types:
addr
struct in_addr { unsigned int s_addr; }

variable_types:
p
char *

variable_types:
hoststr
char *

variable_types:
portstr
char *

variable_types:
opts
char []

user_defined_types: struct hostent { char *h_name; char **h_aliases; int h_addrtype; int h_length; char **h_addr_list; }


decompiled_code:
int __fastcall process_args(int argc, char **argv)
{
int result; // eax
int v5; // eax
int v6; // er12
__pid_t v7; // eax
char *i; // rsi
int v9; // er12
char *v10; // rax
unsigned __int64 v11; // rax
int v12; // eax
char *v13; // r12
__int64 v14; // r13
char *v15; // r12
__int64 v16; // rdx
const __m128i *v17; // rax
__m128i v18; // xmm3
__m128i v19; // xmm4
__m128i *v20; // rdx
int v21; // eax
int *v22; // rax
int v23; // eax
__int64 v24; // rdx
__m128i v25; // xmm1
__m128i v26; // xmm2
__int64 v27; // r14
int v28; // eax
__int16 v29; // di
__int16 v30; // ax
__int64 v31; // rdx
char *v32; // r13
char *v33; // rax
char *v34; // rdx
signed __int64 v35; // rdx
struct hostent *v36; // rax
struct hostent *v37; // rax
int v38; // edx
int v39; // ebx
int *v40; // rax
struct hostent *v41; // rax
struct hostent *v42; // rax
char *v43; // rdx
char *v44; // rdx
in_addr_t v45; // [rsp+Ch] [rbp-5Ch] BYREF
char shortopts[16]; // [rsp+10h] [rbp-58h] BYREF
__m128i v47; // [rsp+20h] [rbp-48h]
char v48[16]; // [rsp+30h] [rbp-38h] BYREF

strcpy(v48, ":C:S:k:K:I:M:");
*(__m128i *)shortopts = _mm_load_si128((const __m128i *)&LC26);
v47 = _mm_load_si128((const __m128i *)&LC27);
set_defaults();
LABEL_2:
while ( 2 )
{
result = getopt(argc, argv, shortopts);
if ( result != -1 )
{
switch ( result )
{
case '?':
goto LABEL_101;
case 'B':
buffer = atoi(optarg);
if ( (unsigned int)(buffer - (_DWORD)&unk_10000) > 0x63F0000 )
{
fwrite("Invalid buffer size\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
continue;
case 'C':
add_hosts_by_name((__int64)&client_fp, &client_fp_count, optarg);
continue;
case 'H':
v15 = strtok(optarg, ",");
if ( !v15 )
continue;
do
{
v32 = strchr(v15, 58);
if ( v32 )
{
v33 = strdup(v15);
v34 = v32++;
v35 = v34 - v15;
v15 = v33;
v33[v35] = 0;
}
LOWORD(hb_hosts[4 * hbhost_count]) = 2;
if ( inet_addr(v15) == -1 )
{
v36 = gethostbyname(v15);
if ( !v36 )
goto LABEL_102;
hb_hosts[4 * hbhost_count + 1] = **(_DWORD **)v36->h_addr_list;
}
else
{
v27 = hbhost_count;
hb_hosts[4 * v27 + 1] = inet_addr(v15);
}
if ( !v32 || (free(v15), v28 = atoi(v32), v29 = v28, (unsigned int)(v28 - 1) > 0xFFFE) )
v29 = 1044;
++hbhost_count;
v30 = _bswap_16(v29);
*(_WORD *)((char *)hb_hosts + v31 + 2) = v30;
v15 = strtok(0LL, ",");
}
while ( v15 );
continue;
case 'I':
v15 = strtok(optarg, ",");
LABEL_53:
if ( !v15 )
continue;
v21 = getifbyname(v15, &ifl, (unsigned int)ifl_len);
if ( v21 != -1 )
{
v16 = interface_count;
v17 = (const __m128i *)((char *)&ifl + 40 * v21);
v18 = _mm_loadu_si128(v17);
++interface_count;
v19 = _mm_loadu_si128(v17 + 1);
v20 = (__m128i *)((char *)&m_interface + 40 * v16);
*v20 = v18;
v20[1] = v19;
LABEL_52:
v20[2].m128i_i64[0] = v17[2].m128i_i64[0];
v15 = strtok(0LL, ",");
goto LABEL_53;
}
if ( inet_addr(v15) == -1 )
{
v37 = gethostbyname(v15);
if ( !v37 )
{
LABEL_102:
v43 = v15;
goto LABEL_103;
}
v22 = (int *)*v37->h_addr_list;
}
else
{
v45 = inet_addr(v15);
v22 = (int *)&v45;
}
v23 = getifbyaddr((unsigned int)*v22, &ifl, (unsigned int)ifl_len);
if ( v23 != -1 )
{
v24 = interface_count;
v17 = (const __m128i *)((char *)&ifl + 40 * v23);
v25 = _mm_loadu_si128(v17);
++interface_count;
v26 = _mm_loadu_si128(v17 + 1);
v20 = (__m128i *)((char *)&m_interface + 40 * v24);
*v20 = v25;
v20[1] = v26;
goto LABEL_52;
}
fprintf(stderr, "Interface %s not found\n", v15);
break;
case 'K':
newkeylen = atoi(optarg);
if ( (unsigned int)(newkeylen - 512) > 0x600 )
{
fwrite("Invalid new key length\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
continue;
case 'L':
strncpy(logfile, optarg, 0x12BuLL);
logfile[299] = 0;
continue;
case 'M':
v13 = strtok(optarg, ",");
if ( !v13 )
continue;
while ( 1 )
{
v14 = pub_multi_count;
*(&pub_multi.s_addr + v14) = inet_addr(v13);
if ( *(&pub_multi.s_addr + pub_multi_count) == -1
|| !(unsigned int)is_multicast(*(&pub_multi.s_addr + pub_multi_count), 0LL) )
{
break;
}
++pub_multi_count;
v13 = strtok(0LL, ",");
if ( !v13 )
goto LABEL_2;
}
fprintf(stderr, "Invalid multicast address: %s\n", v13);
break;
case 'O':
v12 = getifbyname(optarg, &ifl, (unsigned int)ifl_len);
if ( v12 != -1 )
goto LABEL_39;
if ( inet_addr(optarg) == -1 )
{
v42 = gethostbyname(optarg);
if ( !v42 )
{
LABEL_105:
v43 = optarg;
LABEL_103:
fprintf(stderr, "Invalid host name: %s\n", v43);
exit(1);
}
v40 = (int *)*v42->h_addr_list;
}
else
{
v45 = inet_addr(optarg);
v40 = (int *)&v45;
}
v12 = getifbyaddr((unsigned int)*v40, &ifl, (unsigned int)ifl_len);
if ( v12 == -1 )
{
fprintf(stderr, "Interface %s not found\n", optarg);
break;
}
LABEL_39:
out_addr = *((_DWORD *)&ifl + 10 * v12 + 7);
continue;
case 'P':
strncpy(pidfile, optarg, 0x12BuLL);
pidfile[299] = 0;
continue;
case 'Q':
v11 = strtol(optarg, 0LL, 0);
if ( v11 > 0x3F )
{
fwrite("Invalid dscp\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
dscp = 4 * v11;
continue;
case 'S':
add_hosts_by_name((__int64)&server_fp, &server_fp_count, optarg);
continue;
case 'T':
proxy_int = atoi(optarg);
if ( (unsigned int)(proxy_int - 10) > 0x59 )
{
fwrite("Invalid interval percentage\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
continue;
case 'U':
uid = inet_addr(optarg);
if ( uid )
{
if ( (unsigned int)_bswap_32(uid) > (unsigned int)&unk_FFFFFF )
goto LABEL_31;
}
else
{
uid = strtol(optarg, 0LL, 16);
if ( uid - 1 > (unsigned int)&unk_FFFFFE )
{
LABEL_31:
fwrite("Invalid UID\n", 1uLL, 0xCuLL, stderr);
exit(1);
}
uid = _bswap_32(uid);
}
continue;
case 'c':
if ( proxy_type )
goto LABEL_111;
proxy_type = 2;
continue;
case 'd':
debug = 1;
continue;
case 'h':
hb_interval = atoi(optarg);
if ( (unsigned int)(hb_interval - 1) > 0xE0F )
{
fwrite("Invalid hearbeat interval\n", 1uLL, 0x1AuLL, stderr);
exit(1);
}
continue;
case 'k':
for ( i = strtok(optarg, ","); i; i = strtok(0LL, ",") )
{
v9 = keyfile_count + 1;
v10 = strncpy(&keyfile[300 * keyfile_count], i, 0x12BuLL);
keyfile_count = v9;
v10[299] = 0;
}
continue;
case 'm':
sys_keys = 1;
continue;
case 'n':
noname = 1;
continue;
case 'p':
port = atoi(optarg);
if ( !port )
{
fwrite("Invalid port\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
continue;
case 'q':
out_port = atoi(optarg);
if ( !out_port )
{
fwrite("Invalid outgoing port\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
continue;
case 'r':
if ( proxy_type )
goto LABEL_111;
proxy_type = 3;
continue;
case 's':
if ( proxy_type )
{
LABEL_111:
fwrite("Only one of -s, -c, -r may be specified\n", 1uLL, 0x28uLL, stderr);
exit(1);
}
proxy_type = 1;
down_addr = 0LL;
if ( *optarg == 102 && optarg[1] == 112 && optarg[2] == 61 )
{
have_down_fingerprint = parse_fingerprint(&down_fingerprint, optarg + 3);
if ( !have_down_fingerprint )
{
fwrite("Failed to parse downstream fingerprint\n", 1uLL, 0x27uLL, stderr);
exit(1);
}
v6 = time(0LL);
v7 = getpid();
srand(v6 ^ v7);
down_nonce = rand();
}
else
{
have_down_fingerprint = 0;
LOWORD(down_addr) = 2;
if ( inet_addr(optarg) == -1 )
{
v41 = gethostbyname(optarg);
if ( !v41 )
goto LABEL_105;
DWORD1(down_addr) = **(_DWORD **)v41->h_addr_list;
}
else
{
DWORD1(down_addr) = inet_addr(optarg);
}
}
continue;
case 't':
v5 = atoi(optarg);
if ( (unsigned __int64)(v5 - 1LL) > 0xFE )
{
fwrite("Invalid ttl\n", 1uLL, 0xCuLL, stderr);
exit(1);
}
ttl = v5;
continue;
case 'v':
verbose = atoi(optarg);
continue;
default:
continue;
}
LABEL_46:
exit(1);
}
break;
}
if ( !proxy_type )
{
fwrite("Either -s, -c, or -r must be specified\n", 1uLL, 0x27uLL, stderr);
LABEL_101:
fwrite(
"uftpproxyd { -s { dest | fp=fingerprint } | -c | -r } [ -d ] [ -n ]\n"
" [ -p port ] [ -t ttl ] [ -Q dscp ] [ -O out_multi_interface ]\n"
" [ -U UID ] [ -q dest_port ] [ -T interval_pct ] [ -m ]\n"
" [ -H hb_server[:port][,hb_server[:port]...] ] [ -h hb_interval ]\n"
" [ -B udp_buf_size ] [ -L logfile ] [ -P pidfile ] [ -C clientlist_file ]\n"
" [ -S serverlist_file ] [ -k keyfile[,keyfile...] ] [ -K new_key_length ]\n"
" [ -I interface[,interface...] ] [ -M pub_mcast_addr[,pub_mcast_addr...] ]\n",
1uLL,
0x1EEuLL,
stderr);
exit(1);
}
if ( proxy_type != 2 )
{
WORD1(down_addr) = _bswap_16(out_port);
result = server_fp_count;
if ( server_fp_count )
{
result = pub_multi_count;
if ( pub_multi_count > 0 )
{
v39 = 0;
while ( (unsigned int)is_multicast(*(&pub_multi.s_addr + v39), 1LL) )
{
result = pub_multi_count;
if ( pub_multi_count <= ++v39 )
goto LABEL_85;
}
v44 = inet_ntoa(*(&pub_multi + v39));
fprintf(stderr, "Invalid source specific multicast address: %s\n", v44);
goto LABEL_46;
}
LABEL_85:
if ( !result )
{
fprintf(stderr, "Default multicast address %s invalid for source specific multicast\n", "230.4.4.1");
goto LABEL_46;
}
v38 = proxy_type;
}
if ( v38 == 3 )
{
result = (unsigned __int16)port;
out_port = port;
}
}
return result;
}

canonical_decompiled_code:
int __fastcall func4(int argc, char **argv)
{
int result; // eax
int v5; // eax
int v6; // er12
__pid_t v7; // eax
char *i; // rsi
int v9; // er12
char *v10; // rax
unsigned __int64 v11; // rax
int v12; // eax
char *v13; // r12
__int64 v14; // r13
char *v15; // r12
__int64 v16; // rdx
const __m128i *v17; // rax
__m128i v18; // xmm3
__m128i v19; // xmm4
__m128i *v20; // rdx
int v21; // eax
int *v22; // rax
int v23; // eax
__int64 v24; // rdx
__m128i v25; // xmm1
__m128i v26; // xmm2
__int64 v27; // r14
int v28; // eax
__int16 v29; // di
__int16 v30; // ax
__int64 v31; // rdx
char *v32; // r13
char *v33; // rax
char *v34; // rdx
signed __int64 v35; // rdx
struct hostent *v36; // rax
struct hostent *v37; // rax
int v38; // edx
int v39; // ebx
int *v40; // rax
struct hostent *v41; // rax
struct hostent *v42; // rax
char *v43; // rdx
char *v44; // rdx
in_addr_t v45; // [rsp+Ch] [rbp-5Ch] BYREF
char shortopts[16]; // [rsp+10h] [rbp-58h] BYREF
__m128i v47; // [rsp+20h] [rbp-48h]
char v48[16]; // [rsp+30h] [rbp-38h] BYREF

strcpy(v48, ":C:S:k:K:I:M:");
*(__m128i *)shortopts = _mm_load_si128((const __m128i *)&LC26);
v47 = _mm_load_si128((const __m128i *)&LC27);
func3();
LABEL_2:
while ( 2 )
{
result = getopt(argc, argv, shortopts);
if ( result != -1 )
{
switch ( result )
{
case '?':
goto LABEL_101;
case 'B':
buffer = atoi(optarg);
if ( (unsigned int)(buffer - (_DWORD)&unk_10000) > 0x63F0000 )
{
fwrite("Invalid buffer size\n", 1uLL, 0x14uLL, stderr);
exit(1);
}
continue;
case 'C':
func2((__int64)&client_fp, &client_fp_count, optarg);
continue;
case 'H':
v15 = strtok(optarg, ",");
if ( !v15 )
continue;
do
{
v32 = strchr(v15, 58);
if ( v32 )
{
v33 = strdup(v15);
v34 = v32++;
v35 = v34 - v15;
v15 = v33;
v33[v35] = 0;
}
LOWORD(hb_hosts[4 * hbhost_count]) = 2;
if ( inet_addr(v15) == -1 )
{
v36 = gethostbyname(v15);
if ( !v36 )
goto LABEL_102;
hb_hosts[4 * hbhost_count + 1] = **(_DWORD **)v36->h_addr_list;
}
else
{
v27 = hbhost_count;
hb_hosts[4 * v27 + 1] = inet_addr(v15);
}
if ( !v32 || (free(v15), v28 = atoi(v32), v29 = v28, (unsigned int)(v28 - 1) > 0xFFFE) )
v29 = 1044;
++hbhost_count;
v30 = func1(v29);
*(_WORD *)((char *)hb_hosts + v31 + 2) = v30;
v15 = strtok(0LL, ",");
}
while ( v15 );
continue;
case 'I':
v15 = strtok(optarg, ",");
LABEL_53:
if ( !v15 )
continue;
v21 = getifbyname(v15, &ifl, (unsigned int)ifl_len);
if ( v21 != -1 )
{
v16 = interface_count;
v17 = (const __m128i *)((char *)&ifl + 40 * v21);
v18 = _mm_loadu_si128(v17);
++interface_count;
v19 = _mm_loadu_si128(v17 + 1);
v20 = (__m128i *)((char *)&m_interface + 40 * v16);
*v20 = v18;
v20[1] = v19;
LABEL_52:
v20[2].m128i_i64[0] = v17[2].m128i_i64[0];
v15 = strtok(0LL, ",");
goto LABEL_53;
}
if ( inet_addr(v15) == -1 )
{
v37 = gethostbyname(v15);
if ( !v37 )
{
LABEL_102:
v43 = v15;
goto LABEL_103;
}
v22 = (int *)*v37->h_addr_list;
}
else
{
v45 = inet_addr(v15);
v22 = (int *)&v45;
}
v23 = getifbyaddr((unsigned int)*v22, &ifl, (unsigned int)ifl_len);
if ( v23 != -1 )
{
v24 = interface_count;
v17 = (const __m128i *)((char *)&ifl + 40 * v23);
v25 = _mm_loadu_si128(v17);
++interface_count;
v26 = _mm_loadu_si128(v17 + 1);
v20 = (__m128i *)((char *)&m_interface + 40 * v24);
*v20 = v25;
v20[1] = v26;
goto LABEL_52;
}
fprintf(stderr, "Interface %s not found\n", v15);
break;
case 'K':
newkeylen = atoi(optarg);
if ( (unsigned int)(newkeylen - 512) > 0x600 )
{
fwrite("Invalid new key length\n", 1uLL, 0x17uLL, stderr);
exit(1);
}
continue;
case 'L':
strncpy(logfile, optarg, 0x12BuLL);
logfile[299] = 0;
continue;
case 'M':
v13 = strtok(optarg, ",");
if ( !v13 )
continue;
while ( 1 )
{
v14 = pub_multi_count;
*(&pub_multi.s_addr + v14) = inet_addr(v13);
if ( *(&pub_multi.s_addr + pub_multi_count) == -1
|| !(unsigned int)is_multicast(*(&pub_multi.s_addr + pub_multi_count), 0LL) )
{
break;
}
++pub_multi_count;
v13 = strtok(0LL, ",");
if ( !v13 )
goto LABEL_2;
}
fprintf(stderr, "Invalid multicast address: %s\n", v13);
break;
case 'O':
v12 = getifbyname(optarg, &ifl, (unsigned int)ifl_len);
if ( v12 != -1 )
goto LABEL_39;
if ( inet_addr(optarg) == -1 )
{
v42 = gethostbyname(optarg);
if ( !v42 )
{
LABEL_105:
v43 = optarg;
LABEL_103:
fprintf(stderr, "Invalid host name: %s\n", v43);
exit(1);
}
v40 = (int *)*v42->h_addr_list;
}
else
{
v45 = inet_addr(optarg);
v40 = (int *)&v45;
}
v12 = getifbyaddr((unsigned int)*v40, &ifl, (unsigned int)ifl_len);
if ( v12 == -1 )
{
fprintf(stderr, "Interface %s not found\n", optarg);
break;
}
LABEL_39:
out_addr = *((_DWORD *)&ifl + 10 * v12 + 7);
continue;
case 'P':
strncpy(pidfile, optarg, 0x12BuLL);
pidfile[299] = 0;
continue;
case 'Q':
v11 = strtol(optarg, 0LL, 0);
if ( v11 > 0x3F )
{
fwrite("Invalid dscp\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
dscp = 4 * v11;
continue;
case 'S':
func2((__int64)&server_fp, &server_fp_count, optarg);
continue;
case 'T':
proxy_int = atoi(optarg);
if ( (unsigned int)(proxy_int - 10) > 0x59 )
{
fwrite("Invalid interval percentage\n", 1uLL, 0x1CuLL, stderr);
exit(1);
}
continue;
case 'U':
uid = inet_addr(optarg);
if ( uid )
{
if ( (unsigned int)func0(uid) > (unsigned int)&unk_FFFFFF )
goto LABEL_31;
}
else
{
uid = strtol(optarg, 0LL, 16);
if ( uid - 1 > (unsigned int)&unk_FFFFFE )
{
LABEL_31:
fwrite("Invalid UID\n", 1uLL, 0xCuLL, stderr);
exit(1);
}
uid = func0(uid);
}
continue;
case 'c':
if ( proxy_type )
goto LABEL_111;
proxy_type = 2;
continue;
case 'd':
debug = 1;
continue;
case 'h':
hb_interval = atoi(optarg);
if ( (unsigned int)(hb_interval - 1) > 0xE0F )
{
fwrite("Invalid hearbeat interval\n", 1uLL, 0x1AuLL, stderr);
exit(1);
}
continue;
case 'k':
for ( i = strtok(optarg, ","); i; i = strtok(0LL, ",") )
{
v9 = keyfile_count + 1;
v10 = strncpy(&keyfile[300 * keyfile_count], i, 0x12BuLL);
keyfile_count = v9;
v10[299] = 0;
}
continue;
case 'm':
sys_keys = 1;
continue;
case 'n':
noname = 1;
continue;
case 'p':
port = atoi(optarg);
if ( !port )
{
fwrite("Invalid port\n", 1uLL, 0xDuLL, stderr);
exit(1);
}
continue;
case 'q':
out_port = atoi(optarg);
if ( !out_port )
{
fwrite("Invalid outgoing port\n", 1uLL, 0x16uLL, stderr);
exit(1);
}
continue;
case 'r':
if ( proxy_type )
goto LABEL_111;
proxy_type = 3;
continue;
case 's':
if ( proxy_type )
{
LABEL_111:
fwrite("Only one of -s, -c, -r may be specified\n", 1uLL, 0x28uLL, stderr);
exit(1);
}
proxy_type = 1;
down_addr = 0LL;
if ( *optarg == 102 && optarg[1] == 112 && optarg[2] == 61 )
{
have_down_fingerprint = parse_fingerprint(&down_fingerprint, optarg + 3);
if ( !have_down_fingerprint )
{
fwrite("Failed to parse downstream fingerprint\n", 1uLL, 0x27uLL, stderr);
exit(1);
}
v6 = time(0LL);
v7 = getpid();
srand(v6 ^ v7);
down_nonce = rand();
}
else
{
have_down_fingerprint = 0;
LOWORD(down_addr) = 2;
if ( inet_addr(optarg) == -1 )
{
v41 = gethostbyname(optarg);
if ( !v41 )
goto LABEL_105;
DWORD1(down_addr) = **(_DWORD **)v41->h_addr_list;
}
else
{
DWORD1(down_addr) = inet_addr(optarg);
}
}
continue;
case 't':
v5 = atoi(optarg);
if ( (unsigned __int64)(v5 - 1LL) > 0xFE )
{
fwrite("Invalid ttl\n", 1uLL, 0xCuLL, stderr);
exit(1);
}
ttl = v5;
continue;
case 'v':
verbose = atoi(optarg);
continue;
default:
continue;
}
LABEL_46:
exit(1);
}
break;
}
if ( !proxy_type )
{
fwrite("Either -s, -c, or -r must be specified\n", 1uLL, 0x27uLL, stderr);
LABEL_101:
fwrite(
"uftpproxyd { -s { dest | fp=fingerprint } | -c | -r } [ -d ] [ -n ]\n"
" [ -p port ] [ -t ttl ] [ -Q dscp ] [ -O out_multi_interface ]\n"
" [ -U UID ] [ -q dest_port ] [ -T interval_pct ] [ -m ]\n"
" [ -H hb_server[:port][,hb_server[:port]...] ] [ -h hb_interval ]\n"
" [ -B udp_buf_size ] [ -L logfile ] [ -P pidfile ] [ -C clientlist_file ]\n"
" [ -S serverlist_file ] [ -k keyfile[,keyfile...] ] [ -K new_key_length ]\n"
" [ -I interface[,interface...] ] [ -M pub_mcast_addr[,pub_mcast_addr...] ]\n",
1uLL,
0x1EEuLL,
stderr);
exit(1);
}
if ( proxy_type != 2 )
{
WORD1(down_addr) = func1(out_port);
result = server_fp_count;
if ( server_fp_count )
{
result = pub_multi_count;
if ( pub_multi_count > 0 )
{
v39 = 0;
while ( (unsigned int)is_multicast(*(&pub_multi.s_addr + v39), 1LL) )
{
result = pub_multi_count;
if ( pub_multi_count <= ++v39 )
goto LABEL_85;
}
v44 = inet_ntoa(*(&pub_multi + v39));
fprintf(stderr, "Invalid source specific multicast address: %s\n", v44);
goto LABEL_46;
}
LABEL_85:
if ( !result )
{
fprintf(stderr, "Default multicast address %s invalid for source specific multicast\n", "230.4.4.1");
goto LABEL_46;
}
v38 = proxy_type;
}
if ( v38 == 3 )
{
result = (unsigned __int16)port;
out_port = port;
}
}
return result;
}

variable_types: struct in_addr { unsigned int s_addr; } *


decompiled_code:
__int64 set_defaults()
{
__int64 result; // rax

memset(&hb_hosts, 0, 0x640uLL);
out_port = 1044;
proxy_type = 0;
proxy_int = 50;
hbhost_count = 0;
hb_interval = 20;
debug = 0;
noname = 0;
verbose = 0;
port = 1044;
out_addr = -1;
ttl = 1;
dscp = 0;
uid = 0;
buffer = 0;
strncpy(logfile, "/tmp/uftpproxyd.log", 0x12BuLL);
result = 0LL;
logfile[299] = 0;
memset(pidfile, 0, 0x128uLL);
server_fp_count = 0;
client_fp_count = 0;
key_count = 0;
keyfile_count = 0;
newkeylen = 0;
interface_count = 0;
*(_DWORD *)&pidfile[296] = 0;
pub_multi_count = 0;
sys_keys = 0;
return result;
}

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

memset(&hb_hosts, 0, 0x640uLL);
out_port = 1044;
proxy_type = 0;
proxy_int = 50;
hbhost_count = 0;
hb_interval = 20;
debug = 0;
noname = 0;
verbose = 0;
port = 1044;
out_addr = -1;
ttl = 1;
dscp = 0;
uid = 0;
buffer = 0;
strncpy(logfile, "/tmp/uftpproxyd.log", 0x12BuLL);
result = 0LL;
logfile[299] = 0;
memset(pidfile, 0, 0x128uLL);
server_fp_count = 0;
client_fp_count = 0;
key_count = 0;
keyfile_count = 0;
newkeylen = 0;
interface_count = 0;
*(_DWORD *)&pidfile[296] = 0;
pub_multi_count = 0;
sys_keys = 0;
return result;
}

original_code:
void set_defaults()
{
    proxy_type = UNDEF_PROXY;
    proxy_int = 50;
    hbhost_count = 0;
    memset(hb_hosts, 0, sizeof(hb_hosts));
    hb_interval = 20;
    debug = 0;
    noname = 0;
    verbose = 0;
    port = 1044;
    out_addr.s_addr = ((in_addr_t) 0xffffffff);
    ttl = 1;
    dscp = 0;
    out_port = 1044;
    uid = 0;
    buffer = 0;
    strncpy(logfile, "/tmp/uftpproxyd.log", sizeof(logfile)-1);
    logfile[sizeof(logfile)-1] = '\x0';
    memset(pidfile, 0, sizeof(pidfile));
    server_fp_count = 0;
    client_fp_count = 0;
    key_count = 0;
    keyfile_count = 0;
    newkeylen = 0;
    interface_count = 0;
    pub_multi_count = 0;
    sys_keys = 0;
}

canonical_original_code:
void set_defaults()
{
    proxy_type = UNDEF_PROXY;
    proxy_int = 50;
    hbhost_count = 0;
    memset(hb_hosts, 0, sizeof(hb_hosts));
    hb_interval = 20;
    debug = 0;
    noname = 0;
    verbose = 0;
    port = 1044;
    out_addr.s_addr = ((unsigned int) 0xffffffff);
    ttl = 1;
    dscp = 0;
    out_port = 1044;
    uid = 0;
    buffer = 0;
    strncpy(logfile, "/tmp/uftpproxyd.log", sizeof(logfile)-1);
    logfile[sizeof(logfile)-1] = '\x0';
    memset(pidfile, 0, sizeof(pidfile));
    server_fp_count = 0;
    client_fp_count = 0;
    key_count = 0;
    keyfile_count = 0;
    newkeylen = 0;
    interface_count = 0;
    pub_multi_count = 0;
    sys_keys = 0;
}