NtQueryObject 函数

本文详细介绍了Windows API中的NtQueryObject函数,包括其参数、返回值和相关结构体。该函数用于获取对象的各种信息,如基本信息、名称、类型等。注意,微软可能在未来更改或移除该函数,且不会提前通知。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

若翻译出现错误,请指出,本人会即时改正。

这个函数未来可能会改变或者从windows中移除,但是不会通告你。(微软有多贱,我嘞个草了)

函数声明:

NTSTATUS NtQueryObject(

_In_opt_  HANDLE  Handle,

_In_        OBJECT_INFORMATION_CLASS objectInformationClass,

_Out_opt_ PVOID   ObjectInformation,

_In_ ULONG ObjectInformationLength,

_Out_opt_ PULONG ReturnLength

);

参数:

Handle  [IN]

需要查询信息对象的句柄,可以为NULL

ObjectInformationClass [IN]

下列枚举类型中的某个值,指出被索引对象的类型。

typedef enum _OBJECT_INFORMATION_CLASS{

ObjectBasicInformation,  

ObjectNameInformation,

ObjectTypeInformation,

ObjectAllInformation,

ObjectDataInformation

}OBJECT_INFORMATION_CALSS,*POBJECT_INFORMATION_CLASS;

ObjectInformation[out]

指向存放返回信息缓冲区的指针。大小和信息存放格式依赖于ObjectInformationClass参数。

ObjectBasicInformation 对应结构为:OBJECT_BASIC_INFORMATION

ObjectNameInformation 对应结构为:OBJECT_NAME_INFORMATION

ObjectTypeInformation  对应结构为:OBJECT_TYPE_INFORMATION

ObjectAllInformation  对应结构为:   OBJECT_ALL_INFORMATION

ObjectDataInformation对应结构为:  OBJECT_DATA_INFORMATION

具体结构体细节,请参考链接:

http://undocumented.ntinternals.net/index.html?page=UserMode%2FUndocumented%20Functions%2FNT%20Objects%2FType%20independed%2FNtQueryObject.html

ObjectInformationLength [IN]

ObjectInformation参数的字节大小

ReturnLength[out]

返回信息需要空间的大小。如果此值小于或等于ObjectInformationLength的值,函数将信息复制到缓冲区中,否则函数返回NTSTATUS错误码,并将信息需要的字节数放入ReturnLength中。

返回值:

返回NTSTATUS或错误码

NTSTATUS的格式和意义在WDK的Ntstatus.h中列出,并在WDK文档中被形容。

参考原文链接:

链接一:

https://msdn.microsoft.com/en-us/library/bb432383(v=vs.85).aspx

链接二:

http://undocumented.ntinternals.net/index.html?page=UserMode%2FUndocumented%20Functions%2FNT%20Objects%2FType%20independed%2FNtQueryObject.html


前言 上一次发布过的程序:【首发】检测文件的占用,具有学习和商业价值(By超级用户),可以使用,仿电脑管家 正文 对于怎么枚举文件句柄 ,上一帖子对此有介绍,核心代码大概如下:如果 (ZwQueryObject (handle, #ObjectTypeInformation, unicode, 0, size) ≠ #STATUS_INVALID_HANDLE )' 只要不是无效的,为什么,详细看下面的注释 ' 参数 ' Handle ' 对象的一个句柄来获取信息。 ' ObjectInformationClass ' 指定一个OBJECT_INFORMATION_CLASS返回值的类型决定了信息在ObjectInformation缓冲区。 ' ObjectInformation ' 一个指向caller-allocated缓冲接收请求的信息。 ' ObjectInformationLength ' 指定的大小,以字节为单位,ObjectInformation缓冲区。 ' ReturnLength ' 一个指向变量的指针,接收的大小,以字节为单位,请求的关键信息。如果NtQueryObject STATUS_SUCCESS返回,返回的变量包含的数据量。如果NtQueryObject返回STATUS_BUFFER_OVERFLOW或STATUS_BUFFER_TOO_SMALL,您可以使用变量的值来确定所需的缓冲区大小。 ' 返回值 ' NtQueryObject返回STATUS_SUCCESS或适当的错误状态。可能的错误状态码包括以下: ' 返回代码 描述 ' STATUS_ACCESS_DENIED ' 有足够的权限来执行该cha询。 ' STATUS_INVALID_HANDLE ' 提供对象句柄无效。 ' STATUS_INFO_LENGTH_MISMATCH ' 信息长度不足以容纳数据。 unicode = 取空白字节集 (size) ZwQueryObject (handle, #ObjectTypeInformation, unicode, size, 0)' 读取信息的unicode文本 RtlUnicodeStringToAnsiString (ansi, unicode, 真)' 编码转换 ' RtlUnicodeStringToAnsiString例程将给定Unicode字符串转换成一个ANSI字符串。 str = 指针到文本 (ansi.Buffer) ' RtlFreeAnsiString常规版本存储由RtlUnicodeStringToAnsiString分配。 ' 参数 ' AnsiString ' 指针ANSI字符串缓冲区由RtlUnicodeStringToAnsiString以前分配的。 RtlFreeAnsiString (ansi) str = “无法获取”' 无效的怎么获取…… 返回 (str) 这一次呢更新了一个RemoteCloseHandle ,大概的原理是什么呢? 同时也采用了一些比较骚的方法,这种方法的限制较多,但是对于32位进程就很有效果。 NtClose在MSDN的大概介绍 1. NtClose is a generic routine that operates on any type of object. 2. Closing an open object handle causes that handle to become invalid. The system also decrements the handle count for the object and checks whether the object can be deleted. The system does not actually delete the object until all of the object's handles are closed and no referenced pointers remain. 3. A driver must close every handle that it opens as soon as the handle is no longer required. Kernel handles, which are those that are opened by a system thread or by specifying the OBJ_KERNEL_HANDLE flag, can be closed only when the previous processor mo
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值