//
// sub_850354 from 0x850354 to 0x85090a (1462 bytes)
//
// 1 xrefs:
// > sub_84DC64 @ 0x84de60
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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 12:02:31 +0000
//
int __fastcall sub_850354(size_t a1, char *a2, const char *a3, const char *a4, int a5, const char **a6, size_t *a7)
{
int result; // r0
char *v9; // r11
char *v10; // r0
int v11; // r3
char *v12; // r2
bool v13; // zf
int v14; // r0
int v15; // t1
bool v16; // zf
char *v17; // r3
int v18; // r10
char *v19; // r0
int v20; // r3
char *v21; // r0
bool v22; // zf
int v23; // t1
bool v24; // zf
char *v25; // r10
char *v26; // r0
int v27; // r3
char *v28; // r0
bool v29; // zf
int v30; // r2
int v31; // t1
bool v32; // zf
char *v33; // r2
char *v34; // r0
int v35; // r2
char *v36; // r1
bool v37; // zf
int v38; // r3
int v39; // t1
bool v40; // zf
char *v41; // r3
int v42; // r7
char *v43; // r0
char *v44; // r0
char *v45; // r4
void **v46; // r5
void **v47; // r0
void **v48; // r5
char *v49; // r5
char *v50; // r4
int v51; // t1
char *v52; // r10
void **v53; // r5
char *v54; // r8
char *v55; // r5
char *v56; // r0
int v57; // t1
void **v58; // r0
void **v59; // r5
const char **v60; // r8
char *v61; // r5
int v62; // t1
char *v63; // r4
int v64; // r7
char *v68; // [sp+34h] [bp-20h]
char v69[8]; // [sp+4Ch] [bp-8h] BYREF
char v70[12]; // [sp+54h] [bp+0h] BYREF
char v71[16]; // [sp+60h] [bp+Ch] BYREF
_BYTE v72[16]; // [sp+70h] [bp+1Ch] BYREF
_DWORD v73[4]; // [sp+80h] [bp+2Ch] BYREF
char v74; // [sp+90h] [bp+3Ch] BYREF
char v75; // [sp+B0h] [bp+5Ch] BYREF
char v76; // [sp+B4h] [bp+60h] BYREF
char v77; // [sp+D4h] [bp+80h] BYREF
const char *v78[8]; // [sp+D8h] [bp+84h] BYREF
char v79; // [sp+F8h] [bp+A4h] BYREF
char *v80[9]; // [sp+FCh] [bp+A8h] BYREF
char v81[63]; // [sp+120h] [bp+CCh] BYREF
char v82; // [sp+15Fh] [bp+10Bh] BYREF
char v83[63]; // [sp+160h] [bp+10Ch] BYREF
char v84; // [sp+19Fh] [bp+14Bh] BYREF
char v85[63]; // [sp+1A0h] [bp+14Ch] BYREF
char v86; // [sp+1DFh] [bp+18Bh] BYREF
char v87[127]; // [sp+1E0h] [bp+18Ch] BYREF
char v88; // [sp+25Fh] [bp+20Bh] BYREF
strcpy(v70, "00000001");
strcpy(v71, "AUTHENTICATE");
v78[0] = nullptr;
strcpy(v69, "auth");
v80[0] = nullptr;
if ( !strlen(a2) )
return 61;
result = (unsigned __int8)*a2;
if ( result != 61 )
{
result = sub_81FB28(a2, v78, (size_t *)v80);
if ( !result )
{
v9 = (char *)v78[0];
if ( v78[0] )
{
v10 = strstr(v78[0], "nonce=\"");
if ( !v10 )
goto LABEL_77;
v11 = (unsigned __int8)v10[7];
v12 = v10 + 7;
v13 = v11 == 0;
if ( v10[7] )
v13 = v11 == 34;
if ( v13 )
{
v17 = v81;
}
else
{
v14 = 0;
do
{
v81[v14++] = v11;
v15 = (unsigned __int8)*++v12;
v11 = v15;
v16 = v15 == 0;
if ( v15 )
v16 = v11 == 34;
if ( v16 )
{
v17 = &v81[v14];
goto LABEL_16;
}
}
while ( v14 != 63 );
v17 = &v82;
}
LABEL_16:
v18 = 0;
*v17 = 0;
v19 = strstr(v9, "realm=\"");
if ( v19 )
{
v20 = (unsigned __int8)v19[7];
v21 = v19 + 7;
v22 = v20 == 0;
if ( v20 )
v22 = v20 == 34;
if ( v22 )
{
v25 = v87;
}
else
{
do
{
v87[v18++] = v20;
v23 = (unsigned __int8)*++v21;
v20 = v23;
v24 = v23 == 0;
if ( v23 )
v24 = v20 == 34;
if ( v24 )
{
v25 = &v87[v18];
goto LABEL_27;
}
}
while ( v18 != 127 );
v25 = &v88;
}
LABEL_27:
*v25 = 0;
}
else
{
v87[0] = 0;
}
v26 = strstr(v9, "algorithm=");
if ( !v26 )
goto LABEL_77;
v27 = (unsigned __int8)v26[10];
v28 = v26 + 10;
v29 = v27 == 0;
if ( v27 )
v29 = v27 == 44;
if ( v29 )
{
v33 = v83;
}
else
{
v30 = 0;
do
{
v83[v30++] = v27;
v31 = (unsigned __int8)*++v28;
v27 = v31;
v32 = v31 == 0;
if ( v31 )
v32 = v27 == 44;
if ( v32 )
{
v33 = &v83[v30];
goto LABEL_39;
}
}
while ( v30 != 63 );
v33 = &v84;
}
LABEL_39:
*v33 = 0;
v34 = strstr(v9, "qop=\"");
if ( !v34 )
{
LABEL_77:
off_D200B0(v9);
return 61;
}
v35 = (unsigned __int8)v34[5];
v36 = v34 + 5;
v37 = v35 == 0;
if ( v34[5] )
v37 = v35 == 34;
if ( v37 )
{
v41 = v85;
}
else
{
v38 = 0;
do
{
v85[v38++] = v35;
v39 = (unsigned __int8)*++v36;
v35 = v39;
v40 = v39 == 0;
if ( v39 )
v40 = v35 == 34;
if ( v40 )
{
v41 = &v85[v38];
goto LABEL_50;
}
}
while ( v38 != 63 );
v41 = &v86;
}
LABEL_50:
*v41 = 0;
off_D200B0(v9);
v42 = strcmp(v83, "md5-sess");
if ( !v42 )
{
v43 = off_D200B8(v85);
v68 = v43;
if ( !v43 )
return 27;
v44 = strtok_r(v43, ",", v80);
if ( v44 )
{
v45 = v44;
do
{
if ( sub_83AAF4(v45, "auth") )
{
v42 |= 1u;
}
else if ( sub_83AAF4(v45, "auth-int") )
{
v42 |= 2u;
}
else if ( sub_83AAF4(v45, "auth-conf") )
{
v42 |= 4u;
}
v45 = strtok_r(nullptr, ",", v80);
}
while ( v45 );
off_D200B0(v68);
if ( (v42 & 1) != 0 )
{
result = sub_84E000(a1, (int)v73, 4);
if ( result )
return result;
sub_8346C0(v80, 33, "%08x%08x%08x%08x", v73[0], v73[1], v73[2], v73[3]);
v46 = (void **)sub_8420C4((int)&off_D132D0);
if ( v46 )
{
strlen(a3);
nullsub_1();
sub_842108(v46);
sub_842108(v46);
strlen(v87);
nullsub_1();
sub_842108(v46);
sub_842108(v46);
strlen(a4);
nullsub_1();
sub_842108(v46);
sub_842118(v46, (int)v72);
v47 = (void **)sub_8420C4((int)&off_D132D0);
v48 = v47;
if ( v47 )
{
sub_842108(v47);
sub_842108(v48);
strlen(v81);
nullsub_1();
sub_842108(v48);
sub_842108(v48);
strlen((const char *)v80);
nullsub_1();
sub_842108(v48);
sub_842118(v48, (int)v72);
v49 = &v74;
v50 = &v71[15];
do
{
v51 = (unsigned __int8)*++v50;
sub_8346C0(v49, 3, "%02x", v51);
v49 += 2;
}
while ( v49 != &v75 );
v52 = sub_84FF20(a5, (int)v87, 0);
if ( v52 )
{
v53 = (void **)sub_8420C4((int)&off_D132D0);
if ( !v53 )
goto LABEL_90;
strlen(v71);
nullsub_1();
sub_842108(v53);
sub_842108(v53);
strlen(v52);
nullsub_1();
sub_842108(v53);
sub_842118(v53, (int)v72);
v54 = &v76;
v55 = &v71[15];
do
{
v56 = v54;
v54 += 2;
v57 = (unsigned __int8)*++v55;
sub_8346C0(v56, 3, "%02x", v57);
}
while ( v54 != &v77 );
v58 = (void **)sub_8420C4((int)&off_D132D0);
v59 = v58;
if ( !v58 )
{
LABEL_90:
off_D200B0(v52);
return 27;
}
sub_842108(v58);
sub_842108(v59);
strlen(v81);
nullsub_1();
sub_842108(v59);
sub_842108(v59);
strlen(v70);
nullsub_1();
sub_842108(v59);
sub_842108(v59);
strlen((const char *)v80);
nullsub_1();
sub_842108(v59);
sub_842108(v59);
strlen(v69);
nullsub_1();
sub_842108(v59);
sub_842108(v59);
sub_842108(v59);
v60 = v78;
sub_842118(v59, (int)v72);
v61 = &v71[15];
do
{
v62 = (unsigned __int8)*++v61;
sub_8346C0(v60, 3, "%02x", v62);
v60 = (const char **)((char *)v60 + 2);
}
while ( v60 != (const char **)&v79 );
v63 = sub_837044(
"username=\"%s\",realm=\"%s\",nonce=\"%s\",cnonce=\"%s\",nc=\"%s\",digest-uri=\"%s\",response=%s,qop=%s",
a3,
v87,
v81,
(const char *)v80,
v70,
v52,
(const char *)v78,
v69);
off_D200B0(v52);
if ( v63 )
{
v64 = sub_81FC8C(a1, v63, 0, a6, a7);
off_D200B0(v63);
return v64;
}
}
}
}
return 27;
}
}
else
{
off_D200B0(v68);
}
}
}
return 61;
}
}
return result;
}