diff options
author | Adam <you@example.com> | 2020-05-17 05:51:50 +0200 |
---|---|---|
committer | Adam <you@example.com> | 2020-05-17 05:51:50 +0200 |
commit | e611b132f9b8abe35b362e5870b74bce94a1e58e (patch) | |
tree | a5781d2ec0e085eeca33cf350cf878f2efea6fe5 /private/ntos/rtl/uexec2.c | |
download | NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.gz NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.bz2 NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.lz NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.xz NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.tar.zst NT4.0-e611b132f9b8abe35b362e5870b74bce94a1e58e.zip |
Diffstat (limited to 'private/ntos/rtl/uexec2.c')
-rw-r--r-- | private/ntos/rtl/uexec2.c | 258 |
1 files changed, 258 insertions, 0 deletions
diff --git a/private/ntos/rtl/uexec2.c b/private/ntos/rtl/uexec2.c new file mode 100644 index 000000000..8174d71b6 --- /dev/null +++ b/private/ntos/rtl/uexec2.c @@ -0,0 +1,258 @@ +/*++ + +Copyright (c) 1989 Microsoft Corporation + +Module Name: + + uexec.c + +Abstract: + + Test program for the NT OS User Mode Runtime Library (URTL) + +Author: + + Mark Lucovsyt (markl) 14-Jun-1990 + +Revision History: + +--*/ + +#include <nt.h> +#include <ntrtl.h> +#include <nturtl.h> + +NTSTATUS +main( + IN ULONG argc, + IN PCH argv[], + IN PCH envp[], + IN ULONG DebugParameter OPTIONAL + ) +{ + NTSTATUS st; + STRING ImagePathName; + UNICODE_STRING ConfigFilePathname; + RTL_USER_PROCESS_INFORMATION ProcessInformation; + PEB_SM_DATA PebSessionInformation; + HANDLE FileHandle; + ULONG FileIndexNumber; + IO_STATUS_BLOCK IoStatus; + OBJECT_ATTRIBUTES ObjectAttributes; + FILE_INTERNAL_INFORMATION FileInformation; + PPEB Peb; + + Peb = NtCurrentPeb(); + RtlZeroMemory(&PebSessionInformation,sizeof(PebSessionInformation)); + + // + // If we started from cli then do all this work to + // pass thru stdin + // + + if ( !Peb->Sm.StandardInput.FileHandle ) { + + RtlInitUnicodeString(&ConfigFilePathname,L"\\SystemRoot\\nt.cfg"); + + // + // Open the file + // + + InitializeObjectAttributes( + &ObjectAttributes, + &ConfigFilePathname, + OBJ_CASE_INSENSITIVE, + NULL, + NULL + ); + + st = NtOpenFile( + &FileHandle, + SYNCHRONIZE | FILE_READ_DATA, + &ObjectAttributes, + &IoStatus, + FILE_SHARE_READ, + 0 + ); + + if (!NT_SUCCESS( st )) { + DbgPrint("NtOpenFile: %wZ failed 0x%lx\n",&ConfigFilePathname,st); + ASSERT(NT_SUCCESS(st)); + } + + // + // get the file serial number + // + + st = NtQueryInformationFile( + FileHandle, + &IoStatus, + (PVOID) &FileInformation, + sizeof(FileInformation), + FileInternalInformation + ); + + if (!NT_SUCCESS( st )) { + DbgPrint("NtQueryInformationFile: %wZ failed 0x%lx\n",&ConfigFilePathname,st); + ASSERT(NT_SUCCESS(st)); + } + + PebSessionInformation.Length = sizeof(PebSessionInformation); + PebSessionInformation.StandardInput.FileHandle = FileHandle; + PebSessionInformation.StandardInput.Context = (PVOID) FileInformation.IndexNumber; + + RtlInitString(&ImagePathName,"\\A:\\uexec2.exe"); + + st = RtlCreateUserProcess( + &ImagePathName, + NULL, + NULL, + NULL, + FALSE, + NULL, + NULL, + NULL, + &ProcessInformation, + &PebSessionInformation + ); + + ASSERT(NT_SUCCESS(st)); + + NtResumeThread(ProcessInformation.Thread,NULL); + NtWaitForSingleObject(ProcessInformation.Process,FALSE,NULL); + NtClose(ProcessInformation.Process); + NtClose(ProcessInformation.Thread); + NtTerminateProcess(NtCurrentProcess(),STATUS_SUCCESS); + + } else { + + if ( !Peb->Sm.StandardOutput.FileHandle ) { + + // + // Started from this program. Stdin is inherited + // + + st = NtQueryInformationFile( + Peb->Sm.StandardInput.FileHandle, + &IoStatus, + (PVOID) &FileInformation, + sizeof(FileInformation), + FileInternalInformation + ); + + if (!NT_SUCCESS( st )) { + DbgPrint("NtQueryInformationFile: failed 0x%lx\n",st); + ASSERT(NT_SUCCESS(st)); + } + + ASSERT(Peb->Sm.StandardInput.Context == (PVOID) FileInformation.IndexNumber); + + PebSessionInformation.Length = sizeof(PebSessionInformation); + PebSessionInformation.StandardInput.FileHandle = (HANDLE)PEB_STDIO_HANDLE_SUBSYS; + PebSessionInformation.StandardOutput.FileHandle = Peb->Sm.StandardInput.FileHandle; + PebSessionInformation.StandardOutput.Context = (PVOID) FileInformation.IndexNumber; + + RtlInitString(&ImagePathName,"\\A:\\uexec2.exe"); + + st = RtlCreateUserProcess( + &ImagePathName, + NULL, + NULL, + NULL, + FALSE, + NULL, + NULL, + NULL, + &ProcessInformation, + &PebSessionInformation + ); + + ASSERT(NT_SUCCESS(st)); + + NtResumeThread(ProcessInformation.Thread,NULL); + NtWaitForSingleObject(ProcessInformation.Process,FALSE,NULL); + NtClose(ProcessInformation.Process); + NtClose(ProcessInformation.Thread); + NtTerminateProcess(NtCurrentProcess(),STATUS_SUCCESS); + + } else { + + ASSERT(Peb->Sm.StandardInput.FileHandle == (HANDLE)PEB_STDIO_HANDLE_SUBSYS); + + if ( !Peb->Sm.StandardError.FileHandle ) { + + // + // Started by this program with StandardOutput Inherited + // + + st = NtQueryInformationFile( + Peb->Sm.StandardOutput.FileHandle, + &IoStatus, + (PVOID) &FileInformation, + sizeof(FileInformation), + FileInternalInformation + ); + + if (!NT_SUCCESS( st )) { + DbgPrint("NtQueryInformationFile: failed 0x%lx\n",st); + ASSERT(NT_SUCCESS(st)); + } + + ASSERT(Peb->Sm.StandardOutput.Context == (PVOID) FileInformation.IndexNumber); + + PebSessionInformation.Length = sizeof(PebSessionInformation); + PebSessionInformation.StandardInput.FileHandle = (HANDLE)PEB_STDIO_HANDLE_SUBSYS; + PebSessionInformation.StandardOutput.FileHandle = (HANDLE)PEB_STDIO_HANDLE_PM; + PebSessionInformation.StandardError.FileHandle = Peb->Sm.StandardOutput.FileHandle; + PebSessionInformation.StandardError.Context = (PVOID) FileInformation.IndexNumber; + + RtlInitString(&ImagePathName,"\\A:\\uexec2.exe"); + + st = RtlCreateUserProcess( + &ImagePathName, + NULL, + NULL, + NULL, + FALSE, + NULL, + NULL, + NULL, + &ProcessInformation, + &PebSessionInformation + ); + + ASSERT(NT_SUCCESS(st)); + + NtResumeThread(ProcessInformation.Thread,NULL); + NtWaitForSingleObject(ProcessInformation.Process,FALSE,NULL); + NtClose(ProcessInformation.Process); + NtClose(ProcessInformation.Thread); + NtTerminateProcess(NtCurrentProcess(),STATUS_SUCCESS); + + } else { + + ASSERT(Peb->Sm.StandardOutput.FileHandle == (HANDLE)PEB_STDIO_HANDLE_PM); + + // + // Started by this program with StandardError Inherited + // + + st = NtQueryInformationFile( + Peb->Sm.StandardError.FileHandle, + &IoStatus, + (PVOID) &FileInformation, + sizeof(FileInformation), + FileInternalInformation + ); + + if (!NT_SUCCESS( st )) { + DbgPrint("NtQueryInformationFile: failed 0x%lx\n",st); + ASSERT(NT_SUCCESS(st)); + } + + ASSERT(Peb->Sm.StandardError.Context == (PVOID) FileInformation.IndexNumber); + NtTerminateProcess(NtCurrentProcess(),STATUS_SUCCESS); + } + } + } +} |