A forum for reverse engineering, OS internals and malware analysis 

Forum for discussion about kernel-mode development.
 #25524  by Vrtule
 Sat Mar 28, 2015 12:24 pm
Hello,

PsSetLoadImageNotifyRoutine lets you register a callback that is invoked whenever a PE image (including driver ones) is mapped to memory. So, you get notified when a driver image is mapped to the kernel memory, however, you don't get information about creation of its DRIVER_OBJECT etc.

To monitor unload of a specific driver, you can try to modify the DriverUnload field of its DRIVER_OBJECT structure. Of course, you must not do it in case this field is NULL (that would make the driver unloadable even if it do not wish so). I am not sure whether the DriverUnload field is protected by Patchguard.
 #25674  by cziter15
 Fri Apr 17, 2015 4:49 pm
Vrtule wrote: I am not sure whether the DriverUnload field is protected by Patchguard.
It isn't. Anyway if it will even be, in future, you can simply hook DriverUnload routine, so protecting this value does not make sense.