ReactOS  0.4.15-dev-1148-g8a4273b
ntobjenum.cpp File Reference
#include "precomp.h"
#include <strsafe.h>
Include dependency graph for ntobjenum.cpp:

Go to the source code of this file.

Classes

struct  RootKeyEntry
 
class  CEnumRegRoot
 
class  CEnumRegKey
 
class  CEnumNTDirectory
 

Macros

#define MAX_EMBEDDED_DATA   32
 

Typedefs

typedef NTSTATUS(__stdcallpfnNtGenericOpen) (PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES)
 
typedef NTSTATUS(__stdcallpfnNtOpenFile) (PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES, PIO_STATUS_BLOCK, ULONG, ULONG)
 

Functions

static DWORD NtOpenObject (OBJECT_TYPE type, PHANDLE phandle, DWORD access, LPCWSTR path)
 
OBJECT_TYPE MapTypeNameToType (LPCWSTR TypeName, DWORD cbTypeName)
 
HRESULT ReadRegistryValue (HKEY root, PCWSTR path, PCWSTR valueName, PVOID *valueData, PDWORD valueLength)
 
HRESULT GetNTObjectSymbolicLinkTarget (LPCWSTR path, LPCWSTR entryName, PUNICODE_STRING LinkTarget)
 
HRESULT GetEnumRegistryRoot (IEnumIDList **ppil)
 
HRESULT GetEnumRegistryKey (LPCWSTR path, HKEY root, IEnumIDList **ppil)
 
HRESULT GetEnumNTDirectory (LPCWSTR path, IEnumIDList **ppil)
 

Variables

static struct RootKeyEntry RootKeys []
 
const LPCWSTR ObjectTypeNames []
 
const LPCWSTR RegistryTypeNames []
 

Macro Definition Documentation

◆ MAX_EMBEDDED_DATA

#define MAX_EMBEDDED_DATA   32

Typedef Documentation

◆ pfnNtGenericOpen

typedef NTSTATUS(__stdcall* pfnNtGenericOpen) (PHANDLE, ACCESS_MASK, POBJECT_ATTRIBUTES)

Definition at line 33 of file ntobjenum.cpp.

◆ pfnNtOpenFile

Definition at line 34 of file ntobjenum.cpp.

Function Documentation

◆ GetEnumNTDirectory()

HRESULT GetEnumNTDirectory ( LPCWSTR  path,
IEnumIDList **  ppil 
)

Definition at line 748 of file ntobjenum.cpp.

749 {
750  return ShellObjectCreatorInit<CEnumNTDirectory>(path, IID_PPV_ARG(IEnumIDList, ppil));
751 }
#define IID_PPV_ARG(Itype, ppType)

Referenced by CNtObjectFolder::EnumObjects().

◆ GetEnumRegistryKey()

HRESULT GetEnumRegistryKey ( LPCWSTR  path,
HKEY  root,
IEnumIDList **  ppil 
)

Definition at line 743 of file ntobjenum.cpp.

744 {
745  return ShellObjectCreatorInit<CEnumRegKey>(path, root, IID_PPV_ARG(IEnumIDList, ppil));
746 }
#define IID_PPV_ARG(Itype, ppType)

Referenced by CRegistryFolder::EnumObjects().

◆ GetEnumRegistryRoot()

HRESULT GetEnumRegistryRoot ( IEnumIDList **  ppil)

Definition at line 738 of file ntobjenum.cpp.

739 {
740  return ShellObjectCreator<CEnumRegRoot>(IID_PPV_ARG(IEnumIDList, ppil));
741 }
#define IID_PPV_ARG(Itype, ppType)

Referenced by CRegistryFolder::EnumObjects().

◆ GetNTObjectSymbolicLinkTarget()

HRESULT GetNTObjectSymbolicLinkTarget ( LPCWSTR  path,
LPCWSTR  entryName,
PUNICODE_STRING  LinkTarget 
)

Definition at line 162 of file ntobjenum.cpp.

163 {
164  HANDLE handle;
166  LPWSTR pend = buffer;
167 
168  StringCbCopyExW(buffer, sizeof(buffer), path, &pend, NULL, 0);
169 
170  if (pend[-1] != '\\')
171  {
172  *pend++ = '\\';
173  *pend = 0;
174  }
175 
176  StringCbCatW(buffer, sizeof(buffer), entryName);
177 
178  DbgPrint("GetNTObjectSymbolicLinkTarget %d\n", buffer);
179 
180  LinkTarget->Length = 0;
181 
183  if (!NT_SUCCESS(err))
184  return HRESULT_FROM_NT(err);
185 
187  if (!NT_SUCCESS(err))
188  return HRESULT_FROM_NT(err);
189 
190  NtClose(handle);
191 
192  return S_OK;
193 }
namespace GUID const ADDRINFOEXW ADDRINFOEXW struct timeval OVERLAPPED LPLOOKUPSERVICE_COMPLETION_ROUTINE HANDLE * handle
Definition: sock.c:82
#define DbgPrint
Definition: loader.c:25
GLuint buffer
Definition: glext.h:5915
STRSAFEAPI StringCbCatW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:342
STRSAFEAPI StringCbCopyExW(STRSAFE_LPWSTR pszDest, size_t cbDest, STRSAFE_LPCWSTR pszSrc, STRSAFE_LPWSTR *ppszDestEnd, size_t *pcbRemaining, STRSAFE_DWORD dwFlags)
Definition: strsafe.h:210
_Inout_ PUNICODE_STRING LinkTarget
Definition: zwfuncs.h:292
smooth NULL
Definition: ftsmooth.c:416
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define HRESULT_FROM_NT(x)
Definition: winerror.h:94
#define MAX_PATH
Definition: compat.h:34
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
#define err(...)
#define S_OK
Definition: intsafe.h:51
#define SYMBOLIC_LINK_QUERY
Definition: nt_native.h:1265
WCHAR * LPWSTR
Definition: xmlstorage.h:184
static DWORD NtOpenObject(OBJECT_TYPE type, PHANDLE phandle, DWORD access, LPCWSTR path)
Definition: ntobjenum.cpp:61

Referenced by CNtObjectFolder::GetDetailsEx(), CNtObjectFolder::GetDetailsOf(), and CNtObjectFolder::ResolveSymLink().

◆ MapTypeNameToType()

OBJECT_TYPE MapTypeNameToType ( LPCWSTR  TypeName,
DWORD  cbTypeName 
)

Definition at line 92 of file ntobjenum.cpp.

93 {
94  if (!TypeName)
95  return UNKNOWN_OBJECT_TYPE;
96 
97  for (UINT i = 0; i < _countof(ObjectTypeNames); i++)
98  {
99  LPCWSTR typeName = ObjectTypeNames[i];
100  if (!StrCmpNW(typeName, TypeName, cbTypeName / sizeof(WCHAR)))
101  {
102  return (OBJECT_TYPE) i;
103  }
104  }
105 
106  return UNKNOWN_OBJECT_TYPE;
107 }
INT WINAPI StrCmpNW(LPCWSTR lpszStr, LPCWSTR lpszComp, INT iLen)
Definition: string.c:504
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
const LPCWSTR ObjectTypeNames[]
Definition: ntobjenum.cpp:36
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
OBJECT_TYPE
Definition: ntobjenum.h:23
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define _countof(array)
Definition: sndvol32.h:68
unsigned int UINT
Definition: ndis.h:50

Referenced by CEnumNTDirectory::EnumerateNext().

◆ NtOpenObject()

static DWORD NtOpenObject ( OBJECT_TYPE  type,
PHANDLE  phandle,
DWORD  access,
LPCWSTR  path 
)
static

Definition at line 61 of file ntobjenum.cpp.

62 {
63  UNICODE_STRING ustr;
64 
65  RtlInitUnicodeString(&ustr, path);
66 
67  OBJECT_ATTRIBUTES open_struct = { sizeof(OBJECT_ATTRIBUTES), 0x00, &ustr, 0x40 };
68 
69  if (type != FILE_OBJECT)
71 
72  IO_STATUS_BLOCK ioStatusBlock;
73 
74  switch (type)
75  {
76  case DIRECTORY_OBJECT: return NtOpenDirectoryObject(phandle, access, &open_struct);
77  case SYMBOLICLINK_OBJECT: return NtOpenSymbolicLinkObject(phandle, access, &open_struct);
78  case MUTANT_OBJECT: return NtOpenMutant(phandle, access, &open_struct);
79  case SECTION_OBJECT: return NtOpenSection(phandle, access, &open_struct);
80  case EVENT_OBJECT: return NtOpenEvent(phandle, access, &open_struct);
81  case SEMAPHORE_OBJECT: return NtOpenSemaphore(phandle, access, &open_struct);
82  case TIMER_OBJECT: return NtOpenTimer(phandle, access, &open_struct);
83  case KEY_OBJECT: return NtOpenKey(phandle, access, &open_struct);
84  case EVENTPAIR_OBJECT: return NtOpenEventPair(phandle, access, &open_struct);
85  case IOCOMPLETION_OBJECT: return NtOpenIoCompletion(phandle, access, &open_struct);
86  case FILE_OBJECT: return NtOpenFile(phandle, access, &open_struct, &ioStatusBlock, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 0);
87  default:
89  }
90 }
NTSTATUS NTAPI NtOpenIoCompletion(OUT PHANDLE IoCompletionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: iocomp.c:326
#define ERROR_INVALID_FUNCTION
Definition: dderror.h:6
NTSTATUS NTAPI NtOpenDirectoryObject(OUT PHANDLE DirectoryHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: obdir.c:401
struct _SECTION_OBJECT SECTION_OBJECT
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:136
NTSTATUS NTAPI NtOpenTimer(OUT PHANDLE TimerHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: timer.c:463
NTSTATUS NTAPI NtOpenEventPair(OUT PHANDLE EventPairHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: evtpair.c:140
NTSTATUS NTAPI NtOpenSection(OUT PHANDLE SectionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: section.c:3501
struct _OBJECT_ATTRIBUTES OBJECT_ATTRIBUTES
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3951
NTSTATUS NTAPI NtOpenSemaphore(OUT PHANDLE SemaphoreHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: sem.c:161
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define STANDARD_RIGHTS_READ
Definition: nt_native.h:65
NTSTATUS NTAPI NtOpenEvent(OUT PHANDLE EventHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: event.c:185
GLuint GLint GLboolean GLint GLenum access
Definition: glext.h:7866
NTSTATUS NTAPI NtOpenMutant(OUT PHANDLE MutantHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: mutant.c:166
NTSYSAPI NTSTATUS NTAPI NtOpenKey(OUT PHANDLE KeyHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes)
Definition: ntapi.c:336
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)

Referenced by GetNTObjectSymbolicLinkTarget(), CEnumRegKey::Initialize(), CEnumNTDirectory::Initialize(), and ReadRegistryValue().

◆ ReadRegistryValue()

HRESULT ReadRegistryValue ( HKEY  root,
PCWSTR  path,
PCWSTR  valueName,
PVOID valueData,
PDWORD  valueLength 
)

Definition at line 109 of file ntobjenum.cpp.

110 {
111  HKEY hkey;
112 
113  DWORD res;
114  if (root)
115  {
116  res = RegOpenKeyExW(root, *path == '\\' ? path + 1 : path, 0, STANDARD_RIGHTS_READ | KEY_QUERY_VALUE, &hkey);
117  }
118  else
119  {
121  }
122  if (!NT_SUCCESS(res))
123  {
124  ERR("RegOpenKeyExW failed for path %S with status=%x\n", path, res);
125  return HRESULT_FROM_NT(res);
126  }
127 
128  res = RegQueryValueExW(hkey, valueName, NULL, NULL, NULL, valueLength);
129  if (!NT_SUCCESS(res))
130  {
131  ERR("RegQueryValueExW failed for path %S with status=%x\n", path, res);
132  return HRESULT_FROM_NT(res);
133  }
134 
135  if (*valueLength > 0)
136  {
137  PBYTE data = (PBYTE) CoTaskMemAlloc(*valueLength);
138  *valueData = data;
139 
140  res = RegQueryValueExW(hkey, valueName, NULL, NULL, data, valueLength);
141  if (!NT_SUCCESS(res))
142  {
144  *valueData = NULL;
145 
146  RegCloseKey(hkey);
147 
148  ERR("RegOpenKeyExW failed for path %S with status=%x\n", path, res);
149  return HRESULT_FROM_NT(res);
150  }
151  }
152  else
153  {
154  *valueData = NULL;
155  }
156 
157  RegCloseKey(hkey);
158 
159  return S_OK;
160 }
VOID WINAPI CoTaskMemFree(LPVOID ptr)
Definition: ifs.c:442
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define HRESULT_FROM_NT(x)
Definition: winerror.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:454
#define STANDARD_RIGHTS_READ
Definition: nt_native.h:65
#define ERR(fmt,...)
Definition: debug.h:110
#define S_OK
Definition: intsafe.h:51
#define KEY_QUERY_VALUE
Definition: nt_native.h:1016
GLuint res
Definition: glext.h:9613
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
static DWORD NtOpenObject(OBJECT_TYPE type, PHANDLE phandle, DWORD access, LPCWSTR path)
Definition: ntobjenum.cpp:61
BYTE * PBYTE
Definition: pedump.c:66
LPVOID WINAPI CoTaskMemAlloc(SIZE_T size)
Definition: ifs.c:426

Variable Documentation

◆ ObjectTypeNames

const LPCWSTR ObjectTypeNames[]
Initial value:
= {
L"Directory", L"SymbolicLink",
L"Mutant", L"Section", L"Event", L"Semaphore",
L"Timer", L"Key", L"EventPair", L"IoCompletion",
L"Device", L"File", L"Controller", L"Profile",
L"Type", L"Desktop", L"WindowStation", L"Driver",
L"Token", L"Process", L"Thread", L"Adapter", L"Port",
0
}
static const WCHAR L[]
Definition: oid.c:1250

Definition at line 36 of file ntobjenum.cpp.

Referenced by CNtObjectFolder::GetDetailsEx(), CNtObjectFolder::GetDetailsOf(), and MapTypeNameToType().

◆ RegistryTypeNames

const LPCWSTR RegistryTypeNames[]
Initial value:
= {
L"REG_NONE",
L"REG_SZ",
L"REG_EXPAND_SZ",
L"REG_BINARY",
L"REG_DWORD",
L"REG_DWORD_BIG_ENDIAN",
L"REG_LINK",
L"REG_MULTI_SZ",
L"REG_RESOURCE_LIST",
L"REG_FULL_RESOURCE_DESCRIPTOR",
L"REG_RESOURCE_REQUIREMENTS_LIST ",
L"REG_QWORD"
}
static const WCHAR L[]
Definition: oid.c:1250

Definition at line 46 of file ntobjenum.cpp.

Referenced by CRegistryFolder::GetDetailsEx(), and CRegistryFolder::GetDetailsOf().

◆ RootKeys

struct RootKeyEntry RootKeys[]
static
Initial value:
= {
{ HKEY_CLASSES_ROOT, L"HKEY_CLASSES_ROOT" },
{ HKEY_CURRENT_USER, L"HKEY_CURRENT_USER" },
{ HKEY_LOCAL_MACHINE, L"HKEY_LOCAL_MACHINE" },
{ HKEY_USERS, L"HKEY_USERS" },
{ HKEY_CURRENT_CONFIG, L"HKEY_CURRENT_CONFIG" }
}
#define HKEY_USERS
Definition: winreg.h:13
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define HKEY_CURRENT_CONFIG
Definition: winreg.h:15
static const WCHAR L[]
Definition: oid.c:1250
#define HKEY_CLASSES_ROOT
Definition: winreg.h:10
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by CEnumRegRoot::EnumerateNext().