summaryrefslogtreecommitdiffstats
path: root/private/ntos/rtl/uexec.c
blob: 71fe7a684f036ee900a2a951bb7f2d468c99a809 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*++

Copyright (c) 1989  Microsoft Corporation

Module Name:

    uexec.c

Abstract:

    Test program for the NT OS User Mode Runtime Library (URTL)

Author:

    Steve Wood (stevewo) 18-Aug-1989

Revision History:

--*/

#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>

#include <string.h>

PVOID MyHeap = NULL;

NTSTATUS
main(
    IN ULONG argc,
    IN PCH argv[],
    IN PCH envp[],
    IN ULONG DebugParameter OPTIONAL
    )
{
    NTSTATUS Status;
    STRING ImagePathName;
    PCHAR PathVariable, *pp;
    CHAR ImageNameBuffer[ 128 ];
    RTL_USER_PROCESS_INFORMATION ProcessInformation;
    PRTL_USER_PROCESS_PARAMETERS ProcessParameters;
    ULONG i, CountBytes, envc, Bogus;
    PSTRING DstString;
    PCH Src, Dst;
    PCH Parameters[ RTL_USER_PROC_PARAMS_DEBUGFLAG+2 ];

    Parameters[ RTL_USER_PROC_PARAMS_IMAGEFILE ] =
         "Full Path Specification of Image File goes here";

    Parameters[ RTL_USER_PROC_PARAMS_CMDLINE ] =
         "Complete Command Line goes here";

    Parameters[ RTL_USER_PROC_PARAMS_DEBUGFLAG ] =
         "Debugging String goes here";

    Parameters[ RTL_USER_PROC_PARAMS_DEBUGFLAG+1 ] = NULL;

    MyHeap = RtlProcessHeap();

#if DBG
    DbgPrint( "Entering UEXEC User Mode Test Program\n" );
    DbgPrint( "argc = %ld\n", argc );
    for (i=0; i<=argc; i++) {
        DbgPrint( "argv[ %ld ]: %s\n",
                  i,
                  argv[ i ] ? argv[ i ] : "<NULL>"
                );
        }
    DbgPrint( "\n" );
    for (i=0; envp[i]; i++) {
        DbgPrint( "envp[ %ld ]: %s\n", i, envp[ i ] );
        }

#endif

    PathVariable = "\\SystemRoot";
    if (envp != NULL) {
        pp = envp;
        while (Src = *pp++) {
            if (!_strnicmp( Src, "PATH=", 5 )) {
                PathVariable = Src+5;
                break;
                }
            }
        }

    DbgPrint( "PATH=%s\n", PathVariable );

    ProcessParameters = (PRTL_USER_PROCESS_PARAMETERS)
                            RtlAllocateHeap( MyHeap, 0, 2048 );
    ProcessParameters->MaximumLength = 2048;

    argv[ argc ] = NULL;
    Status = RtlVectorsToProcessParameters(
                argv,
                envp,
                Parameters,
                ProcessParameters
                );

    ImagePathName.Buffer = ImageNameBuffer;
    ImagePathName.Length = 0;
    ImagePathName.MaximumLength = sizeof( ImageNameBuffer );
    if (RtlSearchPath( PathVariable, "uexec1.exe", NULL, &ImagePathName )) {
        Status = RtlCreateUserProcess( &ImagePathName,
                                       NULL,
                                       NULL,
                                       NULL,
                                       TRUE,
                                       NULL,
                                       NULL,
                                       ProcessParameters,
                                       &ProcessInformation,
                                       NULL
                                     );
        if (NT_SUCCESS( Status )) {
            Status = NtResumeThread( ProcessInformation.Thread, &Bogus );
            if (NT_SUCCESS( Status )) {
#if DBG
                DbgPrint( "UEXEC waiting for UEXEC1...\n" );
#endif
                Status = NtWaitForSingleObject( ProcessInformation.Process,
                                                TRUE,
                                                NULL
                                              );
                }
            }
        }
    else {
        DbgPrint( "UEXEC1.EXE not found in %s\n", PathVariable );
        Status = STATUS_UNSUCCESSFUL;
        }

#if DBG
    DbgPrint( "Leaving UEXEC User Mode Test Program\n" );
#endif

    return( Status );
}