//
// ssl_get_new_session from 0xd46360 to 0xd4665c (764 bytes)
//
// 7 xrefs:
// > tls_construct_client_hello @ 0xd48d4c
// > tls_construct_client_hello @ 0xd48e5c
// > tls_process_server_hello @ 0xd49444
// > tls_process_client_hello @ 0xd50aa8
// > tls_process_client_hello @ 0xd50cbc
// > tls_process_client_hello @ 0xd50e60
// > ??> @ 0x906a8
//
// 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 ssl_get_new_session(__int64 a1, int a2)
{
__int64 v4; // x20
__int64 v5; // x0
unsigned int v6; // w2
unsigned int v7; // w21
__int64 *v8; // x0
__int64 v9; // x0
int v11; // w0
__int64 v12; // x0
__int64 v13; // x0
__int64 v14; // x2
__int64 v15; // x4
__int64 (__fastcall *v16)(__int64, const void *, unsigned int *); // x22
__int64 v17; // x0
unsigned int v18; // w24
unsigned int v19; // w2
unsigned int v20; // [xsp+4Ch] [xbp+4Ch] BYREF
v4 = SSL_SESSION_new();
if ( v4 )
{
v5 = *(_QWORD *)(*(_QWORD *)(a1 + 720) + 72LL);
if ( v5 )
*(_QWORD *)(v4 + 192) = v5;
else
*(_QWORD *)(v4 + 192) = SSL_get_default_timeout(a1);
SSL_SESSION_free(*(_QWORD *)(a1 + 376));
*(_QWORD *)(a1 + 376) = 0;
if ( !a2 )
{
*(_DWORD *)(v4 + 56) = 0;
LABEL_6:
v6 = *(_DWORD *)(a1 + 336);
if ( v6 <= 0x20 )
{
v7 = 1;
memcpy((void *)(v4 + 96), (const void *)(a1 + 340), v6);
v8 = *(__int64 **)(a1 + 144);
*(_DWORD *)(v4 + 92) = *(_DWORD *)(a1 + 336);
*(_QWORD *)(a1 + 376) = v4;
v9 = *v8;
*(_DWORD *)v4 = *(_DWORD *)a1;
*(_QWORD *)(v4 + 176) = 0;
if ( (v9 & 0x200) != 0 )
*(_DWORD *)(v4 + 336) |= 1u;
return v7;
}
v14 = 68;
v15 = 411;
goto LABEL_23;
}
v11 = *(_DWORD *)a1;
if ( *(_DWORD *)a1 != 768 && v11 != 769 && v11 != 770 && v11 != 771 && v11 != 256 && v11 != 65279 && v11 != 65277 )
{
v14 = 259;
v15 = 333;
LABEL_23:
ERR_put_error(20, 181, v14, "ssl/ssl_sess.c", v15);
SSL_SESSION_free(v4);
return 0;
}
v7 = *(_DWORD *)(a1 + 644);
*(_DWORD *)v4 = v11;
*(_DWORD *)(v4 + 56) = 32;
if ( v7 )
{
*(_DWORD *)(v4 + 56) = 0;
}
else
{
CRYPTO_THREAD_read_lock(*(_QWORD *)(a1 + 4432));
CRYPTO_THREAD_read_lock(*(_QWORD *)(*(_QWORD *)(a1 + 720) + 864LL));
v16 = *(__int64 (__fastcall **)(__int64, const void *, unsigned int *))(a1 + 384);
v17 = *(_QWORD *)(a1 + 720);
if ( !v16 )
{
v16 = *(__int64 (__fastcall **)(__int64, const void *, unsigned int *))(v17 + 368);
if ( !v16 )
v16 = sub_D45E84;
}
CRYPTO_THREAD_unlock(*(_QWORD *)(v17 + 864));
CRYPTO_THREAD_unlock(*(_QWORD *)(a1 + 4432));
v18 = *(_DWORD *)(v4 + 56);
memset((void *)(v4 + 60), 0, v18);
v20 = v18;
if ( !(unsigned int)v16(a1, (const void *)(v4 + 60), &v20) )
{
v7 = 0;
ERR_put_error(20, 181, 301, "ssl/ssl_sess.c", 373);
SSL_SESSION_free(v4);
return v7;
}
v19 = v20;
if ( !v20 || v20 > *(_DWORD *)(v4 + 56) )
{
ERR_put_error(20, 181, 303, "ssl/ssl_sess.c", 384);
SSL_SESSION_free(v4);
return v7;
}
*(_DWORD *)(v4 + 56) = v20;
if ( SSL_has_matching_session_id(a1, (const void *)(v4 + 60), v19) )
{
ERR_put_error(20, 181, 302, "ssl/ssl_sess.c", 392);
SSL_SESSION_free(v4);
return v7;
}
}
v12 = *(_QWORD *)(a1 + 552);
if ( !v12 )
goto LABEL_6;
v13 = CRYPTO_strdup(v12, "ssl/ssl_sess.c", 399);
*(_QWORD *)(v4 + 264) = v13;
v7 = v13;
if ( v13 )
goto LABEL_6;
ERR_put_error(20, 181, 68, "ssl/ssl_sess.c", 401);
SSL_SESSION_free(v4);
return v7;
}
return 0;
}