kcynice
驱动牛犊
驱动牛犊
  • 注册日期2008-03-03
  • 最后登录2010-08-28
  • 粉丝1
  • 关注0
  • 积分43分
  • 威望138点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分2分
阅读:3045回复:5

IRP消息处理的一个问题(IRP_MJ_DEVICE_CONTROL)

楼主#
更多 发布于:2008-09-12 16:48
大家都知道,IRP响应函数(DriverObject->MajorFuction)的原型都接收两个参数:
(PDEVICE_OBJECT pDeviceObject , PIRP irp)
我在网上查了一下IRP结构的定义如下:
typedef struct _IRP
{
 +00:    SHORT Type;
 +02:   WORD Size;
 +04:    PMDL MdlAddress;
 +08:   ULONG Flags;
 +0C:    ULONG AssociatedIrp;
 +10:    LIST_ENTRY ThreadListEntry;
 +18:    IO_STATUS_BLOCK IoStatus;
 +20:    CHAR RequestorMode;
 +21:    UCHAR PendingReturned;
 +22:   CHAR StackCount;
 +23:    CHAR CurrentLocation;
 +24:    UCHAR Cancel;
 +25:    UCHAR CancelIrql;
 +26:    CHAR ApcEnvironment;
 +27:    UCHAR AllocationFlags;
 +2B:    PIO_STATUS_BLOCK UserIosb;
 +30:    PKEVENT UserEvent;
 +34:   UINT64 Overlay;
 +3C:    PVOID CancelRoutine;
 +40:    PVOID UserBuffer;
 +44:    ULONG Tail;
} IRP, *PIRP;
从而,一个IRP结构是00x44个字节,但是,我看了一个驱动中一个函数的汇编码是这样:
//参数PDEVICE_OBJECT,PIRP
mov edi,edi        ;//肯定没关系,不管它
push ebp
mov ebp,esp     ;这是常规套路
sub esp,0c        ;为局部变量分配空间,不管
push ebx
mov ebx,[ebp+0Ch]   ;//得到的是第2个参数
push esi                      ;保存原始值
mov esi,[ebx+60h]    ;==========我的问题就在这儿
.....
在上面的代码中,取得第2个参数之后,就是得到了IRP结构的首地址,可是,根据前面的统计,一个IRP结构最大只有0x48字节长,可是它怎么在下面访问偏移0x60处的数据呢?

谢谢
kgdiwss
驱动牛犊
驱动牛犊
  • 注册日期2005-11-30
  • 最后登录2009-02-11
  • 粉丝2
  • 关注0
  • 积分655分
  • 威望89点
  • 贡献值0点
  • 好评度65点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2008-09-12 18:31
结构里套有其它结构的.你应该用windbg的-r参数,就能看到原来还有很多隐藏看不到的东西.
bbs.80dnst.com -- 驱动/逆向
kcynice
驱动牛犊
驱动牛犊
  • 注册日期2008-03-03
  • 最后登录2010-08-28
  • 粉丝1
  • 关注0
  • 积分43分
  • 威望138点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分2分
板凳#
发布于:2008-09-16 11:05
引用第1楼kgdiwss于2008-09-12 18:31发表的  :
结构里套有其它结构的.你应该用windbg的-r参数,就能看到原来还有很多隐藏看不到的东西.


是的,的确是可以看到更多隐藏看不到的东西,可那只是伸展了子元素。可以看到的是,IRP结构里面的子元素大部分都是指针,所以并不影响啊,我的原贴上的偏移不知道是哪儿有问题?
我直接在驱动原文件中试过用sizeof(IRP),结果是0x70,而我算得的是0x48不知道问题出在哪儿?
rayyang2000
管理员
管理员
  • 注册日期2001-03-23
  • 最后登录2012-09-13
  • 粉丝3
  • 关注0
  • 积分1036分
  • 威望925点
  • 贡献值3点
  • 好评度823点
  • 原创分0分
  • 专家分0分
地板#
发布于:2008-09-16 12:25
0: kd> dt nt!_IRP -r
   +0x000 Type             : Int2B
   +0x002 Size             : Uint2B
   +0x004 MdlAddress       : Ptr32 _MDL
      +0x000 Next             : Ptr32 _MDL
         +0x000 Next             : Ptr32 _MDL
         +0x004 Size             : Int2B
         +0x006 MdlFlags         : Int2B
         +0x008 Process          : Ptr32 _EPROCESS
         +0x00c MappedSystemVa   : Ptr32 Void
         +0x010 StartVa          : Ptr32 Void
         +0x014 ByteCount        : Uint4B
         +0x018 ByteOffset       : Uint4B
      +0x004 Size             : Int2B
      +0x006 MdlFlags         : Int2B
      +0x008 Process          : Ptr32 _EPROCESS
         +0x000 Pcb              : _KPROCESS
         +0x06c ProcessLock      : _EX_PUSH_LOCK
         +0x070 CreateTime       : _LARGE_INTEGER
         +0x078 ExitTime         : _LARGE_INTEGER
         +0x080 RundownProtect   : _EX_RUNDOWN_REF
         +0x084 UniqueProcessId  : Ptr32 Void
         +0x088 ActiveProcessLinks : _LIST_ENTRY
         +0x090 QuotaUsage       : [3] Uint4B
         +0x09c QuotaPeak        : [3] Uint4B
         +0x0a8 CommitCharge     : Uint4B
         +0x0ac PeakVirtualSize  : Uint4B
         +0x0b0 VirtualSize      : Uint4B
         +0x0b4 SessionProcessLinks : _LIST_ENTRY
         +0x0bc DebugPort        : Ptr32 Void
         +0x0c0 ExceptionPort    : Ptr32 Void
         +0x0c4 ObjectTable      : Ptr32 _HANDLE_TABLE
         +0x0c8 Token            : _EX_FAST_REF
         +0x0cc WorkingSetLock   : _FAST_MUTEX
         +0x0ec WorkingSetPage   : Uint4B
         +0x0f0 AddressCreationLock : _FAST_MUTEX
         +0x110 HyperSpaceLock   : Uint4B
         +0x114 ForkInProgress   : Ptr32 _ETHREAD
         +0x118 HardwareTrigger  : Uint4B
         +0x11c VadRoot          : Ptr32 Void
         +0x120 VadHint          : Ptr32 Void
         +0x124 CloneRoot        : Ptr32 Void
         +0x128 NumberOfPrivatePages : Uint4B
         +0x12c NumberOfLockedPages : Uint4B
         +0x130 Win32Process     : Ptr32 Void
         +0x134 Job              : Ptr32 _EJOB
         +0x138 SectionObject    : Ptr32 Void
         +0x13c SectionBaseAddress : Ptr32 Void
         +0x140 QuotaBlock       : Ptr32 _EPROCESS_QUOTA_BLOCK
         +0x144 WorkingSetWatch  : Ptr32 _PAGEFAULT_HISTORY
         +0x148 Win32WindowStation : Ptr32 Void
         +0x14c InheritedFromUniqueProcessId : Ptr32 Void
         +0x150 LdtInformation   : Ptr32 Void
         +0x154 VadFreeHint      : Ptr32 Void
         +0x158 VdmObjects       : Ptr32 Void
         +0x15c DeviceMap        : Ptr32 Void
         +0x160 PhysicalVadList  : _LIST_ENTRY
         +0x168 PageDirectoryPte : _HARDWARE_PTE
         +0x168 Filler           : Uint8B
         +0x170 Session          : Ptr32 Void
         +0x174 ImageFileName    : [16] UChar
         +0x184 JobLinks         : _LIST_ENTRY
         +0x18c LockedPagesList  : Ptr32 Void
         +0x190 ThreadListHead   : _LIST_ENTRY
         +0x198 SecurityPort     : Ptr32 Void
         +0x19c PaeTop           : Ptr32 Void
         +0x1a0 ActiveThreads    : Uint4B
         +0x1a4 GrantedAccess    : Uint4B
         +0x1a8 DefaultHardErrorProcessing : Uint4B
         +0x1ac LastThreadExitStatus : Int4B
         +0x1b0 Peb              : Ptr32 _PEB
         +0x1b4 PrefetchTrace    : _EX_FAST_REF
         +0x1b8 ReadOperationCount : _LARGE_INTEGER
         +0x1c0 WriteOperationCount : _LARGE_INTEGER
         +0x1c8 OtherOperationCount : _LARGE_INTEGER
         +0x1d0 ReadTransferCount : _LARGE_INTEGER
         +0x1d8 WriteTransferCount : _LARGE_INTEGER
         +0x1e0 OtherTransferCount : _LARGE_INTEGER
         +0x1e8 CommitChargeLimit : Uint4B
         +0x1ec CommitChargePeak : Uint4B
         +0x1f0 AweInfo          : Ptr32 Void
         +0x1f4 SeAuditProcessCreationInfo : _SE_AUDIT_PROCESS_CREATION_INFO
         +0x1f8 Vm               : _MMSUPPORT
         +0x238 LastFaultCount   : Uint4B
         +0x23c ModifiedPageCount : Uint4B
         +0x240 NumberOfVads     : Uint4B
         +0x244 JobStatus        : Uint4B
         +0x248 Flags            : Uint4B
         +0x248 CreateReported   : Pos 0, 1 Bit
         +0x248 NoDebugInherit   : Pos 1, 1 Bit
         +0x248 ProcessExiting   : Pos 2, 1 Bit
         +0x248 ProcessDelete    : Pos 3, 1 Bit
         +0x248 Wow64SplitPages  : Pos 4, 1 Bit
         +0x248 VmDeleted        : Pos 5, 1 Bit
         +0x248 OutswapEnabled   : Pos 6, 1 Bit
         +0x248 Outswapped       : Pos 7, 1 Bit
         +0x248 ForkFailed       : Pos 8, 1 Bit
         +0x248 HasPhysicalVad   : Pos 9, 1 Bit
         +0x248 AddressSpaceInitialized : Pos 10, 2 Bits
         +0x248 SetTimerResolution : Pos 12, 1 Bit
         +0x248 BreakOnTermination : Pos 13, 1 Bit
         +0x248 SessionCreationUnderway : Pos 14, 1 Bit
         +0x248 WriteWatch       : Pos 15, 1 Bit
         +0x248 ProcessInSession : Pos 16, 1 Bit
         +0x248 OverrideAddressSpace : Pos 17, 1 Bit
         +0x248 HasAddressSpace  : Pos 18, 1 Bit
         +0x248 LaunchPrefetched : Pos 19, 1 Bit
         +0x248 InjectInpageErrors : Pos 20, 1 Bit
         +0x248 VmTopDown        : Pos 21, 1 Bit
         +0x248 Unused3          : Pos 22, 1 Bit
         +0x248 Unused4          : Pos 23, 1 Bit
         +0x248 VdmAllowed       : Pos 24, 1 Bit
         +0x248 Unused           : Pos 25, 5 Bits
         +0x248 Unused1          : Pos 30, 1 Bit
         +0x248 Unused2          : Pos 31, 1 Bit
         +0x24c ExitStatus       : Int4B
         +0x250 NextPageColor    : Uint2B
         +0x252 SubSystemMinorVersion : UChar
         +0x253 SubSystemMajorVersion : UChar
         +0x252 SubSystemVersion : Uint2B
         +0x254 PriorityClass    : UChar
         +0x255 WorkingSetAcquiredUnsafe : UChar
         +0x258 Cookie           : Uint4B
      +0x00c MappedSystemVa   : Ptr32 Void
      +0x010 StartVa          : Ptr32 Void
      +0x014 ByteCount        : Uint4B
      +0x018 ByteOffset       : Uint4B
   +0x008 Flags            : Uint4B
   +0x00c AssociatedIrp    : __unnamed
      +0x000 MasterIrp        : Ptr32 _IRP
         +0x000 Type             : Int2B
         +0x002 Size             : Uint2B
         +0x004 MdlAddress       : Ptr32 _MDL
         +0x008 Flags            : Uint4B
         +0x00c AssociatedIrp    : __unnamed
         +0x010 ThreadListEntry  : _LIST_ENTRY
         +0x018 IoStatus         : _IO_STATUS_BLOCK
         +0x020 RequestorMode    : Char
         +0x021 PendingReturned  : UChar
         +0x022 StackCount       : Char
         +0x023 CurrentLocation  : Char
         +0x024 Cancel           : UChar
         +0x025 CancelIrql       : UChar
         +0x026 ApcEnvironment   : Char
         +0x027 AllocationFlags  : UChar
         +0x028 UserIosb         : Ptr32 _IO_STATUS_BLOCK
         +0x02c UserEvent        : Ptr32 _KEVENT
         +0x030 Overlay          : __unnamed
         +0x038 CancelRoutine    : Ptr32           void
         +0x03c UserBuffer       : Ptr32 Void
         +0x040 Tail             : __unnamed
      +0x000 IrpCount         : Int4B
      +0x000 SystemBuffer     : Ptr32 Void
   +0x010 ThreadListEntry  : _LIST_ENTRY
      +0x000 Flink            : Ptr32 _LIST_ENTRY
         +0x000 Flink            : Ptr32 _LIST_ENTRY
         +0x004 Blink            : Ptr32 _LIST_ENTRY
      +0x004 Blink            : Ptr32 _LIST_ENTRY
         +0x000 Flink            : Ptr32 _LIST_ENTRY
         +0x004 Blink            : Ptr32 _LIST_ENTRY
   +0x018 IoStatus         : _IO_STATUS_BLOCK
      +0x000 Status           : Int4B
      +0x000 Pointer          : Ptr32 Void
      +0x004 Information      : Uint4B
   +0x020 RequestorMode    : Char
   +0x021 PendingReturned  : UChar
   +0x022 StackCount       : Char
   +0x023 CurrentLocation  : Char
   +0x024 Cancel           : UChar
   +0x025 CancelIrql       : UChar
   +0x026 ApcEnvironment   : Char
   +0x027 AllocationFlags  : UChar
   +0x028 UserIosb         : Ptr32 _IO_STATUS_BLOCK
      +0x000 Status           : Int4B
      +0x000 Pointer          : Ptr32 Void
      +0x004 Information      : Uint4B
   +0x02c UserEvent        : Ptr32 _KEVENT
      +0x000 Header           : _DISPATCHER_HEADER
         +0x000 Type             : UChar
         +0x001 Absolute         : UChar
         +0x002 Size             : UChar
         +0x003 Inserted         : UChar
         +0x004 SignalState      : Int4B
         +0x008 WaitListHead     : _LIST_ENTRY
   +0x030 Overlay          : __unnamed
      +0x000 AsynchronousParameters : __unnamed
         +0x000 UserApcRoutine   : Ptr32           void
         +0x004 UserApcContext   : Ptr32 Void
      +0x000 AllocationSize   : _LARGE_INTEGER
         +0x000 LowPart          : Uint4B
         +0x004 HighPart         : Int4B
         +0x000 u                : __unnamed
         +0x000 QuadPart         : Int8B
   +0x038 CancelRoutine    : Ptr32     void
   +0x03c UserBuffer       : Ptr32 Void
   +0x040 Tail             : __unnamed
      +0x000 Overlay          : __unnamed
         +0x000 DeviceQueueEntry : _KDEVICE_QUEUE_ENTRY
         +0x000 DriverContext    : [4] Ptr32 Void
         +0x010 Thread           : Ptr32 _ETHREAD
         +0x014 AuxiliaryBuffer  : Ptr32 Char
         +0x018 ListEntry        : _LIST_ENTRY
         +0x020 CurrentStackLocation : Ptr32 _IO_STACK_LOCATION
         +0x020 PacketType       : Uint4B
         +0x024 OriginalFileObject : Ptr32 _FILE_OBJECT
      +0x000 Apc              : _KAPC
         +0x000 Type             : Int2B
         +0x002 Size             : Int2B
         +0x004 Spare0           : Uint4B
         +0x008 Thread           : Ptr32 _KTHREAD
         +0x00c ApcListEntry     : _LIST_ENTRY
         +0x014 KernelRoutine    : Ptr32           void
         +0x018 RundownRoutine   : Ptr32           void
         +0x01c NormalRoutine    : Ptr32           void
         +0x020 NormalContext    : Ptr32 Void
         +0x024 SystemArgument1  : Ptr32 Void
         +0x028 SystemArgument2  : Ptr32 Void
         +0x02c ApcStateIndex    : Char
         +0x02d ApcMode          : Char
         +0x02e Inserted         : UChar
      +0x000 CompletionKey    : Ptr32 Void

#define IoGetCurrentIrpStackLocation( Irp ) ( (Irp)->Tail.Overlay.CurrentStackLocation )
天天coding-debugging中----超稀饭memory dump file ======================================================== [b]Windows Device Driver Development and Consulting Service[/b] [color=blue][url]http://www.ybwork.com[/url][/color] ========================================================
kcynice
驱动牛犊
驱动牛犊
  • 注册日期2008-03-03
  • 最后登录2010-08-28
  • 粉丝1
  • 关注0
  • 积分43分
  • 威望138点
  • 贡献值0点
  • 好评度1点
  • 原创分0分
  • 专家分2分
地下室#
发布于:2008-09-18 17:07
谢谢,我知道我的问题出在什么地方了
destinyqq
驱动牛犊
驱动牛犊
  • 注册日期2006-09-18
  • 最后登录2013-01-29
  • 粉丝0
  • 关注0
  • 积分7分
  • 威望35点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
5楼#
发布于:2008-09-18 20:46
??  为什么呢?
游客

返回顶部