//
// EVP_DecodeUpdate from 0x8b7108 to 0x8b7334 (556 bytes)
//
// 4 xrefs:
// > PEM_read_bio @ 0x822be4
// > sub_8D1D58 @ 0x8d1ffc
// > sub_8D1D58 @ 0x8d2100
// > ??> @ 0x653cc
//
// 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 EVP_DecodeUpdate(int *a1, int a2, int *a3, unsigned __int8 *a4, int a5)
{
unsigned __int8 *v5; // r6
int v6; // r12
int v10; // r7
int v11; // r5
int result; // r0
int v13; // r1
int v14; // r2
unsigned __int8 *v15; // r8
unsigned __int8 *v16; // r4
const char *v17; // r3
int v18; // t1
int v19; // r4
int v20; // r0
int v21; // r0
int v22; // r0
const char *v23; // [sp+4h] [bp-8h]
v5 = (unsigned __int8 *)(a1 + 2);
v6 = *a1;
v10 = a5;
if ( *a1 > 0 && v5[v6 - 1] == 61 )
{
if ( v6 == 1 )
{
v11 = 1;
}
else if ( v5[v6 - 2] == 61 )
{
v11 = 2;
}
else
{
v11 = 1;
}
}
else
{
v11 = 0;
}
if ( !a5 )
{
result = 0;
goto LABEL_44;
}
if ( a5 <= 0 )
{
v10 = 0;
LABEL_38:
if ( v6 > 0 )
{
v19 = v6 & 3;
if ( (v6 & 3) == 0 )
goto LABEL_28;
}
goto LABEL_40;
}
v13 = *a4;
if ( (v13 & 0x80) != 0 || (v14 = (unsigned __int8)aAbcdefghijklmn_7[v13 + 68], v14 == 255) )
{
*a3 = 0;
*a1 = v6;
return -1;
}
v15 = &a4[a5];
v16 = a4 + 1;
v10 = 0;
v17 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
while ( 1 )
{
if ( v13 != 61 )
{
if ( v11 && (v14 | 0x13) != 0xF3 )
goto LABEL_21;
if ( v14 == 242 )
break;
goto LABEL_14;
}
if ( ++v11 == 3 )
goto LABEL_21;
if ( v14 == 242 )
break;
LABEL_14:
if ( (v14 | 0x13) != 0xF3 )
{
if ( v6 > 63 )
goto LABEL_21;
v5[v6++] = v13;
}
if ( v6 == 64 )
{
v23 = v17;
v21 = EVP_DecodeBlock(a2, v5, 64);
v6 = (unsigned int)v21 >> 31;
if ( v11 > v21 )
v6 = 1;
if ( v6 )
goto LABEL_51;
v22 = v21 - v11;
v10 += v22;
a2 += v22;
v17 = v23;
if ( v16 == v15 )
goto LABEL_38;
}
else if ( v16 == v15 )
{
goto LABEL_38;
}
v18 = *v16++;
v13 = v18;
if ( (v18 & 0x80) == 0 )
{
v14 = (unsigned __int8)v17[v13 + 68];
if ( v14 != 255 )
continue;
}
goto LABEL_21;
}
if ( v6 <= 0 )
{
result = 0;
goto LABEL_44;
}
if ( (v6 & 3) != 0 )
{
LABEL_21:
result = -1;
goto LABEL_44;
}
v19 = 1;
LABEL_28:
v20 = EVP_DecodeBlock(a2, v5, v6);
v6 = (unsigned int)v20 >> 31;
if ( v11 > v20 )
v6 = 1;
if ( v6 )
{
LABEL_51:
v6 = 0;
result = -1;
}
else
{
v10 += v20 - v11;
if ( v19 )
{
result = 0;
goto LABEL_44;
}
v6 = 0;
LABEL_40:
result = v6;
if ( v6 )
result = 1;
if ( !v11 )
result |= 1u;
}
LABEL_44:
*a3 = v10;
*a1 = v6;
return result;
}