mirror of
https://github.com/reactos/reactos.git
synced 2025-02-24 17:34:57 +00:00
PEB will be created in NtCreateProcess.
svn path=/trunk/; revision=695
This commit is contained in:
parent
81a9f1c4b0
commit
babfe77ea9
10 changed files with 281 additions and 247 deletions
|
@ -2078,14 +2078,14 @@ CreateProcessA(
|
|||
DWORD dwCreationFlags,
|
||||
LPVOID lpEnvironment,
|
||||
LPCSTR lpCurrentDirectory,
|
||||
LPSTARTUPINFO lpStartupInfo,
|
||||
LPSTARTUPINFOA lpStartupInfo,
|
||||
LPPROCESS_INFORMATION lpProcessInformation
|
||||
);
|
||||
|
||||
VOID
|
||||
STDCALL
|
||||
GetStartupInfoA(
|
||||
LPSTARTUPINFO lpStartupInfo
|
||||
LPSTARTUPINFOA lpStartupInfo
|
||||
);
|
||||
|
||||
HANDLE
|
||||
|
@ -2979,7 +2979,7 @@ DdeQueryStringA (DWORD, HSZ, char *, DWORD, int);
|
|||
WINBOOL STDCALL LogonUserA (LPSTR, LPSTR, LPSTR, DWORD, DWORD, HANDLE *);
|
||||
WINBOOL STDCALL CreateProcessAsUserA (HANDLE, LPCTSTR, LPTSTR,
|
||||
SECURITY_ATTRIBUTES*, SECURITY_ATTRIBUTES*, WINBOOL, DWORD, LPVOID,
|
||||
LPCTSTR, STARTUPINFO*, PROCESS_INFORMATION*);
|
||||
LPCTSTR, STARTUPINFOA*, PROCESS_INFORMATION*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
typedef NTSTATUS (*PKSTART_ROUTINE)(PVOID StartContext);
|
||||
|
||||
typedef struct _STACK_INFORMATION
|
||||
typedef struct _STACK_INFORMATION
|
||||
{
|
||||
PVOID BaseAddress;
|
||||
PVOID UpperAddress;
|
||||
|
@ -46,30 +46,31 @@ typedef struct linux_sigcontext {
|
|||
|
||||
typedef ULONG THREADINFOCLASS;
|
||||
|
||||
typedef struct _STARTUPINFOW {
|
||||
DWORD cb;
|
||||
WCHAR WindowTitle[MAX_PATH];
|
||||
WCHAR ImageFile[MAX_PATH];
|
||||
WCHAR CommandLine[MAX_PATH];
|
||||
WCHAR DllPath[MAX_PATH];
|
||||
WCHAR Reserved[MAX_PATH];
|
||||
WCHAR Desktop[MAX_PATH];
|
||||
WCHAR Title[MAX_PATH];
|
||||
DWORD dwX;
|
||||
DWORD dwY;
|
||||
DWORD dwXSize;
|
||||
DWORD dwYSize;
|
||||
DWORD dwXCountChars;
|
||||
DWORD dwYCountChars;
|
||||
DWORD dwFillAttribute;
|
||||
DWORD dwFlags;
|
||||
WORD wShowWindow;
|
||||
WORD cbReserved2;
|
||||
unsigned char * lpReserved2;
|
||||
HANDLE hStdInput;
|
||||
HANDLE hStdOutput;
|
||||
HANDLE hStdError;
|
||||
} PROCESSINFOW, *PPROCESSINFOW;
|
||||
typedef struct _PROCESSINFO
|
||||
{
|
||||
WCHAR WindowTitle[MAX_PATH];
|
||||
WCHAR ImageFile[MAX_PATH];
|
||||
WCHAR CommandLine[MAX_PATH];
|
||||
WCHAR DllPath[MAX_PATH];
|
||||
WCHAR Reserved[MAX_PATH];
|
||||
WCHAR Desktop[MAX_PATH];
|
||||
WCHAR Title[MAX_PATH];
|
||||
PVOID Environment;
|
||||
DWORD dwX;
|
||||
DWORD dwY;
|
||||
DWORD dwXSize;
|
||||
DWORD dwYSize;
|
||||
DWORD dwXCountChars;
|
||||
DWORD dwYCountChars;
|
||||
DWORD dwFillAttribute;
|
||||
DWORD dwFlags;
|
||||
WORD wShowWindow;
|
||||
WORD cbReserved2;
|
||||
unsigned char *lpReserved2;
|
||||
HANDLE hStdInput;
|
||||
HANDLE hStdOutput;
|
||||
HANDLE hStdError;
|
||||
} PROCESSINFO, *PPROCESSINFO;
|
||||
|
||||
|
||||
|
||||
|
@ -92,7 +93,7 @@ typedef struct _NT_PEB
|
|||
WORD NumberOfProcessors; // 11h
|
||||
WORD NtGlobalFlag; // 13h
|
||||
|
||||
PPROCESSINFOW StartupInfo; // 15h
|
||||
PPROCESSINFO ProcessInfo; // 15h
|
||||
HANDLE ProcessHeap; // 19h
|
||||
ATOMTABLE LocalAtomTable; // 1Dh
|
||||
LPCRITICAL_SECTION CriticalSection; // 35h
|
||||
|
@ -100,15 +101,15 @@ typedef struct _NT_PEB
|
|||
WORD MajorVersion; // 3Dh
|
||||
WORD MinorVersion; // 3Fh
|
||||
WORD BuildNumber; // 41h
|
||||
WORD PlatformId; // 43h
|
||||
} NT_PEB, *PNT_PEB;
|
||||
WORD PlatformId; // 43h
|
||||
} NT_PEB, *PNT_PEB;
|
||||
|
||||
typedef struct _CLIENT_ID
|
||||
typedef struct _CLIENT_ID
|
||||
{
|
||||
HANDLE UniqueProcess;
|
||||
HANDLE UniqueThread;
|
||||
} CLIENT_ID, *PCLIENT_ID;
|
||||
|
||||
|
||||
typedef struct _NT_TIB {
|
||||
struct _EXCEPTION_REGISTRATION_RECORD *ExceptionList; // 00h
|
||||
PVOID StackBase; // 04h
|
||||
|
@ -124,25 +125,25 @@ typedef struct _NT_TIB {
|
|||
|
||||
typedef struct _NT_TEB
|
||||
{
|
||||
NT_TIB Tib; // 00h
|
||||
ULONG reserved1; // 1Ch ???
|
||||
CLIENT_ID Cid; // 20h
|
||||
ULONG reserved2; // 28h ???
|
||||
ULONG reserved3; // 2Ch ???
|
||||
NT_PEB *Peb; // 30h
|
||||
DWORD LastErrorCode; // 34h
|
||||
NT_TIB Tib; // 00h
|
||||
ULONG reserved1; // 1Ch ???
|
||||
CLIENT_ID Cid; // 20h
|
||||
ULONG reserved2; // 28h ???
|
||||
ULONG reserved3; // 2Ch ???
|
||||
PNT_PEB Peb; // 30h
|
||||
DWORD LastErrorCode; // 34h
|
||||
|
||||
HANDLE RPCHandle; // 36
|
||||
PVOID TlsData[TLS_MINIMUM_AVAILABLE]; // 40
|
||||
DWORD dwTlsIndex; // 230
|
||||
HANDLE RPCHandle; // 36
|
||||
PVOID TlsData[TLS_MINIMUM_AVAILABLE]; // 40
|
||||
DWORD dwTlsIndex; // 230
|
||||
NTSTATUS LastStatusValue; // 242
|
||||
DWORD LockCount; // 244
|
||||
UCHAR HardErrorMode; // 248
|
||||
|
||||
/* reactos only ??? (Eric Kohl) */
|
||||
PVOID StackCommit;
|
||||
PVOID StackCommitMax;
|
||||
PVOID StackReserved;
|
||||
/* reactos only ??? (Eric Kohl) */
|
||||
PVOID StackCommit;
|
||||
PVOID StackCommitMax;
|
||||
PVOID StackReserved;
|
||||
} NT_TEB, *PNT_TEB;
|
||||
|
||||
struct _KPROCESS;
|
||||
|
@ -233,9 +234,10 @@ typedef struct _KTHREAD
|
|||
// According to documentation the stack should have a commited [ 1 page ] and
|
||||
// a reserved part [ 1 M ] but can be specified otherwise in the image file.
|
||||
|
||||
typedef struct _INITIAL_TEB {
|
||||
typedef struct _INITIAL_TEB
|
||||
{
|
||||
PVOID StackBase;
|
||||
PVOID StackLimit;
|
||||
PVOID StackLimit;
|
||||
PVOID StackCommit;
|
||||
PVOID StackCommitMax;
|
||||
PVOID StackReserved;
|
||||
|
@ -289,7 +291,7 @@ typedef struct _ETHREAD {
|
|||
UCHAR LpcExitThreadCalled;
|
||||
UCHAR HardErrorsAreDisabled;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Added by David Welch (welch@cwcom.net)
|
||||
*/
|
||||
|
|
|
@ -3971,11 +3971,11 @@ typedef struct tagSOUNDSENTRY {
|
|||
DWORD iWindowsEffectOrdinal;
|
||||
} SOUNDSENTRY, *LPSOUNDSENTRY;
|
||||
|
||||
typedef struct _STARTUPINFO {
|
||||
typedef struct _STARTUPINFOA {
|
||||
DWORD cb;
|
||||
LPTSTR lpReserved;
|
||||
LPTSTR lpDesktop;
|
||||
LPTSTR lpTitle;
|
||||
LPSTR lpReserved;
|
||||
LPSTR lpDesktop;
|
||||
LPSTR lpTitle;
|
||||
DWORD dwX;
|
||||
DWORD dwY;
|
||||
DWORD dwXSize;
|
||||
|
@ -3990,7 +3990,36 @@ typedef struct _STARTUPINFO {
|
|||
HANDLE hStdInput;
|
||||
HANDLE hStdOutput;
|
||||
HANDLE hStdError;
|
||||
} STARTUPINFO, *LPSTARTUPINFO;
|
||||
} STARTUPINFOA, *LPSTARTUPINFOA;
|
||||
|
||||
typedef struct _STARTUPINFOW {
|
||||
DWORD cb;
|
||||
LPWSTR lpReserved;
|
||||
LPWSTR lpDesktop;
|
||||
LPWSTR lpTitle;
|
||||
DWORD dwX;
|
||||
DWORD dwY;
|
||||
DWORD dwXSize;
|
||||
DWORD dwYSize;
|
||||
DWORD dwXCountChars;
|
||||
DWORD dwYCountChars;
|
||||
DWORD dwFillAttribute;
|
||||
DWORD dwFlags;
|
||||
WORD wShowWindow;
|
||||
WORD cbReserved2;
|
||||
LPBYTE lpReserved2;
|
||||
HANDLE hStdInput;
|
||||
HANDLE hStdOutput;
|
||||
HANDLE hStdError;
|
||||
} STARTUPINFOW, *LPSTARTUPINFOW;
|
||||
|
||||
#ifdef UNICODE
|
||||
typedef STARTUPINFOW STARTUPINFO;
|
||||
typedef LPSTARTUPINFOW LPSTARTUPINFO;
|
||||
#else
|
||||
typedef STARTUPINFOA STARTUPINFO;
|
||||
typedef LPSTARTUPINFOA LPSTARTUPINFO;
|
||||
#endif /* UNICODE */
|
||||
|
||||
typedef struct tagSTICKYKEYS {
|
||||
DWORD cbSize;
|
||||
|
|
|
@ -2093,14 +2093,14 @@ CreateProcessW(
|
|||
DWORD dwCreationFlags,
|
||||
LPVOID lpEnvironment,
|
||||
LPCWSTR lpCurrentDirectory,
|
||||
LPSTARTUPINFO lpStartupInfo,
|
||||
LPSTARTUPINFOW lpStartupInfo,
|
||||
LPPROCESS_INFORMATION lpProcessInformation
|
||||
);
|
||||
|
||||
VOID
|
||||
STDCALL
|
||||
GetStartupInfoW(
|
||||
LPSTARTUPINFO lpStartupInfo
|
||||
LPSTARTUPINFOW lpStartupInfo
|
||||
);
|
||||
|
||||
HANDLE
|
||||
|
@ -2999,7 +2999,7 @@ DdeQueryStringW (DWORD, HSZ, LPCWSTR, DWORD, int);
|
|||
WINBOOL STDCALL LogonUserW (LPWSTR, LPWSTR, LPWSTR, DWORD, DWORD, HANDLE *);
|
||||
WINBOOL STDCALL CreateProcessAsUserW (HANDLE, LPCWSTR, LPWSTR,
|
||||
SECURITY_ATTRIBUTES*, SECURITY_ATTRIBUTES*, WINBOOL,
|
||||
DWORD, LPVOID, LPCWSTR, STARTUPINFO*,
|
||||
DWORD, LPVOID, LPCWSTR, STARTUPINFOW*,
|
||||
PROCESS_INFORMATION*);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -41,6 +41,6 @@ LPSTR STDCALL GetCommandLineA(VOID)
|
|||
|
||||
LPWSTR STDCALL GetCommandLineW(VOID)
|
||||
{
|
||||
return(NtCurrentPeb()->StartupInfo->CommandLine);
|
||||
return(NtCurrentPeb()->ProcessInfo->CommandLine);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
/*
|
||||
/* $Id: create.c,v 1.12 1999/10/13 22:35:55 ekohl Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
* FILE: lib/kernel32/proc/proc.c
|
||||
|
@ -36,7 +37,7 @@ WINBOOL STDCALL CreateProcessA(LPCSTR lpApplicationName,
|
|||
DWORD dwCreationFlags,
|
||||
LPVOID lpEnvironment,
|
||||
LPCSTR lpCurrentDirectory,
|
||||
LPSTARTUPINFO lpStartupInfo,
|
||||
LPSTARTUPINFOA lpStartupInfo,
|
||||
LPPROCESS_INFORMATION lpProcessInformation)
|
||||
/*
|
||||
* FUNCTION: The CreateProcess function creates a new process and its
|
||||
|
@ -65,24 +66,24 @@ WINBOOL STDCALL CreateProcessA(LPCSTR lpApplicationName,
|
|||
DPRINT("CreateProcessA\n");
|
||||
|
||||
PApplicationNameW = InternalAnsiToUnicode(ApplicationNameW,
|
||||
lpApplicationName,
|
||||
lpApplicationName,
|
||||
MAX_PATH);
|
||||
PCommandLineW = InternalAnsiToUnicode(CommandLineW,
|
||||
lpCommandLine,
|
||||
MAX_PATH);
|
||||
PCurrentDirectoryW = InternalAnsiToUnicode(CurrentDirectoryW,
|
||||
lpCurrentDirectory,
|
||||
MAX_PATH);
|
||||
MAX_PATH);
|
||||
return CreateProcessW(PApplicationNameW,
|
||||
PCommandLineW,
|
||||
PCommandLineW,
|
||||
lpProcessAttributes,
|
||||
lpThreadAttributes,
|
||||
bInheritHandles,
|
||||
dwCreationFlags,
|
||||
lpEnvironment,
|
||||
PCurrentDirectoryW,
|
||||
lpStartupInfo,
|
||||
lpProcessInformation);
|
||||
(LPSTARTUPINFOW)lpStartupInfo,
|
||||
lpProcessInformation);
|
||||
}
|
||||
|
||||
#define STACK_TOP (0xb0000000)
|
||||
|
@ -98,7 +99,7 @@ HANDLE STDCALL CreateFirstThread(HANDLE ProcessHandle,
|
|||
HANDLE NTDllSectionHandle,
|
||||
HANDLE SectionHandle,
|
||||
PVOID ImageBase)
|
||||
{
|
||||
{
|
||||
NTSTATUS Status;
|
||||
HANDLE ThreadHandle;
|
||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||
|
@ -109,7 +110,7 @@ HANDLE STDCALL CreateFirstThread(HANDLE ProcessHandle,
|
|||
PVOID BaseAddress;
|
||||
ULONG BytesWritten;
|
||||
HANDLE DupNTDllSectionHandle, DupSectionHandle;
|
||||
|
||||
|
||||
ObjectAttributes.Length = sizeof(OBJECT_ATTRIBUTES);
|
||||
ObjectAttributes.RootDirectory = NULL;
|
||||
ObjectAttributes.ObjectName = NULL;
|
||||
|
@ -141,7 +142,6 @@ HANDLE STDCALL CreateFirstThread(HANDLE ProcessHandle,
|
|||
{
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
|
||||
memset(&ThreadContext,0,sizeof(CONTEXT));
|
||||
ThreadContext.Eip = (ULONG)lpStartAddress;
|
||||
|
@ -150,7 +150,7 @@ HANDLE STDCALL CreateFirstThread(HANDLE ProcessHandle,
|
|||
ThreadContext.SegEs = USER_DS;
|
||||
ThreadContext.SegDs = USER_DS;
|
||||
ThreadContext.SegCs = USER_CS;
|
||||
ThreadContext.SegSs = USER_DS;
|
||||
ThreadContext.SegSs = USER_DS;
|
||||
ThreadContext.Esp = STACK_TOP - 16;
|
||||
ThreadContext.EFlags = (1<<1) + (1<<9);
|
||||
|
||||
|
@ -348,57 +348,50 @@ static NTSTATUS CreatePeb(HANDLE ProcessHandle, PWSTR CommandLine)
|
|||
ULONG PebSize;
|
||||
NT_PEB Peb;
|
||||
ULONG BytesWritten;
|
||||
PVOID StartupInfoBase;
|
||||
ULONG StartupInfoSize;
|
||||
PROCESSINFOW StartupInfo;
|
||||
|
||||
PVOID ProcessInfoBase;
|
||||
ULONG ProcessInfoSize;
|
||||
PROCESSINFO ProcessInfo;
|
||||
|
||||
PebBase = (PVOID)PEB_BASE;
|
||||
PebSize = 0x1000;
|
||||
Status = ZwAllocateVirtualMemory(ProcessHandle,
|
||||
&PebBase,
|
||||
0,
|
||||
&PebSize,
|
||||
MEM_COMMIT,
|
||||
PAGE_READWRITE);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return(Status);
|
||||
}
|
||||
|
||||
|
||||
memset(&Peb, 0, sizeof(Peb));
|
||||
Peb.StartupInfo = (PPROCESSINFOW)PEB_STARTUPINFO;
|
||||
|
||||
ZwWriteVirtualMemory(ProcessHandle,
|
||||
NtReadVirtualMemory(ProcessHandle,
|
||||
(PVOID)PEB_BASE,
|
||||
&Peb,
|
||||
sizeof(Peb),
|
||||
&BytesWritten);
|
||||
|
||||
Peb.ProcessInfo = (PPROCESSINFO)PEB_STARTUPINFO;
|
||||
|
||||
NtWriteVirtualMemory(ProcessHandle,
|
||||
(PVOID)PEB_BASE,
|
||||
&Peb,
|
||||
sizeof(Peb),
|
||||
&BytesWritten);
|
||||
|
||||
StartupInfoBase = (PVOID)PEB_STARTUPINFO;
|
||||
StartupInfoSize = 0x1000;
|
||||
Status = ZwAllocateVirtualMemory(ProcessHandle,
|
||||
&StartupInfoBase,
|
||||
|
||||
ProcessInfoBase = (PVOID)PEB_STARTUPINFO;
|
||||
ProcessInfoSize = 0x1000;
|
||||
Status = NtAllocateVirtualMemory(ProcessHandle,
|
||||
&ProcessInfoBase,
|
||||
0,
|
||||
&StartupInfoSize,
|
||||
&ProcessInfoSize,
|
||||
MEM_COMMIT,
|
||||
PAGE_READWRITE);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return(Status);
|
||||
}
|
||||
|
||||
|
||||
memset(&StartupInfo, 0, sizeof(StartupInfo));
|
||||
wcscpy(StartupInfo.CommandLine, CommandLine);
|
||||
|
||||
DPRINT("StartupInfoSize %x\n",StartupInfoSize);
|
||||
|
||||
memset(&ProcessInfo, 0, sizeof(PROCESSINFO));
|
||||
wcscpy(ProcessInfo.CommandLine, CommandLine);
|
||||
|
||||
DPRINT("ProcessInfoSize %x\n",ProcessInfoSize);
|
||||
ZwWriteVirtualMemory(ProcessHandle,
|
||||
(PVOID)PEB_STARTUPINFO,
|
||||
&StartupInfo,
|
||||
StartupInfoSize,
|
||||
&ProcessInfo,
|
||||
ProcessInfoSize,
|
||||
&BytesWritten);
|
||||
|
||||
|
||||
return(STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
|
@ -411,7 +404,7 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
|
|||
DWORD dwCreationFlags,
|
||||
LPVOID lpEnvironment,
|
||||
LPCWSTR lpCurrentDirectory,
|
||||
LPSTARTUPINFO lpStartupInfo,
|
||||
LPSTARTUPINFOW lpStartupInfo,
|
||||
LPPROCESS_INFORMATION lpProcessInformation)
|
||||
{
|
||||
HANDLE hSection, hProcess, hThread;
|
||||
|
@ -500,13 +493,13 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
|
|||
SetLastError(RtlNtStatusToDosError(Status));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Create Process Environment Block
|
||||
*/
|
||||
DPRINT("Creating peb\n");
|
||||
CreatePeb(hProcess, TempCommandLine);
|
||||
|
||||
|
||||
DPRINT("Creating thread for process\n");
|
||||
lpStartAddress = (LPTHREAD_START_ROUTINE)
|
||||
((PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(NTDLL_BASE))->
|
||||
|
@ -526,10 +519,11 @@ WINBOOL STDCALL CreateProcessW(LPCWSTR lpApplicationName,
|
|||
|
||||
if ( hThread == NULL )
|
||||
return FALSE;
|
||||
|
||||
|
||||
lpProcessInformation->hProcess = hProcess;
|
||||
lpProcessInformation->hThread = hThread;
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* EOF */
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: proc.c,v 1.21 1999/10/07 23:45:25 ekohl Exp $
|
||||
/* $Id: proc.c,v 1.22 1999/10/13 22:35:55 ekohl Exp $
|
||||
*
|
||||
* COPYRIGHT: See COPYING in the top level directory
|
||||
* PROJECT: ReactOS system libraries
|
||||
|
@ -11,7 +11,7 @@
|
|||
|
||||
/* INCLUDES ****************************************************************/
|
||||
|
||||
#define UNICODE
|
||||
//#define UNICODE
|
||||
#include <ddk/ntddk.h>
|
||||
#include <windows.h>
|
||||
#include <kernel32/proc.h>
|
||||
|
@ -25,7 +25,7 @@
|
|||
#include <kernel32/kernel32.h>
|
||||
|
||||
/* TYPES *********************************************************************/
|
||||
|
||||
/*
|
||||
typedef struct _WSTARTUPINFO {
|
||||
DWORD cb;
|
||||
LPWSTR lpReserved;
|
||||
|
@ -45,7 +45,8 @@ typedef struct _WSTARTUPINFO {
|
|||
HANDLE hStdInput;
|
||||
HANDLE hStdOutput;
|
||||
HANDLE hStdError;
|
||||
} WSTARTUPINFO, *LPWSTARTUPINFO;
|
||||
} WSTARTUPINFO, *LPWSTARTUPINFO;
|
||||
*/
|
||||
|
||||
/* GLOBALS *******************************************************************/
|
||||
|
||||
|
@ -113,8 +114,8 @@ GetCurrentThread (VOID)
|
|||
DWORD
|
||||
STDCALL
|
||||
GetCurrentProcessId (VOID)
|
||||
{
|
||||
return (DWORD) (GetTeb()->Cid).UniqueProcess;
|
||||
{
|
||||
return (DWORD) (GetTeb()->Cid).UniqueProcess;
|
||||
}
|
||||
|
||||
|
||||
|
@ -186,13 +187,13 @@ InternalAnsiToUnicode (
|
|||
else
|
||||
{
|
||||
i = 0;
|
||||
while ((*In)!=0 && i < MaxLength)
|
||||
while ((*In)!=0 && i < MaxLength)
|
||||
{
|
||||
Out[i] = *In;
|
||||
In++;
|
||||
i++;
|
||||
}
|
||||
Out[i] = 0;
|
||||
Out[i] = 0;
|
||||
return(Out);
|
||||
}
|
||||
}
|
||||
|
@ -245,15 +246,15 @@ WinExec (
|
|||
UINT uCmdShow
|
||||
)
|
||||
{
|
||||
STARTUPINFO StartupInfo;
|
||||
PROCESS_INFORMATION ProcessInformation;
|
||||
STARTUPINFOA StartupInfo;
|
||||
PROCESS_INFORMATION ProcessInformation;
|
||||
HINSTANCE hInst;
|
||||
DWORD dosErr;
|
||||
|
||||
StartupInfo.cb = sizeof(STARTUPINFO);
|
||||
StartupInfo.wShowWindow = uCmdShow ;
|
||||
StartupInfo.cb = sizeof(STARTUPINFOA);
|
||||
StartupInfo.wShowWindow = uCmdShow;
|
||||
StartupInfo.dwFlags = 0;
|
||||
|
||||
|
||||
hInst = (HINSTANCE)CreateProcessA(NULL,
|
||||
(PVOID)lpCmdLine,
|
||||
NULL,
|
||||
|
@ -335,112 +336,89 @@ SleepEx (
|
|||
VOID
|
||||
STDCALL
|
||||
GetStartupInfoW (
|
||||
LPSTARTUPINFO _lpStartupInfo
|
||||
LPSTARTUPINFOW lpStartupInfo
|
||||
)
|
||||
{
|
||||
NT_PEB *pPeb = NtCurrentPeb();
|
||||
LPWSTARTUPINFO lpStartupInfo = (LPWSTARTUPINFO)_lpStartupInfo;
|
||||
|
||||
|
||||
if (lpStartupInfo == NULL)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return;
|
||||
}
|
||||
|
||||
lpStartupInfo->cb = sizeof(STARTUPINFO);
|
||||
// lstrcpyW(lpStartupInfo->lpDesktop, pPeb->StartupInfo->Desktop);
|
||||
// lstrcpyW(lpStartupInfo->lpTitle, pPeb->StartupInfo->Title);
|
||||
lpStartupInfo->dwX = pPeb->StartupInfo->dwX;
|
||||
lpStartupInfo->dwY = pPeb->StartupInfo->dwY;
|
||||
lpStartupInfo->dwXSize = pPeb->StartupInfo->dwXSize;
|
||||
lpStartupInfo->dwYSize = pPeb->StartupInfo->dwYSize;
|
||||
lpStartupInfo->dwXCountChars = pPeb->StartupInfo->dwXCountChars;
|
||||
lpStartupInfo->dwYCountChars = pPeb->StartupInfo->dwYCountChars;
|
||||
lpStartupInfo->dwFillAttribute = pPeb->StartupInfo->dwFillAttribute;
|
||||
lpStartupInfo->dwFlags = pPeb->StartupInfo->dwFlags;
|
||||
lpStartupInfo->wShowWindow = pPeb->StartupInfo->wShowWindow;
|
||||
//lpStartupInfo->cbReserved2 = pPeb->StartupInfo->cbReserved;
|
||||
//lpStartupInfo->lpReserved = pPeb->StartupInfo->lpReserved1;
|
||||
//lpStartupInfo->lpReserved2 = pPeb->StartupInfo->lpReserved2;
|
||||
|
||||
lpStartupInfo->cb = sizeof(STARTUPINFO);
|
||||
lstrcpyW(lpStartupInfo->lpDesktop, pPeb->StartupInfo->Desktop);
|
||||
lstrcpyW(lpStartupInfo->lpTitle, pPeb->StartupInfo->Title);
|
||||
lpStartupInfo->dwX = pPeb->StartupInfo->dwX;
|
||||
lpStartupInfo->dwY = pPeb->StartupInfo->dwY;
|
||||
lpStartupInfo->dwXSize = pPeb->StartupInfo->dwXSize;
|
||||
lpStartupInfo->dwYSize = pPeb->StartupInfo->dwYSize;
|
||||
lpStartupInfo->dwXCountChars = pPeb->StartupInfo->dwXCountChars;
|
||||
lpStartupInfo->dwYCountChars = pPeb->StartupInfo->dwYCountChars;
|
||||
lpStartupInfo->dwFillAttribute = pPeb->StartupInfo->dwFillAttribute;
|
||||
lpStartupInfo->dwFlags = pPeb->StartupInfo->dwFlags;
|
||||
lpStartupInfo->wShowWindow = pPeb->StartupInfo->wShowWindow;
|
||||
//lpStartupInfo->cbReserved2 = pPeb->StartupInfo->cbReserved;
|
||||
//lpStartupInfo->lpReserved = pPeb->StartupInfo->lpReserved1;
|
||||
//lpStartupInfo->lpReserved2 = pPeb->StartupInfo->lpReserved2;
|
||||
|
||||
lpStartupInfo->hStdInput = pPeb->StartupInfo->hStdInput;
|
||||
lpStartupInfo->hStdOutput = pPeb->StartupInfo->hStdOutput;
|
||||
lpStartupInfo->hStdError = pPeb->StartupInfo->hStdError;
|
||||
|
||||
|
||||
|
||||
return;
|
||||
|
||||
lpStartupInfo->cb = sizeof(STARTUPINFOW);
|
||||
// lstrcpyW(lpStartupInfo->lpDesktop, pPeb->ProcessInfo->Desktop);
|
||||
// lstrcpyW(lpStartupInfo->lpTitle, pPeb->ProcessInfo->Title);
|
||||
lpStartupInfo->dwX = pPeb->ProcessInfo->dwX;
|
||||
lpStartupInfo->dwY = pPeb->ProcessInfo->dwY;
|
||||
lpStartupInfo->dwXSize = pPeb->ProcessInfo->dwXSize;
|
||||
lpStartupInfo->dwYSize = pPeb->ProcessInfo->dwYSize;
|
||||
lpStartupInfo->dwXCountChars = pPeb->ProcessInfo->dwXCountChars;
|
||||
lpStartupInfo->dwYCountChars = pPeb->ProcessInfo->dwYCountChars;
|
||||
lpStartupInfo->dwFillAttribute = pPeb->ProcessInfo->dwFillAttribute;
|
||||
lpStartupInfo->dwFlags = pPeb->ProcessInfo->dwFlags;
|
||||
lpStartupInfo->wShowWindow = pPeb->ProcessInfo->wShowWindow;
|
||||
// lpStartupInfo->cbReserved2 = pPeb->ProcessInfo->cbReserved;
|
||||
// lpStartupInfo->lpReserved = pPeb->ProcessInfo->lpReserved1;
|
||||
// lpStartupInfo->lpReserved2 = pPeb->ProcessInfo->lpReserved2;
|
||||
|
||||
lpStartupInfo->hStdInput = pPeb->ProcessInfo->hStdInput;
|
||||
lpStartupInfo->hStdOutput = pPeb->ProcessInfo->hStdOutput;
|
||||
lpStartupInfo->hStdError = pPeb->ProcessInfo->hStdError;
|
||||
}
|
||||
|
||||
|
||||
VOID
|
||||
STDCALL
|
||||
GetStartupInfoA (
|
||||
LPSTARTUPINFO lpStartupInfo
|
||||
LPSTARTUPINFOA lpStartupInfo
|
||||
)
|
||||
{
|
||||
NT_PEB *pPeb = NtCurrentPeb();
|
||||
ULONG i = 0;
|
||||
|
||||
if (lpStartupInfo == NULL)
|
||||
|
||||
if (lpStartupInfo == NULL)
|
||||
{
|
||||
SetLastError(ERROR_INVALID_PARAMETER);
|
||||
return;
|
||||
}
|
||||
|
||||
lpStartupInfo->cb = sizeof(STARTUPINFO);
|
||||
|
||||
lpStartupInfo->cb = sizeof(STARTUPINFOA);
|
||||
|
||||
i = 0;
|
||||
|
||||
while ((pPeb->StartupInfo->Desktop[i])!=0 && i < MAX_PATH)
|
||||
while ((pPeb->ProcessInfo->Desktop[i])!=0 && i < MAX_PATH)
|
||||
{
|
||||
lpStartupInfo->lpDesktop[i] = (unsigned char)
|
||||
pPeb->StartupInfo->Desktop[i];
|
||||
pPeb->ProcessInfo->Desktop[i];
|
||||
i++;
|
||||
}
|
||||
lpStartupInfo->lpDesktop[i] = 0;
|
||||
|
||||
|
||||
i = 0;
|
||||
while ((pPeb->StartupInfo->Title[i])!=0 && i < MAX_PATH)
|
||||
while ((pPeb->ProcessInfo->Title[i])!=0 && i < MAX_PATH)
|
||||
{
|
||||
lpStartupInfo->lpTitle[i] = (unsigned char)pPeb->StartupInfo->Title[i];
|
||||
lpStartupInfo->lpTitle[i] = (unsigned char)pPeb->ProcessInfo->Title[i];
|
||||
i++;
|
||||
}
|
||||
lpStartupInfo->lpTitle[i] = 0;
|
||||
|
||||
lpStartupInfo->dwX = pPeb->StartupInfo->dwX;
|
||||
lpStartupInfo->dwY = pPeb->StartupInfo->dwY;
|
||||
lpStartupInfo->dwXSize = pPeb->StartupInfo->dwXSize;
|
||||
lpStartupInfo->dwYSize = pPeb->StartupInfo->dwYSize;
|
||||
lpStartupInfo->dwXCountChars = pPeb->StartupInfo->dwXCountChars;
|
||||
lpStartupInfo->dwYCountChars = pPeb->StartupInfo->dwYCountChars;
|
||||
lpStartupInfo->dwFillAttribute = pPeb->StartupInfo->dwFillAttribute;
|
||||
lpStartupInfo->dwFlags = pPeb->StartupInfo->dwFlags;
|
||||
lpStartupInfo->wShowWindow = pPeb->StartupInfo->wShowWindow;
|
||||
//lpStartupInfo->cbReserved2 = pPeb->StartupInfo->cbReserved;
|
||||
//lpStartupInfo->lpReserved = pPeb->StartupInfo->lpReserved1;
|
||||
//lpStartupInfo->lpReserved2 = pPeb->StartupInfo->lpReserved2;
|
||||
|
||||
lpStartupInfo->hStdInput = pPeb->StartupInfo->hStdInput;
|
||||
lpStartupInfo->hStdOutput = pPeb->StartupInfo->hStdOutput;
|
||||
lpStartupInfo->hStdError = pPeb->StartupInfo->hStdError;
|
||||
|
||||
return;
|
||||
|
||||
lpStartupInfo->dwX = pPeb->ProcessInfo->dwX;
|
||||
lpStartupInfo->dwY = pPeb->ProcessInfo->dwY;
|
||||
lpStartupInfo->dwXSize = pPeb->ProcessInfo->dwXSize;
|
||||
lpStartupInfo->dwYSize = pPeb->ProcessInfo->dwYSize;
|
||||
lpStartupInfo->dwXCountChars = pPeb->ProcessInfo->dwXCountChars;
|
||||
lpStartupInfo->dwYCountChars = pPeb->ProcessInfo->dwYCountChars;
|
||||
lpStartupInfo->dwFillAttribute = pPeb->ProcessInfo->dwFillAttribute;
|
||||
lpStartupInfo->dwFlags = pPeb->ProcessInfo->dwFlags;
|
||||
lpStartupInfo->wShowWindow = pPeb->ProcessInfo->wShowWindow;
|
||||
// lpStartupInfo->cbReserved2 = pPeb->ProcessInfo->cbReserved;
|
||||
// lpStartupInfo->lpReserved = pPeb->ProcessInfo->lpReserved1;
|
||||
// lpStartupInfo->lpReserved2 = pPeb->ProcessInfo->lpReserved2;
|
||||
|
||||
lpStartupInfo->hStdInput = pPeb->ProcessInfo->hStdInput;
|
||||
lpStartupInfo->hStdOutput = pPeb->ProcessInfo->hStdOutput;
|
||||
lpStartupInfo->hStdError = pPeb->ProcessInfo->hStdError;
|
||||
}
|
||||
|
||||
|
||||
|
@ -515,12 +493,11 @@ FatalAppExitA (
|
|||
i++;
|
||||
}
|
||||
MessageTextW[i] = 0;
|
||||
|
||||
|
||||
return FatalAppExitW(uAction,MessageTextW);
|
||||
}
|
||||
|
||||
|
||||
|
||||
VOID
|
||||
STDCALL
|
||||
FatalAppExitW (
|
||||
|
@ -528,7 +505,7 @@ FatalAppExitW (
|
|||
LPCWSTR lpMessageText
|
||||
)
|
||||
{
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -124,7 +124,6 @@ RtlpCreateFirstThread(HANDLE ProcessHandle,
|
|||
sizeof(DupSectionHandle),
|
||||
&BytesWritten);
|
||||
|
||||
|
||||
Status = NtCreateThread(&ThreadHandle,
|
||||
THREAD_ALL_ACCESS,
|
||||
&ObjectAttributes,
|
||||
|
@ -230,23 +229,21 @@ RtlpCreatePeb(HANDLE ProcessHandle, PUNICODE_STRING CommandLine)
|
|||
ULONG PebSize;
|
||||
NT_PEB Peb;
|
||||
ULONG BytesWritten;
|
||||
PVOID StartupInfoBase;
|
||||
ULONG StartupInfoSize;
|
||||
PROCESSINFOW StartupInfo;
|
||||
PVOID ProcessInfoBase;
|
||||
ULONG ProcessInfoSize;
|
||||
PROCESSINFO ProcessInfo;
|
||||
|
||||
PebBase = (PVOID)PEB_BASE;
|
||||
PebSize = 0x1000;
|
||||
Status = NtAllocateVirtualMemory(ProcessHandle,
|
||||
&PebBase,
|
||||
0,
|
||||
&PebSize,
|
||||
MEM_COMMIT,
|
||||
PAGE_READWRITE);
|
||||
if (!NT_SUCCESS(Status))
|
||||
return(Status);
|
||||
|
||||
NtReadVirtualMemory(ProcessHandle,
|
||||
(PVOID)PEB_BASE,
|
||||
&Peb,
|
||||
sizeof(Peb),
|
||||
&BytesWritten);
|
||||
|
||||
memset(&Peb, 0, sizeof(Peb));
|
||||
Peb.StartupInfo = (PPROCESSINFOW)PEB_STARTUPINFO;
|
||||
Peb.ProcessInfo = (PPROCESSINFO)PEB_STARTUPINFO;
|
||||
|
||||
NtWriteVirtualMemory(ProcessHandle,
|
||||
(PVOID)PEB_BASE,
|
||||
|
@ -254,25 +251,25 @@ RtlpCreatePeb(HANDLE ProcessHandle, PUNICODE_STRING CommandLine)
|
|||
sizeof(Peb),
|
||||
&BytesWritten);
|
||||
|
||||
StartupInfoBase = (PVOID)PEB_STARTUPINFO;
|
||||
StartupInfoSize = 0x1000;
|
||||
ProcessInfoBase = (PVOID)PEB_STARTUPINFO;
|
||||
ProcessInfoSize = 0x1000;
|
||||
Status = NtAllocateVirtualMemory(ProcessHandle,
|
||||
&StartupInfoBase,
|
||||
&ProcessInfoBase,
|
||||
0,
|
||||
&StartupInfoSize,
|
||||
&ProcessInfoSize,
|
||||
MEM_COMMIT,
|
||||
PAGE_READWRITE);
|
||||
if (!NT_SUCCESS(Status))
|
||||
return(Status);
|
||||
|
||||
memset(&StartupInfo, 0, sizeof(StartupInfo));
|
||||
wcscpy(StartupInfo.CommandLine, CommandLine->Buffer);
|
||||
memset(&ProcessInfo, 0, sizeof(PROCESSINFO));
|
||||
wcscpy(ProcessInfo.CommandLine, CommandLine->Buffer);
|
||||
|
||||
DPRINT("StartupInfoSize %x\n",StartupInfoSize);
|
||||
DPRINT("ProcessInfoSize %x\n",ProcessInfoSize);
|
||||
NtWriteVirtualMemory(ProcessHandle,
|
||||
(PVOID)PEB_STARTUPINFO,
|
||||
&StartupInfo,
|
||||
StartupInfoSize,
|
||||
&ProcessInfo,
|
||||
ProcessInfoSize,
|
||||
&BytesWritten);
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
|
@ -283,14 +280,11 @@ NTSTATUS STDCALL
|
|||
RtlCreateUserProcess(PUNICODE_STRING ApplicationName,
|
||||
PSECURITY_DESCRIPTOR ProcessSd,
|
||||
PSECURITY_DESCRIPTOR ThreadSd,
|
||||
WINBOOL bInheritHandles,
|
||||
DWORD dwCreationFlags,
|
||||
// LPVOID lpEnvironment,
|
||||
// LPCWSTR lpCurrentDirectory,
|
||||
// LPSTARTUPINFO lpStartupInfo,
|
||||
PCLIENT_ID ClientId,
|
||||
PHANDLE ProcessHandle,
|
||||
PHANDLE ThreadHandle)
|
||||
WINBOOL bInheritHandles,
|
||||
DWORD dwCreationFlags,
|
||||
PCLIENT_ID ClientId,
|
||||
PHANDLE ProcessHandle,
|
||||
PHANDLE ThreadHandle)
|
||||
{
|
||||
HANDLE hSection, hProcess, hThread;
|
||||
NTSTATUS Status;
|
||||
|
@ -398,3 +392,4 @@ RtlCreateUserProcess(PUNICODE_STRING ApplicationName,
|
|||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* EOF */
|
||||
|
|
|
@ -62,32 +62,22 @@ static NTSTATUS LdrCreatePeb(HANDLE ProcessHandle)
|
|||
ULONG PebSize;
|
||||
NT_PEB Peb;
|
||||
ULONG BytesWritten;
|
||||
|
||||
|
||||
|
||||
PebBase = (PVOID)PEB_BASE;
|
||||
PebSize = 0x1000;
|
||||
Status = ZwAllocateVirtualMemory(ProcessHandle,
|
||||
&PebBase,
|
||||
0,
|
||||
&PebSize,
|
||||
MEM_COMMIT,
|
||||
PAGE_READWRITE);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return(Status);
|
||||
}
|
||||
|
||||
|
||||
|
||||
memset(&Peb, 0, sizeof Peb);
|
||||
|
||||
Peb.StartupInfo = (PPROCESSINFOW) PEB_STARTUPINFO;
|
||||
|
||||
Peb.ProcessInfo = (PPROCESSINFO) PEB_STARTUPINFO;
|
||||
|
||||
ZwWriteVirtualMemory(ProcessHandle,
|
||||
(PVOID)PEB_BASE,
|
||||
&Peb,
|
||||
sizeof(Peb),
|
||||
&BytesWritten);
|
||||
|
||||
|
||||
/* FIXME: Create ProcessInfo block */
|
||||
|
||||
return(STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include <string.h>
|
||||
#include <internal/string.h>
|
||||
#include <internal/id.h>
|
||||
#include <internal/teb.h>
|
||||
|
||||
//#define NDEBUG
|
||||
#include <internal/debug.h>
|
||||
|
@ -109,6 +110,44 @@ VOID PiDeleteProcess(PVOID ObjectBody)
|
|||
(VOID)MmReleaseMmInfo((PEPROCESS)ObjectBody);
|
||||
}
|
||||
|
||||
|
||||
static NTSTATUS
|
||||
PsCreatePeb(HANDLE ProcessHandle)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
PVOID PebBase;
|
||||
ULONG PebSize;
|
||||
NT_PEB Peb;
|
||||
ULONG BytesWritten;
|
||||
|
||||
PebBase = (PVOID)PEB_BASE;
|
||||
PebSize = 0x1000;
|
||||
Status = NtAllocateVirtualMemory(ProcessHandle,
|
||||
&PebBase,
|
||||
0,
|
||||
&PebSize,
|
||||
MEM_COMMIT,
|
||||
PAGE_READWRITE);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
return(Status);
|
||||
}
|
||||
|
||||
memset(&Peb, 0, sizeof(Peb));
|
||||
|
||||
ZwWriteVirtualMemory(ProcessHandle,
|
||||
(PVOID)PEB_BASE,
|
||||
&Peb,
|
||||
sizeof(Peb),
|
||||
&BytesWritten);
|
||||
|
||||
DbgPrint ("PsCreatePeb: Peb created at %x\n", PebBase);
|
||||
// DPRINT("PsCreatePeb: Peb created at %x\n", PebBase);
|
||||
|
||||
return(STATUS_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
PKPROCESS KeGetCurrentProcess(VOID)
|
||||
/*
|
||||
* FUNCTION: Returns a pointer to the current process
|
||||
|
@ -210,7 +249,15 @@ NtCreateProcess (
|
|||
KeAcquireSpinLock(&PsProcessListLock, &oldIrql);
|
||||
InsertHeadList(&PsProcessListHead, &KProcess->ProcessListEntry);
|
||||
KeReleaseSpinLock(&PsProcessListLock, oldIrql);
|
||||
|
||||
|
||||
Status = PsCreatePeb (*ProcessHandle);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
// DPRINT("NtCreateProcess() Peb creation failed: Status %x\n",Status);
|
||||
DbgPrint ("NtCreateProcess() Peb creation failed: Status %x\n",Status);
|
||||
return(Status);
|
||||
}
|
||||
|
||||
/*
|
||||
* FIXME: I don't what I'm supposed to know with a section handle
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue