Пример #1
0
NTSTATUS
AddDevice(
    IN  PDRIVER_OBJECT  DriverObject,
    IN  PDEVICE_OBJECT  DeviceObject
    )
{
    NTSTATUS            status;

    ASSERT3P(DriverObject, ==, __DriverGetDriverObject());

    status = FdoCreate(DeviceObject);
    if (!NT_SUCCESS(status))
        goto fail1;

    // prefast stupidity
    ASSERT(!(DeviceObject->Flags & DO_DEVICE_INITIALIZING));
    DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;

    return STATUS_SUCCESS;

fail1:
    Error("fail1 (%08x)\n", status);

    return status;
}
Пример #2
0
static
NTSTATUS
NTAPI
DispatchCreate(IN PDEVICE_OBJECT DeviceObject,
               IN PIRP Irp)
{
    if (((PFDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension)->Common.IsFDO)
        return FdoCreate(DeviceObject, Irp);
    else
        return PdoCreate(DeviceObject, Irp);
}
Пример #3
0
NTSTATUS
#pragma prefast(suppress:28152) // Does not clear DO_DEVICE_INITIALIZING
AddDevice(
    IN  PDRIVER_OBJECT  DriverObject,
    IN  PDEVICE_OBJECT  PhysicalDeviceObject
    )
{
    HANDLE              ParametersKey;
    PWCHAR              DeviceID;
    UNICODE_STRING      Unicode;
    ANSI_STRING         Name;
    PANSI_STRING        Type;
    NTSTATUS            status;

    ASSERT3P(DriverObject, ==, __DriverGetDriverObject());

    ParametersKey = __DriverGetParametersKey();
    if (ParametersKey == NULL)
        goto done;

    status = __DriverQueryId(PhysicalDeviceObject, BusQueryDeviceID, &DeviceID);
    if (!NT_SUCCESS(status))
        goto fail1;

    RtlInitUnicodeString(&Unicode, DeviceID);

    status = RtlUnicodeStringToAnsiString(&Name, &Unicode, TRUE);
    if (!NT_SUCCESS(status))
        goto fail2;

    status = RegistryQuerySzValue(ParametersKey,
                                  Name.Buffer,
                                  &Type);
    if (NT_SUCCESS(status)) {
        status = FdoCreate(PhysicalDeviceObject, &Name, Type);
        if (!NT_SUCCESS(status))
            goto fail3;

        RegistryFreeSzValue(Type);
    }

    RtlFreeAnsiString(&Name);
    ExFreePool(DeviceID);

done:
    return STATUS_SUCCESS;

fail3:
    Error("fail3\n");

    RegistryFreeSzValue(Type);

    RtlFreeAnsiString(&Name);

fail2:
    Error("fail2\n");

    ExFreePool(DeviceID);

fail1:
    Error("fail1 (%08x)\n", status);

    return status;
}
Пример #4
0
NTSTATUS
#pragma prefast(suppress:28152) // Does not clear DO_DEVICE_INITIALIZING
AddDevice(
    IN  PDRIVER_OBJECT  DriverObject,
    IN  PDEVICE_OBJECT  DeviceObject
    )
{
    HANDLE              ParametersKey;
    PANSI_STRING        ActiveDeviceInstance;
    BOOLEAN             Active;
    PWCHAR              DeviceID;
    PWCHAR              InstanceID;
    UNICODE_STRING      Unicode;
    ULONG               Length;
    NTSTATUS            status;

    ASSERT3P(DriverObject, ==, __DriverGetDriverObject());

    ParametersKey = __DriverGetParametersKey();

    ActiveDeviceInstance = NULL;
    if (ParametersKey != NULL) {
        status = RegistryQuerySzValue(ParametersKey,
                                      "ActiveDeviceInstance",
                                      &ActiveDeviceInstance);
        ASSERT(IMPLY(!NT_SUCCESS(status), ActiveDeviceInstance == NULL));
    } else {
        ActiveDeviceInstance = NULL;
    }

    Active = FALSE;

    DeviceID = NULL;
    InstanceID = NULL;

    RtlZeroMemory(&Unicode, sizeof (UNICODE_STRING));

    if (ActiveDeviceInstance == NULL)
        goto done;

    status = __DriverQueryId(DeviceObject, BusQueryDeviceID, &DeviceID);
    if (!NT_SUCCESS(status))
        goto fail1;

    status = __DriverQueryId(DeviceObject, BusQueryInstanceID, &InstanceID);
    if (!NT_SUCCESS(status))
        goto fail2;

    status = RtlAnsiStringToUnicodeString(&Unicode, ActiveDeviceInstance, TRUE);
    if (!NT_SUCCESS(status))
        goto fail3;

    Length = (ULONG)wcslen(DeviceID);
    if (_wcsnicmp(Unicode.Buffer,
                  DeviceID,
                  Length) != 0)
        goto done;

    Length = (ULONG)wcslen(InstanceID);
    if (_wcsnicmp(Unicode.Buffer + (Unicode.Length / sizeof (WCHAR)) - Length,
                  InstanceID,
                  Length) != 0)
        goto done;

    Active = TRUE;

    RegistryFreeSzValue(ActiveDeviceInstance);

done:
    if (Unicode.Buffer != NULL)
        RtlFreeUnicodeString(&Unicode);

    if (InstanceID != NULL)
        ExFreePool(InstanceID);

    if (DeviceID != NULL)
        ExFreePool(DeviceID);

    status = FdoCreate(DeviceObject, Active);
    if (!NT_SUCCESS(status))
        goto fail3;

    return STATUS_SUCCESS;

fail3:
    if (InstanceID != NULL)
        ExFreePool(InstanceID);

fail2:
    if (DeviceID != NULL)
        ExFreePool(DeviceID);

fail1:
    RegistryFreeSzValue(ActiveDeviceInstance);

    Error("fail1 (%08x)\n", status);

    return status;
}