NTSTATUS NTAPI HalpDriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { NTSTATUS Status; PDEVICE_OBJECT TargetDevice = NULL; DPRINT("HAL: PnP Driver ENTRY!\n"); /* This is us */ HalpDriverObject = DriverObject; /* Set up add device */ DriverObject->DriverExtension->AddDevice = HalpAddDevice; /* Set up the callouts */ DriverObject->MajorFunction[IRP_MJ_PNP] = HalpDispatchPnp; DriverObject->MajorFunction[IRP_MJ_POWER] = HalpDispatchPower; DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = HalpDispatchWmi; /* Create the PDO */ Status = IoCreateDevice(DriverObject, 0, NULL, FILE_DEVICE_CONTROLLER, 0, FALSE, &TargetDevice); if (!NT_SUCCESS(Status)) return Status; TargetDevice->Flags &= ~DO_DEVICE_INITIALIZING; /* Set up the device stack */ Status = HalpAddDevice(DriverObject, TargetDevice); if (!NT_SUCCESS(Status)) { IoDeleteDevice(TargetDevice); return Status; } /* Tell the PnP manager about us */ Status = IoReportDetectedDevice(DriverObject, InterfaceTypeUndefined, -1, -1, NULL, NULL, FALSE, &TargetDevice); /* Return to kernel */ return Status; }
/* * FUNCTION: Called by the system to initialize the driver * ARGUMENTS: * DriverObject = object describing this driver * RegistryPath = path to our configuration entries * RETURNS: Success or failure */ NTSTATUS NTAPI DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath) { PDEVICE_OBJECT DeviceObject; NTSTATUS Status; UNICODE_STRING DeviceName; DPRINT("MUP 0.0.1\n"); RtlInitUnicodeString(&DeviceName, L"\\Device\\Mup"); Status = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION), &DeviceName, FILE_DEVICE_MULTI_UNC_PROVIDER, 0, FALSE, &DeviceObject); if (!NT_SUCCESS(Status)) { return Status; } /* Initialize driver data */ DeviceObject->Flags |= DO_DIRECT_IO; // DriverObject->MajorFunction[IRP_MJ_CLOSE] = NtfsClose; DriverObject->MajorFunction[IRP_MJ_CREATE] = MupCreate; DriverObject->MajorFunction[IRP_MJ_CREATE_NAMED_PIPE] = MupCreate; DriverObject->MajorFunction[IRP_MJ_CREATE_MAILSLOT] = MupCreate; // DriverObject->MajorFunction[IRP_MJ_READ] = NtfsRead; // DriverObject->MajorFunction[IRP_MJ_WRITE] = NtfsWrite; // DriverObject->MajorFunction[IRP_MJ_FILE_SYSTEM_CONTROL] = // NtfsFileSystemControl; // DriverObject->MajorFunction[IRP_MJ_DIRECTORY_CONTROL] = // NtfsDirectoryControl; // DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = // NtfsQueryInformation; // DriverObject->MajorFunction[IRP_MJ_QUERY_VOLUME_INFORMATION] = // NtfsQueryVolumeInformation; // DriverObject->MajorFunction[IRP_MJ_SET_VOLUME_INFORMATION] = // NtfsSetVolumeInformation; DriverObject->DriverUnload = NULL; /* Initialize global data */ // DeviceExtensionNtfsGlobalData = DeviceObject->DeviceExtension; // RtlZeroMemory(NtfsGlobalData, // sizeof(NTFS_GLOBAL_DATA)); // NtfsGlobalData->DriverObject = DriverObject; // NtfsGlobalData->DeviceObject = DeviceObject; return STATUS_SUCCESS; }
/* * DriverInitialize * * Purpose: * * Driver main. * */ NTSTATUS DriverInitialize( _In_ struct _DRIVER_OBJECT *DriverObject, _In_ PUNICODE_STRING RegistryPath ) { NTSTATUS status; UNICODE_STRING SymLink, DevName; PDEVICE_OBJECT devobj; ULONG t; //RegistryPath is unused UNREFERENCED_PARAMETER(RegistryPath); g_NotifySet = FALSE; g_VBoxDD.Chains = NULL; g_VBoxDD.ChainsLength = 0; KeInitializeMutex(&g_VBoxDD.Lock, 0); RtlInitUnicodeString(&DevName, TSUGUMI_DEV_OBJECT); status = IoCreateDevice(DriverObject, 0, &DevName, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, TRUE, &devobj); if (!NT_SUCCESS(status)) { return status; } RtlInitUnicodeString(&SymLink, TSUGUMI_SYM_LINK); status = IoCreateSymbolicLink(&SymLink, &DevName); if (!NT_SUCCESS(status)) { IoDeleteDevice(devobj); return status; } devobj->Flags |= DO_BUFFERED_IO; for (t = 0; t <= IRP_MJ_MAXIMUM_FUNCTION; t++) DriverObject->MajorFunction[t] = &UnsupportedDispatch; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = &DevioctlDispatch; DriverObject->MajorFunction[IRP_MJ_CREATE] = &CreateCloseDispatch; DriverObject->MajorFunction[IRP_MJ_CLOSE] = &CreateCloseDispatch; #ifndef _SIGNED_BUILD DriverObject->DriverUnload = NULL; devobj->Flags &= ~DO_DEVICE_INITIALIZING; #else DriverObject->DriverUnload = &DriverUnload; status = TsmiLoadParameters(); if (NT_SUCCESS(status)) { status = PsSetLoadImageNotifyRoutine(TsmiPsImageHandler); if (NT_SUCCESS(status)) { g_NotifySet = TRUE; } } #endif return STATUS_SUCCESS; }
NTSTATUS DriverEntry( PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pRegistryPath ) { PDEVICE_OBJECT pdo = NULL; NTSTATUS s = STATUS_SUCCESS; UNICODE_STRING usDriverName, usDosDeviceName; RtlInitUnicodeString( &usDriverName, DRIVER_NAME ); RtlInitUnicodeString( &usDosDeviceName, DEVICE_NAME ); s = IoCreateDevice( pDriverObject, 0, &usDriverName, \ FILE_DRIVER_SSDT, FILE_DEVICE_SECURE_OPEN, \ FALSE, &pdo ); if( STATUS_SUCCESS == s ) { pDriverObject->MajorFunction[IRP_MJ_CREATE] = SSDTCreate; pDriverObject->MajorFunction[IRP_MJ_CLOSE]=SSDTClose; pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] \ = SSDTDeviceIoCtl; pDriverObject->DriverUnload = SSDTUnload; IoCreateSymbolicLink( &usDosDeviceName, &usDriverName ); } MUTEX_INIT(LogMutex); // GetProcessNameOffset(); Log = ExAllocatePool(NonPagedPool,sizeof(LOG_BUF)); if(Log == NULL) { s = STATUS_INSUFFICIENT_RESOURCES; } else { Log->Length = 0; Log->Next = NULL; //pCurrentLog = Log; NumLog = 1; } pSystem = PsGetCurrentProcess(); DbgPrint("pSystem %0x",pSystem); pebAddress = GetPebAddress(); pObjectTypeProcess = *(PULONG)((ULONG)pSystem - OBJECT_HEADER_SIZE +OBJECT_TYPE_OFFSET); MyPspTerminateThreadByPointer =GetUndocumentFunctionAdress(); GetProcessNameOffset(); DbgPrint( "SSDT: Load Success!" ); return s; }
NTSTATUS STDCALL DriverEntry(PDRIVER_OBJECT driverObject, PUNICODE_STRING registryPath) { NTSTATUS status = STATUS_SUCCESS; // default status // Debug print DbgPrint("Hello!!\n"); DbgPrint("RegistryPath=%wZ\n", registryPath); // Creation of the associated device PDEVICE_OBJECT deviceObject = NULL; // represents a logical, virtual, or physical device for which a driver handles I/O requests. UNICODE_STRING deviceName; UNICODE_STRING dosDeviceName;// unicode string struct: USHORT Length, current length of the string // USHORT MaximumLength, max length of the string // PWSTR Buffer, the string /!\not even NULL terminated! RtlInitUnicodeString(&deviceName, L"\\Device\\Example"); // Initialize a unicode string RtlInitUnicodeString(&dosDeviceName, L"\\DosDevices\\Example"); status = IoCreateDevice(driverObject, // driver object 0, // length of device extention (extra data to pass) &deviceName, // device name FILE_DEVICE_UNKNOWN, // unknow because it's not a specific device FILE_DEVICE_SECURE_OPEN,// flags: FILE_DEVICE_SECURE_OPEN, // FILE_FLOPPY_DISKETTE, // FILE_READ_ONLY_DEVICE, // FILE_REMOVABLE_MEDIA, // FILE_WRITE_ONCE_MEDIA FALSE, // is an exclusive device? &deviceObject); // out if (status != STATUS_SUCCESS) { IoDeleteDevice(deviceObject); goto cleanup; } for (UINT i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++) { driverObject->MajorFunction[i] = unsuported_function; } driverObject->MajorFunction[IRP_MJ_CLOSE] = my_close; driverObject->MajorFunction[IRP_MJ_CREATE] = my_create; driverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = my_io_control; // Setting my_unload as unload function driverObject->DriverUnload = my_unload; deviceObject->Flags |= IO_TYPE; deviceObject->Flags &= (~DO_DEVICE_INITIALIZING); // DO_DEVICE_INITIALIZING: tell to not send I/O request to // the device. It is MANDATORY to clear it to use the device. // (except in DriverEntry because it is automatic) IoCreateSymbolicLink(&dosDeviceName, &deviceName); cleanup: return status; }
NTSTATUS MouFilter_AddDevice( IN PDRIVER_OBJECT Driver, IN PDEVICE_OBJECT PDO ) { PDEVICE_EXTENSION devExt; IO_ERROR_LOG_PACKET errorLogEntry; PDEVICE_OBJECT device; NTSTATUS status = STATUS_SUCCESS; PAGED_CODE(); DbgPrint(("MouFilter_AddDevice() called\n")); status = IoCreateDevice(Driver, sizeof(DEVICE_EXTENSION), NULL, FILE_DEVICE_MOUSE, 0, FALSE, &device ); if (!NT_SUCCESS(status)) { return (status); } RtlZeroMemory(device->DeviceExtension, sizeof(DEVICE_EXTENSION)); devExt = (PDEVICE_EXTENSION) device->DeviceExtension; devExt->TopOfStack = IoAttachDeviceToDeviceStack(device, PDO); if (devExt->TopOfStack == NULL) { IoDeleteDevice(device); return STATUS_DEVICE_NOT_CONNECTED; } ASSERT(devExt->TopOfStack); devExt->Self = device; devExt->PDO = PDO; devExt->DeviceState = PowerDeviceD0; devExt->SurpriseRemoved = FALSE; devExt->Removed = FALSE; devExt->Started = FALSE; device->Flags |= (DO_BUFFERED_IO | DO_POWER_PAGABLE); device->Flags &= ~DO_DEVICE_INITIALIZING; MouFilter_QueryMouseAttributes(devExt->TopOfStack); return status; }
NTSTATUS MrAddDevice( IN PDRIVER_OBJECT DriverObject, IN PDEVICE_OBJECT DeviceObject ) { struct mr_dcb *dcb; PDEVICE_OBJECT devobj = NULL; NTSTATUS status; /* create filter object for target device */ status = IoCreateDevice(DriverObject, sizeof(struct mr_dcb), NULL, FILE_DEVICE_MOUSE, 0, FALSE, &devobj ); if (!NT_SUCCESS(status)) { goto errorout; } /* initialize device extension */ dcb = (struct mr_dcb*)devobj->DeviceExtension; memset(dcb, 0, sizeof(struct mr_dcb)); /* query device info (VID/DID ...) */ status = MrInitDcb(dcb, DeviceObject); /* check whether this mouse is to be swapped */ if (STATUS_SUCCESS == status) { if (MrLookupId(dcb)) { dcb->md_state |= MR_DEV_STATE_PERSIST | MR_DEV_STATE_ENABLED; } } /* attach filter into target device stack */ dcb->md_target = IoAttachDeviceToDeviceStack( devobj, DeviceObject); devobj->Flags |= DO_BUFFERED_IO | DO_POWER_PAGABLE; devobj->Flags &= ~DO_DEVICE_INITIALIZING; /* insert dcb into global list */ MrLockGlobal(TRUE); InsertTailList(&g_core.mc_dcb_list, &dcb->md_link); g_core.mc_dcb_count++; MrUnlockGlobal(); errorout: return STATUS_SUCCESS; }
NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) { NTSTATUS ntStatus; UNICODE_STRING uszDriverString; UNICODE_STRING uszDeviceString; UNICODE_STRING uszProcessEventString; PDEVICE_OBJECT pDeviceObject; PDEVICE_EXTENSION extension; RtlInitUnicodeString(&uszDriverString, DEVICE_NAME); ntStatus = IoCreateDevice(DriverObject, sizeof(DEVICE_EXTENSION), &uszDriverString, FILE_DEVICE_UNKNOWN, 0, FALSE, &pDeviceObject); if(ntStatus != STATUS_SUCCESS) return ntStatus; extension = pDeviceObject->DeviceExtension; RtlInitUnicodeString(&uszDeviceString, DEVICE_LINK_NAME); ntStatus = IoCreateSymbolicLink(&uszDeviceString, &uszDriverString); if(ntStatus != STATUS_SUCCESS) { IoDeleteDevice(pDeviceObject); return ntStatus; } g_pDeviceObject = pDeviceObject; DriverObject->MajorFunction[IRP_MJ_CREATE] = DispatchCreateClose; DriverObject->MajorFunction[IRP_MJ_CLOSE] = DispatchCreateClose; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = Dispatch; DriverObject->DriverUnload = UnloadDriver; RtlInitUnicodeString(&uszProcessEventString, MONITOR_PROCESS_EVENT); extension->ProcessEvent = IoCreateNotificationEvent (&uszProcessEventString, &extension->hProcessHandle); KeClearEvent(extension->ProcessEvent); ntStatus = PsSetCreateProcessNotifyRoutine(ProcessCallback, FALSE); return ntStatus; }
NTSTATUS NTAPI KMix_InstallDevice( IN PDRIVER_OBJECT DriverObject) { NTSTATUS Status; UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\kmixer"); PDEVICE_OBJECT DeviceObject; PKMIXER_DEVICE_EXT DeviceExtension; DPRINT1("KMix_InstallDevice called\n"); /* create the device */ Status = IoCreateDevice(DriverObject, sizeof(KMIXER_DEVICE_EXT), &DeviceName, FILE_DEVICE_KS, 0, FALSE, &DeviceObject); /* check for success */ if (!NT_SUCCESS(Status)) { DPRINT("Failed to create \\Device\\kmixer !\n"); return Status; } DeviceExtension = (PKMIXER_DEVICE_EXT)DeviceObject->DeviceExtension; /* initialize device extension */ RtlZeroMemory(DeviceExtension, sizeof(KMIXER_DEVICE_EXT)); Status = KMixAllocateDeviceHeader(DeviceExtension); if (!NT_SUCCESS(Status)) { DPRINT1("KMixAllocateDeviceHeader failed with %x\n", Status); goto cleanup; } /* set io flags */ DeviceObject->Flags |= DO_DIRECT_IO | DO_POWER_PAGABLE; /* clear initializing flag */ DeviceObject->Flags &= ~ DO_DEVICE_INITIALIZING; DPRINT("KMix_InstallDevice result %x\n", Status); return STATUS_SUCCESS; cleanup: IoDeleteDevice(DeviceObject); return Status; }
NTSTATUS NTAPI DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { PDEVICE_OBJECT DeviceObject; UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\Null"); NTSTATUS Status; PFAST_IO_DISPATCH FastIoDispatch; PAGED_CODE(); /* Page the driver */ MmPageEntireDriver(DriverEntry); /* Create null device */ Status = IoCreateDevice(DriverObject, 0, &DeviceName, FILE_DEVICE_NULL, 0, FALSE, &DeviceObject); if (!NT_SUCCESS(Status)) return Status; /* Register driver routines */ DriverObject->MajorFunction[IRP_MJ_CLOSE] = NullDispatch; DriverObject->MajorFunction[IRP_MJ_CREATE] = NullDispatch; DriverObject->MajorFunction[IRP_MJ_WRITE] = NullDispatch; DriverObject->MajorFunction[IRP_MJ_READ] = NullDispatch; DriverObject->MajorFunction[IRP_MJ_LOCK_CONTROL] = NullDispatch; DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = NullDispatch; /* Allocate the fast I/O dispatch table */ FastIoDispatch = ExAllocatePool(NonPagedPool, sizeof(FAST_IO_DISPATCH)); if (!FastIoDispatch) { /* Failed, cleanup */ IoDeleteDevice(DeviceObject); return STATUS_INSUFFICIENT_RESOURCES; } /* Initialize it */ RtlZeroMemory(FastIoDispatch, sizeof(FAST_IO_DISPATCH)); FastIoDispatch->SizeOfFastIoDispatch = sizeof(FAST_IO_DISPATCH); /* Setup our pointers */ FastIoDispatch->FastIoRead = NullRead; FastIoDispatch->FastIoWrite = NullWrite; DriverObject->FastIoDispatch = FastIoDispatch; /* Return success */ return STATUS_SUCCESS; }
VOID NTAPI HalpReportDetectedDevices(IN PDRIVER_OBJECT DriverObject, IN PVOID Context, IN ULONG Count) { PFDO_EXTENSION FdoExtension = Context; PPDO_EXTENSION PdoExtension; PDEVICE_OBJECT PdoDeviceObject; PDESCRIPTION_HEADER Wdrt; NTSTATUS Status; /* Create the PDO */ Status = IoCreateDevice(DriverObject, sizeof(PDO_EXTENSION), NULL, FILE_DEVICE_BUS_EXTENDER, FILE_AUTOGENERATED_DEVICE_NAME, FALSE, &PdoDeviceObject); if (!NT_SUCCESS(Status)) { /* Fail */ DPRINT1("HAL: Could not create ACPI device object status=0x%08x\n", Status); return; } /* Setup the PDO device extension */ PdoExtension = PdoDeviceObject->DeviceExtension; PdoExtension->ExtensionType = PdoExtensionType; PdoExtension->PhysicalDeviceObject = PdoDeviceObject; PdoExtension->ParentFdoExtension = FdoExtension; PdoExtension->PdoType = AcpiPdo; /* Add the PDO to the head of the list */ PdoExtension->Next = FdoExtension->ChildPdoList; FdoExtension->ChildPdoList = PdoExtension; /* Initialization is finished */ PdoDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; /* Find the ACPI watchdog table */ Wdrt = HalAcpiGetTable(0, 'TRDW'); if (Wdrt) { /* FIXME: TODO */ DPRINT1("You have an ACPI Watchdog. That's great! You should be proud ;-)\n"); } /* This will synchronously load the ACPI driver (needed because we're critical for boot) */ IoSynchronousInvalidateDeviceRelations(FdoExtension->PhysicalDeviceObject, BusRelations); }
// // 创建一个可见的设备 // NTSTATUS XFilter_Create( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) { NTSTATUS status = STATUS_SUCCESS; PXPACKET_DEVICE_EXTENSION pDeviceExtension = NULL; PDEVICE_OBJECT pFilterDeviceObject = NULL; UNICODE_STRING usTempName; UNICODE_STRING SymbolicLinkName; RtlInitUnicodeString(&usTempName, XPACKET_XFILTER_DEVICE_NAME); status = IoCreateDevice( IN DriverObject, IN sizeof(XPACKET_DEVICE_EXTENSION), IN &usTempName, IN FILE_DEVICE_XPACKET, IN 0, IN FALSE, OUT &pFilterDeviceObject ); if(status != STATUS_SUCCESS) { dprintf(("XFilter_Create: Couldn't create the XFilter Device Object(0x%X)\n", status)); return( status ); } RtlInitUnicodeString(&SymbolicLinkName, XPACKET_XFILTER_DOS_DEVICE_NAME); status = IoCreateSymbolicLink( &SymbolicLinkName, &usTempName); if (!NT_SUCCESS(status)) { dprintf(("IpFilter_Attach: Couldn't create the Ip Filter Dos Device Object(0x%X)\n", status)); IoDeleteDevice(pFilterDeviceObject); pFilterDeviceObject = NULL; return( status ); } pDeviceExtension = (PXPACKET_DEVICE_EXTENSION)pFilterDeviceObject->DeviceExtension; NdisZeroMemory(pDeviceExtension, sizeof(XPACKET_DEVICE_EXTENSION)); pDeviceExtension->ulNodeType = XPACKET_NOTE_TYPE_X_FILTER_DEVICE; pDeviceExtension->ulNodeSize = sizeof(XPACKET_DEVICE_EXTENSION); dprintf(("XFilter_Create: Success Create XFilter Device Object(0x%X)\n", status)); return status; }
NTSTATUS VolumeFilterAddDevice (PDRIVER_OBJECT driverObject, PDEVICE_OBJECT pdo) { VolumeFilterExtension *Extension; NTSTATUS status; PDEVICE_OBJECT filterDeviceObject = NULL; PDEVICE_OBJECT attachedDeviceObject; Dump ("VolumeFilterAddDevice pdo=%p\n", pdo); attachedDeviceObject = IoGetAttachedDeviceReference (pdo); status = IoCreateDevice (driverObject, sizeof (VolumeFilterExtension), NULL, attachedDeviceObject->DeviceType, 0, FALSE, &filterDeviceObject); ObDereferenceObject (attachedDeviceObject); if (!NT_SUCCESS (status)) { filterDeviceObject = NULL; goto err; } Extension = (VolumeFilterExtension *) filterDeviceObject->DeviceExtension; memset (Extension, 0, sizeof (VolumeFilterExtension)); Extension->LowerDeviceObject = IoAttachDeviceToDeviceStack (filterDeviceObject, pdo); // IoAttachDeviceToDeviceStackSafe() is not required in AddDevice routine and is also unavailable on Windows 2000 SP4 if (!Extension->LowerDeviceObject) { status = STATUS_DEVICE_REMOVED; goto err; } Extension->IsVolumeFilterDevice = TRUE; Extension->DeviceObject = filterDeviceObject; Extension->Pdo = pdo; IoInitializeRemoveLock (&Extension->Queue.RemoveLock, 'LRCT', 0, 0); filterDeviceObject->Flags |= Extension->LowerDeviceObject->Flags & (DO_DIRECT_IO | DO_BUFFERED_IO | DO_POWER_PAGABLE); filterDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING; return status; err: if (filterDeviceObject) { if (Extension->LowerDeviceObject) IoDetachDevice (Extension->LowerDeviceObject); IoDeleteDevice (filterDeviceObject); } return status; }
NTSTATUS ulkAddDevice( PDRIVER_OBJECT driverObject, PDEVICE_OBJECT pdo) { NTSTATUS status; PDEVICE_OBJECT fdo = NULL; PULK_DEV_EXT devExt; PAGED_CODE(); #ifdef DBG DbgPrint("[ulk] AddDevice(0x%x)\n", pdo); #endif __try { status = IoCreateDevice(driverObject, sizeof(ULK_DEV_EXT), NULL, pdo->DeviceType, 0, FALSE, &fdo); if(!NT_SUCCESS(status)) { DbgPrint("[ulk] ERROR ulkAddDevice:IoCreateDevice(%s)\n", OsrNTStatusToString(status)); __leave; } devExt = (PULK_DEV_EXT)fdo->DeviceExtension; RtlZeroMemory(devExt, sizeof(ULK_DEV_EXT)); IoInitializeRemoveLock(&devExt->removeLock, DEV_EXT_TAG, 0, 0); devExt->pdo = pdo; devExt->lowerDevice = IoAttachDeviceToDeviceStack(fdo, pdo); if (!devExt->lowerDevice) { DbgPrint("[ulk] ERROR ulkAddDevice:IoAttachDeviceToDeviceStack\n"); status = STATUS_INTERNAL_ERROR; __leave; } fdo->Flags = pdo->Flags & (DO_BUFFERED_IO | DO_DIRECT_IO | DO_POWER_INRUSH | DO_POWER_PAGABLE); fdo->Flags &= ~DO_DEVICE_INITIALIZING; } __finally { if (!NT_SUCCESS(status)) { if (fdo) { ulkDeleteDevice(fdo); } } } return STATUS_SUCCESS; }
// // This is where it all starts... // NTSTATUS DriverEntry(IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath) { NTSTATUS status; PDEVICE_OBJECT device_object; UNICODE_STRING ctl_device_name; UNICODE_STRING sym_link; AWEAllocDriverObject = DriverObject; MmPageEntireDriver((PVOID)(ULONG_PTR)DriverEntry); // Create the control device. RtlInitUnicodeString(&ctl_device_name, AWEALLOC_DEVICE_NAME); status = IoCreateDevice(DriverObject, 0, &ctl_device_name, FILE_DEVICE_NULL, 0, FALSE, &device_object); if (!NT_SUCCESS(status)) return status; device_object->Flags |= DO_DIRECT_IO; RtlInitUnicodeString(&sym_link, AWEALLOC_SYMLINK_NAME); status = IoCreateUnprotectedSymbolicLink(&sym_link, &ctl_device_name); if (!NT_SUCCESS(status)) { IoDeleteDevice(device_object); return status; } DriverObject->MajorFunction[IRP_MJ_CREATE] = AWEAllocCreate; DriverObject->MajorFunction[IRP_MJ_CLOSE] = AWEAllocClose; DriverObject->MajorFunction[IRP_MJ_READ] = AWEAllocReadWrite; DriverObject->MajorFunction[IRP_MJ_WRITE] = AWEAllocReadWrite; DriverObject->MajorFunction[IRP_MJ_FLUSH_BUFFERS] = AWEAllocFlushBuffers; DriverObject->MajorFunction[IRP_MJ_QUERY_INFORMATION] = AWEAllocQueryInformation; DriverObject->MajorFunction[IRP_MJ_SET_INFORMATION] = AWEAllocSetInformation; DriverObject->DriverUnload = AWEAllocUnload; KdPrint(("AWEAlloc: Initialization done. Leaving DriverEntry().\n")); return STATUS_SUCCESS; }
//初始化设备对象 NTSTATUS CreateDevice(IN PDRIVER_OBJECT pDriverObject) { NTSTATUS status; PDEVICE_OBJECT pDevObj; PDEVICE_EXTENSION pDevExt; //创建设备名称 UNICODE_STRING szDevName; RtlInitUnicodeString(&szDevName,L"\\Device\\ZdgDevice"); //创建设备 status=IoCreateDevice(pDriverObject, sizeof(DEVICE_EXTENSION), &(UNICODE_STRING)szDevName, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, TRUE, &pDevObj); //创建不成功的话 if(!NT_SUCCESS(status)) { DbgPrint("IoCreateDevice UnOK!\n"); return status; } else DbgPrint("IoCreateDevice OK!\n"); //赋值相应参数 pDevObj->Flags|=DO_BUFFERED_IO; pDevExt=(PDEVICE_EXTENSION)pDevObj->DeviceExtension; pDevExt->pDevice=pDevObj; pDevExt->ustrDeviceName=szDevName; //创建符号链接 UNICODE_STRING symLinkName; RtlInitUnicodeString(&symLinkName,L"\\??\\InstFilters"); pDevExt->ustrSymLinkName=symLinkName; //创建符号链接 status=IoCreateSymbolicLink(&symLinkName,&szDevName); if(!NT_SUCCESS(status)) { DbgPrint("IoCreateSymbolicLink UnOK"); IoDeleteDevice(pDevObj); return status; } else DbgPrint("IoCreateSymbolicLink OK"); return STATUS_SUCCESS; }
NTSTATUS STDCALL DriverEntry(PDRIVER_OBJECT driverObject, PUNICODE_STRING registryPath) { NTSTATUS status = STATUS_SUCCESS; PDEVICE_OBJECT deviceObject = NULL; DbgPrint("Load\n"); driverObject->DriverUnload = my_unload; status = IoCreateDevice(driverObject, sizeof(device_extension_t), NULL, // Filter driver: device has no name FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &deviceObject); if (status != STATUS_SUCCESS) { DbgPrint("Cannot create device\n"); goto cleanup; } for (int i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++) { // Filter driver: ignore function instead of unsupported driverObject->MajorFunction[i] = my_ignored_function; } driverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = my_ioctl; device_extension_t* device_extension = (device_extension_t*) deviceObject->DeviceExtension; UNICODE_STRING deviceToFilter; RtlInitUnicodeString(&deviceToFilter, DEVICE_PATH); // Attach the filter device in the device stack status = IoAttachDevice(deviceObject, &deviceToFilter, &device_extension->next); if (status != STATUS_SUCCESS) { DbgPrint("Cannot attach device\n"); goto cleanup; } PDEVICE_OBJECT filteredDevice = device_extension->next; // These flags are used only for ReadFile and WriteFile. deviceObject->Flags |= filteredDevice->Flags & (DO_BUFFERED_IO | DO_DIRECT_IO); deviceObject->DeviceType = filteredDevice->DeviceType; deviceObject->Characteristics = filteredDevice->Characteristics; deviceObject->Flags &= ~DO_DEVICE_INITIALIZING; cleanup: if (status != STATUS_SUCCESS) { if (deviceObject) { IoDeleteDevice(deviceObject); } } return status; }
NTSTATUS DriverEntry( __in PDRIVER_OBJECT DriverObject, __in PUNICODE_STRING RegistryPath ) { NTSTATUS status; UNICODE_STRING deviceName; PDEVICE_OBJECT deviceObject; PAGED_CODE(); KphDriverObject = DriverObject; if (!NT_SUCCESS(status = KphDynamicDataInitialization())) return status; KphDynamicImport(); if (!NT_SUCCESS(status = KphpReadDriverParameters(RegistryPath))) return status; // Create the device. RtlInitUnicodeString(&deviceName, KPH_DEVICE_NAME); status = IoCreateDevice( DriverObject, 0, &deviceName, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &deviceObject ); if (!NT_SUCCESS(status)) return status; KphDeviceObject = deviceObject; // Set up I/O. DriverObject->MajorFunction[IRP_MJ_CREATE] = KphDispatchCreate; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = KphDispatchDeviceControl; DriverObject->DriverUnload = DriverUnload; deviceObject->Flags &= ~DO_DEVICE_INITIALIZING; dprintf("Driver loaded\n"); return status; }
NTSTATUS STDCALL DriverEntry(PDRIVER_OBJECT driverObject, PUNICODE_STRING registryPath) { NTSTATUS status = STATUS_SUCCESS; PDEVICE_OBJECT deviceObject = NULL; DbgPrint("Load\n"); driverObject->DriverUnload = my_unload; UNICODE_STRING deviceName; RtlInitUnicodeString(&deviceName, DEVICE_PATH); status = IoCreateDevice(driverObject, sizeof(device_context_t), &deviceName, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &deviceObject); if (status != STATUS_SUCCESS) { DbgPrint("Cannot create device\n"); goto cleanup; } // Initialize the context device_context_t* context = (device_context_t*) deviceObject->DeviceExtension; KeInitializeMutex(&(context->mutex), 0); context->stack = NULL; for (int i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; i++) { driverObject->MajorFunction[i] = my_unsuported_function; } driverObject->MajorFunction[IRP_MJ_CREATE] = my_create; driverObject->MajorFunction[IRP_MJ_CLOSE] = my_close; driverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = my_ioctl; deviceObject->Flags |= DO_BUFFERED_IO; deviceObject->Flags &= (~DO_DEVICE_INITIALIZING); UNICODE_STRING dosDeviceName; RtlInitUnicodeString(&dosDeviceName, DOSDEVICE_PATH); IoCreateSymbolicLink(&dosDeviceName, &deviceName); cleanup: if (status != STATUS_SUCCESS) { if (deviceObject) { IoDeleteDevice(deviceObject); } } return status; }
NTSTATUS DriverEntry( IN OUT PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) { PDEVICE_OBJECT pdoDeviceObj = 0; NTSTATUS status = STATUS_UNSUCCESSFUL; pdoGlobalDrvObj = DriverObject; //首先初始化各种变量 if(EnviromentInitialize(DriverObject) == FALSE) return status; // Create the device object. if(!NT_SUCCESS(status = IoCreateDevice( DriverObject, 0, &usDeviceName, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &pdoDeviceObj ))) { // Bail out (implicitly forces the driver to unload). return status; }; // Now create the respective symbolic link object if(!NT_SUCCESS(status = IoCreateSymbolicLink( &usSymlinkName, &usDeviceName ))) { IoDeleteDevice(pdoDeviceObj); return status; } // NOTE: You need not provide your own implementation for any major function that // you do not want to handle. I have seen code using DDKWizard that left the // *empty* dispatch routines intact. This is not necessary at all! DriverObject->MajorFunction[IRP_MJ_CREATE] = DriverObject->MajorFunction[IRP_MJ_CLOSE] = CRARKSYS_DispatchCreateClose; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = CRARKSYS_DispatchDeviceControl; DriverObject->DriverUnload = CRARKSYS_DriverUnload; KdPrint(("CrArkSys DriverLoad.\n")); return STATUS_SUCCESS; }
/* The entry point - this is called when kexec.sys is loaded, and it runs to completion before the associated userspace call to StartService() returns, no matter what. */ NTSTATUS DDKAPI DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath KEXEC_UNUSED) { NTSTATUS status; UNICODE_STRING DeviceName; UNICODE_STRING SymlinkName; PDEVICE_OBJECT DeviceObject; DbgPrint("Loading kexec driver " VERSION_STR "\n"); /* Allow kexec.sys to be unloaded. */ DriverObject->DriverUnload = DriverUnload; /* Init the buffers. */ KexecInitBuffer(&KexecKernel); KexecInitBuffer(&KexecInitrd); KexecInitBuffer(&KexecKernelCommandLine); RtlInitUnicodeString(&DeviceName, L"\\Device\\Kexec"); RtlInitUnicodeString(&SymlinkName, L"\\??\\kexec"); /* Register \\.\kexec with the Windows kernel. */ status = IoCreateDevice(DriverObject, 0, &DeviceName, FILE_DEVICE_UNKNOWN, 0, FALSE, &DeviceObject); if (!NT_SUCCESS(status)) return status; /* Set our handlers for I/O operations on \\.\kexec. */ DriverObject->MajorFunction[IRP_MJ_CREATE] = KexecOpen; DriverObject->MajorFunction[IRP_MJ_CLOSE] = KexecClose; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = KexecIoctl; DriverObject->MajorFunction[IRP_MJ_SHUTDOWN] = KexecShutdown; status = IoCreateSymbolicLink(&SymlinkName, &DeviceName); if (!NT_SUCCESS(status)) goto cleanupdev; /* Have the kernel poke us when the system is about to shut down. */ status = IoRegisterLastChanceShutdownNotification(DeviceObject); if (!NT_SUCCESS(status)) goto cleanupsymlink; return status; cleanupsymlink: IoDeleteSymbolicLink(&SymlinkName); cleanupdev: IoDeleteDevice(DeviceObject); return status; }
NTSTATUS VBoxDrvAddDevice(IN PDRIVER_OBJECT Driver, IN PDEVICE_OBJECT PDO) { NTSTATUS rc; PDEVICE_OBJECT pDO, pDOParent; PVBOXMOUSE_DEVEXT pDevExt; PAGED_CODE(); LOGF_ENTER(); rc = IoCreateDevice(Driver, sizeof(VBOXMOUSE_DEVEXT), NULL, FILE_DEVICE_MOUSE, 0, FALSE, &pDO); if (!NT_SUCCESS(rc)) { WARN(("IoCreateDevice failed with %#x", rc)); return rc; } pDevExt = (PVBOXMOUSE_DEVEXT) pDO->DeviceExtension; RtlZeroMemory(pDevExt, sizeof(VBOXMOUSE_DEVEXT)); IoInitializeRemoveLock(&pDevExt->RemoveLock, VBOXUSB_RLTAG, 1, 100); rc = IoAcquireRemoveLock(&pDevExt->RemoveLock, pDevExt); if (!NT_SUCCESS(rc)) { WARN(("IoAcquireRemoveLock failed with %#x", rc)); IoDeleteDevice(pDO); return rc; } pDOParent = IoAttachDeviceToDeviceStack(pDO, PDO); if (!pDOParent) { IoReleaseRemoveLockAndWait(&pDevExt->RemoveLock, pDevExt); WARN(("IoAttachDeviceToDeviceStack failed")); IoDeleteDevice(pDO); return STATUS_DEVICE_NOT_CONNECTED; } pDevExt->pdoMain = PDO; pDevExt->pdoSelf = pDO; pDevExt->pdoParent = pDOParent; VBoxDeviceAdded(pDevExt); pDO->Flags |= (DO_BUFFERED_IO | DO_POWER_PAGABLE); pDO->Flags &= ~DO_DEVICE_INITIALIZING; LOGF_LEAVE(); return rc; }
//----------------------------------------------------------------------------- // Name: DriverEntry // Object: Entry point of the driver // Parameters : // in : // out : // return : //----------------------------------------------------------------------------- NTSTATUS DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) { PDEVICE_OBJECT pDeviceObject = NULL; NTSTATUS ntStatus; UNICODE_STRING uszDeviceName; UNICODE_STRING uszDeviceLink; UNREFERENCED_PARAMETER(RegistryPath); // Point uszDriverString at the driver name RtlInitUnicodeString(&uszDeviceName, DEVICE_NAME); // Create and initialize device object ntStatus = IoCreateDevice( DriverObject, 0,// number of bytes to be allocated for the device extension of the device object &uszDeviceName, FILE_DEVICE_UNKNOWN, 0, FALSE, &pDeviceObject ); if(ntStatus != STATUS_SUCCESS) return ntStatus; // Point uszDeviceString at the device name RtlInitUnicodeString(&uszDeviceLink, DEVICE_LINK); // Create symbolic link to the user-visible name ntStatus = IoCreateSymbolicLink(&uszDeviceLink, &uszDeviceName); if(ntStatus != STATUS_SUCCESS) { // Delete device object if not successful IoDeleteDevice(pDeviceObject); return ntStatus; } // Set handler for Major Function IRP dispatching DriverObject->DriverUnload = UnloadDriver; DriverObject->MajorFunction[IRP_MJ_CREATE] = DispatchCreate; DriverObject->MajorFunction[IRP_MJ_CLOSE] = DispatchClose; DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = DispatchIoctl; // Return success return ntStatus; }
/* * Mount an NTK volume: * - create a device describing the volume * - mount an undelining linux LKL device */ static NTSTATUS LklMountVolume(IN PLKL_IRP_CONTEXT IrpContext) { PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation(IrpContext->Irp); PDEVICE_OBJECT physical_dev; PDEVICE_OBJECT vol_dev; PLKL_VCB vcb = NULL; PVPB vpb; NTSTATUS status; int sectors; vpb = IrpSp->Parameters.MountVolume.Vpb; physical_dev = IrpSp->Parameters.MountVolume.DeviceObject; if (physical_dev == g_lklvfs->device) return STATUS_INVALID_DEVICE_REQUEST; /* create a device object for the volume device, * and allocate LKL_VCB in the device */ status = IoCreateDevice(g_lklvfs->driver, sizeof(LKL_VCB), NULL, FILE_DEVICE_DISK_FILE_SYSTEM, 0, FALSE, &vol_dev); if (!NT_SUCCESS(status)) return status; if (vol_dev->AlignmentRequirement < physical_dev->AlignmentRequirement) vol_dev->AlignmentRequirement = physical_dev->AlignmentRequirement; vol_dev->StackSize = (CCHAR)(physical_dev->StackSize+1); status = LklVcbInit(vol_dev, physical_dev, vpb, &vcb); if (!NT_SUCCESS(status)) goto free_vol_dev; status = BlockDeviceNrSectors(physical_dev, vcb, §ors); if (!NT_SUCCESS(status)) goto free_vcb; status = LklMount(vcb, sectors); if (!NT_SUCCESS(status)) goto free_vcb; SET_FLAG(vcb->Flags, VCB_MOUNTED); vpb->DeviceObject = vol_dev; return STATUS_SUCCESS; free_vcb: LklVcbFini(vcb); free_vol_dev: IoDeleteDevice(vol_dev); return status; }
static NTSTATUS vboxUsbDdiAddDevice(PDRIVER_OBJECT pDriverObject, PDEVICE_OBJECT pPDO) { PDEVICE_OBJECT pFDO = NULL; NTSTATUS Status = IoCreateDevice(pDriverObject, sizeof (VBOXUSBDEV_EXT), NULL, /* IN PUNICODE_STRING pDeviceName OPTIONAL */ FILE_DEVICE_UNKNOWN, /* IN DEVICE_TYPE DeviceType */ FILE_AUTOGENERATED_DEVICE_NAME, /* IN ULONG DeviceCharacteristics */ FALSE, /* IN BOOLEAN fExclusive */ &pFDO); Assert(Status == STATUS_SUCCESS); if (Status == STATUS_SUCCESS) { PVBOXUSBDEV_EXT pDevExt = (PVBOXUSBDEV_EXT)pFDO->DeviceExtension; /* init Device Object bits */ pFDO->Flags |= DO_DIRECT_IO; if (pPDO->Flags & DO_POWER_PAGABLE) pFDO->Flags |= DO_POWER_PAGABLE; /* now init our state bits */ pDevExt->cHandles = 0; pDevExt->pFDO = pFDO; pDevExt->pPDO = pPDO; pDevExt->pLowerDO = IoAttachDeviceToDeviceStack(pFDO, pPDO); Assert(pDevExt->pLowerDO); if (pDevExt->pLowerDO) { vboxUsbDdiStateInit(pDevExt); Status = vboxUsbRtInit(pDevExt); if (Status == STATUS_SUCCESS) { /* we're done! */ pFDO->Flags &= ~DO_DEVICE_INITIALIZING; return STATUS_SUCCESS; } IoDetachDevice(pDevExt->pLowerDO); } else Status = STATUS_NO_SUCH_DEVICE; IoDeleteDevice(pFDO); } return Status; }
NTSTATUS CreateDevice ( IN PDRIVER_OBJECT pDriverObject) { NTSTATUS status; PDEVICE_OBJECT pDevObj; PDEVICE_EXTENSION pDevExt; UNICODE_STRING devName; RtlInitUnicodeString(&devName,DEVICE_NAME); UNICODE_STRING symLinkName; RtlInitUnicodeString(&symLinkName,DOS_NAME); status = IoCreateDevice( pDriverObject, sizeof(DEVICE_EXTENSION), &(UNICODE_STRING)devName, FILE_DEVICE_UNKNOWN, FILE_DEVICE_SECURE_OPEN, FALSE, &pDevObj ); if (!NT_SUCCESS(status)) { KdPrint( ("create device is error!\n") ); return status; } IoRegisterShutdownNotification(pDevObj); pDevObj->Flags |= DO_BUFFERED_IO; pDevObj->Flags &= (~DO_DEVICE_INITIALIZING);//wdm used pDevExt = (PDEVICE_EXTENSION)pDevObj->DeviceExtension; pDevExt->pDevice = pDevObj; pDevExt->ustrDeviceName = devName;// pDevExt->ustrSymLinkName = symLinkName;// status = IoCreateSymbolicLink( &symLinkName,&devName ); if (!NT_SUCCESS(status)) { IoDeleteDevice( pDevObj ); KdPrint( ("create symbolicLink is error!\n") ); return status; } //fanzhenxing add InitBlackCache(); InitFilterCache(); return STATUS_SUCCESS; }
NTSTATUS CreateDevice (IN PDRIVER_OBJECT pDriverObject) { KdPrint(("CreateDevice begin\n")); NTSTATUS status; //设备对象 指针 PDEVICE_OBJECT pDevObj; //设备对象扩展结构 指针 PDEVICE_EXTENSION pDevExt; //设备名称 UNICODE_STRING devName; RtlInitUnicodeString(&devName,L"\\Device\\MyDDKDevice"); //创建设备 status = IoCreateDevice( pDriverObject, //驱动对象 sizeof(DEVICE_EXTENSION), //设备扩展结构大小 &(UNICODE_STRING)devName, //设备名 或 NULL FILE_DEVICE_UNKNOWN, //设备类型 FILE_DEVICE_UNKNOWN 未知虚拟设备,且为独占(既只能被一个应用程序使用) 0, TRUE, &pDevObj ); //设备地址 out if (!NT_SUCCESS(status)) return status; //以直接的方式读写(既不使用缓冲区) pDevObj->Flags |= DO_DIRECT_IO; //填充扩展结构数据 pDevExt = (PDEVICE_EXTENSION)pDevObj->DeviceExtension; pDevExt->pDevice = pDevObj; pDevExt->ustrDeviceName = devName; //符号链接名 UNICODE_STRING symLinkName; RtlInitUnicodeString(&symLinkName,L"\\??\\HelloDDK"); //创建符号链接 pDevExt->ustrSymLinkName = symLinkName; status = IoCreateSymbolicLink( &symLinkName,&devName ); if (!NT_SUCCESS(status)) { IoDeleteDevice( pDevObj ); return status; } KdPrint(("CreateDevice sucess and end\n")); return STATUS_SUCCESS; }
// Standard entry point for the device driver. Initialize ourselves // and create the proper links to ourselves... NTSTATUS DriverEntry( IN PDRIVER_OBJECT driverObject, IN PUNICODE_STRING registryPath) { NTSTATUS result = STATUS_INSUFFICIENT_RESOURCES; PDEVICE_OBJECT deviceObject; UNICODE_STRING deviceName, dosName; ioMap = MmAllocateNonCachedMemory(sizeof(IOPM)); if(ioMap) { // this will allow access to all ports. if we want to // allow limited access we could set only ports we want // to access to 0. RtlZeroMemory(ioMap, sizeof(IOPM)); // create unicode string for device name; //wcscpy(foo, L"\\Device\\portio"); RtlInitUnicodeString(&deviceName, devicePath); // create the actual device result = IoCreateDevice(driverObject, 0, &deviceName, FILE_DEVICE_UNKNOWN, 0, FALSE, &deviceObject); if(NT_SUCCESS(result)) { // create symbolic link to driver RtlInitUnicodeString(&dosName, dosDevicePath); result = IoCreateSymbolicLink (&dosName, &deviceName); if(NT_SUCCESS(result)) { // finally register the entry points for the driver functions driverObject->MajorFunction[IRP_MJ_CREATE] = DriverCreateDispatch; driverObject->DriverUnload = DriverUnload; result = STATUS_SUCCESS; } } } return result; }
//StartService时调用 NTSTATUS DriverEntry( IN PDRIVER_OBJECT theDriverObject, IN PUNICODE_STRING theRegistryPath ) { NTSTATUS status=STATUS_SUCCESS; ULONG i; for(i= 0;i<IRP_MJ_MAXIMUM_FUNCTION;++i) theDriverObject->MajorFunction[i] = DisPatchCreateClose; theDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]=DispatchDeviceControl; __asm { nop mov edi,edi } theDriverObject->DriverUnload=DriverUnload; __asm { nop add eax,-258 add eax,258 } RtlInitUnicodeString(&DerName,L"\\Device\\RESSDT"); status=IoCreateDevice(theDriverObject,0,&DerName,FILE_DEVICE_UNKNOWN,0,FALSE,&pDevObj); if(!NT_SUCCESS(status)) { DbgPrint("IoCreateDevice Fail!"); return status; } RtlInitUnicodeString(&DerName2,L"\\??\\RESSDTDOS"); status=IoCreateSymbolicLink(&DerName2,&DerName); if(!NT_SUCCESS(status)) DbgPrint("IoCreateSymbolicLink fail!"); return status; }
NTSTATUS DriverEntry(PDRIVER_OBJECT drvobp, PUNICODE_STRING regpath) { UNICODE_STRING devname, dosdev; NTSTATUS stat; int i; #if 0 /* Create a device object for this driver */ RtlInitUnicodeString(&devname, XFS_DEVICE_NAME); stat = IoCreateDevice(drvobp, 0, &devname, FILE_DEVICE_FILE_SYSTEM, 0, FALSE, &xfs_fsdevptr); if (!NT_SUCCESS(stat)) { printf("XFS: unable to create device object: %x\n", stat); return (stat); } xfs_fsdevptr->Flags |= DO_DIRECT_IO; RtlInitUnicodeString(&dosdev, XFS_DOSDEV_NAME); stat = IoCreateSymbolicLink(&dosdev, &devname); if (!NT_SUCCESS(stat)) { printf("nfsrv: Unable to create dosdevice : %x\n", stat); IoDeleteDevice(xfs_fsdevptr); return (stat); } #endif reiserfs_type.owner = drvobp; /* Setup the driver entrypoints */ for (i = 0; i <= IRP_MJ_MAXIMUM_FUNCTION; i++) { if (i == IRP_MJ_FLUSH_BUFFERS) continue; drvobp->MajorFunction[i] = reiserfs_mod_iodispatch; } vfs_registerfs(reiserfs_type.name, reiserfs_init, &reiserfs_vfsops); #if 0 nfssysctl_ctxp = sysctl_register_external_set(nfssysctl_set, nfs_numsysctl); #endif drvobp->DriverUnload = reiserfs_mod_unload; return (STATUS_SUCCESS); }