I m writing Filter Driver, and for this used sample of minifilter in WDK in preoperation callback
intercepted IRP_MJ_DIRECTORY_CONTROL to iterate file or folder of any folder and to Hide file or folder I used same concepts using in intercepting of ZwQueryDirectoryFile.
Following code please let me know what is the problem.
UNICODE_STRING EntryName;
UNICODE_STRING uStrParent;
NTSTATUS rc;
PUNICODE_STRING puStr = NULL;
PVOID FileInformation = NULL;
UNICODE_STRING defaultName;
UNICODE_STRING uStr, uStr1;
PUNICODE_STRING nameToUse;
NTSTATUS status;
PFILE_BOTH_DIR_INFORMATION stDirInfo;
PFILE_BOTH_DIR_INFORMATION dir_info;
PFLT_FILE_NAME_INFORMATION nameInfo = NULL;
char *ptrParentDir = NULL;
PCHAR ptr = NULL;
char *buffer = NULL;
wchar_t wcFullPathName[1024];
int BytesReturned =0;
int bytesreturned=0;
int i = 0,iPos = 0;
int j = 0 ,iLeft =0;
BOOLEAN bDone;
nameToUse = &FltObjects->FileObject->FileName;//&nameInfo->Name;
RtlInitUnicodeString(&uStr,L"log.txt");
if((Data->Iopb->MajorFunction == IRP_MJ_DIRECTORY_CONTROL))
{
DbgPrint(“IRP_MJ_DIRECTORY_CONTROL\n”);
DbgPrint(“Full Path : %ws\n”,FltObjects->FileObject->FileName.Buffer);
stDirInfo = (PFILE_BOTH_DIR_INFORMATION)Data->Iopb->Parameters.DirectoryControl.QueryDirectory.DirectoryBuffer;
ProbeForRead(stDirInfo,sizeof(FILE_BOTH_DIR_INFORMATION),1);
EntryName.Length = (USHORT)stDirInfo->FileNameLength;
EntryName.MaximumLength = EntryName.Length;
EntryName.Buffer = &stDirInfo->FileName[0];
bytesreturned=0;
while(1)
{
ProbeForRead(&stDirInfo->FileName[0],sizeof(WCHAR),1);
DbgPrint(“File Name : %ws\n”,&stDirInfo->FileName[0]);
uStr1.Length = (USHORT)stDirInfo->FileNameLength;
uStr1.MaximumLength = uStr1.Length;
uStr1.Buffer = &stDirInfo->FileName[0];
//RtlInitUnicodeString(&uStr1,&stDirInfo->FileName[0]);
if(RtlCompareUnicodeString(&uStr1,&uStr,TRUE)==0)
{
DbgPrint(“File Compared”);
if (stDirInfo->NextEntryOffset==0)
break;
stDirInfo=(PFILE_BOTH_DIR_INFORMATION)(((PUCHAR)stDirInfo)+stDirInfo->NextEntryOffset);
continue;
}
if (stDirInfo->NextEntryOffset!=0)
{
bytesreturned+=stDirInfo->NextEntryOffset;
DbgPrint(“BytesRetured = %d, Offset Not Zero = %d\n”,bytesreturned,stDirInfo->NextEntryOffset);
}
else
{
bytesreturned+=sizeof(*stDirInfo)-sizeof(WCHAR)+stDirInfo->FileNameLength;
DbgPrint(“BytesRetured = %d, Offset = %d\n”,bytesreturned,stDirInfo->NextEntryOffset);
}
//ptr+=stDirInfo->NextEntryOffset;
//DbgPrint(“ptr = %d\n”,(ULONG)buffer);
if (stDirInfo->NextEntryOffset==0)
{
DbgPrint(“Quit from inner loop”);
break;
}
stDirInfo=(PFILE_BOTH_DIR_INFORMATION)(((PUCHAR)stDirInfo)+stDirInfo->NextEntryOffset);
DbgPrint(“Next offset is not zero\n”);
}// while end
if (bytesreturned>0)
{
DbgPrint(“BytesRetured > = %d\n”,bytesreturned);
}
Data->IoStatus.Information=bytesreturned;
RtlCopyMemory((PVOID)Data->Iopb->Parameters.DirectoryControl.QueryDirectory.DirectoryBuffer, (PVOID)stDirInfo, bytesreturned);
}