//
// OPENSSL_utf82uni from 0x1049cd8 to 0x1049eec (532 bytes)
//
// 2 xrefs:
// > PKCS12_key_gen_utf8 @ 0x1048340
// > ??> @ 0x46138
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 13:16:35 +0000
//
_BYTE *__fastcall OPENSSL_utf82uni(const char *a1, int a2, _QWORD *a3, int *a4)
{
int v4; // w21
int v8; // w19
int v9; // w20
int v10; // w0
int v11; // w1
int v13; // w20
_BYTE *v14; // x0
_BYTE *v15; // x28
_BYTE *v16; // x19
int v17; // w26
__int16 v18; // w2
int v19; // w0
unsigned __int64 v20; // x2
__int16 v21; // w1
_BYTE *v22; // x0
unsigned __int64 v23; // [xsp+68h] [xbp+68h] BYREF
v23 = 0;
v4 = a2;
if ( a2 == -1 )
v4 = strlen(a1);
if ( v4 > 0 )
{
v8 = 0;
v9 = 0;
do
{
v10 = UTF8_getc((unsigned __int8 *)&a1[v8], v4 - v8, &v23);
v8 += v10;
v11 = v9 + 4;
v9 += 2;
if ( v10 < 0 )
return OPENSSL_asc2uni(a1, v4, a3, a4);
if ( v23 > 0x10FFFF )
return nullptr;
if ( v23 > 0xFFFF )
v9 = v11;
}
while ( v4 > v8 );
v13 = v9 + 2;
v14 = CRYPTO_malloc((void *)v13, (__int64)"crypto/pkcs12/p12_utl.c", 113);
v15 = v14;
if ( v14 )
{
v16 = v14;
v17 = 0;
do
{
while ( 1 )
{
v19 = UTF8_getc((unsigned __int8 *)&a1[v17], v4 - v17, &v23);
v20 = (v23 - 0x10000) >> 10;
v21 = (v23 & 0x3FF) - 9216;
if ( v23 <= 0xFFFF )
break;
v16 += 4;
v23 -= 0x10000LL;
v18 = v20 - 10240;
v17 += v19;
*(v16 - 3) = v18;
*(v16 - 1) = v21;
*(v16 - 2) = HIBYTE(v21);
*(v16 - 4) = HIBYTE(v18);
if ( v4 <= v17 )
goto LABEL_17;
}
*v16 = BYTE1(v23);
v17 += v19;
v16[1] = v23;
v16 += 2;
}
while ( v4 > v17 );
goto LABEL_17;
}
return nullptr;
}
v22 = CRYPTO_malloc((char *)dword_0 + 2, (__int64)"crypto/pkcs12/p12_utl.c", 113);
v15 = v22;
if ( !v22 )
return nullptr;
v16 = v22;
v13 = 2;
LABEL_17:
*v16 = 0;
v16[1] = 0;
if ( a4 )
*a4 = v13;
if ( a3 )
*a3 = v15;
return v15;
}