MCPcopy Create free account
hub / github.com/ByteCorum/DragonBurn / ClearMmUnloadedDrivers

Method ClearMmUnloadedDrivers

DragonBurn-kernel/intel_driver.cpp:708–799  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

706}
707
708bool intel_driver::ClearMmUnloadedDrivers() {
709 std::ostringstream ss;
710 ULONG buffer_size = 0;
711 void* buffer = nullptr;
712
713 NTSTATUS status = NtQuerySystemInformation(static_cast<SYSTEM_INFORMATION_CLASS>(nt::SystemExtendedHandleInformation), buffer, buffer_size, &buffer_size);
714
715 while (status == STATUS_INFO_LENGTH_MISMATCH)
716 {
717 if (buffer != nullptr)
718 VirtualFree(buffer, 0, MEM_RELEASE);
719
720 buffer = VirtualAlloc(nullptr, buffer_size, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
721 status = NtQuerySystemInformation(static_cast<SYSTEM_INFORMATION_CLASS>(nt::SystemExtendedHandleInformation), buffer, buffer_size, &buffer_size);
722 }
723
724 if (!NT_SUCCESS(status) || buffer == nullptr)
725 {
726 if (buffer != nullptr)
727 VirtualFree(buffer, 0, MEM_RELEASE);
728 return false;
729 }
730
731 uint64_t object = 0;
732
733 auto system_handle_inforamtion = static_cast<nt::PSYSTEM_HANDLE_INFORMATION_EX>(buffer);
734
735 for (auto i = 0u; i < system_handle_inforamtion->HandleCount; ++i)
736 {
737 const nt::SYSTEM_HANDLE current_system_handle = system_handle_inforamtion->Handles[i];
738
739 if (current_system_handle.UniqueProcessId != reinterpret_cast<HANDLE>(static_cast<uint64_t>(GetCurrentProcessId())))
740 continue;
741
742 if (current_system_handle.HandleValue == hDevice)
743 {
744 object = reinterpret_cast<uint64_t>(current_system_handle.Object);
745 break;
746 }
747 }
748
749 VirtualFree(buffer, 0, MEM_RELEASE);
750
751 if (!object)
752 return false;
753
754 uint64_t device_object = 0;
755
756 if (!ReadMemory(object + 0x8, &device_object, sizeof(device_object)) || !device_object) {
757 Log::Warning("Failed to find device_object", false);
758 return false;
759 }
760
761 uint64_t driver_object = 0;
762
763 if (!ReadMemory(device_object + 0x8, &driver_object, sizeof(driver_object)) || !driver_object) {
764 Log::Warning("Failed to find driver_object", false);
765 return false;

Callers

nothing calls this directly

Calls 3

WarningFunction · 0.50
FineFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected