forked from gentilkiwi/mimikatz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kull_m_registry.c
562 lines (523 loc) · 17.6 KB
/
kull_m_registry.c
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
/* Benjamin DELPY `gentilkiwi`
http://blog.gentilkiwi.com
Licence : https://creativecommons.org/licenses/by/4.0/
*/
#include "kull_m_registry.h"
const wchar_t * KULL_M_REGISTRY_TYPE_WSTRING[] = {
L"NONE",
L"SZ",
L"EXPAND_SZ",
L"BINARY",
L"DWORD",
L"DWORD_BIG_ENDIAN",
L"LINK",
L"MULTI_SZ",
L"RESOURCE_LIST",
L"FULL_RESOURCE_DESCRIPTOR",
L"RESOURCE_REQUIREMENTS_LIST",
L"QWORD",
};
BOOL kull_m_registry_open(IN KULL_M_REGISTRY_TYPE Type, IN HANDLE hAny, BOOL isWrite, OUT PKULL_M_REGISTRY_HANDLE *hRegistry)
{
BOOL status = FALSE;
PKULL_M_REGISTRY_HIVE_HEADER pFh;
PKULL_M_REGISTRY_HIVE_BIN_HEADER pBh;
*hRegistry = (PKULL_M_REGISTRY_HANDLE) LocalAlloc(LPTR, sizeof(KULL_M_REGISTRY_HANDLE));
if(*hRegistry)
{
(*hRegistry)->type = Type;
switch (Type)
{
case KULL_M_REGISTRY_TYPE_OWN:
status = TRUE;
break;
case KULL_M_REGISTRY_TYPE_HIVE:
(*hRegistry)->pHandleHive = (PKULL_M_REGISTRY_HIVE_HANDLE) LocalAlloc(LPTR, sizeof(KULL_M_REGISTRY_HIVE_HANDLE));
if((*hRegistry)->pHandleHive)
{
(*hRegistry)->pHandleHive->hFileMapping = CreateFileMapping(hAny, NULL, isWrite ? PAGE_READWRITE : PAGE_READONLY, 0, 0, NULL);
if((*hRegistry)->pHandleHive->hFileMapping)
{
(*hRegistry)->pHandleHive->pMapViewOfFile = MapViewOfFile((*hRegistry)->pHandleHive->hFileMapping, isWrite ? FILE_MAP_WRITE : FILE_MAP_READ, 0, 0, 0);
if(pFh = (PKULL_M_REGISTRY_HIVE_HEADER) (*hRegistry)->pHandleHive->pMapViewOfFile)
{
if((pFh->tag == 'fger') && (pFh->fileType == 0))
{
pBh = (PKULL_M_REGISTRY_HIVE_BIN_HEADER) ((PBYTE) pFh + sizeof(KULL_M_REGISTRY_HIVE_HEADER));
if(pBh->tag == 'nibh')
{
(*hRegistry)->pHandleHive->pStartOf = (PBYTE) pBh;
(*hRegistry)->pHandleHive->pRootNamedKey = (PKULL_M_REGISTRY_HIVE_KEY_NAMED) ((PBYTE) pBh + sizeof(KULL_M_REGISTRY_HIVE_BIN_HEADER) + pBh->offsetHiveBin);
status = (((*hRegistry)->pHandleHive->pRootNamedKey->tag == 'kn') && ((*hRegistry)->pHandleHive->pRootNamedKey->flags & (KULL_M_REGISTRY_HIVE_KEY_NAMED_FLAG_ROOT | KULL_M_REGISTRY_HIVE_KEY_NAMED_FLAG_LOCKED)));
}
}
if(!status)
{
UnmapViewOfFile((*hRegistry)->pHandleHive->pMapViewOfFile);
CloseHandle((*hRegistry)->pHandleHive->hFileMapping);
}
}
}
}
break;
default:
break;
}
if(!status)
LocalFree(*hRegistry);
}
return status;
}
PKULL_M_REGISTRY_HANDLE kull_m_registry_close(IN PKULL_M_REGISTRY_HANDLE hRegistry)
{
if(hRegistry)
{
switch (hRegistry->type)
{
case KULL_M_REGISTRY_TYPE_HIVE:
if(hRegistry->pHandleHive)
{
if(hRegistry->pHandleHive->pMapViewOfFile)
UnmapViewOfFile(hRegistry->pHandleHive->pMapViewOfFile);
if(hRegistry->pHandleHive->hFileMapping)
CloseHandle(hRegistry->pHandleHive->hFileMapping);
LocalFree(hRegistry->pHandleHive);
}
default:
break;
}
return (PKULL_M_REGISTRY_HANDLE) LocalFree(hRegistry);
}
else return NULL;
}
BOOL kull_m_registry_RegOpenKeyEx(IN PKULL_M_REGISTRY_HANDLE hRegistry, IN HKEY hKey, IN OPTIONAL LPCWSTR lpSubKey, IN DWORD ulOptions, IN REGSAM samDesired, OUT PHKEY phkResult)
{
BOOL status = FALSE;
DWORD dwErrCode;
PKULL_M_REGISTRY_HIVE_KEY_NAMED pKn;
PKULL_M_REGISTRY_HIVE_BIN_CELL pHbC;
wchar_t * ptrF, * buffer;
*phkResult = 0;
switch(hRegistry->type)
{
case KULL_M_REGISTRY_TYPE_OWN:
dwErrCode = RegOpenKeyEx(hKey, lpSubKey, ulOptions, samDesired, phkResult);
if(!(status = (dwErrCode == ERROR_SUCCESS)))
SetLastError(dwErrCode);
break;
case KULL_M_REGISTRY_TYPE_HIVE:
pKn = hKey ? (PKULL_M_REGISTRY_HIVE_KEY_NAMED) hKey : hRegistry->pHandleHive->pRootNamedKey;
if(pKn->tag == 'kn')
{
if(lpSubKey)
{
if(pKn->nbSubKeys && (pKn->offsetSubKeys != -1))
{
pHbC = (PKULL_M_REGISTRY_HIVE_BIN_CELL) (hRegistry->pHandleHive->pStartOf + pKn->offsetSubKeys);
if(ptrF = wcschr(lpSubKey, L'\\'))
{
if(buffer = (wchar_t *) LocalAlloc(LPTR, (ptrF - lpSubKey + 1) * sizeof(wchar_t)))
{
RtlCopyMemory(buffer, lpSubKey, (ptrF - lpSubKey) * sizeof(wchar_t));
if(*phkResult = (HKEY) kull_m_registry_searchKeyNamedInList(hRegistry, pHbC, buffer))
kull_m_registry_RegOpenKeyEx(hRegistry, *phkResult, ptrF + 1, ulOptions, samDesired, phkResult);
LocalFree(buffer);
}
}
else *phkResult = (HKEY) kull_m_registry_searchKeyNamedInList(hRegistry, pHbC, lpSubKey);
}
}
else *phkResult = (HKEY) pKn;
}
status = (*phkResult != 0);
break;
default:
break;
}
return status;
}
PKULL_M_REGISTRY_HIVE_KEY_NAMED kull_m_registry_searchKeyNamedInList(IN PKULL_M_REGISTRY_HANDLE hRegistry, IN PKULL_M_REGISTRY_HIVE_BIN_CELL pHbC, IN LPCWSTR lpSubKey)
{
PKULL_M_REGISTRY_HIVE_KEY_NAMED pKn, result = NULL;
PKULL_M_REGISTRY_HIVE_LF_LH pLfLh;
DWORD i;
wchar_t * buffer;
switch(pHbC->tag)
{
case 'fl':
case 'hl':
pLfLh = (PKULL_M_REGISTRY_HIVE_LF_LH) pHbC;
for(i = 0 ; i < pLfLh->nbElements && !result; i++)
{
pKn = (PKULL_M_REGISTRY_HIVE_KEY_NAMED) (hRegistry->pHandleHive->pStartOf + pLfLh->elements[i].offsetNamedKey);
if(pKn->tag == 'kn')
{
if(pKn->flags & KULL_M_REGISTRY_HIVE_KEY_NAMED_FLAG_ASCII_NAME)
buffer = kull_m_string_qad_ansi_c_to_unicode((char *) pKn->keyName, pKn->szKeyName);
else if(buffer = (wchar_t *) LocalAlloc(LPTR, pKn->szKeyName + sizeof(wchar_t)))
RtlCopyMemory(buffer, pKn->keyName, pKn->szKeyName);
if(buffer)
{
if(_wcsicmp(lpSubKey, buffer) == 0)
result = pKn;
LocalFree(buffer);
}
}
}
break;
case 'il':
case 'ir':
default:
break;
}
return result;
}
BOOL kull_m_registry_RegQueryInfoKey(IN PKULL_M_REGISTRY_HANDLE hRegistry, IN HKEY hKey, OUT OPTIONAL LPWSTR lpClass, IN OUT OPTIONAL LPDWORD lpcClass, IN OPTIONAL LPDWORD lpReserved, OUT OPTIONAL LPDWORD lpcSubKeys, OUT OPTIONAL LPDWORD lpcMaxSubKeyLen, OUT OPTIONAL LPDWORD lpcMaxClassLen, OUT OPTIONAL LPDWORD lpcValues, OUT OPTIONAL LPDWORD lpcMaxValueNameLen, OUT OPTIONAL LPDWORD lpcMaxValueLen, OUT OPTIONAL LPDWORD lpcbSecurityDescriptor, OUT OPTIONAL PFILETIME lpftLastWriteTime)
{
BOOL status = FALSE;
DWORD dwErrCode;
PKULL_M_REGISTRY_HIVE_KEY_NAMED pKn;
DWORD szInCar;
switch(hRegistry->type)
{
case KULL_M_REGISTRY_TYPE_OWN:
dwErrCode = RegQueryInfoKey(hKey, lpClass, lpcClass, lpReserved, lpcSubKeys, lpcMaxSubKeyLen, lpcMaxClassLen, lpcValues, lpcMaxValueNameLen, lpcMaxValueLen, lpcbSecurityDescriptor, lpftLastWriteTime);
if(!(status = (dwErrCode == ERROR_SUCCESS)))
SetLastError(dwErrCode);
break;
case KULL_M_REGISTRY_TYPE_HIVE:
pKn = hKey ? (PKULL_M_REGISTRY_HIVE_KEY_NAMED) hKey : hRegistry->pHandleHive->pRootNamedKey;
if(status = (pKn->tag == 'kn'))
{
if(lpcSubKeys)
*lpcSubKeys = pKn->nbSubKeys;
if(lpcMaxSubKeyLen)
*lpcMaxSubKeyLen = pKn->szMaxSubKeyName / sizeof(wchar_t);
if(lpcMaxClassLen)
*lpcMaxClassLen = pKn->szMaxSubKeyClassName / sizeof(wchar_t);
if(lpcValues)
*lpcValues = pKn->nbValues;
if(lpcMaxValueNameLen)
*lpcMaxValueNameLen = pKn->szMaxValueName / sizeof(wchar_t);
if(lpcMaxValueLen)
*lpcMaxValueLen = pKn->szMaxValueData;
if(lpcbSecurityDescriptor)
*lpcbSecurityDescriptor = 0; /* NOT SUPPORTED */
if(lpftLastWriteTime)
*lpftLastWriteTime = pKn->lastModification;
if(lpcClass)
{
szInCar = pKn->szClassName / sizeof(wchar_t);
if(lpClass)
{
if(status = (*lpcClass > szInCar))
{
RtlCopyMemory(lpClass, &((PKULL_M_REGISTRY_HIVE_BIN_CELL) (hRegistry->pHandleHive->pStartOf + pKn->offsetClassName))->data , pKn->szClassName);
lpClass[szInCar] = L'\0';
}
}
*lpcClass = szInCar;
}
}
break;
default:
break;
}
return status;
}
PKULL_M_REGISTRY_HIVE_VALUE_KEY kull_m_registry_searchValueNameInList(IN PKULL_M_REGISTRY_HANDLE hRegistry, IN HKEY hKey, IN OPTIONAL LPCWSTR lpValueName)
{
PKULL_M_REGISTRY_HIVE_KEY_NAMED pKn;
PKULL_M_REGISTRY_HIVE_VALUE_LIST pVl;
PKULL_M_REGISTRY_HIVE_VALUE_KEY pVk, pFvk = NULL;
DWORD i;
wchar_t * buffer;
pKn = hKey ? (PKULL_M_REGISTRY_HIVE_KEY_NAMED) hKey : hRegistry->pHandleHive->pRootNamedKey;
if(pKn->tag == 'kn')
{
if(pKn->nbValues && (pKn->offsetValues != -1))
{
pVl = (PKULL_M_REGISTRY_HIVE_VALUE_LIST) (hRegistry->pHandleHive->pStartOf + pKn->offsetValues);
for(i = 0 ; i < pKn->nbValues && !pFvk; i++)
{
pVk = (PKULL_M_REGISTRY_HIVE_VALUE_KEY) (hRegistry->pHandleHive->pStartOf + pVl->offsetValue[i]);
if(pVk->tag == 'kv')
{
if(lpValueName)
{
if(pVk->szValueName)
{
if(pVk->flags & KULL_M_REGISTRY_HIVE_VALUE_KEY_FLAG_ASCII_NAME)
buffer = kull_m_string_qad_ansi_c_to_unicode((char *) pVk->valueName, pVk->szValueName);
else if(buffer = (wchar_t *) LocalAlloc(LPTR, pVk->szValueName + sizeof(wchar_t)))
RtlCopyMemory(buffer, pVk->valueName, pVk->szValueName);
if(buffer)
{
if(_wcsicmp(lpValueName, buffer) == 0)
pFvk = pVk;
LocalFree(buffer);
}
}
}
else if(!pVk->szValueName)
pFvk = pVk;
}
}
}
}
return pFvk;
}
BOOL kull_m_registry_RegQueryValueEx(IN PKULL_M_REGISTRY_HANDLE hRegistry, IN HKEY hKey, IN OPTIONAL LPCWSTR lpValueName, IN LPDWORD lpReserved, OUT OPTIONAL LPDWORD lpType, OUT OPTIONAL LPBYTE lpData, IN OUT OPTIONAL LPDWORD lpcbData)
{
BOOL status = FALSE;
DWORD dwErrCode, szData;
PKULL_M_REGISTRY_HIVE_VALUE_KEY pFvk = NULL;
PVOID dataLoc;
switch(hRegistry->type)
{
case KULL_M_REGISTRY_TYPE_OWN:
dwErrCode = RegQueryValueEx(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData);
if(!(status = (dwErrCode == ERROR_SUCCESS)))
SetLastError(dwErrCode);
break;
case KULL_M_REGISTRY_TYPE_HIVE:
pFvk = kull_m_registry_searchValueNameInList(hRegistry, hKey, lpValueName);
if(status = (pFvk != NULL))
{
szData = pFvk->szData & ~0x80000000;
if(lpType)
*lpType = pFvk->typeData;
if(lpcbData)
{
if(lpData)
{
if(status = (*lpcbData >= szData))
{
dataLoc = (pFvk->szData & 0x80000000) ? &pFvk->offsetData : (PVOID) &(((PKULL_M_REGISTRY_HIVE_BIN_CELL) (hRegistry->pHandleHive->pStartOf + pFvk->offsetData))->data);
RtlCopyMemory(lpData, dataLoc, szData);
}
}
*lpcbData = szData;
}
}
break;
default:
break;
}
return status;
}
BOOL kull_m_registry_RegSetValueEx(IN PKULL_M_REGISTRY_HANDLE hRegistry, IN HKEY hKey, IN OPTIONAL LPCWSTR lpValueName, IN DWORD Reserved, IN DWORD dwType, IN OPTIONAL LPCBYTE lpData, IN DWORD cbData)
{
BOOL status = FALSE;
DWORD szData, flags, dwErrCode;
PKULL_M_REGISTRY_HIVE_VALUE_KEY pFvk;
PVOID dataLoc;
switch(hRegistry->type)
{
case KULL_M_REGISTRY_TYPE_OWN:
dwErrCode = RegSetValueEx(hKey, lpValueName, Reserved, dwType, lpData, cbData);
if(!(status = (dwErrCode == ERROR_SUCCESS)))
SetLastError(dwErrCode);
break;
case KULL_M_REGISTRY_TYPE_HIVE:
if(pFvk = kull_m_registry_searchValueNameInList(hRegistry, hKey, lpValueName))
{
flags = pFvk->szData & 0x80000000;
szData = pFvk->szData & ~0x80000000;
if(status = (szData >= cbData))
{
pFvk->typeData = dwType;
pFvk->szData = flags | cbData;
dataLoc = (pFvk->szData & 0x80000000) ? &pFvk->offsetData : (PVOID) &(((PKULL_M_REGISTRY_HIVE_BIN_CELL) (hRegistry->pHandleHive->pStartOf + pFvk->offsetData))->data);
RtlCopyMemory(dataLoc, lpData, szData);
}
else SetLastError(ERROR_NOT_SUPPORTED);
}
break;
default:
break;
}
return status;
}
BOOL kull_m_registry_RegEnumKeyEx(IN PKULL_M_REGISTRY_HANDLE hRegistry, IN HKEY hKey, IN DWORD dwIndex, OUT LPWSTR lpName, IN OUT LPDWORD lpcName, IN LPDWORD lpReserved, OUT OPTIONAL LPWSTR lpClass, IN OUT OPTIONAL LPDWORD lpcClass, OUT OPTIONAL PFILETIME lpftLastWriteTime)
{
BOOL status = FALSE;
DWORD dwErrCode, szInCar;
PKULL_M_REGISTRY_HIVE_KEY_NAMED pKn, pCandidateKn;
PKULL_M_REGISTRY_HIVE_BIN_CELL pHbC;
PKULL_M_REGISTRY_HIVE_LF_LH pLfLh;
wchar_t * buffer;
switch(hRegistry->type)
{
case KULL_M_REGISTRY_TYPE_OWN:
dwErrCode = RegEnumKeyEx(hKey, dwIndex, lpName, lpcName, lpReserved, lpClass, lpcClass, lpftLastWriteTime);
if(!(status = (dwErrCode == ERROR_SUCCESS)))
SetLastError(dwErrCode);
break;
case KULL_M_REGISTRY_TYPE_HIVE:
pKn = (PKULL_M_REGISTRY_HIVE_KEY_NAMED) hKey;
if(pKn->nbSubKeys && (dwIndex < pKn->nbSubKeys) && (pKn->offsetSubKeys != -1))
{
pHbC = (PKULL_M_REGISTRY_HIVE_BIN_CELL) (hRegistry->pHandleHive->pStartOf + pKn->offsetSubKeys);
switch(pHbC->tag)
{
case 'fl':
case 'hl':
pLfLh = (PKULL_M_REGISTRY_HIVE_LF_LH) pHbC;
if(pLfLh->nbElements && (dwIndex < pLfLh->nbElements))
{
pCandidateKn = (PKULL_M_REGISTRY_HIVE_KEY_NAMED) (hRegistry->pHandleHive->pStartOf + pLfLh->elements[dwIndex].offsetNamedKey);
if((pCandidateKn->tag == 'kn') && lpName && lpcName)
{
if(lpftLastWriteTime)
*lpftLastWriteTime = pKn->lastModification;
if(pCandidateKn->flags & KULL_M_REGISTRY_HIVE_KEY_NAMED_FLAG_ASCII_NAME)
{
szInCar = pCandidateKn->szKeyName;
if(status = (*lpcName > szInCar))
{
if(buffer = kull_m_string_qad_ansi_c_to_unicode((char *) pCandidateKn->keyName, szInCar))
{
RtlCopyMemory(lpName, buffer, szInCar * sizeof(wchar_t));
LocalFree(buffer);
}
}
}
else
{
szInCar = pCandidateKn->szKeyName / sizeof(wchar_t);
if(status = (*lpcName > szInCar))
RtlCopyMemory(lpName, pCandidateKn->keyName, pKn->szKeyName);
}
if(status)
lpName[szInCar] = L'\0';
*lpcName = szInCar;
if(lpcClass)
{
szInCar = pCandidateKn->szClassName / sizeof(wchar_t);
if(lpClass)
{
if(status = (*lpcClass > szInCar))
{
RtlCopyMemory(lpClass, &((PKULL_M_REGISTRY_HIVE_BIN_CELL) (hRegistry->pHandleHive->pStartOf + pCandidateKn->offsetClassName))->data , pCandidateKn->szClassName);
lpClass[szInCar] = L'\0';
}
}
*lpcClass = szInCar;
}
}
}
break;
case 'il':
case 'ir':
default:
break;
}
}
break;
default:
break;
}
return status;
}
BOOL kull_m_registry_RegEnumValue(IN PKULL_M_REGISTRY_HANDLE hRegistry, IN HKEY hKey, IN DWORD dwIndex, OUT LPWSTR lpValueName, IN OUT LPDWORD lpcchValueName, IN LPDWORD lpReserved, OUT OPTIONAL LPDWORD lpType, OUT OPTIONAL LPBYTE lpData, OUT OPTIONAL LPDWORD lpcbData)
{
BOOL status = FALSE;
DWORD dwErrCode, szBuffer;
wchar_t * buffer;
PKULL_M_REGISTRY_HIVE_KEY_NAMED pKn;
PKULL_M_REGISTRY_HIVE_VALUE_LIST pVl;
PKULL_M_REGISTRY_HIVE_VALUE_KEY pVk;
PVOID dataLoc;
switch(hRegistry->type)
{
case KULL_M_REGISTRY_TYPE_OWN:
dwErrCode = RegEnumValue(hKey, dwIndex, lpValueName, lpcchValueName, lpReserved, lpType, lpData, lpcbData);
if(!(status = (dwErrCode == ERROR_SUCCESS)))
SetLastError(dwErrCode);
break;
case KULL_M_REGISTRY_TYPE_HIVE:
pKn = hKey ? (PKULL_M_REGISTRY_HIVE_KEY_NAMED) hKey : hRegistry->pHandleHive->pRootNamedKey;
if(pKn->tag == 'kn')
{
if(pKn->nbValues && (dwIndex < pKn->nbValues) && (pKn->offsetValues != -1))
{
pVl = (PKULL_M_REGISTRY_HIVE_VALUE_LIST) (hRegistry->pHandleHive->pStartOf + pKn->offsetValues);
pVk = (PKULL_M_REGISTRY_HIVE_VALUE_KEY) (hRegistry->pHandleHive->pStartOf + pVl->offsetValue[dwIndex]);
if((pVk->tag == 'kv') && lpValueName && lpcchValueName)
{
if(pVk->szValueName)
{
if(pVk->flags & KULL_M_REGISTRY_HIVE_VALUE_KEY_FLAG_ASCII_NAME)
{
szBuffer = pVk->szValueName + 1;
buffer = kull_m_string_qad_ansi_c_to_unicode((char *) pVk->valueName, pVk->szValueName);
}
else
{
szBuffer = pVk->szValueName / sizeof(wchar_t) + 1;
if(buffer = (wchar_t *) LocalAlloc(LPTR, pVk->szValueName + sizeof(wchar_t)))
RtlCopyMemory(buffer, pVk->valueName, pVk->szValueName);
}
if(buffer)
{
if(status = (*lpcchValueName >= szBuffer))
{
RtlCopyMemory(lpValueName, buffer, szBuffer * sizeof(wchar_t));
*lpcchValueName = szBuffer - 1;
}
LocalFree(buffer);
}
}
else if(!pVk->szValueName)
{
lpValueName = NULL;
*lpcchValueName = 0;
}
if(status)
{
szBuffer = pVk->szData & ~0x80000000;
if(lpType)
*lpType = pVk->typeData;
if(lpcbData)
{
if(lpData)
{
if(status = (*lpcbData >= szBuffer))
{
dataLoc = (pVk->szData & 0x80000000) ? &pVk->offsetData : (PVOID) &(((PKULL_M_REGISTRY_HIVE_BIN_CELL) (hRegistry->pHandleHive->pStartOf + pVk->offsetData))->data);
RtlCopyMemory(lpData, dataLoc , szBuffer);
}
}
*lpcbData = szBuffer;
}
}
}
}
}
break;
default:
break;
}
return status;
}
BOOL kull_m_registry_RegCloseKey(IN PKULL_M_REGISTRY_HANDLE hRegistry, IN HKEY hKey)
{
BOOL status = FALSE;
DWORD dwErrCode;
switch(hRegistry->type)
{
case KULL_M_REGISTRY_TYPE_OWN:
dwErrCode = RegCloseKey(hKey);
if(!(status = (dwErrCode == ERROR_SUCCESS)))
SetLastError(dwErrCode);
break;
case KULL_M_REGISTRY_TYPE_HIVE:
status = TRUE;
break;
default:
break;
}
return status;
}