//
// copy_environment from 0x18013b3ec to 0x18013b4d1 (229 bytes)
//
// 3 xrefs:
// > common_set_variable_in_environment_nolock @ 0x18013ae1e
// > common_set_variable_in_environment_nolock @ 0x18013ae6e
// > ??> @ 0x1802038e4
//
// 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:02 +0000
//
_BYTE *__fastcall copy_environment(const char **a1)
{
const char **v1; // rdi
__int64 v3; // rcx
const char **i; // rax
_BYTE *v5; // rbx
const char *v6; // rax
signed __int64 v7; // r14
__int64 v8; // rsi
char *v9; // rcx
v1 = a1;
if ( !a1 )
return nullptr;
v3 = 0;
for ( i = v1; *i; ++i )
++v3;
v5 = calloc_base(v3 + 1, 8u);
if ( !v5 )
LABEL_15:
abort();
v6 = *v1;
if ( *v1 )
{
v7 = v5 - (_BYTE *)v1;
do
{
v8 = -1;
do
++v8;
while ( v6[v8] );
*(const char **)((char *)v1 + v7) = (const char *)calloc_base(v8 + 1, 1u);
free_base(nullptr);
v9 = *(char **)((char *)v1 + v7);
if ( !v9 )
goto LABEL_15;
if ( strcpy_s(v9, v8 + 1, *v1) )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
v6 = *++v1;
}
while ( *v1 );
}
free_base(nullptr);
return v5;
}