这两天学写驱动以下是我的com.sys的代码...可以捕捉到读与写的数据并在dbg中显示出来并且dbg里显示的都是我修改过的数据...也就是说成功了....但是串口调试工具与监听工具查的话只有IRP_MJ_WRITE的数据可以修改成功IRP_MJ_READ的数据依然没有改变.... 请问应该怎么修改才可以改变从设备传回来的IRP_MJ_READ数据
工具:wdk,dbgview,srvinstw,vmware,vs2005,
代码:
C/C++ code
if(irpsp->MajorFunction == IRP_MJ_WRITE)
{
// 如果是写,先获得长度
ULONG len = irpsp->Parameters.Write.Length;
// 然后获得缓冲区
PUCHAR buf = NULL;
if(irp->MdlAddress != NULL)
{
buf = (PUCHAR)MmGetSystemAddressForMdlSafe(irp->MdlAddress,NormalPagePriority);
DbgPrint("aaaaaaaaaa");
}
else
{
//memset((PUCHAR)irp->UserBuffer,0x31,len);
buf = (PUCHAR)irp->UserBuffer;
DbgPrint("bbbbbbbbbbb");
}
if(buf == NULL)
{
memset((PUCHAR)irp->AssociatedIrp.SystemBuffer,0x31,len);
buf = (PUCHAR)irp->AssociatedIrp.SystemBuffer;
DbgPrint("cccccccccc");
}
// 打印内容
for(j=0;j<len;++j)
{
DbgPrint("comcap: Send Data: %2x\r\n",buf[j]);
}
}
if(irpsp->MajorFunction == IRP_MJ_READ)
{
// 如果是写,先获得长度
ULONG len1 = irpsp->Parameters.Read.Length;
// 然后获得缓冲区
PUCHAR buf1 = NULL;
/*if(irp->MdlAddress != NULL)
{
buf1 =(PUCHAR)MmGetSystemAddressForMdlSafe(irp->MdlAddress,NormalPagePriority);
DbgPrint("1111111111111");
}
else
{
memset((PUCHAR)irp->UserBuffer,0x32,len1);
buf1 = (PUCHAR)irp->UserBuffer;
DbgPrint("222222222");
}*/
if(buf1 == NULL)
{
memset((PUCHAR)irp->AssociatedIrp.SystemBuffer,0x32,len1);
buf1 = (PUCHAR)irp->AssociatedIrp.SystemBuffer;
DbgPrint("33333333");
}
// 打印内容
for(j=0;j<len1;++j)
{
DbgPrint("comcap: Send Data: %2x\r\n",buf1[j]);
}
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!