//
// png_read_end from 0xbd57fc to 0xbd5cac (1200 bytes)
//
// 3 xrefs:
// > cocos2d::CCImage::_initWithPngData @ 0xb0c1d4
// > png_read_png @ 0xbd5fd4
// > ??> @ 0x967b0
//
// 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_read_end(__int64 result, __int64 a2)
{
__int64 v2; // x19
__int64 v4; // x20
unsigned int chunk_header; // w0
int v6; // w19
unsigned int v7; // w2
int v8; // w0
int v9; // w4
int v10; // w5
int v11; // w6
int v12; // w7
bool v13; // zf
int v14; // w19
int v15; // w19
char v16; // [xsp+0h] [xbp+0h]
size_t byte_count; // [xsp+38h] [xbp+38h]
v2 = result;
if ( result )
{
v4 = result;
if ( (unsigned int)png_chunk_unknown_handling(result, 1229209940) )
{
if ( *(_BYTE *)(v4 + 687) != 3 )
goto LABEL_4;
}
else
{
png_read_finish_IDAT(v2);
if ( *(_BYTE *)(v4 + 687) != 3 )
goto LABEL_4;
}
if ( *(_DWORD *)(v4 + 676) > (int)*(unsigned __int16 *)(v4 + 672) )
png_benign_error((_DWORD *)v4, "Read palette index exceeding num_palette");
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
LABEL_4:
while ( 1 )
{
chunk_header = png_read_chunk_header(v4);
v6 = *(_DWORD *)(v4 + 592);
v7 = chunk_header;
if ( v6 != 1229278788 )
break;
result = png_handle_IEND(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
}
if ( v6 != 1229472850 )
break;
result = png_handle_IHDR(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
}
if ( a2 )
break;
LABEL_38:
result = png_crc_finish(v4, v7);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
}
byte_count = chunk_header;
v8 = png_chunk_unknown_handling(v4, v6);
v7 = byte_count;
if ( v8 )
{
if ( v6 == 1229209940 )
{
if ( (_DWORD)byte_count || (*(_DWORD *)(v4 + 356) & 0x2000) != 0 )
png_benign_error((_DWORD *)v4, "Too many IDATs found");
result = png_handle_unknown(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
}
else
{
png_handle_unknown(v4, a2);
result = 1347179589;
v13 = v6 == 1347179589;
v14 = *(_DWORD *)(v4 + 356);
if ( v13 )
{
v15 = v14 | 2;
*(_DWORD *)(v4 + 356) = v15;
if ( (v15 & 0x10) != 0 )
return result;
}
else if ( (v14 & 0x10) != 0 )
{
return result;
}
}
}
else
{
switch ( v6 )
{
case 1229209940:
if ( (_DWORD)byte_count || (*(_DWORD *)(v4 + 356) & 0x2000) != 0 )
{
png_benign_error((_DWORD *)v4, "Too many IDATs found");
v7 = byte_count;
}
goto LABEL_38;
case 1347179589:
result = png_handle_PLTE(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1649100612:
result = png_handle_bKGD(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1665684045:
result = png_handle_cHRM(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1732332865:
result = png_handle_gAMA(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1749635924:
result = png_handle_hIST(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1866876531:
result = png_handle_oFFs(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1883455820:
result = png_handle_pCAL(v4);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1933787468:
result = png_handle_sCAL(v4, a2, byte_count, 0, v9, v10, v11, v12, v16);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1883789683:
result = png_handle_pHYs(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1933723988:
result = png_handle_sBIT(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1934772034:
result = png_handle_sRGB(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1766015824:
result = png_handle_iCCP(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1934642260:
result = png_handle_sPLT(v4);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1950701684:
result = png_handle_tEXt(v4);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1950960965:
result = png_handle_tIME(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1951551059:
result = png_handle_tRNS(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 2052348020:
result = png_handle_zTXt(v4, a2, byte_count, 0, v9, v10, v11, v12, v16);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
case 1767135348:
result = png_handle_iTXt(v4, a2, byte_count, 0, v9, v10, v11, v12, v16);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
default:
result = png_handle_unknown(v4, a2);
if ( (*(_DWORD *)(v4 + 356) & 0x10) != 0 )
return result;
break;
}
}
}
}
return result;
}