//
// sub_844810 from 0x844810 to 0x844c52 (1090 bytes)
//
// 0 xrefs:
//
// 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:23 +0000
//
int __fastcall sub_844810(int *a1, bool *a2)
{
int v2; // r4
int *v3; // r5
int v5; // r8
int v6; // r3
int v7; // r3
int v8; // r2
size_t v9; // r0
int v10; // r2
int v11; // r0
int result; // r0
_BOOL4 v13; // r3
int v14; // r11
size_t v15; // r9
ssize_t v16; // r0
int v17; // r3
const char *v18; // r2
int v19; // r1
int *v20; // r0
char *v21; // r0
size_t v22; // r8
int v23; // r8
__int64 v24; // r2
char *v25; // r10
unsigned __int8 *v26; // r0
size_t v27; // r2
unsigned int v28; // r5
size_t v29; // r6
unsigned int v30; // r7
_BYTE *v31; // r0
int v32; // r9
int v33; // r4
char *v34; // r8
size_t v35; // r4
_BYTE *v36; // r0
unsigned int v37; // r4
size_t v38; // r0
char *v39; // r4
const char *v40; // r9
size_t v41; // r0
int v42; // r0
int v43; // r1
size_t v44; // r0
int v45; // r10
int v46; // r1
__int64 v47; // r2
_DWORD *v48; // r4
int v49; // [sp+2Ch] [bp-1Ch]
int v50; // [sp+30h] [bp-18h]
int *v51; // [sp+34h] [bp-14h]
bool *v52; // [sp+38h] [bp-10h]
size_t v53; // [sp+44h] [bp-4h] BYREF
struct sockaddr v54; // [sp+48h] [bp+0h] BYREF
v2 = a1[272];
v3 = a1;
v5 = *a1;
time((time_t *)&v54);
v6 = *(_DWORD *)(v2 + 40);
if ( v6 < *(int *)&v54.sa_family )
{
*(_DWORD *)(v2 + 8) = -99;
*(_DWORD *)v2 = 3;
*a2 = 0;
goto LABEL_12;
}
if ( *(int *)&v54.sa_family > *(_DWORD *)(v2 + 28) + *(_DWORD *)(v2 + 44) )
{
time((time_t *)(v2 + 44));
v7 = *(_DWORD *)(v2 + 40);
v8 = *(_DWORD *)&v54.sa_family;
*a2 = 0;
if ( v7 - v8 > 0 )
{
v9 = **(_DWORD **)(v2 + 16);
switch ( *(_DWORD *)v2 )
{
case 0:
result = sub_84395C(v2, 7);
if ( !result )
goto LABEL_15;
break;
case 1:
result = sub_843170(v2, 7);
if ( !result )
goto LABEL_15;
break;
case 2:
result = sub_8434D0(v2, 7);
if ( !result )
goto LABEL_15;
break;
case 3:
sub_8280FC(v9, "%s\n", "TFTP finished");
goto LABEL_15;
default:
sub_828178(v9, "%s", "Internal state machine error");
result = 71;
break;
}
return result;
}
LABEL_12:
sub_828178(v5, "TFTP response timeout");
return 28;
}
v10 = v6 - *(_DWORD *)&v54.sa_family;
*a2 = 0;
if ( v10 <= 0 )
goto LABEL_12;
v11 = sub_842E08(*(_DWORD *)(v2 + 20), -1, -1, 0);
if ( v11 == -1 )
{
v20 = (int *)_errno();
v21 = sub_842624((int)v3, *v20);
sub_828178(v5, "%s", v21);
*(_DWORD *)(v2 + 12) = 5;
goto LABEL_8;
}
if ( !v11 )
goto LABEL_8;
v14 = v3[272];
v53 = 128;
v15 = *v3;
v16 = recvfrom(*(_DWORD *)(v14 + 20), *(void **)(v14 + 328), *(_DWORD *)(v14 + 320) + 4, 0, &v54, (socklen_t *)&v53);
v17 = *(_DWORD *)(v14 + 308);
*(_DWORD *)(v14 + 312) = v16;
if ( !v17 )
{
v22 = v53;
memcpy((void *)(v14 + 180), &v54, v53);
v16 = *(_DWORD *)(v14 + 312);
*(_DWORD *)(v14 + 308) = v22;
}
if ( v16 <= 3 )
{
sub_828178(v15, "Received too short packet");
*(_DWORD *)(v14 + 12) = 7;
goto LABEL_30;
}
v18 = *(const char **)(v14 + 328);
v19 = *((unsigned __int8 *)v18 + 1) | (*(unsigned __int8 *)v18 << 8);
*(_DWORD *)(v14 + 12) = v19;
switch ( (__int16)v19 )
{
case 3:
if ( v16 == 4
|| (unsigned __int16)(*(_WORD *)(v14 + 48) + 1) != (*((unsigned __int8 *)v18 + 3)
| (*((unsigned __int8 *)v18 + 2) << 8)) )
{
goto LABEL_36;
}
v23 = sub_8287C8((int)v3, 1, v18 + 4, v16 - 4);
if ( !v23 )
{
v24 = *(_QWORD *)(v15 + 112) + *(_DWORD *)(v14 + 312) - 4;
*(_QWORD *)(v15 + 112) = v24;
sub_820D74(v15, v24);
goto LABEL_36;
}
sub_843D14(v14, 5);
return v23;
case 4:
goto LABEL_36;
case 5:
*(_DWORD *)(v14 + 8) = *((unsigned __int8 *)v18 + 3) | (*((unsigned __int8 *)v18 + 2) << 8);
sub_8280FC(v15, "%s\n", v18 + 4);
goto LABEL_36;
case 6:
v25 = (char *)(v18 + 2);
v26 = (unsigned __int8 *)&v18[v16];
v27 = **(_DWORD **)(v14 + 16);
*(_DWORD *)(v14 + 320) = 512;
v51 = v3;
v28 = (unsigned int)v26;
v52 = a2;
v29 = v27;
v49 = v27;
v50 = v2;
break;
default:
sub_828178(v15, "%s", "Internal error: Unexpected packet");
goto LABEL_36;
}
while ( v28 > (unsigned int)v25 )
{
v30 = v28 - (_DWORD)v25;
v31 = memchr(v25, 0, v28 - (_DWORD)v25);
v32 = v31 - v25;
if ( !v31 )
v32 = v28 - (_DWORD)v25;
v33 = v32 + 1;
if ( v30 <= v32 + 1 )
goto LABEL_61;
v34 = &v25[v33];
v35 = v30 - v33;
v36 = memchr(v34, 0, v35);
if ( v36 )
v35 = v36 - v34;
v37 = v35 + v32 + 2;
if ( v30 < v37 || (v38 = strlen(v25), v39 = &v25[v37], v40 = &v25[v38 + 1], !v39) )
{
LABEL_61:
sub_828178(v49, "Malformed ACK packet, rejecting");
return 71;
}
sub_8280FC(v29, "got option=(%s) value=(%s)\n", v25, &v25[v38 + 1]);
v41 = strlen(v25);
if ( sub_83ACFC(v25, "blksize", v41) )
{
v42 = strtol(v40, nullptr, 10);
if ( !v42 )
{
sub_828178(v49, "invalid blocksize value in OACK packet");
return 71;
}
if ( v42 > 65464 )
{
sub_828178(v49, "%s (%d)", "blksize is larger than max supported", 65464);
return 71;
}
if ( v42 <= 7 )
{
sub_828178(v49, "%s (%d)", "blksize is smaller than min supported", 8);
return 71;
}
v43 = *(_DWORD *)(v14 + 324);
if ( v42 > v43 )
{
sub_828178(v49, "%s (%ld)", "server requested blksize larger than allocated", v42);
return 71;
}
*(_DWORD *)(v14 + 320) = v42;
sub_8280FC(v29, "%s (%d) %s (%d)\n", "blksize parsed from OACK", v42, "requested", v43);
LABEL_54:
v25 = v39;
}
else
{
v44 = strlen(v25);
if ( !sub_83ACFC(v25, "tsize", v44) )
goto LABEL_54;
v45 = strtol(v40, nullptr, 10);
sub_8280FC(v29, "%s (%ld)\n", "tsize parsed from OACK", v45);
if ( *(_BYTE *)(v29 + 905) )
goto LABEL_54;
if ( !v45 )
{
sub_828178(v49, "invalid tsize -:%s:- value in OACK packet", v40);
return 71;
}
v47 = v45;
v25 = v39;
sub_820F14((_DWORD *)v29, v46, v47, SHIDWORD(v47));
}
}
v2 = v50;
v3 = v51;
a2 = v52;
LABEL_36:
if ( sub_820F7C(v3) )
{
sub_843D14(v14, 5);
return 42;
}
LABEL_30:
result = sub_843D14(v2, *(_DWORD *)(v2 + 12));
if ( !result )
{
LABEL_15:
v13 = *(_DWORD *)v2 == 3;
*a2 = *(_DWORD *)v2 == 3;
if ( !v13 )
{
LABEL_9:
if ( sub_820F7C(v3) )
return 42;
v48 = (_DWORD *)*v3;
sub_81FA10((__time_t *)&v54);
return sub_833B2C(v48, *(int *)&v54.sa_family, *(int *)&v54.sa_data[2]);
}
sub_83AA00(v3, -1, -1, -1, 0, 0, -1, nullptr);
LABEL_8:
result = 0;
if ( *a2 )
return result;
goto LABEL_9;
}
return result;
}