3 * reactos/apps/lpc/conport.c
5 * To be run in a real WNT 4.0 system with
6 * "\SmApiPort" as argument. Do not try to
7 * connect to "\Windows\ApiPort" since that
10 * Use Russinovich' HandleEx to verify
11 * conport.exe owns two unnamed LPC ports:
12 * the one created by kernel32.dll connecting
13 * to csrss.exe, and one connected to here.
15 * 19990627 (Emanuele Aliberti)
16 * Initial implementation.
18 * Dump object's attributes moved in dumpinfo.c.
24 #include <ddk/ntddk.h>
27 #define LPC_CONNECT_FLAG1 0x00000001
28 #define LPC_CONNECT_FLAG2 0x00000010
29 #define LPC_CONNECT_FLAG3 0x00000100
30 #define LPC_CONNECT_FLAG4 0x00001000
31 #define LPC_CONNECT_FLAG5 0x00010000
34 (STDCALL * ConnectPort)(
35 OUT PHANDLE PortHandle,
36 IN PUNICODE_STRING PortName,
37 IN POBJECT_ATTRIBUTES ObjectAttributes,
46 (STDCALL * QueryObject)(
47 IN HANDLE ObjectHandle,
48 IN CINT ObjectInformationClass,
49 OUT PVOID ObjectInformation,
51 OUT PULONG ResultLength
55 (STDCALL * YieldExecution)(VOID);
58 #define MAXARG 1000000
62 TryConnectPort(char *port_name)
67 UNICODE_STRING PortName;
68 OBJECT_ATTRIBUTES ObjectAttributes;
69 WORD Name [BUF_SIZE] = {0};
71 char * port_name_save = port_name;
74 * Convert the port's name to Unicode.
79 && (PortName.Length < BUF_SIZE)
83 Name[PortName.Length++] = (WORD) *port_name++;
85 Name[PortName.Length] = 0;
87 PortName.Length = PortName.Length * sizeof (WORD);
88 PortName.MaximumLength = PortName.Length + sizeof (WORD);
89 PortName.Buffer = (PWSTR) Name;
91 * Prepare the port object attributes.
93 ObjectAttributes.Length =
94 sizeof (OBJECT_ATTRIBUTES);
95 ObjectAttributes.RootDirectory =
97 ObjectAttributes.ObjectName =
99 ObjectAttributes.Attributes =
100 OBJ_CASE_INSENSITIVE;
101 ObjectAttributes.SecurityDescriptor =
103 ObjectAttributes.SecurityQualityOfService =
106 * Try to issue a connection request.
109 Status = ConnectPort(
110 & Port, /* & PortHandle */
111 & PortName, /* & PortName */
112 & ObjectAttributes, /* & PortAttributes */
113 NULL, /* & SecurityQos */
114 NULL, /* & SectionInfo */
115 NULL, /* & MapInfo */
116 NULL, /* & MaxMessageSize */
117 LPC_CONNECT_FLAG5 /* & ConnectInfoLength */
119 if (Status == STATUS_SUCCESS)
128 for (dwx=0; dwx<MAXARG; ++dwx)
132 if (FALSE == CloseHandle(Port))
135 "Could not close the port handle %08X.\n",
142 "Connection to port \"%s\" failed (Status = %08X).\n",
149 main( int argc, char * argv[] )
155 printf("WNT LPC Port Connector\n");
156 printf("Usage: %s [port_name]\n",argv[0]);
159 printf("LoadLibrary(NTDLL)\n");
160 ntdll = LoadLibrary("NTDLL");
163 printf("Could not load NTDLL\n");
166 printf("GetProcAddress(NTDLL.NtConnectPort)\n");
167 ConnectPort = (VOID*) GetProcAddress(
171 if (ConnectPort == NULL)
174 printf("Could not find NTDLL.NtConnectPort\n");
177 printf("GetProcAddress(NTDLL.NtQueryObject)\n");
178 QueryObject = (VOID*) GetProcAddress(
182 if (QueryObject == NULL)
185 printf("Could not find NTDLL.NtQueryObject\n");
188 printf("GetProcAddress(NTDLL.NtYieldExecution)\n");
189 YieldExecution = (VOID*) GetProcAddress(
193 if (YieldExecution == NULL)
196 printf("Could not find NTDLL.NtYieldExecution\n");
199 printf("TryConnectPort(%s)\n",argv[1]);
200 TryConnectPort(argv[1]);