【发布时间】:2011-12-02 23:54:01
【问题描述】:
我正在使用以下代码解析 http://msdn.microsoft.com/en-us/library/windows/hardware/ff540352(v=vs.85).aspx 中定义的 _URB_BULK_OR_INTERRUPT_TRANSFER 数据包:
//parse URB Packet
/*
_URB_HEADER {
USHORT Length;
USHORT Function;
USBD_STATUS Status;
PVOID UsbdDeviceHandle;
ULONG UsbdFlags;
}*/
//start header parse
UInt16 urb_length = rdr.ReadUInt16();
UInt16 urb_function = rdr.ReadUInt16();
UInt32 urb_status = rdr.ReadUInt32();
rdr.ReadBytes(System.IntPtr.Size);
UInt32 UsbdFlags = rdr.ReadUInt32();
//end header parse
//.. skip code to check if it a _URB_BULK_OR_INTERRUPT_TRANSFER
// but assuming it is parse it
/*struct _URB_BULK_OR_INTERRUPT_TRANSFER {
struct URB_HEADER Hdr;//covered above
USBD_PIPE_HANDLE PipeHandle;
ULONG TransferFlags;
ULONG TransferBufferLength;
PVOID TransferBuffer;
PMDL TransferBufferMDL;
struct URB *UrbLink;
struct URB_HCD_AREA hca;
}*/
rdr.ReadBytes(System.IntPtr.Size);
UInt32 TransferFlags = rdr.ReadUInt32();
UInt32 TransferBufferLength = rdr.ReadUInt32();
byte[] ptr_bytes = rdr.ReadBytes(System.IntPtr.Size);
System.IntPtr ptr_transfer_buffer = new System.IntPtr(BitConverter.ToUInt32(ptr_bytes, 0));
ptr_bytes = rdr.ReadBytes(System.IntPtr.Size);
System.IntPtr mdl_transfer_buffer = new System.IntPtr(BitConverter.ToUInt32(ptr_bytes, 0))
在读取所有值时检查它们,在 PMDL void 指针之前,大多数值似乎是明智的。这最终是一个很大的负数,而不是 0 (NULL) 或有效地址。谁能指出我为什么会发生这种情况的正确方向?谢谢。
【问题讨论】: