여기 수준 보아하니 쓰레기들이라 별로 기대는 안한다만..
필터에서 여러개 메세지를 동신에 여러게 보냈어...
근데 워커 쓰레드에서는 그메세지를 하나 밖에 못봤었어 다른일 하느라...
그런데 신기한건 다른 여러게 메세지가 어딘가 버퍼에 저장되어 있는지 사라지지 않고 차례차례 들어오더군...
그 이유를 아는 사람?
자세한 코드는 여기 보여주마
어플에서 메세지 받는 부분은 이거고
private void worker()
{
int ovlpOffset = Marshal.OffsetOf(typeof(NOTIFICATION_MESSAGE), "Ovlp").ToInt32();
IntPtr messagePtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(NOTIFICATION_MESSAGE)));
try
{
while (true)
{
NOTIFICATION_MESSAGE notifyMessage = new NOTIFICATION_MESSAGE();
Marshal.StructureToPtr(notifyMessage, messagePtr, false); // memset to 0
long res = NativeMethods.FilterGetMessage(
portPtr,
messagePtr,
ovlpOffset,
messagePtr + ovlpOffset);
HRESULT hr = new HRESULT((uint)res);
if (hr != Win32Error.ERROR_IO_PENDING.ToHRESULT())
break;
uint numOfBytes = 0;
UIntPtr completionKeyPtr = UIntPtr.Zero;
IntPtr overlappedPtr = IntPtr.Zero;
if (!NativeMethods.GetQueuedCompletionStatus(completionPort,
ref numOfBytes,
ref completionKeyPtr,
ref overlappedPtr,
int.MaxValue))
{
break;
}
NOTIFICATION_MESSAGE message = (NOTIFICATION_MESSAGE)Marshal.PtrToStructure(overlappedPtr - ovlpOffset, typeof(NOTIFICATION_MESSAGE));
-->여기서 한참 잡고 있다고 가정해도 메세지가 사라지지 않음
//add to list
fltMsgQueue.Enqueue(message);
}
}
catch
{
}
finally
{
Marshal.FreeHGlobal(messagePtr);
messagePtr = IntPtr.Zero;
}
}
이거는 필터코드
try{
//
// Set notification info.
//
notification.NotifyType = NotifyType;
replyLength = sizeof(REPLY_DATA);
notification.BytesToScan = sizeof(MSG_SEND_DATA);
RtlCopyMemory(¬ification.Contents, MsgData, sizeof(MSG_SEND_DATA));
UNICODE_STRING tmpPath;
RtlInitUnicodeString(&tmpPath, notification.Contents.FilePath);
LOG_PRINT(LOGFL_DEBUG, ("rgFilter!SendLogMessage: Msg sending command : [%d], pid : [%d] File: [%wZ]\n",
notification.Contents.Command, notification.Contents.Pid, &tmpPath));
//
// Send message with msg data and recevied reply data.
//
status = FltSendMessage(gFilterData.Filter,
&gFilterData.ClientPort,
¬ification,
sizeof(NOTIFICATION),
&replyData,
&replyLength,
NULL);
if (STATUS_SUCCESS == status) {
LOG_PRINT(LOGFL_DEBUG, ("rgFilter!SendLogMessage: Msg replied command : [%d], pid : [%d]\n",
replyData.Command, replyData.Pid));
}
//
// in case of reject command recevied , 1: allow 2: reject
//
result = replyData.Command;
}
except(EXCEPTION_EXECUTE_HANDLER) {
//
// The copy failed, return an error, failing the operation.
//
Data->IoStatus.Status = GetExceptionCode();
Data->IoStatus.Information = 0;
leave;
}
ㅎㅌㅊ 어그로 D- 드립니다
설마 코드도 이해 못하는건 아니겠지... > _<
처보기만 하고 왜 반응 들이 없노
참고로 윈플그램은 c# 이고 드라이버는 C로 되있는거임. C#이나 C 고수는 없는건가
자바사무원이라서 웹뜰웹뜰 하느라 씨샵 꺼내볼 시간이 없네효 ㅠㅠ
플그래머//되있->돼있 (되어 = 돼임) [리듬 맞춤법 봇♬]
배우는 중이라 잘 모르겠음다
검색하다 타고들어와서 1년이 넘은 글이라 답글을 볼 지는 모르겠는데 FltSendMessage 마지막 파라메터가 time이라 보낼 수 있을때까지 pending 걸린거다 null (0) 아니고 타임 주면 그 시간만큼 지나고 필터에서 에러로 떨어질거임
fltsendmessage에서 replyBuffer값이 널이아닌데 유저모드에서 reply를 안보냈으니까 reply올때까지 기다리는거 같음
oo과 sdsds 의 응답을 조합하면 됨.
각 필터에선 reply를 얻을 때(유저에서 읽고 응답할 때까지) 까지 무한정 대기 (타임아웃 == null) 필터에서 이런식으로 여러개가 동시에 오면 CompletionPort에 해당 메세지들이 쌓이고 유저단에선 GQCS 할때마다 쌓인 건들이 순서대로 전달. 커널 <-> 어플 뿐 아니라 IOCP로 구현한 소켓 통신도 이렇게 동작.