//
// png_handle_sPLT from 0xe5637c to 0xe56684 (776 bytes)
//
// 4 xrefs:
// > png_push_read_chunk @ 0xe459c8
// > png_read_info @ 0xe49854
// > png_read_end @ 0xe4be04
// > ??> @ 0x75460
//
// 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:10:18 +0000
//
void __fastcall png_handle_sPLT(_DWORD *a1, __int64 a2, unsigned int a3)
{
int v4; // w1
__int64 v5; // x20
int v7; // w1
int v8; // w0
_BYTE *v9; // x23
unsigned __int64 v10; // x19
_BYTE *v11; // x19
int v13; // w1
unsigned __int8 *v14; // x19
unsigned int v15; // w0
unsigned int v16; // w21
_WORD *v17; // x0
int v18; // w4
int v19; // w3
__int16 v20; // w1
_BYTE *v21; // x0
__int16 v22; // w1
_BYTE *v23; // [xsp+40h] [xbp+40h] BYREF
char v24; // [xsp+48h] [xbp+48h]
void *v25; // [xsp+50h] [xbp+50h]
int v26; // [xsp+58h] [xbp+58h]
v4 = a1[295];
v5 = (__int64)a1;
if ( v4 )
{
if ( v4 != 1 )
{
v7 = v4 - 1;
a1[295] = v7;
if ( v7 != 1 )
goto LABEL_4;
png_warning((__int64)a1, "No space in chunk cache for sPLT");
a1 = (_DWORD *)v5;
}
png_crc_finish(a1, a3);
return;
}
LABEL_4:
v8 = a1[89];
if ( (v8 & 1) == 0 )
png_chunk_error(v5, "missing IHDR");
if ( (v8 & 4) != 0 )
{
png_crc_finish((_DWORD *)v5, a3);
png_chunk_benign_error(v5, "out of place");
return;
}
v9 = *(_BYTE **)(v5 + 1232);
v10 = a3 + 1;
if ( !v9 )
goto LABEL_26;
if ( v10 > *(_QWORD *)(v5 + 1240) )
{
*(_QWORD *)(v5 + 1232) = 0;
*(_QWORD *)(v5 + 1240) = 0;
png_free(v5, v9);
LABEL_26:
v21 = png_malloc_base(v5, a3 + 1);
v9 = v21;
if ( !v21 )
{
png_crc_finish((_DWORD *)v5, a3);
png_chunk_benign_error(v5, "out of memory");
return;
}
*(_QWORD *)(v5 + 1232) = v21;
*(_QWORD *)(v5 + 1240) = v10;
}
png_crc_read(v5, (__int64)v9, a3);
if ( !png_crc_finish((_DWORD *)v5, 0) )
{
v11 = v9;
v9[a3] = 0;
if ( *v9 )
{
while ( *++v11 )
;
}
if ( v11 + 1 > &v9[a3 - 2] )
{
png_warning(v5, "malformed sPLT chunk");
}
else
{
v13 = (unsigned __int8)v11[1];
v14 = v11 + 2;
if ( v13 == 8 )
v15 = 6;
else
v15 = 10;
v16 = a3 - ((_DWORD)v14 - (_DWORD)v9);
v24 = v13;
if ( v16 % v15 )
{
png_warning(v5, "sPLT chunk has bad length");
}
else
{
v26 = v16 / v15;
v17 = png_malloc_warn(v5, 10LL * (v16 / v15));
v25 = v17;
if ( v17 )
{
v18 = v26;
if ( v26 > 0 )
{
v19 = 0;
if ( v24 == 8 )
{
do
{
v22 = *v14;
v14 += 6;
*v17 = v22;
v17 += 5;
++v19;
*(v17 - 4) = *(v14 - 5);
*(v17 - 3) = *(v14 - 4);
*(v17 - 2) = *(v14 - 3);
*(v17 - 1) = (*(v14 - 2) << 8) + *(v14 - 1);
}
while ( v19 < v18 );
}
else
{
do
{
v20 = *v14;
v14 += 10;
v17 += 5;
++v19;
*(v17 - 5) = (v20 << 8) + *(v14 - 9);
*(v17 - 4) = (*(v14 - 8) << 8) + *(v14 - 7);
*(v17 - 3) = (*(v14 - 6) << 8) + *(v14 - 5);
*(v17 - 2) = (*(v14 - 4) << 8) + *(v14 - 3);
*(v17 - 1) = (*(v14 - 2) << 8) + *(v14 - 1);
}
while ( v19 < v18 );
}
}
v23 = v9;
png_set_sPLT(v5, a2, &v23, 1);
png_free(v5, v25);
}
else
{
png_warning(v5, "sPLT chunk requires too much memory");
}
}
}
}
}