-
-
[原创]浅谈那些年来我们用过的设备操作
-
发表于: 2014-1-21 12:12 4199
-
NTSTATUS Writea(IN PDEVICE_OBJECT pDevice, IN PIRP pIrp) { NTSTATUS Status=STATUS_SUCCESS; PDEVICE_EXTENSION PDeviN=(PDEVICE_EXTENSION)pDevice->DeviceExtension; PIO_STACK_LOCATION stack=IoGetCurrentIrpStackLocation(pIrp); ULONG WriteLenth=stack->Parameters.Write.Length; ULONG WriteOffset=stack->Parameters.Write.ByteOffset.QuadPart; if (WriteLenth+WriteOffset>1024) //1024是我们分配的内存大小,超过了你很可能就挂彩了 { Status=STATUS_FILE_INVALID; WriteLenth=0; } else { KdPrint(("write buffer 0x%x\n",PDeviN->buffer)); KdPrint(("write Ox%x\n",WriteOffset)); KdPrint(("write Ox%x\n",WriteLenth)); memcpy(PDeviN->buffer+WriteOffset,pIrp->AssociatedIrp.SystemBuffer,WriteLenth); Status=STATUS_SUCCESS; if (WriteLenth+WriteOffset>PDeviN->file_length) { PDeviN->file_length=WriteLenth+WriteOffset; } } pIrp->IoStatus.Status=Status; pIrp->IoStatus.Information=WriteLenth; IoCompleteRequest(pIrp,IO_NO_INCREMENT); return Status; }
NTSTATUS Reada(IN PDEVICE_OBJECT pDevObj, IN PIRP pIrp) { PDEVICE_EXTENSION pDevExt = (PDEVICE_EXTENSION)pDevObj->DeviceExtension; NTSTATUS status = STATUS_SUCCESS; PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(pIrp); ULONG ReadLength = stack->Parameters.Read.Length; ULONG ReadOffset = (ULONG)stack->Parameters.Read.ByteOffset.QuadPart; if (ReadOffset+ReadLength>1024) { status = STATUS_FILE_INVALID; ReadLength = 0; }else { KdPrint(("Read buffer 0x%x\n",pDevExt->buffer)); KdPrint(("Read WriteOffset Ox%x\n",ReadOffset)); KdPrint(("Read WriteLenth Ox%x\n",ReadLength)); memcpy(pIrp->AssociatedIrp.SystemBuffer,pDevExt->buffer+ReadOffset,ReadLength); status = STATUS_SUCCESS; } pIrp->IoStatus.Status=status; pIrp->IoStatus.Information=ReadLength; IoCompleteRequest(pIrp,IO_NO_INCREMENT); return status; }
#define MmGetMdlVirtualAddress(Mdl) \ ((PVOID) ((PCHAR) ((Mdl)->StartVa) + (Mdl)->ByteOffset)) //++ // // ULONG // MmGetMdlByteCount ( // __in PMDL Mdl // ) // // Routine Description: // // The MmGetMdlByteCount returns the length in bytes of the buffer // described by the Mdl. // // Arguments: // // Mdl - Pointer to an MDL. // // Return Value: // // Returns the byte count of the buffer described by the Mdl // //-- #define MmGetMdlByteCount(Mdl) ((Mdl)->ByteCount) //++ // // ULONG // MmGetMdlByteOffset ( // __in PMDL Mdl // ) // // Routine Description: // // The MmGetMdlByteOffset returns the byte offset within the page // of the buffer described by the Mdl. // // Arguments: // // Mdl - Pointer to an MDL. // // Return Value: // // Returns the byte offset within the page of the buffer described by the Mdl // //-- #define MmGetMdlByteOffset(Mdl) ((Mdl)->ByteOffset) //++ // // PVOID // MmGetMdlStartVa ( // __in PMDL Mdl // ) // // Routine Description: // // The MmGetMdlBaseVa returns the virtual address of the buffer // described by the Mdl rounded down to the nearest page. // // Arguments: // // Mdl - Pointer to an MDL. // // Return Value: // // Returns the returns the starting virtual address of the MDL. // // //-- #define MmGetMdlBaseVa(Mdl) ((Mdl)->StartVa)
PVOID Kernel_Address=MmGetSystemAddressForMdlSafe(pIrp->MdlAddress,NormalPagePriority);
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!
赞赏记录
参与人
雪币
留言
时间
心游尘世外
为你点赞~
2024-5-31 07:30
QinBeast
为你点赞~
2024-5-31 07:21
飘零丶
为你点赞~
2024-5-31 01:55
shinratensei
为你点赞~
2024-5-31 01:39
一笑人间万事
为你点赞~
2023-3-5 04:12
赞赏
他的文章
- 浅谈内存监控那点事(一)R3篇 9025
- XX 3114
- 放血,不触发PG的Object Protect 12505
- [原创]所谓的过国内各大厂商的读写???? 4797
看原图
赞赏
雪币:
留言: