aKnightChen
驱动牛犊
驱动牛犊
  • 注册日期2003-05-13
  • 最后登录2005-04-12
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:994回复:1

WDM1例子:对指定地址写操作.但它是如何把指定的地址值传给驱动程序呢?(附代码)

楼主#
更多 发布于:2003-06-06 14:23
WDM1TEST例子(exe文件)
-----------------
ULONG Wvalue = 0x12345678;  //:o:o:o:o:o:o指定地址
if( !WriteFile( hWdm1, &Wvalue, 4, &TxdBytes, NULL))
printf(\"XXX  Could not write %X\\n\",Wvalue);
else if( TxdBytes==4)
printf(\"     Write 0x%x succeeded\\n\",Wvalue);
else
printf(\"XXX  Wrong number of bytes written: %d\\n\",TxdBytes);
===================
驱动程序(sys)
--------------------
NTSTATUS Wdm1Write( IN PDEVICE_OBJECT fdo,
IN PIRP Irp)
{
PIO_STACK_LOCATION IrpStack = IoGetCurrentIrpStackLocation(Irp);
NTSTATUS status = STATUS_SUCCESS;
LONG BytesTxd = 0;

// Get call parameters
LONGLONG FilePointer = IrpStack->Parameters.Write.ByteOffset.QuadPart;

          :o:o:o:o:o //EXE程序中传过来的地址0x12345678到底放在IrpStack的哪个属性里???

ULONG WriteLen = IrpStack->Parameters.Write.Length;
DebugPrint(\"Write %d bytes from file pointer %d\",(int)WriteLen,(int)FilePointer);

if( FilePointer<0)
status = STATUS_INVALID_PARAMETER;
else
{
// Get access to the shared buffer
KIRQL irql;
KeAcquireSpinLock(&BufferLock,&irql);

BytesTxd = WriteLen;

// (Re)allocate buffer if necessary
if( ((ULONG)FilePointer)+WriteLen>BufferSize)
{
ULONG NewBufferSize = ((ULONG)FilePointer)+WriteLen;
PVOID NewBuffer = ExAllocatePool(NonPagedPool,NewBufferSize);
if( NewBuffer==NULL)
{
BytesTxd = BufferSize - (ULONG)FilePointer;
if( BytesTxd<0) BytesTxd = 0;
}
else
{
RtlZeroMemory(NewBuffer,NewBufferSize);
if( Buffer!=NULL)
{
RtlCopyMemory(NewBuffer,Buffer,BufferSize);
ExFreePool(Buffer);
}
Buffer = (PUCHAR)NewBuffer;
BufferSize = NewBufferSize;
}
}

// Write to shared memory
if( BytesTxd>0 && Buffer!=NULL)
RtlCopyMemory( Buffer+FilePointer, Irp->AssociatedIrp.SystemBuffer, BytesTxd);

// Release shared buffer
KeReleaseSpinLock(&BufferLock,irql);
}

DebugPrint(\"Write: %d bytes written\",(int)BytesTxd);

// Complete IRP
return CompleteIrp(Irp,status,BytesTxd);
}
------------------
 
windyguy
驱动牛犊
驱动牛犊
  • 注册日期2003-05-07
  • 最后登录2004-05-28
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-06-06 19:10
……汗

0x12345678是ULONG Wvalue的值,不是一个地址。

这个值传送到驱动程序的Write例程时,放在IRP->AssociatedIrp.SystemBuffer里面。
游客

返回顶部