Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Driver crashes on receiving IRP from user-mode program

Hi,

Thats my IOCTL handle function in the driver
Code
NTSTATUS IOCTL(PDEVICE_OBJECT DeviceObject, PIRP Irp) {

    NTSTATUS Status = STATUS_UNSUCCESSFUL;
    PIO_STACK_LOCATION stck = IoGetCurrentIrpStackLocation(Irp);
    ULONG ctlCode = stck->Parameters.DeviceIoControl.IoControlCode;
    ULONG ByteIO = 0;

    if (ctlCode == IOCTL_TEST_CODE) {
        PULONG ptr_output = (PULONG)Irp->AssociatedIrp.SystemBuffer;
        *ptr_output = 852;

        DbgPrint("I got the code!");
        Status = STATUS_SUCCESS;
        ByteIO = sizeof(*ptr_output);
    }
    else
    {
        ByteIO = 0;
        DbgPrint("Unknown code has been fetched!");
    }

    Irp->IoStatus.Status = Status;
    Irp->IoStatus.Information = ByteIO;
    IoCompleteRequest(Irp, IO_NO_INCREMENT);

    return Status;
}

And that's my controller
Code
#include <iostream>
#include <Windows.h>

using namespace std;

#define IOCTL_TEST_CODE CTL_CODE(FILE_DEVICE_UNKNOWN, 0xdeadbeef, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)

int main()
{
    HANDLE hDriver = CreateFileA("\\\\.\\permppdr", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
        0, OPEN_EXISTING, 0, 0);
    
    if (hDriver == INVALID_HANDLE_VALUE) {
        cout << "Invalid handle!" << endl;
        return 0;
    }

    DeviceIoControl(hDriver, IOCTL_TEST_CODE, 0, 0, 0, 0, 0, 0);
    CloseHandle(hDriver);
    return 0;
}

The driver loads and unloads successfully but the second i run the controller the driver crashes and i get a blue screen :)

Any ideas why?
I don't write drivers, but take a look at this full IOCTL example code from Microsoft: https://github.com/microsoft/Windows-dri.../ioctl/wdm
yeah thank u either way i solved it :) there was a problem with my Irp variables and when i did
Code
IoCompleteRequest(Irp, IO_NO_INCREMENT);
it crashed but now its fixed


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by lo0srJun 12, 2021 06:17 PM 7 293 Jun 12, 2021 06:17 PM
Last Post: lo0sr
[C#] by HardStoNFeb 18, 2021 05:33 AM 0 166 Feb 18, 2021 05:33 AM
Last Post: HardStoN
[C] by HardStoNNov 12, 2020 04:02 PM 5 215 Nov 12, 2020 04:02 PM
Last Post: HardStoN