//
// sub_D9BF74 from 0xd9bf74 to 0xd9c3fc (1160 bytes)
//
// 2 xrefs:
// > ENGINE_add_conf_module @ 0xd9c400
// > ENGINE_add_conf_module @ 0xd9c40c
//
// 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_D9BF74(__int64 a1, __int64 a2)
{
unsigned int v3; // s10
__int64 value; // x0
__int64 section; // x0
__int64 v7; // d13
__int64 v8; // x0
const char *v9; // x27
__int64 v10; // x0
__int64 v11; // x19
__int64 v12; // d12
char *v13; // x2
__int64 v14; // x0
__int64 v15; // x23
unsigned int v16; // s8
__int64 v17; // x26
int v18; // w20
__int64 v19; // x0
const char *v20; // x19
_QWORD *v21; // x21
char *v22; // x0
char *v23; // x22
int v24; // w2
int v25; // w3
int v26; // w4
int v27; // w5
int v28; // w6
int v29; // w7
__int64 v31; // x0
__int64 v32; // x0
__int64 v33; // x0
char v34; // [xsp+0h] [xbp+0h]
__int64 v35; // [xsp+98h] [xbp+98h] BYREF
v3 = 0;
value = CONF_imodule_get_value(a1);
section = NCONF_get_section(a2, value);
v7 = section;
if ( !section )
{
ERR_put_error(38, 187, 148, "crypto/engine/eng_cnf.c", 165);
return 0;
}
if ( (int)OPENSSL_sk_num(section) <= 0 )
return 1;
LABEL_3:
v8 = OPENSSL_sk_value(v7, v3);
v9 = *(const char **)(v8 + 8);
v10 = *(_QWORD *)(v8 + 16);
v35 = -1;
v11 = v10;
v12 = v10;
v13 = strchr(v9, 46);
if ( v13 )
v9 = v13 + 1;
v14 = NCONF_get_section(a2, v11);
v15 = v14;
if ( !v14 )
{
ERR_put_error(38, 188, 149, "crypto/engine/eng_cnf.c", 61);
return 0;
}
v16 = 0;
v17 = 0;
v18 = 0;
if ( (int)OPENSSL_sk_num(v14) > 0 )
{
do
{
v19 = OPENSSL_sk_value(v15, (unsigned int)v18);
v20 = *(const char **)(v19 + 8);
v21 = (_QWORD *)v19;
v22 = strchr(v20, 46);
if ( v22 )
v20 = v22 + 1;
v23 = (char *)v21[2];
if ( !strcmp(v20, "engine_id") )
{
v9 = v23;
++v18;
continue;
}
if ( !strcmp(v20, "soft_load") )
{
++v18;
v16 = 1;
continue;
}
if ( !strcmp(v20, "dynamic_path") )
{
v31 = ENGINE_by_id("dynamic");
v17 = v31;
if ( !v31 )
goto LABEL_27;
if ( !(unsigned int)ENGINE_ctrl_cmd_string(v31, "SO_PATH", v23, 0)
|| !(unsigned int)ENGINE_ctrl_cmd_string(v17, "LIST_ADD", &byte_F78BA8, 0)
|| !(unsigned int)ENGINE_ctrl_cmd_string(v17, "LOAD", 0, 0) )
{
goto LABEL_28;
}
++v18;
}
else
{
if ( !v17 )
{
v17 = ENGINE_by_id(v9);
if ( !v17 )
{
if ( !v16 )
{
LABEL_27:
v17 = 0;
LABEL_28:
ERR_put_error(38, 188, 102, "crypto/engine/eng_cnf.c", 141);
ERR_add_error_data(6, "section=", *v21);
goto LABEL_29;
}
ERR_clear_error(v16);
LABEL_23:
if ( (int)++v3 >= (int)OPENSSL_sk_num(v7) )
return 1;
goto LABEL_3;
}
}
if ( !strcmp(v23, "EMPTY") )
v23 = nullptr;
if ( !strcmp(v20, "init") )
{
if ( !(unsigned int)NCONF_get_number_e(a2, v12, "init", &v35) )
goto LABEL_28;
if ( v35 == 1 )
{
if ( !(unsigned int)ENGINE_init(v17) )
goto LABEL_28;
v32 = qword_125D5E0;
if ( !qword_125D5E0 && (v32 = OPENSSL_sk_new_null(0), (qword_125D5E0 = v32) == 0)
|| !(unsigned int)OPENSSL_sk_push(v32, v17) )
{
ENGINE_finish(v17);
goto LABEL_28;
}
}
else if ( v35 )
{
ERR_put_error(38, 188, 151, "crypto/engine/eng_cnf.c", 122);
goto LABEL_28;
}
goto LABEL_18;
}
if ( !strcmp(v20, "default_algorithms") )
{
if ( !(unsigned int)ENGINE_set_default_string(v17, v23, v24, v25, v26, v27, v28, v29, v34) )
goto LABEL_28;
LABEL_18:
++v18;
continue;
}
if ( !(unsigned int)ENGINE_ctrl_cmd_string(v17, v20, v23, 0) )
goto LABEL_28;
++v18;
}
}
while ( v18 < (int)OPENSSL_sk_num(v15) );
}
if ( !v17 || v35 != -1 )
{
LABEL_22:
ENGINE_free(v17);
goto LABEL_23;
}
if ( (unsigned int)ENGINE_init(v17) )
{
v33 = qword_125D5E0;
if ( qword_125D5E0 || (v33 = OPENSSL_sk_new_null(0), (qword_125D5E0 = v33) != 0) )
{
if ( (unsigned int)OPENSSL_sk_push(v33, v17) )
goto LABEL_22;
}
ENGINE_finish(v17);
}
ERR_put_error(38, 188, 102, "crypto/engine/eng_cnf.c", 141);
LABEL_29:
ENGINE_free(v17);
return 0;
}