//
// policy_cache_set from 0x84b528 to 0x84b850 (808 bytes)
//
// 5 xrefs:
// > X509_policy_check @ 0x84bd20
// > X509_policy_check @ 0x84bd6c
// > X509_policy_check @ 0x84be6c
// > X509_policy_check @ 0x84c72c
// > ??> @ 0x6853c
//
// 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 policy_cache_set(int a1)
{
_DWORD *v3; // r0
_DWORD *v4; // r5
_DWORD *ext_d2i; // r0
_DWORD *v6; // r6
int v7; // r0
int v8; // r0
int v9; // r3
int v10; // r0
_DWORD *v11; // r9
int v12; // r10
int v13; // r0
int v14; // r7
_DWORD *v15; // r0
signed int i; // r8
int v17; // r0
int v18; // r0
int v19; // r0
int v20; // r0
int *v21; // [sp+0h] [bp-14h]
int v22; // [sp+Ch] [bp-8h]
int v23; // [sp+Ch] [bp-8h]
if ( *(_DWORD *)(a1 + 136) )
return *(_DWORD *)(a1 + 136);
CRYPTO_THREAD_write_lock(*(pthread_rwlock_t **)(a1 + 184));
if ( *(_DWORD *)(a1 + 136) )
goto LABEL_4;
v3 = CRYPTO_malloc(&dword_14, (int)"crypto/x509v3/pcy_cache.c", 84);
v4 = v3;
if ( !v3 )
goto LABEL_4;
*v3 = 0;
v3[1] = 0;
v3[2] = -1;
v3[3] = -1;
v3[4] = -1;
*(_DWORD *)(a1 + 136) = v3;
ext_d2i = (_DWORD *)X509_get_ext_d2i(a1);
v6 = ext_d2i;
if ( !ext_d2i )
{
if ( v22 != -1 )
goto LABEL_18;
goto LABEL_12;
}
v7 = *ext_d2i;
if ( !*v6 )
{
v9 = v6[1];
if ( !v9 )
goto LABEL_18;
goto LABEL_10;
}
if ( *(_DWORD *)(v7 + 4) == 258 )
goto LABEL_18;
v8 = ASN1_INTEGER_get(v7);
v9 = v6[1];
v4[3] = v8;
if ( v9 )
{
LABEL_10:
if ( *(_DWORD *)(v9 + 4) == 258 )
goto LABEL_18;
v4[4] = ASN1_INTEGER_get(v9);
}
LABEL_12:
v10 = X509_get_ext_d2i(a1);
v11 = (_DWORD *)v10;
if ( v10 )
{
v21 = *(int **)(a1 + 136);
if ( !OPENSSL_sk_num(v10) || (v15 = OPENSSL_sk_new((int)sub_84B4CC), (v21[1] = (int)v15) == 0) )
{
LABEL_14:
v12 = 0;
LABEL_15:
v13 = v12;
LABEL_16:
policy_data_free(v13);
OPENSSL_sk_pop_free((int)v11, (void (__fastcall *)(int))POLICYINFO_free);
OPENSSL_sk_pop_free(v21[1], (void (__fastcall *)(int))policy_data_free);
v21[1] = 0;
goto LABEL_4;
}
for ( i = 0; i < OPENSSL_sk_num((int)v11); ++i )
{
v17 = OPENSSL_sk_value(v11, i);
v18 = ((int (__fastcall *)(int, _DWORD))policy_data_new)(v17, 0);
v12 = v18;
if ( !v18 )
goto LABEL_14;
if ( OBJ_obj2nid(*(_DWORD *)(v18 + 4)) == (char *)&stru_2DC.st_shndx )
{
if ( *v21 )
goto LABEL_43;
*v21 = v12;
}
else
{
if ( OPENSSL_sk_find(v21[1], v12) != -1 )
{
LABEL_43:
v13 = v12;
*(_DWORD *)(a1 + 112) |= 0x800u;
goto LABEL_16;
}
if ( !OPENSSL_sk_push((int *)v21[1], v12) )
goto LABEL_15;
}
}
policy_data_free(0);
OPENSSL_sk_pop_free((int)v11, (void (__fastcall *)(int))POLICYINFO_free);
v19 = X509_get_ext_d2i(a1);
if ( v19 )
{
v23 = policy_cache_set_mapping(a1, v19);
if ( v23 > 0 )
{
v20 = X509_get_ext_d2i(a1);
v14 = v20;
if ( v20 )
{
if ( *(_DWORD *)(v20 + 4) == 258 )
goto LABEL_19;
v4[2] = ASN1_INTEGER_get(v20);
LABEL_20:
POLICY_CONSTRAINTS_free(v6);
ASN1_INTEGER_free(v14);
goto LABEL_4;
}
}
}
LABEL_18:
v14 = 0;
LABEL_19:
*(_DWORD *)(a1 + 112) |= 0x800u;
goto LABEL_20;
}
if ( v22 != -1 )
goto LABEL_18;
LABEL_4:
CRYPTO_THREAD_unlock(*(pthread_rwlock_t **)(a1 + 184));
return *(_DWORD *)(a1 + 136);
}