码迷,mamicode.com
首页 > 其他好文 > 详细

Ring3下Hook NtQueryDirectoryFile隐藏文件

时间:2016-06-28 23:33:10      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:

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

Ring3下Hook NtQueryDirectoryFile隐藏文件

标签:

原文地址:http://www.cnblogs.com/findumars/p/5625137.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!