ReactOS  0.4.14-dev-49-gfb4591c
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,*/
27  PVOID Buffer,
28  IN POBJECT_ATTRIBUTES PortAttributes OPTIONAL,
31  IN ULONG Flags
32  );
33 
35 (WINAPI * QueryObject)(
36  IN HANDLE ObjectHandle,
39  IN ULONG Length,
41  );
42 
44 (WINAPI * YieldExecution)(VOID);
45 
46 #define BUF_SIZE 1024
47 #define MAXARG 5000000
48 
49 
50 VOID
51 TryCreatePort(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
68  && (PortName.Length < BUF_SIZE)
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 
135 main( 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]);
186  TryCreatePort(argv[1]);
187  printf("Done\n");
188  return EXIT_SUCCESS;
189 }
190 
191 /* EOF */
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
CPPORT Port[4]
Definition: headless.c:34
static int argc
Definition: ServiceArgs.c:12
#define IN
Definition: typedefs.h:38
CONST int CINT
Definition: umtypes.h:124
#define CloseHandle
Definition: compat.h:398
#define LoadLibrary
Definition: winbase.h:3679
USHORT MaximumLength
Definition: env_spec_w32.h:370
NTSTATUS(WINAPI *CreatePort)(PVOID Buffer
uint16_t * PWSTR
Definition: typedefs.h:54
IN POBJECT_ATTRIBUTES PortAttributes IN ACCESS_MASK IN DWORD IN ULONG Flags
Definition: creport.c:28
main(int argc, char *argv[])
Definition: creport.c:135
#define BUF_SIZE
Definition: creport.c:46
#define argv
Definition: mplay32.c:18
IN POBJECT_ATTRIBUTES PortAttributes IN ACCESS_MASK IN DWORD Unknown3
Definition: creport.c:28
VOID TryCreatePort(char *port_name)
Definition: creport.c:51
#define EXIT_SUCCESS
Definition: rdjpgcom.c:55
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
VOID DumpInfo(LPCWSTR Name, NTSTATUS Status, LPCWSTR Comment, HANDLE Port)
Definition: dumpinfo.c:70
smooth NULL
Definition: ftsmooth.c:416
IN CINT OUT PVOID ObjectInformation
Definition: creport.c:37
struct _OBJECT_ATTRIBUTES OBJECT_ATTRIBUTES
#define FreeLibrary(x)
Definition: compat.h:405
#define WINAPI
Definition: msvc.h:8
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
#define EXIT_FAILURE
Definition: jerror.c:33
#define MAXARG
Definition: creport.c:47
#define VOID
Definition: acefi.h:82
#define LPC_CONNECT_FLAG5
Definition: creport.c:22
Status
Definition: gdiplustypes.h:24
IN CINT ObjectInformationClass
Definition: creport.c:37
unsigned int * PULONG
Definition: retypes.h:1
#define OUT
Definition: typedefs.h:39
unsigned int ULONG
Definition: retypes.h:1
IN CINT OUT PVOID IN ULONG OUT PULONG ResultLength
Definition: creport.c:37
#define GetProcAddress(x, y)
Definition: compat.h:410
void exit(int exitcode)
Definition: _exit.c:33
IN CINT OUT PVOID IN ULONG Length
Definition: creport.c:37
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
IN POBJECT_ATTRIBUTES PortAttributes OPTIONAL
Definition: creport.c:28
return STATUS_SUCCESS
Definition: btrfs.c:2966
IN POBJECT_ATTRIBUTES PortAttributes IN ACCESS_MASK DesiredAccess
Definition: creport.c:28
ULONG ACCESS_MASK
Definition: nt_native.h:40
#define printf
Definition: config.h:203
IN PUNICODE_STRING PortName
Definition: conport.c:35