• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ MmGetSystemAddressForMdlSafe函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中MmGetSystemAddressForMdlSafe函数的典型用法代码示例。如果您正苦于以下问题:C++ MmGetSystemAddressForMdlSafe函数的具体用法?C++ MmGetSystemAddressForMdlSafe怎么用?C++ MmGetSystemAddressForMdlSafe使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了MmGetSystemAddressForMdlSafe函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: DumpKernelMemory

NTSTATUS DumpKernelMemory(PVOID DstAddr, PVOID SrcAddr, ULONG Size)
{
    PMDL  pSrcMdl, pDstMdl;
    PUCHAR pAddress, pDstAddress;
    NTSTATUS st = STATUS_UNSUCCESSFUL;
    ULONG r;

	// Создаем MDL для буфера-источника
    pSrcMdl = IoAllocateMdl(SrcAddr, Size, FALSE, FALSE, NULL);

	if (pSrcMdl)
	{
		// Построение MDL
		MmBuildMdlForNonPagedPool(pSrcMdl);
		// Получение адреса из MDL
		pAddress = (PUCHAR)MmGetSystemAddressForMdlSafe(pSrcMdl, NormalPagePriority);
		zDbgPrint("pAddress = %x", pAddress);
		if (pAddress != NULL)
		{
			pDstMdl = IoAllocateMdl(DstAddr, Size, FALSE, FALSE, NULL);
			zDbgPrint("pDstMdl = %x", pDstMdl);
			if (pDstMdl != NULL)
			{
				__try
				{
					MmProbeAndLockPages(pDstMdl, KernelMode, IoWriteAccess);
					pDstAddress = (PUCHAR)MmGetSystemAddressForMdlSafe(pDstMdl, NormalPagePriority);
					zDbgPrint("pDstAddress = %x", pDstAddress);
					if (pDstAddress != NULL)
					{
						memset(pDstAddress, 0, Size);
						zDbgPrint("Copy block");
						for (r = 1; r < Size; r++)
						{
							if (MmIsAddressValid(pAddress)) 
								*pDstAddress = *pAddress;
							else
								*pDstAddress = 0;
							pAddress++;
							pDstAddress++;
						}

						st = STATUS_SUCCESS;
					}

					MmUnlockPages(pDstMdl);
				}
				__except(EXCEPTION_EXECUTE_HANDLER)
				{    
					zDbgPrint("Copy block exception");
				}
				IoFreeMdl(pDstMdl);
			}
		}            
开发者ID:hackshields,项目名称:antivirus,代码行数:54,代码来源:avz.cpp


示例2: MapIrpOutputBuffer

/*
 * --------------------------------------------------------------------------
 *  Utility function to map the output buffer in an IRP. The buffer is assumed
 *  to have been passed down using METHOD_OUT_DIRECT (Direct I/O).
 * --------------------------------------------------------------------------
 */
static NTSTATUS
MapIrpOutputBuffer(PIRP irp,
                   UINT32 bufferLength,
                   UINT32 requiredLength,
                   PVOID *buffer)
{
    ASSERT(irp);
    ASSERT(buffer);
    ASSERT(bufferLength);
    ASSERT(requiredLength);
    if (!buffer || !irp || bufferLength == 0 || requiredLength == 0) {
        return STATUS_INVALID_PARAMETER;
    }

    if (bufferLength < requiredLength) {
        return STATUS_NDIS_INVALID_LENGTH;
    }
    if (irp->MdlAddress == NULL) {
        return STATUS_INVALID_PARAMETER;
    }
    *buffer = MmGetSystemAddressForMdlSafe(irp->MdlAddress,
                                           NormalPagePriority);
    if (*buffer == NULL) {
        return STATUS_INSUFFICIENT_RESOURCES;
    }

    return STATUS_SUCCESS;
}
开发者ID:waltervargas,项目名称:ovs,代码行数:34,代码来源:Datapath.c


示例3: WriteDirectIn

NTSTATUS WriteDirectIn(IN PIRP pIrp,ULONG inSize,ULONG outSize)
{
	KdPrint(("WriteDirectIn begin\n"));
	NTSTATUS status = STATUS_SUCCESS;

	//获取用户层传入的 输入缓冲区的地址
	PVOID lp_input_buffer=pIrp->AssociatedIrp.SystemBuffer,
		lp_output_buffer=NULL;

	//如果传入了输出缓冲区
	if(pIrp->MdlAddress)
	{
		//锁定输出缓冲区 并映射到内核以供 驱动使用
		lp_output_buffer=MmGetSystemAddressForMdlSafe(pIrp->MdlAddress,NormalPagePriority );
	}

	KdPrint(("WriteDirectIn inSize=%d outSize=%d %S\n",inSize,outSize,(WCHAR*)lp_input_buffer));
	
	UNICODE_STRING unicode_string;
	RtlInitUnicodeString(&unicode_string,L"写入数据成功");
	if(lp_output_buffer)
	{
		RtlCopyMemory(lp_output_buffer,unicode_string.Buffer,unicode_string.Length);
	}
	
	pIrp->IoStatus.Information=unicode_string.Length;

	KdPrint(("WriteDirectIn end\n"));

	return status;
}
开发者ID:zuiwuchang,项目名称:document,代码行数:31,代码来源:Driver.cpp


示例4: ReadDirectOut

NTSTATUS ReadDirectOut(IN PIRP pIrp,ULONG inSize,ULONG outSize)
{
	KdPrint(("ReadDirectOut begin\n"));
	NTSTATUS status = STATUS_SUCCESS;

	
	PVOID lp_output_buffer=NULL;

	//如果传入了输出缓冲区
	if(pIrp->MdlAddress)
	{
		//锁定输出缓冲区 并映射到内核以供 驱动使用
		lp_output_buffer=MmGetSystemAddressForMdlSafe(pIrp->MdlAddress,NormalPagePriority );

		KdPrint(("ReadDirectOut inSize=%d outSize=%d\n",inSize,outSize));
	
		UNICODE_STRING unicode_string;
		RtlInitUnicodeString(&unicode_string,L"读取数据成功");
		RtlCopyMemory(lp_output_buffer,unicode_string.Buffer,unicode_string.Length);
		
		pIrp->IoStatus.Information=unicode_string.Length;

		KdPrint(("ReadDirectOut end\n"));

	}

	return status;
}
开发者ID:zuiwuchang,项目名称:document,代码行数:28,代码来源:Driver.cpp


示例5: xixfs_GetCallersBuffer

PVOID
xixfs_GetCallersBuffer(
	PIRP PtrIrp
)
{

	PVOID ReturnedBuffer = NULL;
	
	PAGED_CODE();
	DebugTrace(DEBUG_LEVEL_TRACE, (DEBUG_TARGET_READ|DEBUG_TARGET_WRITE),
		("Enter xixfs_GetCallersBuffer\n"));

	
	// If an MDL is supplied, use it.
	if (PtrIrp->MdlAddress) {
		ReturnedBuffer = MmGetSystemAddressForMdlSafe(PtrIrp->MdlAddress, NormalPagePriority);
	} else {
		ReturnedBuffer = PtrIrp->UserBuffer;
	}

	

	DebugTrace(DEBUG_LEVEL_TRACE, (DEBUG_TARGET_READ|DEBUG_TARGET_WRITE),
		("Exit xixfs_GetCallersBuffer\n"));
	return(ReturnedBuffer);
}
开发者ID:Nevermore2015,项目名称:ndas4windows,代码行数:26,代码来源:xixfs_filemisc.c


示例6: TsmiHandleMemWrite

/*
* TsmiHandleMemWrite
*
* Purpose:
*
* Patch vbox dll in memory.
*
* Warning: potential BSOD-generator due to nonstandard way of loading, take care with patch offsets.
*
*/
NTSTATUS TsmiHandleMemWrite(
    _In_ PVOID SrcAddress,
    _In_ PVOID DestAddress,
    _In_ ULONG Size
)
{
    PMDL        mdl;
    NTSTATUS    status = STATUS_SUCCESS;

    PAGED_CODE();

    mdl = IoAllocateMdl(DestAddress, Size, FALSE, FALSE, NULL);
    if (mdl == NULL) {
        return STATUS_INSUFFICIENT_RESOURCES;
    }
    if (DestAddress >= MmSystemRangeStart)
        if (!MmIsAddressValid(DestAddress)) {
            return STATUS_ACCESS_VIOLATION;
        }
    MmProbeAndLockPages(mdl, KernelMode, IoReadAccess);
    DestAddress = MmGetSystemAddressForMdlSafe(mdl, HighPagePriority);
    if (DestAddress != NULL) {
        status = MmProtectMdlSystemAddress(mdl, PAGE_EXECUTE_READWRITE);
        __movsb((PUCHAR)DestAddress, (const UCHAR *)SrcAddress, Size);
        MmUnmapLockedPages(DestAddress, mdl);
        MmUnlockPages(mdl);
    }
    else {
        status = STATUS_ACCESS_VIOLATION;
    }

    IoFreeMdl(mdl);
    return status;
}
开发者ID:jamella,项目名称:VBoxHardenedLoader,代码行数:44,代码来源:main.c


示例7: FuseMapUserBuffer

PVOID
FuseMapUserBuffer (
    IN OUT PIRP Irp
    )
{
    //
    // If there is no Mdl, then we must be in the Fsd, and we can simply
    // return the UserBuffer field from the Irp.
    //

    if (Irp->MdlAddress == NULL) {

        return Irp->UserBuffer;
    
    } else {

        PVOID Address = MmGetSystemAddressForMdlSafe( Irp->MdlAddress, NormalPagePriority );

        if (Address == NULL) {

            ExRaiseStatus( STATUS_INSUFFICIENT_RESOURCES );
        }

        return Address;
    }
}
开发者ID:alepharchives,项目名称:FUSE-NT,代码行数:26,代码来源:fuseutil.c


示例8: SerialGetUserBuffers

static VOID
SerialGetUserBuffers(
	IN PIRP Irp,
	IN ULONG IoControlCode,
	OUT PVOID* BufferIn,
	OUT PVOID* BufferOut)
{
	ASSERT(Irp);
	ASSERT(BufferIn);
	ASSERT(BufferOut);

	switch (IO_METHOD_FROM_CTL_CODE(IoControlCode))
	{
		case METHOD_BUFFERED:
			*BufferIn = *BufferOut = Irp->AssociatedIrp.SystemBuffer;
			break;
		case METHOD_IN_DIRECT:
		case METHOD_OUT_DIRECT:
			*BufferIn = Irp->AssociatedIrp.SystemBuffer;
			*BufferOut = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
			break;
		case METHOD_NEITHER:
			*BufferIn = IoGetCurrentIrpStackLocation(Irp)->Parameters.DeviceIoControl.Type3InputBuffer;
			*BufferOut = Irp->UserBuffer;
			break;
		default:
			/* Should never happen */
			*BufferIn = NULL;
			*BufferOut = NULL;
			break;
	}
}
开发者ID:RPG-7,项目名称:reactos,代码行数:32,代码来源:devctrl.c


示例9: MmGetSystemAddressForMdlPrettySafe

//
//	Substitute for MmGetSystemAddressForMdlSafe
//	for NT 4.0 DDK does not provide its equivqlent
//	originally written by Bruce Engle for filedisk
//
static PVOID
MmGetSystemAddressForMdlPrettySafe(
	IN PMDL						Mdl,
	IN MM_PAGE_PRIORITY			Priority)
{
#if (VER_PRODUCTBUILD >= 2195)
	if (OsMajorVersion >= 5) {
		return MmGetSystemAddressForMdlSafe(Mdl, Priority);
	}
	else {
#endif	// (VER_PRODUCTBUILD >= 2195)
		CSHORT	MdlMappingCanFail;
		PVOID	MappedSystemVa;

		MdlMappingCanFail = (CSHORT)(Mdl->MdlFlags & MDL_MAPPING_CAN_FAIL);

		Mdl->MdlFlags |= MDL_MAPPING_CAN_FAIL;

		MappedSystemVa = MmGetSystemAddressForMdl(Mdl);

		if (!MdlMappingCanFail) {
			Mdl->MdlFlags &= ~MDL_MAPPING_CAN_FAIL;
		}

		return MappedSystemVa;
#if (VER_PRODUCTBUILD >= 2195)
	}
#endif	// (VER_PRODUCTBUILD >= 2195)
}
开发者ID:layerfsd,项目名称:Work,代码行数:34,代码来源:vfdrdwr.c


示例10: HideProc_Write

NTSTATUS HideProc_Write(PDEVICE_OBJECT DeviceObject, PIRP Irp){
	NTSTATUS NtStatus = STATUS_INVALID_PARAMETER;
	PIO_STACK_LOCATION pIoStackIrp = NULL;
	UINT dwDataWritten = 0;
	ULONG dwEProcAddr;
	PLIST_ENTRY pListProcs;
	PEPROCESS pEProc;
	
	hpstruct *hps;
	
	DbgPrint("HideProc_Write Called\n");
	pIoStackIrp = IoGetCurrentIrpStackLocation(Irp);
	
	if(pIoStackIrp && Irp->MdlAddress){
		hps = (hpstruct *)MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
		if(hps){
			if(pIoStackIrp->Parameters.Write.Length == sizeof(hpstruct)){
				if(PsLookupProcessByProcessId((PVOID)hps->uPid, &pEProc) == STATUS_SUCCESS){
					DbgPrint("EPROCESS found. Address: %08lX.\n", pEProc);
					DbgPrint("Now hiding process %d...\n", hps->uPid);
					dwEProcAddr = (ULONG) pEProc;
					__try{
						pListProcs = (PLIST_ENTRY) (dwEProcAddr + hps->uFlinkOffset);
						*((ULONG*) pListProcs->Blink) = (ULONG) (pListProcs->Flink);   //set flink of prev proc to flink of cur proc
						*((ULONG*) pListProcs->Flink+1) = (ULONG) (pListProcs->Blink); //set blink of next proc to blink of cur proc
						pListProcs->Flink = (PLIST_ENTRY) &(pListProcs->Flink); //set flink and blink of cur proc to themselves
						pListProcs->Blink = (PLIST_ENTRY) &(pListProcs->Flink); //otherwise might bsod when exiting process
						DbgPrint("Process now hidden.\n");
					}__except(EXCEPTION_EXECUTE_HANDLER){
						NtStatus = GetExceptionCode();
						DbgPrint("Exception: %d.\n", NtStatus);
					}
					NtStatus = STATUS_SUCCESS;
				}
			}else{
开发者ID:hammackj,项目名称:wintools,代码行数:35,代码来源:hide.c


示例11: SafeCopyMemory

NTSTATUS SafeCopyMemory(PVOID SrcAddr, PVOID DstAddr, ULONG Size)
{
	PMDL  pSrcMdl, pDstMdl;
	PUCHAR pSrcAddress, pDstAddress;
	NTSTATUS st = STATUS_UNSUCCESSFUL;
	ULONG r;
	BOOL bInit = FALSE;

	pSrcMdl = IoAllocateMdl(SrcAddr, Size, FALSE, FALSE, NULL);
	if (MmIsAddressValidEx(pSrcMdl))
	{
		MmBuildMdlForNonPagedPool(pSrcMdl);
		pSrcAddress = (PUCHAR)MmGetSystemAddressForMdlSafe(pSrcMdl, NormalPagePriority);
		if (MmIsAddressValidEx(pSrcAddress))
		{
			pDstMdl = IoAllocateMdl(DstAddr, Size, FALSE, FALSE, NULL);
			if (MmIsAddressValidEx(pDstMdl))
			{
				__try
				{
					MmProbeAndLockPages(pDstMdl, KernelMode, IoWriteAccess);
					pDstAddress = (PUCHAR)MmGetSystemAddressForMdlSafe(pDstMdl, NormalPagePriority);
					if (MmIsAddressValidEx(pDstAddress))
					{
						RtlZeroMemory(pDstAddress,Size);
						RtlCopyMemory(pDstAddress, pSrcAddress, Size);
						st = STATUS_SUCCESS;
					}
					MmUnlockPages(pDstMdl);
				}
				__except(EXCEPTION_EXECUTE_HANDLER)
				{                 
					if (pDstMdl) MmUnlockPages(pDstMdl);

					if (pDstMdl) IoFreeMdl(pDstMdl);

					if (pSrcMdl) IoFreeMdl(pSrcMdl);

					return GetExceptionCode();
				}
				IoFreeMdl(pDstMdl);
			}
		}            
		IoFreeMdl(pSrcMdl);
	}
	return st;
}
开发者ID:340211173,项目名称:DriverReader,代码行数:47,代码来源:CommonFunc.c


示例12: FileRead

NTSTATUS FileRead(__in BASE_FILE * File, __in PIRP Irp,
		  __in PIO_STACK_LOCATION IrpStack)
{
	BASE_DEVICE *Device = BaseFileGetDevice(File);
	DEVICE_DATA *DeviceData = (DEVICE_DATA *) BaseDeviceGetPrivate(Device);
	ULONG Length = IrpStack->Parameters.Read.Length;
	PLIST_ENTRY ListEntry;
	BUFFER_DATA *BufferData = NULL;
	PVOID Buffer;
	NTSTATUS Status = STATUS_SUCCESS;

	PAGED_CODE();

	__try {
		ListEntry =
		    ExInterlockedRemoveHeadList(&DeviceData->BufferList,
						&DeviceData->BufferListLock);
		if (ListEntry == NULL) {
			TRACE_MSG(TRACE_LEVEL_ERROR, TRACE_FLAG_DEFAULT,
				  "No data available\n");
			Status = STATUS_NO_DATA_DETECTED;
			__leave;
		}
		BufferData = CONTAINING_RECORD(ListEntry, BUFFER_DATA,
					       ListEntry);
		if (Length < BufferData->Length) {
			TRACE_MSG(TRACE_LEVEL_ERROR, TRACE_FLAG_DEFAULT,
				  "Buffer too small (len=%u, required=%u)\n",
				  Length, BufferData->Length);
			Status = STATUS_INVALID_BUFFER_SIZE;
			__leave;
		}
		ASSERT(Irp->MdlAddress);
		if (Irp->MdlAddress == NULL) {
			TRACE_MSG(TRACE_LEVEL_ERROR, TRACE_FLAG_DEFAULT,
				  "Null MDL pointer\n");
			Status = STATUS_INVALID_PARAMETER;
			__leave;
		}
		Buffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress,
						      NormalPagePriority);
		if (Buffer == NULL) {
			Status = STATUS_INSUFFICIENT_RESOURCES;
			TRACE_ERR("MmGetSystemAddressForMdlSafe", Status);
			__leave;
		}
		TRACE_MSG(TRACE_LEVEL_INFO, TRACE_FLAG_DEFAULT,
			  "Return %u bytes (requested %u bytes)\n",
			  BufferData->Length, Length);
		RtlCopyMemory(Buffer, BufferData->Data, BufferData->Length);
		Irp->IoStatus.Information = BufferData->Length;
	}
	__finally {
		if (BufferData)
			ExFreePoolWithTag(BufferData, SAMPLE_POOL_TAG);
		BaseFileCompleteRequest(File, Irp, Status);
	}
	return Status;
}
开发者ID:hiro-sakamoto,项目名称:miscutil,代码行数:59,代码来源:common.c


示例13: __DestrPacket

void __DestrPacket(OUT PPACKET_BASE pPacket)
{
    if (pPacket->pMdl)
    {
        PVOID Va = MmGetSystemAddressForMdlSafe(pPacket->pMdl, LowPagePriority);
        ExFreePoolWithTag(Va, (ULONG)'TTWH');
        IoFreeMdl(pPacket->pMdl);
    }
}
开发者ID:PaulJing,项目名称:Sora,代码行数:9,代码来源:mp_main_5x.c


示例14: FatMapUserBuffer

PVOID
FASTCALL
FatMapUserBuffer(PIRP Irp)
{
    if (!Irp->MdlAddress)
        return Irp->UserBuffer;
    else
        return MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
}
开发者ID:GYGit,项目名称:reactos,代码行数:9,代码来源:fastfat.c


示例15: TsmiHandleMemWrite

/*
* TsmiHandleMemWrite
*
* Purpose:
*
* Patch vbox dll in memory.
*
* Warning: If compiled not in ReleaseSigned configuration this function is a
* potential BSOD-generator due to nonstandard way of loading, take care with patch offsets.
*
*/
NTSTATUS TsmiHandleMemWrite(
    _In_ PVOID SrcAddress,
    _In_ PVOID DestAddress,
    _In_ ULONG Size
)
{
    PMDL        mdl;
    NTSTATUS    status = STATUS_SUCCESS;

    PAGED_CODE();

    mdl = IoAllocateMdl(DestAddress, Size, FALSE, FALSE, NULL);
    if (mdl == NULL) {
#ifdef _DEBUGMSG
        DbgPrint("[TSMI] Failed to create MDL at write\n");
#endif
        return STATUS_INSUFFICIENT_RESOURCES;
    }

#ifdef _SIGNED_BUILD
    __try {
#endif //_SIGNED_BUILD

        if (DestAddress >= MmSystemRangeStart)
            if (!MmIsAddressValid(DestAddress)) {
#ifdef _DEBUGMSG
                DbgPrint("[TSMI] Invalid address\n");
#endif //_DEBUGMSG
                return STATUS_ACCESS_VIOLATION;
            }
        MmProbeAndLockPages(mdl, KernelMode, IoReadAccess);
        DestAddress = MmGetSystemAddressForMdlSafe(mdl, HighPagePriority);
        if (DestAddress != NULL) {
            status = MmProtectMdlSystemAddress(mdl, PAGE_EXECUTE_READWRITE);
            __movsb((PUCHAR)DestAddress, (const UCHAR *)SrcAddress, Size);
            MmUnmapLockedPages(DestAddress, mdl);
            MmUnlockPages(mdl);
        }
        else {
            status = STATUS_ACCESS_VIOLATION;
        }

#ifdef _SIGNED_BUILD
    }
    __except (EXCEPTION_EXECUTE_HANDLER) {
        status = STATUS_ACCESS_VIOLATION;
#ifdef _DEBUGMSG
        DbgPrint("[TSMI] MmProbeAndLockPages failed at write DestAddress = %p\n", DestAddress);
#endif //_DEBUGMSG
    }
#endif //_SIGNED_BUILD

    IoFreeMdl(mdl);
    return status;
}
开发者ID:CM44,项目名称:VBoxHardenedLoader,代码行数:66,代码来源:main.c


示例16: NotifyReceivedPacket

void NotifyReceivedPacket(BASE_FILE * File)
{
	CSFBR_FILE_DATA *FileData =
	    (CSFBR_FILE_DATA *) BaseFileGetPrivate(File);
	CSF_PKT *pkt;
	PIRP Irp;
	PVOID Buffer;
	PIO_STACK_LOCATION IrpStack;
	NTSTATUS Status = STATUS_SUCCESS;

	if (csf_pktq_empty(FileData->rxq)) {
		TRACE_MSG(TRACE_LEVEL_ERROR, TRACE_FLAG_DEFAULT,
			  "Packet queue empty\n");
		return;
	}

	Irp = IoCsqRemoveNextIrp(&FileData->csq, NULL);
	if (Irp == NULL) {
		TRACE_MSG(TRACE_LEVEL_ERROR, TRACE_FLAG_DEFAULT,
			  "IRP list empty\n");
		return;
	}

	pkt = csf_pktq_remove(FileData->rxq);
	if (pkt == NULL) {
		TRACE_MSG(TRACE_LEVEL_ERROR, TRACE_FLAG_DEFAULT,
			  "Packet queue empty\n");
		Status = STATUS_NO_DATA_DETECTED;
	} else {
		ASSERT(Irp->MdlAddress);
		Buffer = MmGetSystemAddressForMdlSafe(Irp->MdlAddress,
						      NormalPagePriority);
		if (Buffer == NULL) {
			Status = STATUS_INSUFFICIENT_RESOURCES;
			TRACE_ERR("MmGetSystemAddressForMdlSafe", Status);
		} else {
			IrpStack = IoGetCurrentIrpStackLocation(Irp);
			if (IrpStack->Parameters.Read.Length <
			    csf_pkt_get_len(pkt)) {
				TRACE_MSG(TRACE_LEVEL_ERROR, TRACE_FLAG_DEFAULT,
					  "Read buffer too small - len %u, required %u\n",
					  IrpStack->Parameters.Read.Length,
					  csf_pkt_get_len(pkt));
				Status = STATUS_BUFFER_TOO_SMALL;
			} else {
				RtlCopyMemory(Buffer, csf_pkt_get_buf(pkt),
					      csf_pkt_get_len(pkt));
				Irp->IoStatus.Information =
				    csf_pkt_get_len(pkt);
			}
		}
		csf_pkt_return(pkt);
	}
	BaseFileCompleteRequest(File, Irp, Status);
}
开发者ID:hiro-sakamoto,项目名称:csf,代码行数:55,代码来源:csfbr.c


示例17: CFTDefaultDispatch

NTSTATUS CFTDefaultDispatch(PDEVICE_OBJECT aDeviceObject, PIRP aIrp)
{
	PIO_STACK_LOCATION ioStackLocation = IoGetCurrentIrpStackLocation(aIrp);
	NTSTATUS status = STATUS_SUCCESS;
	ULONG i = 0, j = 0;

	// 首先需要知道发送给了那哪个设备。
	for (i = 0; i < CFT_MAX_COM_ID; ++i)
	{
		if (global_FileDevice[i] == aDeviceObject)
		{
			// 所有电源操作一律不过滤
			if (ioStackLocation->MajorFunction == IRP_MJ_POWER)
			{
				// 直接发送
				PoStartNextPowerIrp(aIrp);
				IoSkipCurrentIrpStackLocation(aIrp);
				return PoCallDriver(global_RealDevice[i], aIrp);
			}

			// 我们只过滤写请求,获得缓冲区以及长度,打印出来。
			if (ioStackLocation->MajorFunction == IRP_MJ_WRITE)
			{
				// 获得长度
				ULONG len = ioStackLocation->Parameters.Write.Length;

				// 获得缓冲区
				PUCHAR buf = NULL;
				if (aIrp->MdlAddress != NULL)
					buf = (PUCHAR)MmGetSystemAddressForMdlSafe(aIrp->MdlAddress, NormalPagePriority);
				else
					buf = (PUCHAR)aIrp->UserBuffer;

				if (buf == NULL)
					buf = (PUCHAR)aIrp->AssociatedIrp.SystemBuffer;

				// 打印内容
				for (j = 0; j < len; ++j)
					DbgPrint("COM capture : Send-Data : %2x\r\n", buf[j]);
			}
		}

		// 直接下发
		IoSkipCurrentIrpStackLocation(aIrp);
		return IoCallDriver(global_RealDevice[i], aIrp);
	}

	// 如果根本就不在被绑定的设备中,那是有问题的,直接返回参数
	aIrp->IoStatus.Information = 0;
	aIrp->IoStatus.Status = STATUS_INVALID_PARAMETER;
	IoCompleteRequest(aIrp, IO_NO_INCREMENT);
	return STATUS_SUCCESS;
}
开发者ID:killbug2004,项目名称:wy-windows-driver,代码行数:53,代码来源:wycomflt.cpp


示例18: MrGetUserBuffer

PVOID
MrGetUserBuffer(IN PIRP Irp)
{
    ASSERT(Irp != NULL);

    if (Irp->MdlAddress) {
        return MmGetSystemAddressForMdlSafe(Irp->MdlAddress,
                                         NormalPagePriority);
    } else {
        return Irp->UserBuffer;
    }
}
开发者ID:matt-wu,项目名称:Moure,代码行数:12,代码来源:moure.c


示例19: MbrReadComplete

//Called after a read request to the MBR has been processed
NTSTATUS MbrReadComplete(PDEVICE_OBJECT DeviceObject, PIRP Irp, PVOID Context)
{
	PVOID SystemMdlAddress;
	PIO_STACK_LOCATION StackLocation; 
	PCOMPLETION_CTX CompletionCtx;
	CHAR InvokeCompletion = FALSE;
	UCHAR Control;
	NTSTATUS IrpStatus, status = STATUS_SUCCESS;

	CompletionCtx = (PCOMPLETION_CTX)Context;
	StackLocation = IoGetCurrentIrpStackLocation(Irp);

	//If request was successful, we need to replace the real MBR inside buffer
	if(NT_SUCCESS(Irp->IoStatus.Status) && CompletionCtx->TransferLength > 0)
	{
		SystemMdlAddress = MmGetSystemAddressForMdlSafe(Irp->MdlAddress, NormalPagePriority);
		if(SystemMdlAddress)
		{
			memcpy(SystemMdlAddress, FakeMbr, 512);
			DbgPrint("{CompletionRoutine} Disk read request was successful, replaced MBR in buffer %X\n", CompletionCtx->TransferLength);
		}
	}

	//Restore original completion routine information
	StackLocation->Context = CompletionCtx->OriginalContext;
	StackLocation->CompletionRoutine = CompletionCtx->OriginalRoutine;
	StackLocation->Control = CompletionCtx->OriginalControl;

	Control = StackLocation->Control;
	IrpStatus = Irp->IoStatus.Status;

	//If there is an original completion routine, check if it should be called
	if(StackLocation->CompletionRoutine)
	{
		if(NT_SUCCESS(IrpStatus) && (Control & SL_INVOKE_ON_SUCCESS) == SL_INVOKE_ON_SUCCESS)
			InvokeCompletion = TRUE;

		if(IrpStatus == STATUS_CANCELLED && (Control & SL_INVOKE_ON_CANCEL) == SL_INVOKE_ON_CANCEL)
			InvokeCompletion = TRUE;

		if(NT_ERROR(IrpStatus) && IrpStatus != STATUS_CANCELLED && 
			(Control & SL_INVOKE_ON_ERROR) == SL_INVOKE_ON_ERROR)
			InvokeCompletion = TRUE;
	}

	//Call original completion routine
	if(InvokeCompletion == TRUE)
		status = (StackLocation->CompletionRoutine)(DeviceObject, Irp, StackLocation->Context);

	ExFreePool(Context);
	return status;
}
开发者ID:bowlofstew,项目名称:FakeMBR,代码行数:53,代码来源:ScsiFilter.cpp


示例20: DriverDispatch

NTSTATUS DriverDispatch(PDEVICE_OBJECT DeviceObject,PIRP irp)
{
	PIO_STACK_LOCATION io;
	PINJECT_INFO InjectInfo;

	NTSTATUS status;

	io=IoGetCurrentIrpStackLocation(irp);
	irp->IoStatus.Information=0;

	switch(io->MajorFunction)
	{
	    case IRP_MJ_CREATE:
			status=STATUS_SUCCESS;
			break;
		case IRP_MJ_CLOSE:
			status=STATUS_SUCCESS;
			break;
		case IRP_MJ_READ:
			status=STATUS_SUCCESS;
			break;
		case IRP_MJ_WRITE:

			InjectInfo=(PINJECT_INFO)MmGetSystemAddressForMdlSafe(irp->MdlAddress,NormalPagePriority);

			if(!InjectInfo)
			{
				status=STATUS_INSUFFICIENT_RESOURCES;
				break;
			}

			if(!InjectDll(InjectInfo))
			{
				status=STATUS_UNSUCCESSFUL;
				break;
			}

			status=STATUS_SUCCESS;
			irp->IoStatus.Information=sizeof(INJECT_INFO);

			break;

		default:
			status=STATUS_INVALID_DEVICE_REQUEST;
			break;
	}

	irp->IoStatus.Status=status;

	IoCompleteRequest(irp,IO_NO_INCREMENT);
	return status;
}
开发者ID:LTears,项目名称:Kinject-x64,代码行数:52,代码来源:Driver.c



注:本文中的MmGetSystemAddressForMdlSafe函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ MmIsAddressValid函数代码示例发布时间:2022-05-30
下一篇:
C++ MmBuildMdlForNonPagedPool函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap