//
// sub_D6C730 from 0xd6c730 to 0xd6cf94 (2148 bytes)
//
// 2 xrefs:
// > sub_D6B828 @ 0xd6b9d0
// > sub_D6B828 @ 0xd6be9c
//
// 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_D6C730(
__int64 result,
char **a2,
__int64 a3,
__int64 a4,
unsigned int a5,
__int64 a6,
unsigned __int8 a7,
__int64 a8)
{
int v8; // w8
__int64 *v10; // x19
int v12; // w22
__int64 v14; // x21
unsigned int (__fastcall *v15)(__int64, __int64 *, __int64, _QWORD); // x27
int v16; // w21
__int64 v17; // x23
int v18; // w0
int v19; // s9
__int64 v20; // x1
__int64 v21; // x21
_QWORD *v22; // x22
bool v23; // cc
__int64 v24; // x0
__int64 v25; // x23
__int64 field_ptr; // x0
__int64 *v27; // x3
int choice_selector; // w0
__int64 v29; // x2
__int64 v30; // x23
__int64 *v31; // x21
unsigned int v32; // w24
__int64 v33; // d8
int v34; // w0
__int64 v35; // x21
__int64 v36; // x0
__int64 v37; // x24
__int64 v38; // x4
int v39; // w0
int v40; // s8
__int64 v41; // x6
char *v42; // x23
__int64 v43; // x23
__int64 v44; // x0
__int64 *v45; // x0
__int64 v46; // [xsp+90h] [xbp+70h]
__int64 v47; // [xsp+98h] [xbp+78h] BYREF
unsigned __int8 v48; // [xsp+A1h] [xbp+81h] BYREF
unsigned __int8 v49; // [xsp+A2h] [xbp+82h] BYREF
char v50; // [xsp+A3h] [xbp+83h] BYREF
unsigned int v51; // [xsp+A4h] [xbp+84h] BYREF
char *v52; // [xsp+A8h] [xbp+88h] BYREF
v8 = a5;
v47 = a3;
v52 = nullptr;
v10 = (__int64 *)result;
v12 = a7;
v14 = *(_QWORD *)(a4 + 32);
if ( result )
{
if ( v14 )
v15 = *(unsigned int (__fastcall **)(__int64, __int64 *, __int64, _QWORD))(v14 + 24);
else
v15 = nullptr;
switch ( *(_BYTE *)a4 )
{
case 0:
v27 = *(__int64 **)(a4 + 16);
if ( !v27 )
return sub_D6AECC((__int64 *)result, a2, v47, a4, a5, a6, a7, a8);
if ( a5 != -1 || a7 )
{
ERR_put_error(13, 120, 170, "crypto/asn1/tasn_dec.c", 159);
goto LABEL_11;
}
return sub_D6C3B4(result, a2, v47, v27, 0, a8);
case 1:
case 6:
v52 = *a2;
v17 = v47;
if ( a5 == -1 )
{
LODWORD(a6) = 0;
v8 = 16;
}
v18 = sub_D6A774(&v47, nullptr, nullptr, &v49, &v50, &v52, v47, v8, a6, a7, a8);
if ( !v18 )
{
ERR_put_error(13, 120, 58, "crypto/asn1/tasn_dec.c", 274);
goto LABEL_11;
}
if ( v18 == -1 )
return 0xFFFFFFFFLL;
if ( v14 && (*(_DWORD *)(v14 + 8) & 4) != 0 )
{
v19 = 1;
v47 = *a2 - v52 + v17;
}
else
{
v19 = v49;
}
if ( !v50 )
{
ERR_put_error(13, 120, 149, "crypto/asn1/tasn_dec.c", 286);
goto LABEL_11;
}
if ( !*v10 && !(unsigned int)ASN1_item_ex_new(v10, a4) )
{
ERR_put_error(13, 120, 58, "crypto/asn1/tasn_dec.c", 291);
goto LABEL_11;
}
if ( v15 && !v15(4, v10, a4, 0) )
goto LABEL_15;
v20 = *(_QWORD *)(a4 + 24);
v21 = 1;
v22 = *(_QWORD **)(a4 + 16);
if ( v20 <= 0 )
goto LABEL_95;
do
{
if ( (*v22 & 0x300LL) != 0 )
{
v24 = asn1_do_adb(v10, v22, 0);
v25 = v24;
if ( v24 )
{
field_ptr = asn1_get_field_ptr(v10, v24);
asn1_template_free(field_ptr, v25);
}
v20 = *(_QWORD *)(a4 + 24);
}
v23 = v21 < v20;
v22 += 5;
++v21;
}
while ( v23 );
v22 = *(_QWORD **)(a4 + 16);
if ( v20 <= 0 )
{
LABEL_95:
v40 = 0;
LABEL_96:
if ( v49 )
{
if ( v47 > 1 && !*v52 && !v52[1] )
{
v52 += 2;
goto LABEL_85;
}
goto LABEL_102;
}
LABEL_85:
if ( !v19 && v47 )
{
ERR_put_error(13, 120, 148, "crypto/asn1/tasn_dec.c", 369);
goto LABEL_11;
}
}
else
{
v37 = 0;
while ( 1 )
{
v40 = v37;
v31 = (__int64 *)asn1_do_adb(v10, v22, 1);
if ( !v31 )
goto LABEL_11;
v41 = asn1_get_field_ptr(v10, v31);
if ( !v47 )
break;
v42 = v52;
if ( v47 > 1 && !*v52 && !v52[1] )
{
v52 += 2;
if ( v49 )
{
v49 = 0;
v47 -= 2;
goto LABEL_85;
}
ERR_put_error(13, 120, 159, "crypto/asn1/tasn_dec.c", 325);
LABEL_11:
ERR_add_error_data(2, "Type=", *(_QWORD *)(a4 + 48));
return 0;
}
if ( v37 == *(_QWORD *)(a4 + 24) - 1LL )
LOBYTE(v38) = 0;
else
v38 = *v31 & 1;
v46 = v41;
v39 = sub_D6C3B4(v41, &v52, v47, v31, v38, a8);
if ( !v39 )
{
LABEL_75:
ERR_add_error_data(4, "Field=", v31[3]);
return 0;
}
if ( v39 == -1 )
asn1_template_free(v46, v31);
else
v47 += v42 - v52;
++v37;
v22 += 5;
v40 = v37;
if ( *(_QWORD *)(a4 + 24) <= v37 )
goto LABEL_96;
}
if ( v49 )
{
LABEL_102:
ERR_put_error(13, 120, 137, "crypto/asn1/tasn_dec.c", 364);
goto LABEL_11;
}
}
v43 = v40 + 1LL;
if ( *(_QWORD *)(a4 + 24) > v40 )
{
do
{
v45 = (__int64 *)asn1_do_adb(v10, v22, 1);
v31 = v45;
if ( !v45 )
goto LABEL_11;
if ( (*v45 & 1) == 0 )
{
ERR_put_error(13, 120, 121, "crypto/asn1/tasn_dec.c", 389);
goto LABEL_75;
}
v22 += 5;
v44 = asn1_get_field_ptr(v10, v45);
asn1_template_free(v44, v31);
v23 = v43++ < *(_QWORD *)(a4 + 24);
}
while ( v23 );
}
if ( !(unsigned int)asn1_enc_save(v10, *a2, (unsigned int)v52 - (unsigned int)*a2, a4) )
goto LABEL_15;
if ( v15 )
{
LABEL_51:
if ( !v15(5, v10, a4, 0) )
{
LABEL_15:
ERR_put_error(13, 120, 100, "crypto/asn1/tasn_dec.c", 405);
goto LABEL_11;
}
}
LABEL_52:
*a2 = v52;
return 1;
case 2:
if ( v15 && !v15(4, (__int64 *)result, a4, 0) )
goto LABEL_15;
if ( *v10 )
{
choice_selector = asn1_get_choice_selector(v10, a4);
v29 = *(_QWORD *)(a4 + 24);
if ( (choice_selector & 0x80000000) == 0 && choice_selector < v29 )
{
v35 = *(_QWORD *)(a4 + 16) + 40LL * choice_selector;
v36 = asn1_get_field_ptr(v10, v35);
asn1_template_free(v36, v35);
asn1_set_choice_selector(v10, 0xFFFFFFFFLL, a4);
v29 = *(_QWORD *)(a4 + 24);
}
}
else
{
if ( !(unsigned int)ASN1_item_ex_new(v10, a4) )
{
ERR_put_error(13, 120, 58, "crypto/asn1/tasn_dec.c", 214);
goto LABEL_11;
}
v29 = *(_QWORD *)(a4 + 24);
}
v52 = *a2;
v30 = 0;
v31 = *(__int64 **)(a4 + 16);
if ( v29 <= 0 )
{
v32 = 0;
}
else
{
while ( 1 )
{
v32 = v30;
v33 = asn1_get_field_ptr(v10, v31);
v34 = sub_D6C3B4(v33, &v52, v47, v31, 1u, a8);
if ( v34 != -1 )
break;
v29 = *(_QWORD *)(a4 + 24);
v32 = ++v30;
v31 += 5;
if ( v29 <= v30 )
goto LABEL_49;
}
if ( v34 <= 0 )
{
asn1_template_free(v33, v31);
ERR_put_error(13, 120, 58, "crypto/asn1/tasn_dec.c", 237);
if ( !v31 )
goto LABEL_11;
goto LABEL_75;
}
v29 = *(_QWORD *)(a4 + 24);
}
LABEL_49:
if ( v30 != v29 )
{
asn1_set_choice_selector(v10, v32, a4);
if ( !v15 )
goto LABEL_52;
goto LABEL_51;
}
if ( !v12 )
{
ERR_put_error(13, 120, 143, "crypto/asn1/tasn_dec.c", 249);
goto LABEL_11;
}
ASN1_item_ex_free(v10, a4);
return 0xFFFFFFFFLL;
case 4:
return (*(__int64 (__fastcall **)(__int64, char **, __int64, __int64, _QWORD, __int64, _QWORD, __int64))(v14 + 32))(
result,
a2,
v47,
a4,
a5,
a6,
a7,
a8);
case 5:
v52 = *a2;
if ( !(unsigned int)sub_D6AA1C(nullptr, &v51, &v48, nullptr, nullptr, &v52, v47, 1, a8) )
{
ERR_put_error(13, 120, 58, "crypto/asn1/tasn_dec.c", 174);
goto LABEL_11;
}
v16 = v48;
if ( v48 )
{
if ( !v12 )
{
ERR_put_error(13, 120, 139, "crypto/asn1/tasn_dec.c", 183);
goto LABEL_11;
}
return 0xFFFFFFFFLL;
}
if ( (ASN1_tag2bit(v51) & *(_QWORD *)(a4 + 8)) == 0 )
{
if ( !v12 )
{
ERR_put_error(13, 120, 140, "crypto/asn1/tasn_dec.c", 191);
goto LABEL_11;
}
return 0xFFFFFFFFLL;
}
result = sub_D6AECC(v10, a2, v47, a4, v51, v16, v16, a8);
break;
default:
return 0;
}
}
return result;
}