注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

熊猫正正的博客

熊猫正正的天空

 
 
 

日志

 
 

驱动与应用层通信  

2012-03-20 15:27:59|  分类: window驱动学习 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
(1)缓冲模式
#define XX_CODE CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_BUFFER,FILE_ANY_ACCESS)

ULONG cbin = stack->Parameters.DeviceIoControl.InputBufferLength;
ULONG cbout = stack->Parameters.DeviceIoControl.OutputBufferLength;
ULONG code = stack->Parameters.DeviceIoControl.IoControlCode;
switch(code)
{
case XX_CODE:
int* InputBuffer = (int*)pIrp->AssociatedIrp.SystemBuffer;
__asm
{
mov eax,InputBuffer
mov ebx,[eax]
mov a,ebx
mov ebx,[eax+4]
mov b,ebx
}

int* OutputBuffer = (int*)pIrp->AssociatedIrp.SystemBuffer;
__asm
{
mov eax,a
mov ebx,OutputBuffer
mov [ebx],eax
}
info = 4;
break;
}
pIrp->IoStatus.Information = info;
pIrp->IoStatus.Status = STATUS_SUCCESS;
IoCompleteRequest(pIrp,IO_NO_INCREMENT);
return STATUS_SUCCESS;

(2)直接访问模式
#define XX_CODE CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_IN_DIRECT,FILE_ANY_ACCESS)

PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(pIrp);
ULONG cbin = stack->Parameters.DeviceIoControl.InputBufferLength;
ULONG cbout = stack->Parameters.DeviceIoControl.OutputBufferLength;
ULONG code = stack->Parameters.DeviceIoControl.IoControlCode;
switch(code)
{
case XX_CODE:
int* InputBuffer = (int*)pIrp->AssociatedIrp.SystemBuffer;
__asm
{
mov eax,InputBuffer
mov ebx,[eax]
mov a,ebx
mov ebx,[eax+4]
mov b,ebx
}

int* OutputBuffer = (int*)MmGetSystemAddressForMdlSafe(pIrp->MdlAddress,NormalPagePriority);
__asm
{
mov eax,a
mov ebx,OutputBuffer
mov [ebx],eax
}
info = 4;
break;
}
pIrp->IoStatus.Information = info;
pIrp->IoStatus.Status = STATUS_SUCCESS;
IoCompleteRequest(pIrp,IO_NO_INCREMENT);
return STATUS_SUCCESS;

(3)其它模式
#define XX_CODE CTL_CODE(FILE_DEVICE_UNKNOWN,0x800,METHOD_NEITHER,FILE_ANY_ACCESS)

PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(pIrp);
ULONG mf = stack->MajorFunction;
switch(mf)
{
case IRP_MJ_DEVICE_CONTROL:
{
ULONG cbin = stack->Parameters.DeviceIoControl.InputBufferLength;
ULONG cbout = stack->Parameters.DeviceIoControl.OutputBufferLength;
ULONG code = stack->Parameters.DeviceIoControl.IoControlCode;
switch(code)
{
case XX_CODE:
int* InputBuffer = (int*)stack->Parameters.DeviceIoControl.Type3InputBuffer;
__try
{
ProbeForRead(InputBuffer,cbin,__alignof(int));
__asm
{
mov eax,InputBuffer
mov ebx,[eax]
mov a,ebx
mov ebx,[eax+4]
mov b,ebx
}
int* OutputBuffer = (int*)pIrp->UserBuffer;
ProbeForWrite(OutputBuffer,cbout,4);
__asm
{
mov eax,a
mov ebx,OutputBuffer
mov [ebx],eax
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
KdPrint(("Address is not Read or Write!\n"));
}
info = 4;
break;
}
}
break;
}
pIrp->IoStatus.Information = info;
pIrp->IoStatus.Status = STATUS_SUCCESS;
IoCompeleRequest(pIrp,IO_NO_INCREMENT);
return STATUS_SUCCESS;
以上代码只是参考作用,红色标出了三种不同的通信方式~~










  评论这张
 
阅读(95)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017