//
// _write_nolock from 0x18014034c to 0x18014062f (739 bytes)
//
// 2 xrefs:
// > _write @ 0x180140306
// > ??> @ 0x180203c14
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// 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 10:55:04 +0000
//
__int64 __fastcall write_nolock(int a1, _BYTE *a2, unsigned int a3)
{
int v3; // ebx
__int64 v4; // r14
__int64 v8; // r13
__int64 v9; // r15
__int64 v10; // rcx
int v11; // esi
_BYTE *v12; // r12
_WORD *v13; // r14
DWORD v14; // esi
__int64 v15; // rax
__int64 v16; // xmm0_8
__int64 v17; // rcx
void *v18; // rcx
DWORD NumberOfBytesWritten[2]; // [rsp+30h] [rbp-30h] BYREF
int v20; // [rsp+38h] [rbp-28h]
__int64 v21; // [rsp+40h] [rbp-20h]
DWORD Mode[4]; // [rsp+50h] [rbp-10h] BYREF
v3 = 0;
v4 = a3;
if ( !a3 )
return 0;
if ( !a2
|| (v8 = (__int64)a1 >> 6,
v9 = 9LL * (a1 & 0x3F),
v10 = qword_1801F5160[v8],
v11 = *(char *)(v10 + 72LL * (a1 & 0x3F) + 57),
(unsigned __int8)(*(_BYTE *)(v10 + 72LL * (a1 & 0x3F) + 57) - 1) <= 1u)
&& (a3 & 1) != 0 )
{
*_doserrno() = 0;
*errno() = 22;
invalid_parameter_noinfo();
return 0xFFFFFFFFLL;
}
if ( (*(_BYTE *)(v10 + 72LL * (a1 & 0x3F) + 56) & 0x20) != 0 )
common_lseek_nolock<__int64>((unsigned int)a1, 0, 2);
v21 = 0;
if ( !isatty(a1)
|| *(char *)(qword_1801F5160[v8] + 72LL * (a1 & 0x3F) + 56) >= 0
|| !*(_QWORD *)(*(_QWORD *)(_acrt_getptd() + 144) + 312LL)
&& !*(_BYTE *)(qword_1801F5160[v8] + 72LL * (a1 & 0x3F) + 57)
|| !GetConsoleMode(*(HANDLE *)(qword_1801F5160[v8] + 72LL * (a1 & 0x3F) + 40), Mode) )
{
v17 = qword_1801F5160[v8];
if ( *(char *)(v17 + 72LL * (a1 & 0x3F) + 56) >= 0 )
{
v18 = *(void **)(v17 + 72LL * (a1 & 0x3F) + 40);
*(_QWORD *)NumberOfBytesWritten = 0;
v20 = 0;
if ( !WriteFile(v18, a2, v4, &NumberOfBytesWritten[1], nullptr) )
NumberOfBytesWritten[0] = GetLastError();
v3 = v20;
LABEL_37:
v16 = *(_QWORD *)NumberOfBytesWritten;
goto LABEL_38;
}
if ( (_BYTE)v11 )
{
if ( v11 == 1 )
{
v15 = write_text_utf8_nolock((__int64)NumberOfBytesWritten, a1, (WCHAR *)a2, v4);
}
else
{
if ( v11 != 2 )
goto LABEL_39;
v15 = write_text_utf16le_nolock((__int64)NumberOfBytesWritten, a1, (__int16 *)a2, v4);
}
}
else
{
v15 = write_text_ansi_nolock((__int64)NumberOfBytesWritten, a1, a2, v4);
}
LABEL_26:
v16 = *(_QWORD *)v15;
v3 = *(_DWORD *)(v15 + 8);
LABEL_38:
v21 = v16;
goto LABEL_39;
}
if ( !(_BYTE)v11 )
{
v15 = (__int64)write_double_translated_ansi_nolock(NumberOfBytesWritten, a1, a2, v4);
goto LABEL_26;
}
if ( (unsigned __int8)(v11 - 1) <= 1u )
{
v12 = &a2[v4];
*(_QWORD *)NumberOfBytesWritten = 0;
v13 = a2;
if ( a2 < v12 )
{
v14 = NumberOfBytesWritten[1];
while ( 1 )
{
LOWORD(Mode[0]) = *v13;
if ( putwch_nolock(Mode[0]) != LOWORD(Mode[0]) )
break;
v14 += 2;
NumberOfBytesWritten[1] = v14;
if ( LOWORD(Mode[0]) == 10 )
{
if ( putwch_nolock(0xDu) != 13 )
break;
NumberOfBytesWritten[1] = ++v14;
++v3;
}
if ( ++v13 >= (_WORD *)v12 )
goto LABEL_37;
}
NumberOfBytesWritten[0] = GetLastError();
}
goto LABEL_37;
}
LABEL_39:
if ( HIDWORD(v21) )
return (unsigned int)(HIDWORD(v21) - v3);
if ( (_DWORD)v21 )
{
if ( (_DWORD)v21 == 5 )
{
*errno() = 9;
*_doserrno() = 5;
}
else
{
_acrt_errno_map_os_error(v21);
}
return 0xFFFFFFFFLL;
}
if ( (*(_BYTE *)(qword_1801F5160[v8] + 8 * v9 + 56) & 0x40) == 0 || *a2 != 26 )
{
*errno() = 28;
*_doserrno() = 0;
return 0xFFFFFFFFLL;
}
return 0;
}