All,
I want my user mode service to pass back a variable length reply to a
kernel mode message sent by the Driver. the reply is variable length
because, depending on the length of the buffer sought by the driver in the
FltSendMessage, the service creats and fills the buffer with data and sends
back.
Now, after reading the documentation, I wrote the following code:
// This is the structure the user mode will fill up and send down to Driver
typedef struct _MY_REPLY_CONTEXT {
BOOLEAN bReadStatus; // Tells
whether the read was a success or not
PUCHAR pBUffer[1]; // Contains the
data sought by the Kernel
// Size of this
buffer is not required as
// we already
pass length in Request message
} MY_REPLY_CONTEXT, *PMY_REPLY_CONTEXT;
typedef struct _MY_REPLY_FROM_USERLAND_MESSAGE {
FILTER_REPLY_HEADER ReplyHeader; // Must be the first
member of this structure
MY_REPLY_CONTEXT Reply; // This is the reply
from user
} MY_REPLY_FROM_USERLAND_MESSAGE, *PMY_REPLY_FROM_USERLAND_MESSAGE;
In the user land thread…
ULONG Len = sizeof(MY_REPLY_CONTEXT) + pTranslationRequest->uLen; //
the pTranslationRequest->uLen was received from driver
ULONG TotalLen = sizeof(FILTER_REPLY_HEADER) + Len;
pReplyMessage = (PMY_REPLY_FROM_USERLAND_MESSAGE) malloc(TotalLen );
memset(pReplyMessage, 0, TotalLen );
pReplyMessage->ReplyHeader.Status = 0;
pReplyMessage->ReplyHeader.MessageId = pMessage->MessageHeader.MessageId;
pReplyMessage->Reply.bReadStatus = TRUE;
memcpy(pReplyMessage->Reply.pBUffer, pBuff, ullBytesRead); //ullBytesRead
is equal to pTranslationRequest->uLen, pBuff is legit, I saw the contents
in the debugger
hr = FilterReplyMessage( pTPCtx->hPort,
(PFILTER_REPLY_HEADER) pReplyMessage,
Len ); // since in scanner sample they say we
only need to pass the length of our portion of the structure
When this executes, in the driver the buffer is all junk.
Can some one please let me know what I am doing incorrectly.
thanks
ami