阅读:1572回复:1
那位大虾能提供passthru和ndismregisterdevice结合好的原代码啊
我调试了n天也没通过,不是蓝屏就是driverentry结束后系统就调用unload把我的driver卸载了(在driverentry结速前driver还存在的),在论坛上看到一位大侠提供的iocreatedevice和passthru结合的代码,不过ndis不推荐用,不敢用,怕有后遗症
|
|
最新喜欢:Snare
|
沙发#
发布于:2001-11-07 14:46
NTSTATUS
DriverEntry( IN PDRIVER_OBJECT DriverObject, IN PUNICODE_STRING RegistryPath ) /*++ Routine Description: Arguments: Return Value: --*/ { NDIS_STATUS Status; NDIS_PROTOCOL_CHARACTERISTICS PChars; NDIS_MINIPORT_CHARACTERISTICS MChars; PNDIS_CONFIGURATION_PARAMETER Param; NDIS_STRING Name; NDIS_HANDLE WrapperHandle; NTSTATUS status = STATUS_SUCCESS; UNICODE_STRING ntDeviceName; UNICODE_STRING win32DeviceName; PDEVICE_OBJECT deviceObject; ULONG i; PDRIVER_DISPATCH MajorFunction[IRP_MJ_MAXIMUM_FUNCTION + 1]; DBGPRINT("Enter Driver Entry"); NdisMInitializeWrapper(&WrapperHandle, DriverObject, RegistryPath, NULL); // //Save the DriverObject // Globals.DriverObject = DriverObject; // // Save the RegistryPath. // Globals.RegistryPath.MaximumLength = RegistryPath->Length + sizeof(UNICODE_NULL); Globals.RegistryPath.Length = RegistryPath->Length; Globals.RegistryPath.Buffer = ExAllocatePool(PagedPool, Globals.RegistryPath.MaximumLength ); if (!Globals.RegistryPath.Buffer) { DBGPRINT (("Couldn't allocate pool for registry path.")); return STATUS_INSUFFICIENT_RESOURCES; } RtlCopyUnicodeString(&Globals.RegistryPath, RegistryPath); // // Register the miniport with NDIS. Note that it is the miniport // which was started as a driver and not the protocol. Also the miniport // must be registered prior to the protocol since the protocol's BindAdapter // handler can be initiated anytime and when it is, it must be ready to // start driver instances. // NdisZeroMemory(&MChars, sizeof(NDIS_MINIPORT_CHARACTERISTICS)); MChars.MajorNdisVersion = 4; MChars.MinorNdisVersion = 0; MChars.InitializeHandler = MPInitialize; MChars.QueryInformationHandler = MPQueryInformation; MChars.SetInformationHandler = MPSetInformation; MChars.ResetHandler = MPReset; MChars.TransferDataHandler = MPTransferData; MChars.HaltHandler = MPHalt; // // We will disable the check for hang timeout so we do not // need a check for hang handler! // MChars.CheckForHangHandler = NULL; MChars.SendHandler = MPSend; MChars.ReturnPacketHandler = MPReturnPacket; // // Either the Send or the SendPackets handler should be specified. // If SendPackets handler is specified, SendHandler is ignored // // MChars.SendPacketsHandler = MPSendPackets; Status = NdisIMRegisterLayeredMiniport(WrapperHandle, &MChars, sizeof(MChars), &DriverHandle); if (Status != NDIS_STATUS_SUCCESS) { goto ERROR; } NdisMRegisterUnloadHandler(WrapperHandle, PtUnload); // // Now register the protocol. // NdisZeroMemory(&PChars, sizeof(NDIS_PROTOCOL_CHARACTERISTICS)); PChars.MajorNdisVersion = 4; PChars.MinorNdisVersion = 0; // // Make sure the protocol-name matches the service-name under which this protocol is installed. // This is needed to ensure that NDIS can correctly determine the binding and call us to bind // to miniports below. // NdisInitUnicodeString(&Name, L"SFilter"); // Protocol name PChars.Name = Name; PChars.OpenAdapterCompleteHandler = PtOpenAdapterComplete; PChars.CloseAdapterCompleteHandler = PtCloseAdapterComplete; PChars.SendCompleteHandler = PtSendComplete; PChars.TransferDataCompleteHandler = PtTransferDataComplete; PChars.ResetCompleteHandler = PtResetComplete; PChars.RequestCompleteHandler = PtRequestComplete; PChars.ReceiveHandler = PtReceive; PChars.ReceiveCompleteHandler = PtReceiveComplete; PChars.StatusHandler = PtStatus; PChars.StatusCompleteHandler = PtStatusComplete; PChars.BindAdapterHandler = PtBindAdapter; PChars.UnbindAdapterHandler = PtUnbindAdapter; PChars.UnloadHandler = NULL; PChars.ReceivePacketHandler = PtReceivePacket; PChars.PnPEventHandler= PtPNPHandler; NdisRegisterProtocol(&Status, &ProtHandle, &PChars, sizeof(NDIS_PROTOCOL_CHARACTERISTICS)); if (Status != NDIS_STATUS_SUCCESS) { goto ERROR; } NdisIMAssociateMiniport(DriverHandle, ProtHandle); // // Create a control device object for this driver. // Application can send an IOCTL to this device to get // bound adapter information. // RtlInitUnicodeString(&ntDeviceName, NT_DEVICE_NAME); RtlInitUnicodeString(&win32DeviceName, DOS_DEVICE_NAME); // Now set only the dispatch points we would like to handle. for (i = 0 ; i < IRP_MJ_MAXIMUM_FUNCTION ; i++ ) { MajorFunction = NULL; } MajorFunction[IRP_MJ_CREATE] = PacketOpen; MajorFunction[IRP_MJ_CLOSE] = PacketClose; MajorFunction[IRP_MJ_READ] = PacketRead; MajorFunction[IRP_MJ_WRITE] = PacketWrite; MajorFunction[IRP_MJ_CLEANUP] = PacketCleanup; MajorFunction[IRP_MJ_DEVICE_CONTROL] = PacketIoControl; //不能直接调用IoCreateDevice和IoCreateSymbolicLink status = NdisMRegisterDevice(WrapperHandle, &ntDeviceName, &win32DeviceName, MajorFunction, &deviceObject, &Globals.NdisDeviceHandle); if (status != STATUS_SUCCESS ) { goto ERROR; } deviceObject->Flags |= DO_BUFFERED_IO; Globals.ControlDeviceObject = deviceObject; // InitializeListHead(&Globals.AdapterList); // KeInitializeSpinLock(&Globals.GlobalLock); return(Status); ERROR: if(deviceObject) NdisMDeregisterDevice(deviceObject); if(Globals.RegistryPath.Buffer) ExFreePool(Globals.RegistryPath.Buffer); return status; } |
|
|