2003-05-08 05:47:00 +02:00
|
|
|
/*
|
|
|
|
* Ntdll environment functions
|
|
|
|
*
|
|
|
|
* Copyright 1996, 1998 Alexandre Julliard
|
|
|
|
* Copyright 2003 Eric Pouech
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-05-08 05:47:00 +02:00
|
|
|
*/
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
2003-09-06 01:08:26 +02:00
|
|
|
#include <stdarg.h>
|
2003-05-08 05:47:00 +02:00
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2003-09-06 01:08:26 +02:00
|
|
|
#include "windef.h"
|
2003-05-08 05:47:00 +02:00
|
|
|
#include "winternl.h"
|
|
|
|
#include "wine/unicode.h"
|
|
|
|
#include "wine/debug.h"
|
|
|
|
#include "ntdll_misc.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(environ);
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* RtlCreateEnvironment [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlCreateEnvironment(BOOLEAN inherit, PWSTR* env)
|
|
|
|
{
|
|
|
|
NTSTATUS nts;
|
|
|
|
|
|
|
|
TRACE("(%u,%p)!\n", inherit, env);
|
|
|
|
|
|
|
|
if (inherit)
|
|
|
|
{
|
|
|
|
MEMORY_BASIC_INFORMATION mbi;
|
|
|
|
|
|
|
|
RtlAcquirePebLock();
|
|
|
|
|
2004-03-12 02:59:35 +01:00
|
|
|
nts = NtQueryVirtualMemory(NtCurrentProcess(),
|
|
|
|
NtCurrentTeb()->Peb->ProcessParameters->Environment,
|
2003-05-08 05:47:00 +02:00
|
|
|
0, &mbi, sizeof(mbi), NULL);
|
|
|
|
if (nts == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
*env = NULL;
|
|
|
|
nts = NtAllocateVirtualMemory(NtCurrentProcess(), (void**)env, 0, &mbi.RegionSize,
|
|
|
|
MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
|
|
|
if (nts == STATUS_SUCCESS)
|
2004-03-12 02:59:35 +01:00
|
|
|
memcpy(*env, NtCurrentTeb()->Peb->ProcessParameters->Environment, mbi.RegionSize);
|
2003-05-08 05:47:00 +02:00
|
|
|
else *env = NULL;
|
|
|
|
}
|
|
|
|
RtlReleasePebLock();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-09-12 12:36:06 +02:00
|
|
|
SIZE_T size = 1;
|
2004-10-11 22:59:06 +02:00
|
|
|
PVOID addr = NULL;
|
|
|
|
nts = NtAllocateVirtualMemory(NtCurrentProcess(), &addr, 0, &size,
|
2003-05-08 05:47:00 +02:00
|
|
|
MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
2004-10-11 22:59:06 +02:00
|
|
|
if (nts == STATUS_SUCCESS) *env = addr;
|
2003-05-08 05:47:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nts;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* RtlDestroyEnvironment [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlDestroyEnvironment(PWSTR env)
|
|
|
|
{
|
2005-09-12 12:36:06 +02:00
|
|
|
SIZE_T size = 0;
|
2003-05-08 05:47:00 +02:00
|
|
|
|
|
|
|
TRACE("(%p)!\n", env);
|
|
|
|
|
|
|
|
return NtFreeVirtualMemory(NtCurrentProcess(), (void**)&env, &size, MEM_RELEASE);
|
|
|
|
}
|
|
|
|
|
2003-05-13 06:45:50 +02:00
|
|
|
static LPCWSTR ENV_FindVariable(PCWSTR var, PCWSTR name, unsigned namelen)
|
|
|
|
{
|
|
|
|
for (; *var; var += strlenW(var) + 1)
|
|
|
|
{
|
|
|
|
/* match var names, but avoid setting a var with a name including a '='
|
|
|
|
* (a starting '=' is valid though)
|
|
|
|
*/
|
|
|
|
if (strncmpiW(var, name, namelen) == 0 && var[namelen] == '=' &&
|
|
|
|
strchrW(var + 1, '=') == var + namelen)
|
|
|
|
{
|
|
|
|
return var + namelen + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-05-08 05:47:00 +02:00
|
|
|
/******************************************************************
|
|
|
|
* RtlQueryEnvironmentVariable_U [NTDLL.@]
|
|
|
|
*
|
2003-05-13 06:45:50 +02:00
|
|
|
* NOTES: when the buffer is too small, the string is not written, but if the
|
|
|
|
* terminating null char is the only char that cannot be written, then
|
|
|
|
* all chars (except the null) are written and success is returned
|
|
|
|
* (behavior of Win2k at least)
|
2003-05-08 05:47:00 +02:00
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlQueryEnvironmentVariable_U(PWSTR env,
|
|
|
|
PUNICODE_STRING name,
|
|
|
|
PUNICODE_STRING value)
|
|
|
|
{
|
|
|
|
NTSTATUS nts = STATUS_VARIABLE_NOT_FOUND;
|
2003-05-13 06:45:50 +02:00
|
|
|
PCWSTR var;
|
|
|
|
unsigned namelen;
|
2003-05-08 05:47:00 +02:00
|
|
|
|
2005-07-10 19:44:37 +02:00
|
|
|
TRACE("%p %s %p\n", env, debugstr_us(name), value);
|
2003-05-08 05:47:00 +02:00
|
|
|
|
|
|
|
value->Length = 0;
|
|
|
|
namelen = name->Length / sizeof(WCHAR);
|
|
|
|
if (!namelen) return nts;
|
|
|
|
|
|
|
|
if (!env)
|
|
|
|
{
|
|
|
|
RtlAcquirePebLock();
|
2004-03-12 02:59:35 +01:00
|
|
|
var = NtCurrentTeb()->Peb->ProcessParameters->Environment;
|
2003-05-08 05:47:00 +02:00
|
|
|
}
|
|
|
|
else var = env;
|
|
|
|
|
2003-05-13 06:45:50 +02:00
|
|
|
var = ENV_FindVariable(var, name->Buffer, namelen);
|
|
|
|
if (var != NULL)
|
2003-05-08 05:47:00 +02:00
|
|
|
{
|
2003-05-13 06:45:50 +02:00
|
|
|
value->Length = strlenW(var) * sizeof(WCHAR);
|
2003-06-18 05:23:22 +02:00
|
|
|
|
2003-05-13 06:45:50 +02:00
|
|
|
if (value->Length <= value->MaximumLength)
|
2003-05-08 05:47:00 +02:00
|
|
|
{
|
2003-05-13 06:45:50 +02:00
|
|
|
memmove(value->Buffer, var, min(value->Length + sizeof(WCHAR), value->MaximumLength));
|
|
|
|
nts = STATUS_SUCCESS;
|
2003-05-08 05:47:00 +02:00
|
|
|
}
|
2003-05-13 06:45:50 +02:00
|
|
|
else nts = STATUS_BUFFER_TOO_SMALL;
|
2003-05-08 05:47:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!env) RtlReleasePebLock();
|
|
|
|
|
|
|
|
return nts;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* RtlSetCurrentEnvironment [NTDLL.@]
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void WINAPI RtlSetCurrentEnvironment(PWSTR new_env, PWSTR* old_env)
|
|
|
|
{
|
|
|
|
TRACE("(%p %p)\n", new_env, old_env);
|
|
|
|
|
|
|
|
RtlAcquirePebLock();
|
|
|
|
|
2004-03-12 02:59:35 +01:00
|
|
|
if (old_env) *old_env = NtCurrentTeb()->Peb->ProcessParameters->Environment;
|
|
|
|
NtCurrentTeb()->Peb->ProcessParameters->Environment = new_env;
|
2003-05-08 05:47:00 +02:00
|
|
|
|
|
|
|
RtlReleasePebLock();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* RtlSetEnvironmentVariable [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlSetEnvironmentVariable(PWSTR* penv, PUNICODE_STRING name,
|
|
|
|
PUNICODE_STRING value)
|
|
|
|
{
|
|
|
|
INT len, old_size;
|
|
|
|
LPWSTR p, env;
|
|
|
|
NTSTATUS nts = STATUS_VARIABLE_NOT_FOUND;
|
|
|
|
MEMORY_BASIC_INFORMATION mbi;
|
|
|
|
|
2005-07-10 19:44:37 +02:00
|
|
|
TRACE("(%p, %s, %s)\n", penv, debugstr_us(name), debugstr_us(value));
|
2003-05-08 05:47:00 +02:00
|
|
|
|
2004-05-05 03:39:12 +02:00
|
|
|
if (!name || !name->Buffer || !name->Length)
|
2003-05-08 05:47:00 +02:00
|
|
|
return STATUS_INVALID_PARAMETER_1;
|
2004-05-05 03:39:12 +02:00
|
|
|
|
|
|
|
len = name->Length / sizeof(WCHAR);
|
|
|
|
|
2003-05-08 05:47:00 +02:00
|
|
|
/* variable names can't contain a '=' except as a first character */
|
2004-05-05 03:39:12 +02:00
|
|
|
for (p = name->Buffer + 1; p < name->Buffer + len; p++)
|
|
|
|
if (*p == '=') return STATUS_INVALID_PARAMETER;
|
2003-05-08 05:47:00 +02:00
|
|
|
|
|
|
|
if (!penv)
|
|
|
|
{
|
|
|
|
RtlAcquirePebLock();
|
2004-03-12 02:59:35 +01:00
|
|
|
env = NtCurrentTeb()->Peb->ProcessParameters->Environment;
|
2003-05-08 05:47:00 +02:00
|
|
|
} else env = *penv;
|
|
|
|
|
|
|
|
/* compute current size of environment */
|
|
|
|
for (p = env; *p; p += strlenW(p) + 1);
|
|
|
|
old_size = p + 1 - env;
|
|
|
|
|
|
|
|
/* Find a place to insert the string */
|
|
|
|
for (p = env; *p; p += strlenW(p) + 1)
|
|
|
|
{
|
|
|
|
if (!strncmpiW(name->Buffer, p, len) && (p[len] == '=')) break;
|
|
|
|
}
|
|
|
|
if (!value && !*p) goto done; /* Value to remove doesn't exist */
|
|
|
|
|
|
|
|
/* Realloc the buffer */
|
|
|
|
len = value ? len + value->Length / sizeof(WCHAR) + 2 : 0;
|
|
|
|
if (*p) len -= strlenW(p) + 1; /* The name already exists */
|
|
|
|
|
|
|
|
if (len < 0)
|
|
|
|
{
|
|
|
|
LPWSTR next = p + strlenW(p) + 1; /* We know there is a next one */
|
|
|
|
memmove(next + len, next, (old_size - (next - env)) * sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
|
|
|
|
nts = NtQueryVirtualMemory(NtCurrentProcess(), env, 0,
|
|
|
|
&mbi, sizeof(mbi), NULL);
|
|
|
|
if (nts != STATUS_SUCCESS) goto done;
|
|
|
|
|
|
|
|
if ((old_size + len) * sizeof(WCHAR) > mbi.RegionSize)
|
|
|
|
{
|
|
|
|
LPWSTR new_env;
|
2005-09-12 12:36:06 +02:00
|
|
|
SIZE_T new_size = (old_size + len) * sizeof(WCHAR);
|
2003-05-08 05:47:00 +02:00
|
|
|
|
|
|
|
new_env = NULL;
|
|
|
|
nts = NtAllocateVirtualMemory(NtCurrentProcess(), (void**)&new_env, 0,
|
|
|
|
&new_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
|
|
|
if (nts != STATUS_SUCCESS) goto done;
|
|
|
|
|
|
|
|
memmove(new_env, env, (p - env) * sizeof(WCHAR));
|
|
|
|
assert(len > 0);
|
|
|
|
memmove(new_env + (p - env) + len, p, (old_size - (p - env)) * sizeof(WCHAR));
|
|
|
|
p = new_env + (p - env);
|
|
|
|
|
|
|
|
RtlDestroyEnvironment(env);
|
2004-03-12 02:59:35 +01:00
|
|
|
if (!penv) NtCurrentTeb()->Peb->ProcessParameters->Environment = new_env;
|
2003-05-08 05:47:00 +02:00
|
|
|
else *penv = new_env;
|
|
|
|
env = new_env;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (len > 0) memmove(p + len, p, (old_size - (p - env)) * sizeof(WCHAR));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the new string */
|
|
|
|
if (value)
|
|
|
|
{
|
2004-05-05 03:39:12 +02:00
|
|
|
memcpy( p, name->Buffer, name->Length );
|
|
|
|
p += name->Length / sizeof(WCHAR);
|
|
|
|
*p++ = '=';
|
|
|
|
memcpy( p, value->Buffer, value->Length );
|
|
|
|
p[value->Length / sizeof(WCHAR)] = 0;
|
2003-05-08 05:47:00 +02:00
|
|
|
}
|
|
|
|
done:
|
|
|
|
if (!penv) RtlReleasePebLock();
|
|
|
|
|
|
|
|
return nts;
|
|
|
|
}
|
|
|
|
|
2003-05-13 06:45:50 +02:00
|
|
|
/******************************************************************
|
|
|
|
* RtlExpandEnvironmentStrings_U (NTDLL.@)
|
|
|
|
*
|
|
|
|
*/
|
2007-06-22 20:48:12 +02:00
|
|
|
NTSTATUS WINAPI RtlExpandEnvironmentStrings_U(PCWSTR renv, const UNICODE_STRING* us_src,
|
2003-05-13 06:45:50 +02:00
|
|
|
PUNICODE_STRING us_dst, PULONG plen)
|
|
|
|
{
|
2004-11-29 19:24:08 +01:00
|
|
|
DWORD src_len, len, count, total_size = 1; /* 1 for terminating '\0' */
|
2003-06-18 05:23:22 +02:00
|
|
|
LPCWSTR env, src, p, var;
|
2003-05-13 06:45:50 +02:00
|
|
|
LPWSTR dst;
|
|
|
|
|
|
|
|
src = us_src->Buffer;
|
2004-11-29 19:24:08 +01:00
|
|
|
src_len = us_src->Length / sizeof(WCHAR);
|
2003-05-13 06:45:50 +02:00
|
|
|
count = us_dst->MaximumLength / sizeof(WCHAR);
|
|
|
|
dst = count ? us_dst->Buffer : NULL;
|
|
|
|
|
2003-06-18 05:23:22 +02:00
|
|
|
if (!renv)
|
|
|
|
{
|
|
|
|
RtlAcquirePebLock();
|
2004-03-12 02:59:35 +01:00
|
|
|
env = NtCurrentTeb()->Peb->ProcessParameters->Environment;
|
2003-06-18 05:23:22 +02:00
|
|
|
}
|
|
|
|
else env = renv;
|
2003-05-13 06:45:50 +02:00
|
|
|
|
2004-11-29 19:24:08 +01:00
|
|
|
while (src_len)
|
2003-05-13 06:45:50 +02:00
|
|
|
{
|
|
|
|
if (*src != '%')
|
|
|
|
{
|
2004-11-29 19:24:08 +01:00
|
|
|
if ((p = memchrW( src, '%', src_len ))) len = p - src;
|
|
|
|
else len = src_len;
|
2003-05-13 06:45:50 +02:00
|
|
|
var = src;
|
|
|
|
src += len;
|
2004-11-29 19:24:08 +01:00
|
|
|
src_len -= len;
|
2003-05-13 06:45:50 +02:00
|
|
|
}
|
|
|
|
else /* we are at the start of a variable */
|
|
|
|
{
|
2004-11-29 19:24:08 +01:00
|
|
|
if ((p = memchrW( src + 1, '%', src_len - 1 )))
|
2003-05-13 06:45:50 +02:00
|
|
|
{
|
|
|
|
len = p - src - 1; /* Length of the variable name */
|
|
|
|
if ((var = ENV_FindVariable( env, src + 1, len )))
|
|
|
|
{
|
|
|
|
src += len + 2; /* Skip the variable name */
|
2004-11-29 19:24:08 +01:00
|
|
|
src_len -= len + 2;
|
2003-05-13 06:45:50 +02:00
|
|
|
len = strlenW(var);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
var = src; /* Copy original name instead */
|
|
|
|
len += 2;
|
|
|
|
src += len;
|
2004-11-29 19:24:08 +01:00
|
|
|
src_len -= len;
|
2003-05-13 06:45:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* unfinished variable name, ignore it */
|
|
|
|
{
|
|
|
|
var = src;
|
2004-11-29 19:24:08 +01:00
|
|
|
len = src_len; /* Copy whole string */
|
2003-05-13 06:45:50 +02:00
|
|
|
src += len;
|
2004-11-29 19:24:08 +01:00
|
|
|
src_len = 0;
|
2003-05-13 06:45:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
total_size += len;
|
|
|
|
if (dst)
|
|
|
|
{
|
|
|
|
if (count < len) len = count;
|
|
|
|
memcpy(dst, var, len * sizeof(WCHAR));
|
|
|
|
count -= len;
|
|
|
|
dst += len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-06-18 05:23:22 +02:00
|
|
|
if (!renv) RtlReleasePebLock();
|
2003-05-13 06:45:50 +02:00
|
|
|
|
|
|
|
/* Null-terminate the string */
|
|
|
|
if (dst && count) *dst = '\0';
|
|
|
|
|
2003-06-18 05:23:22 +02:00
|
|
|
us_dst->Length = (dst) ? (dst - us_dst->Buffer) * sizeof(WCHAR) : 0;
|
2003-05-13 06:45:50 +02:00
|
|
|
if (plen) *plen = total_size * sizeof(WCHAR);
|
|
|
|
|
|
|
|
return (count) ? STATUS_SUCCESS : STATUS_BUFFER_TOO_SMALL;
|
|
|
|
}
|
|
|
|
|
2003-10-04 05:11:57 +02:00
|
|
|
|
|
|
|
static inline void normalize( void *base, WCHAR **ptr )
|
|
|
|
{
|
|
|
|
if (*ptr) *ptr = (WCHAR *)((char *)base + (UINT_PTR)*ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* RtlNormalizeProcessParams [NTDLL.@]
|
|
|
|
*/
|
|
|
|
PRTL_USER_PROCESS_PARAMETERS WINAPI RtlNormalizeProcessParams( RTL_USER_PROCESS_PARAMETERS *params )
|
|
|
|
{
|
|
|
|
if (params && !(params->Flags & PROCESS_PARAMS_FLAG_NORMALIZED))
|
|
|
|
{
|
2004-04-16 07:00:46 +02:00
|
|
|
normalize( params, ¶ms->CurrentDirectory.DosPath.Buffer );
|
2003-10-04 05:11:57 +02:00
|
|
|
normalize( params, ¶ms->DllPath.Buffer );
|
|
|
|
normalize( params, ¶ms->ImagePathName.Buffer );
|
|
|
|
normalize( params, ¶ms->CommandLine.Buffer );
|
|
|
|
normalize( params, ¶ms->WindowTitle.Buffer );
|
|
|
|
normalize( params, ¶ms->Desktop.Buffer );
|
|
|
|
normalize( params, ¶ms->ShellInfo.Buffer );
|
|
|
|
normalize( params, ¶ms->RuntimeInfo.Buffer );
|
|
|
|
params->Flags |= PROCESS_PARAMS_FLAG_NORMALIZED;
|
|
|
|
}
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-06-22 20:48:12 +02:00
|
|
|
static inline void denormalize( const void *base, WCHAR **ptr )
|
2003-10-04 05:11:57 +02:00
|
|
|
{
|
2007-06-22 20:48:12 +02:00
|
|
|
if (*ptr) *ptr = (WCHAR *)(UINT_PTR)((char *)*ptr - (const char *)base);
|
2003-10-04 05:11:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* RtlDeNormalizeProcessParams [NTDLL.@]
|
|
|
|
*/
|
|
|
|
PRTL_USER_PROCESS_PARAMETERS WINAPI RtlDeNormalizeProcessParams( RTL_USER_PROCESS_PARAMETERS *params )
|
|
|
|
{
|
|
|
|
if (params && (params->Flags & PROCESS_PARAMS_FLAG_NORMALIZED))
|
|
|
|
{
|
2004-04-16 07:00:46 +02:00
|
|
|
denormalize( params, ¶ms->CurrentDirectory.DosPath.Buffer );
|
2003-10-04 05:11:57 +02:00
|
|
|
denormalize( params, ¶ms->DllPath.Buffer );
|
|
|
|
denormalize( params, ¶ms->ImagePathName.Buffer );
|
|
|
|
denormalize( params, ¶ms->CommandLine.Buffer );
|
|
|
|
denormalize( params, ¶ms->WindowTitle.Buffer );
|
|
|
|
denormalize( params, ¶ms->Desktop.Buffer );
|
|
|
|
denormalize( params, ¶ms->ShellInfo.Buffer );
|
|
|
|
denormalize( params, ¶ms->RuntimeInfo.Buffer );
|
|
|
|
params->Flags &= ~PROCESS_PARAMS_FLAG_NORMALIZED;
|
|
|
|
}
|
|
|
|
return params;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* append a unicode string to the process params data; helper for RtlCreateProcessParameters */
|
|
|
|
static void append_unicode_string( void **data, const UNICODE_STRING *src,
|
|
|
|
UNICODE_STRING *dst )
|
|
|
|
{
|
|
|
|
dst->Length = src->Length;
|
|
|
|
dst->MaximumLength = src->MaximumLength;
|
|
|
|
dst->Buffer = *data;
|
|
|
|
memcpy( dst->Buffer, src->Buffer, dst->MaximumLength );
|
|
|
|
*data = (char *)dst->Buffer + dst->MaximumLength;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* RtlCreateProcessParameters [NTDLL.@]
|
|
|
|
*/
|
|
|
|
NTSTATUS WINAPI RtlCreateProcessParameters( RTL_USER_PROCESS_PARAMETERS **result,
|
|
|
|
const UNICODE_STRING *ImagePathName,
|
|
|
|
const UNICODE_STRING *DllPath,
|
|
|
|
const UNICODE_STRING *CurrentDirectoryName,
|
|
|
|
const UNICODE_STRING *CommandLine,
|
|
|
|
PWSTR Environment,
|
|
|
|
const UNICODE_STRING *WindowTitle,
|
|
|
|
const UNICODE_STRING *Desktop,
|
|
|
|
const UNICODE_STRING *ShellInfo,
|
|
|
|
const UNICODE_STRING *RuntimeInfo )
|
|
|
|
{
|
2006-09-19 22:44:40 +02:00
|
|
|
static WCHAR empty[] = {0};
|
|
|
|
static const UNICODE_STRING empty_str = { 0, sizeof(empty), empty };
|
2004-10-25 23:47:23 +02:00
|
|
|
static const UNICODE_STRING null_str = { 0, 0, NULL };
|
2003-10-04 05:11:57 +02:00
|
|
|
|
|
|
|
const RTL_USER_PROCESS_PARAMETERS *cur_params;
|
2005-09-12 12:36:06 +02:00
|
|
|
SIZE_T size, total_size;
|
2003-10-04 05:11:57 +02:00
|
|
|
void *ptr;
|
|
|
|
NTSTATUS status;
|
|
|
|
|
|
|
|
RtlAcquirePebLock();
|
|
|
|
cur_params = NtCurrentTeb()->Peb->ProcessParameters;
|
|
|
|
if (!DllPath) DllPath = &cur_params->DllPath;
|
2004-04-16 07:00:46 +02:00
|
|
|
if (!CurrentDirectoryName) CurrentDirectoryName = &cur_params->CurrentDirectory.DosPath;
|
2003-10-04 05:11:57 +02:00
|
|
|
if (!CommandLine) CommandLine = ImagePathName;
|
|
|
|
if (!Environment) Environment = cur_params->Environment;
|
|
|
|
if (!WindowTitle) WindowTitle = &empty_str;
|
|
|
|
if (!Desktop) Desktop = &empty_str;
|
|
|
|
if (!ShellInfo) ShellInfo = &empty_str;
|
2004-10-25 23:47:23 +02:00
|
|
|
if (!RuntimeInfo) RuntimeInfo = &null_str;
|
2003-10-04 05:11:57 +02:00
|
|
|
|
|
|
|
size = (sizeof(RTL_USER_PROCESS_PARAMETERS)
|
|
|
|
+ ImagePathName->MaximumLength
|
|
|
|
+ DllPath->MaximumLength
|
|
|
|
+ CurrentDirectoryName->MaximumLength
|
|
|
|
+ CommandLine->MaximumLength
|
|
|
|
+ WindowTitle->MaximumLength
|
|
|
|
+ Desktop->MaximumLength
|
|
|
|
+ ShellInfo->MaximumLength
|
|
|
|
+ RuntimeInfo->MaximumLength);
|
|
|
|
|
|
|
|
total_size = size;
|
2004-10-11 22:59:06 +02:00
|
|
|
ptr = NULL;
|
|
|
|
if ((status = NtAllocateVirtualMemory( NtCurrentProcess(), &ptr, 0, &total_size,
|
2003-10-04 05:11:57 +02:00
|
|
|
MEM_COMMIT, PAGE_READWRITE )) == STATUS_SUCCESS)
|
|
|
|
{
|
|
|
|
RTL_USER_PROCESS_PARAMETERS *params = ptr;
|
|
|
|
params->AllocationSize = total_size;
|
|
|
|
params->Size = size;
|
|
|
|
params->Flags = PROCESS_PARAMS_FLAG_NORMALIZED;
|
2004-09-08 03:25:05 +02:00
|
|
|
params->ConsoleFlags = cur_params->ConsoleFlags;
|
2003-10-04 05:11:57 +02:00
|
|
|
params->Environment = Environment;
|
|
|
|
/* all other fields are zero */
|
|
|
|
|
|
|
|
ptr = params + 1;
|
2004-04-16 07:00:46 +02:00
|
|
|
append_unicode_string( &ptr, CurrentDirectoryName, ¶ms->CurrentDirectory.DosPath );
|
2003-10-04 05:11:57 +02:00
|
|
|
append_unicode_string( &ptr, DllPath, ¶ms->DllPath );
|
|
|
|
append_unicode_string( &ptr, ImagePathName, ¶ms->ImagePathName );
|
|
|
|
append_unicode_string( &ptr, CommandLine, ¶ms->CommandLine );
|
|
|
|
append_unicode_string( &ptr, WindowTitle, ¶ms->WindowTitle );
|
|
|
|
append_unicode_string( &ptr, Desktop, ¶ms->Desktop );
|
|
|
|
append_unicode_string( &ptr, ShellInfo, ¶ms->ShellInfo );
|
|
|
|
append_unicode_string( &ptr, RuntimeInfo, ¶ms->RuntimeInfo );
|
|
|
|
*result = RtlDeNormalizeProcessParams( params );
|
|
|
|
}
|
|
|
|
RtlReleasePebLock();
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* RtlDestroyProcessParameters [NTDLL.@]
|
|
|
|
*/
|
|
|
|
void WINAPI RtlDestroyProcessParameters( RTL_USER_PROCESS_PARAMETERS *params )
|
|
|
|
{
|
|
|
|
void *ptr = params;
|
2005-09-12 12:36:06 +02:00
|
|
|
SIZE_T size = 0;
|
2003-10-04 05:11:57 +02:00
|
|
|
NtFreeVirtualMemory( NtCurrentProcess(), &ptr, &size, MEM_RELEASE );
|
|
|
|
}
|