c ++ - Calling kernel driver IoControl

Indlæg af Hanne Mølgaard Plasc

Problem



Jeg har lige sammensat en kernel driver. Nu har jeg samlet en usermode ansøgning, driver indgang og DriverInitialize synes at fungere korrekt. Jeg kan dog ikke få IoControl udløst.


Se nedenfor for uddrag af hvad jeg laver.


Ansøgning:


    HANDLE hDriver = CreateFileA("\\.\Global\testdriver", GENERIC\_READ | GENERIC\_WRITE,
        FILE\_SHARE\_READ | FILE\_SHARE\_WRITE, nullptr, OPEN\_EXISTING, 0, nullptr);


    const bool success = DeviceIoControl(hDriver, REQUEST(WRITE), &WriteRequest, sizeof(WriteRequest),


Chauffør:


    NTSTATUS IoControl(PDEVICE\_OBJECT DeviceObject, PIRP Irp)
    {
        UNREFERENCED\_PARAMETER(DeviceObject);

        DbgPrint("IO FUNCTION");
        // Complete the request
        Irp->IoStatus.Status = STATUS\_SUCCESS;
        Irp->IoStatus.Information = 0;
        IoCompleteRequest(Irp, IO\_NO\_INCREMENT);

        return Status;
    }

NTSTATUS DriverInitialize(
    \_In\_  struct \_DRIVER\_OBJECT *DriverObject,
    \_In\_  PUNICODE\_STRING RegistryPath
)
{
    NTSTATUS        status;
    UNICODE\_STRING  SymLink, DevName;
    PDEVICE\_OBJECT  devobj;
    ULONG           t;

    UNREFERENCED\_PARAMETER(RegistryPath);


    RtlInitUnicodeString(&DevName, L"\Device\testdriver");
    status = IoCreateDevice(DriverObject, 0, &DevName, FILE\_DEVICE\_UNKNOWN, FILE\_DEVICE\_SECURE\_OPEN, TRUE, &devobj);


    if (!NT\_SUCCESS(status)) {
        return status;
    }

    RtlInitUnicodeString(&SymLink, L"\DosDevices\Global\testdriver");
    status = IoCreateSymbolicLink(&SymLink, &DevName);

    devobj->Flags |= DO\_BUFFERED\_IO;

    DriverObject->MajorFunction[IRP\_MJ\_DEVICE\_CONTROL] = &IoControl;

    devobj->Flags &= ~DO\_DEVICE\_INITIALIZING;
    return status;
}

    NTSTATUS DriverEntry(
        \_In\_  struct \_DRIVER\_OBJECT *DriverObject,
        \_In\_  PUNICODE\_STRING RegistryPath
    )
    {
        NTSTATUS        status;
        UNICODE\_STRING  drvName;

        UNREFERENCED\_PARAMETER(DriverObject);
        UNREFERENCED\_PARAMETER(RegistryPath);


        RtlInitUnicodeString(&drvName, L"\Driver\testdriver");
        status = IoCreateDriver(&drvName, &DriverInitialize);


        return status;
    }


DeviceIoControl returnerer sandt, men DbgPrint ('IO FUNCTION') udløses aldrig inden for IoControl. (ej heller er min funktion til at skrive, hvilket virker hvis jeg sætter det ind i førerkortet eller driverens initialisering).


Tak for hjælpen

Bedste reference