⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mapmem.cpp

📁 基于DS编写的windows驱动程序内存映射示例程序,初学者必看
💻 CPP
字号:
// mapmem.cpp -  example driver
//=============================================================================
//
// Compuware Corporation
// NuMega Lab
// 9 Townsend West
// Nashua, NH 03060  USA
//
// Copyright (c) 1998 Compuware Corporation. All Rights Reserved.
// Unpublished - rights reserved under the Copyright laws of the
// United States.
//
//=============================================================================

// This driver maps a range of physical memory on the ISA bus.
// The address and size of the range have default values, but
// can be taken from the Parameters subkey of the driver's
// registry key at initialization. 
//
// The driver does not map the memory to kernel space. Rather,
// it waits until a process sends a DeviceIoControl call, and
// then it maps the address into that process. Later, the process
// calls back to undo the mapping.

#define VDW_MAIN
#include <vdw.h>

#include "mmdevice.h"
#include "mapmem.h"

#pragma code_seg("INIT")

DECLARE_DRIVER_CLASS(MapMemDriver, NULL)

//////////////////////////////////////////////////////////////////////////
// DriverEntry
//
// Retrieve parameters and create device object
//
NTSTATUS MapMemDriver::DriverEntry(PUNICODE_STRING RegistryPath)
{
	MapMemDevice* pDevice;

	ULONG DeviceMemoryAddress = DEFAULT_DEVMEMORY_ADDRESS;
	ULONG DeviceMemorySize = DEFAULT_DEVMEMORY_SIZE;

	KRegistryKey Params(RegistryPath, L"Parameters");
	if ( NT_SUCCESS (Params.LastError()) )
	{
		Params.QueryValue(L"DEVICE_ADDRESS", &DeviceMemoryAddress);
		Params.QueryValue(L"DEVICE_SIZE", &DeviceMemorySize);
	}

	pDevice = new (NonPagedPool) MapMemDevice(DeviceMemoryAddress, DeviceMemorySize);

	if ( pDevice == NULL )
		return STATUS_INSUFFICIENT_RESOURCES;
	else
	{
		NTSTATUS status = pDevice->ConstructorStatus();
		if ( !NT_SUCCESS(status) )
			delete pDevice;
		return status;
	}
}

#pragma code_seg()

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -