SysInternal的WinObj设备列表机制
SysInternals的WinObj可以列出所有设备对象。
我想知道它如何列出设备。
有没有我们可以阅读的开源代码?(或代码片段)
我应该知道的最重要的功能是什么?
SysInternals's WinObj can list all device objects.
I wonder how it can list the devices.
Is there any open source we can read?(or a code snippet)
What is the most significant function I should know?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
WinObj 使用 NT 系统调用
NtOpenDirectoryObject
和NtQueryDirectoryObject
。不需要驱动程序或内核代码。您不会看到导入,因为这些 NT 函数是通过LoadLibrary
/GetProcAddress
加载的。您不必枚举整个对象名称空间。如果您对设备对象感兴趣,请使用
"\Device"
调用NtOpenDirectoryObject
,然后在返回的句柄上调用NtQueryDirectoryObject
。WinObj uses the NT system calls
NtOpenDirectoryObject
andNtQueryDirectoryObject
. There is no driver or kernel code needed. You won't see the imports because these NT functions are loaded viaLoadLibrary
/GetProcAddress
.You don't have to enumerate the entire object namespace. If you're interested in the device objects call
NtOpenDirectoryObject
with"\Device"
, then callNtQueryDirectoryObject
on the returned handle.根据 user1575778 的回答,您可以使用
NtOpenDirectoryObject
和NtQueryDirectoryObject
(从用户模式分别与ZwOpenDirectoryObject
和ZwQueryDirectoryObject
相同)列出对象管理器命名空间内的对象。查看 NT 对象又名 ntobjx 的
objmgr.hpp
,特别是NtObjMgr::Directory
类(或DirectoryT
)。它提供了同样的功能,并且很好地封装到了 C++ 类中。整个实用程序是在自由许可下开源的(由于 WTL 使用而获得双重许可:MIT 和 MS-PL),因此只要您遵守许可条款,您就可以随意重复使用片段和片段。但这里有一个简单的 C++ 代码示例,只是满足您的用例:
一些备注:这不会深入到子目录,它不会 列出除
Device
之外的任何类型,并且它不会解析符号链接(如果有)。对于任何这些功能,请查看上述实用程序的源代码并根据需要进行调整。winternl.h
应该在任何最新的 Windows SDK 中可用。函数
RtlInitUnicodeString_
和NtClose_
后面有一个下划线,以避免与这些本机 API 函数发生冲突,这些函数在winternl.h
中声明,但使用 <代码>__declspec(dllimport)。披露:我是 ntobjx 的作者。
As per the answer from user1575778 you can use
NtOpenDirectoryObject
andNtQueryDirectoryObject
(which from user mode are identical toZwOpenDirectoryObject
andZwQueryDirectoryObject
respectively) to list the objects inside the object manager namespace.Have a look at
objmgr.hpp
of NT Objects aka ntobjx, in particular at the classNtObjMgr::Directory
(orDirectoryT
). It provides the same functionality nicely wrapped into a C++ class. The whole utility is open source under a liberal license (dual-licensed due to WTL-use: MIT and MS-PL), so bits and pieces can be reused however you please, provided you comply with the license terms.But here's a simple C++ code example catering just your use case:
Some remarks: This will not delve into subdirectories, it will not list any types other than
Device
and it will not resolve symbolic links, if any. For any of those features, please look at the aforementioned utility's source code and adjust as needed.winternl.h
should be available in any recent Windows SDK.The functions
RtlInitUnicodeString_
andNtClose_
have a trailing underscore to avoid clashes with these native API functions, which are declared inwinternl.h
, but use__declspec(dllimport)
.Disclosure: I am the author of ntobjx.
根据 SysInternals 网页:
我尝试查看 WinObj 的导入表 (
dumpbin /imports winobj.exe
),但没有明显的嫌疑:-(According to SysInternals' web page:
I've tried looking at WinObj's import table (
dumpbin /imports winobj.exe
) but there are no obvious suspects :-(您可以使用 NtOpenDirectoryObject 和 NtQueryDirectoryObject 枚举给定目录中的对象列表。
You can use NtOpenDirectoryObject and NtQueryDirectoryObject to enumarate the objects list in a given directory.
要获取对象命名空间的详细信息,必须使用 Windows NT 未记录的 API。正如它所描述的那样,WinObj 也使用它 此处说明了 WinOBj 如何获取所有结果。对于那些说我们需要驱动程序来执行此操作的人,请阅读给定页面上的这些行。
To get the details of the object namespace, you must use the Windows NT Undocumented API. That is also used by the WinObj as it is described here that how WinOBj getting the all results..and for those who are saying that we need a driver to do this please, read these lines on given page.
您可以从SetupDiCreateDeviceInfoList开始并使用其他相关函数来枚举所有设备。这东西用起来很痛苦。
You can start with SetupDiCreateDeviceInfoList and use other related functions to enumerate all the devices. This stuff is painful to use.