//
// sub_8D2AE8 from 0x8d2ae8 to 0x8d2d58 (624 bytes)
//
// 1 xrefs:
// > ??> @ 0xa3a620
//
// 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 sub_8D2AE8(int a1, int a2, int a3, int a4)
{
int data; // r4
_DWORD *v9; // r0
bool v10; // zf
int v11; // r6
_DWORD *v12; // r9
int v13; // r4
int result; // r0
int v15; // r1
int v16; // r2
int v17; // r3
int v18; // r0
int v19; // r0
int v20; // r3
int v21; // r2
int *v22; // r0
int v23; // r2
data = BIO_get_data(a1);
v9 = (_DWORD *)BIO_next(a1);
v10 = data == 0;
if ( data )
v10 = v9 == nullptr;
v11 = v10;
if ( v10 )
return 0;
v12 = v9;
if ( a2 == 11 )
{
v19 = *(_DWORD *)data;
v20 = *(_DWORD *)(data + 4);
while ( v20 == v19 )
{
LABEL_31:
if ( (BIO_test_flags(a1, -1) & 0x100) != 0 )
{
v21 = *(_DWORD *)(data + 8);
if ( !v21 )
goto LABEL_43;
v19 = EVP_EncodeBlock((_BYTE *)(data + 32), data + 1534, v21);
*(_DWORD *)(data + 8) = v11;
v20 = 0;
*(_DWORD *)data = v19;
*(_DWORD *)(data + 4) = v11;
}
else
{
if ( !*(_DWORD *)(data + 16) || !EVP_ENCODE_CTX_num(*(_DWORD *)(data + 28)) )
{
LABEL_43:
v9 = v12;
v16 = a3;
v17 = a4;
v15 = 11;
return BIO_ctrl(v9, v15, v16, v17);
}
v22 = *(int **)(data + 28);
*(_DWORD *)(data + 4) = 0;
EVP_EncodeFinal(v22, (_BYTE *)(data + 32), (int *)data);
v19 = *(_DWORD *)data;
v20 = *(_DWORD *)(data + 4);
}
}
while ( 1 )
{
result = sub_8D2508(a1, nullptr, 0);
if ( result < 0 )
break;
if ( *(_DWORD *)(data + 4) == *(_DWORD *)data )
goto LABEL_31;
}
}
else
{
if ( a2 <= 11 )
{
switch ( a2 )
{
case 2:
if ( *(int *)(data + 24) <= 0 )
return 1;
break;
case 10:
v23 = *(_DWORD *)(data + 4);
if ( *(_DWORD *)data < v23 )
OPENSSL_die("assertion failed: ctx->buf_len >= ctx->buf_off", "crypto/evp/bio_b64.c", 472);
if ( *(_DWORD *)data - v23 > 0 )
return *(_DWORD *)data - v23;
break;
case 1:
*(_DWORD *)(data + 24) = 1;
*(_DWORD *)(data + 20) = 1;
*(_DWORD *)(data + 16) = v11;
break;
}
LABEL_17:
v15 = a2;
v16 = a3;
v17 = a4;
return BIO_ctrl(v9, v15, v16, v17);
}
if ( a2 != 13 )
{
if ( a2 >= 13 )
{
if ( a2 == 101 )
{
BIO_clear_flags(a1, 15);
v13 = BIO_ctrl(v12, 101, a3, a4);
BIO_copy_next_retry(a1);
return v13;
}
goto LABEL_17;
}
return 1;
}
v18 = *(_DWORD *)(data + 4);
if ( *(_DWORD *)data < v18 )
OPENSSL_die("assertion failed: ctx->buf_len >= ctx->buf_off", "crypto/evp/bio_b64.c", 463);
result = *(_DWORD *)data - v18;
if ( !result )
{
if ( !*(_DWORD *)(data + 16) || !EVP_ENCODE_CTX_num(*(_DWORD *)(data + 28)) )
goto LABEL_24;
return 1;
}
if ( result <= 0 )
{
LABEL_24:
v9 = v12;
v16 = a3;
v17 = a4;
v15 = 13;
return BIO_ctrl(v9, v15, v16, v17);
}
}
return result;
}