1

Sysinternals 的 Process Explorer 显示进程持有的所有句柄,包括对象名称、类型、地址和句柄值等字段。例如:

https://i.stack.imgur.com/hlUQI.png

ETW 的NT Kernel Logger跟踪会话具有用于句柄操作的事件,语法如下:

class ObHandleEvent : ObTrace
{
  uint32 Handle;
  uint32 Object;
  string ObjectName;
  uint16 ObjectType;
};

我的问题是:ETW 中的 ObjectType 是一个 16 位整数。如何将整型 ObjectType 值映射到对应的对象类型名称(如 Process Explorer 中所示)?

4

1 回答 1

0

我认为内核对象类型是您所追求的。使用以下命令在内核调试器或 livekd 中签出

0: kd> !object \ObjectTypes
Object: ffffe589f9c17aa0  Type: (ffffb28572cd3820) Directory
    ObjectHeader: ffffe589f9c17a70 (new version)
    HandleCount: 0 PointerCount: 68
    Directory Object: ffffe589f9c14a60  Name: ObjectTypes

    Hash Address          Type                      Name
    ---- -------          ----                      ----
     00  ffffb28572d7e180 Type                      TmTm
     01  ffffb28572d76310 Type                      Desktop
         ffffb28572c3e680 Type                      Process
     02  ffffb28572d53ad0 Type                      EnergyTracker
         ffffb28572d5cbb0 Type                      RegistryTransaction
     03  ffffb28572cccc60 Type                      DebugObject
     04  ffffb28575682520 Type                      VRegConfigurationContext
         ffffb28572ccc440 Type                      TpWorkerFactory
     05  ffffb28572d6da20 Type                      Adapter
         ffffb28572ccfc40 Type                      Token
     06  ffffb2857562ebb0 Type                      DxgkSharedResource
     07  ffffb28572ccb560 Type                      PsSiloContextPaged
     ....

然后你可以转储对象头

0: kd> dt nt!_OBJECT_TYPE ffffb28572d68e80
   +0x000 TypeList         : _LIST_ENTRY [ 0xffffb285`72d68e80 - 0xffffb285`72d68e80 ]
   +0x010 Name             : _UNICODE_STRING "Section"
   +0x020 DefaultObject    : 0xfffff801`a03c4680 Void
   **+0x028 Index            : 0x29 ')'**
   +0x02c TotalNumberOfObjects : 0x4943
   +0x030 TotalNumberOfHandles : 0xf50
   +0x034 HighWaterNumberOfObjects : 0x4ccc
   +0x038 HighWaterNumberOfHandles : 0x10c3
   +0x040 TypeInfo         : _OBJECT_TYPE_INITIALIZER
   +0x0b8 TypeLock         : _EX_PUSH_LOCK
   +0x0c0 Key              : 0x74636553
   +0x0c8 CallbackList     : _LIST_ENTRY [ 0xffffb285`72d68f48 - 0xffffb285`72d68f48 ]

Index 字段应与相应的 ETW 事件相关。我不确定这个索引在 Windows 版本之间是否保持不变,但我认为不是。

Process Hacker(更好的进程浏览器)使用以下方法格式化对象类型:

static VOID PhpDumpObjectInfo(
    _In_ PPH_OBJECT_HEADER ObjectHeader
    )
{
    PVOID object;
    PPH_OBJECT_TYPE objectType;

    object = PhObjectHeaderToObject(ObjectHeader);
    objectType = PhGetObjectType(object);

    __try
    {
        wprintf(L"Type: %s\n", objectType->Name);
        wprintf(L"Reference count: %d\n", ObjectHeader->RefCount);
        wprintf(L"Flags: %x\n", ObjectHeader->Flags);

        if (objectType == PhObjectTypeObject)
        {
            wprintf(L"Name: %s\n", ((PPH_OBJECT_TYPE)object)->Name);
            wprintf(L"Number of objects: %u\n", ((PPH_OBJECT_TYPE)object)->NumberOfObjects);
            wprintf(L"Flags: %u\n", ((PPH_OBJECT_TYPE)object)->Flags);
            wprintf(L"Type index: %u\n", ((PPH_OBJECT_TYPE)object)->TypeIndex);
            wprintf(L"Free list count: %u\n", ((PPH_OBJECT_TYPE)object)->FreeList.Count);
        }
        else if (objectType == PhStringType)
        {
            wprintf(L"%s\n", ((PPH_STRING)object)->Buffer);
        }

这应该会给你一些指示下一步该往哪里看。

于 2018-12-11T18:55:36.517 回答