对象OBJECT_HEADER的引用计数
			 2024-01-16
			  46
			 0
			
			
			
				
			
			
		
			Windows内核的任意一对象的头部必为OBJECT_HEADER。通过Windbg可以看到该结构体的数据结构体为:
3: kd> dt _OBJECT_HEADER
nt!_OBJECT_HEADER
   +0x000 PointerCount     : Int8B
   +0x008 HandleCount      : Int8B
   +0x008 NextToFree       : Ptr64 Void
   +0x010 Lock             : _EX_PUSH_LOCK
   +0x018 TypeIndex        : UChar
   +0x019 TraceFlags       : UChar
   +0x019 DbgRefTrace      : Pos 0, 1 Bit
   +0x019 DbgTracePermanent : Pos 1, 1 Bit
   +0x01a InfoMask         : UChar
   +0x01b Flags            : UChar
   +0x01b NewObject        : Pos 0, 1 Bit
   +0x01b KernelObject     : Pos 1, 1 Bit
   +0x01b KernelOnlyAccess : Pos 2, 1 Bit
   +0x01b ExclusiveObject  : Pos 3, 1 Bit
   +0x01b PermanentObject  : Pos 4, 1 Bit
   +0x01b DefaultSecurityQuota : Pos 5, 1 Bit
   +0x01b SingleHandleEntry : Pos 6, 1 Bit
   +0x01b DeletedInline    : Pos 7, 1 Bit
   +0x01c Reserved         : Uint4B
   +0x020 ObjectCreateInfo : Ptr64 _OBJECT_CREATE_INFORMATION
   +0x020 QuotaBlockCharged : Ptr64 Void
   +0x028 SecurityDescriptor : Ptr64 Void
   +0x030 Body             : _QUAD
在该结构体中,存在两个成员PointerCount和HandleCount。
- PointerCount是对象真正的引用计数,该计数包含了内核和应用层对该对象的引用计数之和。
 - HandleCount是句柄引用计数,只是保存了应用层对该内核对象的引用计数。
所以PointerCount-HandleCount的值就是内核对该对象的引用计数。 
在内核中,通过ObReferenceOjbetHandle函数只增加PointerCount的计数,而不更改HandleCount的计数。
			Windows驱动笔记
			




