//
// SMIME_read_ASN1 from 0x8c57bc to 0x8c5d90 (1492 bytes)
//
// 2 xrefs:
// > SMIME_read_CMS @ 0x87449c
// > ??> @ 0x6a31c
//
// 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 SMIME_read_ASN1(_DWORD *a1, int *a2, int a3)
{
int *v6; // r0
int *v7; // r6
signed int v8; // r1
int v9; // r0
int v10; // r7
const char *v11; // r8
int v12; // r0
_DWORD *v13; // r0
_DWORD *v14; // r6
_DWORD *v15; // r5
int v16; // r4
signed int v18; // r1
int v19; // r0
char *v20; // r1
int v21; // r4
_DWORD *v22; // r5
int *v23; // r0
int *v24; // r6
int v25; // r4
signed int v26; // r1
int v27; // r0
int v28; // r11
const char *v29; // r7
int v30; // r0
_DWORD *v31; // r0
_DWORD *v32; // r7
_DWORD *v33; // r6
void **v34; // [sp+10h] [bp-14h] BYREF
const char *v35; // [sp+14h] [bp-10h] BYREF
int v36; // [sp+18h] [bp-Ch]
int v37; // [sp+1Ch] [bp-8h]
if ( a2 )
*a2 = 0;
v34 = nullptr;
v6 = sub_8C4EEC(a1);
v7 = v6;
if ( !v6 )
{
ERR_put_error(13, 212, 207, (int)"crypto/asn1/asn_mime.c", 384);
return 0;
}
v35 = "content-type";
v36 = 0;
v37 = 0;
v8 = OPENSSL_sk_find((int)v6, (int)&v35);
if ( v8 < 0 || (v9 = OPENSSL_sk_value(v7, v8), (v10 = v9) == 0) || (v11 = *(const char **)(v9 + 4)) == nullptr )
{
OPENSSL_sk_pop_free((int)v7, sub_8C492C);
ERR_put_error(13, 212, 209, (int)"crypto/asn1/asn_mime.c", 391);
return 0;
}
if ( !strcmp(*(const char **)(v9 + 4), "multipart/signed") )
{
v36 = 0;
v35 = "boundary";
v18 = OPENSSL_sk_find(*(_DWORD *)(v10 + 8), (int)&v35);
if ( v18 < 0 || (v19 = OPENSSL_sk_value(*(_DWORD **)(v10 + 8), v18)) == 0 || (v20 = *(char **)(v19 + 4)) == nullptr )
{
OPENSSL_sk_pop_free((int)v7, sub_8C492C);
ERR_put_error(13, 212, 211, (int)"crypto/asn1/asn_mime.c", 402);
return 0;
}
v21 = sub_8C4CA8(a1, v20, (int **)&v34);
OPENSSL_sk_pop_free((int)v7, sub_8C492C);
if ( v21 && OPENSSL_sk_num((int)v34) == 2 )
{
v22 = (_DWORD *)OPENSSL_sk_value(v34, 1u);
v23 = sub_8C4EEC(v22);
v24 = v23;
if ( v23 )
{
v25 = 0;
v35 = "content-type";
v36 = 0;
v37 = 0;
v26 = OPENSSL_sk_find((int)v23, (int)&v35);
if ( v26 < 0
|| (v27 = OPENSSL_sk_value(v24, v26), (v28 = v27) == 0)
|| (v29 = *(const char **)(v27 + 4)) == nullptr )
{
OPENSSL_sk_pop_free((int)v24, sub_8C492C);
ERR_put_error(13, 212, 212, (int)"crypto/asn1/asn_mime.c", 427);
return 0;
}
if ( strcmp(*(const char **)(v27 + 4), "application/x-pkcs7-signature")
&& strcmp(v29, "application/pkcs7-signature") )
{
ERR_put_error(13, 212, 213, (int)"crypto/asn1/asn_mime.c", 433);
ERR_add_error_data(2, "type: ", *(_DWORD *)(v28 + 4));
OPENSSL_sk_pop_free((int)v24, sub_8C492C);
LABEL_35:
OPENSSL_sk_pop_free((int)v34, (void (__fastcall *)(int))BIO_vfree);
return v25;
}
OPENSSL_sk_pop_free((int)v24, sub_8C492C);
v30 = BIO_f_base64();
v31 = BIO_new(v30);
v32 = v31;
if ( v31 )
{
v33 = BIO_push(v31, (int)v22);
v25 = ASN1_item_d2i_bio(a3, (int)v33, nullptr);
if ( v25 )
{
BIO_ctrl(v33, 11, 0, 0);
BIO_pop(v33);
BIO_free(v32);
if ( a2 )
{
*a2 = OPENSSL_sk_value(v34, 0);
BIO_free(v22);
OPENSSL_sk_free(v34);
return v25;
}
goto LABEL_35;
}
ERR_put_error(13, 209, 110, (int)"crypto/asn1/asn_mime.c", 143);
BIO_ctrl(v33, 11, 0, 0);
BIO_pop(v33);
BIO_free(v32);
}
else
{
ERR_put_error(13, 209, 65, (int)"crypto/asn1/asn_mime.c", 137);
}
ERR_put_error(13, 212, 204, (int)"crypto/asn1/asn_mime.c", 442);
}
else
{
ERR_put_error(13, 212, 208, (int)"crypto/asn1/asn_mime.c", 417);
}
}
else
{
ERR_put_error(13, 212, 210, (int)"crypto/asn1/asn_mime.c", 408);
}
OPENSSL_sk_pop_free((int)v34, (void (__fastcall *)(int))BIO_vfree);
return 0;
}
if ( !strcmp(v11, "application/x-pkcs7-mime") || !strcmp(v11, "application/pkcs7-mime") )
{
OPENSSL_sk_pop_free((int)v7, sub_8C492C);
v12 = BIO_f_base64();
v13 = BIO_new(v12);
v14 = v13;
if ( v13 )
{
v15 = BIO_push(v13, (int)a1);
v16 = ASN1_item_d2i_bio(a3, (int)v15, nullptr);
if ( v16 )
{
BIO_ctrl(v15, 11, 0, 0);
BIO_pop(v15);
BIO_free(v14);
return v16;
}
ERR_put_error(13, 209, 110, (int)"crypto/asn1/asn_mime.c", 143);
BIO_ctrl(v15, 11, 0, 0);
BIO_pop(v15);
BIO_free(v14);
}
else
{
ERR_put_error(13, 209, 65, (int)"crypto/asn1/asn_mime.c", 137);
}
ERR_put_error(13, 212, 203, (int)"crypto/asn1/asn_mime.c", 469);
return 0;
}
else
{
ERR_put_error(13, 212, 205, (int)"crypto/asn1/asn_mime.c", 460);
ERR_add_error_data(2, "type: ", *(_DWORD *)(v10 + 4));
OPENSSL_sk_pop_free((int)v7, sub_8C492C);
return 0;
}
}