Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

ulpc.h File Reference

#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

Go to the source code of this file.

Classes

struct  _TLPC_PORTMSG
struct  _PAGE

Defines

#define PORT_NAME   L"\\RPC Control\\LpcTestPort"
#define TLPC_MAX_MSG_DATA_LENGTH   16

Typedefs

typedef _TLPC_PORTMSG TLPC_PORTMSG
typedef _TLPC_PORTMSGPTLPC_PORTMSG
typedef _PAGE PAGE
typedef _PAGEPPAGE

Functions

PPORT_MESSAGE InitTlpcMsg (PTLPC_PORTMSG Msg, PVOID Context, ULONG MsgLength)
BOOLEAN CheckTlpcMsg (NTSTATUS Status, PTLPC_PORTMSG Msg)
BOOLEAN ShowHandleOrStatus (NTSTATUS Status, HANDLE Handle)
BOOLEAN ShowStatus (NTSTATUS Status)
NTSTATUS SendRequest (ULONG Level, PSZ ThreadName, HANDLE PortHandle, PVOID Context, ULONG MsgLength, PTLPC_PORTMSG CallBackTarget, BOOLEAN ServerCallingClient)
VOID EnterThread (PSZ ThreadName, ULONG Context)

Variables

UNICODE_STRING PortName
char * LpcMsgTypes []
SECURITY_QUALITY_OF_SERVICE DynamicQos
PCH ClientMemoryBase = 0
ULONG ClientMemorySize = 0
PCH ServerMemoryBase = 0
ULONG ServerMemoryDelta = 0
PCH EnterString = ">>>>>>>>>>"
PCH InnerString = "||||||||||"
PCH LeaveString = "<<<<<<<<<<"


Define Documentation

#define PORT_NAME   L"\\RPC Control\\LpcTestPort"
 

Definition at line 30 of file ulpc.h.

Referenced by main().

#define TLPC_MAX_MSG_DATA_LENGTH   16
 

Definition at line 55 of file ulpc.h.

Referenced by ClientThread(), and InitTlpcMsg().


Typedef Documentation

typedef struct _PAGE PAGE
 

typedef struct _PAGE * PPAGE
 

typedef struct _TLPC_PORTMSG * PTLPC_PORTMSG
 

typedef struct _TLPC_PORTMSG TLPC_PORTMSG
 

Referenced by main().


Function Documentation

BOOLEAN CheckTlpcMsg NTSTATUS  Status,
PTLPC_PORTMSG  Msg
 

Definition at line 101 of file ulpc.h.

References ClientMemoryBase, _TLPC_PORTMSG::Data, EXCEPTION_EXECUTE_HANDLER, FALSE, _TLPC_PORTMSG::h, NT_SUCCESS, ServerMemoryDelta, Status, and TRUE.

Referenced by SendRequest(), and ServerThread().

00105 { 00106 ULONG i; 00107 ULONG ClientIndex; 00108 ULONG cbData = Msg->h.u1.s1.DataLength; 00109 ULONG Context; 00110 PULONG ServerMemoryPtr; 00111 PULONG ClientMemoryPtr; 00112 ULONG ExpectedContext; 00113 BOOLEAN Result; 00114 00115 if (!NT_SUCCESS( Status )) { 00116 fprintf( stderr, " - FAILED. Status == %X\n", Status ); 00117 return( FALSE ); 00118 } 00119 00120 if (Msg->h.u2.s2.Type == LPC_CONNECTION_REQUEST) { 00121 fprintf( stderr, " connection request" ); 00122 } 00123 else 00124 if (cbData) { 00125 Context = Msg->Data[ 0 ]; 00126 ClientIndex = Context & 0xF; 00127 ClientIndex -= 1; 00128 ClientMemoryPtr = (PULONG)(ClientMemoryBase + (ClientIndex * 0x1000)); 00129 for (i=1; i<(cbData/sizeof( ULONG )); i++) { 00130 if (Msg->h.u2.s2.Type == LPC_REPLY) { 00131 if (Msg->Data[ i ] != ((ULONG)ClientMemoryPtr + ServerMemoryDelta) || 00132 *ClientMemoryPtr != (ULONG)Context 00133 ) { 00134 fprintf( stderr, " incorrectly\n" ); 00135 fprintf( stderr, " Msg->Data[ %ld ] == %lx != %lx || %lx -> %lx != %lx\n", 00136 i, Msg->Data[ i ], (ULONG)ClientMemoryPtr + ServerMemoryDelta, 00137 ClientMemoryPtr, *ClientMemoryPtr, Context 00138 ); 00139 return( FALSE ); 00140 } 00141 00142 ClientMemoryPtr++; 00143 } 00144 else { 00145 ServerMemoryPtr = (PULONG)(Msg->Data[ i ]); 00146 try { 00147 ExpectedContext = *ServerMemoryPtr; 00148 Result = (ExpectedContext != Context) ? FALSE : TRUE; 00149 } 00150 except( EXCEPTION_EXECUTE_HANDLER ) { 00151 ExpectedContext = 0xFEFEFEFE; 00152 Result = FALSE; 00153 } 00154 00155 if (!Result) { 00156 fprintf( stderr, " incorrectly\n" ); 00157 fprintf( stderr, " Msg->Data[ %ld ] == %lx -> %lx != %lx\n", 00158 i, Msg->Data[ i ], ExpectedContext, Context 00159 ); 00160 return( FALSE ); 00161 } 00162 } 00163 } 00164 } 00165 00166 fprintf( stderr, " correctly\n" ); 00167 return( TRUE ); 00168 }

VOID EnterThread PSZ  ThreadName,
ULONG  Context
 

Definition at line 318 of file ulpc.h.

Referenced by ClientThread(), and ServerThread().

00322 { 00323 fprintf( stderr, "Entering %s thread, Context = 0x%lx\n", 00324 ThreadName, 00325 Context 00326 ); 00327 }

PPORT_MESSAGE InitTlpcMsg PTLPC_PORTMSG  Msg,
PVOID  Context,
ULONG  MsgLength
 

Definition at line 72 of file ulpc.h.

References ClientMemoryBase, _TLPC_PORTMSG::Data, _TLPC_PORTMSG::h, ServerMemoryDelta, and TLPC_MAX_MSG_DATA_LENGTH.

Referenced by SendRequest().

00077 { 00078 ULONG i; 00079 ULONG ClientIndex; 00080 ULONG cbData = MsgLength % (TLPC_MAX_MSG_DATA_LENGTH * sizeof( ULONG )); 00081 PULONG ClientMemoryPtr; 00082 00083 Msg->h.u1.Length = ((sizeof( Msg->h ) + cbData) << 16) | cbData; 00084 Msg->h.u2.ZeroInit = 0; 00085 ClientIndex = (ULONG)Context & 0xF; 00086 ClientIndex -= 1; 00087 if (cbData) { 00088 Msg->Data[ 0 ] = (ULONG)Context; 00089 ClientMemoryPtr = (PULONG)(ClientMemoryBase + (ClientIndex * 0x1000)); 00090 for (i=1; i<(cbData/sizeof(ULONG)); i++) { 00091 *ClientMemoryPtr = (ULONG)Context; 00092 Msg->Data[ i ] = (ULONG)ClientMemoryPtr + ServerMemoryDelta; 00093 ClientMemoryPtr++; 00094 } 00095 } 00096 00097 return( (PPORT_MESSAGE)Msg ); 00098 }

NTSTATUS SendRequest ULONG  Level,
PSZ  ThreadName,
HANDLE  PortHandle,
PVOID  Context,
ULONG  MsgLength,
PTLPC_PORTMSG  CallBackTarget,
BOOLEAN  ServerCallingClient
 

Definition at line 208 of file ulpc.h.

References CheckTlpcMsg(), EnterString, _TLPC_PORTMSG::h, InitTlpcMsg(), InnerString, LeaveString, NtReplyWaitReplyPort(), NtRequestWaitReplyPort(), NTSTATUS(), NULL, PortHandle, Request(), and Status.

Referenced by ClientThread(), and ServerThread().

00217 { 00218 NTSTATUS Status; 00219 TLPC_PORTMSG Request, Reply; 00220 PTEB Teb = NtCurrentTeb(); 00221 00222 fprintf( stderr, "%.*sEnter SendRequest, %lx.%lx", 00223 Level, EnterString, 00224 Teb->ClientId.UniqueProcess, 00225 Teb->ClientId.UniqueThread 00226 ); 00227 00228 InitTlpcMsg( &Request, Context, MsgLength ); 00229 if (CallBackTarget == NULL) { 00230 fprintf( stderr, " - Request"); 00231 } 00232 else { 00233 Request.h.u2.s2.Type = LPC_REQUEST; 00234 Request.h.ClientId = CallBackTarget->h.ClientId; 00235 Request.h.MessageId = CallBackTarget->h.MessageId; 00236 fprintf( stderr, " - Callback to %lx.%lx, ID: %ld", 00237 Request.h.ClientId.UniqueProcess, 00238 Request.h.ClientId.UniqueThread, 00239 Request.h.MessageId 00240 ); 00241 } 00242 00243 fprintf( stderr, " (%ld bytes)...\n", Request.h.u1.s1.DataLength ); 00244 Status = NtRequestWaitReplyPort( PortHandle, 00245 (PPORT_MESSAGE)&Request, 00246 (PPORT_MESSAGE)&Reply 00247 ); 00248 fprintf( stderr, "%.*s %lx.%lx, ID: %u received ", 00249 Level, InnerString, 00250 Teb->ClientId.UniqueProcess, 00251 Teb->ClientId.UniqueThread, 00252 Reply.h.MessageId 00253 ); 00254 00255 if (Reply.h.u2.s2.Type == LPC_REPLY) { 00256 if (!CheckTlpcMsg( Status, &Reply )) { 00257 Status = STATUS_UNSUCCESSFUL; 00258 fprintf( stderr, "SendRequest got invalid reply message at %x\n", &Reply ); 00259 DbgBreakPoint(); 00260 } 00261 } 00262 else { 00263 fprintf( stderr, "callback from %lx.%lx, ID: %ld", 00264 Reply.h.ClientId.UniqueProcess, 00265 Reply.h.ClientId.UniqueThread, 00266 Reply.h.MessageId 00267 ); 00268 if (!CheckTlpcMsg( Status, &Reply )) { 00269 Status = STATUS_UNSUCCESSFUL; 00270 fprintf( stderr, "SendRequest got invalid callback message at %x\n", &Reply ); 00271 DbgBreakPoint(); 00272 } 00273 else { 00274 MsgLength = Reply.h.u1.s1.DataLength / 2; 00275 if (MsgLength) { 00276 Status = SendRequest( Level+1, 00277 ThreadName, 00278 PortHandle, 00279 Context, 00280 MsgLength, 00281 &Reply, 00282 ServerCallingClient 00283 ); 00284 } 00285 00286 if (!ServerCallingClient || Level > 1) { 00287 fprintf( stderr, "%.*s %lx.%lx sending ", 00288 Level, InnerString, 00289 Teb->ClientId.UniqueProcess, 00290 Teb->ClientId.UniqueThread 00291 ); 00292 fprintf( stderr, " callback (%u) reply to %lx.%lx, ID: %u (%ld bytes)...\n", 00293 Level, 00294 Reply.h.ClientId.UniqueProcess, 00295 Reply.h.ClientId.UniqueThread, 00296 Reply.h.MessageId, 00297 Reply.h.u1.s1.DataLength 00298 ); 00299 if (Level > 1) { 00300 Status = NtReplyWaitReplyPort( PortHandle, 00301 (PPORT_MESSAGE)&Reply 00302 ); 00303 } 00304 } 00305 } 00306 } 00307 00308 fprintf( stderr, "%.*sLeave SendRequest, %lx.%lx - Status == %X\n", 00309 Level, LeaveString, 00310 Teb->ClientId.UniqueProcess, 00311 Teb->ClientId.UniqueThread, 00312 Status 00313 ); 00314 return( Status ); 00315 }

BOOLEAN ShowHandleOrStatus NTSTATUS  Status,
HANDLE  Handle
 

Definition at line 172 of file ulpc.h.

References FALSE, Handle, NT_SUCCESS, Status, and TRUE.

Referenced by main(), and ServerHandleConnectionRequest().

00176 { 00177 if (NT_SUCCESS( Status )) { 00178 fprintf( stderr, " - Handle = 0x%lx\n", Handle ); 00179 return( TRUE ); 00180 } 00181 else { 00182 fprintf( stderr, " - *** FAILED *** Status == %X\n", Status ); 00183 return( FALSE ); 00184 } 00185 }

BOOLEAN ShowStatus NTSTATUS  Status  ) 
 

Definition at line 189 of file ulpc.h.

References FALSE, NT_SUCCESS, Status, and TRUE.

00192 { 00193 if (NT_SUCCESS( Status )) { 00194 fprintf( stderr, " - success\n" ); 00195 return( TRUE ); 00196 } 00197 else { 00198 fprintf( stderr, " - *** FAILED *** Status == %X\n", Status ); 00199 return( FALSE ); 00200 } 00201 }


Variable Documentation

PCH ClientMemoryBase = 0
 

Definition at line 62 of file ulpc.h.

Referenced by CheckTlpcMsg(), InitTlpcMsg(), main(), and ServerHandleConnectionRequest().

ULONG ClientMemorySize = 0
 

Definition at line 63 of file ulpc.h.

Referenced by main(), and ServerHandleConnectionRequest().

SECURITY_QUALITY_OF_SERVICE DynamicQos
 

Initial value:

{ SecurityImpersonation, SECURITY_DYNAMIC_TRACKING, TRUE }

Definition at line 49 of file ulpc.h.

Referenced by ConnectToTerminalServer(), CsrpConnectToServer(), DbgSspConnectToDbg(), DbgUiConnectToDbg(), main(), SepRmCommandServerThreadInit(), and TerminalServerRequestThread().

PCH EnterString = ">>>>>>>>>>"
 

Definition at line 203 of file ulpc.h.

Referenced by SendRequest().

PCH InnerString = "||||||||||"
 

Definition at line 204 of file ulpc.h.

Referenced by SendRequest().

PCH LeaveString = "<<<<<<<<<<"
 

Definition at line 205 of file ulpc.h.

Referenced by SendRequest().

char* LpcMsgTypes[]
 

Initial value:

{ "** INVALID **", "LPC_REQUEST", "LPC_REPLY", "LPC_DATAGRAM", "LPC_LOST_REPLY", "LPC_PORT_CLOSED", "LPC_CLIENT_DIED", "LPC_EXCEPTION", "LPC_DEBUG_EVENT", "LPC_ERROR_EVENT", "LPC_CONNECTION_REQUEST", NULL }

Definition at line 34 of file ulpc.h.

Referenced by ServerThread().

UNICODE_STRING PortName
 

Definition at line 32 of file ulpc.h.

Referenced by ComPortDBAdd(), ConnectToTerminalServer(), CtLnpQos(), CtLpcQos(), DbgSspConnectToDbg(), DbgUiConnectToDbg(), main(), NtConnectPort(), NtSecureConnectPort(), RtlCreateLpcServer(), and TerminalServerRequestThread().

PCH ServerMemoryBase = 0
 

Definition at line 64 of file ulpc.h.

Referenced by main(), and ServerHandleConnectionRequest().

ULONG ServerMemoryDelta = 0
 

Definition at line 65 of file ulpc.h.

Referenced by CheckTlpcMsg(), InitTlpcMsg(), main(), and ServerHandleConnectionRequest().


Generated on Sat May 15 19:45:52 2004 for test by doxygen 1.3.7