Nov 10, 2020 01:08 PM
(This post was last modified: Nov 10, 2020 01:08 PM by HardStoN.)
Hi,
Thats my IOCTL handle function in the driver
And that's my controller
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?
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?

