I am using TDI filter driver to get which process want to access network.
When some apps want to access network, I want to notify app.
I use asynchronous DeviceIoControl and then WaitforSingleObject in my app.
In driver, I put this DeviceIoControl irp to a list and return pending status.
The function does work.
But if there are two processes want to access network, the information
of one process is lost because there are no pending irps in list
. I think the problem is in my app.
How to solve this problem?
Following is the code:
//some codes in driver:
void NotifyApp()
{
appMonitorListEntry = NdisInterlockedRemoveHeadList(
&Globals.appMonitorList,
&Globals.appMonitorListLock);
if (appMonitorListEntry == NULL) return ;
appMonitorIRP = CONTAINING_RECORD(appMonitorListEntry,
APPMLET,
qLink);
appIrp = appMonitorIRP->irp;
appMonitorIRP->irp = NULL;
NdisFreeMemory(appMonitorIRP, sizeof(APPMLET), 0);
appInfo = (PRing3Permission)((PUCHAR)appIrp->AssociatedIrp.SystemBuffer);
…
appIrp->IoStatus.Status = STATUS_SUCCESS;
appIrp->IoStatus.Information = sizeof(Ring3Permission);
IoCompleteRequest(appIrp, IO_NO_INCREMENT);
}
//some codes in my console:
DWORD WaitForNotify(LPVOID lpmm)
{
OVERLAPPED Overlap;
HANDLE hEvent;
DWORD junk;
int i;
HANDLE frameAppHandle;
CStartNatPage *m_natpage= (CStartNatPage *)lpmm;
//overlapped
frameAppHandle=CreateFile(“\\.\NdisHook”,
GENERIC_READ|GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED |
FILE_FLAG_DELETE_ON_CLOSE,
NULL);
if(frameAppHandle==INVALID_HANDLE_VALUE) return 1;
m_thEvent.ResetEvent();
while(monitorApp)
{
hEvent=::CreateEvent(NULL,TRUE,0,NULL);
Overlap.Internal=0;
Overlap.InternalHigh=0;
Overlap.Offset=0;
Overlap.OffsetHigh=0;
Overlap.hEvent=hEvent;
memset(&appInfo, 0, sizeof(Ring3Permission));
DeviceIoControl(frameAppHandle,IOCTL_WAIT_NOTIFY,
NULL,0,&appInfo,sizeof(appInfo),&junk,&Overlap);
i=::WaitForSingleObjectEx(hEvent,INFINITE,false);
GetOverlappedResult(frameAppHandle,&Overlap,&junk,false);
if (monitorApp)
{
::PostMessage((HWND)m_natpage->m_hWnd, WM_APPINFO, 0, 0);
}
CloseHandle(hEvent);
}
CloseHandle(frameAppHandle);
m_thEvent.SetEvent();
return 1;
}
////////////////////////////////////////////////////////////