//
// png_handle_sBIT from 0x65cc10 to 0x65cd94 (388 bytes)
//
// 3 xrefs:
// > png_push_read_chunk @ 0x6529d8
// > png_read_info @ 0x6558e2
// > png_read_end @ 0x657396
//
// 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
//
int __fastcall png_handle_sBIT(int a1, int a2, unsigned int a3)
{
unsigned int v3; // r7
int v5; // r3
unsigned int v8; // r6
bool v9; // zf
bool v10; // zf
int result; // r0
char v12; // r2
char v13; // r1
_BOOL4 v14; // r3
_BOOL4 v15; // r3
_BOOL4 v16; // r3
int v17; // r7
char v18; // r0
char v19; // r3
int v20; // [sp+4h] [bp-8h] BYREF
v5 = *(_DWORD *)(a1 + 308);
if ( (v5 & 1) == 0 )
png_chunk_error(a1, "missing IHDR");
if ( (v5 & 6) != 0 )
{
png_crc_finish((_DWORD *)a1, a3);
return png_chunk_benign_error(a1, "out of place");
}
else if ( a2 && (*(_DWORD *)(a2 + 8) & 2) != 0 )
{
png_crc_finish((_DWORD *)a1, a3);
return png_chunk_benign_error(a1, "duplicate");
}
else
{
v8 = *(unsigned __int8 *)(a1 + 535);
v9 = v8 == 3;
if ( v8 == 3 )
v3 = 8;
else
v8 = *(unsigned __int8 *)(a1 + 539);
if ( !v9 )
v3 = *(unsigned __int8 *)(a1 + 536);
v10 = a3 == 4;
if ( a3 <= 4 )
v10 = a3 == v8;
if ( v10 )
{
v20 = (unsigned __int8)v3
| (unsigned __int16)((unsigned __int8)v3 << 8)
| ((unsigned __int8)v3 << 16) & 0xFFFFFF
| ((unsigned __int8)v3 << 24);
png_crc_read((_DWORD *)a1, (int)&v20, v8);
result = png_crc_finish((_DWORD *)a1, 0);
if ( !result )
{
v12 = v20;
v13 = BYTE1(v20);
if ( !v8 )
goto LABEL_33;
v14 = (unsigned __int8)v20 == 0;
if ( v3 < (unsigned __int8)v20 )
v14 = 1;
if ( v14 )
return png_chunk_benign_error(a1, "invalid");
v13 = BYTE1(v20);
if ( v8 <= 1 )
goto LABEL_33;
v15 = v3 < BYTE1(v20);
if ( !BYTE1(v20) )
v15 = 1;
if ( v15 )
return png_chunk_benign_error(a1, "invalid");
if ( v8 == 2 )
goto LABEL_33;
v16 = v3 < BYTE2(v20);
if ( !BYTE2(v20) )
v16 = 1;
if ( v16 )
return png_chunk_benign_error(a1, "invalid");
if ( v8 == 3 )
goto LABEL_33;
v17 = v3 < HIBYTE(v20);
if ( !HIBYTE(v20) )
v17 |= 1u;
if ( v17 )
{
return png_chunk_benign_error(a1, "invalid");
}
else
{
LABEL_33:
if ( (*(_BYTE *)(a1 + 535) & 2) != 0 )
{
v18 = BYTE2(v20);
v19 = HIBYTE(v20);
*(_BYTE *)(a1 + 616) = v20;
*(_BYTE *)(a1 + 617) = v13;
*(_BYTE *)(a1 + 618) = v18;
*(_BYTE *)(a1 + 620) = v19;
}
else
{
*(_BYTE *)(a1 + 619) = v20;
*(_BYTE *)(a1 + 616) = v12;
*(_BYTE *)(a1 + 617) = v12;
*(_BYTE *)(a1 + 618) = v12;
*(_BYTE *)(a1 + 620) = v13;
}
return png_set_sBIT(a1, a2, a1 + 616);
}
}
}
else
{
png_chunk_benign_error(a1, "invalid");
return png_crc_finish((_DWORD *)a1, a3);
}
}
return result;
}