//
// png_handle_sBIT from 0xbdf6c4 to 0xbdf8b4 (496 bytes)
//
// 4 xrefs:
// > png_push_read_chunk @ 0xbcf708
// > png_read_info @ 0xbd3664
// > png_read_end @ 0xbd5b54
// > ??> @ 0x37d70
//
// 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_handle_sBIT(__int64 a1, __int64 a2, unsigned int a3)
{
int v4; // w1
unsigned int v6; // w20
unsigned int v7; // w22
__int64 result; // x0
unsigned __int8 v9; // w0
unsigned __int8 v10; // w0
unsigned __int8 v12; // [xsp+48h] [xbp+48h] BYREF
unsigned __int8 v13; // [xsp+49h] [xbp+49h]
unsigned __int8 v14; // [xsp+4Ah] [xbp+4Ah]
unsigned __int8 v15; // [xsp+4Bh] [xbp+4Bh]
v4 = *(_DWORD *)(a1 + 356);
if ( (v4 & 1) == 0 )
png_chunk_error(a1, "missing IHDR");
if ( (v4 & 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
{
v6 = *(unsigned __int8 *)(a1 + 687);
if ( v6 == 3 )
{
v7 = 8;
}
else
{
v6 = *(unsigned __int8 *)(a1 + 691);
v7 = *(unsigned __int8 *)(a1 + 688);
}
if ( a3 == v6 && a3 <= 4 )
{
v15 = v7;
v14 = v7;
v12 = v7;
v13 = v7;
png_crc_read(a1, (__int64)&v12, v6);
result = png_crc_finish((_DWORD *)a1, 0);
if ( !(_DWORD)result )
{
v9 = v12;
if ( !v6
|| v7 >= v12
&& v12
&& (v6 <= 1 || v13 && v7 >= v13 && (v6 == 2 || v14 && v7 >= v14 && (v6 == 3 || v15 && v7 >= v15))) )
{
if ( (*(_BYTE *)(a1 + 687) & 2) != 0 )
{
*(_BYTE *)(a1 + 800) = v12;
*(_BYTE *)(a1 + 801) = v13;
*(_BYTE *)(a1 + 802) = v14;
v10 = v15;
}
else
{
*(_BYTE *)(a1 + 803) = v12;
*(_BYTE *)(a1 + 800) = v9;
*(_BYTE *)(a1 + 801) = v9;
*(_BYTE *)(a1 + 802) = v9;
v10 = v13;
}
*(_BYTE *)(a1 + 804) = v10;
return png_set_sBIT(a1, a2, a1 + 800);
}
else
{
return png_chunk_benign_error(a1, "invalid");
}
}
}
else
{
png_chunk_benign_error(a1, "invalid");
return png_crc_finish((_DWORD *)a1, a3);
}
}
return result;
}