-
-
[原创]WIN8句柄表枚举
-
发表于:
2012-11-17 09:34
5489
-
win8以前回调的定义:
typedef BOOLEAN (*EX_ENUMERATE_HANDLE_ROUTINE)(
IN PHANDLE_TABLE_ENTRY HandleTableEntry,
IN HANDLE Handle,
IN PVOID EnumParameter
);
而win8接受的定义为
BOOLEAN SYSCOMIC::ProcessEnumeraterEx(
IN PHANDLE_TABLE HandleTable,
IN PHANDLE_TABLE_ENTRY HandleTableEntry,
IN HANDLE Handle,
IN PVOID EnumParameter
);
变4参数了,调用时我是这样的:
if( (m_nMajorVersion == 6) && (m_nMinorVersion > 1) ) {
TsRtlEnumHandleTable(m_pSystemCidTable, (EX_ENUMERATE_HANDLE_ROUTINE) SYSCOMIC::ProcessEnumeraterEx, EnumProcessContext, &LastHandle);
} else {
TsRtlEnumHandleTable(m_pSystemCidTable, SYSCOMIC::ProcessEnumerater, EnumProcessContext, &LastHandle);
}
TsrtlEnumHandleTable是我自己山寨的,其实就等同于系统的EnumHandleTable,请大家无视..
win8下强制转换下回调类型. 不会死人的~
关键部分在回调的结束部分,
BOOLEAN SYSCOMIC::ProcessEnumeraterEx(
IN PHANDLE_TABLE HandleTable,
IN PHANDLE_TABLE_ENTRY HandleTableEntry,
IN HANDLE Handle,
IN PVOID EnumParameter
)
{
POBJECT_TYPE ObjectType ;
LONG_PTR ObjectData = (LONG_PTR) HandleTableEntry->Object;
ULONG_PTR Object;
#ifdef AMD64
Object = (ULONG_PTR) (ObjectData >> 0x13);
#endif
Object = (Object & ~OBJ_HANDLE_ATTRIBUTES);
ObjectType = (POBJECT_TYPE) TsRtlGetNewObjectType( (PVOID) Object);
g_pSysData->SysComic->ProcessEnumeraterCall( (PVOID) Object,
Handle,
ObjectType,
(PENUM_PROCESS_CONTEXT) EnumParameter
);
if(g_pSysData->SysComic->ExUnlockPushLock) {
PEXP_PUSH_LOCK PushLocker = (PEXP_PUSH_LOCK) &HandleTable->HandleTableLock[3];
LONG_PTR OldValue;
#if defined (_WIN64)
OldValue = InterlockedExchangeAdd64 ((PLONGLONG) &HandleTableEntry->Value, EXHANDLE_TABLE_ENTRY_LOCK_BIT);
#else
OldValue = InterlockedOr ((LONG *) &HandleTableEntry->Value, EXHANDLE_TABLE_ENTRY_LOCK_BIT);
#endif
if((OldValue&EXHANDLE_TABLE_ENTRY_LOCK_BIT))
{
g_pSysData->SysComic->ExUnlockPushLock( PushLocker, NULL);
}
//if(PushLocker->Locked) {
// KernelHandles->ExUnlockPushLock( PushLocker, NULL);
//}
}
return FALSE;
}
WIN8句柄表的 PHANDLE_TABLE_ENTRY增加了新的成员,大家可以dt看下>>13的具体含义
if(g_pSysData->SysComic->ExUnlockPushLock) 起是为了给句柄表解索而新增加的
OldValue解除锁定标志
ExUnlockPushLock根据Oldvaule来决定要不要解锁HandleTable
下面这句是这样的, 结构体定义与win8有区别,所以[3]的位置偏移刚好是锁
PEXP_PUSH_LOCK PushLocker = (PEXP_PUSH_LOCK) &HandleTable->HandleTableLock[3];
这个函数是仅在win8中使用
[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课