//
// sub_843FB0 from 0x843fb0 to 0x8443d2 (1058 bytes)
//
// 1 xrefs:
// > sub_844440 @ 0x84448e
//
// 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_843FB0(int *a1, bool *a2)
{
int v2; // r4
int *v3; // r5
int v5; // r9
int v6; // r3
int v7; // r3
int v8; // r2
size_t v9; // r0
int v10; // r3
int v11; // r0
int result; // r0
_BOOL4 v13; // r3
int v14; // r10
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; // r7
int v23; // r7
__int64 v24; // r2
char *v25; // r9
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; // r8
int v33; // r4
char *v34; // r11
size_t v35; // r4
_BYTE *v36; // r0
unsigned int v37; // r4
size_t v38; // r0
char *v39; // r4
const char *v40; // r8
size_t v41; // r0
int v42; // r0
int v43; // r1
size_t v44; // r0
int v45; // r9
int v46; // r1
__int64 v47; // r2
int v48; // [sp+28h] [bp-9Ch]
int v49; // [sp+2Ch] [bp-98h]
int *v50; // [sp+30h] [bp-94h]
bool *v51; // [sp+34h] [bp-90h]
size_t v52; // [sp+3Ch] [bp-88h] BYREF
struct sockaddr timer[8]; // [sp+40h] [bp-84h] BYREF
v2 = a1[272];
v3 = a1;
v5 = *a1;
time((time_t *)timer);
v6 = *(_DWORD *)(v2 + 40);
if ( v6 < *(int *)&timer[0].sa_family )
{
*(_DWORD *)(v2 + 8) = -99;
*(_DWORD *)v2 = 3;
*a2 = 0;
goto LABEL_10;
}
if ( *(int *)&timer[0].sa_family > *(_DWORD *)(v2 + 28) + *(_DWORD *)(v2 + 44) )
{
time((time_t *)(v2 + 44));
v7 = *(_DWORD *)(v2 + 40);
v8 = *(_DWORD *)&timer[0].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_12;
break;
case 1:
result = sub_843170(v2, 7);
if ( !result )
goto LABEL_12;
break;
case 2:
result = sub_8434D0(v2, 7);
if ( !result )
goto LABEL_12;
break;
case 3:
sub_8280FC(v9, "%s\n", "TFTP finished");
goto LABEL_12;
default:
sub_828178(v9, "%s", "Internal state machine error");
result = 71;
break;
}
return result;
}
LABEL_10:
sub_828178(v5, "TFTP response timeout");
return 28;
}
v10 = v6 - *(_DWORD *)&timer[0].sa_family;
*a2 = 0;
if ( v10 <= 0 )
goto LABEL_10;
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;
return 0;
}
if ( !v11 )
return 0;
v14 = v3[272];
v52 = 128;
v15 = *v3;
v16 = recvfrom(*(_DWORD *)(v14 + 20), *(void **)(v14 + 328), *(_DWORD *)(v14 + 320) + 4, 0, timer, (socklen_t *)&v52);
v17 = *(_DWORD *)(v14 + 308);
*(_DWORD *)(v14 + 312) = v16;
if ( !v17 )
{
v22 = v52;
memcpy((void *)(v14 + 180), timer, v52);
v16 = *(_DWORD *)(v14 + 312);
*(_DWORD *)(v14 + 308) = v22;
}
if ( v16 <= 3 )
{
sub_828178(v15, "Received too short packet");
*(_DWORD *)(v14 + 12) = 7;
goto LABEL_27;
}
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_33;
}
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_33;
}
sub_843D14(v14, 5);
return v23;
case 4:
goto LABEL_33;
case 5:
*(_DWORD *)(v14 + 8) = *((unsigned __int8 *)v18 + 3) | (*((unsigned __int8 *)v18 + 2) << 8);
sub_8280FC(v15, "%s\n", v18 + 4);
goto LABEL_33;
case 6:
v25 = (char *)(v18 + 2);
v26 = (unsigned __int8 *)&v18[v16];
v27 = **(_DWORD **)(v14 + 16);
*(_DWORD *)(v14 + 320) = 512;
v50 = v3;
v28 = (unsigned int)v26;
v51 = a2;
v29 = v27;
v48 = v27;
v49 = v2;
break;
default:
sub_828178(v15, "%s", "Internal error: Unexpected packet");
goto LABEL_33;
}
while ( (unsigned int)v25 < v28 )
{
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_58;
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_58:
sub_828178(v48, "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(v48, "invalid blocksize value in OACK packet");
return 71;
}
if ( v42 > 65464 )
{
sub_828178(v48, "%s (%d)", "blksize is larger than max supported", 65464);
return 71;
}
if ( v42 <= 7 )
{
sub_828178(v48, "%s (%d)", "blksize is smaller than min supported", 8);
return 71;
}
v43 = *(_DWORD *)(v14 + 324);
if ( v42 > v43 )
{
sub_828178(v48, "%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_50:
v25 = v39;
}
else
{
v44 = strlen(v25);
if ( !sub_83ACFC(v25, "tsize", v44) )
goto LABEL_50;
v45 = strtol(v40, nullptr, 10);
sub_8280FC(v29, "%s (%ld)\n", "tsize parsed from OACK", v45);
if ( *(_BYTE *)(v29 + 905) )
goto LABEL_50;
if ( !v45 )
{
sub_828178(v48, "invalid tsize -:%s:- value in OACK packet", v40);
return 71;
}
v47 = v45;
v25 = v39;
sub_820F14((_DWORD *)v29, v46, v47, SHIDWORD(v47));
}
}
v2 = v49;
v3 = v50;
a2 = v51;
LABEL_33:
if ( sub_820F7C(v3) )
{
sub_843D14(v14, 5);
return 42;
}
LABEL_27:
result = sub_843D14(v2, *(_DWORD *)(v2 + 12));
if ( !result )
{
LABEL_12:
v13 = *(_DWORD *)v2 == 3;
*a2 = *(_DWORD *)v2 == 3;
if ( v13 )
{
sub_83AA00(v3, -1, -1, -1, 0, 0, -1, nullptr);
return 0;
}
return 0;
}
return result;
}