//
// sub_6353AC from 0x6353ac to 0x635a5c (1712 bytes)
//
// 1 xrefs:
// > sub_6211D4 @ 0x62124a
//
// 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
//
int __fastcall sub_6353AC(const char *a1, const char *a2, char *a3, int a4, int a5, int a6)
{
int v8; // r8
_DWORD *v9; // r6
size_t v10; // r9
int v11; // r10
int v12; // r0
int v13; // r2
char v14; // r2
int v16; // r0
char *v17; // r1
int v18; // r7
int v19; // r9
int v20; // r3
int v21; // r3
char *v22; // r1
int v23; // r2
int v24; // r3
char v25; // t1
int v26; // r3
char *v27; // r1
int v28; // r2
int v29; // r3
char v30; // t1
size_t v31; // r10
size_t v32; // r0
size_t v33; // r3
size_t v34; // r2
int v35; // r10
size_t v36; // r10
int v37; // r5
int v38; // r4
unsigned int v39; // [sp+44h] [bp-2C8h]
char *v41; // [sp+48h] [bp-2C4h]
void *v43; // [sp+58h] [bp-2B4h]
int v44; // [sp+64h] [bp-2A8h] BYREF
ssize_t v45; // [sp+68h] [bp-2A4h] BYREF
char *v46; // [sp+6Ch] [bp-2A0h] BYREF
char buf[64]; // [sp+70h] [bp-29Ch] BYREF
unsigned __int8 v48; // [sp+B0h] [bp-25Ch] BYREF
unsigned __int8 v49; // [sp+B1h] [bp-25Bh]
char v50; // [sp+B2h] [bp-25Ah] BYREF
char v51; // [sp+B3h] [bp-259h] BYREF
unsigned __int8 v52; // [sp+B4h] [bp-258h]
unsigned __int8 v53; // [sp+B5h] [bp-257h] BYREF
unsigned __int8 v54; // [sp+B6h] [bp-256h]
unsigned __int8 v55; // [sp+B7h] [bp-255h]
unsigned __int8 v56; // [sp+B8h] [bp-254h]
unsigned __int8 v57; // [sp+B9h] [bp-253h]
char v58[594]; // [sp+BAh] [bp-252h] BYREF
v8 = *(_DWORD *)(a6 + 4 * (a5 + 104));
v9 = *(_DWORD **)a6;
v39 = *(_DWORD *)(a6 + 216) == 5;
v10 = strlen(a3);
if ( *(_BYTE *)(a6 + 618) )
sub_61807C((size_t)v9, "SOCKS5: connecting to HTTP proxy %s port %d\n", a3, a4);
if ( (v10 > 0xFF) > v39 )
{
v39 = 1;
sub_61807C(*(_DWORD *)a6, "SOCKS5: server resolving disabled for hostnames of length > 255 [actual len=%zu]\n", v10);
}
v11 = sub_62D584(v9, nullptr, 1);
if ( v11 < 0 )
{
sub_6180F8((int)v9, "Connection time-out");
return 28;
}
sub_636148(v8, 1);
v12 = sub_632D88(-1, -1, v8, v11);
v13 = v12 + 1;
if ( v12 == -1 )
{
sub_6180F8(*(_DWORD *)a6, "SOCKS5: no connection here", v13);
return 7;
}
if ( !v12 )
{
sub_6180F8(*(_DWORD *)a6, "SOCKS5: connection timeout", v13);
return 28;
}
if ( (v12 & 4) != 0 )
{
sub_6180F8(*(_DWORD *)a6, "SOCKS5: error occurred during connection", v13, v12 & 4);
return 7;
}
v50 = 0;
if ( a1 )
v14 = 2;
else
v14 = 1;
v48 = 5;
v49 = v14;
v51 = 2;
sub_636148(v8, 0);
sub_61807C((size_t)v9, "SOCKS5 communication to %s:%d\n", a3, a4);
if ( sub_6183F0((int *)a6, v8, &v48, v49 + 2, &v45) || v49 + 2 != v45 )
{
sub_6180F8((int)v9, "Unable to send initial SOCKS5 request.");
return 7;
}
sub_636148(v8, 1);
v16 = sub_632D88(v8, -1, -1, v11);
if ( v16 == -1 )
{
sub_6180F8(*(_DWORD *)a6, "SOCKS5 nothing to read");
return 7;
}
if ( !v16 )
{
sub_6180F8(*(_DWORD *)a6, "SOCKS5 read timeout");
return 28;
}
if ( (v16 & 4) != 0 )
{
sub_6180F8(*(_DWORD *)a6, "SOCKS5 read error occurred");
return 56;
}
sub_636148(v8, 0);
if ( sub_634F0C((_DWORD **)a6, v8, (char *)&v48, 2u, &v44) || v44 != 2 )
{
sub_6180F8((int)v9, "Unable to receive initial SOCKS5 response.");
return 7;
}
if ( v48 != 5 )
{
sub_6180F8((int)v9, "Received invalid version in initial SOCKS5 response.");
return 7;
}
if ( v49 )
{
if ( v49 != 2 )
{
if ( v49 == 1 )
{
sub_6180F8((int)v9, "SOCKS5 GSSAPI per-message authentication is not supported.");
return 7;
}
else if ( v49 == 255 )
{
if ( a1 && *a1 )
{
sub_6180F8((int)v9, "No authentication method was acceptable.");
return 7;
}
else
{
sub_6180F8(
(int)v9,
"No authentication method was acceptable. (It is quite likely that the SOCKS5 server wanted a username/passwo"
"rd, since none was supplied to the server on this connection.)");
return 7;
}
}
else
{
sub_6180F8((int)v9, "Undocumented SOCKS5 mode attempted to be used by server.");
return 7;
}
}
if ( a1 && a2 )
{
v31 = strlen(a1);
v32 = strlen(a2);
v49 = v31;
v48 = 1;
v33 = v32;
if ( v31 )
{
v43 = (void *)v32;
memcpy(&v50, a1, v31);
v33 = (size_t)v43;
}
v34 = v31 + 2;
v35 = v31 + 3;
*(&v48 + v34) = v33;
if ( v33 )
{
v41 = (char *)v33;
memcpy(&v48 + v35, a2, v33);
v33 = (size_t)v41;
}
}
else
{
v49 = 0;
v33 = 0;
v50 = 0;
v35 = 3;
v48 = 1;
}
v36 = v35 + v33;
if ( sub_6183F0((int *)a6, v8, &v48, v36, &v45) || v36 != v45 )
{
sub_6180F8((int)v9, "Failed to send SOCKS5 sub-negotiation request.");
return 7;
}
if ( sub_634F0C((_DWORD **)a6, v8, (char *)&v48, 2u, &v44) || v44 != 2 )
{
sub_6180F8((int)v9, "Unable to receive SOCKS5 sub-negotiation response.");
return 7;
}
if ( v49 )
{
sub_6180F8((int)v9, "User was rejected by the SOCKS5 server (%d %d).", v48, v49);
return 7;
}
}
v48 = 5;
v50 = 0;
v49 = 1;
if ( v39 )
{
if ( ((sub_610224((int *)a6, a3, a4, (const char **)&v46) + 1) & 0xFFFFFFFD) != 0 )
{
if ( v46 )
{
v19 = *(_DWORD *)v46;
if ( *(_DWORD *)v46 )
{
sub_60FFC0(*(_DWORD *)v46, buf, 64);
v20 = *(_DWORD *)(v19 + 4);
if ( v20 == 2 )
{
v51 = 1;
v26 = *(_DWORD *)(v19 + 24);
v27 = &v51;
v28 = v26 + 3;
v29 = v26 + 7;
do
{
v30 = *(_BYTE *)++v28;
*++v27 = v30;
}
while ( v28 != v29 );
v18 = 8;
sub_61807C((size_t)v9, "SOCKS5 connect to IPv4 %s (locally resolved)\n", buf);
goto LABEL_48;
}
if ( v20 == 10 )
{
v51 = 4;
v21 = *(_DWORD *)(v19 + 24);
v22 = &v51;
v23 = v21 + 7;
v24 = v21 + 23;
do
{
v25 = *(_BYTE *)++v23;
*++v22 = v25;
}
while ( v23 != v24 );
v18 = 20;
sub_61807C((size_t)v9, "SOCKS5 connect to IPv6 %s (locally resolved)\n", buf);
LABEL_48:
sub_610524((int)v9, v46);
goto LABEL_37;
}
sub_6180F8((int)v9, "SOCKS5 connection to %s not supported\n", buf);
sub_610524((int)v9, v46);
}
}
sub_6180F8((int)v9, "Failed to resolve \"%s\" for SOCKS5 connect.", a3);
}
return 6;
}
v17 = a3;
v52 = v10;
v51 = 3;
v18 = v10 + 5;
memcpy(&v53, v17, v10);
LABEL_37:
*(&v48 + v18) = BYTE1(a4);
*(&v48 + v18 + 1) = a4;
if ( sub_6183F0((int *)a6, v8, &v48, v18 + 2, &v45) || v18 + 2 != v45 )
{
sub_6180F8((int)v9, "Failed to send SOCKS5 connect request.");
return 7;
}
if ( sub_634F0C((_DWORD **)a6, v8, (char *)&v48, 0xAu, &v44) )
goto LABEL_76;
v37 = v44;
if ( v44 != 10 )
goto LABEL_76;
if ( v48 != 5 )
{
sub_6180F8((int)v9, "SOCKS5 reply has wrong version, version should be 5.");
return 7;
}
if ( v51 == 3 )
{
v37 = v52 + 7;
if ( v37 <= 10 )
{
if ( v49 )
goto LABEL_90;
LABEL_91:
sub_61807C((size_t)v9, "SOCKS5 request granted.\n");
sub_636148(v8, 1);
return 0;
}
}
else
{
if ( v51 != 4 )
goto LABEL_82;
v37 = 22;
}
if ( sub_634F0C((_DWORD **)a6, v8, v58, v37 - 10, &v44) || v37 - 10 != v44 )
{
LABEL_76:
sub_6180F8((int)v9, "Failed to receive SOCKS5 connect request ack.");
return 7;
}
LABEL_82:
if ( !v49 )
goto LABEL_91;
switch ( v51 )
{
case 1:
sub_6180F8(
(int)v9,
"Can't complete SOCKS5 connection to %d.%d.%d.%d:%d. (%d)",
v52,
v53,
v54,
v55,
v57 | (v56 << 8),
v49);
return 7;
case 3:
LABEL_90:
v38 = *(&v48 + v37 - 2);
*(&v48 + v37 - 2) = 0;
sub_6180F8(
(int)v9,
"Can't complete SOCKS5 connection to %s:%d. (%d)",
(const char *)&v53,
*(&v48 + v37 - 1) | (v38 << 8),
v49);
return 7;
case 4:
sub_6180F8(
(int)v9,
"Can't complete SOCKS5 connection to %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%d. (%d)",
v52,
v53,
v54,
v55,
v56,
v57,
(unsigned __int8)v58[0],
(unsigned __int8)v58[1],
(unsigned __int8)v58[2],
(unsigned __int8)v58[3],
(unsigned __int8)v58[4],
(unsigned __int8)v58[5],
(unsigned __int8)v58[6],
(unsigned __int8)v58[7],
(unsigned __int8)v58[8],
(unsigned __int8)v58[9],
(unsigned __int8)v58[11] | ((unsigned __int8)v58[10] << 8),
v49);
break;
}
return 7;
}