-
Notifications
You must be signed in to change notification settings - Fork 1
/
object_util.cpp
99 lines (77 loc) · 2.13 KB
/
object_util.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*++
Copyright (c) 2019 changeofpace. All rights reserved.
Use of this source code is governed by the MIT license. See the 'LICENSE' file
for more information.
--*/
#include "object_util.h"
#include "log.h"
#include "nt.h"
_Use_decl_annotations_
EXTERN_C
NTSTATUS
ObuQueryNameString(
PVOID pObject,
POBJECT_NAME_INFORMATION* ppObjectNameInfo
)
/*++
Routine Description:
This function is a convenience wrapper for ObQueryNameString.
Parameters:
pObject - Pointer to the object to be queried.
ppObjectNameInfo - Returns a pointer to an allocated buffer for the object
name information for the specified object. If the object is unnamed
then the unicode string object in the returned buffer is zeroed. The
buffer is allocated from the NonPaged pool.
Remarks:
If successful, the caller must free the returned object name information
buffer by calling ExFreePool.
--*/
{
POBJECT_NAME_INFORMATION pObjectNameInfo = NULL;
ULONG cbReturnLength = 0;
NTSTATUS ntstatus = STATUS_SUCCESS;
//
// Zero out parameters.
//
*ppObjectNameInfo = NULL;
ntstatus = ObQueryNameString(pObject, NULL, 0, &cbReturnLength);
if (STATUS_INFO_LENGTH_MISMATCH != ntstatus)
{
ERR_PRINT("ObQueryNameString failed: 0x%X (Unexpected)", ntstatus);
ntstatus = STATUS_UNSUCCESSFUL;
goto exit;
}
pObjectNameInfo = (POBJECT_NAME_INFORMATION)ExAllocatePool(
NonPagedPool,
cbReturnLength);
if (!pObjectNameInfo)
{
ntstatus = STATUS_INSUFFICIENT_RESOURCES;
goto exit;
}
//
RtlSecureZeroMemory(pObjectNameInfo, cbReturnLength);
ntstatus = ObQueryNameString(
pObject,
pObjectNameInfo,
cbReturnLength,
&cbReturnLength);
if (!NT_SUCCESS(ntstatus))
{
ERR_PRINT("ObQueryNameString failed: 0x%X", ntstatus);
goto exit;
}
//
// Set out parameters.
//
*ppObjectNameInfo = pObjectNameInfo;
exit:
if (!NT_SUCCESS(ntstatus))
{
if (pObjectNameInfo)
{
ExFreePool(pObjectNameInfo);
}
}
return ntstatus;
}