// // sub_10057171C from 0x10057171c to 0x100571e84 (1896 bytes) // // 3 xrefs: // > sub_100571370 @ 0x1005713dc // > sub_100571EB4 @ 0x100571ec8 // > @ 0x10082e4a0 // // 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 // __int64 __fastcall sub_10057171C(__int64 *a1, bool *a2) { __int64 v4; // x22 __int64 v5; // x20 __int64 v6; // x9 __int64 v7; // x8 __int64 v8; // x1 int v9; // w0 int *v10; // x0 const char *v11; // x0 __int64 v12; // x22 size_t v14; // x25 __int64 v15; // x27 int v16; // w0 unsigned __int8 *v17; // x8 int v18; // w10 size_t v19; // x0 size_t v20; // x0 bool v21; // zf __int16 v22; // w8 __int64 v23; // x9 char *v24; // x28 unsigned __int64 v25; // x26 _BYTE *v26; // x0 unsigned __int64 v27; // x22 unsigned __int64 v28; // x8 char *v29; // x27 char *v30; // x0 char *v31; // x8 unsigned __int64 v32; // x22 size_t v33; // x0 char *v34; // x25 const char *v35; // x26 size_t v36; // x0 __int64 v37; // x0 __int64 v38; // x8 size_t v39; // x0 __int64 v40; // x28 __int16 v41; // w8 const char *v42; // x1 __int64 v43; // x1 __int64 v44; // x8 const char *v45; // x9 __int16 v46; // w8 __int16 v47; // w8 const char *v48; // [xsp+0h] [xbp-130h] __int64 v49; // [xsp+8h] [xbp-128h] unsigned __int64 v50; // [xsp+30h] [xbp-100h] size_t v51; // [xsp+38h] [xbp-F8h] __int64 v52; // [xsp+40h] [xbp-F0h] socklen_t v53; // [xsp+54h] [xbp-DCh] BYREF sockaddr __src[8]; // [xsp+58h] [xbp-D8h] BYREF v4 = *a1; v5 = a1[167]; time((time_t *)__src); v6 = *(_QWORD *)&__src[0].sa_len; v7 = *(_QWORD *)(v5 + 48); if ( *(__int64 *)&__src[0].sa_len > v7 ) { *(_DWORD *)(v5 + 8) = -99; *(_DWORD *)v5 = 3; *a2 = 0; LABEL_11: sub_100552734(v4, "TFTP response timeout"); return 28; } if ( *(__int64 *)&__src[0].sa_len <= *(int *)(v5 + 32) + *(_QWORD *)(v5 + 56) ) { v8 = 0xFFFFFFFFLL; } else { time((time_t *)(v5 + 56)); v7 = *(_QWORD *)(v5 + 48); v8 = 7; v6 = *(_QWORD *)&__src[0].sa_len; } *a2 = 0; if ( v7 <= v6 ) goto LABEL_11; if ( (_DWORD)v8 != -1 ) goto LABEL_30; v9 = sub_100570DE8(*(_DWORD *)(v5 + 24), -1, -1, 0); if ( !v9 ) return 0; if ( v9 == -1 ) { v10 = __error(); v11 = (const char *)sub_100570168((__int64)a1, *v10); sub_100552734(v4, "%s", v11); v12 = 0; *(_DWORD *)(v5 + 12) = 5; return v12; } v14 = *a1; v15 = a1[167]; v53 = 128; v16 = recvfrom(*(_DWORD *)(v15 + 24), *(void **)(v15 + 352), *(int *)(v15 + 340) + 4LL, 0, __src, &v53); *(_DWORD *)(v15 + 332) = v16; if ( !*(_DWORD *)(v15 + 328) ) { memcpy((void *)(v15 + 200), __src, v53); *(_DWORD *)(v15 + 328) = v53; v16 = *(_DWORD *)(v15 + 332); } if ( v16 <= 3 ) { sub_100552734(v14, "Received too short packet"); *(_DWORD *)(v15 + 12) = 7; LABEL_29: v8 = *(unsigned int *)(v5 + 12); LABEL_30: v12 = sub_10057213C(v5, v8); if ( (_DWORD)v12 ) return v12; v21 = *(_DWORD *)v5 == 3; *a2 = v21; if ( v21 ) sub_100567898((__int64)a1, -1, -1, 0, 0, -1, 0); return 0; } v17 = *(unsigned __int8 **)(v15 + 352); v18 = v17[1] | (*v17 << 8); *(_DWORD *)(v15 + 12) = v18; switch ( v18 ) { case 3: if ( v16 < 5 || _byteswap_ushort(*((_WORD *)v17 + 1)) != (unsigned __int16)(*(_WORD *)(v15 + 64) + 1) ) goto LABEL_26; v12 = sub_100552F3C((__int64)a1, 1, (char *)v17 + 4, v16 - 4); if ( !(_DWORD)v12 ) { v43 = *(int *)(v15 + 332) + *(_QWORD *)(v14 + 152) - 4LL; *(_QWORD *)(v14 + 152) = v43; sub_10054A8B0(v14, v43); goto LABEL_26; } v19 = **(_QWORD **)(v15 + 16); switch ( *(_DWORD *)v15 ) { case 0: goto LABEL_73; case 1: **(_BYTE **)(v15 + 360) = 0; *(_BYTE *)(*(_QWORD *)(v15 + 360) + 1LL) = 5; v46 = *(_WORD *)(v15 + 64); *(_BYTE *)(*(_QWORD *)(v15 + 360) + 2LL) = HIBYTE(v46); *(_BYTE *)(*(_QWORD *)(v15 + 360) + 3LL) = v46; sendto( *(_DWORD *)(v15 + 24), *(const void **)(v15 + 360), 4u, 0, (const sockaddr *)(v15 + 200), *(_DWORD *)(v15 + 328)); LABEL_73: *(_DWORD *)v15 = 3; break; case 2: *(_DWORD *)v15 = 3; **(_BYTE **)(v15 + 360) = 0; *(_BYTE *)(*(_QWORD *)(v15 + 360) + 1LL) = 5; v47 = *(_WORD *)(v15 + 64); *(_BYTE *)(*(_QWORD *)(v15 + 360) + 2LL) = HIBYTE(v47); *(_BYTE *)(*(_QWORD *)(v15 + 360) + 3LL) = v47; sendto( *(_DWORD *)(v15 + 24), *(const void **)(v15 + 360), 4u, 0, (const sockaddr *)(v15 + 200), *(_DWORD *)(v15 + 328)); *(_DWORD *)v15 = 3; break; case 3: sub_1005524A4(v19, "%s\n", "TFTP finished"); break; default: sub_100552734(v19, "%s", "Internal state machine error"); break; } return v12; case 4: goto LABEL_26; case 5: *(_DWORD *)(v15 + 8) = v17[3] | (v17[2] << 8); sub_1005524A4(v14, "%s\n", (const char *)v17 + 4); goto LABEL_26; case 6: v23 = (__int64)&v17[v16]; v50 = v23; v51 = **(_QWORD **)(v15 + 16); *(_DWORD *)(v15 + 340) = 512; v24 = (char *)(v17 + 2); break; default: sub_100552734(v14, "%s", "Internal error: Unexpected packet"); goto LABEL_26; } do { v52 = v15; v25 = v23 - (_QWORD)v24; v26 = memchr(v24, 0, v23 - (_QWORD)v24); if ( v26 ) v27 = v26 - v24; else v27 = v25; v28 = v27 + 1; if ( v25 <= v27 + 1 ) goto LABEL_62; v29 = &v24[v28]; v30 = (char *)memchr(&v24[v28], 0, v25 - (v27 + 1)); v31 = (char *)(v30 - v29); if ( !v30 ) v31 = (char *)(v25 - (v27 + 1)); v32 = (unsigned __int64)&v31[v27 + 2]; if ( v32 > v25 || (v33 = strlen(v24), (v34 = &v24[v32]) == nullptr) ) { LABEL_62: sub_100552734(v51, "Malformed ACK packet, rejecting", v48, v49); return 71; } v35 = &v24[v33 + 1]; sub_1005524A4(v51, "got option=(%s) value=(%s)\n", v24, v35); v36 = strlen(v24); if ( (unsigned int)sub_10057405C(v24, "blksize", v36) ) { v37 = strtol(v35, nullptr, 10); if ( v37 ) { if ( v37 >= 65465 ) { v44 = 65464; v45 = "blksize is larger than max supported"; } else { if ( v37 > 7 ) { v15 = v52; v38 = *(int *)(v52 + 344); if ( v37 <= v38 ) { *(_DWORD *)(v52 + 340) = v37; sub_1005524A4(v51, "%s (%d) %s (%d)\n", "blksize parsed from OACK", v37, "requested", v38); goto LABEL_57; } v48 = "server requested blksize larger than allocated"; v49 = v37; v42 = "%s (%ld)"; goto LABEL_69; } v44 = 8; v45 = "blksize is smaller than min supported"; } v48 = v45; v49 = v44; v42 = "%s (%d)"; } else { v42 = "invalid blocksize value in OACK packet"; } LABEL_69: sub_100552734(v51, v42, v48, v49); return 71; } v39 = strlen(v24); v15 = v52; if ( (unsigned int)sub_10057405C(v24, "tsize", v39) ) { v40 = strtol(v35, nullptr, 10); sub_1005524A4(v51, "%s (%ld)\n", "tsize parsed from OACK", v40); if ( !*(_BYTE *)(v51 + 1313) ) { if ( !v40 ) { v48 = v35; v42 = "invalid tsize -:%s:- value in OACK packet"; goto LABEL_69; } sub_10054A714(v51, v40); } } LABEL_57: v23 = v50; v24 = v34; } while ( (unsigned __int64)v34 < v50 ); LABEL_26: if ( !(unsigned int)sub_10054A1EC(a1) ) goto LABEL_29; v20 = **(_QWORD **)(v15 + 16); switch ( *(_DWORD *)v15 ) { case 0: goto LABEL_37; case 1: **(_BYTE **)(v15 + 360) = 0; *(_BYTE *)(*(_QWORD *)(v15 + 360) + 1LL) = 5; v22 = *(_WORD *)(v15 + 64); *(_BYTE *)(*(_QWORD *)(v15 + 360) + 2LL) = HIBYTE(v22); *(_BYTE *)(*(_QWORD *)(v15 + 360) + 3LL) = v22; sendto( *(_DWORD *)(v15 + 24), *(const void **)(v15 + 360), 4u, 0, (const sockaddr *)(v15 + 200), *(_DWORD *)(v15 + 328)); LABEL_37: *(_DWORD *)v15 = 3; break; case 2: *(_DWORD *)v15 = 3; **(_BYTE **)(v15 + 360) = 0; *(_BYTE *)(*(_QWORD *)(v15 + 360) + 1LL) = 5; v41 = *(_WORD *)(v15 + 64); *(_BYTE *)(*(_QWORD *)(v15 + 360) + 2LL) = HIBYTE(v41); *(_BYTE *)(*(_QWORD *)(v15 + 360) + 3LL) = v41; sendto( *(_DWORD *)(v15 + 24), *(const void **)(v15 + 360), 4u, 0, (const sockaddr *)(v15 + 200), *(_DWORD *)(v15 + 328)); *(_DWORD *)v15 = 3; break; case 3: sub_1005524A4(v20, "%s\n", "TFTP finished"); break; default: sub_100552734(v20, "%s", "Internal state machine error"); break; } return 42; }
GD Web Decomp Icon

GD Web Decomp

Raw Source