NTSTATUS WINAPI Hook_NtQueryDirectoryFile(IN HANDLE FileHandle,IN HANDLE Event OPTIONAL,
IN PIO_APC_ROUTINE ApcRoutine OPTIONAL,IN PVOID ApcContext OPTIONAL,
OUT PIO_STATUS_BLOCK IoStatusBlock,OUT PVOID FileInformation,
IN ULONG FileInformationLength,IN FILE_INFORMATION_CLASS FileInformationClass,
IN BOOLEAN ReturnSingleEntry, IN PUNICODE_STRING FileName OPTIONAL,IN BOOLEAN RestartScan)
{
NTSTATUS Status=STATUS_SUCCESS;
Status=OldNtQueryDirectoryFile(FileHandle,Event,ApcRoutine,ApcContext,\
  IoStatusBlock,FileInformation,FileInformationLength,\
  FileInformationClass,ReturnSingleEntry,FileName,RestartScan);

if (!NT_SUCCESS(Status))
{
  return Status;
}

//////////////////////////////////
if (FileBothDirectoryInformation==FileInformationClass)
{
  FILE_BOTH_DIRECTORY_INFORMATION* pFileInfo = (FILE_BOTH_DIRECTORY_INFORMATION*)FileInformation;
  FILE_BOTH_DIRECTORY_INFORMATION* pLastFileInfo = NULL;
  BOOL bLastFlag=FALSE;
  do
  {
   bLastFlag=!(pFileInfo->NextEntryOffset);
   if (NULL!=wcsstr(pFileInfo->FileName,L"1.hook"))
   {
    OutputDebugStringW(L"已发现目标");
    if (bLastFlag) //链表里最后一个文件
    {

pLastFileInfo->NextEntryOffset=0;
     break;
    }
    else
    {
     int iPos = (ULONG)pFileInfo - (ULONG)FileInformation;
     int iLeft = (ULONG)FileInformationLength - iPos - pFileInfo->NextEntryOffset;

RtlCopyMemory( (PVOID)pFileInfo, (PVOID)( (char *)pFileInfo + pFileInfo->NextEntryOffset ), iLeft );
                      continue;
    }
   }

pLastFileInfo=pFileInfo;
   pFileInfo=(PFILE_BOTH_DIRECTORY_INFORMATION)((CHAR*)pFileInfo+pFileInfo->NextEntryOffset);

}while(!bLastFlag);
}
return Status;
}

http://www.cnblogs.com/lzjsky/archive/2010/12/01/1892702.html

04-04 23:54