//
// sub_D6AECC from 0xd6aecc to 0xd6b808 (2364 bytes)
//
// 6 xrefs:
// > sub_D6B828 @ 0xd6c300
// > sub_D6B828 @ 0xd6c32c
// > sub_D6C730 @ 0xd6ced8
// > sub_D6C730 @ 0xd6cf24
// > ASN1_item_ex_d2i @ 0xd6d774
// > ASN1_item_ex_d2i @ 0xd6d7c4
//
// 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 sub_D6AECC(
__int64 *a1,
char **a2,
__int64 a3,
__int64 a4,
int a5,
int a6,
unsigned __int8 a7,
__int64 a8)
{
__int64 *v8; // x20
int v12; // w22
int v14; // w27
char *v16; // x21
int v17; // w7
char *v18; // x1
int v19; // w3
int object; // w0
char v22; // w25
signed __int64 v23; // x7
int v24; // w1
__int64 v25; // x21
char *v26; // x22
unsigned int v27; // w3
int v28; // w1
int v29; // w2
char *v30; // x19
__int64 v31; // x0
int v32; // w22
__int64 (__fastcall *v33)(__int64 *, char *); // x6
int v34; // w0
__int64 v35; // x19
__int64 *v36; // x21
__int64 v37; // x23
char *v38; // x0
__int64 v39; // x0
int v40; // w25
char v41; // w0
int v42; // w1
signed __int64 v43; // x0
char *v44; // x4
signed __int64 v45; // x0
int v46; // w0
__int64 v47; // x0
__int64 v48; // x0
unsigned int v49; // [xsp+88h] [xbp+78h]
unsigned int v50; // [xsp+88h] [xbp+78h]
__int64 v51; // [xsp+88h] [xbp+78h]
unsigned int v52; // [xsp+88h] [xbp+78h]
unsigned int v53; // [xsp+88h] [xbp+78h]
unsigned int v54; // [xsp+88h] [xbp+78h]
unsigned __int8 v55; // [xsp+9Bh] [xbp+8Bh]
int v56; // [xsp+9Ch] [xbp+8Ch] BYREF
int v57; // [xsp+A0h] [xbp+90h] BYREF
int v58; // [xsp+A4h] [xbp+94h] BYREF
char *v59; // [xsp+A8h] [xbp+98h] BYREF
signed __int64 v60; // [xsp+B0h] [xbp+A0h] BYREF
char *v61; // [xsp+B8h] [xbp+A8h] BYREF
__int64 v62; // [xsp+C0h] [xbp+B0h] BYREF
char *v63; // [xsp+C8h] [xbp+B8h]
__int64 v64; // [xsp+D0h] [xbp+C0h]
__int64 v65; // [xsp+D8h] [xbp+C8h]
v55 = 0;
v8 = a1;
v62 = 0;
v63 = nullptr;
v64 = 0;
v65 = 0;
v12 = a5;
v14 = a7;
if ( !a1 )
{
ERR_put_error(13, 108, 125, "crypto/asn1/tasn_dec.c", 635);
return (unsigned int)v8;
}
if ( *(_BYTE *)a4 == 5 )
{
v56 = a5;
if ( a5 != -4 )
{
a6 = 0;
goto LABEL_6;
}
v12 = -1;
goto LABEL_27;
}
v56 = *(_QWORD *)(a4 + 8);
if ( v56 == -4 )
{
if ( (a5 & 0x80000000) == 0 )
{
LODWORD(v8) = 0;
ERR_put_error(13, 108, 127, "crypto/asn1/tasn_dec.c", 649);
return (unsigned int)v8;
}
LABEL_27:
if ( a7 )
{
LODWORD(v8) = 0;
ERR_put_error(13, 108, 126, "crypto/asn1/tasn_dec.c", 654);
return (unsigned int)v8;
}
v59 = *a2;
if ( !(unsigned int)sub_D6AA1C(nullptr, &v56, &v61, nullptr, nullptr, &v59, a3, 0, a8) )
{
LODWORD(v8) = 0;
ERR_put_error(13, 108, 58, "crypto/asn1/tasn_dec.c", 661);
return (unsigned int)v8;
}
if ( (_BYTE)v61 )
v56 = -3;
}
if ( v12 == -1 )
{
v12 = v56;
a6 = 0;
}
LABEL_6:
v59 = *a2;
v16 = v59;
v61 = v59;
if ( a8 )
{
if ( *(_BYTE *)a8 )
{
v17 = *(_DWORD *)(a8 + 20);
v18 = &v59[*(int *)(a8 + 24)];
v19 = *(_DWORD *)(a8 + 16);
object = *(_DWORD *)(a8 + 4);
v60 = *(_QWORD *)(a8 + 8);
v58 = v17;
v57 = v19;
v61 = v18;
}
else
{
object = ASN1_get_object(&v61, &v60, &v57, &v58, a3);
*(_DWORD *)(a8 + 4) = object;
v22 = object & 0x81;
v23 = v60;
v24 = (_DWORD)v61 - (_DWORD)v16;
*(_DWORD *)(a8 + 20) = v58;
*(_DWORD *)(a8 + 16) = v57;
*(_QWORD *)(a8 + 8) = v23;
*(_DWORD *)(a8 + 24) = v24;
*(_BYTE *)a8 = 1;
if ( (object & 0x81) == 0 && a3 < v23 + v24 )
{
ERR_put_error(13, 104, 155, "crypto/asn1/tasn_dec.c", 1092);
*(_BYTE *)a8 = v22;
goto LABEL_16;
}
}
if ( (object & 0x80) == 0 )
goto LABEL_10;
ERR_put_error(13, 104, 102, "crypto/asn1/tasn_dec.c", 1100);
*(_BYTE *)a8 = 0;
LABEL_16:
LODWORD(v8) = 0;
ERR_put_error(13, 108, 58, "crypto/asn1/tasn_dec.c", 676);
return (unsigned int)v8;
}
LOBYTE(object) = ASN1_get_object(&v61, &v60, &v57, &v58, a3);
if ( (object & 0x80) != 0 )
{
ERR_put_error(13, 104, 102, "crypto/asn1/tasn_dec.c", 1100);
goto LABEL_16;
}
LABEL_10:
if ( v12 < 0 )
goto LABEL_32;
if ( v12 != v57 || a6 != v58 )
{
if ( v14 )
{
LODWORD(v8) = -1;
return (unsigned int)v8;
}
if ( a8 )
*(_BYTE *)a8 = 0;
ERR_put_error(13, 104, 168, "crypto/asn1/tasn_dec.c", 1112);
goto LABEL_16;
}
if ( a8 )
*(_BYTE *)a8 = 0;
LABEL_32:
if ( (object & 1) != 0 )
{
v26 = v61;
v25 = a3 + v16 - v61;
}
else
{
v25 = v60;
v26 = v61;
}
v27 = v56;
v59 = v26;
if ( (unsigned int)(v56 - 16) <= 1 )
{
if ( (object & 0x20) == 0 )
{
LODWORD(v8) = 0;
ERR_put_error(13, 108, 156, "crypto/asn1/tasn_dec.c", 694);
return (unsigned int)v8;
}
goto LABEL_61;
}
if ( v56 == -3 )
{
if ( a8 )
*(_BYTE *)a8 = 0;
LABEL_61:
v30 = *a2;
if ( (object & 1) != 0 )
{
v40 = 1;
if ( v25 <= 0 )
{
LABEL_101:
ERR_put_error(13, 190, 137, "crypto/asn1/tasn_dec.c", 943);
v28 = 0;
goto LABEL_41;
}
while ( 1 )
{
if ( v25 == 1 || *v26 || v26[1] )
{
v61 = v26;
v41 = ASN1_get_object(&v61, &v60, &v57, &v58, v25);
if ( v41 < 0 )
{
ERR_put_error(13, 104, 102, "crypto/asn1/tasn_dec.c", 1100);
ERR_put_error(13, 190, 58, "crypto/asn1/tasn_dec.c", 928);
v28 = 0;
goto LABEL_41;
}
v42 = v41 & 1;
if ( (v41 & 1) != 0 )
{
v44 = v61;
v43 = v25 + v26 - v61;
}
else
{
v43 = v60;
v44 = v61;
}
if ( v42 )
{
if ( v40 == -1 )
{
ERR_put_error(13, 190, 58, "crypto/asn1/tasn_dec.c", 933);
v28 = 0;
goto LABEL_41;
}
++v40;
}
else
{
v44 += v43;
}
v45 = v26 - v44;
v26 = v44;
v25 += v45;
}
else
{
--v40;
v26 += 2;
if ( !v40 )
{
v59 = v26;
v29 = (_DWORD)v26 - (_DWORD)v30;
v27 = v56;
goto LABEL_45;
}
v25 -= 2;
}
if ( v25 <= 0 )
goto LABEL_101;
}
}
v29 = (_DWORD)v26 - (_DWORD)v30 + v25;
v59 = &v26[v25];
goto LABEL_45;
}
if ( (object & 0x20) == 0 )
{
v29 = v25;
v59 = &v26[v25];
v30 = v26;
goto LABEL_45;
}
if ( (v56 & 0xFFFFFFFB) - 1 <= 1 || v56 == 10 )
{
LODWORD(v8) = 0;
ERR_put_error(13, 108, 195, "crypto/asn1/tasn_dec.c", 712);
return (unsigned int)v8;
}
v55 = 1;
if ( !(unsigned int)sub_D6AC34((int *)&v62, (void **)&v59, v25, object & 1, 0) )
{
LABEL_40:
v28 = v55;
goto LABEL_41;
}
v51 = v62;
v39 = BUF_MEM_grow_clean(&v62, v62 + 1);
v29 = v51;
if ( v39 )
{
v63[v51] = 0;
v30 = v63;
v27 = v56;
LABEL_45:
v31 = *(_QWORD *)(a4 + 32);
v32 = v29;
v61 = v30;
if ( v31 )
{
v33 = *(__int64 (__fastcall **)(__int64 *, char *))(v31 + 40);
if ( v33 )
{
v34 = v33(v8, v30);
v28 = v55;
if ( !v34 )
goto LABEL_41;
LABEL_48:
LODWORD(v8) = 1;
*a2 = v59;
goto LABEL_42;
}
}
if ( *(_QWORD *)(a4 + 8) == -4 )
{
v35 = *v8;
if ( !*v8 )
{
v53 = v27;
v47 = ASN1_TYPE_new();
v35 = v47;
if ( !v47 )
{
((void (*)(void))ASN1_TYPE_free)();
v28 = v55;
goto LABEL_41;
}
*v8 = v47;
v27 = v53;
}
if ( v27 != *(_DWORD *)v35 )
{
v52 = v27;
ASN1_TYPE_set(v35, v27, 0);
v27 = v52;
}
v36 = v8;
v8 = (__int64 *)(v35 + 8);
}
else
{
v35 = 0;
v36 = nullptr;
}
switch ( v27 )
{
case 1u:
if ( v32 != 1 )
{
ERR_put_error(13, 204, 106, "crypto/asn1/tasn_dec.c", 800);
goto LABEL_79;
}
*(_DWORD *)v8 = (unsigned __int8)*v61;
v28 = v55;
goto LABEL_48;
case 2u:
case 0xAu:
v50 = v27;
if ( !c2i_ASN1_INTEGER(v8, &v61, v32) )
goto LABEL_79;
v27 = v50;
v28 = v55;
*(_DWORD *)(*v8 + 4) = v50 | *(_DWORD *)(*v8 + 4) & 0x100;
goto LABEL_57;
case 3u:
if ( !c2i_ASN1_BIT_STRING(v8, &v61, v32) )
goto LABEL_79;
goto LABEL_75;
case 5u:
if ( !v32 )
{
*v8 = 1;
v28 = v55;
goto LABEL_57;
}
ERR_put_error(13, 204, 144, "crypto/asn1/tasn_dec.c", 792);
goto LABEL_79;
case 6u:
if ( !c2i_ASN1_OBJECT(v8, &v61, v32) )
goto LABEL_79;
LABEL_75:
v28 = v55;
goto LABEL_48;
default:
if ( v27 == 30 )
{
if ( (v32 & 1) != 0 )
{
ERR_put_error(13, 204, 214, "crypto/asn1/tasn_dec.c", 842);
goto LABEL_79;
}
}
else if ( v27 == 28 && (v32 & 3) != 0 )
{
ERR_put_error(13, 204, 215, "crypto/asn1/tasn_dec.c", 847);
goto LABEL_79;
}
v37 = *v8;
if ( *v8 )
{
*(_DWORD *)(v37 + 4) = v27;
}
else
{
v54 = v27;
v48 = ASN1_STRING_type_new(v27);
v37 = v48;
v27 = v54;
if ( !v48 )
{
ERR_put_error(13, 204, 65, "crypto/asn1/tasn_dec.c", 854);
goto LABEL_79;
}
*v8 = v48;
}
v49 = v27;
if ( v55 )
{
CRYPTO_free(*(_QWORD *)(v37 + 8), "crypto/asn1/tasn_dec.c", 864);
v38 = v61;
v28 = 0;
*(_DWORD *)v37 = v32;
v27 = v49;
*(_QWORD *)(v37 + 8) = v38;
LABEL_57:
if ( v35 && v27 == 5 )
*(_QWORD *)(v35 + 8) = 0;
goto LABEL_48;
}
v46 = ASN1_STRING_set(v37, v61, v32);
v27 = v49;
if ( v46 )
{
v28 = v55;
goto LABEL_57;
}
ERR_put_error(13, 204, 65, "crypto/asn1/tasn_dec.c", 870);
ASN1_STRING_free(v37);
*v8 = 0;
LABEL_79:
ASN1_TYPE_free(v35);
if ( !v36 )
goto LABEL_40;
*v36 = 0;
v28 = v55;
LABEL_41:
LODWORD(v8) = 0;
goto LABEL_42;
}
}
LODWORD(v8) = 0;
ERR_put_error(13, 108, 65, "crypto/asn1/tasn_dec.c", 730);
v28 = 1;
LABEL_42:
if ( v28 )
CRYPTO_free(v63, "crypto/asn1/tasn_dec.c", 750);
return (unsigned int)v8;
}