4 #define WIN32_NO_STATUS
8 #include <ndk/rtltypes.h>
10 #define RtlRosInitUnicodeStringFromLiteral(__Name__, __Value__) \
12 (__Name__)->Buffer = (__Value__); \
13 (__Name__)->Length = sizeof(__Value__) - sizeof(WCHAR); \
14 (__Name__)->MaximumLength = sizeof(__Value__); \
20 void dprintf(char* fmt
, ...)
26 vsprintf(buffer
,fmt
,args
);
27 WriteConsoleA(OutputHandle
, buffer
, strlen(buffer
), NULL
, NULL
);
31 void do_enumeratekey(PWSTR Name
)
34 KEY_BASIC_INFORMATION KeyInformation
[5];
36 OBJECT_ATTRIBUTES ObjectAttributes
;
38 UNICODE_STRING KeyName
;
40 RtlInitUnicodeString(&KeyName
, Name
);
41 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
43 Status
=NtOpenKey( &hKey1
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
44 dprintf("NtEnumerateKey : \n");
46 while(Status
== STATUS_SUCCESS
)
48 Status
=NtEnumerateKey(hKey1
,Index
++,KeyBasicInformation
49 ,&KeyInformation
[0], sizeof(KeyInformation
)
51 if(Status
== STATUS_SUCCESS
)
53 dprintf("\tSubKey Name = ");
54 for (i
=0;i
<KeyInformation
[0].NameLength
/2;i
++)
55 dprintf("%C",KeyInformation
[0].Name
[i
]);
63 void CreateKeyTest(void)
66 OBJECT_ATTRIBUTES ObjectAttributes
;
68 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\testkey");
70 dprintf("Create key '\\Registry\\Machine\\Software\\testkey':\n");
72 InitializeObjectAttributes(&ObjectAttributes
,
77 dprintf("NtCreateKey:\n");
78 Status
= NtCreateKey(&hKey
,
83 REG_OPTION_NON_VOLATILE
,
85 dprintf(" Status = %lx\n",Status
);
86 if (NT_SUCCESS(Status
))
93 void DeleteKeyTest(void)
95 OBJECT_ATTRIBUTES ObjectAttributes
;
96 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\testkey");
100 dprintf("Delete key '\\Registry\\Machine\\Software\\testkey':\n");
102 InitializeObjectAttributes(&ObjectAttributes
,
104 OBJ_CASE_INSENSITIVE
,
107 dprintf("NtOpenKey:\n");
108 Status
= NtOpenKey(&hKey
,
111 dprintf(" Status = %lx\n",Status
);
112 if (!NT_SUCCESS(Status
))
115 dprintf("NtDeleteKey:\n");
116 Status
= NtDeleteKey(hKey
);
117 dprintf(" Status = %lx\n",Status
);
122 void EnumerateKeyTest(void)
125 OBJECT_ATTRIBUTES ObjectAttributes
;
127 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software");
131 KEY_BASIC_INFORMATION KeyInformation
[5];
133 dprintf("Enumerate key '\\Registry\\Machine\\Software':\n");
135 InitializeObjectAttributes(&ObjectAttributes
,
137 OBJ_CASE_INSENSITIVE
,
140 dprintf("NtOpenKey:\n");
141 Status
= NtOpenKey(&hKey
,
144 dprintf(" Status = %lx\n", Status
);
145 if (!NT_SUCCESS(Status
))
148 dprintf("NtQueryKey:\n");
149 Status
= NtQueryKey(hKey
,
152 sizeof(KeyInformation
),
154 dprintf(" Status = %lx\n", Status
);
155 if (NT_SUCCESS(Status
))
157 dprintf("\tKey Name = ");
158 for (i
= 0; i
< KeyInformation
[0].NameLength
/ 2; i
++)
159 dprintf("%C", KeyInformation
[0].Name
[i
]);
163 dprintf("NtEnumerateKey:\n");
165 while(NT_SUCCESS(Status
))
167 Status
= NtEnumerateKey(hKey
,
171 sizeof(KeyInformation
),
173 if (NT_SUCCESS(Status
))
175 dprintf("\tSubKey Name = ");
176 for (i
= 0; i
< KeyInformation
[0].NameLength
/ 2; i
++)
177 dprintf("%C", KeyInformation
[0].Name
[i
]);
183 dprintf("NtClose:\n");
184 Status
= NtClose(hKey
);
185 dprintf(" Status = %lx\n", Status
);
189 void SetValueTest1(void)
192 OBJECT_ATTRIBUTES ObjectAttributes
;
193 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\testkey");
194 UNICODE_STRING ValueName
= RTL_CONSTANT_STRING(L
"TestValue");
197 dprintf("Create key '\\Registry\\Machine\\Software\\testkey':\n");
199 InitializeObjectAttributes(&ObjectAttributes
,
201 OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
,
204 dprintf("NtCreateKey:\n");
205 Status
= NtCreateKey(&hKey
,
210 REG_OPTION_NON_VOLATILE
,
212 dprintf(" Status = %lx\n",Status
);
213 if (!NT_SUCCESS(Status
))
217 dprintf("NtSetValueKey:\n");
218 Status
= NtSetValueKey(hKey
,
222 (PVOID
)L
"TestString",
224 dprintf(" Status = %lx\n",Status
);
230 void SetValueTest2(void)
233 OBJECT_ATTRIBUTES ObjectAttributes
;
234 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\testkey");
235 UNICODE_STRING ValueName
= RTL_CONSTANT_STRING(L
"TestValue");
238 dprintf("Create key '\\Registry\\Machine\\Software\\testkey':\n");
240 InitializeObjectAttributes(&ObjectAttributes
,
242 OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
,
245 dprintf("NtCreateKey:\n");
246 Status
= NtCreateKey(&hKey
,
251 REG_OPTION_NON_VOLATILE
,
253 dprintf(" Status = %lx\n",Status
);
254 if (!NT_SUCCESS(Status
))
257 dprintf("NtSetValueKey:\n");
258 Status
= NtSetValueKey(hKey
,
264 dprintf(" Status = %lx\n",Status
);
270 void DeleteValueTest(void)
272 OBJECT_ATTRIBUTES ObjectAttributes
;
273 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\testkey");
274 UNICODE_STRING ValueName
= RTL_CONSTANT_STRING(L
"TestValue");
278 dprintf("Open key '\\Registry\\Machine\\Software\\testkey':\n");
280 InitializeObjectAttributes(&ObjectAttributes
,
282 OBJ_CASE_INSENSITIVE
,
285 Status
=NtOpenKey(&KeyHandle
,
288 dprintf(" Status = %lx\n", Status
);
289 if (!NT_SUCCESS(Status
))
292 dprintf("Delete value:\n");
295 Status
= NtDeleteValueKey(KeyHandle
,
297 dprintf(" Status = %lx\n", Status
);
299 dprintf("Close key:\n");
300 Status
= NtClose(KeyHandle
);
301 dprintf(" Status = %lx\n", Status
);
305 void EnumerateValueTest(void)
307 KEY_VALUE_FULL_INFORMATION KeyValueInformation
[5];
308 OBJECT_ATTRIBUTES ObjectAttributes
;
309 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\testkey");
310 ULONG Index
,Length
,i
;
314 dprintf("Open key '\\Registry\\Machine\\Software\\testkey':\n");
316 InitializeObjectAttributes(&ObjectAttributes
,
318 OBJ_CASE_INSENSITIVE
,
321 Status
=NtOpenKey(&hKey
,
324 dprintf(" Status = %lx\n", Status
);
325 if (!NT_SUCCESS(Status
))
328 dprintf("Enumerate values:\n");
330 while (Status
== STATUS_SUCCESS
)
332 Status
= NtEnumerateValueKey(hKey
,
334 KeyValueFullInformation
,
335 &KeyValueInformation
[0],
336 sizeof(KeyValueInformation
),
338 if (Status
== STATUS_SUCCESS
)
340 dprintf(" Value:DO=%d, DL=%d, NL=%d, Name = ",
341 KeyValueInformation
[0].DataOffset
,
342 KeyValueInformation
[0].DataLength
,
343 KeyValueInformation
[0].NameLength
);
344 for (i
= 0; i
< KeyValueInformation
[0].NameLength
/ 2; i
++)
345 dprintf("%C", KeyValueInformation
[0].Name
[i
]);
346 dprintf(", Type = %d\n", KeyValueInformation
[0].Type
);
348 if (KeyValueInformation
[0].Type
== REG_SZ
)
349 dprintf(" Value = %S\n",
350 ((char*)&KeyValueInformation
[0]+KeyValueInformation
[0].DataOffset
));
352 if (KeyValueInformation
[0].Type
== REG_DWORD
)
353 dprintf(" Value = %X\n",
354 *((DWORD
*)((char*)&KeyValueInformation
[0]+KeyValueInformation
[0].DataOffset
)));
358 dprintf("NtClose:\n");
359 Status
= NtClose(hKey
);
360 dprintf(" Status = %lx\n", Status
);
368 HANDLE hKey
= NULL
, hKey1
;
369 OBJECT_ATTRIBUTES ObjectAttributes
;
371 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software");
372 ULONG Index
,Length
,i
;
373 KEY_BASIC_INFORMATION KeyInformation
[5];
376 dprintf("NtOpenKey \\Registry : ");
378 dprintf("NtOpenKey \\Registry\\Machine\\Software : ");
379 InitializeObjectAttributes(&ObjectAttributes
,
381 OBJ_CASE_INSENSITIVE
,
384 Status
=NtOpenKey( &hKey1
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
385 dprintf("\t\t\t\tStatus =%x\n",Status
);
388 dprintf("NtQueryKey : ");
389 Status
=NtQueryKey(hKey1
,KeyBasicInformation
390 ,&KeyInformation
[0], sizeof(KeyInformation
)
392 dprintf("\t\t\t\t\tStatus =%x\n",Status
);
393 if (Status
== STATUS_SUCCESS
)
395 dprintf("\tKey Name = ");
396 for (i
=0;i
<KeyInformation
[0].NameLength
/2;i
++)
397 dprintf("%C",KeyInformation
[0].Name
[i
]);
400 dprintf("NtEnumerateKey : \n");
402 while(Status
== STATUS_SUCCESS
)
404 Status
=NtEnumerateKey(hKey1
,Index
++,KeyBasicInformation
405 ,&KeyInformation
[0], sizeof(KeyInformation
)
407 if(Status
== STATUS_SUCCESS
)
409 dprintf("\tSubKey Name = ");
410 for (i
=0;i
<KeyInformation
[0].NameLength
/2;i
++)
411 dprintf("%C",KeyInformation
[0].Name
[i
]);
415 dprintf("NtClose : ");
416 Status
= NtClose( hKey1
);
417 dprintf("\t\t\t\t\tStatus =%x\n",Status
);
426 OBJECT_ATTRIBUTES ObjectAttributes
;
427 UNICODE_STRING KeyName
;
431 dprintf("NtCreateKey non volatile: \n");
432 dprintf(" \\Registry\\Machine\\Software\\test3reactos: ");
433 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\Software\\test3reactos");
434 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
436 Status
= NtCreateKey ( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
437 ,0,NULL
,REG_OPTION_NON_VOLATILE
,NULL
);
438 dprintf("\t\tStatus=%x\n",Status
);
441 dprintf("delete \\Registry\\Machine\\software\\test3reactos ?");
442 ReadConsoleA(InputHandle
, Buffer
, 3, &Result
, NULL
) ;
443 if (Buffer
[0] != 'y' && Buffer
[0] != 'Y') return;
445 dprintf("delete \\Registry\\Machine\\software\\test3reactos ?");
446 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\Software\\test3reactos");
447 InitializeObjectAttributes(&ObjectAttributes
,
449 OBJ_CASE_INSENSITIVE
,
452 dprintf("NtOpenKey : ");
453 Status
=NtOpenKey( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
);
454 dprintf("\t\t\t\tStatus =%x\n",Status
);
455 dprintf("NtDeleteKey : ");
456 Status
=NtDeleteKey(hKey
);
457 dprintf("\t\t\t\tStatus =%x\n",Status
);
463 HKEY hKey
= NULL
,hKey1
;
466 DWORD RegDataType
, RegDataSize
;
467 BOOL GlobalFifoEnable
;
469 DWORD RegDisposition
;
476 DWORD cchMaxValueName
;
477 DWORD cbMaxValueData
;
478 DWORD cbSecurityDescriptor
;
479 FILETIME ftLastWriteTime
;
480 SYSTEMTIME LastWriteTime
;
482 dprintf ("RegOpenKeyExW HKLM\\System\\Setup: ");
483 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
488 dprintf("\t\tdwError =%x\n",dwError
);
489 if (dwError
== ERROR_SUCCESS
)
491 dprintf("RegQueryInfoKeyW: ");
493 dwError
= RegQueryInfoKeyW(hKey1
494 , szClass
, &cchClass
, NULL
, &cSubKeys
495 , &cchMaxSubkey
, &cchMaxClass
, &cValues
, &cchMaxValueName
496 , &cbMaxValueData
, &cbSecurityDescriptor
, &ftLastWriteTime
);
497 dprintf ("\t\t\t\tdwError %x\n", dwError
);
498 FileTimeToSystemTime(&ftLastWriteTime
,&LastWriteTime
);
499 dprintf ("\tnb of subkeys=%d,last write : %d/%d/%d %d:%02.2d'%02.2d''%03.3d\n",cSubKeys
500 ,LastWriteTime
.wMonth
504 ,LastWriteTime
.wMinute
505 ,LastWriteTime
.wSecond
506 ,LastWriteTime
.wMilliseconds
511 dprintf ("RegOpenKeyExW: ");
512 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
513 L
"System\\ControlSet001\\Services\\Serial",
517 dprintf ("\t\t\t\t\tdwError %x\n", dwError
);
518 RegDataSize
= sizeof(GlobalFifoEnable
);
519 if (dwError
== ERROR_SUCCESS
)
521 dprintf ("RegQueryValueExW: ");
522 dwError
= RegQueryValueExW(hKey
,
526 (PBYTE
)&GlobalFifoEnable
,
528 dprintf("\t\t\t\tdwError =%x\n",dwError
);
531 dprintf("\tValue:DT=%d, DS=%d, Value=%d\n"
537 dprintf ("RegCreateKeyExW: ");
538 dwError
= RegCreateKeyExW(hKey
,
539 L
"Parameters\\Serial001",
548 dprintf ("\t\t\t\tdwError %x\n", dwError
);
550 dprintf ("RegCreateKeyExW: ");
551 dwError
= RegCreateKeyExW (HKEY_LOCAL_MACHINE
,
552 L
"Software\\test4reactos\\test",
555 REG_OPTION_NON_VOLATILE
,
561 dprintf ("\t\t\t\tdwError %x ", dwError
);
562 dprintf ("dwDisposition %x\n", dwDisposition
);
563 if (dwError
== ERROR_SUCCESS
)
565 dprintf ("RegSetValueExW: ");
566 dwError
= RegSetValueExW (hKey
,
570 (BYTE
*)L
"TestString",
573 dprintf ("\t\t\t\tdwError %x\n", dwError
);
574 dprintf ("RegCloseKey: ");
575 dwError
= RegCloseKey (hKey
);
576 dprintf ("\t\t\t\t\tdwError %x\n", dwError
);
582 dprintf ("RegCreateKeyExW: ");
583 dwError
= RegCreateKeyExW (HKEY_LOCAL_MACHINE
,
593 dprintf ("\t\t\t\tdwError %x ", dwError
);
594 dprintf ("dwDisposition %x\n", dwDisposition
);
597 if (dwError
== ERROR_SUCCESS
)
599 dprintf("RegQueryInfoKeyW: ");
601 dwError
= RegQueryInfoKeyW(hKey
602 , szClass
, &cchClass
, NULL
, &cSubKeys
603 , &cchMaxSubkey
, &cchMaxClass
, &cValues
, &cchMaxValueName
604 , &cbMaxValueData
, &cbSecurityDescriptor
, &ftLastWriteTime
);
605 dprintf ("\t\t\t\tdwError %x\n", dwError
);
606 FileTimeToSystemTime(&ftLastWriteTime
,&LastWriteTime
);
607 dprintf ("\tnb of subkeys=%d,last write : %d/%d/%d %d:%02.2d'%02.2d''%03.3d\n",cSubKeys
608 ,LastWriteTime
.wMonth
612 ,LastWriteTime
.wMinute
613 ,LastWriteTime
.wSecond
614 ,LastWriteTime
.wMilliseconds
616 dprintf ("RegCloseKey: ");
617 dwError
= RegCloseKey (hKey
);
618 dprintf ("\t\t\t\t\tdwError %x\n", dwError
);
620 dprintf ("\nTests done...\n");
626 OBJECT_ATTRIBUTES ObjectAttributes
;
627 UNICODE_STRING KeyName
;
630 dprintf("NtOpenKey : \n");
631 dprintf(" \\Registry\\Machine\\Software\\reactos : ");
632 RtlRosInitUnicodeStringFromLiteral(&KeyName
,L
"\\Registry\\Machine\\Software\\reactos");
633 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
635 Status
=NtOpenKey( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
);
636 dprintf("\t\tStatus=%x\n",Status
);
637 dprintf("NtFlushKey : \n");
638 Status
= NtFlushKey(hKey
);
639 dprintf("\t\tStatus=%x\n",Status
);
640 dprintf("NtCloseKey : \n");
641 Status
=NtClose(hKey
);
642 dprintf("\t\tStatus=%x\n",Status
);
645 /* registry link create test */
649 OBJECT_ATTRIBUTES ObjectAttributes
;
650 UNICODE_STRING KeyName
,ValueName
;
652 KEY_VALUE_FULL_INFORMATION KeyValueInformation
[5];
655 dprintf("Create target key\n");
656 dprintf(" Key: \\Registry\\Machine\\SOFTWARE\\Reactos\n");
657 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\SOFTWARE\\Reactos");
658 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
660 Status
= NtCreateKey(&hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
661 ,0,NULL
, REG_OPTION_VOLATILE
,NULL
);
662 dprintf(" NtCreateKey() called (Status %lx)\n",Status
);
663 if (!NT_SUCCESS(Status
))
666 dprintf("Create target value\n");
667 dprintf(" Value: TestValue = 'Test String'\n");
668 RtlRosInitUnicodeStringFromLiteral(&ValueName
, L
"TestValue");
669 Status
=NtSetValueKey(hKey
,&ValueName
,0,REG_SZ
,(PVOID
)L
"TestString",22);
670 dprintf(" NtSetValueKey() called (Status %lx)\n",Status
);
671 if (!NT_SUCCESS(Status
))
674 dprintf("Close target key\n");
678 dprintf("Create link key\n");
679 dprintf(" Key: \\Registry\\Machine\\SOFTWARE\\Test\n");
680 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\SOFTWARE\\Test");
681 InitializeObjectAttributes(&ObjectAttributes
,
683 OBJ_CASE_INSENSITIVE
| OBJ_OPENLINK
,
686 Status
= NtCreateKey(&hKey
,
687 KEY_ALL_ACCESS
| KEY_CREATE_LINK
,
691 REG_OPTION_VOLATILE
| REG_OPTION_CREATE_LINK
,
693 dprintf(" NtCreateKey() called (Status %lx)\n",Status
);
694 if (!NT_SUCCESS(Status
))
697 dprintf("Create link value\n");
698 dprintf(" Value: SymbolicLinkValue = '\\Registry\\Machine\\SOFTWARE\\Reactos'\n");
699 RtlRosInitUnicodeStringFromLiteral(&ValueName
, L
"SymbolicLinkValue");
700 Status
=NtSetValueKey(hKey
,&ValueName
,0,REG_LINK
,(PVOID
)L
"\\Registry\\Machine\\SOFTWARE\\Reactos",68);
701 dprintf(" NtSetValueKey() called (Status %lx)\n",Status
);
702 if (!NT_SUCCESS(Status
))
704 dprintf("Creating link value failed! Test failed!\n");
709 dprintf("Close link key\n");
712 dprintf("Open link key\n");
713 dprintf(" Key: \\Registry\\Machine\\SOFTWARE\\Test\n");
714 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\SOFTWARE\\Test");
715 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
717 Status
= NtCreateKey(&hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
718 ,0,NULL
, REG_OPTION_VOLATILE
, NULL
);
719 dprintf(" NtCreateKey() called (Status %lx)\n",Status
);
720 if (!NT_SUCCESS(Status
))
723 dprintf("Query value\n");
724 dprintf(" Value: TestValue\n");
725 RtlRosInitUnicodeStringFromLiteral(&ValueName
, L
"TestValue");
726 Status
=NtQueryValueKey(hKey
,
728 KeyValueFullInformation
,
729 &KeyValueInformation
[0],
730 sizeof(KeyValueInformation
),
732 dprintf(" NtQueryValueKey() called (Status %lx)\n",Status
);
733 if (Status
== STATUS_SUCCESS
)
735 dprintf(" Value: Type %d DataLength %d NameLength %d Name '",
736 KeyValueInformation
[0].Type
,
737 KeyValueInformation
[0].DataLength
,
738 KeyValueInformation
[0].NameLength
);
739 for (i
=0; i
< KeyValueInformation
[0].NameLength
/ sizeof(WCHAR
); i
++)
740 dprintf("%C",KeyValueInformation
[0].Name
[i
]);
742 if (KeyValueInformation
[0].Type
== REG_SZ
)
743 dprintf(" Value '%S'\n",
744 KeyValueInformation
[0].Name
+1
745 +KeyValueInformation
[0].NameLength
/2);
748 dprintf("Close link key\n");
751 dprintf("Test successful!\n");
754 /* registry link delete test */
758 OBJECT_ATTRIBUTES ObjectAttributes
;
759 UNICODE_STRING KeyName
,ValueName
;
762 dprintf("Open link key\n");
763 dprintf(" Key: \\Registry\\Machine\\SOFTWARE\\Test\n");
764 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\SOFTWARE\\Test");
765 InitializeObjectAttributes(&ObjectAttributes
,
767 OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
| OBJ_OPENLINK
,
770 Status
= NtCreateKey(&hKey
,
775 REG_OPTION_VOLATILE
| REG_OPTION_OPEN_LINK
,
777 dprintf(" NtCreateKey() called (Status %lx)\n",Status
);
778 if (!NT_SUCCESS(Status
))
780 dprintf("Could not open the link key. Please run the link create test first!\n");
784 dprintf("Delete link value\n");
785 RtlRosInitUnicodeStringFromLiteral(&ValueName
, L
"SymbolicLinkValue");
786 Status
= NtDeleteValueKey(hKey
,
788 dprintf(" NtDeleteValueKey() called (Status %lx)\n",Status
);
790 dprintf("Delete link key\n");
791 Status
=NtDeleteKey(hKey
);
792 dprintf(" NtDeleteKey() called (Status %lx)\n",Status
);
794 dprintf("Close link key\n");
801 OBJECT_ATTRIBUTES ObjectAttributes
;
802 UNICODE_STRING KeyName
;
805 TOKEN_PRIVILEGES NewPrivileges
;
809 Status
=NtOpenProcessToken(GetCurrentProcess()
810 ,TOKEN_ADJUST_PRIVILEGES
,&Token
);
811 // ,TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&Token);
812 dprintf("\t\t\t\tStatus =%x\n",Status
);
813 // bRes=LookupPrivilegeValueA(NULL,SE_RESTORE_NAME,&Luid);
814 // dprintf("\t\t\t\tbRes =%x\n",bRes);
815 NewPrivileges
.PrivilegeCount
= 1;
816 NewPrivileges
.Privileges
[0].Luid
= Luid
;
817 // NewPrivileges.Privileges[0].Luid.u.LowPart=18;
818 // NewPrivileges.Privileges[0].Luid.u.HighPart=0;
819 NewPrivileges
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
821 // Status = NtAdjustPrivilegesToken(
822 bRes
= AdjustTokenPrivileges(
830 dprintf("\t\t\t\tbRes =%x\n",bRes
);
832 // Status=NtClose(Token);
833 // dprintf("\t\t\t\tStatus =%x\n",Status);
836 RtlRosInitUnicodeStringFromLiteral(&KeyName
,L
"test5");
837 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
839 Status
= NtLoadKey((HANDLE
)HKEY_LOCAL_MACHINE
,&ObjectAttributes
);
840 dprintf("\t\t\t\tStatus =%x\n",Status
);
841 dwError
=RegLoadKey(HKEY_LOCAL_MACHINE
,"def"
843 dprintf("\t\t\t\tdwError =%x\n",dwError
);
845 dprintf("NtOpenKey \\Registry\\Machine : ");
846 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine");
847 InitializeObjectAttributes(&ObjectAttributes
,
849 OBJ_CASE_INSENSITIVE
,
852 Status
=NtOpenKey( &hKey
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
853 dprintf("\t\t\tStatus =%x\n",Status
);
854 RtlRosInitUnicodeStringFromLiteral(&KeyName
,L
"test5");
855 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
857 Status
= NtLoadKey(hKey
,&ObjectAttributes
);
858 dprintf("\t\t\t\tStatus =%x\n",Status
);
863 HANDLE hKey
= NULL
, hKey1
;
864 OBJECT_ATTRIBUTES ObjectAttributes
;
866 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry");
867 ULONG Index
,Length
,i
;
868 KEY_BASIC_INFORMATION KeyInformation
[5];
869 KEY_VALUE_FULL_INFORMATION KeyValueInformation
[5];
871 dprintf("NtOpenKey \\Registry : ");
872 InitializeObjectAttributes(&ObjectAttributes
,
874 OBJ_CASE_INSENSITIVE
,
877 Status
=NtOpenKey( &hKey1
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
878 dprintf("\t\t\t\tStatus =%x\n",Status
);
880 dprintf("NtQueryKey : ");
881 Status
= NtQueryKey(hKey1
, KeyBasicInformation
, &KeyInformation
[0], sizeof(KeyInformation
), &Length
);
882 dprintf("\t\t\t\t\tStatus =%x\n",Status
);
883 if (Status
== STATUS_SUCCESS
) {
884 dprintf("\tKey Name = ");
885 for (i
=0;i
<KeyInformation
[0].NameLength
/2;i
++)
886 dprintf("%C",KeyInformation
[0].Name
[i
]);
890 dprintf("NtEnumerateKey : \n");
892 while (Status
== STATUS_SUCCESS
) {
893 Status
= NtEnumerateKey(hKey1
,Index
++,KeyBasicInformation
,&KeyInformation
[0], sizeof(KeyInformation
),&Length
);
894 if (Status
== STATUS_SUCCESS
) {
895 dprintf("\tSubKey Name = ");
896 for (i
= 0; i
< KeyInformation
[0].NameLength
/ 2; i
++)
897 dprintf("%C",KeyInformation
[0].Name
[i
]);
901 dprintf("NtClose : ");
902 Status
= NtClose( hKey1
);
903 dprintf("\t\t\t\t\tStatus =%x\n",Status
);
905 NtClose(hKey
); // RobD - hKey unused so-far, should this have been hKey1 ???
907 dprintf("NtOpenKey \\Registry\\Machine : ");
908 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine");
909 InitializeObjectAttributes(&ObjectAttributes
,
911 OBJ_CASE_INSENSITIVE
,
914 Status
= NtOpenKey(&hKey1
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
915 dprintf("\t\t\tStatus =%x\n",Status
);
917 //Status of c0000001 opening \Registry\Machine\System\CurrentControlSet\Services\Tcpip\Linkage
919 // dprintf("NtOpenKey System\\CurrentControlSet\\Services\\Tcpip : ");
920 // RtlRosInitUnicodeStringFromLiteral(&KeyName, L"System\\CurrentControlSet\\Services\\Tcpip");
922 dprintf("NtOpenKey System\\ControlSet001\\Services\\Tcpip\\Parameters : ");
923 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"System\\ControlSet001\\Services\\Tcpip\\Parameters");
925 dprintf("NtOpenKey System\\CurrentControlSet\\Services\\Tcpip : ");
926 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"System\\CurrentControlSet\\Services\\Tcpip");
928 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
, hKey1
, NULL
);
929 Status
= NtOpenKey(&hKey
, KEY_READ
, &ObjectAttributes
);
930 dprintf("\t\t\tStatus =%x\n",Status
);
932 dprintf("NtQueryValueKey : ");
933 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"NameServer");
934 Status
= NtQueryValueKey(hKey
, &KeyName
, KeyValueFullInformation
, &KeyValueInformation
[0], sizeof(KeyValueInformation
), &Length
);
935 dprintf("\t\t\t\tStatus =%x\n",Status
);
936 if (Status
== STATUS_SUCCESS
) {
937 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
938 ,KeyValueInformation
[0].DataOffset
939 ,KeyValueInformation
[0].DataLength
940 ,KeyValueInformation
[0].NameLength
);
941 for (i
= 0; i
< 10 && i
< KeyValueInformation
[0].NameLength
/ 2; i
++)
942 dprintf("%C", KeyValueInformation
[0].Name
[i
]);
944 dprintf("\t\tType = %d\n", KeyValueInformation
[0].Type
);
945 if (KeyValueInformation
[0].Type
== REG_SZ
)
946 //dprintf("\t\tValue = %S\n", KeyValueInformation[0].Name + 1 + KeyValueInformation[0].NameLength / 2);
947 dprintf("\t\tValue = %S\n", KeyValueInformation
[0].Name
+ KeyValueInformation
[0].NameLength
/ 2);
949 dprintf("NtEnumerateValueKey : \n");
951 while (Status
== STATUS_SUCCESS
) {
952 Status
= NtEnumerateValueKey(hKey
, Index
++, KeyValueFullInformation
, &KeyValueInformation
[0], sizeof(KeyValueInformation
), &Length
);
953 if (Status
== STATUS_SUCCESS
) {
954 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
955 ,KeyValueInformation
[0].DataOffset
956 ,KeyValueInformation
[0].DataLength
957 ,KeyValueInformation
[0].NameLength
);
958 for (i
= 0; i
< KeyValueInformation
[0].NameLength
/ 2; i
++)
959 dprintf("%C", KeyValueInformation
[0].Name
[i
]);
960 dprintf(", Type = %d\n", KeyValueInformation
[0].Type
);
961 if (KeyValueInformation
[0].Type
== REG_SZ
)
962 dprintf("\t\tValue = %S\n", ((char*)&KeyValueInformation
[0]+KeyValueInformation
[0].DataOffset
));
963 if (KeyValueInformation
[0].Type
== REG_DWORD
)
964 dprintf("\t\tValue = %X\n", *((DWORD
*)((char*)&KeyValueInformation
[0]+KeyValueInformation
[0].DataOffset
)));
967 dprintf("NtClose : ");
968 Status
= NtClose(hKey
);
969 dprintf("\t\t\t\t\tStatus =%x\n", Status
);
975 int main(int argc
, char* argv
[])
981 InputHandle
= GetStdHandle(STD_INPUT_HANDLE
);
982 OutputHandle
= GetStdHandle(STD_OUTPUT_HANDLE
);
985 dprintf("choose test :\n");
986 dprintf(" 0 = Exit\n");
987 dprintf(" 1 = Create key\n");
988 dprintf(" 2 = Delete key\n");
989 dprintf(" 3 = Enumerate key\n");
990 dprintf(" 4 = Set value (REG_SZ)\n");
991 dprintf(" 5 = Set value (REG_DWORD)\n");
992 dprintf(" 6 = Delete value\n");
993 dprintf(" 7 = Enumerate value\n");
994 ReadConsoleA(InputHandle
, Buffer
, 3, &Result
, NULL
) ;
1025 EnumerateValueTest();