ReactOS 0.4.15-dev-5664-g3bf4ef6
cmname.c File Reference
#include "cmlib.h"
#include <debug.h>
Include dependency graph for cmname.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

USHORT NTAPI CmpCopyName (IN PHHIVE Hive, OUT PWCHAR Destination, IN PCUNICODE_STRING Source)
 
VOID NTAPI CmpCopyCompressedName (OUT PWCHAR Destination, IN ULONG DestinationLength, IN PWCHAR Source, IN ULONG SourceLength)
 
USHORT NTAPI CmpNameSize (IN PHHIVE Hive, IN PCUNICODE_STRING Name)
 
USHORT NTAPI CmpCompressedNameSize (IN PWCHAR Name, IN ULONG Length)
 
LONG NTAPI CmpCompareCompressedName (IN PCUNICODE_STRING SearchName, IN PWCHAR CompressedName, IN ULONG NameLength)
 
BOOLEAN NTAPI CmpFindNameInList (IN PHHIVE Hive, IN PCHILD_LIST ChildList, IN PCUNICODE_STRING Name, OUT PULONG ChildIndex OPTIONAL, OUT PHCELL_INDEX CellIndex)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file cmname.c.

Function Documentation

◆ CmpCompareCompressedName()

LONG NTAPI CmpCompareCompressedName ( IN PCUNICODE_STRING  SearchName,
IN PWCHAR  CompressedName,
IN ULONG  NameLength 
)

Definition at line 109 of file cmname.c.

112{
113 WCHAR* p;
114 UCHAR* pp;
115 WCHAR chr1, chr2;
116 USHORT SearchLength;
117 LONG Result;
118
119 /* Set the pointers and length and then loop */
120 p = SearchName->Buffer;
121 pp = (PUCHAR)CompressedName;
122 SearchLength = (SearchName->Length / sizeof(WCHAR));
123 while (SearchLength > 0 && NameLength > 0)
124 {
125 /* Get the characters */
126 chr1 = *p++;
127 chr2 = (WCHAR)(*pp++);
128
129 /* Check if we have a direct match */
130 if (chr1 != chr2)
131 {
132 /* See if they match and return result if they don't */
135 if (Result) return Result;
136 }
137
138 /* Next chars */
139 SearchLength--;
140 NameLength--;
141 }
142
143 /* Return the difference directly */
144 return SearchLength - NameLength;
145}
GLfloat GLfloat p
Definition: glext.h:8902
unsigned char * PUCHAR
Definition: retypes.h:3
WCHAR NTAPI RtlUpcaseUnicodeChar(_In_ WCHAR Source)
Definition: nlsboot.c:176
long LONG
Definition: pedump.c:60
unsigned short USHORT
Definition: pedump.c:61
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by CmpDoCompareKeyName(), CmpFindNameInList(), CmpFindValueByNameFromCache(), and CmpGetNameControlBlock().

◆ CmpCompressedNameSize()

USHORT NTAPI CmpCompressedNameSize ( IN PWCHAR  Name,
IN ULONG  Length 
)

Definition at line 95 of file cmname.c.

97{
98 /*
99 * Don't remove this: compressed names are "opaque" and just because
100 * the current implementation turns them into ansi-names doesn't mean
101 * that it will remain that way forever, so -never- assume this code
102 * below internally!
103 */
104 return (USHORT)Length * sizeof(WCHAR);
105}
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102

Referenced by BiEnumerateSubKeys(), CmpAddDriverToList(), CmpAddSubKey(), CmpConstructName(), CmpGetHiveName(), CmpIsSafe(), CmpMarkIndexDirty(), CmpQueryKeyData(), CmpQueryKeyDataFromCache(), CmpQueryKeyValueData(), CmpQueryNameInformation(), and CmpRemoveSubKey().

◆ CmpCopyCompressedName()

VOID NTAPI CmpCopyCompressedName ( OUT PWCHAR  Destination,
IN ULONG  DestinationLength,
IN PWCHAR  Source,
IN ULONG  SourceLength 
)

Definition at line 56 of file cmname.c.

60{
61 ULONG i, Length;
62
63 /* Get the actual length to copy */
64 Length = min(DestinationLength / sizeof(WCHAR), SourceLength);
65 for (i = 0; i < Length; i++)
66 {
67 /* Copy each character */
69 }
70}
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
unsigned int ULONG
Definition: retypes.h:1
#define min(a, b)
Definition: monoChain.cc:55
_In_ UINT _In_ UINT _In_ PNDIS_PACKET Source
Definition: ndis.h:3169
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2992

Referenced by BiEnumerateSubKeys(), CmpAddDriverToList(), CmpAddSubKey(), CmpGetHiveName(), CmpIsSafe(), CmpMarkIndexDirty(), CmpQueryKeyData(), CmpQueryKeyValueData(), CmpQueryNameInformation(), and CmpRemoveSubKey().

◆ CmpCopyName()

USHORT NTAPI CmpCopyName ( IN PHHIVE  Hive,
OUT PWCHAR  Destination,
IN PCUNICODE_STRING  Source 
)

Definition at line 21 of file cmname.c.

24{
25 ULONG i;
26
27 /* Check for old hives */
28 if (Hive->Version == 1)
29 {
30 /* Just copy the source directly */
31 RtlCopyMemory(Destination, Source->Buffer, Source->Length);
32 return Source->Length;
33 }
34
35 /* For new versions, check for compressed name */
36 for (i = 0; i < (Source->Length / sizeof(WCHAR)); i++)
37 {
38 /* Check if the name is non compressed */
39 if (Source->Buffer[i] > (UCHAR)-1)
40 {
41 /* Do the copy */
42 RtlCopyMemory(Destination, Source->Buffer, Source->Length);
43 return Source->Length;
44 }
45
46 /* Copy this character */
47 ((PCHAR)Destination)[i] = (CHAR)(Source->Buffer[i]);
48 }
49
50 /* Compressed name, return length */
51 return Source->Length / sizeof(WCHAR);
52}
#define CHAR(Char)
#define PCHAR
Definition: match.c:90
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263

Referenced by CmCreateRootNode(), CmiAddValueKey(), CmiCreateSubKey(), CmpCreateLinkNode(), CmpCreateRootNode(), CmpDoCreateChild(), and CmpSetValueKeyNew().

◆ CmpFindNameInList()

BOOLEAN NTAPI CmpFindNameInList ( IN PHHIVE  Hive,
IN PCHILD_LIST  ChildList,
IN PCUNICODE_STRING  Name,
OUT PULONG ChildIndex  OPTIONAL,
OUT PHCELL_INDEX  CellIndex 
)

Definition at line 149 of file cmname.c.

154{
155 PCELL_DATA CellData;
156 HCELL_INDEX CellToRelease = HCELL_NIL;
157 ULONG i;
158 PCM_KEY_VALUE KeyValue;
159 LONG Result;
160 UNICODE_STRING SearchName;
162
163 /* Make sure there's actually something on the list */
164 if (ChildList->Count != 0)
165 {
166 /* Get the cell data */
167 CellData = (PCELL_DATA)HvGetCell(Hive, ChildList->List);
168 if (!CellData)
169 {
170 /* Couldn't get the cell... tell the caller */
171 *CellIndex = HCELL_NIL;
172 return FALSE;
173 }
174
175 /* Now loop every entry */
176 for (i = 0; i < ChildList->Count; i++)
177 {
178 /* Check if we have a cell to release */
179 if (CellToRelease != HCELL_NIL)
180 {
181 /* Release it */
182 HvReleaseCell(Hive, CellToRelease);
183 CellToRelease = HCELL_NIL;
184 }
185
186 /* Get this value */
187 KeyValue = (PCM_KEY_VALUE)HvGetCell(Hive, CellData->u.KeyList[i]);
188 if (!KeyValue)
189 {
190 /* Return with no data found */
191 *CellIndex = HCELL_NIL;
192 Success = FALSE;
193 goto Return;
194 }
195
196 /* Save the cell to release */
197 CellToRelease = CellData->u.KeyList[i];
198
199 /* Check if it's a compressed value name */
200 if (KeyValue->Flags & VALUE_COMP_NAME)
201 {
202 /* Compare compressed names */
204 KeyValue->Name,
205 KeyValue->NameLength);
206 }
207 else
208 {
209 /* Compare the Unicode name directly */
210 SearchName.Length = KeyValue->NameLength;
211 SearchName.MaximumLength = SearchName.Length;
212 SearchName.Buffer = KeyValue->Name;
213 Result = RtlCompareUnicodeString(Name, &SearchName, TRUE);
214 }
215
216 /* Check if we found it */
217 if (!Result)
218 {
219 /* We did... return info to caller */
220 if (ChildIndex) *ChildIndex = i;
221 *CellIndex = CellData->u.KeyList[i];
222
223 /* Set success state */
224 Success = TRUE;
225 goto Return;
226 }
227 }
228
229 /* Got to the end of the list */
230 if (ChildIndex) *ChildIndex = i;
231 *CellIndex = HCELL_NIL;
232
233 /* Nothing found if we got here */
234 Success = TRUE;
235 goto Return;
236 }
237
238 /* Nothing found... check if the caller wanted more info */
239 ASSERT(ChildList->Count == 0);
240 if (ChildIndex) *ChildIndex = 0;
241 *CellIndex = HCELL_NIL;
242
243 /* Nothing found if we got here */
244 return TRUE;
245
246Return:
247 /* Release the first cell we got */
248 if (CellData) HvReleaseCell(Hive, ChildList->List);
249
250 /* Release the secondary one, if we have one */
251 if (CellToRelease) HvReleaseCell(Hive, CellToRelease);
252 return Success;
253}
unsigned char BOOLEAN
struct _CELL_DATA * PCELL_DATA
struct _CM_KEY_VALUE * PCM_KEY_VALUE
#define VALUE_COMP_NAME
Definition: cmdata.h:44
#define HvReleaseCell(Hive, Cell)
Definition: cmlib.h:384
#define HvGetCell(Hive, Cell)
Definition: cmlib.h:381
LONG NTAPI CmpCompareCompressedName(IN PCUNICODE_STRING SearchName, IN PWCHAR CompressedName, IN ULONG NameLength)
Definition: cmname.c:109
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
ULONG RtlCompareUnicodeString(PUNICODE_STRING s1, PUNICODE_STRING s2, BOOLEAN UpCase)
Definition: string_lib.cpp:31
@ Success
Definition: eventcreate.c:712
#define HCELL_NIL
Definition: hivedata.h:85
ULONG HCELL_INDEX
Definition: hivedata.h:80
#define ASSERT(a)
Definition: mode.c:44
HCELL_INDEX KeyList[ANYSIZE_ARRAY]
Definition: cmdata.h:205
union _CELL_DATA::@4093 u
WCHAR Name[ANYSIZE_ARRAY]
Definition: cmdata.h:131
USHORT NameLength
Definition: cmdata.h:125
USHORT Flags
Definition: cmdata.h:129
USHORT MaximumLength
Definition: env_spec_w32.h:370
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_CHILD_LIST_CONFIG _In_opt_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFCHILDLIST * ChildList
Definition: wdfchildlist.h:481

Referenced by BiGetRegistryValue(), CmDeleteValueKey(), CmpFindValueByName(), CmSetValueKey(), RegDeleteValueW(), and RegSetValueExW().

◆ CmpNameSize()

USHORT NTAPI CmpNameSize ( IN PHHIVE  Hive,
IN PCUNICODE_STRING  Name 
)

Definition at line 74 of file cmname.c.

76{
77 ULONG i;
78
79 /* For old hives, just return the length */
80 if (Hive->Version == 1) return Name->Length;
81
82 /* For new versions, check for compressed name */
83 for (i = 0; i < (Name->Length / sizeof(WCHAR)); i++)
84 {
85 /* Check if the name is non compressed */
86 if (Name->Buffer[i] > (UCHAR)-1) return Name->Length;
87 }
88
89 /* Compressed name, return length */
90 return Name->Length / sizeof(WCHAR);
91}

Referenced by CmCreateRootNode(), CmiAddValueKey(), CmiCreateSubKey(), CmpCreateLinkNode(), CmpCreateRootNode(), CmpDoCreateChild(), and CmpSetValueKeyNew().