//
// DTLSv1_listen from 0x9cb1f8 to 0x9cbb1c (2340 bytes)
//
// 1 xrefs:
// > ??> @ 0x776fc
//
// 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:07:09 +0000
//
int __fastcall DTLSv1_listen(int a1, int a2)
{
int v3; // r0
int rbio; // r6
int wbio; // r0
bool v6; // zf
int v7; // r4
int v8; // r0
int v9; // r0
int v10; // r3
int v11; // r7
_BYTE *v12; // r4
int v13; // r0
int v14; // r11
void (__fastcall *v15)(_DWORD, _DWORD, int, _BYTE *, int, int, _DWORD); // r12
int v16; // r0
unsigned int v18; // r3
unsigned int v19; // r0
unsigned int v20; // r7
bool v21; // zf
int v22; // r0
void (__fastcall *v23)(int, _DWORD, int, _BYTE *, int, int, _DWORD); // r12
unsigned int v24; // r3
unsigned int v25; // r2
unsigned int v26; // r0
bool v27; // cc
unsigned int v28; // r3
unsigned int v29; // r7
_BYTE *v30; // r1
unsigned int v31; // r7
unsigned int v32; // r2
int v33; // r1
int (__fastcall *v34)(int, int); // r3
int v35; // r0
int v36; // r0
int (__fastcall *v37)(int, _BYTE *, unsigned int *); // r3
char *v38; // r0
char v39; // r2
int v40; // r3
__int16 v41; // r11
bool v42; // zf
int v43; // r3
char *v44; // r7
void *v45; // r0
int (__fastcall *v46)(int, _DWORD, int, _BYTE *, int, int, _DWORD); // r12
int v47; // r7
int v48; // r10
int v49; // r3
_WORD *v50; // r3
_WORD *v51; // r0
int v52; // r0
int v53; // r0
int v54; // r4
int v55; // r0
int v57; // [sp+14h] [bp-118h]
unsigned int v58; // [sp+1Ch] [bp-110h] BYREF
_BYTE v59[8]; // [sp+20h] [bp-10Ch] BYREF
_BYTE v60[260]; // [sp+28h] [bp-104h] BYREF
v3 = SSL_clear(a1);
if ( !v3 )
return -1;
ERR_clear_error(v3);
rbio = SSL_get_rbio(a1);
wbio = SSL_get_wbio(a1);
v6 = rbio == 0;
if ( rbio )
v6 = wbio == 0;
v57 = wbio;
v7 = v6;
if ( v6 )
{
ERR_put_error(20, 350, 128, "ssl/d1_lib.c", 454);
return -1;
}
v8 = SSL_get_rbio(a1);
v9 = BIO_ctrl(v8, 50, 1, v7);
if ( (*(_DWORD *)a1 & 0xFF00) != 0xFE00 )
{
ERR_put_error(20, 350, 259, "ssl/d1_lib.c", 473);
return -1;
}
v10 = *(_DWORD *)(a1 + 88);
if ( !v10 )
{
v53 = BUF_MEM_new(v9);
v54 = v53;
if ( !v53 )
{
ERR_put_error(20, 350, 65, "ssl/d1_lib.c", 479);
return -1;
}
if ( !BUF_MEM_grow(v53, 0x4000) )
{
BUF_MEM_free(v54);
ERR_put_error(20, 350, 65, "ssl/d1_lib.c", 485);
return -1;
}
v10 = v54;
*(_DWORD *)(a1 + 88) = v54;
}
v11 = 0;
v12 = *(_BYTE **)(v10 + 4);
while ( 1 )
{
*(_DWORD *)_errno() = 0;
v13 = BIO_read(rbio, v12, 0x4000);
v14 = v13;
if ( v13 <= 0 )
break;
if ( v13 <= 12 )
{
ERR_put_error(20, 350, 298, "ssl/d1_lib.c", 533);
goto LABEL_17;
}
v15 = *(void (__fastcall **)(_DWORD, _DWORD, int, _BYTE *, int, int, _DWORD))(a1 + 112);
if ( v15 )
v15(0, 0, 256, v12, 13, a1, *(_DWORD *)(a1 + 116));
if ( v14 == 1 )
{
ERR_put_error(20, 350, 159, "ssl/d1_lib.c", 544);
goto LABEL_17;
}
if ( *v12 != 22 )
{
ERR_put_error(20, 350, 244, "ssl/d1_lib.c", 549);
goto LABEL_17;
}
if ( (unsigned __int8)v12[1] != 254 )
{
ERR_put_error(20, 350, 116, "ssl/d1_lib.c", 558);
goto LABEL_17;
}
if ( (unsigned int)(v14 - 2) <= 8
|| (memcpy(v59, v12 + 3, sizeof(v59)), (unsigned int)(v14 - 11) <= 1)
|| (v18 = (unsigned __int8)v12[12] | ((unsigned __int8)v12[11] << 8), v18 > v14 - 13) )
{
ERR_put_error(20, 350, 159, "ssl/d1_lib.c", 566);
goto LABEL_17;
}
if ( v59[0] || v59[1] )
{
ERR_put_error(20, 350, 244, "ssl/d1_lib.c", 576);
goto LABEL_17;
}
if ( !v18
|| v18 - 1 <= 2
|| (v19 = ((unsigned __int8)v12[15] << 8) | ((unsigned __int8)v12[14] << 16) | (unsigned __int8)v12[16],
v18 - 4 <= 1)
|| v18 - 6 <= 2
|| v18 - 9 <= 2
|| (v20 = ((unsigned __int8)v12[23] << 8) | ((unsigned __int8)v12[22] << 16) | (unsigned __int8)v12[24],
v20 > v18 - 12)
|| v20 != v18 - 12 )
{
ERR_put_error(20, 350, 159, "ssl/d1_lib.c", 591);
goto LABEL_17;
}
if ( v12[13] != 1 )
{
ERR_put_error(20, 350, 244, "ssl/d1_lib.c", 596);
goto LABEL_17;
}
if ( ((unsigned __int8)v12[18] | ((unsigned __int8)v12[17] << 8)) > 2u )
{
ERR_put_error(20, 350, 402, "ssl/d1_lib.c", 602);
goto LABEL_17;
}
v21 = v19 == v20;
if ( v19 >= v20 )
v21 = (((unsigned __int8)v12[20] << 8) | ((unsigned __int8)v12[19] << 16) | (unsigned __int8)v12[21]) == 0;
v22 = !v21;
if ( !v21 )
{
ERR_put_error(20, 350, 401, "ssl/d1_lib.c", 615);
goto LABEL_17;
}
v23 = *(void (__fastcall **)(int, _DWORD, int, _BYTE *, int, int, _DWORD))(a1 + 112);
if ( v23 )
v23(
v22,
*(_DWORD *)a1,
22,
v12 + 13,
(unsigned __int8)v12[12] | ((unsigned __int8)v12[11] << 8),
a1,
*(_DWORD *)(a1 + 116));
if ( v20 <= 1 )
{
ERR_put_error(20, 350, 159, "ssl/d1_lib.c", 625);
goto LABEL_17;
}
v24 = (unsigned __int8)v12[26] | ((unsigned __int8)v12[25] << 8);
if ( v24 == 256 )
{
v25 = **(_DWORD **)(a1 + 4);
if ( v25 == 256 )
goto LABEL_56;
v24 = 65280;
}
else
{
v25 = **(_DWORD **)(a1 + 4);
if ( v25 == 256 )
{
v26 = 65280;
goto LABEL_53;
}
}
v26 = v25;
LABEL_53:
v27 = v25 > 0x1FFFF;
if ( v25 != 0x1FFFF )
v27 = v24 > v26;
if ( v27 )
{
ERR_put_error(20, 350, 267, "ssl/d1_lib.c", 634);
goto LABEL_17;
}
LABEL_56:
if ( v20 - 2 <= 0x20
|| (v28 = (unsigned __int8)v12[59], v29 = v20 - 35, v30 = v12 + 60, v28 > v29)
|| (v31 = v29 - v28) == 0
|| (v32 = (unsigned __int8)v30[v28], v33 = (int)&v30[v28 + 1], v32 > v31 - 1) )
{
ERR_put_error(20, 350, 159, "ssl/d1_lib.c", 645);
goto LABEL_17;
}
if ( v32 )
{
v34 = *(int (__fastcall **)(int, int))(*(_DWORD *)(a1 + 276) + 124);
if ( !v34 )
{
ERR_put_error(20, 350, 403, "ssl/d1_lib.c", 660);
return -1;
}
if ( v34(a1, v33) )
{
v50 = *(_WORD **)(a1 + 108);
v51 = v50 + 134;
v50 += 132;
*v51 = 1;
*v50 = 1;
v50[1] = 1;
DTLS_RECORD_LAYER_set_write_sequence(a1 + 556, v59);
SSL_set_options(a1, 0x2000);
ossl_statem_set_hello_verify_done((_DWORD *)a1);
if ( BIO_ctrl(rbio, 46, 0, a2) <= 0 )
BIO_ADDR_clear(a2);
BIO_ADDR_free(0);
v52 = SSL_get_rbio(a1);
BIO_ctrl(v52, 50, 0, 0);
return 1;
}
}
v35 = SSL_get_rbio(a1);
BIO_ctrl(v35, 50, 0, 0);
BIO_read(rbio, v12, 0x4000);
v36 = SSL_get_rbio(a1);
BIO_ctrl(v36, 50, 1, 0);
v37 = *(int (__fastcall **)(int, _BYTE *, unsigned int *))(*(_DWORD *)(a1 + 276) + 120);
if ( !v37 || !v37(a1, v60, &v58) || v58 > 0xFF )
{
ERR_put_error(20, 350, 400, "ssl/d1_lib.c", 697);
return -1;
}
v38 = dtls_raw_hello_verify_request(v12 + 25, v60, (unsigned __int8)v58);
v12[17] = 0;
v12[18] = 0;
v12[19] = 0;
v12[20] = 0;
v12[21] = 0;
v12[14] = BYTE2(v38);
v12[22] = BYTE2(v38);
v12[15] = BYTE1(v38);
v12[23] = BYTE1(v38);
v12[16] = (_BYTE)v38;
v12[24] = (_BYTE)v38;
v12[13] = 3;
*v12 = 22;
v39 = -1;
v40 = **(_DWORD **)(a1 + 4);
v41 = (_WORD)v38 + 12;
v42 = v40 == 0x1FFFF;
if ( v40 == 0x1FFFF )
v39 = -2;
else
v40 = *(_DWORD *)a1;
if ( v42 )
LOBYTE(v43) = -1;
else
v43 = v40 >> 8;
if ( v42 )
{
v12[1] = v39;
}
else
{
v12[1] = v43;
v43 = *(_DWORD *)a1;
}
v44 = v38;
v12[2] = v43;
v45 = memcpy(v12 + 3, v59, 8u);
v12[12] = v41;
v12[11] = HIBYTE(v41);
v46 = *(int (__fastcall **)(int, _DWORD, int, _BYTE *, int, int, _DWORD))(a1 + 112);
v47 = (int)(v44 + 25);
if ( v46 )
v45 = (void *)v46(1, 0, 256, v12, 13, a1, *(_DWORD *)(a1 + 116));
v48 = BIO_ADDR_new(v45);
if ( !v48 )
{
ERR_put_error(20, 350, 65, "ssl/d1_lib.c", 762);
LABEL_17:
BIO_ADDR_free(0);
v16 = SSL_get_rbio(a1);
BIO_ctrl(v16, 50, 0, 0);
LABEL_18:
BIO_read(rbio, v12, 0x4000);
return 0;
}
if ( BIO_ctrl(rbio, 46, 0, v48) > 0 )
BIO_ctrl(v57, 44, 0, v48);
BIO_ADDR_free(v48);
if ( v47 <= BIO_write(v57, v12, v47, v49) )
{
v11 = 1;
if ( BIO_ctrl(v57, 11, 0, 0) > 0 )
continue;
}
if ( BIO_test_flags(v57, 8) )
goto LABEL_17;
return -1;
}
if ( BIO_test_flags(rbio, 8) )
{
BIO_ADDR_free(0);
v55 = SSL_get_rbio(a1);
BIO_ctrl(v55, 50, 0, 0);
if ( v11 )
goto LABEL_18;
return 0;
}
return -1;
}