- src_vd.zip
- src
- CoreMnt.sln
- CoreMnt
- CoreMnt_user
- CoreMntTest
- ddk_build.bat
- deploy.bat
- drvCppLib
- build.bat
- buildchk_wxp_x86.log
- cxx.h
- drvCppLib_vs7.vcproj
- drvCppLib_vs8.vcproj
- drvCppLib_vs9.vcproj
- drvCppLib_vs9.vcproj.DEV.genesis.user
- drvCppLib_vs9.vcproj.genesisnote.genesis.user
- 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
- objchk_wxp_x86
- _objects.mac
- i386
- except.obj
- libcpp.obj
- rtti.obj
- rtti.cpp
- Sources
- drvUtils
- mnt_cmn
- STLPort
- usrUtils
|
#ifndef KERNEL_RESOURCE_WRAPPER_H_INCLUDED
#define KERNEL_RESOURCE_WRAPPER_H_INCLUDED
extern "C"
{
#include "ntifs.h"
}
#include "sync.h"
#include "new"
#include "exception"
namespace utils
{
template<EVENT_TYPE eventType>
class KernelCustomEvent
{
KEVENT event_;
KernelCustomEvent(const KernelCustomEvent&);
KernelCustomEvent& operator =(const KernelCustomEvent&);
public:
KernelCustomEvent(BOOLEAN initState = FALSE)
{
KeInitializeEvent(&event_, eventType, initState);
}
KEVENT* getPointer()
{
return &event_;
}
void wait()
{
NTSTATUS status = KeWaitForSingleObject(&event_, Executive, KernelMode, FALSE, NULL);
if(!NT_SUCCESS(status))
{
KdPrint((__FUNCTION__" KeWaitForMutexObject fail %08X\n", status));
__asm int 3;
}
}
bool readState()
{
return KeReadStateEvent(&event_) != 0;
}
void set()
{
KeSetEvent(&event_, 0, FALSE);
}
void reset()
{
KeClearEvent(&event_);
}
};
typedef KernelCustomEvent<NotificationEvent> KernelNotificationEvent;
typedef KernelCustomEvent<SynchronizationEvent> KernelSynchronizationEvent;
template<class LockType>
class ReverseSemaphore
{
KernelNotificationEvent readyEvent_;
LockType lock_;
int count_;
public:
ReverseSemaphore():count_(0), readyEvent_(TRUE){}
KEVENT* getPointer()
{
return readyEvent_.getPointer();
}
void enter()
{
AutoGuard<LockType> guard(lock_);
++count_;
readyEvent_.reset();
}
void leave()
{
bool ready = false;
{
AutoGuard<LockType> guard(lock_);
--count_;
ASSERT(count_ >= 0);
if(count_ == 0)
ready = true;
}
if(ready)
readyEvent_.set();
}
};
typedef ReverseSemaphore<Mutex> ReverseMutexSemaphore;
typedef AutoGuard<ReverseMutexSemaphore> AutoReverseMutexSemaphore;
typedef AutoGuardPtr<ReverseMutexSemaphore> AutoReverseMutexSemaphorePtr;
//---------------------------------------------------------------
// auto_ptr_kernel
template<class ResourceType>
class auto_ptr_kernel
{
ResourceType * m_pResource;
public:
auto_ptr_kernel()
: m_pResource(0)
{
}
explicit auto_ptr_kernel(ResourceType * pResource)
: m_pResource( pResource )
{
}
auto_ptr_kernel(auto_ptr_kernel & source_ptr)
:
m_pResource( source_ptr.get() )
{
source_ptr.m_pResource = 0;
}
auto_ptr_kernel & operator = (auto_ptr_kernel & source_ptr)
{
m_pResource = source_ptr.get();
source_ptr.m_pResource = 0;
return *this;
}
~auto_ptr_kernel()
{
if (m_pResource)
ExFreePool( m_pResource );
}
const ResourceType * get() const { return m_pResource; }
ResourceType * get() { return m_pResource; }
ResourceType * release()
{
ResourceType * pRes = m_pResource;
m_pResource = 0;
return pRes;
}
ResourceType * operator -> () { return m_pResource; }
const ResourceType * operator -> () const { return m_pResource; }
ResourceType & operator * () { return *m_pResource; }
const ResourceType & operator * () const { return *m_pResource; }
// non-standard
ResourceType ** getPtr2()
{
if (m_pResource)
throw std::exception("Cannot access member");
return &m_pResource;
}
};
//--------------------------------------------------------------
inline void * AllocatePaged(int iAdditionalSize)
{
void * pData = ExAllocatePool(PagedPool, iAdditionalSize);
if (!pData)
throw std::bad_alloc();
return pData;
}
//--------------------------------------------------------------
template<class Type>
Type * AllocatePaged(int iAdditionalSize=0)
{
void * pData = ExAllocatePool(PagedPool, sizeof(Type)+iAdditionalSize);
if (!pData)
throw std::bad_alloc();
memset(pData, 0, sizeof(Type));
return (Type * )pData;
}
//--------------------------------------------------------------
template<class Type>
Type * AllocateNonPaged(int iAdditionalSize=0)
{
void * pData = ExAllocatePool(NonPagedPool, sizeof(Type)+iAdditionalSize);
if (!pData)
throw std::bad_alloc();
memset(pData, 0, sizeof(Type));
return (Type * )pData;
}
//--------------------------------------------------------------
}//namespace utils
#endif
|
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.