//
// sub_85C3A0 from 0x85c3a0 to 0x85c704 (868 bytes)
//
// 4 xrefs:
// > X509_check_host @ 0x85dfa4
// > X509_check_email @ 0x85e06c
// > X509_check_ip @ 0x85e0e8
// > X509_check_ip_asc @ 0x85e2f4
//
// 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 sub_85C3A0(int a1, char *a2, unsigned int a3, __int16 a4, int a5, unsigned __int8 **a6)
{
unsigned int v7; // r8
int v8; // r9
unsigned int v9; // r10
_DWORD *ext_d2i; // r5
int v11; // r7
signed int i; // r4
_DWORD *v13; // r0
unsigned int *v14; // r7
_BYTE *v15; // r3
unsigned int v16; // r1
int v17; // r1
unsigned __int8 *v18; // r0
int v19; // r12
unsigned __int8 *v20; // r0
int index_by_NID; // r5
int *subject_name; // r6
int entry; // r0
int *data; // r12
int v26; // r0
int v27; // r11
int v28; // r0
bool v29; // cc
int v30; // r4
int v31; // r0
bool v32; // cc
int v33; // r12
__int16 v34; // [sp+8h] [bp-1Ch]
int v35; // [sp+8h] [bp-1Ch]
int v36; // [sp+8h] [bp-1Ch]
int (__fastcall *v38)(int, size_t, void *); // [sp+10h] [bp-14h]
unsigned __int8 *v39; // [sp+14h] [bp-10h]
unsigned __int8 *v40; // [sp+1Ch] [bp-8h] BYREF
v7 = a3;
v34 = a4 & 0x7FFF;
if ( a5 == 1 )
{
v8 = 22;
v38 = sub_85C728;
v9 = 48;
}
else if ( a5 == 2 )
{
if ( a3 > 1 && *a2 == 46 )
v34 |= 0x8000u;
v8 = 22;
if ( (v34 & 2) != 0 )
v38 = (int (__fastcall *)(int, size_t, void *))sub_85BFE0;
else
v38 = (int (__fastcall *)(int, size_t, void *))sub_85C874;
v9 = 13;
}
else
{
v8 = 4;
v9 = 0;
v38 = (int (__fastcall *)(int, size_t, void *))sub_85C2E8;
}
if ( !a3 )
v7 = strlen(a2);
ext_d2i = (_DWORD *)X509_get_ext_d2i(a1);
if ( !ext_d2i )
goto LABEL_27;
v11 = 0;
for ( i = 0; i < OPENSSL_sk_num((int)ext_d2i); ++i )
{
v13 = (_DWORD *)OPENSSL_sk_value(ext_d2i, i);
if ( *v13 == a5 )
{
v14 = (unsigned int *)v13[1];
v15 = (_BYTE *)v14[2];
if ( v15 )
{
v16 = *v14;
if ( *v14 )
{
if ( v8 == v14[1] )
{
if ( v8 == 22 )
{
v31 = ((int (__fastcall *)(_BYTE *, unsigned int, unsigned __int8 *, unsigned int, __int16))v38)(
v15,
v16,
(unsigned __int8 *)a2,
v7,
v34);
v32 = (int)a6 <= 0;
if ( a6 )
v32 = v31 <= 0;
if ( !v32 )
{
v19 = v31;
v17 = *v14;
v18 = (unsigned __int8 *)v14[2];
LABEL_22:
v35 = v19;
v20 = CRYPTO_strndup(v18, v17, (int)"crypto/x509v3/v3_utl.c", 753);
v33 = v35;
*a6 = v20;
goto LABEL_23;
}
if ( v31 )
{
v33 = v31;
goto LABEL_23;
}
}
else if ( v16 == v7 )
{
v39 = (unsigned __int8 *)v14[2];
if ( !memcmp(v39, a2, v7) )
{
if ( a6 )
{
v17 = v7;
v18 = v39;
v19 = 1;
goto LABEL_22;
}
v33 = 1;
LABEL_23:
v36 = v33;
GENERAL_NAMES_free(ext_d2i);
return v36;
}
}
}
}
}
v11 = 1;
}
}
GENERAL_NAMES_free(ext_d2i);
if ( !v11 || (v34 & 1) != 0 )
{
LABEL_27:
if ( v9 && (v34 & 0x20) == 0 )
{
index_by_NID = -1;
subject_name = (int *)X509_get_subject_name(a1);
while ( 1 )
{
do
{
index_by_NID = X509_NAME_get_index_by_NID(subject_name, v9, index_by_NID);
if ( index_by_NID < 0 )
return 0;
entry = X509_NAME_get_entry(subject_name, index_by_NID);
data = (int *)X509_NAME_ENTRY_get_data(entry);
}
while ( !data[2] || !*data );
v26 = ASN1_STRING_to_UTF8(&v40, data);
v27 = v26;
if ( v26 < 0 )
break;
v28 = ((int (__fastcall *)(_BYTE *, unsigned int, unsigned __int8 *, unsigned int, __int16))v38)(
v40,
v26,
(unsigned __int8 *)a2,
v7,
v34);
v29 = (int)a6 <= 0;
if ( a6 )
v29 = v28 <= 0;
v30 = v28;
if ( !v29 )
{
*a6 = CRYPTO_strndup(v40, v27, (int)"crypto/x509v3/v3_utl.c", 767);
CRYPTO_free(v40, (int)"crypto/x509v3/v3_utl.c", 768);
return v30;
}
CRYPTO_free(v40, (int)"crypto/x509v3/v3_utl.c", 768);
if ( v30 )
return v30;
}
return -1;
}
}
return 0;
}