//
// png_handle_sPLT from 0x86d524 to 0x86d73a (534 bytes)
//
// 3 xrefs:
// > png_push_read_chunk @ 0x862b0c
// > png_read_info @ 0x865986
// > png_read_end @ 0x8674b6
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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 12:02:55 +0000
//
void __fastcall png_handle_sPLT(_DWORD *a1, int a2, unsigned int a3)
{
_DWORD *v3; // r5
int v4; // r3
int v7; // r3
int v8; // r3
_BYTE *v9; // r8
unsigned int v10; // r4
_BYTE *v11; // r3
unsigned __int8 *v13; // r4
unsigned int v14; // r7
unsigned int v15; // r10
int v16; // r9
char *v17; // r0
int v18; // r7
unsigned __int8 *v19; // r1
char *v20; // r3
_BYTE *v21; // r0
_BYTE *v22; // [sp+0h] [bp-10h] BYREF
char v23; // [sp+4h] [bp-Ch]
char *v24; // [sp+8h] [bp-8h]
int v25; // [sp+Ch] [bp-4h]
v3 = a1;
v4 = a1[214];
if ( v4 )
{
if ( v4 != 1 )
{
v7 = v4 - 1;
a1[214] = v7;
if ( v7 != 1 )
goto LABEL_4;
png_warning((int)a1, "No space in chunk cache for sPLT");
a1 = v3;
}
png_crc_finish(a1, a3);
return;
}
LABEL_4:
v8 = a1[77];
if ( (v8 & 1) == 0 )
png_chunk_error((int)a1, "missing IHDR");
if ( (v8 & 4) != 0 )
{
png_crc_finish(a1, a3);
png_chunk_benign_error((int)v3, "out of place");
return;
}
v9 = (_BYTE *)a1[222];
v10 = a3 + 1;
if ( !v9 )
goto LABEL_31;
if ( v10 > a1[223] )
{
a1[222] = 0;
a1[223] = 0;
png_free((int)a1, v9);
LABEL_31:
v21 = png_malloc_base((int)v3, a3 + 1);
v9 = v21;
if ( !v21 )
{
png_crc_finish(v3, a3);
png_chunk_benign_error((int)v3, "out of memory");
return;
}
v3[222] = v21;
v3[223] = v10;
}
png_crc_read(v3, (int)v9, a3);
if ( !png_crc_finish(v3, 0) )
{
v9[a3] = 0;
if ( *v9 )
{
v11 = v9;
while ( *++v11 )
;
}
else
{
v11 = v9;
}
if ( v11 + 1 > &v9[a3 - 2] )
{
png_warning((int)v3, "malformed sPLT chunk");
}
else
{
v13 = v11 + 2;
v14 = a3 + v9 - (v11 + 2);
v23 = v11[1];
if ( v23 == 8 )
v15 = 6;
else
v15 = 10;
v16 = v14 % v15;
if ( v14 % v15 )
{
png_warning((int)v3, "sPLT chunk has bad length");
}
else if ( v14 / v15 > 0x19999999 )
{
png_warning((int)v3, "sPLT chunk too long");
}
else
{
v25 = v14 / v15;
v17 = (char *)png_malloc_warn((int)v3, 10 * (v14 / v15));
v24 = v17;
if ( v17 )
{
if ( v25 > 0 )
{
v18 = 0;
while ( 1 )
{
v20 = &v17[v16];
if ( v23 == 8 )
{
v19 = v13 + 4;
*(_WORD *)&v17[v16] = *v13;
*((_WORD *)v20 + 1) = v13[1];
*((_WORD *)v20 + 2) = v13[2];
*((_WORD *)v20 + 3) = v13[3];
}
else
{
v19 = v13 + 8;
*(_WORD *)&v17[v16] = v13[1] + (*v13 << 8);
*((_WORD *)v20 + 1) = v13[3] + (v13[2] << 8);
*((_WORD *)v20 + 2) = v13[5] + (v13[4] << 8);
*((_WORD *)v20 + 3) = v13[7] + (v13[6] << 8);
}
++v18;
v16 += 10;
v13 = v19 + 2;
*((_WORD *)v20 + 4) = v19[1] + (*v19 << 8);
if ( v25 <= v18 )
break;
v17 = v24;
}
}
v22 = v9;
((void (__fastcall *)(_DWORD *, int, _BYTE **, int))png_set_sPLT)(v3, a2, &v22, 1);
png_free((int)v3, v24);
}
else
{
png_warning((int)v3, "sPLT chunk requires too much memory");
}
}
}
}
}