//
// ASN1_item_ex_d2i from 0x7c6c28 to 0x7c75cc (2468 bytes)
//
// 3 xrefs:
// > ASN1_item_d2i @ 0x7c766c
// > sub_849F20 @ 0x849f7c
// > ??> @ 0x5ea9c
//
// 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 ASN1_item_ex_d2i(
int *a1,
unsigned __int8 **a2,
int a3,
int a4,
int a5,
int a6,
unsigned __int8 a7,
int a8)
{
int v11; // r8
int (__fastcall *v13)(int, int *, int, _DWORD); // r10
int v14; // r7
int v15; // r5
int *v17; // r3
bool v18; // zf
int v19; // r0
int v20; // r2
_DWORD *v21; // r7
int v22; // r9
int i; // r5
int v24; // r8
int field_ptr; // r0
int choice_selector; // r0
int v27; // r3
int v28; // r9
int *v29; // r8
int v30; // r0
int v31; // r7
int v32; // r0
int v33; // r3
int v34; // r0
int v35; // r0
int v36; // r2
int v37; // r10
unsigned __int8 *v38; // r5
int *v39; // r0
int v40; // r0
int v41; // [sp+24h] [bp-20h]
int v42; // [sp+24h] [bp-20h]
int (__fastcall *v43)(int, int *, int, _DWORD); // [sp+28h] [bp-1Ch]
unsigned __int8 v44; // [sp+31h] [bp-13h] BYREF
unsigned __int8 v45; // [sp+32h] [bp-12h] BYREF
char v46; // [sp+33h] [bp-11h] BYREF
int v47; // [sp+34h] [bp-10h] BYREF
unsigned __int8 *v48; // [sp+38h] [bp-Ch] BYREF
unsigned int v49; // [sp+3Ch] [bp-8h] BYREF
v47 = a3;
v11 = *(_DWORD *)(a4 + 16);
v48 = nullptr;
if ( !a1 )
{
v15 = 0;
goto LABEL_9;
}
if ( v11 )
{
v13 = *(int (__fastcall **)(int, int *, int, _DWORD))(v11 + 16);
switch ( *(_BYTE *)a4 )
{
case 0:
goto LABEL_11;
case 1:
case 6:
goto LABEL_18;
case 2:
if ( v13 && !v13(4, a1, a4, 0) )
goto LABEL_39;
goto LABEL_48;
case 4:
goto LABEL_41;
case 5:
goto LABEL_4;
default:
goto LABEL_44;
}
}
switch ( *(_BYTE *)a4 )
{
case 0:
LABEL_11:
v17 = *(int **)(a4 + 8);
if ( v17 )
{
v18 = a5 == -1;
if ( a5 == -1 )
v18 = a7 == 0;
if ( !v18 )
{
ERR_put_error(13, 120, 170, "crypto/asn1/tasn_dec.c", 159);
goto LABEL_8;
}
v15 = sub_7C5EB8((int)a1, a2, a3, v17, 0, a8);
}
else
{
v15 = sub_7C46C4(a1, (void **)a2, a3, a4, a5, a6, a7, a8);
}
goto LABEL_42;
case 1:
case 6:
v13 = nullptr;
LABEL_18:
v48 = *a2;
if ( a5 == -1 )
{
a6 = 0;
a5 = 16;
}
v19 = sub_7C3F3C(&v47, nullptr, nullptr, &v45, &v46, &v48, a3, a5, a6, a7, a8);
if ( !v19 )
{
ERR_put_error(13, 120, 58, "crypto/asn1/tasn_dec.c", 274);
goto LABEL_8;
}
if ( v19 == -1 )
goto LABEL_114;
if ( v11 && (*(_DWORD *)(v11 + 4) & 4) != 0 )
{
v41 = 1;
v47 = a3 + *a2 - v48;
}
else
{
v41 = v45;
}
if ( !v46 )
{
ERR_put_error(13, 120, 149, "crypto/asn1/tasn_dec.c", 286);
goto LABEL_8;
}
if ( !*a1 && !ASN1_item_ex_new(a1, a4) )
{
ERR_put_error(13, 120, 58, "crypto/asn1/tasn_dec.c", 291);
goto LABEL_8;
}
if ( v13 && !v13(4, a1, a4, 0) )
goto LABEL_39;
v20 = *(_DWORD *)(a4 + 12);
v21 = *(_DWORD **)(a4 + 8);
if ( v20 <= 0 )
{
v22 = 0;
goto LABEL_104;
}
for ( i = 0; i < v20; ++i )
{
if ( (*v21 & 0x300) != 0 )
{
v24 = asn1_do_adb(a1, v21, 0);
if ( v24 )
{
field_ptr = asn1_get_field_ptr(a1, v24);
asn1_template_free(field_ptr, v24);
}
v20 = *(_DWORD *)(a4 + 12);
}
v21 += 5;
}
v22 = 0;
v21 = *(_DWORD **)(a4 + 8);
if ( v20 <= 0 )
{
LABEL_104:
if ( !v45 )
goto LABEL_92;
if ( v47 > 1 && !*v48 && !v48[1] )
{
v48 += 2;
goto LABEL_92;
}
LABEL_110:
ERR_put_error(13, 120, 137, "crypto/asn1/tasn_dec.c", 364);
goto LABEL_8;
}
v43 = v13;
while ( 1 )
{
v29 = (int *)asn1_do_adb(a1, v21, 1);
if ( !v29 )
goto LABEL_8;
v35 = asn1_get_field_ptr(a1, v29);
v36 = v47;
v37 = v35;
if ( !v47 )
{
v13 = v43;
if ( !v45 )
goto LABEL_98;
goto LABEL_110;
}
v38 = v48;
if ( v47 > 1 && !*v48 && !v48[1] )
break;
if ( *(_DWORD *)(a4 + 12) - 1 == v22 )
LOBYTE(v33) = 0;
else
v33 = *v29 & 1;
v34 = sub_7C5EB8(v35, &v48, v47, v29, v33, a8);
if ( !v34 )
goto LABEL_79;
if ( v34 == -1 )
asn1_template_free(v37, v29);
else
v47 += v38 - v48;
++v22;
v21 += 5;
if ( v22 >= *(_DWORD *)(a4 + 12) )
{
v13 = v43;
goto LABEL_104;
}
}
if ( v45 )
v36 = v47 - 2;
v13 = v43;
v48 += 2;
if ( !v45 )
{
ERR_put_error(13, 120, 159, "crypto/asn1/tasn_dec.c", 325);
goto LABEL_8;
}
v47 = v36;
v45 = 0;
LABEL_92:
if ( !v41 && v47 )
{
ERR_put_error(13, 120, 148, "crypto/asn1/tasn_dec.c", 369);
goto LABEL_8;
}
LABEL_98:
while ( v22 < *(_DWORD *)(a4 + 12) )
{
v39 = (int *)asn1_do_adb(a1, v21, 1);
++v22;
v21 += 5;
v29 = v39;
if ( !v39 )
goto LABEL_8;
if ( (*v39 & 1) == 0 )
{
ERR_put_error(13, 120, 121, "crypto/asn1/tasn_dec.c", 389);
goto LABEL_79;
}
v40 = asn1_get_field_ptr(a1, v39);
asn1_template_free(v40, v29);
}
if ( !asn1_enc_save(a1, *a2, v48 - *a2, a4) )
goto LABEL_39;
if ( !v13 )
{
LABEL_59:
*a2 = v48;
return 1;
}
LABEL_58:
if ( v13(5, a1, a4, 0) )
goto LABEL_59;
LABEL_39:
ERR_put_error(13, 120, 100, "crypto/asn1/tasn_dec.c", 405);
LABEL_8:
ERR_add_error_data(2, "Type=", *(_DWORD *)(a4 + 24));
v15 = 0;
LABEL_9:
ASN1_item_ex_free(a1, a4);
return v15;
case 2:
v13 = nullptr;
LABEL_48:
if ( *a1 )
{
choice_selector = asn1_get_choice_selector(a1, a4);
v27 = *(_DWORD *)(a4 + 12);
if ( choice_selector >= 0 && choice_selector < v27 )
{
v31 = *(_DWORD *)(a4 + 8) + 20 * choice_selector;
v32 = asn1_get_field_ptr(a1, v31);
asn1_template_free(v32, v31);
asn1_set_choice_selector(a1, -1, a4);
v27 = *(_DWORD *)(a4 + 12);
}
}
else
{
if ( !ASN1_item_ex_new(a1, a4) )
{
ERR_put_error(13, 120, 58, "crypto/asn1/tasn_dec.c", 214);
goto LABEL_8;
}
v27 = *(_DWORD *)(a4 + 12);
}
v28 = 0;
v48 = *a2;
v29 = *(int **)(a4 + 8);
if ( v27 <= 0 )
goto LABEL_56;
while ( 1 )
{
v42 = asn1_get_field_ptr(a1, v29);
v30 = sub_7C5EB8(v42, &v48, v47, v29, 1u, a8);
if ( v30 != -1 )
break;
v27 = *(_DWORD *)(a4 + 12);
++v28;
v29 += 5;
if ( v28 >= v27 )
goto LABEL_56;
}
if ( v30 <= 0 )
{
asn1_template_free(v42, v29);
ERR_put_error(13, 120, 58, "crypto/asn1/tasn_dec.c", 237);
if ( !v29 )
goto LABEL_8;
LABEL_79:
ERR_add_error_data(4, "Field=", v29[3]);
v15 = 0;
goto LABEL_9;
}
v27 = *(_DWORD *)(a4 + 12);
LABEL_56:
if ( v28 != v27 )
{
asn1_set_choice_selector(a1, v28, a4);
if ( !v13 )
goto LABEL_59;
goto LABEL_58;
}
if ( !a7 )
{
ERR_put_error(13, 120, 143, "crypto/asn1/tasn_dec.c", 249);
goto LABEL_8;
}
ASN1_item_ex_free(a1, a4);
LABEL_114:
v15 = -1;
goto LABEL_9;
case 4:
v13 = (int (__fastcall *)(int, int *, int, _DWORD))(&stru_280000 + 3);
LABEL_41:
v15 = ((int (__fastcall *)(int *, unsigned __int8 **, int, int, int, int, _DWORD, int))v13)(
a1,
a2,
a3,
a4,
a5,
a6,
a7,
a8);
goto LABEL_42;
case 5:
LABEL_4:
v48 = *a2;
if ( !sub_7C41C0(nullptr, &v49, &v44, nullptr, nullptr, &v48, a3, 1, a8) )
{
ERR_put_error(13, 120, 58, "crypto/asn1/tasn_dec.c", 174);
goto LABEL_8;
}
v14 = v44;
if ( v44 )
{
if ( a7 )
goto LABEL_114;
ERR_put_error(13, 120, 139, "crypto/asn1/tasn_dec.c", 183);
goto LABEL_8;
}
if ( (ASN1_tag2bit(v49) & *(_DWORD *)(a4 + 4)) != 0 )
{
v15 = sub_7C46C4(a1, (void **)a2, v47, a4, v49, v14, v14, a8);
LABEL_42:
if ( v15 > 0 )
return v15;
goto LABEL_9;
}
if ( a7 )
goto LABEL_114;
ERR_put_error(13, 120, 140, "crypto/asn1/tasn_dec.c", 191);
goto LABEL_8;
default:
LABEL_44:
v15 = 0;
goto LABEL_9;
}
}