//
// dtls1_get_record from 0x78cc48 to 0x78ceb0 (616 bytes)
//
// 2 xrefs:
// > dtls1_read_bytes @ 0x787134
// > ??> @ 0x5a5dc
//
// 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
//
int __fastcall dtls1_get_record(int *a1)
{
int v2; // r9
void *v3; // r5
unsigned int v4; // r3
unsigned int v5; // r6
int result; // r0
void (__fastcall *v7)(_DWORD, _DWORD, int, unsigned __int8 *, int, int *, int); // r11
unsigned __int8 *v8; // r6
int v9; // lr
int v10; // r11
int v11; // r11
bool v12; // zf
int v13; // r3
unsigned __int16 *bitmap; // r11
int v15; // [sp+14h] [bp-8h]
int v16; // [sp+1Ch] [bp+0h] BYREF
v2 = (int)(a1 + 309);
v3 = (char *)a1 + 2822;
v15 = (int)(a1 + 319);
while ( dtls1_process_buffered_records(a1) )
{
if ( dtls1_retrieve_buffered_record(a1, a1[711] + 36) )
return 1;
if ( a1[141] == 241 && (v4 = a1[694], v4 > 0xC) )
{
v5 = a1[311];
if ( v4 - 13 < v5 )
goto LABEL_7;
}
else
{
result = ssl3_read_n(a1, 13, a1[146], 0, 1);
if ( result <= 0 )
return result;
if ( a1[694] != 13 )
{
a1[694] = 0;
continue;
}
v7 = (void (__fastcall *)(_DWORD, _DWORD, int, unsigned __int8 *, int, int *, int))a1[28];
a1[141] = 241;
v8 = (unsigned __int8 *)a1[693];
if ( v7 )
v7(0, 0, 256, v8, 13, a1, a1[29]);
a1[310] = *v8;
v9 = v8[1];
v10 = v8[2];
a1[318] = v8[4] | (v8[3] << 8);
v11 = v10 | (v9 << 8);
memcpy(v3, v8 + 5, 6u);
v5 = v8[12] | (v8[11] << 8);
v12 = a1[80] == 0;
a1[311] = v5;
v13 = *a1;
if ( v12 )
{
if ( v11 != v13 )
goto LABEL_8;
}
else if ( (((unsigned __int16)v11 ^ (unsigned __int16)v13) & 0xFF00) != 0 )
{
goto LABEL_8;
}
if ( v5 > 0x4540 )
goto LABEL_8;
if ( a1[694] - 13 < v5 )
{
LABEL_7:
if ( ssl3_read_n(a1, v5, v5, 1, 1) != v5 )
goto LABEL_8;
}
}
a1[141] = 240;
bitmap = dtls1_get_bitmap((int)a1, v2, &v16);
if ( bitmap && dtls1_record_replay_check(a1, bitmap) )
{
if ( !a1[311] )
continue;
if ( v16 )
{
if ( (SSL_in_init(a1) || ossl_statem_get_in_handshake(a1)) && dtls1_buffer_record(a1, a1[711] + 28, v15) < 0 )
return -1;
}
else if ( dtls1_process_record(a1, (int)bitmap) )
{
return 1;
}
}
LABEL_8:
a1[311] = 0;
a1[694] = 0;
}
return -1;
}