⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cusbevent.cpp

📁 一个内核开发的usb加密解密驱动
💻 CPP
字号:


//--------------------------------------------------------------------
// Include
#include "stdafx.h"
#include "CUSBEvent.h"

//--------------------------------------------------------------------
// class 

/*@
  @func		CUSBCntlEvent(void)
  @brief	Constructor
  @*/
CUSBEvent::CUSBEvent(void)
{
	this->m_wstrEventName.clear();
	this->m_hEvent = NULL;
}

/*@
  @func		~CUSBCntlEvent(void)
  @brief	Destructor
  @*/
CUSBEvent::~CUSBEvent(void)
{
	this->Close();
}

/*@
  @func		BOOL CreateWithName(PWCHAR pwszModuleName, BOOL bManualReset)
  @brief	Initialization
  @arg		[I]		PWCHAR	pwszModuleName		:Pointer of module name
  @arg		[I]		BOOL	bManualReset		:It is specified whether it is a manual reset object. 
  @return	TRUE	:Success
			FALSE	:Failure
  @*/
BOOL CUSBEvent::CreateWithName(PWCHAR pwszModuleName, BOOL bManualReset)
{
	//LOGDBG((1, LOG_ID_CMMN, L"start"));

	if (pwszModuleName == NULL || wcslen(pwszModuleName) == 0) {
		//LOGERR((1, LOG_ID_CMMN, L"Parameter Error"));
		return FALSE;
	}
	wstring wstrEventName = CM_EVENT_PRENAME;
	wstrEventName.append(pwszModuleName);

	return this->Create((PWCHAR)wstrEventName.c_str(), bManualReset);
}

/*@
  @func		BOOL Create(PWCHAR pwszEventName, BOOL bManualReset)
  @brief	Initialization
  @arg		[I]		PWCHAR	pwszEventName		:Pointer of Ibentol name
  @arg		[I]		BOOL	bManualReset		:It is specified whether it is a manual reset object. 
  @return	TRUE	:Success
			FALSE	:Failure
  @*/
BOOL CUSBEvent::Create(PWCHAR pwszEventName, BOOL bManualReset)
{
	//LOGDBG((1, LOG_ID_CMMN, L"start"));

	if (pwszEventName == NULL || wcslen(pwszEventName) == 0) {
		//LOGERR((1, LOG_ID_CMMN, L"Parameter Error"));
		return FALSE;
	}
	this->m_wstrEventName = pwszEventName;

	if (!this->m_cUsbSdMgr.GenerateSdOfSystemAndEveryoneFullAccess(CUSBCntlSdMgr::driEvent)){
		return FALSE;
	}
	//SERVICE_STOPEVENT:Service stop event making
	this->m_hEvent = ::CreateEventW(&(this->m_cUsbSdMgr.m_SecAttr), bManualReset, FALSE, this->m_wstrEventName.c_str());
	if (this->m_hEvent == NULL) {
		//LOGERR((3, LOG_ID_CMMN, L"CreateEventW Error", ::GetLastError()));
		return FALSE;
//	} else if (::GetLastError() == ERROR_ALREADY_EXISTS) {
//		//LOGERR((3, LOG_ID_CMMN, L"CreateEventW Error", ::GetLastError()));
//		return FALSE;
	}

	//LOGDBG((1, LOG_ID_CMMN, L"end"));
	return TRUE;
}

/*@
  @func		BOOL OpenWithName(PWCHAR pwszModuleName)
  @brief	Event opening processing
  @arg		[I]		PWCHAR	pwszModuleName		:Pointer of module name
  @return	TRUE	:Success
			FALSE	:Failure
  @*/
BOOL CUSBEvent::OpenWithName(PWCHAR pwszModuleName)
{
	//LOGDBG((1, LOG_ID_CMMN, L"start"));

	if (pwszModuleName == NULL || wcslen(pwszModuleName) == 0) {
		//LOGERR((1, LOG_ID_CMMN, L"Parameter Error"));
		return FALSE;
	}
	wstring wstrEventName = CM_EVENT_PRENAME;
	wstrEventName.append(pwszModuleName);

	return this->Open((PWCHAR)wstrEventName.c_str());
}

/*@
  @func		BOOL OpenWithName(PWCHAR pwszEventName)
  @brief	Event opening processing
  @arg		[I]		PWCHAR	pwszEventName		:Pointer of Ibentol name
  @return	TRUE	:Success
			FALSE	:Failure
  @*/
BOOL CUSBEvent::Open(PWCHAR pwszEventName)
{
	//LOGDBG((1, LOG_ID_CMMN, L"start"));

	if (pwszEventName == NULL || wcslen(pwszEventName) == 0) {
		//LOGERR((1, LOG_ID_CMMN, L"Parameter Error"));
		return FALSE;
	}
	this->m_wstrEventName = pwszEventName;

	this->m_hEvent = ::OpenEventW(SYNCHRONIZE|EVENT_MODIFY_STATE, FALSE , this->m_wstrEventName.c_str());
	if (this->m_hEvent == NULL) {
		//LOGERR((3, LOG_ID_CMMN, L"OpenEventW Error", ::GetLastError()));
		return FALSE;
	}

	//LOGDBG((1, LOG_ID_CMMN, L"end"));
	return TRUE;
}

/*@
  @func		BOOL Close(void)
  @brief	Close of event
  @return	TRUE	:Success
			FALSE	:Failure
  @*/
BOOL CUSBEvent::Close(void)
{
	if (this->m_hEvent != NULL) {
		::CloseHandle(this->m_hEvent);
		this->m_hEvent = NULL;
	}
	return TRUE;
}

/*@
  @func		BOOL SetEvent(void)
  @brief	Making of event signal
  @return	TRUE	:Success
			FALSE	:Failure
  @*/
BOOL CUSBEvent::SetEvent(void)
{
	if (this->m_hEvent == NULL) {
		return FALSE;
	}
	return ::SetEvent(this->m_hEvent);
}

/*@
  @func		BOOL ResetEvent(void)
  @brief	Making of event non-signal
  @return	TRUE	:Success
			FALSE	:Failure
  @*/
BOOL CUSBEvent::ResetEvent(void)
{
	if (this->m_hEvent == NULL) {
		return FALSE;
	}
	return ::ResetEvent(this->m_hEvent);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -