A forum for reverse engineering, OS internals and malware analysis 

Forum for discussion about kernel-mode development.
 #14167  by AlexCasual
 Fri Jun 22, 2012 2:04 pm
Hello guyz)

I have usb device object address and want to send IRP_MN_REMOVE_DEVICE :
Code: Select all
...
PIRP Irp;
PIO_STACK_LOCATION IrpStack;
IO_STATUS_BLOCK IoStatusBlock;
KEVENT Event;
NTSTATUS Status;
PDEVICE_OBJECT TopDeviceObject;

PAGED_CODE();

TopDeviceObject = IoGetAttachedDeviceReference(DeviceObject);
 
 Irp = IoAllocateIrp(TopDeviceObject->StackSize + 1, FALSE);

 if(!Irp) 
    return STATUS_INSUFFICIENT_RESOURCES;
    
 KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
        
IrpStack = IoGetNextIrpStackLocation(Irp);

IrpStack->DeviceObject  = TopDeviceObject;
IrpStack->MajorFunction = IRP_MJ_PNP;
IrpStack->MinorFunction = IRP_MN_REMOVE_DEVICE;

Irp->UserIosb = &IoStatusBlock;
Irp->UserEvent = &Event;

Status = IoCallDriver(TopDeviceObject, Irp);
if (Status == STATUS_PENDING)
{
        KeWaitForSingleObject(&Event,
                              Executive,
                              KernelMode,
                              FALSE,
                              NULL);

        Status = IoStatusBlock.Status;
}

ObDereferenceObject(TopDeviceObject);
...
And have BSOD IRQL_NOT_LESS_OR_EQUAL...

What I do wrong?
 #14194  by rkhunter
 Sat Jun 23, 2012 10:33 am
Would be great using Windbg in this case: analyze of crash dump or post mortem debug. So you have sources and symbols this would be easy I think.
 #14216  by frank_boldewin
 Sun Jun 24, 2012 6:10 am
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
Reserved for system use. Drivers must not send this IRP.

If a bus driver detects that one (or more) of its child devices (child PDOs) has been physically removed from the computer, the bus driver calls IoInvalidateDeviceRelations to report the change to the PnP manager. The PnP manager then sends remove IRPs for any devices that have disappeared.