//
// sub_100579A34 from 0x100579a34 to 0x10057a330 (2300 bytes)
//
// 1 xrefs:
// > sub_1005793F0 @ 0x100579428
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
__int64 __fastcall sub_100579A34(__int64 a1)
{
__int64 v2; // x21
__int64 v3; // x8
__int64 v4; // x20
_BYTE *v5; // x21
__int64 result; // x0
__int64 v7; // x23
__int64 v8; // x27
unsigned int *v9; // x22
const char *v10; // x26
__int64 v11; // x27
size_t v12; // x25
int v13; // w8
__int64 v14; // x25
__int64 v15; // x23
const char *v16; // x27
unsigned int *v17; // x24
__int64 v18; // x25
__int64 v19; // x22
char *v20; // x26
size_t v21; // x0
__int64 v22; // x8
bool v23; // zf
__int64 v24; // x0
_BYTE **v25; // x8
__int64 v26; // x0
__int64 v27; // x9
_QWORD *v28; // x0
unsigned __int64 v29; // x8
size_t v30; // x25
__int64 v31; // x8
__int64 v32; // x8
unsigned __int64 v33; // x22
unsigned __int8 *v34; // x26
unsigned __int64 v35; // x8
__int64 i; // x25
int v38; // w0
int v39; // w8
int v40; // w8
__int64 v41; // x28
__int64 v43; // x0
__int64 v44; // [xsp+20h] [xbp-90h]
unsigned int *v45; // [xsp+28h] [xbp-88h]
__int64 v46; // [xsp+30h] [xbp-80h]
_BYTE *v47; // [xsp+38h] [xbp-78h]
__int64 v48; // [xsp+40h] [xbp-70h] BYREF
unsigned int v49; // [xsp+4Ch] [xbp-64h] BYREF
__int64 v50; // [xsp+50h] [xbp-60h] BYREF
int v51; // [xsp+5Ch] [xbp-54h] BYREF
v2 = *(unsigned int *)(a1 + 464);
v3 = *(_QWORD *)a1;
v4 = a1 + 1336;
v48 = 0;
if ( *(_DWORD *)(a1 + 1448) != 5 )
{
if ( *(_QWORD *)(a1 + 1384) )
return sub_10057ABFC(a1 + 1336);
v7 = a1 + 1336;
v8 = a1 + 1464;
v46 = a1 + 1336;
v47 = (_BYTE *)(a1 + 1452);
v9 = (unsigned int *)(v3 + 35744);
v45 = (unsigned int *)(v3 + 35744);
v10 = "EHLO %s";
while ( 2 )
{
result = sub_10057A914(v2, v4, &v49, &v48);
if ( (_DWORD)result )
return result;
v40 = *(_DWORD *)(a1 + 1448);
v41 = v49;
if ( v40 != 12 && v49 != 1 )
{
*v9 = v49;
v41 = v49;
}
if ( !(_DWORD)v41 )
return 0;
switch ( v40 )
{
case 1:
if ( (unsigned int)(v41 - 200) < 0x64 )
goto LABEL_26;
sub_100552734(*(_QWORD *)a1, "Got unexpected smtp-server response: %d", v41);
return 8;
case 2:
v44 = v8;
v11 = *(_QWORD *)a1;
v12 = strlen((const char *)(*(_QWORD *)a1 + 2384LL));
if ( (_DWORD)v41 != 1 && (unsigned int)(v41 - 200) >= 0x64 )
{
if ( *(_DWORD *)(v11 + 1328) < 2u || *(_BYTE *)(a1 + 520) )
{
*(_DWORD *)(a1 + 1484) = 0;
result = sub_10057A8EC(v4, "HELO %s", *(const char **)(a1 + 1456));
if ( !(_DWORD)result )
{
result = 0;
*(_DWORD *)(a1 + 1448) = 3;
}
}
else
{
sub_100552734(v11, "Remote access denied: %d", v41);
result = 9;
}
goto LABEL_117;
}
v28 = (_QWORD *)(v11 + 2388);
v29 = v12 - 4;
if ( v12 - 4 < 8 )
{
if ( v29 < 4 )
goto LABEL_96;
}
else if ( *v28 == 0x534C545452415453LL )
{
*(_BYTE *)(a1 + 1496) = 1;
goto LABEL_96;
}
if ( *(_DWORD *)v28 == 1163544915 )
{
*(_BYTE *)(v7 + 161) = 1;
}
else if ( v29 >= 5 && !memcmp(v28, "AUTH ", 5u) )
{
*(_BYTE *)(v7 + 162) = 1;
v33 = v12 - 9;
if ( v12 != 9 )
{
v34 = (unsigned __int8 *)(v11 + 2393);
do
{
while ( 1 )
{
v35 = *v34;
if ( v35 > 0x20 || ((1LL << v35) & 0x100002600LL) == 0 )
break;
++v34;
if ( !--v33 )
goto LABEL_96;
}
for ( i = 0; ; ++i )
{
if ( (unsigned __int8)v35 <= 0x20u && ((1LL << v35) & 0x100002600LL) != 0 )
goto LABEL_88;
if ( v33 <= i + 1 )
break;
LOBYTE(v35) = v34[i + 1];
}
++i;
LABEL_88:
v38 = sub_10057FE20(v34);
if ( v38 && v50 == i )
*(_DWORD *)(v44 + 12) |= v38;
v34 += i;
v33 -= i;
}
while ( v33 );
}
}
LABEL_96:
if ( (_DWORD)v41 == 1 )
{
result = 0;
v9 = v45;
v10 = "EHLO %s";
}
else
{
v39 = *(_DWORD *)(v11 + 1328);
v9 = v45;
v10 = "EHLO %s";
if ( !v39 || *(_BYTE *)(a1 + 520) )
goto LABEL_112;
if ( *(_BYTE *)(a1 + 1496) )
{
result = sub_10057A8EC(v4, "%s", "STARTTLS");
if ( !(_DWORD)result )
{
result = 0;
*(_DWORD *)(a1 + 1448) = 4;
}
goto LABEL_117;
}
if ( v39 == 1 )
{
LABEL_112:
if ( *(_BYTE *)(v7 + 162) && (sub_10058010C(v44, a1) & 1) != 0 )
{
result = sub_10058012C(v44, a1, 0, &v51);
if ( !(_DWORD)result )
{
if ( v51 == 1 )
{
result = 0;
*(_DWORD *)(a1 + 1448) = 6;
}
else
{
sub_1005524A4(*(_QWORD *)a1, "No known authentication mechanisms supported!\n");
result = 67;
}
}
}
else
{
result = 0;
*(_DWORD *)(a1 + 1448) = 0;
}
goto LABEL_117;
}
sub_100552734(v11, "STARTTLS not supported.");
result = 64;
}
LABEL_117:
v8 = v44;
goto LABEL_118;
case 3:
if ( (unsigned int)(v41 - 200) < 0x64 )
goto LABEL_137;
sub_100552734(*(_QWORD *)a1, "Remote access denied: %d", v41);
return 9;
case 4:
if ( (_DWORD)v41 != 220 )
{
if ( *(_DWORD *)(*(_QWORD *)a1 + 1328LL) != 1 )
{
sub_100552734(*(_QWORD *)a1, "STARTTLS denied. %c", v41);
return 64;
}
if ( *(_BYTE *)(v7 + 162) && (sub_10058010C(v8, a1) & 1) != 0 )
{
result = sub_10058012C(v8, a1, 0, &v50);
if ( !(_DWORD)result )
{
if ( (_DWORD)v50 == 1 )
{
result = 0;
*(_DWORD *)(a1 + 1448) = 6;
}
else
{
sub_1005524A4(*(_QWORD *)a1, "No known authentication mechanisms supported!\n");
result = 67;
}
}
}
else
{
LABEL_94:
result = 0;
*(_DWORD *)(a1 + 1448) = 0;
}
goto LABEL_118;
}
result = sub_100587124(a1, 0, v47);
if ( (_DWORD)result )
return result;
if ( *(_DWORD *)(a1 + 1448) != 5 )
*(_DWORD *)(a1 + 1448) = 5;
if ( !*v47 )
goto LABEL_120;
*(_QWORD *)(a1 + 800) = &off_10082E9D0;
*(_BYTE *)(a1 + 736) = 1;
LABEL_26:
*(_DWORD *)(a1 + 1476) = 0;
*(_DWORD *)(a1 + 1484) = 0;
*(_BYTE *)(a1 + 1496) = 0;
*(_BYTE *)(a1 + 1498) = 0;
result = sub_10057A8EC(v7, v10, *(_QWORD *)(a1 + 1456));
if ( (_DWORD)result )
return result;
v13 = 2;
goto LABEL_108;
case 6:
v14 = *(_QWORD *)a1;
result = sub_100580780(v8, a1, v41, &v50);
if ( (_DWORD)result )
goto LABEL_118;
if ( !(_DWORD)v50 )
{
sub_100552734(v14, "Authentication cancelled");
result = 67;
goto LABEL_118;
}
if ( (_DWORD)v50 == 2 )
goto LABEL_94;
result = 0;
goto LABEL_118;
case 7:
v15 = v8;
v16 = v10;
v17 = v9;
v18 = *(_QWORD *)a1;
v19 = *(_QWORD *)(*(_QWORD *)a1 + 536LL);
v20 = (char *)(*(_QWORD *)a1 + 2384LL);
v21 = strlen(v20);
v22 = *(_QWORD *)(v19 + 16);
if ( (unsigned int)(v41 - 200) >= 0x64
&& (v22 ? (v23 = (_DWORD)v41 == 1) : (v23 = 1), !v23 && (_DWORD)v41 != 553)
|| (_DWORD)v41 != 1 && (unsigned int)(v41 - 200) >= 0x64 && !v22 )
{
sub_100552734(v18, "Command failed: %d", v41);
return 56;
}
if ( *(_BYTE *)(v18 + 1311) )
{
result = 0;
}
else
{
v30 = v18 + v21;
*(_BYTE *)(v30 + 2384) = 10;
result = sub_100552F3C(a1, 1, v20, v21 + 1);
*(_BYTE *)(v30 + 2384) = 0;
}
v10 = v16;
v8 = v15;
if ( (_DWORD)v41 == 1 )
goto LABEL_69;
v31 = *(_QWORD *)(v19 + 16);
if ( v31 && (v32 = *(_QWORD *)(v31 + 8), (*(_QWORD *)(v19 + 16) = v32) != 0) )
{
v9 = v17;
if ( *(_QWORD *)(*(_QWORD *)(*(_QWORD *)a1 + 536LL) + 16LL) )
result = sub_10057A8EC(v4, "%s %s");
else
result = sub_10057A8EC(v4, "%s");
v7 = v46;
if ( (_DWORD)result )
return result;
v13 = 7;
LABEL_108:
*(_DWORD *)(a1 + 1448) = v13;
}
else
{
*(_DWORD *)(a1 + 1448) = 0;
LABEL_69:
v9 = v17;
v7 = v46;
LABEL_118:
if ( (_DWORD)result )
return result;
if ( !*(_DWORD *)(a1 + 1448) )
return 0;
}
LABEL_120:
if ( (sub_10057A72C(v4) & 1) == 0 )
return 0;
continue;
case 8:
v24 = *(_QWORD *)a1;
if ( (unsigned int)(v41 - 200) >= 0x64 )
{
sub_100552734(v24, "MAIL failed: %d");
return 55;
}
v25 = *(_BYTE ***)(*(_QWORD *)(v24 + 536) + 16LL);
goto LABEL_46;
case 9:
v26 = *(_QWORD *)a1;
if ( (unsigned int)(v41 - 200) >= 0x64 )
{
sub_100552734(v26, "RCPT failed: %d");
return 55;
}
v27 = *(_QWORD *)(v26 + 536);
v25 = *(_BYTE ***)(*(_QWORD *)(v27 + 16) + 8LL);
*(_QWORD *)(v27 + 16) = v25;
if ( v25 )
{
LABEL_46:
if ( **v25 == 60 )
result = sub_10057A8EC(v4, "RCPT TO:%s");
else
result = sub_10057A8EC(v4, "RCPT TO:<%s>");
if ( (_DWORD)result )
return result;
v13 = 9;
}
else
{
result = sub_10057A8EC(v4, "%s", "DATA");
if ( (_DWORD)result )
return result;
v13 = 10;
}
goto LABEL_108;
case 10:
v43 = *(_QWORD *)a1;
if ( (_DWORD)v41 != 354 )
{
sub_100552734(v43, "DATA failed: %d");
return 55;
}
sub_10054A740(v43, *(_QWORD *)(v43 + 35640));
sub_100567898(a1, -1, -1, 0, 0, 0, 0);
LABEL_137:
*(_DWORD *)(a1 + 1448) = 0;
return 0;
case 11:
*(_DWORD *)(a1 + 1448) = 0;
if ( (_DWORD)v41 == 250 )
return 0;
return 56;
default:
goto LABEL_137;
}
}
}
v5 = (_BYTE *)(a1 + 1452);
result = sub_100587124(a1, 0, a1 + 1452);
if ( !(_DWORD)result )
{
if ( *(_DWORD *)(a1 + 1448) != 5 )
*(_DWORD *)(a1 + 1448) = 5;
if ( *v5 )
{
*(_DWORD *)(a1 + 1476) = 0;
*(_QWORD *)(a1 + 800) = &off_10082E9D0;
*(_BYTE *)(a1 + 736) = 1;
*(_DWORD *)(a1 + 1484) = 0;
*(_BYTE *)(a1 + 1496) = 0;
*(_BYTE *)(a1 + 1498) = 0;
result = sub_10057A8EC(v4, "EHLO %s", *(const char **)(a1 + 1456));
if ( !(_DWORD)result )
{
*(_DWORD *)(a1 + 1448) = 2;
return 0;
}
}
else
{
return 0;
}
}
return result;
}