VOID DDKUnload (IN PDRIVER_OBJECT pDriverObject) { //::KeWaitForSingleObject(&g_DispatchMutex,Executive,KernelMode,FALSE,NULL); KdPrint(("==> DriverUnload\n")); // 取消进程回调 PsSetCreateProcessNotifyRoutine(OnProcessQuit, TRUE); UnHookSSDT(); WriteSysLog(LOG_TYPE_DEBUG,L" FinishH2"); if(pEvent) ObDereferenceObject(pEvent); ClearFilterCache(); ClearBlackCache(); WriteSysLog(LOG_TYPE_DEBUG,L" ClearB"); LogUninitialize(); //::KeReleaseMutex(&g_DispatchMutex,FALSE); while(g_HookCounter>0) { LARGE_INTEGER interval; interval.QuadPart = -10 * 1000 * 1000; KeDelayExecutionThread(KernelMode, FALSE, &interval); } // PDEVICE_OBJECT pNextObj; pNextObj = pDriverObject->DeviceObject; while (pNextObj != NULL) { PDEVICE_EXTENSION pDevExt = (PDEVICE_EXTENSION) pNextObj->DeviceExtension; //删除符号链接 UNICODE_STRING pLinkName = pDevExt->ustrSymLinkName; IoDeleteSymbolicLink(&pLinkName); pNextObj = pNextObj->NextDevice; IoDeleteDevice( pDevExt->pDevice ); IoUnregisterShutdownNotification(pDevExt->pDevice); } KdPrint(("<== DriverUnload\n")); }
/* Called just before kexec.sys is unloaded. */ void DDKAPI DriverUnload(PDRIVER_OBJECT DriverObject) { UNICODE_STRING SymlinkName; DbgPrint("Unloading kexec driver\n"); /* Unregister \\.\kexec with the Windows kernel. */ RtlInitUnicodeString(&SymlinkName, L"\\??\\kexec"); IoDeleteSymbolicLink(&SymlinkName); IoUnregisterShutdownNotification(DriverObject->DeviceObject); IoDeleteDevice(DriverObject->DeviceObject); /* Don't waste kernel memory! */ KexecDestroyBuffer(&KexecKernel); KexecDestroyBuffer(&KexecInitrd); KexecDestroyBuffer(&KexecKernelCommandLine); }
EXTERN_C static void LogpFinalizeBufferInfo( _In_opt_ PDEVICE_OBJECT DeviceObject, _In_ LogBufferInfo *Info) { PAGED_CODE(); NT_ASSERT(Info); // Closing the log buffer flush thread. if (Info->BufferFlushThreadHandle) { Info->BufferFlushThreadShouldBeAlive = false; auto status = ZwWaitForSingleObject(Info->BufferFlushThreadHandle, FALSE, nullptr); if (!NT_SUCCESS(status)) { DBG_BREAK(); } ZwClose(Info->BufferFlushThreadHandle); Info->BufferFlushThreadHandle = nullptr; } // Cleaning up other things. if (Info->LogFileHandle) { ZwClose(Info->LogFileHandle); Info->LogFileHandle = nullptr; } if (Info->LogBuffer2) { ExFreePoolWithTag(Info->LogBuffer2, LOGP_POOL_TAG_NAME); Info->LogBuffer2 = nullptr; } if (Info->LogBuffer1) { ExFreePoolWithTag(Info->LogBuffer1, LOGP_POOL_TAG_NAME); Info->LogBuffer1 = nullptr; } if (DeviceObject) { IoUnregisterShutdownNotification(DeviceObject); } if (Info->ResourceInitialized) { ExDeleteResourceLite(&Info->Resource); Info->ResourceInitialized = false; } }
/////////////////////////////////////////////////////////////////////////////////////////////////// // testdrvUnload // Driver unload callback. // // Arguments: // IN DriverObject // pointer to the driver object // // Return Value: // none // VOID testdrvUnload( IN PDRIVER_OBJECT DriverObject ) { UNICODE_STRING win32Name; testdrvDebugPrint(DBG_UNLOAD, DBG_TRACE, __FUNCTION__"++"); RtlInitUnicodeString(&win32Name, L"\\??\\testdrvDevice"); IoDeleteSymbolicLink(&win32Name); IoUnregisterShutdownNotification(DriverObject->DeviceObject); IoDeleteDevice(DriverObject->DeviceObject); // The device object(s) should be NULL now // (since we unload, all the devices objects associated with this // driver must be deleted. ASSERT(DriverObject->DeviceObject == NULL); // We should not be unloaded until all the devices we control // have been removed from our queue. // release memory block allocated for registry path if (g_Data.RegistryPath.Buffer != NULL) { ExFreePool(g_Data.RegistryPath.Buffer); g_Data.RegistryPath.Buffer = NULL; } testdrvDebugPrint(DBG_UNLOAD, DBG_TRACE, __FUNCTION__"--"); #ifdef TESTDRV_WMI_TRACE WPP_CLEANUP(DriverObject); #endif return; }
NTSTATUS RemoveCallbackNotify(PVOID InBuffer) { NTSTATUS Status = STATUS_SUCCESS; PREMOVE_CALLBACK Temp = (PREMOVE_CALLBACK)InBuffer; ULONG_PTR CallbackAddress = Temp->CallbackAddress; CALLBACK_TYPE CallBackType = Temp->NotifyType; if (!CallbackAddress || !MmIsAddressValid((PVOID)CallbackAddress)) { return STATUS_UNSUCCESSFUL; } DbgPrint("CallBackType: %d\r\n",CallBackType); switch(CallBackType) { case NotifyLoadImage: { DbgPrint("Remove NotifyLoadImage\r\n"); Status = PsRemoveLoadImageNotifyRoutine((PLOAD_IMAGE_NOTIFY_ROUTINE)CallbackAddress); break; } case NotifyCmCallBack: { LARGE_INTEGER Cookie; ULONG_PTR Note = Temp->Note; Cookie.QuadPart = 0; DbgPrint("Remove NotifyCmCallBack\r\n"); if (WinVersion == WINDOWS_XP) { Cookie = XpGetRegisterCallbackCookie(Note); } if (WinVersion==WINDOWS_7) { Cookie.QuadPart = Note; } if (Cookie.LowPart == 0 && Cookie.HighPart == 0) { return STATUS_UNSUCCESSFUL; } Status = CmUnRegisterCallback(Cookie); break; } case NotifyKeBugCheckReason: { PREMOVE_CALLBACK Temp = (PREMOVE_CALLBACK)InBuffer; ULONG_PTR Note = Temp->Note; if (Note!=NULL&&MmIsAddressValid((PVOID)Note)) { KeDeregisterBugCheckReasonCallback((PKBUGCHECK_REASON_CALLBACK_RECORD)Note); } break; } case NotifyShutdown: { LARGE_INTEGER Cookie; PREMOVE_CALLBACK Temp = (PREMOVE_CALLBACK)InBuffer; ULONG_PTR Note = Temp->Note; if (Note!=NULL&&MmIsAddressValid((PVOID)Note)) { IoUnregisterShutdownNotification((PDEVICE_OBJECT)Note); } break; } case NotifyCreateThread: { NTSTATUS Status = STATUS_SUCCESS; PREMOVE_CALLBACK Temp = (PREMOVE_CALLBACK)InBuffer; ULONG_PTR CallbackAddress = Temp->CallbackAddress; if (!CallbackAddress || !MmIsAddressValid((PVOID)CallbackAddress)||!PsRemoveCreateThreadNotifyRoutine) { return STATUS_UNSUCCESSFUL; } Status = PsRemoveCreateThreadNotifyRoutine((PCREATE_THREAD_NOTIFY_ROUTINE)CallbackAddress); break; } default: { Status = STATUS_UNSUCCESSFUL; } } return Status; }
VOID SoundCleanup( IN PGLOBAL_DEVICE_INFO pGDI ) /*++ Routine Description: Clean up all resources allocated by our initialization Arguments: pGDI - Pointer to global data Return Value: NONE --*/ { PGLOBAL_DEVICE_INFO NextGDI; PGLOBAL_DEVICE_INFO FirstGDI; PDRIVER_OBJECT DriverObject; FirstGDI = pGDI; for (;;) { NextGDI = pGDI->Next; // // Free the synth device // SynthCleanup(&pGDI->Synth); // // Reset MPU401 if any // if (pGDI->Hw.MPU401.PortBase != NULL) { // // Just in case // READ_PORT_UCHAR(pGDI->Hw.MPU401.PortBase + MPU401_REG_DATA); MPU401Write(pGDI->Hw.MPU401.PortBase, TRUE, MPU401_CMD_RESET); } // // Free our interrupt // if (pGDI->WaveInfo.Interrupt) { IoDisconnectInterrupt(pGDI->WaveInfo.Interrupt); } // // Free our DMA Buffer // SoundFreeCommonBuffer(&pGDI->WaveInfo.DMABuf); // // Unregister shutdown notification // if (pGDI->ShutdownRegistered) { IoUnregisterShutdownNotification(pGDI->DeviceObject[WaveInDevice]); } // // Free our I/O Ports // if (pGDI->MemType == 0) { if (pGDI->Hw.PortBase != NULL) { MmUnmapIoSpace(pGDI->Hw.PortBase, NUMBER_OF_SOUND_PORTS); } if (pGDI->Hw.MPU401.PortBase != NULL) { MmUnmapIoSpace(pGDI->Hw.MPU401.PortBase, NUMBER_OF_MPU401_PORTS); } #ifdef SB_CD if (pGDI->Hw.SBCDBase != NULL) { MmUnmapIoSpace(pGDI->Hw.SBCDBase, 6); } #endif // SB_CD } // // Free device name // if (pGDI->RegistryPathName) { HANDLE hKey; // // Free devices key // if (NT_SUCCESS(SoundOpenDevicesKey(pGDI->RegistryPathName, &hKey))) { ZwDeleteKey(hKey); ZwClose(hKey); } ExFreePool(pGDI->RegistryPathName); } // // Save driver object // DriverObject = pGDI->DriverObject; // // Free the Pool // ExFreePool(pGDI); if (NextGDI == FirstGDI) { break; } else { pGDI = NextGDI; } } // // Free all devices for this driver. This will free everything for // every card. // if (DriverObject != NULL) { while (DriverObject->DeviceObject != NULL) { /* ** Undeclare resources used by device and ** delete the device object and associated data */ SoundFreeDevice(DriverObject->DeviceObject); } } }
VOID NTAPI FreeDeviceData(IN PDEVICE_OBJECT DeviceObject) { PSAC_DEVICE_EXTENSION DeviceExtension; NTSTATUS Status; KIRQL OldIrql; SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC FreeDeviceData: Entering.\n"); /* Get the device extension and see how far we had gotten */ DeviceExtension = (PSAC_DEVICE_EXTENSION)DeviceObject->DeviceExtension; if ((GlobalDataInitialized) && (DeviceExtension->Initialized)) { /* Attempt to rundown while holding the lock */ KeAcquireSpinLock(&DeviceExtension->Lock, &OldIrql); while (DeviceExtension->RundownInProgress) { SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC FreeDeviceData: Waiting....\n"); /* Initiate and wait for rundown */ KeInitializeEvent(&DeviceExtension->RundownEvent, SynchronizationEvent, 0); KeReleaseSpinLock(&DeviceExtension->Lock, OldIrql); Status = KeWaitForSingleObject(&DeviceExtension->RundownEvent, Executive, KernelMode, FALSE, NULL); ASSERT(Status == STATUS_SUCCESS); /* Re-acquire the lock and check if rundown is done */ KeAcquireSpinLock(&DeviceExtension->Lock, &OldIrql); } } /* Now set the rundown flag while we cancel the timer */ DeviceExtension->RundownInProgress = TRUE; KeReleaseSpinLock(&DeviceExtension->Lock, OldIrql); /* Cancel it */ KeCancelTimer(&DeviceExtension->Timer); /* Reacquire the lock*/ KeAcquireSpinLock(&DeviceExtension->Lock, &OldIrql); DeviceExtension->RundownInProgress = FALSE; /* Now do the last rundown attempt, we should be the only ones here */ KeInitializeEvent(&DeviceExtension->RundownEvent, SynchronizationEvent, 0); KeReleaseSpinLock(&DeviceExtension->Lock, OldIrql); KeSetEvent(&DeviceExtension->Event, DeviceExtension->PriorityBoost, 0); Status = KeWaitForSingleObject(&DeviceExtension->RundownEvent, Executive, KernelMode, FALSE, NULL); ASSERT(Status == STATUS_SUCCESS); /* We no longer care about shutdown */ IoUnregisterShutdownNotification(DeviceObject); /* We are now fully uninitialized */ KeAcquireSpinLock(&DeviceExtension->Lock, &OldIrql); DeviceExtension->Initialized = FALSE; KeReleaseSpinLock(&DeviceExtension->Lock, OldIrql); SAC_DBG(SAC_DBG_ENTRY_EXIT, "SAC FreeDeviceData: Exiting.\n"); }
NTSTATUS DriverEntry( PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) { NTSTATUS ntStatus = STATUS_SUCCESS; AFSDeviceExt *pDeviceExt; ULONG ulTimeIncrement = 0; UNICODE_STRING uniSymLinkName; UNICODE_STRING uniDeviceName; ULONG ulIndex = 0; ULONG ulValue = 0; UNICODE_STRING uniValueName; BOOLEAN bExit = FALSE; UNICODE_STRING uniRoutine; RTL_OSVERSIONINFOW sysVersion; UNICODE_STRING uniPsSetCreateProcessNotifyRoutineEx; PsSetCreateProcessNotifyRoutineEx_t pPsSetCreateProcessNotifyRoutineEx = NULL; __try { DbgPrint("AFSRedirFs DriverEntry Initialization build %s:%s\n", __DATE__, __TIME__); // // Initialize some local variables for easier processing // uniSymLinkName.Buffer = NULL; AFSDumpFileLocation.Length = 0; AFSDumpFileLocation.MaximumLength = 0; AFSDumpFileLocation.Buffer = NULL; AFSDumpFileName.Length = 0; AFSDumpFileName.Buffer = NULL; AFSDumpFileName.MaximumLength = 0; ExInitializeResourceLite( &AFSDbgLogLock); // // Initialize the server name // AFSReadServerName(); RtlZeroMemory( &sysVersion, sizeof( RTL_OSVERSIONINFOW)); sysVersion.dwOSVersionInfoSize = sizeof( RTL_OSVERSIONINFOW); RtlGetVersion( &sysVersion); RtlInitUnicodeString( &uniRoutine, L"ZwSetInformationToken"); AFSSetInformationToken = (PAFSSetInformationToken)MmGetSystemRoutineAddress( &uniRoutine); if( AFSSetInformationToken == NULL) { #ifndef AMD64 AFSSrvcTableEntry *pServiceTable = NULL; pServiceTable = (AFSSrvcTableEntry *)KeServiceDescriptorTable; // // Only perform this lookup for Windows XP. // if( pServiceTable != NULL && sysVersion.dwMajorVersion == 5 && sysVersion.dwMinorVersion == 1) { AFSSetInformationToken = (PAFSSetInformationToken)pServiceTable->ServiceTable[ 0xE6]; } #endif } // // And the global root share name // RtlInitUnicodeString( &AFSGlobalRootName, AFS_GLOBAL_ROOT_SHARE_NAME); RtlZeroMemory( &AFSNoPAGAuthGroup, sizeof( GUID)); // // Our backdoor to not let the driver load // if( bExit) { try_return( ntStatus); } // // Perform some initialization // AFSDriverObject = DriverObject; ntStatus = AFSReadRegistry( RegistryPath); if( !NT_SUCCESS( ntStatus)) { DbgPrint("AFS DriverEntry: Failed to read registry Status %08lX\n", ntStatus); ntStatus = STATUS_SUCCESS; } // // Initialize the debug log and dump file interface // AFSInitializeDbgLog(); AFSInitializeDumpFile(); #if DBG if( BooleanFlagOn( AFSDebugFlags, AFS_DBG_FLAG_BREAK_ON_ENTRY)) { DbgPrint("AFSRedirFs DriverEntry - Break on entry\n"); AFSBreakPoint(); if ( bExit) { // // Just as above // try_return( ntStatus = STATUS_UNSUCCESSFUL); } } #endif if( BooleanFlagOn( AFSDebugFlags, AFS_DBG_REQUIRE_CLEAN_SHUTDOWN) && !BooleanFlagOn( AFSDebugFlags, AFS_DBG_CLEAN_SHUTDOWN)) { AFSPrint("AFS DriverEntry: Failed to shutdown clean, exiting\n"); try_return( ntStatus = STATUS_UNSUCCESSFUL); } // // Setup the registry string // AFSRegistryPath.MaximumLength = RegistryPath->MaximumLength; AFSRegistryPath.Length = RegistryPath->Length; AFSRegistryPath.Buffer = (PWSTR)ExAllocatePoolWithTag( PagedPool, AFSRegistryPath.Length, AFS_GENERIC_MEMORY_18_TAG); if( AFSRegistryPath.Buffer == NULL) { DbgPrint("AFSRedirFs DriverEntry Failed to allocate registry path buffer\n"); try_return( ntStatus = STATUS_INSUFFICIENT_RESOURCES); } RtlCopyMemory( AFSRegistryPath.Buffer, RegistryPath->Buffer, RegistryPath->Length); if( BooleanFlagOn( AFSDebugFlags, AFS_DBG_REQUIRE_CLEAN_SHUTDOWN)) { // // Update the shutdown flag // ulValue = (ULONG)-1; RtlInitUnicodeString( &uniValueName, AFS_REG_SHUTDOWN_STATUS); AFSUpdateRegistryParameter( &uniValueName, REG_DWORD, &ulValue, sizeof( ULONG)); } RtlInitUnicodeString( &uniDeviceName, AFS_CONTROL_DEVICE_NAME); ntStatus = IoCreateDeviceSecure( DriverObject, sizeof( AFSDeviceExt), &uniDeviceName, FILE_DEVICE_NETWORK_FILE_SYSTEM, 0, FALSE, &SDDL_DEVOBJ_SYS_ALL_ADM_RWX_WORLD_RWX_RES_RWX, (LPCGUID)&GUID_SD_AFS_REDIRECTOR_CONTROL_OBJECT, &AFSDeviceObject); if( !NT_SUCCESS( ntStatus)) { DbgPrint("AFS DriverEntry - Failed to allocate device control object Status %08lX\n", ntStatus); try_return( ntStatus); } // // Setup the device extension // pDeviceExt = (AFSDeviceExt *)AFSDeviceObject->DeviceExtension; InitializeListHead( &pDeviceExt->Specific.Control.DirNotifyList); FsRtlNotifyInitializeSync( &pDeviceExt->Specific.Control.NotifySync); // // Now initialize the control device // ntStatus = AFSInitializeControlDevice(); if( !NT_SUCCESS( ntStatus)) { try_return( ntStatus); } // // Allocate our symbolic link for service communication // RtlInitUnicodeString( &uniSymLinkName, AFS_SYMLINK_NAME); ntStatus = IoCreateSymbolicLink( &uniSymLinkName, &uniDeviceName); if( !NT_SUCCESS( ntStatus)) { DbgPrint("AFS DriverEntry - Failed to create symbolic link Status %08lX\n", ntStatus); // // OK, no one can communicate with us so fail // try_return( ntStatus); } // // Fill in the dispatch table // for( ulIndex = 0; ulIndex <= IRP_MJ_MAXIMUM_FUNCTION; ulIndex++) { DriverObject->MajorFunction[ ulIndex] = AFSDefaultDispatch; } DriverObject->MajorFunction[IRP_MJ_CREATE] = AFSCreate; DriverObject->MajorFunction[IRP_MJ_CLOSE] = AFSClose; DriverObject->MajorFunction[IRP_MJ_READ] = AFSRead; DriverObject->MajorFunction[IRP_MJ_WRITE] = AFSWrite; DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = AFSQueryFileInfo; DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = AFSSetFileInfo; DriverObject->MajorFunction[IRP_MJ_QUERY_EA] = AFSQueryEA; DriverObject->MajorFunction[IRP_MJ_SET_EA] = AFSSetEA; DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = AFSFlushBuffers; DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = AFSQueryVolumeInfo; DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = AFSSetVolumeInfo; DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = AFSDirControl; DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = AFSFSControl; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = AFSDevControl; DriverObject->MajorFunction[IRP_MJ_INTERNAL_DEVICE_CONTROL] = AFSInternalDevControl; DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = AFSShutdown; DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = AFSLockControl; DriverObject->MajorFunction[IRP_MJ_CLEANUP] = AFSCleanup; DriverObject->MajorFunction[IRP_MJ_QUERY_SECURITY] = AFSQuerySecurity; DriverObject->MajorFunction[IRP_MJ_SET_SECURITY] = AFSSetSecurity; DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = AFSSystemControl; //DriverObject->MajorFunction[IRP_MJ_QUERY_QUOTA] = AFSQueryQuota; //DriverObject->MajorFunction[IRP_MJ_SET_QUOTA] = AFSSetQuota; // // Since we are not a true FSD then we are not controlling a device and hence these will not be needed // #ifdef FSD_NOT_USED DriverObject->MajorFunction[IRP_MJ_POWER] = AFSPower; DriverObject->MajorFunction[IRP_MJ_PNP] = AFSPnP; #endif // // Fast IO Dispatch table // DriverObject->FastIoDispatch = &AFSFastIoDispatch; RtlZeroMemory( &AFSFastIoDispatch, sizeof( AFSFastIoDispatch)); // // Again, since we are not a registered FSD many of these are not going to be called. They are here // for completeness. // AFSFastIoDispatch.SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH); AFSFastIoDispatch.FastIoCheckIfPossible = AFSFastIoCheckIfPossible; // CheckForFastIo AFSFastIoDispatch.FastIoRead = AFSFastIoRead; // Read AFSFastIoDispatch.FastIoWrite = AFSFastIoWrite; // Write AFSFastIoDispatch.FastIoQueryBasicInfo = AFSFastIoQueryBasicInfo; // QueryBasicInfo AFSFastIoDispatch.FastIoQueryStandardInfo = AFSFastIoQueryStandardInfo; // QueryStandardInfo AFSFastIoDispatch.FastIoLock = AFSFastIoLock; // Lock AFSFastIoDispatch.FastIoUnlockSingle = AFSFastIoUnlockSingle; // UnlockSingle AFSFastIoDispatch.FastIoUnlockAll = AFSFastIoUnlockAll; // UnlockAll AFSFastIoDispatch.FastIoUnlockAllByKey = AFSFastIoUnlockAllByKey; // UnlockAllByKey AFSFastIoDispatch.FastIoQueryNetworkOpenInfo = AFSFastIoQueryNetworkOpenInfo; AFSFastIoDispatch.AcquireForCcFlush = AFSFastIoAcquireForCCFlush; AFSFastIoDispatch.ReleaseForCcFlush = AFSFastIoReleaseForCCFlush; AFSFastIoDispatch.FastIoDeviceControl = AFSFastIoDevCtrl; AFSFastIoDispatch.AcquireFileForNtCreateSection = AFSFastIoAcquireFile; AFSFastIoDispatch.ReleaseFileForNtCreateSection = AFSFastIoReleaseFile; AFSFastIoDispatch.FastIoDetachDevice = AFSFastIoDetachDevice; //AFSFastIoDispatch.AcquireForModWrite = AFSFastIoAcquireForModWrite; //AFSFastIoDispatch.ReleaseForModWrite = AFSFastIoReleaseForModWrite; AFSFastIoDispatch.MdlRead = AFSFastIoMdlRead; AFSFastIoDispatch.MdlReadComplete = AFSFastIoMdlReadComplete; AFSFastIoDispatch.PrepareMdlWrite = AFSFastIoPrepareMdlWrite; AFSFastIoDispatch.MdlWriteComplete = AFSFastIoMdlWriteComplete; AFSFastIoDispatch.FastIoReadCompressed = AFSFastIoReadCompressed; AFSFastIoDispatch.FastIoWriteCompressed = AFSFastIoWriteCompressed; AFSFastIoDispatch.MdlReadCompleteCompressed = AFSFastIoMdlReadCompleteCompressed; AFSFastIoDispatch.MdlWriteCompleteCompressed = AFSFastIoMdlWriteCompleteCompressed; AFSFastIoDispatch.FastIoQueryOpen = AFSFastIoQueryOpen; // // Cache manager callback routines. // AFSCacheManagerCallbacks.AcquireForLazyWrite = &AFSAcquireFcbForLazyWrite; AFSCacheManagerCallbacks.ReleaseFromLazyWrite = &AFSReleaseFcbFromLazyWrite; AFSCacheManagerCallbacks.AcquireForReadAhead = &AFSAcquireFcbForReadAhead; AFSCacheManagerCallbacks.ReleaseFromReadAhead = &AFSReleaseFcbFromReadAhead; // // System process. // AFSSysProcess = PsGetCurrentProcessId(); // // Register for shutdown notification // IoRegisterShutdownNotification( AFSDeviceObject); // // Initialize the system process cb // AFSInitializeProcessCB( 0, (ULONGLONG)AFSSysProcess); // // Initialize the redirector device // ntStatus = AFSInitRDRDevice(); if( !NT_SUCCESS( ntStatus)) { DbgPrint("AFS DriverEntry Failed to initialize redirector device Status %08lX\n"); try_return( ntStatus); } // // Initialize some server name based strings // AFSInitServerStrings(); // // Register the call back for process creation and tear down. // On Vista SP1 and above, PsSetCreateProcessNotifyRoutineEx // will be used. This function returns STATUS_ACCESS_DENIED // if there is a signing error. In that case, the AFSProcessNotifyEx // routine has not been registered and we can fallback to the // Windows 2000 interface and AFSProcessNotify. // RtlInitUnicodeString( &uniPsSetCreateProcessNotifyRoutineEx, L"PsSetCreateProcessNotifyRoutineEx"); pPsSetCreateProcessNotifyRoutineEx = (PsSetCreateProcessNotifyRoutineEx_t)MmGetSystemRoutineAddress(&uniPsSetCreateProcessNotifyRoutineEx); ntStatus = STATUS_ACCESS_DENIED; if ( pPsSetCreateProcessNotifyRoutineEx) { ntStatus = pPsSetCreateProcessNotifyRoutineEx( AFSProcessNotifyEx, FALSE); } if ( ntStatus == STATUS_ACCESS_DENIED) { ntStatus = PsSetCreateProcessNotifyRoutine( AFSProcessNotify, FALSE); } ntStatus = STATUS_SUCCESS; try_exit: if( !NT_SUCCESS( ntStatus)) { DbgPrint("AFSRedirFs DriverEntry failed to initialize %08lX\n", ntStatus); if( AFSRegistryPath.Buffer != NULL) { ExFreePool( AFSRegistryPath.Buffer); } if( uniSymLinkName.Buffer != NULL) { IoDeleteSymbolicLink( &uniSymLinkName); } if( AFSDeviceObject != NULL) { AFSRemoveControlDevice(); FsRtlNotifyUninitializeSync( &pDeviceExt->Specific.Control.NotifySync); IoUnregisterShutdownNotification( AFSDeviceObject); IoDeleteDevice( AFSDeviceObject); } AFSTearDownDbgLog(); ExDeleteResourceLite( &AFSDbgLogLock); } } __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()) ) { AFSDbgLogMsg( 0, 0, "EXCEPTION - AFSRedirFs DriverEntry\n"); AFSDumpTraceFilesFnc(); } return ntStatus; }