//
// sub_8C34C0 from 0x8c34c0 to 0x8c409c (3036 bytes)
//
// 2 xrefs:
// > TIFFReadDirectory @ 0x8c0afc
// > TIFFReadCustomDirectory @ 0x8c26d4
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 12:04:00 +0000
//
int __fastcall sub_8C34C0(const char **a1, __int64 a2, int *a3, _QWORD *a4)
{
__int64 v5; // r0
int v7; // r0
__int64 v8; // r0
__int64 v9; // r0
unsigned int v13; // [sp+1Ch] [bp-48h] BYREF
unsigned __int64 v14; // [sp+20h] [bp-44h] BYREF
unsigned int v15; // [sp+2Ch] [bp-38h] BYREF
unsigned __int64 v16; // [sp+30h] [bp-34h] BYREF
unsigned __int16 v17; // [sp+3Ah] [bp-2Ah] BYREF
_WORD *v18; // [sp+3Ch] [bp-28h]
int v19; // [sp+40h] [bp-24h]
int v20; // [sp+44h] [bp-20h]
_WORD *v21; // [sp+48h] [bp-1Ch]
int v22; // [sp+4Ch] [bp-18h]
unsigned __int16 i; // [sp+52h] [bp-12h]
int v24; // [sp+54h] [bp-10h]
int v25; // [sp+58h] [bp-Ch]
int v26; // [sp+5Ch] [bp-8h]
if ( !a3 )
_assert2();
*((_QWORD *)a1 + 2) = a2;
if ( a4 )
*a4 = 0;
if ( ((unsigned int)a1[3] & 0x800) != 0 )
{
v25 = (int)a1[4];
if ( v25 != *((_QWORD *)a1 + 2) )
{
LABEL_39:
TIFFErrorExt(a1[157], "TIFFFetchDirectory", "Can not read TIFF directory count");
return 0;
}
if ( ((unsigned int)a1[3] & 0x80000) != 0 )
{
v26 = v25 + 8;
if ( v25 + 8 <= v25 || v26 <= 7 || (int)a1[154] < v26 )
goto LABEL_39;
TIFFmemcpy(&v14, &a1[153][v25], 8);
v25 += 8;
if ( ((unsigned int)a1[3] & 0x80) != 0 )
TIFFSwabLong8(&v14);
if ( v14 > 0x1000 )
{
TIFFErrorExt(
a1[157],
"TIFFFetchDirectory",
"Sanity check on directory count failed, this is probably not a valid IFD offset");
return 0;
}
v17 = v14;
v19 = 20;
}
else
{
v24 = v25 + 2;
if ( v25 + 2 <= v25 || v24 <= 1 || (int)a1[154] < v24 )
goto LABEL_39;
TIFFmemcpy(&v17, &a1[153][v25], 2);
v25 += 2;
if ( ((unsigned int)a1[3] & 0x80) != 0 )
TIFFSwabShort(&v17);
if ( v17 > 0x1000u )
goto LABEL_14;
v19 = 12;
}
if ( !v17 )
{
TIFFErrorExt(
a1[157],
"TIFFFetchDirectory",
"Sanity check on directory count failed, zero tag directories not supported");
return 0;
}
v18 = (_WORD *)TIFFCheckMalloc(a1, v17, v19, "to read TIFF directory");
if ( !v18 )
return 0;
v24 = v19 * v17 + v25;
if ( v24 < v25 || v19 * v17 > v24 || (int)a1[154] < v24 )
{
TIFFErrorExt(a1[157], "TIFFFetchDirectory", "Can not read TIFF directory");
TIFFfree(v18);
return 0;
}
TIFFmemcpy(v18, &a1[153][v25], v19 * v17);
if ( a4 )
{
v25 += v19 * v17;
if ( ((unsigned int)a1[3] & 0x80000) != 0 )
{
v24 = v25 + 8;
if ( v25 + 8 > v25 && v24 > 7 && (int)a1[154] >= v24 )
TIFFmemcpy(a4, &a1[153][v25], 8);
else
*a4 = 0;
if ( ((unsigned int)a1[3] & 0x80) != 0 )
TIFFSwabLong8(a4);
}
else
{
v24 = v25 + 4;
if ( v25 + 4 > v25 && v24 > 3 && (int)a1[154] >= v24 )
TIFFmemcpy(&v13, &a1[153][v25], 4);
else
v13 = 0;
if ( ((unsigned int)a1[3] & 0x80) != 0 )
TIFFSwabLong(&v13);
*a4 = v13;
}
}
goto LABEL_83;
}
LODWORD(v5) = ((int (__fastcall *)(const char *, const char *, const char *, const char *, _DWORD))a1[160])(
a1[157],
a1[160],
a1[4],
a1[5],
0);
if ( v5 != *((_QWORD *)a1 + 2) )
{
TIFFErrorExt(a1[157], "TIFFFetchDirectory", "%s: Seek error accessing TIFF directory", *a1);
return 0;
}
if ( ((unsigned int)a1[3] & 0x80000) != 0 )
{
if ( ((int (__fastcall *)(const char *, unsigned __int64 *, int))a1[158])(a1[157], &v16, 8) != 8 )
{
TIFFErrorExt(a1[157], "TIFFFetchDirectory", "%s: Can not read TIFF directory count", *a1);
return 0;
}
if ( ((unsigned int)a1[3] & 0x80) != 0 )
TIFFSwabLong8(&v16);
if ( v16 > 0x1000 )
{
TIFFErrorExt(
a1[157],
"TIFFFetchDirectory",
"Sanity check on directory count failed, this is probably not a valid IFD offset");
return 0;
}
v17 = v16;
v19 = 20;
}
else
{
if ( ((int (__fastcall *)(const char *, unsigned __int16 *, int))a1[158])(a1[157], &v17, 2) != 2 )
{
TIFFErrorExt(a1[157], "TIFFFetchDirectory", "%s: Can not read TIFF directory count", *a1);
return 0;
}
if ( ((unsigned int)a1[3] & 0x80) != 0 )
TIFFSwabShort(&v17);
if ( v17 > 0x1000u )
{
LABEL_14:
TIFFErrorExt(
a1[157],
"TIFFFetchDirectory",
"Sanity check on directory count failed, this is probably not a valid IFD offset");
return 0;
}
v19 = 12;
}
v18 = (_WORD *)TIFFCheckMalloc(a1, v17, v19, "to read TIFF directory");
if ( !v18 )
return 0;
v7 = ((int (__fastcall *)(const char *, _WORD *, int))a1[158])(a1[157], v18, v19 * v17);
if ( v7 != v19 * v17 )
{
TIFFErrorExt(a1[157], "TIFFFetchDirectory", "%.100s: Can not read TIFF directory", *a1);
TIFFfree(v18);
return 0;
}
if ( a4 )
{
if ( ((unsigned int)a1[3] & 0x80000) != 0 )
{
if ( ((int (__fastcall *)(const char *, _QWORD *, int))a1[158])(a1[157], a4, 8) != 8 )
*a4 = 0;
if ( ((unsigned int)a1[3] & 0x80) != 0 )
TIFFSwabLong8(a4);
}
else
{
if ( ((int (__fastcall *)(const char *, unsigned int *, int))a1[158])(a1[157], &v15, 4) != 4 )
v15 = 0;
if ( ((unsigned int)a1[3] & 0x80) != 0 )
TIFFSwabLong(&v15);
*a4 = v15;
}
}
LABEL_83:
v20 = TIFFCheckMalloc(a1, v17, 24, "to read TIFF directory");
if ( v20 )
{
v21 = v18;
v22 = v20;
for ( i = 0; i < (unsigned int)v17; ++i )
{
if ( ((unsigned int)a1[3] & 0x80) != 0 )
TIFFSwabShort(v21);
*(_WORD *)v22 = *v21++;
if ( ((unsigned int)a1[3] & 0x80) != 0 )
TIFFSwabShort(v21);
*(_WORD *)(v22 + 2) = *v21++;
if ( ((unsigned int)a1[3] & 0x80000) != 0 )
{
if ( ((unsigned int)a1[3] & 0x80) != 0 )
TIFFSwabLong8(v21);
v8 = sub_8B9620((int)v21);
*(_QWORD *)(v22 + 8) = v8;
v21 += 4;
v9 = sub_8B9620((int)v21);
*(_QWORD *)(v22 + 16) = v9;
v21 += 4;
}
else
{
if ( ((unsigned int)a1[3] & 0x80) != 0 )
TIFFSwabLong(v21);
*(_QWORD *)(v22 + 8) = *(unsigned int *)v21;
v21 += 2;
*(_DWORD *)(v22 + 16) = *(_DWORD *)v21;
v21 += 2;
}
v22 += 24;
}
TIFFfree(v18);
*a3 = v20;
return v17;
}
else
{
TIFFfree(v18);
return 0;
}
}