//
// sub_E395A4 from 0xe395a4 to 0xe3997c (984 bytes)
//
// 1 xrefs:
// > lws_read @ 0xe31714
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 13:09:59 +0000
//
__int64 __fastcall sub_E395A4(__int64 a1, _QWORD *a2, __int64 a3)
{
unsigned __int8 *v6; // x1
const char *v8; // x0
char *v9; // x27
int v10; // w26
int v11; // w0
__int64 v12; // x0
int v13; // w3
_QWORD *v14; // x23
int v15; // w25
__int64 v16; // x24
__int64 v17; // x28
unsigned int (__fastcall *v18)(__int64, __int64, __int64, __int64, _QWORD); // x23
__int64 v19; // x0
int v20; // w2
__int64 v21; // x0
int v22; // w2
size_t v23; // x1
void *v24; // x0
__int64 v25; // x19
__int64 context; // [xsp+80h] [xbp+80h]
int v27; // [xsp+88h] [xbp+88h]
__int64 v28; // [xsp+88h] [xbp+88h]
int v29; // [xsp+94h] [xbp+94h] BYREF
char v30[32]; // [xsp+98h] [xbp+98h] BYREF
char v31[128]; // [xsp+B8h] [xbp+B8h] BYREF
context = lws_get_context(a1);
if ( !a3 )
return 0;
while ( 1 )
{
v6 = (unsigned __int8 *)(*a2)++;
if ( (unsigned int)sub_E3433C(a1, *v6) )
goto LABEL_44;
if ( *(_BYTE *)(a1 + 164) == 86 )
break;
LABEL_4:
if ( !--a3 )
return 0;
}
*(_BYTE *)(a1 + 72) = 2;
lws_set_timeout(a1, 0, 0);
if ( !(unsigned int)lws_hdr_total_length(a1, 5u) || !(unsigned int)lws_hdr_total_length(a1, 4u) )
{
v25 = *(_QWORD *)(a1 + 152);
lws_union_transition(a1, 1);
*(_BYTE *)(a1 + 73) = 0;
*(_QWORD *)(a1 + 152) = v25;
*(_DWORD *)(a1 + 160) = -1;
return sub_E392B4(a1);
}
v8 = (const char *)sub_E341E0(a1, 5u);
if ( strcasecmp(v8, "websocket") )
{
LABEL_44:
sub_E33FF8(a1);
return 1;
}
if ( !*(_QWORD *)(a1 + 8) )
lws_log(1, "NULL protocol at lws_read\n");
if ( (lws_hdr_copy(a1, v31, 127, 0xCu) & 0x80000000) != 0 )
{
lws_log(1, "protocol list too long");
goto LABEL_44;
}
v27 = 0;
v9 = v31;
v31[(int)lws_hdr_total_length(a1, 0xCu)] = 0;
v10 = (unsigned __int8)v31[0];
while ( 1 )
{
v11 = v27;
if ( !v10 )
break;
LABEL_14:
if ( v11 )
goto LABEL_33;
v12 = 0;
while ( 1 )
{
v10 = (unsigned __int8)*v9;
v13 = v12;
if ( !*v9 || v10 == 44 )
break;
v30[v12++] = v10;
if ( v12 == 31 )
{
v10 = (unsigned __int8)v9[1];
v13 = 31;
++v9;
break;
}
++v9;
}
v30[v13] = 0;
if ( v10 )
v10 = (unsigned __int8)*++v9;
v14 = *(_QWORD **)(a1 + 8);
if ( v14 )
{
v15 = 1;
v16 = *(_QWORD *)(context + 4584);
while ( 1 )
{
v17 = v16 + 48LL * (unsigned int)(v15 - 1);
if ( !*(_QWORD *)(v17 + 8) )
break;
if ( *v14 && !strcmp(*(const char **)(v16 + 48LL * (unsigned int)(v15 - 1)), v30) )
{
*(_QWORD *)(a1 + 8) = v17;
v27 = 1;
v11 = 1;
if ( v10 )
goto LABEL_14;
goto LABEL_30;
}
++v15;
}
}
}
LABEL_30:
if ( !v11 )
{
if ( sub_E341E0(a1, 0xCu) )
{
lws_log(1, "No protocol from list \"%s\" supported\n", v31);
goto LABEL_44;
}
*(_QWORD *)(a1 + 8) = *(_QWORD *)(context + 4584);
}
LABEL_33:
if ( (unsigned int)sub_E3218C(a1) )
goto LABEL_44;
v28 = *(_QWORD *)(a1 + 144);
v18 = *(unsigned int (__fastcall **)(__int64, __int64, __int64, __int64, _QWORD))(*(_QWORD *)(a1 + 8) + 8LL);
v19 = sub_E341E0(a1, 0xCu);
if ( v18(a1, 20, v28, v19, 0) )
{
lws_log(2, "User code denied connection\n");
goto LABEL_44;
}
v20 = *(unsigned __int8 *)(a1 + 66);
if ( v20 != 13 )
{
lws_log(2, "Unknown client spec version %d\n", v20);
goto LABEL_44;
}
if ( (unsigned int)sub_E3A3A0(context, a1) )
goto LABEL_44;
sub_E33FF8(a1);
lws_union_transition(a1, 3);
v21 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 24LL);
if ( (_DWORD)v21 )
{
v22 = v21 + 28;
v23 = (int)v21 + 28;
}
else
{
v23 = 4124;
v22 = 4124;
}
v29 = v22;
v24 = sub_E35A4C(nullptr, v23);
*(_QWORD *)(a1 + 152) = v24;
if ( v24 )
{
if ( !setsockopt(*(_DWORD *)(a1 + 88), 1, 7, &v29, 4u) )
goto LABEL_4;
lws_log(2, "Failed to set SNDBUF to %d", v29);
return 1;
}
else
{
lws_log(1, "Out of Mem allocating rx buffer %d\n", v29);
return 1;
}
}