--- trunk/reactos/lib/kernel32/process/create.c 2005-04-02 19:26:54 UTC (rev 14453)
+++ trunk/reactos/lib/kernel32/process/create.c 2005-04-02 19:33:08 UTC (rev 14454)
@@ -27,74 +27,69 @@
typedef NTSTATUS STDCALL (K32_MBSTR_TO_WCSTR)
(
- UNICODE_STRING *,
- ANSI_STRING *,
- BOOLEAN
+ UNICODE_STRING *,
+ ANSI_STRING *,
+ BOOLEAN
);
-NTSTATUS STDCALL K32MbStrToWcStr
-(
- IN K32_MBSTR_TO_WCSTR * True,
- UNICODE_STRING * DestStr,
- ANSI_STRING * SourceStr,
- BOOLEAN Allocate
-)
+NTSTATUS STDCALL K32MbStrToWcStr(IN K32_MBSTR_TO_WCSTR * True,
+ UNICODE_STRING * DestStr,
+ ANSI_STRING * SourceStr,
+ BOOLEAN Allocate)
{
- if(SourceStr->Buffer == NULL)
- {
- DestStr->Length = DestStr->MaximumLength = 0;
- DestStr->Buffer = NULL;
- return STATUS_SUCCESS;
- }
+ if(SourceStr->Buffer == NULL)
+ {
+ DestStr->Length = DestStr->MaximumLength = 0;
+ DestStr->Buffer = NULL;
+ return STATUS_SUCCESS;
+ }
- return True(DestStr, SourceStr, Allocate);
+ return True(DestStr, SourceStr, Allocate);
}
-VOID STDCALL RtlRosR32AttribsToNativeAttribs
-(
- OUT OBJECT_ATTRIBUTES * NativeAttribs,
- IN SECURITY_ATTRIBUTES * Ros32Attribs OPTIONAL
-)
+VOID STDCALL RtlRosR32AttribsToNativeAttribs(OUT OBJECT_ATTRIBUTES * NativeAttribs,
+ IN SECURITY_ATTRIBUTES * Ros32Attribs OPTIONAL)
{
- NativeAttribs->Length = sizeof(*NativeAttribs);
- NativeAttribs->ObjectName = NULL;
- NativeAttribs->RootDirectory = NULL;
- NativeAttribs->Attributes = 0;
- NativeAttribs->SecurityQualityOfService = NULL;
+ NativeAttribs->Length = sizeof(*NativeAttribs);
+ NativeAttribs->ObjectName = NULL;
+ NativeAttribs->RootDirectory = NULL;
+ NativeAttribs->Attributes = 0;
+ NativeAttribs->SecurityQualityOfService = NULL;
- if(Ros32Attribs != NULL && Ros32Attribs->nLength >= sizeof(*Ros32Attribs))
- {
- NativeAttribs->SecurityDescriptor = Ros32Attribs->lpSecurityDescriptor;
+ if(Ros32Attribs != NULL && Ros32Attribs->nLength >= sizeof(*Ros32Attribs))
+ {
+ NativeAttribs->SecurityDescriptor = Ros32Attribs->lpSecurityDescriptor;
- if(Ros32Attribs->bInheritHandle)
- NativeAttribs->Attributes |= OBJ_INHERIT;
- }
- else
- NativeAttribs->SecurityDescriptor = NULL;
+ if(Ros32Attribs->bInheritHandle)
+ {
+ NativeAttribs->Attributes |= OBJ_INHERIT;
+ }
+ }
+ else
+ {
+ NativeAttribs->SecurityDescriptor = NULL;
+ }
}
-VOID STDCALL RtlRosR32AttribsToNativeAttribsNamed
-(
- OUT OBJECT_ATTRIBUTES * NativeAttribs,
- IN SECURITY_ATTRIBUTES * Ros32Attribs OPTIONAL,
- OUT UNICODE_STRING * NativeName OPTIONAL,
- IN WCHAR * Ros32Name OPTIONAL,
- IN HANDLE Ros32NameRoot OPTIONAL
-)
+VOID STDCALL RtlRosR32AttribsToNativeAttribsNamed(OUT OBJECT_ATTRIBUTES * NativeAttribs,
+ IN SECURITY_ATTRIBUTES * Ros32Attribs OPTIONAL,
+ OUT UNICODE_STRING * NativeName OPTIONAL,
+ IN WCHAR * Ros32Name OPTIONAL,
+ IN HANDLE Ros32NameRoot OPTIONAL)
{
- if(!NativeAttribs) return;
+ if(!NativeAttribs) return;
- RtlRosR32AttribsToNativeAttribs(NativeAttribs, Ros32Attribs);
+ RtlRosR32AttribsToNativeAttribs(NativeAttribs, Ros32Attribs);
- if(Ros32Name != NULL && NativeName != NULL)
- {
- RtlInitUnicodeString(NativeName, Ros32Name);
+ if(Ros32Name != NULL && NativeName != NULL)
+ {
+ RtlInitUnicodeString(NativeName, Ros32Name);
- NativeAttribs->ObjectName = NativeName;
- NativeAttribs->RootDirectory = Ros32NameRoot;
- NativeAttribs->Attributes |= OBJ_CASE_INSENSITIVE;
- }
+ NativeAttribs->ObjectName = NativeName;
+ NativeAttribs->RootDirectory = Ros32NameRoot;
+ NativeAttribs->Attributes |= OBJ_CASE_INSENSITIVE;
+ }
}
@@ -144,12 +139,9 @@
BOOL bRetVal;
STARTUPINFOW wsiStartupInfo;
- NTSTATUS STDCALL_FUNC (*pTrue)
- (
- UNICODE_STRING *,
- ANSI_STRING *,
- BOOLEAN
- );
+ NTSTATUS STDCALL_FUNC (*pTrue)(UNICODE_STRING *,
+ ANSI_STRING *,
+ BOOLEAN);
ULONG STDCALL_FUNC (*pRtlMbStringToUnicodeSize)(ANSI_STRING *);
@@ -318,9 +310,13 @@
/* translate EXCEPTION_XXX defines into EXCEPTION_DISPOSITION enum values */
if (ExceptionDisposition == EXCEPTION_CONTINUE_EXECUTION)
- return ExceptionContinueExecution;
+ {
+ return ExceptionContinueExecution;
+ }
else if (ExceptionDisposition == EXCEPTION_CONTINUE_SEARCH)
- return ExceptionContinueSearch;
+ {
+ return ExceptionContinueSearch;
+ }
return -1; /* unknown return from UnhandledExceptionFilter */
}
@@ -343,102 +339,93 @@
}
-HANDLE STDCALL KlCreateFirstThread
-(
- HANDLE ProcessHandle,
- LPSECURITY_ATTRIBUTES lpThreadAttributes,
- PSECTION_IMAGE_INFORMATION Sii,
- LPTHREAD_START_ROUTINE lpStartAddress,
- DWORD dwCreationFlags,
- LPDWORD lpThreadId
-)
+HANDLE STDCALL KlCreateFirstThread(HANDLE ProcessHandle,
+ LPSECURITY_ATTRIBUTES lpThreadAttributes,
+ PSECTION_IMAGE_INFORMATION Sii,
+ LPTHREAD_START_ROUTINE lpStartAddress,
+ DWORD dwCreationFlags,
+ LPDWORD lpThreadId)
{
- OBJECT_ATTRIBUTES oaThreadAttribs;
- CLIENT_ID cidClientId;
- PVOID pTrueStartAddress;
- NTSTATUS nErrCode;
- HANDLE hThread;
+ OBJECT_ATTRIBUTES oaThreadAttribs;
+ CLIENT_ID cidClientId;
+ PVOID pTrueStartAddress;
+ NTSTATUS nErrCode;
+ HANDLE hThread;
- /* convert the thread attributes */
- RtlRosR32AttribsToNativeAttribs(&oaThreadAttribs, lpThreadAttributes);
+ /* convert the thread attributes */
+ RtlRosR32AttribsToNativeAttribs(&oaThreadAttribs, lpThreadAttributes);
- /* native image */
- if(Sii->Subsystem != IMAGE_SUBSYSTEM_NATIVE)
- pTrueStartAddress = (PVOID)BaseProcessStart;
- /* Win32 image */
- else
- pTrueStartAddress = (PVOID)RtlBaseProcessStartRoutine;
+ /* native image */
+ if(Sii->Subsystem != IMAGE_SUBSYSTEM_NATIVE)
+ {
+ pTrueStartAddress = (PVOID)BaseProcessStart;
+ }
+ /* Win32 image */
+ else
+ {
+ pTrueStartAddress = (PVOID)RtlBaseProcessStartRoutine;
+ }
- DPRINT
- (
- "RtlRosCreateUserThreadVa\n"
- "(\n"
- " ProcessHandle %p,\n"
- " ObjectAttributes %p,\n"
- " CreateSuspended %d,\n"
- " StackZeroBits %d,\n"
- " StackReserve %lu,\n"
- " StackCommit %lu,\n"
- " StartAddress %p,\n"
- " ThreadHandle %p,\n"
- " ClientId %p,\n"
- " ParameterCount %u,\n"
- " Parameters[0] %p,\n"
- " Parameters[1] %p\n"
- ")\n",
- ProcessHandle,
- &oaThreadAttribs,
- dwCreationFlags & CREATE_SUSPENDED,
- 0,
- Sii->StackReserve,
- Sii->StackCommit,
- pTrueStartAddress,
- &hThread,
- &cidClientId,
- 2,
- lpStartAddress,
- PEB_BASE
- );
+ DPRINT("RtlRosCreateUserThreadVa\n"
+ "(\n"
+ " ProcessHandle %p,\n"
+ " ObjectAttributes %p,\n"
+ " CreateSuspended %d,\n"
+ " StackZeroBits %d,\n"
+ " StackReserve %lu,\n"
+ " StackCommit %lu,\n"
+ " StartAddress %p,\n"
+ " ThreadHandle %p,\n"
+ " ClientId %p,\n"
+ " ParameterCount %u,\n"
+ " Parameters[0] %p,\n"
+ " Parameters[1] %p\n"
+ ")\n",
+ ProcessHandle,
+ &oaThreadAttribs,
+ dwCreationFlags & CREATE_SUSPENDED,
+ 0,
+ Sii->StackReserve,
+ Sii->StackCommit,
+ pTrueStartAddress,
+ &hThread,
+ &cidClientId,
+ 2,
+ lpStartAddress,
+ PEB_BASE);
- /* create the first thread */
- nErrCode = RtlRosCreateUserThreadVa
- (
- ProcessHandle,
- &oaThreadAttribs,
- dwCreationFlags & CREATE_SUSPENDED,
- 0,
- &(Sii->StackReserve),
- &(Sii->StackCommit),
- pTrueStartAddress,
- &hThread,
- &cidClientId,
- 2,
- (ULONG_PTR)lpStartAddress,
- (ULONG_PTR)PEB_BASE
- );
-
- /* failure */
- if(!NT_SUCCESS(nErrCode))
- {
- SetLastErrorByStatus(nErrCode);
- return NULL;
- }
+ /* create the first thread */
+ nErrCode = RtlRosCreateUserThreadVa(ProcessHandle,
+ &oaThreadAttribs,
+ dwCreationFlags & CREATE_SUSPENDED,
+ 0,
+ &(Sii->StackReserve),
+ &(Sii->StackCommit),
+ pTrueStartAddress,
+ &hThread,
+ &cidClientId,
+ 2,
+ (ULONG_PTR)lpStartAddress,
+ (ULONG_PTR)PEB_BASE);
+ /* failure */
+ if(!NT_SUCCESS(nErrCode))
+ {
+ SetLastErrorByStatus(nErrCode);
+ return NULL;
+ }
- DPRINT
- (
- "StackReserve %p\n"
- "StackCommit %p\n"
- "ThreadHandle %p\n"
- "ClientId.UniqueThread %p\n",
- Sii->StackReserve,
- Sii->StackCommit,
- hThread,
- cidClientId.UniqueThread
- );
+ DPRINT("StackReserve %p\n"
+ "StackCommit %p\n"
+ "ThreadHandle %p\n"
+ "ClientId.UniqueThread %p\n",
+ Sii->StackReserve,
+ Sii->StackCommit,
+ hThread,
+ cidClientId.UniqueThread);
- /* success */
- if(lpThreadId) *lpThreadId = (DWORD)cidClientId.UniqueThread;
- return hThread;
+ /* success */
+ if(lpThreadId) *lpThreadId = (DWORD)cidClientId.UniqueThread;
+ return hThread;
}
HANDLE KlMapFile(LPCWSTR lpApplicationName)
@@ -476,20 +463,20 @@
*/
Status = NtOpenFile(&hFile,
- SYNCHRONIZE|FILE_EXECUTE|FILE_READ_DATA,
- &ObjectAttributes,
- &IoStatusBlock,
- FILE_SHARE_DELETE|FILE_SHARE_READ,
- FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE);
+ SYNCHRONIZE|FILE_EXECUTE|FILE_READ_DATA,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ FILE_SHARE_DELETE|FILE_SHARE_READ,
+ FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE);
RtlFreeUnicodeString (&ApplicationNameString);
if (!NT_SUCCESS(Status))
- {
- DPRINT("Failed to open file\n");
- SetLastErrorByStatus (Status);
- return(NULL);
- }
+ {
+ DPRINT("Failed to open file\n");
+ SetLastErrorByStatus (Status);
+ return(NULL);
+ }
Status = NtCreateSection(&hSection,
SECTION_ALL_ACCESS,
@@ -501,32 +488,29 @@
NtClose(hFile);
if (!NT_SUCCESS(Status))
- {
- DPRINT("Failed to create section\n");
- SetLastErrorByStatus (Status);
- return(NULL);
- }
+ {
+ DPRINT("Failed to create section\n");
+ SetLastErrorByStatus (Status);
+ return(NULL);
+ }
return(hSection);
}
-static NTSTATUS KlInitPeb
-(
- HANDLE ProcessHandle,
- PRTL_USER_PROCESS_PARAMETERS Ppb,
- PVOID * ImageBaseAddress,
- ULONG ImageSubSystem
-)
+static NTSTATUS KlInitPeb(HANDLE ProcessHandle,
+ PRTL_USER_PROCESS_PARAMETERS Ppb,
+ PVOID * ImageBaseAddress,
+ ULONG ImageSubSystem)
{
- NTSTATUS Status;
- PVOID PpbBase;
- ULONG PpbSize;
- ULONG BytesWritten;
- ULONG Offset;
- PVOID ParentEnv = NULL;
- PVOID EnvPtr = NULL;
- PWCHAR ptr;
- ULONG EnvSize = 0, EnvSize1 = 0;
+ NTSTATUS Status;
+ PVOID PpbBase;
+ ULONG PpbSize;
+ ULONG BytesWritten;
+ ULONG Offset;
+ PVOID ParentEnv = NULL;
+ PVOID EnvPtr = NULL;
+ PWCHAR ptr;
+ ULONG EnvSize = 0, EnvSize1 = 0;
/* create the Environment */
if (Ppb->Environment != NULL)
@@ -535,7 +519,7 @@
ptr = ParentEnv;
while (*ptr)
{
- while(*ptr++);
+ while(*ptr++);
}
ptr++;
EnvSize = (PVOID)ptr - ParentEnv;
@@ -545,41 +529,41 @@
MEMORY_BASIC_INFORMATION MemInfo;
ParentEnv = NtCurrentPeb()->ProcessParameters->Environment;
- Status = NtQueryVirtualMemory (NtCurrentProcess (),
- ParentEnv,
- MemoryBasicInformation,
- &MemInfo,
- sizeof(MEMORY_BASIC_INFORMATION),
- NULL);
- if (!NT_SUCCESS(Status))
- {
- return Status;
- }
- EnvSize = MemInfo.RegionSize;
- }
+ Status = NtQueryVirtualMemory (NtCurrentProcess (),
+ ParentEnv,
+ MemoryBasicInformation,
+ &MemInfo,
+ sizeof(MEMORY_BASIC_INFORMATION),
+ NULL);
+ if (!NT_SUCCESS(Status))
+ {
+ return Status;
+ }
+ EnvSize = MemInfo.RegionSize;
+ }
DPRINT("EnvironmentSize %ld\n", EnvSize);
/* allocate and initialize new environment block */
if (EnvSize != 0)
- {
- EnvSize1 = EnvSize;
- Status = NtAllocateVirtualMemory(ProcessHandle,
- &EnvPtr,
- 0,
- &EnvSize1,
- MEM_RESERVE | MEM_COMMIT,
- PAGE_READWRITE);
- if (!NT_SUCCESS(Status))
- {
- return(Status);
- }
+ {
+ EnvSize1 = EnvSize;
+ Status = NtAllocateVirtualMemory(ProcessHandle,
+ &EnvPtr,
+ 0,
+ &EnvSize1,
+ MEM_RESERVE | MEM_COMMIT,
+ PAGE_READWRITE);
+ if (!NT_SUCCESS(Status))
+ {
+ return(Status);
+ }
- NtWriteVirtualMemory(ProcessHandle,
- EnvPtr,
- ParentEnv,
- EnvSize,
- &BytesWritten);
- }
+ NtWriteVirtualMemory(ProcessHandle,
+ EnvPtr,
+ ParentEnv,
+ EnvSize,
+ &BytesWritten);
+ }
/* create the PPB */
PpbBase = NULL;
@@ -591,9 +575,9 @@
MEM_RESERVE | MEM_COMMIT,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
- {
- return(Status);
- }
+ {
+ return(Status);
+ }
//DPRINT("Ppb->MaximumLength %x\n", Ppb->MaximumLength);
NtWriteVirtualMemory(ProcessHandle,
@@ -651,102 +635,102 @@
GetFileName(LPCWSTR CurDir, LPCWSTR AppName, LPWSTR CmdLine, LPWSTR Buffer,
unsigned BufLen)
{
- WCHAR *Name, *Pos, *Ret = NULL;
- const WCHAR *p;
+ WCHAR *Name, *Pos, *Ret = NULL;
+ const WCHAR *p;
- /* if we have an app name, everything is easy */
+ /* if we have an app name, everything is easy */
- if (NULL != AppName)
- {
+ if (NULL != AppName)
+ {
/* use the unmodified app name as file name */
wcsncpy(Buffer, AppName, BufLen );
Ret = CmdLine;
if (NULL == Ret || L'\0' == CmdLine[0])
- {
- /* no command-line, create one */
- Ret = RtlAllocateHeap(GetProcessHeap(), 0, (wcslen(AppName) + 3) * sizeof(WCHAR));
- if (NULL != Ret)
- {
- Ret[0] = L'"';
- wcscpy(Ret + 1, AppName);
- wcscat(Ret, L"\"");
- }
- }
- return Ret;
- }
+ {
+ /* no command-line, create one */
+ Ret = RtlAllocateHeap(GetProcessHeap(), 0, (wcslen(AppName) + 3) * sizeof(WCHAR));
+ if (NULL != Ret)
+ {
+ Ret[0] = L'"';
+ wcscpy(Ret + 1, AppName);
+ wcscat(Ret, L"\"");
+ }
+ }
+ return Ret;
+ }
- if (NULL == CmdLine)
- {
+ if (NULL == CmdLine)
+ {
SetLastError(ERROR_INVALID_PARAMETER);
return NULL;
- }
+ }
- /* first check for a quoted file name */
- if (L'"' == CmdLine[0] && NULL != (p = wcschr(CmdLine + 1, L'"')))
- {
+ /* first check for a quoted file name */
+ if (L'"' == CmdLine[0] && NULL != (p = wcschr(CmdLine + 1, L'"')))
+ {
int Len = p - CmdLine - 1;
/* extract the quoted portion as file name */
Name = RtlAllocateHeap(GetProcessHeap(), 0, (Len + 1) * sizeof(WCHAR));
if (NULL == Name)
- {
- return NULL;
- }
+ {
+ return NULL;
+ }
memcpy(Name, CmdLine + 1, Len * sizeof(WCHAR));
Name[Len] = L'\0';
if (SearchPathW(NULL, Name, L".exe", BufLen, Buffer, NULL))
- {
- Ret = CmdLine; /* no change necessary */
- }
+ {
+ Ret = CmdLine; /* no change necessary */
+ }
RtlFreeHeap(GetProcessHeap(), 0, Name);
return Ret;
- }
+ }
- /* now try the command-line word by word */
- Name = RtlAllocateHeap(GetProcessHeap(), 0, (wcslen(CmdLine) + 1) * sizeof(WCHAR));
- if (NULL == Name)
- {
+ /* now try the command-line word by word */
+ Name = RtlAllocateHeap(GetProcessHeap(), 0, (wcslen(CmdLine) + 1) * sizeof(WCHAR));
+ if (NULL == Name)
+ {
return NULL;
- }
- Pos = Name;
- p = CmdLine;
+ }
+ Pos = Name;
+ p = CmdLine;
- while (L'\0' != *p)
- {
+ while (L'\0' != *p)
+ {
do
- {
- *Pos++ = *p++;
- }
+ {
+ *Pos++ = *p++;
+ }
while (L'\0' != *p && L' ' != *p);
*Pos = 0;
if (SearchPathW(NULL, Name, L".exe", BufLen, Buffer, NULL))
- {
- Ret = CmdLine;
- break;
- }
- }
+ {
+ Ret = CmdLine;
+ break;
+ }
+ }
- if (NULL == Ret || NULL == wcschr(Name, L' '))
- {
+ if (NULL == Ret || NULL == wcschr(Name, L' '))
+ {
RtlFreeHeap(GetProcessHeap(), 0, Name); /* no change necessary */
return Ret;
- }
+ }
- /* now build a new command-line with quotes */
- Ret = RtlAllocateHeap(GetProcessHeap(), 0, (wcslen(CmdLine) + 3) * sizeof(WCHAR));
- if (NULL == Ret)
- {
+ /* now build a new command-line with quotes */
+ Ret = RtlAllocateHeap(GetProcessHeap(), 0, (wcslen(CmdLine) + 3) * sizeof(WCHAR));
+ if (NULL == Ret)
+ {
RtlFreeHeap(GetProcessHeap(), 0, Name); /* no change necessary */
return NULL;
- }
- Ret[0] = L'"';
- wcscpy(Ret + 1, Name);
- wcscat(Ret, L"\"");
- wcscat(Ret, p);
+ }
+ Ret[0] = L'"';
+ wcscpy(Ret + 1, Name);
+ wcscat(Ret, L"\"");
+ wcscat(Ret, p);
- RtlFreeHeap(GetProcessHeap(), 0, Name);
- return Ret;
+ RtlFreeHeap(GetProcessHeap(), 0, Name);
+ return Ret;
}
@@ -754,19 +738,16 @@
* @implemented
*/
BOOL STDCALL
-CreateProcessW
-(
- LPCWSTR lpApplicationName,
- LPWSTR lpCommandLine,
- LPSECURITY_ATTRIBUTES lpProcessAttributes,
- LPSECURITY_ATTRIBUTES lpThreadAttributes,
- BOOL bInheritHandles,
- DWORD dwCreationFlags,
- LPVOID lpEnvironment,
- LPCWSTR lpCurrentDirectory,
- LPSTARTUPINFOW lpStartupInfo,
- LPPROCESS_INFORMATION lpProcessInformation
-)
+CreateProcessW(LPCWSTR lpApplicationName,
+ LPWSTR lpCommandLine,
+ LPSECURITY_ATTRIBUTES lpProcessAttributes,
+ LPSECURITY_ATTRIBUTES lpThreadAttributes,
+ BOOL bInheritHandles,
+ DWORD dwCreationFlags,
+ LPVOID lpEnvironment,
+ LPCWSTR lpCurrentDirectory,
+ LPSTARTUPINFOW lpStartupInfo,
+ LPPROCESS_INFORMATION lpProcessInformation)
{
HANDLE hSection, hProcess, hThread;
NTSTATUS Status;
@@ -798,99 +779,99 @@
PVOID ProcSecurity = NULL;
DPRINT("CreateProcessW(lpApplicationName '%S', lpCommandLine '%S')\n",
- lpApplicationName, lpCommandLine);
+ lpApplicationName, lpCommandLine);
TidyCmdLine = GetFileName(lpCurrentDirectory, lpApplicationName, lpCommandLine, Name,
sizeof(Name) / sizeof(WCHAR));
if (NULL == TidyCmdLine)
- {
- return FALSE;
- }
+ {
+ return FALSE;
+ }
DPRINT("TidyCmdLine '%S'\n", TidyCmdLine);
if (lpApplicationName != NULL && lpApplicationName[0] != 0)
- {
- wcscpy (TempApplicationNameW, lpApplicationName);
- i = wcslen(TempApplicationNameW);
- if (TempApplicationNameW[i - 1] == L'.')
- {
- TempApplicationNameW[i - 1] = 0;
- }
- else
- {
- s = max(wcsrchr(TempApplicationNameW, L'\\'), wcsrchr(TempApplicationNameW, L'/'));
- if (s == NULL)
- {
- s = TempApplicationNameW;
- }
- else
- {
- s++;
- }
+ {
+ wcscpy (TempApplicationNameW, lpApplicationName);
+ i = wcslen(TempApplicationNameW);
+ if (TempApplicationNameW[i - 1] == L'.')
+ {
+ TempApplicationNameW[i - 1] = 0;
+ }
+ else
+ {
+ s = max(wcsrchr(TempApplicationNameW, L'\\'), wcsrchr(TempApplicationNameW, L'/'));
+ if (s == NULL)
+ {
+ s = TempApplicationNameW;
+ }
+ else
+ {
+ s++;
+ }
+ e = wcsrchr(s, L'.');
+ if (e == NULL)
+ {
+ wcscat(s, L".exe");
e = wcsrchr(s, L'.');
- if (e == NULL)
- {
- wcscat(s, L".exe");
- e = wcsrchr(s, L'.');
- }
- }
- }
+ }
+ }
+ }
else if (L'"' == TidyCmdLine[0])
- {
- wcscpy(TempApplicationNameW, TidyCmdLine + 1);
- s = wcschr(TempApplicationNameW, L'"');
- if (NULL == s)
- {
- return FALSE;
- }
- *s = L'\0';
- }
+ {
+ wcscpy(TempApplicationNameW, TidyCmdLine + 1);
+ s = wcschr(TempApplicationNameW, L'"');
+ if (NULL == s)
+ {
+ return FALSE;
+ }
+ *s = L'\0';
+ }
else
- {
- wcscpy(TempApplicationNameW, TidyCmdLine);
- s = wcschr(TempApplicationNameW, L' ');
- if (NULL != s)
- {
- *s = L'\0';
- }
- }
+ {
+ wcscpy(TempApplicationNameW, TidyCmdLine);
+ s = wcschr(TempApplicationNameW, L' ');
+ if (NULL != s)
+ {
+ *s = L'\0';
+ }
+ }
s = max(wcsrchr(TempApplicationNameW, L'\\'), wcsrchr(TempApplicationNameW, L'/'));
if (NULL == s)
- {
- s = TempApplicationNameW;
- }
+ {
+ s = TempApplicationNameW;
+ }
s = wcsrchr(s, L'.');
if (NULL == s)
- {
- wcscat(TempApplicationNameW, L".exe");
- }
+ {
+ wcscat(TempApplicationNameW, L".exe");
+ }
if (!SearchPathW(NULL, TempApplicationNameW, NULL, sizeof(ImagePathName)/sizeof(WCHAR), ImagePathName, &s))
{
- return FALSE;
+ return FALSE;
}
e = wcsrchr(s, L'.');
if (e != NULL && (!_wcsicmp(e, L".bat") || !_wcsicmp(e, L".cmd")))
{
- // the command is a batch file
- IsBatchFile = TRUE;
- if (lpApplicationName != NULL && lpApplicationName[0])
- {
- // FIXME: use COMSPEC for the command interpreter
- wcscpy(TempCommandLineNameW, L"cmd /c ");
- wcscat(TempCommandLineNameW, lpApplicationName);
- lpCommandLine = TempCommandLineNameW;
- wcscpy(TempApplicationNameW, L"cmd.exe");
- if (!SearchPathW(NULL, TempApplicationNameW, NULL, sizeof(ImagePathName)/sizeof(WCHAR), ImagePathName, &s))
- {
- return FALSE;
- }
- }
- else
- {
- return FALSE;
- }
+ // the command is a batch file
+ IsBatchFile = TRUE;
+ if (lpApplicationName != NULL && lpApplicationName[0])
+ {
+ // FIXME: use COMSPEC for the command interpreter
+ wcscpy(TempCommandLineNameW, L"cmd /c ");
+ wcscat(TempCommandLineNameW, lpApplicationName);
+ lpCommandLine = TempCommandLineNameW;
+ wcscpy(TempApplicationNameW, L"cmd.exe");
+ if (!SearchPathW(NULL, TempApplicationNameW, NULL, sizeof(ImagePathName)/sizeof(WCHAR), ImagePathName, &s))
+ {
+ return FALSE;
+ }
+ }
+ else
+ {
+ return FALSE;
+ }
}
/*
@@ -905,16 +886,16 @@
/* Initialize the current directory string */
if (lpCurrentDirectory != NULL)
- {
- RtlInitUnicodeString(&CurrentDirectory_U,
- lpCurrentDirectory);
- }
+ {
+ RtlInitUnicodeString(&CurrentDirectory_U,
+ lpCurrentDirectory);
+ }
else
- {
- GetCurrentDirectoryW(256, TempCurrentDirectoryW);
- RtlInitUnicodeString(&CurrentDirectory_U,
- TempCurrentDirectoryW);
- }
+ {
+ GetCurrentDirectoryW(256, TempCurrentDirectoryW);
+ RtlInitUnicodeString(&CurrentDirectory_U,
+ TempCurrentDirectoryW);
+ }
/*
* Create a section for the executable
@@ -924,91 +905,95 @@
if (hSection == NULL)
{
/////////////////////////////////////////
- /*
- * Inspect the image to determine executable flavour
- */
- IO_STATUS_BLOCK IoStatusBlock;
- UNICODE_STRING ApplicationNameString;
- OBJECT_ATTRIBUTES ObjectAttributes;
- PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
- IMAGE_DOS_HEADER DosHeader;
- IO_STATUS_BLOCK Iosb;
- LARGE_INTEGER Offset;
- HANDLE hFile = NULL;
+ /*
+ * Inspect the image to determine executable flavour
+ */
+ IO_STATUS_BLOCK IoStatusBlock;
+ UNICODE_STRING ApplicationNameString;
+ OBJECT_ATTRIBUTES ObjectAttributes;
+ PSECURITY_DESCRIPTOR SecurityDescriptor = NULL;
+ IMAGE_DOS_HEADER DosHeader;
+ IO_STATUS_BLOCK Iosb;
+ LARGE_INTEGER Offset;
+ HANDLE hFile = NULL;
+ DPRINT("Inspecting Image Header for image type id\n");
- DPRINT("Inspecting Image Header for image type id\n");
+ // Find the application name
+ if (!RtlDosPathNameToNtPathName_U((LPWSTR)lpApplicationName,
+ &ApplicationNameString, NULL, NULL))
+ {
+ return FALSE;
+ }
+ DPRINT("ApplicationName %S\n",ApplicationNameString.Buffer);
- // Find the application name
- if (!RtlDosPathNameToNtPathName_U((LPWSTR)lpApplicationName,
- &ApplicationNameString, NULL, NULL)) {
- return FALSE;
- }
- DPRINT("ApplicationName %S\n",ApplicationNameString.Buffer);
+ InitializeObjectAttributes(&ObjectAttributes,
+ &ApplicationNameString,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ SecurityDescriptor);
- InitializeObjectAttributes(&ObjectAttributes,
- &ApplicationNameString,
- OBJ_CASE_INSENSITIVE,
- NULL,
- SecurityDescriptor);
+ // Try to open the executable
+ Status = NtOpenFile(&hFile,
+ SYNCHRONIZE|FILE_EXECUTE|FILE_READ_DATA,
+ &ObjectAttributes,
+ &IoStatusBlock,
+ FILE_SHARE_DELETE|FILE_SHARE_READ,
+ FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE);
- // Try to open the executable
- Status = NtOpenFile(&hFile,
- SYNCHRONIZE|FILE_EXECUTE|FILE_READ_DATA,
- &ObjectAttributes,
- &IoStatusBlock,
- FILE_SHARE_DELETE|FILE_SHARE_READ,
- FILE_SYNCHRONOUS_IO_NONALERT|FILE_NON_DIRECTORY_FILE);
+ RtlFreeUnicodeString(&ApplicationNameString);
- RtlFreeUnicodeString(&ApplicationNameString);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT("Failed to open file\n");
+ SetLastErrorByStatus(Status);
+ return FALSE;
+ }
- if (!NT_SUCCESS(Status)) {
- DPRINT("Failed to open file\n");
- SetLastErrorByStatus(Status);
- return FALSE;
- }
+ // Read the dos header
+ Offset.QuadPart = 0;
+ Status = ZwReadFile(hFile,
+ NULL,
+ NULL,
+ NULL,
+ &Iosb,
+ &DosHeader,
[truncated at 1000 lines; 325 more skipped]