|
[求助]打开设备返回INVALLID_HANDLE_VALUE errorcode是 操作已成功完成是怎么回事啊
恩??是创建时 还是打开时?? 我试了下 创建符号链接时用 "\\??\\MyLegacyDriver " 打开时用 L"\\DosDevices\\Global\\MyLegacyDriver" 不行啊…… 然后又试了 创建符号链接时用 "\\??\\MyLegacyDriver 打开时用 L"\\\\DosDevices\\Global\\MyLegacyDriver" 还是不行 然后又试了各种各样的组合 结果都是 系统找不到指定文件 我用winobj 看到创建的符号链接 在\ 目录下 的 Global?? 目录 里 我该用什么样的格式打开 |
|
[求助]打开设备返回INVALLID_HANDLE_VALUE errorcode是 操作已成功完成是怎么回事啊
符号链接 改成 \\??\\MyLegacyDriver 打开时CreateFile里使用 \\\\.\\MyLegacyDriver 还是找不到指定设备 明明符号连接已经创建成功了 |
|
|
|
|
|
[求助]打开设备返回INVALLID_HANDLE_VALUE errorcode是 操作已成功完成是怎么回事啊
我发现 是不是不应该在 GetLasterrorcode前调用 messagebox |
|
[求助]打开设备返回INVALLID_HANDLE_VALUE errorcode是 操作已成功完成是怎么回事啊
#define IOCTL_TEST1 CTL_CODE(FILE_DEVICE_UNKNOWN,0x821,METHOD_BUFFERED,FILE_ANY_ACCESS) //#include <wdm.h> #include<Ntddk.h> typedef struct _MY_DRIVER_EXTENSION { int x; }MY_DRIVER_EXTENSION,*PMY_PDRIVER_EXTENSION; typedef struct _MY_DEVICE_EXTENSION { PDEVICE_OBJECT pDevbj; UNICODE_STRING DeviceName; UNICODE_STRING UserSymbolicName; }MY_DEVICE_EXTENSION,*PMY_DEVICE_EXTENSION; //NTSTATUS MyWdmAddDevice(PDRIVER_OBJECT DriverObject,PDEVICE_OBJECT physicalDeviceObject); //NTSTATUS MyWdmPnp(PDEVICE_OBJECT DeviceObject,PIRP Trp); void MyWdmUnload(PDRIVER_OBJECT DriverObject); NTSTATUS MyWdmCreate(PDEVICE_OBJECT DeviceObject,PIRP Irp); NTSTATUS MyWdmDispatch(PDEVICE_OBJECT DeviceObject,PIRP Trp); static VOID NTAPI SearchForLegacyDrivers(IN PDRIVER_OBJECT DriverObject,IN PVOID Context, IN ULONG Count); #pragma code_seg("INIT") extern "C" NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject,PUNICODE_STRING RegistryPath) { KdPrint(("EnterDriverEntry\n")); //pDriverObject->DriverExtension->AddDevice=MyWdmAddDevice; //pDriverObject->MajorFunction[IRP_MJ_PNP]=MyWdmPnp; pDriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL]=MyWdmDispatch; pDriverObject->MajorFunction[IRP_MJ_CREATE]=MyWdmCreate; pDriverObject->MajorFunction[IRP_MJ_READ]=MyWdmDispatch; pDriverObject->MajorFunction[IRP_MJ_CLOSE]=MyWdmDispatch; pDriverObject->MajorFunction[IRP_MJ_WRITE]=MyWdmDispatch; pDriverObject->DriverUnload = MyWdmUnload; PMY_PDRIVER_EXTENSION MyDriverExtension; NTSTATUS Status; Status=IoAllocateDriverObjectExtension(pDriverObject,pDriverObject,sizeof(MY_DRIVER_EXTENSION),(PVOID*)&MyDriverExtension); if(!NT_SUCCESS(Status)) { KdPrint(("allocate for DriverExtension faild")); return Status; } IoRegisterDriverReinitialization(pDriverObject,SearchForLegacyDrivers,MyDriverExtension); KdPrint(("leave DriverEntry")); return STATUS_SUCCESS; DbgPrint("leave enter driver entry "); } #pragma code_seg("PAGE") static VOID SearchForLegacyDrivers(IN PDRIVER_OBJECT pDriverObject,IN PVOID Context, IN ULONG Count) { NTSTATUS Status; UNICODE_STRING DevName; PDEVICE_OBJECT pDevObj; PMY_DEVICE_EXTENSION pDevExt; DbgPrint("print enter SearchForLegacyDrivers "); KdPrint(("enter SearchForLegacyDrivers")); RtlInitUnicodeString(&DevName,L"\\Device\\MyWdmDevice"); PMY_PDRIVER_EXTENSION pDriverExtension=(PMY_PDRIVER_EXTENSION)Context; Status=IoCreateDevice(pDriverObject,sizeof(MY_DEVICE_EXTENSION),&DevName,FILE_DEVICE_UNKNOWN,0,FALSE,&pDevObj); if (!NT_SUCCESS(Status)) { IoDeleteDevice(pDevObj); KdPrint((" create device faild ")); return ; } KdPrint(("Create Device Success")); pDevObj->Flags|=DO_BUFFERED_IO; //决定了设备的访问类型 pDevExt=(PMY_DEVICE_EXTENSION)pDevObj->DeviceExtension; pDevExt->pDevbj=pDevObj; pDevExt->DeviceName=DevName; UNICODE_STRING SymLinkName; RtlInitUnicodeString(&SymLinkName,L"\\DosDevices\\MyLegacyDriver"); pDevExt->UserSymbolicName=SymLinkName; Status=IoCreateSymbolicLink(&SymLinkName,&DevName); if (!NT_SUCCESS(Status)) { IoDeleteDevice(pDevObj); KdPrint((" create symbolic faild ")); return; } KdPrint(("Create symbolic success")); return; } /* #pragma code_seg("PAGE") NTSTATUS MyWdmAddDevice(PDRIVER_OBJECT DriverObject,PDEVICE_OBJECT physicalDeviceObject) { return STATUS_SUCCESS; } #pragma code_seg("PAGE") NTSTATUS MyWdmPnp(PDEVICE_OBJECT DeviceObject,PIRP Trp) //老式驱动没有这两项 { } */ #pragma code_seg("PAGE") NTSTATUS MyWdmRead(PDEVICE_OBJECT DeviceObject,PIRP Irp) { KdPrint(("enter MyWdmRead")); NTSTATUS Status=STATUS_SUCCESS; PIO_STACK_LOCATION stack=IoGetCurrentIrpStackLocation(Irp); ULONG ulReadLength =stack->Parameters.Read.Length; //得到要读的字节数 Irp->IoStatus.Status=Status; Irp->IoStatus.Information=ulReadLength; memset(Irp->AssociatedIrp.SystemBuffer,0xAA,ulReadLength); IoCompleteRequest(Irp,IO_NO_INCREMENT); KdPrint(("leave MyWdmRead ")); return Status; } #pragma code_seg("PAGE") NTSTATUS MyWdmWrite(PDEVICE_OBJECT DeviceObject,PIRP Irp) { KdPrint(("enter MyWdmWrite")); PIO_STACK_LOCATION stack= IoGetCurrentIrpStackLocation(Irp); ULONG ulWriteLength= stack->Parameters.Write.Length; //得到要写的长度 ULONG ulWriteOffset= (ULONG)stack->Parameters.Write.ByteOffset.QuadPart; OBJECT_ATTRIBUTES objectAttributes; HANDLE myfile; NTSTATUS Status; IO_STATUS_BLOCK iostatus; UNICODE_STRING file_name_path; RtlInitUnicodeString( &file_name_path, L"\\??\\d:\\1.log" ); Status=ZwCreateFile( &myfile, GENERIC_WRITE, &objectAttributes, &iostatus, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ, FILE_OPEN_IF, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0 ); if (!NT_SUCCESS(Status)) { return STATUS_UNSUCCESSFUL; } LARGE_INTEGER LGINOffset; LGINOffset.QuadPart=ulWriteLength; Status=ZwWriteFile(myfile,0,0,0,&iostatus,Irp->AssociatedIrp.SystemBuffer,ulWriteLength,&LGINOffset,0); if(NT_SUCCESS(Status)) { KdPrint(("Write file failed")); return Status; } ZwClose(myfile); Irp->IoStatus.Status=Status; Irp->IoStatus.Information=ulWriteLength; IoCompleteRequest(Irp,IO_NO_INCREMENT); KdPrint(("leave myWdm Write file")); return Status; } #pragma code_seg("PAGE") NTSTATUS MyWdmCreate(PDEVICE_OBJECT DeviceObject,PIRP Irp) { KdPrint(("enter My Wdm Create!")); Irp->IoStatus.Status=STATUS_SUCCESS; Irp->IoStatus.Information=0; IoCompleteRequest(Irp,IO_NO_INCREMENT); KdPrint(("Leave My Wdm Create!")); return STATUS_SUCCESS; } #pragma code_seg("PAGE") NTSTATUS MyWdmDeviceControl(PDEVICE_OBJECT DeviceObject,PIRP Irp) { NTSTATUS Status; Status=STATUS_SUCCESS; KdPrint(("enter my wdmDeviceIoControl")); PIO_STACK_LOCATION stack=IoGetCurrentIrpStackLocation(Irp); //ULONG buffer_in=stack->Parameters.DeviceIoControl.InputBufferLength; //得到输入缓冲区长度 //ULONG buffer_out=stack->Parameters.DeviceIoControl.OutputBufferLength; //得到输出缓冲区长度 ULONG code=stack->Parameters.DeviceIoControl.IoControlCode; ULONG info=0; switch(code) { case IOCTL_TEST1: KdPrint(("device io control success !")); break; default: break; } Irp->IoStatus.Status=Status; Irp->IoStatus.Information=0; IoCompleteRequest(Irp,IO_NO_INCREMENT); KdPrint(("leave my wdmDeviceIoContrl")); return Status; } #pragma code_seg("PAGE") NTSTATUS MyWdmDeviceClose(PDEVICE_OBJECT DeviceObject,PIRP Irp) { KdPrint(("enter MyWdmDeviceClose")); NTSTATUS Status; Status=STATUS_SUCCESS; Irp->IoStatus.Status=Status; Irp->IoStatus.Information=0; IoCompleteRequest(Irp,IO_NO_INCREMENT); KdPrint(("leave MyWdmDeviceClose")); return Status; } #pragma code_seg("PAGE") NTSTATUS MyWdmDispatch(PDEVICE_OBJECT DeviceObject,PIRP Irp) { KdPrint(("Enter my_wdm_diapatch_function")); NTSTATUS Status=NULL; PIO_STACK_LOCATION irpsp=IoGetCurrentIrpStackLocation(Irp); switch (irpsp->MajorFunction) { case IRP_MJ_CREATE: Status=MyWdmCreate(DeviceObject,Irp); break; case IRP_MJ_WRITE: Status=MyWdmWrite(DeviceObject,Irp); break; case IRP_MJ_READ: Status=MyWdmRead(DeviceObject,Irp); break; case IRP_MJ_DEVICE_CONTROL: Status=MyWdmDeviceControl(DeviceObject,Irp); break; case IRP_MJ_CLOSE: Status=MyWdmDeviceClose(DeviceObject,Irp); default: Irp->IoStatus.Status=STATUS_SUCCESS; Irp->IoStatus.Information=0L; IoCompleteRequest(Irp,IO_NO_INCREMENT); } KdPrint(("leave my wdm dispatch")); return Status; } #pragma code_seg("PAGE") void MyWdmUnload(PDRIVER_OBJECT pDriverObject) //负责删除创建的设备对象 { PDEVICE_OBJECT pNextObj; KdPrint(("enter Driver unload")); pNextObj=pDriverObject->DeviceObject; while(pNextObj!=NULL) { PMY_DEVICE_EXTENSION pDevExt=(PMY_DEVICE_EXTENSION)pNextObj->DeviceExtension; UNICODE_STRING pLinkName=pDevExt->UserSymbolicName; IoDeleteSymbolicLink(&pLinkName); pNextObj=pNextObj->NextDevice; IoDeleteDevice(pDevExt->pDevbj); } } void CuserMyWdmMfcDlg::OnBnClickedButton1() { hDevice=CreateFile(L"\\\\DosDevives\\MyLegacyDriver",GENERIC_READ|GENERIC_WRITE,0,NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);//异步方式打开设备要加上 | FILE_FLAG_OVERLAPPED if(hDevice==INVALID_HANDLE_VALUE) { MessageBox(L"打开失败 ",L"txt",MB_OK); LPVOID lpMsgBuf; int error = GetLastError(); FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */ (LPTSTR) &lpMsgBuf, 0, NULL); /* Display the string. */ ::MessageBox( NULL, (LPCTSTR)lpMsgBuf, L"Error", MB_OK | MB_ICONERROR ); return ; } MessageBox(L"Open Device success",L"box!",MB_OK); return ; } |
|
[求助]打开设备返回INVALLID_HANDLE_VALUE errorcode是 操作已成功完成是怎么回事啊
errorcode 为0 表示 操作已成功完成 这到底是什么意思 设备确实创建了 符号链接也创建了 DeviceTree里都能看到 但是CreateFile返回 INVALID_HANDLE_VALUE 而且句柄也是无效不能使用 返回的errorcode 是0 而且 debugview显示 没进入过设置的IRP_MJ_CREATE分发函数 因为没打印信息 |
|
[求助][求助]kdprint 在DebugView里什么都不显示
不是因为这个好伐… |
|
|
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值