- detectdriversrc.zip
- DetectDriverSrc
- DetectDriver
- src
- Common
- ddk_build.bat
- DetectDriver
- DetectDriver_vs9.sln
- DetectDriverGUI
- drvCppLib
- build.bat
- cxx.h
- drvCppLib_vs8.vcproj
- drvCppLib_vs9.vcproj
- except.c
- lib_copy
- _memicmp.obj
- _stricmp.obj
- _strnicm.obj
- atlssup.obj
- chkesp.obj
- chkstk.obj
- conv.lib
- eh.lib
- eh3valid.obj
- enable.obj
- exsup.obj
- exsup2.obj
- exsup3.obj
- info.txt
- inp.obj
- lldiv.obj
- lldvrm.obj
- llmul.obj
- llrem.obj
- llshl.obj
- llshr.obj
- longjmp.obj
- matherr.obj
- memccpy.obj
- memchr.obj
- memcmp.obj
- memcpy.obj
- memmove.obj
- memset.obj
- outp.obj
- rtc.lib
- sehprolg.obj
- sehsupp.obj
- setjmp.obj
- setjmp3.obj
- setjmpex.obj
- strcat.obj
- strchr.obj
- strcmp.obj
- strcspn.obj
- strdup.obj
- strlen.obj
- strncat.obj
- strncmp.obj
- strncpy.obj
- strnset.obj
- strpbrk.obj
- strrchr.obj
- strrev.obj
- strset.obj
- strspn.obj
- strstr.obj
- tlssup.obj
- tran.lib
- ulldiv.obj
- ulldvrm.obj
- ullrem.obj
- ullshr.obj
- libcpp.cpp
- libcpp.h
- MAKEFILE
- new.h
- rtti.cpp
- Sources
- drvCppLibTest
- drvSingleModeTest
- drvUtils
- HideDriver
- HideDriverGUI
- info.txt
- STLPort
- Utils
- UtilsPortable
- UtilsPortableUnitTest
- detectdriverbin.zip
- DetectDriverBin
- DetectDriverBin
- DetectDriver.sys
- DetectDriverGUI.exe
- HideDriver.sys
- HideDriverGUI.exe
|
#pragma once
#include "IFileChecker.h"
#include "ListUtils.h"
#include <boost/bind.hpp>
#include <vector>
namespace HideAlgorithm
{
typedef NTSTATUS(*OriginalHandlerWrapperPtr)(const NtQueryDirParams& params);
struct HideParams
{
const NtQueryDirParams& callParams;
IFileChecker* checker;
OriginalHandlerWrapperPtr wrapperPtr;
};
template<class InfoType>
inline bool
CheckFileEntry( utils::NtList* list,
const HideParams& params )
{
InfoType* info = (InfoType*)list;
return params.checker->CheckFile(info->FileName,
info->FileNameLength/2,
params.callParams);
}
inline void
ShiftBuffer(utils::NtList* pList,utils::NtList* newBegin)
{
size_t shiftSize = newBegin - pList;
size_t infoSize = utils::GetListSize(pList);
size_t newInfoSize = infoSize - shiftSize;
std::vector<char> buffer(newInfoSize);
memcpy(&buffer.front(),newBegin,newInfoSize);
memcpy(pList,&buffer.front(),newInfoSize);
}
template<class InfoType>
inline NTSTATUS
FirstEntryProcessor( const HideParams& params )
{
utils::NtList* pList =
(utils::NtList*)params.callParams.FileInformation;
utils::NtList* pCurEntry = pList;
while(true)
{
if(!CheckFileEntry<InfoType>(pCurEntry,params))
{
if(pList == pCurEntry)
break; // Nothing to hide
ShiftBuffer(pList,pCurEntry);
break; // First entry hiding complete
}
// This entry needs to be hidden
if( utils::IsEntryLast(pCurEntry) == false )
{
// Move to next entry to check
// This need to shift buffer only once
pCurEntry = utils::GetNextEntryPointer(pCurEntry);
}
else
{
// Reached last entry
// This mean that all data needs to be hidden
// Try to request more data
NTSTATUS status = params.wrapperPtr(params.callParams);
if( !NT_SUCCESS(status) )
return status;
// Move to begin and resume checking
pCurEntry = pList;
}
}
return STATUS_SUCCESS;
}
template<class InfoType>
inline NTSTATUS
NextEntryProcessor( const HideParams& params )
{
utils::NtList* pList =
(utils::NtList*)params.callParams.FileInformation;
if( utils::IsEntryLast(pList) )
return STATUS_SUCCESS;
utils::CutFromListByFakeOffset_If(pList,
boost::bind(&CheckFileEntry<InfoType>,_1,params));
return STATUS_SUCCESS;
}
template<class InfoType>
inline NTSTATUS
HideFileImpl( const HideParams& params )
{
NTSTATUS status = FirstEntryProcessor<InfoType>(params);
if( !NT_SUCCESS(status) )
return status;
status = NextEntryProcessor<InfoType>(params);
if( !NT_SUCCESS(status) )
return status;
return STATUS_SUCCESS;
}
template<class InfoType>
inline NTSTATUS
HideFile( const HideParams& params )
{
try
{
return HideFileImpl<InfoType>(params);
}
catch(const std::exception& ex)
{
#ifdef KdPrint // For use in user mode environment
KdPrint( (__FUNCTION__" std::exception: %s\n",ex.what()) );
#endif
}
return STATUS_SUCCESS;
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
ApriorIT is a software research and development company specializing in cybersecurity and data management technology engineering. We work for a broad range of clients from Fortune 500 technology leaders to small innovative startups building unique solutions.
As Apriorit offers integrated research&development services for the software projects in such areas as endpoint security, network security, data security, embedded Systems, and virtualization, we have strong kernel and driver development skills, huge system programming expertise, and are reals fans of research projects.
Our specialty is reverse engineering, we apply it for security testing and security-related projects.
A separate department of Apriorit works on large-scale business SaaS solutions, handling tasks from business analysis, data architecture design, and web development to performance optimization and DevOps.
Official site: https://www.apriorit.com
Clutch profile: https://clutch.co/profile/apriorit
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.