ReactOS 0.4.16-dev-401-g45b008d
creport.c
Go to the documentation of this file.
1/*
2 * reactos/apps/lpc/creport.c
3 *
4 * To be run in a real WNT 4.0 system to
5 * create an LPC named port.
6 *
7 * Use Russinovich' HandleEx to verify
8 * creport.exe owns the named LPC port
9 * you asked to create.
10 */
11#include <windows.h>
12#include <stdio.h>
13#include <stdlib.h>
14#define PROTO_LPC
15#include <ddk/ntddk.h>
16#include "dumpinfo.h"
17
18#define LPC_CONNECT_FLAG1 0x00000001
19#define LPC_CONNECT_FLAG2 0x00000010
20#define LPC_CONNECT_FLAG3 0x00000100
21#define LPC_CONNECT_FLAG4 0x00001000
22#define LPC_CONNECT_FLAG5 0x00010000
23
25(WINAPI * CreatePort)(
26 /*OUT PHANDLE PortHandle,*/
32 );
33
35(WINAPI * QueryObject)(
36 IN HANDLE ObjectHandle,
41 );
42
44(WINAPI * YieldExecution)(VOID);
45
46#define BUF_SIZE 1024
47#define MAXARG 5000000
48
49
50VOID
51TryCreatePort(char *port_name)
52{
53 DWORD Status = 0;
54 HANDLE Port = 0;
55 int i;
58 WORD Name [BUF_SIZE] = {0};
59 int dwx = 0;
60 char * port_name_save = port_name;
61
62 /*
63 * Convert the port's name to Unicode.
64 */
65 for (
66 PortName.Length = 0;
67 ( *port_name
69 );
70 )
71 {
72 Name[PortName.Length++] = (WORD) *port_name++;
73 }
74 Name[PortName.Length] = 0;
75
76 PortName.Length = PortName.Length * sizeof (WORD);
79 /*
80 * Prepare the port object attributes.
81 */
83 sizeof (OBJECT_ATTRIBUTES);
84 ObjectAttributes.RootDirectory =
85 NULL;
86 ObjectAttributes.ObjectName =
87 & PortName;
88 ObjectAttributes.Attributes =
89 0; //OBJ_CASE_INSENSITIVE --> STATUS_INVALID_PARAMETER ==> case sensitive!;
90 ObjectAttributes.SecurityDescriptor =
91 NULL;
92 ObjectAttributes.SecurityQualityOfService =
93 NULL;
94 /*
95 * Try to issue a connection request.
96 */
97 Port = 0;
98 Status = CreatePort(
99 & Port,
101 0, /* ACCESS_MASK? */
102 0, /* Unknown3 */
104 );
105 if (Status == STATUS_SUCCESS)
106 {
107 DumpInfo(
108 Name,
109 Status,
110 "created",
111 Port
112 );
113 /* Hot waiting */
114 for (dwx=0; dwx<MAXARG; ++dwx)
115 {
116 YieldExecution();
117 }
118 if (FALSE == CloseHandle(Port))
119 {
120 printf(
121 "Could not close the port handle %08X.\n",
122 Port
123 );
124 }
125 return;
126 }
127 printf(
128 "Creating port \"%s\" failed (Status = %08X).\n",
129 port_name_save,
130 Status
131 );
132}
133
134
135main( int argc, char * argv[] )
136{
137 HINSTANCE ntdll;
138
139 if (argc != 2)
140 {
141 printf("WNT LPC Port Creator\n");
142 printf("Usage: %s [port_name]\n",argv[0]);
144 }
145 printf("LoadLibrary(NTDLL)\n");
146 ntdll = LoadLibrary("NTDLL");
147 if (ntdll == NULL)
148 {
149 printf("Could not load NTDLL\n");
150 return EXIT_FAILURE;
151 }
152 printf("GetProcAddress(NTDLL.NtCreatePort)\n");
153 CreatePort = (VOID*) GetProcAddress(
154 ntdll,
155 "NtCreatePort"
156 );
157 if (CreatePort == NULL)
158 {
159 FreeLibrary(ntdll);
160 printf("Could not find NTDLL.NtCreatePort\n");
161 return EXIT_FAILURE;
162 }
163 printf("GetProcAddress(NTDLL.NtQueryObject)\n");
164 QueryObject = (VOID*) GetProcAddress(
165 ntdll,
166 "NtQueryObject"
167 );
168 if (QueryObject == NULL)
169 {
170 FreeLibrary(ntdll);
171 printf("Could not find NTDLL.NtQueryObject\n");
172 return EXIT_FAILURE;
173 }
174 printf("GetProcAddress(NTDLL.NtYieldExecution)\n");
175 YieldExecution = (VOID*) GetProcAddress(
176 ntdll,
177 "NtYieldExecution"
178 );
179 if (YieldExecution == NULL)
180 {
181 FreeLibrary(ntdll);
182 printf("Could not find NTDLL.NtYieldExecution\n");
183 return EXIT_FAILURE;
184 }
185 printf("TryCreatePort(%s)\n",argv[1]);
187 printf("Done\n");
188 return EXIT_SUCCESS;
189}
190
191/* EOF */
static UNICODE_STRING PortName
static int argc
Definition: ServiceArgs.c:12
#define VOID
Definition: acefi.h:82
Definition: bufpool.h:45
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
IN CINT ObjectInformationClass
Definition: creport.c:37
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: creport.c:41
IN POBJECT_ATTRIBUTES PortAttributes OPTIONAL
Definition: creport.c:28
IN CINT OUT PVOID ObjectInformation
Definition: creport.c:38
#define MAXARG
Definition: creport.c:47
#define BUF_SIZE
Definition: creport.c:46
IN CINT OUT PVOID IN ULONG Length
Definition: creport.c:39
#define LPC_CONNECT_FLAG5
Definition: creport.c:22
IN POBJECT_ATTRIBUTES PortAttributes IN ACCESS_MASK DesiredAccess
Definition: creport.c:29
VOID TryCreatePort(char *port_name)
Definition: creport.c:51
IN POBJECT_ATTRIBUTES PortAttributes IN ACCESS_MASK IN DWORD IN ULONG Flags
Definition: creport.c:32
IN POBJECT_ATTRIBUTES PortAttributes IN ACCESS_MASK IN DWORD Unknown3
Definition: creport.c:30
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define NTSTATUS
Definition: precomp.h:19
#define CloseHandle
Definition: compat.h:739
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
int main()
Definition: test.c:6
VOID DumpInfo(LPCWSTR Name, NTSTATUS Status, LPCWSTR Comment, HANDLE Port)
Definition: dumpinfo.c:70
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
#define printf
Definition: freeldr.h:97
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
CPPORT Port[4]
Definition: headless.c:35
#define EXIT_FAILURE
Definition: jerror.c:33
#define argv
Definition: mplay32.c:18
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
#define exit(n)
Definition: config.h:202
#define STATUS_SUCCESS
Definition: shellext.h:65
USHORT MaximumLength
Definition: env_spec_w32.h:370
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t * PULONG
Definition: typedefs.h:59
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define OUT
Definition: typedefs.h:40
CONST int CINT
Definition: umtypes.h:124
struct _OBJECT_ATTRIBUTES OBJECT_ATTRIBUTES
#define LoadLibrary
Definition: winbase.h:3887
#define WINAPI
Definition: msvc.h:6