static void ReHash(struct WordList *WL) { unsigned long i = 0; ClearHash(&WL->Hash); FORWL(i, *WL) InsertHash(WL->Stack.Data[i], &WL->Hash); }
void GLSLProgramObject::Release() { IProgramObject::Release(); glDeleteProgram(objID); ClearHash(); curFlagsHash = 0; objID = 0; objID = glCreateProgram(); curSrcHash = 0; }
void ClearWord(struct WordList *WL) { if(WL) { WL->Stack.Used = 0; WL->MaxLen = 0; ClearHash(&WL->Hash); if(WL->NonEmpty) InsertWord("", WL); } }
/* ======================== idLZWCompressor::BumpBits Possibly increments codeBits. return: bool - true, if the dictionary was cleared. ======================== */ bool idLZWCompressor::BumpBits() { if ( lzwData->nextCode == ( 1 << lzwData->codeBits ) ) { lzwData->codeBits ++; if ( lzwData->codeBits > lzwCompressionData_t::LZW_DICT_BITS ) { lzwData->nextCode = LZW_FIRST_CODE; lzwData->codeBits = LZW_START_BITS; ClearHash(); return true; } } return false; }
/* ======================== idLZWCompressor::Start ======================== */ void idLZWCompressor::Start( uint8 * data_, int maxSize_, bool append ) { // Clear hash ClearHash(); if ( append ) { assert( lzwData->nextCode > LZW_FIRST_CODE ); int originalNextCode = lzwData->nextCode; lzwData->nextCode = LZW_FIRST_CODE; // If we are appending, then fill up the hash for ( int i = LZW_FIRST_CODE; i < originalNextCode; i++ ) { AddToDict( lzwData->dictionaryW[i], lzwData->dictionaryK[i] ); } assert( originalNextCode == lzwData->nextCode ); } else { for ( int i = 0; i < LZW_FIRST_CODE; i++ ) { lzwData->dictionaryK[i] = (uint8)i; lzwData->dictionaryW[i] = 0xFFFF; } lzwData->nextCode = LZW_FIRST_CODE; lzwData->codeBits = LZW_START_BITS; lzwData->codeWord = -1; lzwData->tempValue = 0; lzwData->tempBits = 0; lzwData->bytesWritten = 0; } oldCode = -1; // Used by DecompressBlock data = data_; blockSize = 0; blockIndex = 0; bytesRead = 0; maxSize = maxSize_; overflowed = false; savedBytesWritten = 0; savedCodeWord = 0; saveCodeBits = 0; savedTempValue = 0; savedTempBits = 0; }
void ClearWord(struct WordList *WL) { char *Word; if (WL) { while ( (Word = StkPop( &WL->Stack )) ) { free(Word); } WL->Stack.Used = 0; WL->MaxLen = 0; ClearHash(&WL->Hash); if (WL->NonEmpty) InsertWord("", WL); } }
/* ================ idAASBuild::StoreFile ================ */ bool idAASBuild::StoreFile( const idBrushBSP& bsp ) { aasEdge_t edge; aasFace_t face; aasArea_t area; aasNode_t node; common->Printf( "[Store AAS]\n" ); SetupHash(); ClearHash( bsp.GetTreeBounds() ); file = new idAASFileLocal(); file->Clear(); SetSizeEstimate( bsp, file ); // the first edge is a dummy memset( &edge, 0, sizeof( edge ) ); file->edges.Append( edge ); // the first face is a dummy memset( &face, 0, sizeof( face ) ); file->faces.Append( face ); // the first area is a dummy memset( &area, 0, sizeof( area ) ); file->areas.Append( area ); // the first node is a dummy memset( &node, 0, sizeof( node ) ); file->nodes.Append( node ); // store the tree StoreTree_r( bsp.GetRootNode() ); // calculate area bounds and a reachable point in the area file->FinishAreas(); ShutdownHash(); common->Printf( "\r%6d areas\n", file->areas.Num() ); return true; }
// 主搜索例程 void SearchMain(int nDepth) { int i, vl, vlLast, nDraw; int nCurrTimer, nLimitTimer, nLimitNodes; bool bUnique; #ifndef CCHESS_A3800 int nBookMoves; uint32_t dwMoveStr; BookStruct bks[MAX_GEN_MOVES]; #endif // 主搜索例程包括以下几个步骤: // 1. 遇到和棋则直接返回 if (Search.pos.IsDraw() || Search.pos.RepStatus(3) > 0) { #ifndef CCHESS_A3800 printf("nobestmove\n"); fflush(stdout); #endif return; } #ifndef CCHESS_A3800 // 2. 从开局库中搜索着法 if (Search.bUseBook) { // a. 获取开局库中的所有走法 nBookMoves = GetBookMoves(Search.pos, Search.szBookFile, bks); if (nBookMoves > 0) { vl = 0; for (i = 0; i < nBookMoves; i ++) { vl += bks[i].wvl; dwMoveStr = MOVE_COORD(bks[i].wmv); printf("info depth 0 score %d pv %.4s\n", bks[i].wvl, (const char *) &dwMoveStr); fflush(stdout); } // b. 根据权重随机选择一个走法 vl = Search.rc4Random.NextLong() % (uint32_t) vl; for (i = 0; i < nBookMoves; i ++) { vl -= bks[i].wvl; if (vl < 0) { break; } } __ASSERT(vl < 0); __ASSERT(i < nBookMoves); // c. 如果开局库中的着法够成循环局面,那么不走这个着法 Search.pos.MakeMove(bks[i].wmv); if (Search.pos.RepStatus(3) == 0) { dwMoveStr = MOVE_COORD(bks[i].wmv); printf("bestmove %.4s", (const char *) &dwMoveStr); // d. 给出后台思考的着法(开局库中第一个即权重最大的后续着法) nBookMoves = GetBookMoves(Search.pos, Search.szBookFile, bks); Search.pos.UndoMakeMove(); if (nBookMoves > 0) { dwMoveStr = MOVE_COORD(bks[0].wmv); printf(" ponder %.4s", (const char *) &dwMoveStr); } printf("\n"); fflush(stdout); return; } Search.pos.UndoMakeMove(); } } #endif // 3. 如果深度为零则返回静态搜索值 if (nDepth == 0) { #ifndef CCHESS_A3800 printf("info depth 0 score %d\n", SearchQuiesc(Search.pos, -MATE_VALUE, MATE_VALUE)); fflush(stdout); printf("nobestmove\n"); fflush(stdout); #endif return; } // 4. 生成根结点的每个着法 Search2.MoveSort.InitRoot(Search.pos, Search.nBanMoves, Search.wmvBanList); // 5. 初始化时间和计数器 Search2.bStop = Search2.bPonderStop = Search2.bPopPv = Search2.bPopCurrMove = false; Search2.nPopDepth = Search2.vlPopValue = 0; Search2.nAllNodes = Search2.nMainNodes = Search2.nUnchanged = 0; Search2.wmvPvLine[0] = 0; ClearKiller(Search2.wmvKiller); ClearHistory(); ClearHash(); // 由于 ClearHash() 需要消耗一定时间,所以计时从这以后开始比较合理 Search2.llTime = GetTime(); vlLast = 0; // 如果走了10回合无用着法,那么允许主动提和,以后每隔8回合提和一次 nDraw = -Search.pos.LastMove().CptDrw; if (nDraw > 5 && ((nDraw - 4) / 2) % 8 == 0) { Search.bDraw = true; } bUnique = false; nCurrTimer = 0; // 6. 做迭代加深搜索 for (i = 1; i <= nDepth; i ++) { // 需要输出主要变例时,第一个"info depth n"是不输出的 #ifndef CCHESS_A3800 if (Search2.bPopPv || Search.bDebug) { printf("info depth %d\n", i); fflush(stdout); } // 7. 根据搜索的时间决定,是否需要输出主要变例和当前思考的着法 Search2.bPopPv = (nCurrTimer > 300); Search2.bPopCurrMove = (nCurrTimer > 3000); #endif // 8. 搜索根结点 vl = SearchRoot(i); if (Search2.bStop) { if (vl > -MATE_VALUE) { vlLast = vl; // 跳出后,vlLast会用来判断认输或投降,所以需要给定最近一个值 } break; // 没有跳出,则"vl"是可靠值 } nCurrTimer = (int) (GetTime() - Search2.llTime); // 9. 如果搜索时间超过适当时限,则终止搜索 if (Search.nGoMode == GO_MODE_TIMER) { // a. 如果没有使用空着裁剪,那么适当时限减半(因为分枝因子加倍了) nLimitTimer = (Search.bNullMove ? Search.nProperTimer : Search.nProperTimer / 2); // b. 如果当前搜索值没有落后前一层很多,那么适当时限减半 nLimitTimer = (vl + DROPDOWN_VALUE >= vlLast ? nLimitTimer / 2 : nLimitTimer); // c. 如果最佳着法连续多层没有变化,那么适当时限减半 nLimitTimer = (Search2.nUnchanged >= UNCHANGED_DEPTH ? nLimitTimer / 2 : nLimitTimer); if (nCurrTimer > nLimitTimer) { if (Search.bPonder) { Search2.bPonderStop = true; // 如果处于后台思考模式,那么只是在后台思考命中后立即中止搜索。 } else { vlLast = vl; break; // 不管是否跳出,"vlLast"都已更新 } } } else if (Search.nGoMode == GO_MODE_NODES) { // nLimitNodes的计算方法与nLimitTimer是一样的 nLimitNodes = (Search.bNullMove ? Search.nNodes : Search.nNodes / 2); nLimitNodes = (vl + DROPDOWN_VALUE >= vlLast ? nLimitNodes / 2 : nLimitNodes); nLimitNodes = (Search2.nUnchanged >= UNCHANGED_DEPTH ? nLimitNodes / 2 : nLimitNodes); // GO_MODE_NODES下是不延长后台思考时间的 if (Search2.nAllNodes > nLimitNodes) { vlLast = vl; break; } } vlLast = vl; // 10. 搜索到杀棋则终止搜索 if (vlLast > WIN_VALUE || vlLast < -WIN_VALUE) { break; } // 11. 是唯一着法,则终止搜索 if (SearchUnique(1 - WIN_VALUE, i)) { bUnique = true; break; } } #ifdef CCHESS_A3800 Search.mvResult = Search2.wmvPvLine[0]; #else // 12. 输出最佳着法及其最佳应对(作为后台思考的猜测着法) if (Search2.wmvPvLine[0] != 0) { PopPvLine(); dwMoveStr = MOVE_COORD(Search2.wmvPvLine[0]); printf("bestmove %.4s", (const char *) &dwMoveStr); if (Search2.wmvPvLine[1] != 0) { dwMoveStr = MOVE_COORD(Search2.wmvPvLine[1]); printf(" ponder %.4s", (const char *) &dwMoveStr); } // 13. 判断是否认输或提和,但是经过唯一着法检验的不适合认输或提和(因为搜索深度不够) if (!bUnique) { if (vlLast > -WIN_VALUE && vlLast < -RESIGN_VALUE) { printf(" resign"); } else if (Search.bDraw && !Search.pos.NullSafe() && vlLast < DRAW_OFFER_VALUE * 2) { printf(" draw"); } } } else { printf("nobestmove"); } printf("\n"); fflush(stdout); #endif }
NTSTATUS DispatchDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP IRP) { KdPrint(("==>DriverDeviceControl\n")); NTSTATUS ntStatus = STATUS_UNSUCCESSFUL; ULONG tmpLen=0; PIO_STACK_LOCATION pIoStackIrp = IoGetCurrentIrpStackLocation(IRP); switch (pIoStackIrp->Parameters.DeviceIoControl.IoControlCode) { case IOCTL_SET_PROTECT_PID: KdPrint(("IOCTL_SET_PROTECT_PID\n")); { unsigned char pUnPack[256]; int unPackLength; unPackLength=DownloadUnPack((unsigned char *)IRP->AssociatedIrp.SystemBuffer,pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength,pUnPack); if (unPackLength>0) { PPID_INFO pInputBuffer = (PPID_INFO)pUnPack; int iStringLength = unPackLength; if(iStringLength != sizeof(PID_INFO)) // The PID should contain exactly 1 member. break; __int64 elapsedTime = __rdtsc() - pInputBuffer->currentTime; KdPrint(("IOCTL_SET_PROTECT_PID elapsed time: %I64d.\n", elapsedTime)); if((elapsedTime > COMMUNICATE_TIME_LIMIT)||(elapsedTime <=COMMUNICATE_TIME_DOWN)) { KdPrint(("IOCTL_SET_PROTECT_PID exceeds time limit.\n")); } else { // 加入进程 ID AddProtectPID(pInputBuffer->PID[0]); } ntStatus = STATUS_SUCCESS; } } break; case IOCTL_GET_PROTECT_PIDS: KdPrint(("IOCTL_GET_PROTECT_PIDS\n")); if (IRP->MdlAddress) { PPID_INFO pUserBuffer = (PPID_INFO)MmGetSystemAddressForMdlSafe(IRP->MdlAddress, NormalPagePriority); ULONG OutputLength = pIoStackIrp->Parameters.DeviceIoControl.OutputBufferLength; ULONG PIDLength = OutputLength - sizeof(PID_INFO) + sizeof(UINT32);//1025*sizeof(unsigned int),last one for another // add by bh PPID_INFO tmpBuf=(PPID_INFO)ExAllocatePoolWithTag(PagedPool,OutputLength-sizeof(UINT32),'bnak'); if(!tmpBuf) return ntStatus; ///judge safe KdPrint(("entry check hook safe!\n")); if(checkHookSafe()) { KdPrint((" safe!\n")); tmpBuf->count = GetPIDs(tmpBuf->PID, PIDLength / sizeof(UINT32)); tmpBuf->currentTime = __rdtsc(); ULONG bufLength=sizeof(PID_INFO)+tmpBuf->count*sizeof(UINT32); tmpLen = UploadPack((PUCHAR)tmpBuf , bufLength , (PUCHAR)pUserBuffer); } else { KdPrint( (" unfalse\n")); RtlZeroMemory(tmpBuf,OutputLength-sizeof(UINT32)); tmpLen=0; } /// //pUserBuffer->count = GetPIDs(pUserBuffer->PID, PIDLength / sizeof(UINT32)); //pUserBuffer->currentTime = __rdtsc(); ExFreePoolWithTag(tmpBuf,'bnak'); ///// end ntStatus = STATUS_SUCCESS; } break; case IOCTL_SET_SECU_PATHS: KdPrint(("IOCTL_SET_SECU_PATHS\n")); { /////////////////add by bh if(!g_tmpB) setStartTime(); ////////////////end /*PUCHAR pInputBuffer = (PUCHAR)IRP->AssociatedIrp.SystemBuffer; int iStringLength = pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength; ClearSecurePaths(); ULONG index = 0; while(index < iStringLength) { ULONG length = *(PULONG)((ULONG)pInputBuffer + index); index += 4; if(index + length >= iStringLength) break; AddSecurePath((WCHAR*)((ULONG)pInputBuffer + index), length); index += length * 2 + 2; }*/ ntStatus = STATUS_SUCCESS; } break; case IOCTL_SET_SECU_MD5: KdPrint(("IOCTL_SET_SECU_MD5\n")); { PUCHAR pInputBuffer; int iStringLength = pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength; unsigned char * pUnPack=(UCHAR *)ExAllocatePoolWithTag(PagedPool,iStringLength,'knab'); int unPackLength; unPackLength=DownloadUnPack((unsigned char *)IRP->AssociatedIrp.SystemBuffer,pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength,pUnPack); //add by bh //iStringLength=*((ULONG*)pUnPack ); RtlCopyBytes((PVOID)&iStringLength,(PVOID)pUnPack,sizeof(ULONG) ); pInputBuffer=pUnPack+sizeof(ULONG); //if(!g_globalTime) //g_globalTime=*((__int64 *)(pInputBuffer+iStringLength) ); RtlCopyBytes((PVOID)&g_globalTime,(PVOID)(pInputBuffer+iStringLength),8 ); __int64 elapseTime=__rdtsc()-g_globalTime; if( (elapseTime<COMMUNICATE_TIME_LIMIT) && (elapseTime>=COMMUNICATE_TIME_DOWN) ) { KdPrint( ("entry elapse check! ") ); if (unPackLength>0) {KdPrint( ("entry length check! ") ); ClearHash(); for(int i = 0; i <= iStringLength - HASH_SIZE; i += HASH_SIZE) AddSecureHash(pInputBuffer + i); ntStatus = STATUS_SUCCESS; } } ExFreePoolWithTag(pUnPack,'knab'); // } break; case IOCTL_SET_UP_UNLOAD: KdPrint(("IOCTL_SET_UP_UNLOAD\n")); DeviceObject->DriverObject->DriverUnload = DriverUnload; ntStatus = STATUS_SUCCESS; break; } IRP->IoStatus.Status = 0; IRP->IoStatus.Information = tmpLen ; IoCompleteRequest(IRP, IO_NO_INCREMENT); KdPrint(("<==DriverDeviceControl\n")); return ntStatus; }
/** * 驱动分发函数,相应上层应用的各种操作命令 * */ NTSTATUS DispatchDeviceControl(PDEVICE_OBJECT DeviceObject, PIRP IRP) { ::KeWaitForSingleObject(&g_DispatchMutex,Executive,KernelMode,FALSE,NULL); NTSTATUS ntStatus = STATUS_UNSUCCESSFUL; ULONG tmpLen = 0; PIO_STACK_LOCATION pIoStackIrp = IoGetCurrentIrpStackLocation(IRP); switch (pIoStackIrp->Parameters.DeviceIoControl.IoControlCode) { case IOCTL_SET_PROTECT_PID://设置保护PID KdPrint(("IOCTL_SET_PROTECT_PID\n")); { unsigned char pUnPack[256]; int unPackLength; unPackLength = DownloadUnPack((unsigned char *)IRP->AssociatedIrp.SystemBuffer,pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength,pUnPack); if (unPackLength > 0) { PPID_INFO pInputBuffer = (PPID_INFO)pUnPack; int iStringLength = unPackLength; if(iStringLength != sizeof(PID_INFO)) break; __int64 elapsedTime = __rdtsc() - pInputBuffer->currentTime; KdPrint(("IOCTL_SET_PROTECT_PID elapsed time: %I64d.\n", elapsedTime)); if((elapsedTime > COMMUNICATE_TIME_LIMIT)||(elapsedTime <=COMMUNICATE_TIME_DOWN)) { KdPrint(("IOCTL_SET_PROTECT_PID exceeds time limit.\n")); } else { // 加入进程 ID AddProtectPID(pInputBuffer->PID[0]); } ntStatus = STATUS_SUCCESS; } } break; case IOCTL_GET_PROTECT_PIDS:///判断驱动是否在正常工作 KdPrint(("IOCTL_GET_PROTECT_PIDS\n")); if (IRP->MdlAddress) { PPID_INFO pUserBuffer = (PPID_INFO)MmGetSystemAddressForMdlSafe(IRP->MdlAddress, NormalPagePriority); if(pUserBuffer == NULL) return ntStatus; ULONG OutputLength = pIoStackIrp->Parameters.DeviceIoControl.OutputBufferLength; ULONG PIDLength = OutputLength - sizeof(PID_INFO) + sizeof(UINT32); PPID_INFO tmpBuf=(PPID_INFO)ExAllocatePoolWithTag(PagedPool,OutputLength-sizeof(UINT32),'bak'); if(!tmpBuf) return ntStatus; KdPrint(("entry check hook safe!\n")); if(checkHookSafe()) { tmpBuf->count = GetKernelPIDs(tmpBuf->PID, PIDLength / sizeof(UINT32)); tmpBuf->currentTime = __rdtsc(); ULONG bufLength = sizeof(PID_INFO) + tmpBuf->count*sizeof(UINT32); tmpLen = UploadPack((PUCHAR)tmpBuf , bufLength , (PUCHAR)pUserBuffer); } else { RtlZeroMemory(tmpBuf,OutputLength-sizeof(UINT32)); tmpLen = 0; } ExFreePoolWithTag(tmpBuf,'bak'); ntStatus = STATUS_SUCCESS; } break; case IOCTL_SET_SECU_PATHS://无效 KdPrint(("IOCTL_SET_SECU_PATHS\n")); { ntStatus = STATUS_SUCCESS; } break; case IOCTL_SET_SECU_MD5://设置白名单哈希列表 KdPrint(("IOCTL_SET_SECU_MD5\n")); { PUCHAR pInputBuffer; int iStringLength = pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength; unsigned char * pUnPack=(UCHAR *)ExAllocatePoolWithTag(PagedPool,iStringLength,'knab'); int unPackLength; unPackLength = DownloadUnPack((unsigned char *)IRP->AssociatedIrp.SystemBuffer,pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength,pUnPack); RtlCopyBytes((PVOID)&iStringLength,(PVOID)pUnPack,sizeof(ULONG) ); pInputBuffer = pUnPack + sizeof(ULONG); RtlCopyBytes((PVOID)&g_globalTime,(PVOID)(pInputBuffer + iStringLength),8 ); __int64 elapseTime = __rdtsc() - g_globalTime; if( (elapseTime < COMMUNICATE_TIME_LIMIT) && (elapseTime >= COMMUNICATE_TIME_DOWN) ) { if (unPackLength > 0) { for(int i = 0; i <= iStringLength - HASH_SIZE; i += HASH_SIZE) AddSecureHash(pInputBuffer + i); getSecuTable(); ClearHash(); ntStatus = STATUS_SUCCESS; } } ExFreePoolWithTag(pUnPack,'knab'); // } break; ///////////// case IOCTL_SET_BLACK_MD5://设置黑名单哈希列表 KdPrint(("IOCTL_SET_SECU_MD5\n")); { PUCHAR pInputBuffer; int iStringLength = pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength; unsigned char * pUnPack=(UCHAR *)ExAllocatePoolWithTag(PagedPool,iStringLength,'knab'); int unPackLength; unPackLength = DownloadUnPack((unsigned char *)IRP->AssociatedIrp.SystemBuffer,pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength,pUnPack); RtlCopyBytes((PVOID)&iStringLength,(PVOID)pUnPack,sizeof(ULONG) ); pInputBuffer = pUnPack + sizeof(ULONG); RtlCopyBytes((PVOID)&g_globalTime,(PVOID)(pInputBuffer + iStringLength),8 ); __int64 elapseTime = __rdtsc() - g_globalTime; if( (elapseTime < COMMUNICATE_TIME_LIMIT) && (elapseTime >= COMMUNICATE_TIME_DOWN) ) { if (unPackLength > 0) { for(int i = 0; i <= iStringLength - HASH_SIZE; i += HASH_SIZE) AddBlackHash(pInputBuffer + i); getBlackTable(); ClearBlackHash(); ntStatus = STATUS_SUCCESS; } } ExFreePoolWithTag(pUnPack,'knab'); // } break; ///////////// case IOCTL_SET_UP_UNLOAD://设置卸载驱动函数 KdPrint(("IOCTL_SET_UP_UNLOAD\n")); while(g_bBusy) { LARGE_INTEGER interval; interval.QuadPart = -3 * 1000 * 1000;//滞后3秒进行卸载 KeDelayExecutionThread(KernelMode, FALSE, &interval); } DeviceObject->DriverObject->DriverUnload= DDKUnload; ntStatus = STATUS_SUCCESS; break; case IOCTL_GET_DRIVER_STATUS://得到驱动接受白名单状态 { ////////////////////////////////////////////////////// unsigned char pUnPack[256]; int unPackLength; unPackLength = DownloadUnPack((unsigned char *)IRP->AssociatedIrp.SystemBuffer,pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength,pUnPack); if (unPackLength > 0) { MYDRIVERSTATUS type = *(MYDRIVERSTATUS *)pUnPack; PUCHAR pUserBuffer = (PUCHAR)MmGetSystemAddressForMdlSafe(IRP->MdlAddress, NormalPagePriority);// 在虚拟内存紧张时会返回NULL if(pUserBuffer == NULL) return ntStatus; ULONG OutputLength = pIoStackIrp->Parameters.DeviceIoControl.OutputBufferLength; ULONG * tmpBuf=(ULONG *)ExAllocatePoolWithTag(PagedPool,4,'bnak'); if(!tmpBuf) return ntStatus; if(type == DRIVER_RECEIVED)//是否接受到白名单 { if(!isRestart()) g_isReceive=false; *tmpBuf = g_isReceive ? 1 : 0; tmpLen = UploadPack((PUCHAR)tmpBuf , 4 , (PUCHAR)pUserBuffer); } ExFreePoolWithTag(tmpBuf,'bnak'); } ntStatus = STATUS_SUCCESS; ////////////////////////////////////////////////////// } break; case IOCTL_SET_HANDLE://得到同步句柄 { if(pEvent) ObDereferenceObject(pEvent); HANDLE hEvent = NULL; int unPackLength; unPackLength=DownloadUnPack((unsigned char *)IRP->AssociatedIrp.SystemBuffer,pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength,(unsigned char *)&hEvent); if (unPackLength>0) { ObReferenceObjectByHandle(hEvent , EVENT_MODIFY_STATE, *ExEventObjectType, KernelMode, (PVOID *)&pEvent, NULL); ntStatus = STATUS_SUCCESS; } } break; case IOCTL_RETURN_DATA://返回灰名单 { if (IRP->MdlAddress) { wchar_t fName[260] = {0}; unsigned char cHash[16] = {0}; getData(fName,cHash); unsigned char dataBuf[260*sizeof(wchar_t) + 16 + 4*4] = {0}; *(DWORD*)(dataBuf) = 1; RtlCopyMemory(dataBuf+4,fName,DATAPATHLEN); *(wchar_t*)(dataBuf + DATAPATHLEN -2) = L'\0'; RtlCopyMemory(dataBuf+4+DATAPATHLEN,cHash,DATAHASHLEN); wchar_t * pUserBuffer = (wchar_t *)MmGetSystemAddressForMdlSafe(IRP->MdlAddress, NormalPagePriority); ULONG OutputLength = pIoStackIrp->Parameters.DeviceIoControl.OutputBufferLength; tmpLen = UploadPack((PUCHAR)dataBuf, 260*sizeof(wchar_t) + 16 + 4*4, (PUCHAR)pUserBuffer); } ntStatus = STATUS_SUCCESS; } break; case IOCTL_SET_FILTERRESULT://验证结果 { char rResult; //bool bResult = false; //rResult = (*(unsigned char *)(IRP->AssociatedIrp.SystemBuffer)); WriteSysLog(LOG_TYPE_INFO,L" IOCTL GET"); int unPackLength=DownloadUnPack((unsigned char *)IRP->AssociatedIrp.SystemBuffer,pIoStackIrp->Parameters.DeviceIoControl.InputBufferLength,(unsigned char *)&rResult); //g_bPassFilter = (rResult == 1) ? true : false; if (unPackLength>0) { g_bPassFilter = (rResult == 1) ? true : false; } else { WriteSysLog(LOG_TYPE_INFO,L" IOCTL LError"); g_bPassFilter = false; } WriteSysLog(LOG_TYPE_INFO,L" IOCTL SET"); KeSetEvent(g_pEventFilterGo, IO_NO_INCREMENT, FALSE); ntStatus = STATUS_SUCCESS; } break; } IRP->IoStatus.Status = 0; IRP->IoStatus.Information = tmpLen ; IoCompleteRequest(IRP, IO_NO_INCREMENT); ::KeReleaseMutex(&g_DispatchMutex,FALSE); return ntStatus; }