//
// png_push_read_chunk from 0x6526cc to 0x652bea (1310 bytes)
//
// 1 xrefs:
// > png_process_some_data @ 0x653206
//
// 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
//
void __fastcall png_push_read_chunk(_DWORD *a1, int a2)
{
int v3; // r3
int v4; // r4
int v5; // r5
int v6; // r3
int v7; // r3
unsigned int v8; // r1
unsigned int v9; // r3
int v10; // r3
unsigned int v11; // r2
int v12; // r3
bool v13; // cc
unsigned int v14; // r3
size_t v15; // r2
char v16[4]; // [sp+0h] [bp-8h] BYREF
unsigned int v17; // [sp+4h] [bp-4h] BYREF
v3 = a1[77];
v4 = (int)a1;
if ( (v3 & 0x100) == 0 )
{
if ( a1[174] <= 7u )
{
LABEL_14:
png_push_save_buffer((int)a1);
return;
}
png_push_fill_buffer(a1, v16, 4u);
*(_DWORD *)(v4 + 680) = png_get_uint_31(v4, v16);
png_reset_crc(v4);
png_crc_read(v4, &v17, 4);
*(_DWORD *)(v4 + 476) = _byteswap_ulong(v17);
png_check_chunk_name(v4);
v3 = *(_DWORD *)(v4 + 308) | 0x100;
*(_DWORD *)(v4 + 308) = v3;
}
v5 = *(_DWORD *)(v4 + 476);
if ( v5 != 1229209940 )
{
if ( v5 == 1229472850 )
{
if ( *(_DWORD *)(v4 + 680) != 13 )
png_error(v4, "Invalid IHDR length");
if ( *(_DWORD *)(v4 + 696) > 0x10u )
{
png_handle_IHDR(v4, a2);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
goto LABEL_13;
}
if ( v5 == 1229278788 )
{
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_IEND(v4, a2);
*(_DWORD *)(v4 + 704) = 6;
png_push_have_end(v4);
v6 = *(_DWORD *)(v4 + 308);
LABEL_9:
*(_DWORD *)(v4 + 308) = v6 & 0xFFFFFEFF;
return;
}
goto LABEL_13;
}
if ( !png_chunk_unknown_handling(v4, *(_DWORD *)(v4 + 476)) )
{
if ( v5 == 1347179589 )
{
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_PLTE(v4, a2);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
}
else
{
v7 = *(_DWORD *)(v4 + 476);
switch ( v7 )
{
case 1732332865:
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_gAMA(v4, a2);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
break;
case 1933723988:
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_sBIT(v4, a2);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
break;
case 1665684045:
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_cHRM(v4, a2);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
break;
default:
if ( v5 == 1934772034 )
{
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_sRGB(v4, a2);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
}
else if ( v7 == 1766015824 )
{
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_iCCP(v4, a2);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
}
else
{
switch ( v5 )
{
case 1934642260:
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_sPLT(v4);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
break;
case 1951551059:
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_tRNS(v4, a2);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
break;
case 1649100612:
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_bKGD(v4, a2);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
break;
case 1749635924:
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_hIST(v4, a2);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
break;
case 1883789683:
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_pHYs(v4, a2);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
break;
case 1866876531:
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_oFFs(v4, a2);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
break;
case 1883455820:
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_pCAL(v4);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
break;
case 1933787468:
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_sCAL(v4);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
break;
case 1950960965:
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_tIME(v4, a2);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
break;
case 1950701684:
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_tEXt(v4);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
break;
case 2052348020:
v15 = *(_DWORD *)(v4 + 680);
if ( v15 + 4 <= *(_DWORD *)(v4 + 696) )
{
png_handle_zTXt(v4, a2, v15);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
break;
default:
v8 = *(_DWORD *)(v4 + 680) + 4;
v9 = *(_DWORD *)(v4 + 696);
if ( v5 == 1767135348 )
{
if ( v8 <= v9 )
{
png_handle_iTXt(v4);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
}
else if ( v8 <= v9 )
{
png_handle_unknown(v4, a2);
v6 = *(_DWORD *)(v4 + 308);
goto LABEL_9;
}
break;
}
}
break;
}
}
goto LABEL_13;
}
LABEL_51:
if ( (unsigned int)(*(_DWORD *)(v4 + 680) + 4) <= *(_DWORD *)(v4 + 696) )
{
png_handle_unknown(v4, a2);
v6 = *(_DWORD *)(v4 + 308);
if ( v5 == 1347179589 )
v6 |= 2u;
goto LABEL_9;
}
LABEL_13:
a1 = (_DWORD *)v4;
goto LABEL_14;
}
if ( (v3 & 8) != 0 )
{
v3 |= 0x2000u;
*(_DWORD *)(v4 + 308) = v3;
}
if ( (v3 & 1) == 0 )
png_error(v4, "Missing IHDR before IDAT");
if ( *(_BYTE *)(v4 + 535) == 3 && (v3 & 2) == 0 )
png_error(v4, "Missing PLTE before IDAT");
*(_DWORD *)(v4 + 704) = 2;
*(_DWORD *)(v4 + 308) = v3 | 4;
if ( (v3 & 0x2000) != 0 || *(_DWORD *)(v4 + 680) )
{
if ( (v3 & 8) != 0 )
png_benign_error((_DWORD *)v4, "Too many IDATs found");
if ( png_chunk_unknown_handling(v4, 1229209940) )
goto LABEL_51;
v10 = *(_DWORD *)(v4 + 680);
*(_DWORD *)(v4 + 704) = 2;
*(_DWORD *)(v4 + 508) = v10;
png_push_have_info(v4);
v11 = *(unsigned __int8 *)(v4 + 538);
v12 = *(_DWORD *)(v4 + 468);
v13 = v11 > 7;
if ( v11 <= 7 )
v12 *= v11;
else
v11 >>= 3;
if ( v13 )
v14 = v12 * v11;
else
v14 = (unsigned int)(v12 + 7) >> 3;
*(_DWORD *)(v4 + 336) = *(_DWORD *)(v4 + 484);
*(_DWORD *)(v4 + 340) = v14 + 1;
}
}