//
// __dcrt_get_narrow_environment_from_os from 0x18013ac04 to 0x18013ad05 (257 bytes)
//
// 2 xrefs:
// > common_initialize_environment_nolock @ 0x180131e52
// > ??> @ 0x1802038b4
//
// 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
//
CHAR *_dcrt_get_narrow_environment_from_os()
{
LPWCH EnvironmentStringsW; // rax
WCHAR *v1; // rbx
char *v2; // rsi
__int64 v3; // rax
__int64 v4; // rsi
int v5; // eax
int v6; // ebp
CHAR *v7; // rax
CHAR *v8; // rdi
CHAR *v9; // rsi
EnvironmentStringsW = GetEnvironmentStringsW();
v1 = EnvironmentStringsW;
if ( !EnvironmentStringsW )
goto LABEL_12;
v2 = (char *)EnvironmentStringsW;
if ( *EnvironmentStringsW )
{
do
{
v3 = -1;
do
++v3;
while ( *(_WORD *)&v2[2 * v3] );
v2 += 2 * v3 + 2;
}
while ( *(_WORD *)v2 );
}
v4 = (v2 - (char *)v1 + 2) >> 1;
v5 = _acrt_WideCharToMultiByte(0, 0, v1, v4, nullptr, 0, nullptr, nullptr);
v6 = v5;
if ( v5 )
{
v7 = (CHAR *)malloc_base(v5);
v8 = v7;
if ( v7 && _acrt_WideCharToMultiByte(0, 0, v1, v4, v7, v6, nullptr, nullptr) )
{
v9 = v8;
v8 = nullptr;
}
else
{
v9 = nullptr;
}
free_base(v8);
}
else
{
LABEL_12:
v9 = nullptr;
}
if ( v1 )
FreeEnvironmentStringsW(v1);
return v9;
}