Ring3下Hook NtQueryDirectoryFile隐藏文件
Posted 朝闻道
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ring3下Hook NtQueryDirectoryFile隐藏文件相关的知识,希望对你有一定的参考价值。
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隐藏文件的主要内容,如果未能解决你的问题,请参考以下文章
HOOK集合----SSDT Inline Hook(X86 win7)