3 * reactos/apps/lpc/creport.c
5 * To be run in a real WNT 4.0 system to
6 * create an LPC named port.
8 * Use Russinovich' HandleEx to verify
9 * creport.exe owns the named LPC port
10 * you asked to create.
16 #include <ddk/ntddk.h>
19 #define LPC_CONNECT_FLAG1 0x00000001
20 #define LPC_CONNECT_FLAG2 0x00000010
21 #define LPC_CONNECT_FLAG3 0x00000100
22 #define LPC_CONNECT_FLAG4 0x00001000
23 #define LPC_CONNECT_FLAG5 0x00010000
26 (STDCALL * CreatePort)(
27 /*OUT PHANDLE PortHandle,*/
29 IN POBJECT_ATTRIBUTES PortAttributes OPTIONAL,
30 IN ACCESS_MASK DesiredAccess,
36 (STDCALL * QueryObject)(
37 IN HANDLE ObjectHandle,
38 IN CINT ObjectInformationClass,
39 OUT PVOID ObjectInformation,
41 OUT PULONG ResultLength
45 (STDCALL * YieldExecution)(VOID);
48 #define MAXARG 5000000
52 TryCreatePort(char *port_name)
57 UNICODE_STRING PortName;
58 OBJECT_ATTRIBUTES ObjectAttributes;
59 WORD Name [BUF_SIZE] = {0};
61 char * port_name_save = port_name;
64 * Convert the port's name to Unicode.
69 && (PortName.Length < BUF_SIZE)
73 Name[PortName.Length++] = (WORD) *port_name++;
75 Name[PortName.Length] = 0;
77 PortName.Length = PortName.Length * sizeof (WORD);
78 PortName.MaximumLength = PortName.Length + sizeof (WORD);
79 PortName.Buffer = (PWSTR) Name;
81 * Prepare the port object attributes.
83 ObjectAttributes.Length =
84 sizeof (OBJECT_ATTRIBUTES);
85 ObjectAttributes.RootDirectory =
87 ObjectAttributes.ObjectName =
89 ObjectAttributes.Attributes =
90 0; //OBJ_CASE_INSENSITIVE --> STATUS_INVALID_PARAMETER ==> case sensitive!;
91 ObjectAttributes.SecurityDescriptor =
93 ObjectAttributes.SecurityQualityOfService =
96 * Try to issue a connection request.
102 0, /* ACCESS_MASK? */
106 if (Status == STATUS_SUCCESS)
115 for (dwx=0; dwx<MAXARG; ++dwx)
119 if (FALSE == CloseHandle(Port))
122 "Could not close the port handle %08X.\n",
129 "Creating port \"%s\" failed (Status = %08X).\n",
136 main( int argc, char * argv[] )
142 printf("WNT LPC Port Creator\n");
143 printf("Usage: %s [port_name]\n",argv[0]);
146 printf("LoadLibrary(NTDLL)\n");
147 ntdll = LoadLibrary("NTDLL");
150 printf("Could not load NTDLL\n");
153 printf("GetProcAddress(NTDLL.NtCreatePort)\n");
154 CreatePort = (VOID*) GetProcAddress(
158 if (CreatePort == NULL)
161 printf("Could not find NTDLL.NtCreatePort\n");
164 printf("GetProcAddress(NTDLL.NtQueryObject)\n");
165 QueryObject = (VOID*) GetProcAddress(
169 if (QueryObject == NULL)
172 printf("Could not find NTDLL.NtQueryObject\n");
175 printf("GetProcAddress(NTDLL.NtYieldExecution)\n");
176 YieldExecution = (VOID*) GetProcAddress(
180 if (YieldExecution == NULL)
183 printf("Could not find NTDLL.NtYieldExecution\n");
186 printf("TryCreatePort(%s)\n",argv[1]);
187 TryCreatePort(argv[1]);