//
// png_set_unknown_chunks from 0xbe4ae4 to 0xbe4ca0 (444 bytes)
//
// 2 xrefs:
// > png_handle_unknown @ 0xbe1d94
// > ??> @ 0x77da8
//
// 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
//
__int64 __fastcall png_set_unknown_chunks(__int64 result, __int64 a2, __int64 a3, int a4)
{
__int64 v4; // x26
__int64 v6; // x23
char *v8; // x27
__int64 v9; // x24
int v10; // w0
__int64 v11; // x20
char *v12; // x24
char v13; // w0
int v14; // w0
int i; // w1
size_t v16; // x1
void *v17; // x0
size_t v18; // x27
v4 = result;
v6 = a3;
if ( result && a2 && a4 > 0 && a3 )
{
v8 = png_realloc_array(result, *(const void **)(a2 + 288), *(_DWORD *)(a2 + 296), a4, 0x20u);
if ( v8 )
{
png_free(v4, *(void **)(a2 + 288));
v9 = *(int *)(a2 + 296);
v10 = *(_DWORD *)(a2 + 284);
*(_QWORD *)(a2 + 288) = v8;
v11 = v6 + 32 * ((unsigned int)(a4 - 1) + 1LL);
v12 = &v8[32 * v9];
*(_DWORD *)(a2 + 284) = v10 | 0x200;
while ( 1 )
{
v13 = *(_BYTE *)(v6 + 24);
*(_DWORD *)v12 = *(_DWORD *)v6;
v14 = v13 & 0xB;
v12[4] = 0;
if ( !v14 )
{
if ( (*(_DWORD *)(v4 + 356) & 0x8000) != 0
|| (png_app_warning(v4, "png_set_unknown_chunks now expects a valid location"),
(v14 = *(_BYTE *)(v4 + 356) & 0xB) == 0) )
{
png_error(v4, "invalid location in png_set_unknown_chunks");
}
}
for ( i = -v14 & v14; i != v14; i = -v14 & v14 )
v14 &= ~i;
v16 = *(_QWORD *)(v6 + 16);
v12[24] = v14;
if ( v16 )
{
v17 = png_malloc_base(v4, v16);
*((_QWORD *)v12 + 1) = v17;
if ( !v17 )
{
result = png_chunk_report(v4, "unknown chunk: out of memory", 1);
goto LABEL_16;
}
v18 = *(_QWORD *)(v6 + 16);
memcpy(v17, *(const void **)(v6 + 8), v18);
*((_QWORD *)v12 + 2) = v18;
}
else
{
*((_QWORD *)v12 + 1) = 0;
*((_QWORD *)v12 + 2) = 0;
}
v12 += 32;
result = (unsigned int)(*(_DWORD *)(a2 + 296) + 1);
*(_DWORD *)(a2 + 296) = result;
LABEL_16:
v6 += 32;
if ( v6 == v11 )
return result;
}
}
return png_chunk_report(v4, "too many unknown chunks", 1);
}
return result;
}