Ejemplo n.º 1
0
static NTSTATUS drv_control(PDEVICE_OBJECT device, PIRP irp) {
	PIO_STACK_LOCATION irpstack;
	ULONG controlcode;
	NTSTATUS status;

	irp->IoStatus.Status=STATUS_SUCCESS;
	irp->IoStatus.Information=0;

	irpstack=IoGetCurrentIrpStackLocation(irp);
	controlcode=irpstack->Parameters.DeviceIoControl.IoControlCode;

	switch(controlcode) {
		case IOCTL_PEERGUARDIAN_HOOK:
			if(irp->AssociatedIrp.SystemBuffer!=NULL && irpstack->Parameters.DeviceIoControl.InputBufferLength==sizeof(int)) {
				int *hook=(int*)irp->AssociatedIrp.SystemBuffer;
				setfilter((*hook)?filter_cb:NULL);
			}
			else irp->IoStatus.Status=STATUS_INVALID_PARAMETER;
			break;
		case IOCTL_PEERGUARDIAN_HTTP:
			if(irp->AssociatedIrp.SystemBuffer!=NULL && irpstack->Parameters.DeviceIoControl.InputBufferLength==sizeof(int)) {
				g_internal->blockhttp=*((int*)irp->AssociatedIrp.SystemBuffer);
			}
			else irp->IoStatus.Status=STATUS_INVALID_PARAMETER;
			break;
		case IOCTL_PEERGUARDIAN_SETRANGES: {
			PGRANGES *ranges;
			ULONG inputlen;

			ranges = irp->AssociatedIrp.SystemBuffer;
			inputlen = irpstack->Parameters.DeviceIoControl.InputBufferLength;

			if(inputlen >= offsetof(PGRANGES, ranges[0]) && inputlen >= offsetof(PGRANGES, ranges[ranges->count])) {
				SetRanges(ranges, ranges->block);
			}
			else {
				irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
			}
		} break;
		case IOCTL_PEERGUARDIAN_GETNOTIFICATION:
			return Notification_Recieve(&g_internal->queue, irp);
		case IOCTL_PEERGUARDIAN_CONNECTION_LIMIT:
			if(irp->AssociatedIrp.SystemBuffer!=NULL && irpstack->Parameters.DeviceIoControl.InputBufferLength==sizeof(int)) {
				g_internal->f_cons_last_received_IP_count_limit=*((int*)irp->AssociatedIrp.SystemBuffer);
			}
			else irp->IoStatus.Status=STATUS_INVALID_PARAMETER;
			break;
		case IOCTL_PEERGUARDIAN_SET_PORT:
			if(irp->AssociatedIrp.SystemBuffer!=NULL && irpstack->Parameters.DeviceIoControl.InputBufferLength==sizeof(int))
			{
				int param = *((int*)irp->AssociatedIrp.SystemBuffer);
				char openstatus = (char)(0xFF & param);
				unsigned short portnumber = param >> 16;
				if( portnumber == 0 || openstatus == 0)
					irp->IoStatus.Status=STATUS_INVALID_PARAMETER;
				g_internal->f_port_open_ports[ portnumber ] = openstatus - 1;
			}
			else irp->IoStatus.Status=STATUS_INVALID_PARAMETER;
Ejemplo n.º 2
0
static NTSTATUS drv_control(PDEVICE_OBJECT device, PIRP irp)
{
	PIO_STACK_LOCATION irpstack;
	ULONG controlcode;
	NTSTATUS status;

	irp->IoStatus.Status=STATUS_SUCCESS;
	irp->IoStatus.Information=0;

	irpstack=IoGetCurrentIrpStackLocation(irp);
	controlcode=irpstack->Parameters.DeviceIoControl.IoControlCode;

	switch(controlcode)
	{
	case IOCTL_PEERBLOCK_HOOK:
		DbgPrint("pbfilter:  > IOCTL_PEERBLOCK_HOOK\n");
		if(irp->AssociatedIrp.SystemBuffer!=NULL && irpstack->Parameters.DeviceIoControl.InputBufferLength==sizeof(int))
		{
			int *hook=(int*)irp->AssociatedIrp.SystemBuffer;
			DbgPrint("pbfilter:    setting filter...\n");
			setfilter((*hook)?filter_cb:NULL);
			DbgPrint("pbfilter:    ...filter set\n");
		}
		else
		{
			DbgPrint("pbfilter:  * ERROR: invalid parameter\n");
			irp->IoStatus.Status=STATUS_INVALID_PARAMETER;
		}
		DbgPrint("pbfilter:  < IOCTL_PEERBLOCK_HOOK\n");
		break;

	case IOCTL_PEERBLOCK_SETRANGES:
	{
		PBRANGES *ranges;
		ULONG inputlen;

		DbgPrint("pbfilter:  > IOCTL_PEERBLOCK_SETRANGES\n");
		ranges = irp->AssociatedIrp.SystemBuffer;
		inputlen = irpstack->Parameters.DeviceIoControl.InputBufferLength;

		if(inputlen >= offsetof(PBRANGES, ranges[0]) && inputlen >= offsetof(PBRANGES, ranges[ranges->count]))
		{
			DbgPrint("pbfilter:    calling SetRanges()\n");
			SetRanges(ranges, ranges->block);
		}
		else
		{
			DbgPrint("pbfilter:  * Error: STATUS_INVALID_PARAMETER\n");
			irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
		}
		DbgPrint("pbfilter:  < IOCTL_PEERBLOCK_SETRANGES\n");
	}
	break;

	case IOCTL_PEERBLOCK_GETNOTIFICATION:
		return Notification_Recieve(&g_internal->queue, irp);

	case IOCTL_PEERBLOCK_SETDESTINATIONPORTS:
	{
		USHORT *ports;
		ULONG count;

		DbgPrint("pbfilter:    > IOCTL_PEERBLOCK_SETDESTINATIONPORTS\n");
		ports = irp->AssociatedIrp.SystemBuffer;
		count = irpstack->Parameters.DeviceIoControl.InputBufferLength;

		SetDestinationPorts(ports, (USHORT) (count / sizeof(USHORT)));
		DbgPrint("pbfilter:    < IOCTL_PEERBLOCK_SETDESTINATIONPORTS\n");

	}
	break;

	case IOCTL_PEERBLOCK_SETSOURCEPORTS:
	{
		USHORT *ports;
		ULONG count;

		DbgPrint("pbfilter:    > IOCTL_PEERBLOCK_SETSOURCEPORTS\n");
		ports = irp->AssociatedIrp.SystemBuffer;
		count = irpstack->Parameters.DeviceIoControl.InputBufferLength;

		SetSourcePorts(ports, (USHORT) (count / sizeof(USHORT)));
		DbgPrint("pbfilter:    < IOCTL_PEERBLOCK_SETSOURCEPORTS\n");

	}
	break;

	default:
		DbgPrint("pbfilter:  * ERROR: invalid parameter for IOCTL!\n");
		irp->IoStatus.Status=STATUS_INVALID_PARAMETER;
	}

	status=irp->IoStatus.Status;
	IoCompleteRequest(irp, IO_NO_INCREMENT);
	return status;
}