//
// cms_EnvelopedData_init_bio from 0xe1e6b4 to 0xe1e90c (600 bytes)
//
// 2 xrefs:
// > CMS_dataInit @ 0xe1fa68
// > ??> @ 0x79830
//
// 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
//
_QWORD *__fastcall cms_EnvelopedData_init_bio(__int64 a1)
{
__int64 v2; // x22
_QWORD *inited; // x23
int v4; // w19
unsigned int *v5; // x20
__int64 v6; // x0
bool v7; // cc
int v8; // w1
__int64 v9; // x21
__int64 v10; // x0
_BYTE *v11; // x0
unsigned __int64 v12; // x1
unsigned int **v14; // x20
int v15; // w19
int v16; // w1
int v17; // w0
int v18; // w19
int v19; // w1
int v20; // w19
int v21; // w1
__int64 v22; // x0
v2 = *(_QWORD *)(*(_QWORD *)(a1 + 8) + 24LL);
inited = (_QWORD *)cms_EncryptedContent_init_bio(v2);
if ( inited && *(_QWORD *)(v2 + 24) )
{
v4 = 0;
v5 = *(unsigned int **)(*(_QWORD *)(a1 + 8) + 16LL);
while ( 1 )
{
v7 = v4 < (int)OPENSSL_sk_num(v5);
v8 = v4++;
if ( !v7 )
break;
v6 = OPENSSL_sk_value((__int64)v5, v8);
if ( (int)CMS_RecipientInfo_encrypt(a1, v6) <= 0 )
{
ERR_put_error(46, 125, 116, (__int64)"crypto/cms/cms_env.c", 868);
*(_QWORD *)(v2 + 24) = 0;
CRYPTO_clear_free(*(_BYTE **)(v2 + 32), *(_QWORD *)(v2 + 40), (__int64)"crypto/cms/cms_env.c", 0x36Eu);
*(_QWORD *)(v2 + 32) = 0;
*(_QWORD *)(v2 + 40) = 0;
BIO_free(inited);
return nullptr;
}
}
v9 = *(_QWORD *)(a1 + 8);
v10 = *(_QWORD *)v9;
if ( *(__int64 *)v9 <= 3 )
{
v14 = *(unsigned int ***)(v9 + 8);
if ( v14 )
{
v15 = 0;
while ( 1 )
{
v7 = v15 < (int)OPENSSL_sk_num(*v14);
v16 = v15++;
if ( !v7 )
break;
v17 = *(_DWORD *)OPENSSL_sk_value((__int64)*v14, v16);
if ( v17 == 4 )
{
LABEL_18:
*(_QWORD *)v9 = 4;
goto LABEL_7;
}
if ( v17 == 3 && *(__int64 *)v9 <= 2 )
*(_QWORD *)v9 = 3;
}
v18 = 0;
while ( 1 )
{
v7 = v18 < (int)OPENSSL_sk_num(v14[1]);
v19 = v18++;
if ( !v7 )
break;
if ( *(_DWORD *)OPENSSL_sk_value((__int64)v14[1], v19) == 1 )
goto LABEL_18;
}
v10 = *(_QWORD *)v9;
}
if ( v10 <= 2 )
{
v20 = 0;
while ( 1 )
{
v7 = v20 < (int)OPENSSL_sk_num(*(unsigned int **)(v9 + 16));
v21 = v20++;
if ( !v7 )
break;
v22 = OPENSSL_sk_value(*(_QWORD *)(v9 + 16), v21);
if ( (unsigned int)(*(_DWORD *)v22 - 3) <= 1 )
{
*(_QWORD *)v9 = 3;
goto LABEL_7;
}
if ( *(_DWORD *)v22 || **(_QWORD **)(v22 + 8) )
*(_QWORD *)v9 = 2;
}
if ( *(_QWORD *)(v9 + 8) || *(_QWORD *)(v9 + 32) )
{
*(_QWORD *)v9 = 2;
}
else if ( *(_QWORD *)v9 != 2 )
{
*(_QWORD *)v9 = 0;
}
}
}
LABEL_7:
v11 = *(_BYTE **)(v2 + 32);
v12 = *(_QWORD *)(v2 + 40);
*(_QWORD *)(v2 + 24) = 0;
CRYPTO_clear_free(v11, v12, (__int64)"crypto/cms/cms_env.c", 0x36Eu);
*(_QWORD *)(v2 + 32) = 0;
*(_QWORD *)(v2 + 40) = 0;
}
return inited;
}