| 167 | } |
| 168 | |
| 169 | NTSTATUS DevMonManager::AddDriver(PCWSTR driverName, PVOID* driverObject) { |
| 170 | int index = -1; |
| 171 | // |
| 172 | // find first available slot,make sure driver is not already monitored |
| 173 | // |
| 174 | |
| 175 | for (int i = 0; i < MaxMonitoredDrivers; ++i) { |
| 176 | if (globals.Drivers[i].DriverObject == nullptr) { |
| 177 | if (index < 0) |
| 178 | index = i; |
| 179 | } |
| 180 | else { |
| 181 | // existing driver,check if not already being monitored |
| 182 | if (_wcsicmp(globals.Drivers[i].DriverName, driverName) == 0) { |
| 183 | *driverObject = globals.Drivers[i].DriverObject; |
| 184 | return STATUS_SUCCESS; |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | UNICODE_STRING name; |
| 190 | RtlInitUnicodeString(&name, driverName); |
| 191 | PDRIVER_OBJECT driver; |
| 192 | auto status = ObReferenceObjectByName(&name, OBJ_CASE_INSENSITIVE, nullptr, 0, *IoDriverObjectType, KernelMode, nullptr, (PVOID*)&driver); |
| 193 | if (!NT_SUCCESS(status)) |
| 194 | return status; |
| 195 | |
| 196 | ::wcscpy_s(globals.Drivers[index].DriverName, driverName); |
| 197 | |
| 198 | for (int i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) { |
| 199 | globals.Drivers[i].MajorFunction[i] = |
| 200 | static_cast<PDRIVER_DISPATCH>(InterlockedExchangePointer((PVOID*)&driver->MajorFunction[i], DriverMonGenericDispatch)); |
| 201 | } |
| 202 | |
| 203 | globals.Drivers[index].DriverUnload = |
| 204 | static_cast<PDRIVER_UNLOAD>(InterlockedExchangePointer((PVOID*)&driver->DriverUnload, GenericDriverUnload)); |
| 205 | globals.Drivers[index].DriverObject = driver; |
| 206 | ++globals.Count; |
| 207 | *driverObject = driverObject; |
| 208 | |
| 209 | return STATUS_SUCCESS; |
| 210 | } |
| 211 | |
| 212 | NTSTATUS DevMonManager::RemoveDriver(int index) { |
| 213 | auto& driver = globals.Drivers[index]; |
nothing calls this directly
no test coverage detected