// ---------------------------------------------------- //
// WinIo v2.0 //
// Direct Hardware Access Under Windows 9x/NT/2000/XP //
// Copyright 1998-2002 Yariv Kaplan //
// http://www.internals.com //
// ---------------------------------------------------- //
#include <ntddk.h>
#include "winio_nt.h"
#define OutputDebugString
#define IOPM_SIZE 0x2000
typedef char IOPM[IOPM_SIZE];
IOPM *pIOPM = NULL;
// Function definition section
// -----------------------------------------------------------------
NTSTATUS WinIoDispatch(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp);
void WinIoUnload(IN PDRIVER_OBJECT DriverObject);
NTSTATUS UnmapPhysicalMemory(HANDLE PhysicalMemoryHandle, PVOID pPhysMemLin);
NTSTATUS MapPhysicalMemoryToLinearSpace(PVOID pPhysAddress,
ULONG PhysMemSizeInBytes,
PVOID *ppPhysMemLin,
HANDLE *pPhysicalMemoryHandle);
void Ke386SetIoAccessMap(int, IOPM *);
void Ke386QueryIoAccessMap(int, IOPM *);
void Ke386IoSetAccessProcess(PEPROCESS, int);
// -----------------------------------------------------------------
// Installable driver initialization entry point.
// This entry point is called directly by the I/O system.
NTSTATUS DriverEntry (IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath)
{
UNICODE_STRING DeviceNameUnicodeString;
UNICODE_STRING DeviceLinkUnicodeString;
NTSTATUS ntStatus;
PDEVICE_OBJECT DeviceObject = NULL;
OutputDebugString ("Entering DriverEntry");
RtlInitUnicodeString (&DeviceNameUnicodeString, L"\\Device\\WinIo");
// Create an EXCLUSIVE device object (only 1 thread at a time
// can make requests to this device).
ntStatus = IoCreateDevice (DriverObject,
0,
&DeviceNameUnicodeString,
FILE_DEVICE_WINIO,
0,
TRUE,
&DeviceObject);
if (NT_SUCCESS(ntStatus))
{
// Create dispatch points for device control, create, close.
DriverObject->MajorFunction[IRP_MJ_CREATE] =
DriverObject->MajorFunction[IRP_MJ_CLOSE] =
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = WinIoDispatch;
DriverObject->DriverUnload = WinIoUnload;
// Create a symbolic link, e.g. a name that a Win32 app can specify
// to open the device.
RtlInitUnicodeString (&DeviceLinkUnicodeString, L"\\DosDevices\\WinIo");
ntStatus = IoCreateSymbolicLink (&DeviceLinkUnicodeString,
&DeviceNameUnicodeString);
if (!NT_SUCCESS(ntStatus))
{
// Symbolic link creation failed- note this & then delete the
// device object (it's useless if a Win32 app can't get at it).
OutputDebugString ("ERROR: IoCreateSymbolicLink failed");
IoDeleteDevice (DeviceObject);
}
}
else
{
OutputDebugString ("ERROR: IoCreateDevice failed");
}
OutputDebugString ("Leaving DriverEntry");
return ntStatus;
}
// Process the IRPs sent to this device
NTSTATUS WinIoDispatch(IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp)
{
PIO_STACK_LOCATION IrpStack;
ULONG dwInputBufferLength;
ULONG dwOutputBufferLength;
ULONG dwIoControlCode;
PVOID pvIOBuffer;
NTSTATUS ntStatus;
struct tagPhys32Struct Phys32Struct;
OutputDebugString ("Entering WinIoDispatch");
// Init to default settings
Irp->IoStatus.Status = STATUS_SUCCESS;
Irp->IoStatus.Information = 0;
IrpStack = IoGetCurrentIrpStackLocation(Irp);
// Get the pointer to the input/output buffer and it's length
pvIOBuffer = Irp->AssociatedIrp.SystemBuffer;
dwInputBufferLength = IrpStack->Parameters.DeviceIoControl.InputBufferLength;
dwOutputBufferLength = IrpStack->Parameters.DeviceIoControl.OutputBufferLength;
switch (IrpStack->MajorFunction)
{
case IRP_MJ_CREATE:
OutputDebugString("IRP_MJ_CREATE");
break;
case IRP_MJ_CLOSE:
OutputDebugString("IRP_MJ_CLOSE");
break;
case IRP_MJ_DEVICE_CONTROL:
OutputDebugString("IRP_MJ_DEVICE_CONTROL");
dwIoControlCode = IrpStack->Parameters.DeviceIoControl.IoControlCode;
switch (dwIoControlCode)
{
case IOCTL_WINIO_ENABLEDIRECTIO:
OutputDebugString("IOCTL_WINIO_ENABLEDIRECTIO");
pIOPM = MmAllocateNonCachedMemory(sizeof(IOPM));
if (pIOPM)
{
RtlZeroMemory(pIOPM, sizeof(IOPM));
Ke386IoSetAccessProcess(PsGetCurrentProcess(), 1);
Ke386SetIoAccessMap(1, pIOPM);
}
else
Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
break;
case IOCTL_WINIO_DISABLEDIRECTIO:
OutputDebugString("IOCTL_WINIO_DISABLEDIRECTIO");
if (pIOPM)
{
Ke386IoSetAccessProcess(PsGetCurrentProcess(), 0);
Ke386SetIoAccessMap(1, pIOPM);
MmFreeNonCachedMemory(pIOPM, sizeof(IOPM));
pIOPM = NULL;
}
break;
case IOCTL_WINIO_MAPPHYSTOLIN:
OutputDebugString("IOCTL_WINIO_MAPPHYSTOLIN");
if (dwInputBufferLength)
{
memcpy (&Phys32Struct, pvIOBuffer, dwInputBufferLength);
ntStatus = MapPhysicalMemoryToLinearSpace(Phys32Struct.pvPhysAddress,
Phys32Struct.dwPhysMemSizeInBytes,
&Phys32Struct.pvPhysMemLin,
&Phys32Struct.PhysicalMemoryHandle);
if (NT_SUCCESS(ntStatus))
{
memcpy (pvIOBuffer, &Phys32Struct, dwInputBufferLength);
Irp->IoStatus.Information = dwInputBufferLength;
}
Irp->IoStatus.Status = ntStatus;
}
else
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
break;
case IOCTL_WINIO_UNMAPPHYSADDR:
OutputDebugString("IOCTL_WINIO_UNMAPPHYSADDR");
if (dwInputBufferLength)
{
memcpy (&Phys32Struct, pvIOBuffer, dwInputBufferLength);
ntStatus = UnmapPhysicalMemory(Phys32Struct.PhysicalMemoryHandle, Phys32Struct.pvPhysMemLin);
Irp->IoStatus.Status = ntStatus;
}
else
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
break;
default:
OutputDebugString("ERROR: Unknown IRP_MJ_DEVICE_CONTROL");
Irp->IoStatus.Status = STATUS_INVALID_PARAMETER;
break;
}
break;
}
// DON'T get cute and try to use the status field of the irp in the
// return status. That IRP IS GONE as soon as you call IoCompleteRequest.
ntStatus = Irp->IoStatus.Status;
IoCompleteRequest (Irp, IO_NO_INCREMENT);
// We never have pending operation so always return the status code.
OutputDebugString("Leaving WinIoDispatch");
return ntStatus;
}
// Delete the associated device and return
void WinIoUnload(IN PDRIVER_OBJECT DriverObject)
{
UNICODE_STRING DeviceLinkUnicodeString;
NTSTATUS ntStatus;
OutputDebugString ("Entering WinIoUnload");
RtlInitUnicodeString (&DeviceLinkUnicodeString, L"\\DosDevices\\WinIo");
ntStatus = IoDeleteSymbolicLink (&DeviceLinkUnicodeString);
if (NT_SUCCESS(ntStatus))
{
IoDeleteDevice (DriverObject->DeviceObject);
}
else
没有合适的资源?快使用搜索试试~ 我知道了~
WinIo2.0(含源代码和帮助)
共67个文件
h:10个
sys:6个
cpp:5个
需积分: 10 16 下载量 6 浏览量
2009-04-16
12:57:05
上传
评论
收藏 85KB RAR 举报
温馨提示
我想知道WinIo库的人,都会知道它的强大吧? 现有源码,实例和帮助文件! 希望大家看了会有所帮助!
资源推荐
资源详情
资源评论
收起资源包目录
WinIo2.0(含源代码和帮助).rar (67个子文件)
20051041061569
WinIo
Help
WinIo.chm 15KB
Examples
C
WinIoTest
WinIoTest.opt 53KB
WinIo.lib 4KB
WinIoTest.cpp 1KB
WinIoTest.dsw 541B
Release
WinIo.dll 48KB
WinIoTest.exe 40KB
WINIO.VXD 5KB
WinIo.sys 5KB
WinIo.h 1KB
WinIoTest.dsp 4KB
VB
VBDumpPort32
MSSCCPRJ.SCC 199B
WinIo.Bas 1KB
WinIo.dll 48KB
VBDumpPort32.frm 7KB
VBDumpPort32.Vbp 1KB
WINIO.VXD 5KB
WinIo.sys 5KB
VBDumpPort32.vbw 91B
VBDumpPort32.exe 24KB
VBDumpPhys32
VBDumpPhys32.vbw 85B
MSSCCPRJ.SCC 199B
WinIo.Bas 1KB
VBDumpPhys32.Vbp 1KB
WinIo.dll 48KB
VBDumpPhys32.frm 7KB
WINIO.VXD 5KB
VBDumpPhys32.exe 24KB
WinIo.sys 5KB
Source
Dll
WinIo.dsp 4KB
K32Call.h 112B
k32exp.h 5KB
resource.h 409B
Port32.h 741B
WinIo.def 184B
k32exp.c 3KB
Port32.cpp 2KB
Phys32.cpp 3KB
Release
WinIo.lib 4KB
WinIo.dll 48KB
WinIo.h 1KB
Phys32.h 124B
WinIo.cpp 3KB
InstDrv.cpp 3KB
WinIo.dsw 533B
WinIo.rc 3KB
Drv
NT
OBJ
_OBJECTS.MAC 294B
I386
WINIO.OBJ 33KB
I386
Checked
WinIo.sys 41KB
Free
WinIo.sys 5KB
WinIo_NT.h 2KB
WinIo.c 12KB
MAKEFILE 267B
SOURCES 85B
BUILD.LOG 2KB
9x
WINIO.DEF 1KB
winio.mak 274B
WinIo_9x.h 363B
WINIO.exp 2KB
WinIo.c 2KB
WinIo.h 189B
WINIO.VXD 5KB
WINIO.lib 2KB
WINIO.VRC 303B
Release
WinIo.dll 48KB
WINIO.VXD 5KB
WinIo.sys 5KB
共 67 条
- 1
资源评论
SpiritMFC
- 粉丝: 39
- 资源: 44
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 学院期间学习代码,包括C,Python,HTML, Java等代码.zip
- 控制原理之经典传递函数
- 全国大学生电子设计竞赛 历年赛题(1994-2023)
- Unity适用于Windows与移动平台双端的轮盘交互式提示菜单
- UE5/UE4超详细教程接入科大讯飞语音唤醒SDK并初始持久监听(10102错误码解决)
- 靠搬运古装剧解说视频,日收益200+,作品原创度90%以上,超详细教程-教程网盘链接提取码下载 .txt
- 2024最强数学建模之美赛攻略.md
- STM32单片机FPGA毕设电路原理论文报告一种机器人寻线控制系统
- STM32单片机FPGA毕设电路原理论文报告一种光电编码器位置检测系统研究与应用
- linux常用命令大全
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功