12 void dprintf(char* fmt
, ...)
18 vsprintf(buffer
,fmt
,args
);
19 WriteConsoleA(OutputHandle
, buffer
, strlen(buffer
), NULL
, NULL
);
23 void do_enumeratekey(PWSTR Name
)
26 KEY_BASIC_INFORMATION KeyInformation
[5];
28 OBJECT_ATTRIBUTES ObjectAttributes
;
30 UNICODE_STRING KeyName
;
32 RtlInitUnicodeString(&KeyName
, Name
);
33 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
35 Status
=NtOpenKey( &hKey1
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
36 dprintf("NtEnumerateKey : \n");
38 while(Status
== STATUS_SUCCESS
)
40 Status
=NtEnumerateKey(hKey1
,Index
++,KeyBasicInformation
41 ,&KeyInformation
[0], sizeof(KeyInformation
)
43 if(Status
== STATUS_SUCCESS
)
45 dprintf("\tSubKey Name = ");
46 for (i
=0;i
<KeyInformation
[0].NameLength
/2;i
++)
47 dprintf("%C",KeyInformation
[0].Name
[i
]);
55 void CreateKeyTest(void)
58 OBJECT_ATTRIBUTES ObjectAttributes
;
60 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\testkey");
62 dprintf("Create key '\\Registry\\Machine\\Software\\testkey':\n");
64 InitializeObjectAttributes(&ObjectAttributes
,
69 dprintf("NtCreateKey:\n");
70 Status
= NtCreateKey(&hKey
,
75 REG_OPTION_NON_VOLATILE
,
77 dprintf(" Status = %lx\n",Status
);
78 if (NT_SUCCESS(Status
))
85 void DeleteKeyTest(void)
87 OBJECT_ATTRIBUTES ObjectAttributes
;
88 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\testkey");
92 dprintf("Delete key '\\Registry\\Machine\\Software\\testkey':\n");
94 InitializeObjectAttributes(&ObjectAttributes
,
99 dprintf("NtOpenKey:\n");
100 Status
= NtOpenKey(&hKey
,
103 dprintf(" Status = %lx\n",Status
);
104 if (!NT_SUCCESS(Status
))
107 dprintf("NtDeleteKey:\n");
108 Status
= NtDeleteKey(hKey
);
109 dprintf(" Status = %lx\n",Status
);
114 void EnumerateKeyTest(void)
117 OBJECT_ATTRIBUTES ObjectAttributes
;
119 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software");
123 KEY_BASIC_INFORMATION KeyInformation
[5];
125 dprintf("Enumerate key '\\Registry\\Machine\\Software':\n");
127 InitializeObjectAttributes(&ObjectAttributes
,
129 OBJ_CASE_INSENSITIVE
,
132 dprintf("NtOpenKey:\n");
133 Status
= NtOpenKey(&hKey
,
136 dprintf(" Status = %lx\n", Status
);
137 if (!NT_SUCCESS(Status
))
140 dprintf("NtQueryKey:\n");
141 Status
= NtQueryKey(hKey
,
144 sizeof(KeyInformation
),
146 dprintf(" Status = %lx\n", Status
);
147 if (NT_SUCCESS(Status
))
149 dprintf("\tKey Name = ");
150 for (i
= 0; i
< KeyInformation
[0].NameLength
/ 2; i
++)
151 dprintf("%C", KeyInformation
[0].Name
[i
]);
155 dprintf("NtEnumerateKey:\n");
157 while(NT_SUCCESS(Status
))
159 Status
= NtEnumerateKey(hKey
,
163 sizeof(KeyInformation
),
165 if (NT_SUCCESS(Status
))
167 dprintf("\tSubKey Name = ");
168 for (i
= 0; i
< KeyInformation
[0].NameLength
/ 2; i
++)
169 dprintf("%C", KeyInformation
[0].Name
[i
]);
175 dprintf("NtClose:\n");
176 Status
= NtClose(hKey
);
177 dprintf(" Status = %lx\n", Status
);
181 void SetValueTest1(void)
184 OBJECT_ATTRIBUTES ObjectAttributes
;
185 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\testkey");
186 UNICODE_STRING ValueName
= RTL_CONSTANT_STRING(L
"TestValue");
189 dprintf("Create key '\\Registry\\Machine\\Software\\testkey':\n");
191 InitializeObjectAttributes(&ObjectAttributes
,
193 OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
,
196 dprintf("NtCreateKey:\n");
197 Status
= NtCreateKey(&hKey
,
202 REG_OPTION_NON_VOLATILE
,
204 dprintf(" Status = %lx\n",Status
);
205 if (!NT_SUCCESS(Status
))
209 dprintf("NtSetValueKey:\n");
210 Status
= NtSetValueKey(hKey
,
214 (PVOID
)L
"TestString",
216 dprintf(" Status = %lx\n",Status
);
222 void SetValueTest2(void)
225 OBJECT_ATTRIBUTES ObjectAttributes
;
226 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\testkey");
227 UNICODE_STRING ValueName
= RTL_CONSTANT_STRING(L
"TestValue");
230 dprintf("Create key '\\Registry\\Machine\\Software\\testkey':\n");
232 InitializeObjectAttributes(&ObjectAttributes
,
234 OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
,
237 dprintf("NtCreateKey:\n");
238 Status
= NtCreateKey(&hKey
,
243 REG_OPTION_NON_VOLATILE
,
245 dprintf(" Status = %lx\n",Status
);
246 if (!NT_SUCCESS(Status
))
249 dprintf("NtSetValueKey:\n");
250 Status
= NtSetValueKey(hKey
,
256 dprintf(" Status = %lx\n",Status
);
262 void DeleteValueTest(void)
264 OBJECT_ATTRIBUTES ObjectAttributes
;
265 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\testkey");
266 UNICODE_STRING ValueName
= RTL_CONSTANT_STRING(L
"TestValue");
270 dprintf("Open key '\\Registry\\Machine\\Software\\testkey':\n");
272 InitializeObjectAttributes(&ObjectAttributes
,
274 OBJ_CASE_INSENSITIVE
,
277 Status
=NtOpenKey(&KeyHandle
,
280 dprintf(" Status = %lx\n", Status
);
281 if (!NT_SUCCESS(Status
))
284 dprintf("Delete value:\n");
287 Status
= NtDeleteValueKey(KeyHandle
,
289 dprintf(" Status = %lx\n", Status
);
291 dprintf("Close key:\n");
292 Status
= NtClose(KeyHandle
);
293 dprintf(" Status = %lx\n", Status
);
297 void EnumerateValueTest(void)
299 KEY_VALUE_FULL_INFORMATION KeyValueInformation
[5];
300 OBJECT_ATTRIBUTES ObjectAttributes
;
301 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software\\testkey");
302 ULONG Index
,Length
,i
;
306 dprintf("Open key '\\Registry\\Machine\\Software\\testkey':\n");
308 InitializeObjectAttributes(&ObjectAttributes
,
310 OBJ_CASE_INSENSITIVE
,
313 Status
=NtOpenKey(&hKey
,
316 dprintf(" Status = %lx\n", Status
);
317 if (!NT_SUCCESS(Status
))
320 dprintf("Enumerate values:\n");
322 while (Status
== STATUS_SUCCESS
)
324 Status
= NtEnumerateValueKey(hKey
,
326 KeyValueFullInformation
,
327 &KeyValueInformation
[0],
328 sizeof(KeyValueInformation
),
330 if (Status
== STATUS_SUCCESS
)
332 dprintf(" Value:DO=%d, DL=%d, NL=%d, Name = ",
333 KeyValueInformation
[0].DataOffset
,
334 KeyValueInformation
[0].DataLength
,
335 KeyValueInformation
[0].NameLength
);
336 for (i
= 0; i
< KeyValueInformation
[0].NameLength
/ 2; i
++)
337 dprintf("%C", KeyValueInformation
[0].Name
[i
]);
338 dprintf(", Type = %d\n", KeyValueInformation
[0].Type
);
340 if (KeyValueInformation
[0].Type
== REG_SZ
)
341 dprintf(" Value = %S\n",
342 ((char*)&KeyValueInformation
[0]+KeyValueInformation
[0].DataOffset
));
344 if (KeyValueInformation
[0].Type
== REG_DWORD
)
345 dprintf(" Value = %X\n",
346 *((DWORD
*)((char*)&KeyValueInformation
[0]+KeyValueInformation
[0].DataOffset
)));
350 dprintf("NtClose:\n");
351 Status
= NtClose(hKey
);
352 dprintf(" Status = %lx\n", Status
);
360 HKEY hKey
= NULL
, hKey1
;
361 OBJECT_ATTRIBUTES ObjectAttributes
;
363 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry\\Machine\\Software");
364 ULONG Index
,Length
,i
;
365 KEY_BASIC_INFORMATION KeyInformation
[5];
368 dprintf("NtOpenKey \\Registry : ");
370 dprintf("NtOpenKey \\Registry\\Machine\\Software : ");
371 InitializeObjectAttributes(&ObjectAttributes
,
373 OBJ_CASE_INSENSITIVE
,
376 Status
=NtOpenKey( &hKey1
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
377 dprintf("\t\t\t\tStatus =%x\n",Status
);
380 dprintf("NtQueryKey : ");
381 Status
=NtQueryKey(hKey1
,KeyBasicInformation
382 ,&KeyInformation
[0], sizeof(KeyInformation
)
384 dprintf("\t\t\t\t\tStatus =%x\n",Status
);
385 if (Status
== STATUS_SUCCESS
)
387 dprintf("\tKey Name = ");
388 for (i
=0;i
<KeyInformation
[0].NameLength
/2;i
++)
389 dprintf("%C",KeyInformation
[0].Name
[i
]);
392 dprintf("NtEnumerateKey : \n");
394 while(Status
== STATUS_SUCCESS
)
396 Status
=NtEnumerateKey(hKey1
,Index
++,KeyBasicInformation
397 ,&KeyInformation
[0], sizeof(KeyInformation
)
399 if(Status
== STATUS_SUCCESS
)
401 dprintf("\tSubKey Name = ");
402 for (i
=0;i
<KeyInformation
[0].NameLength
/2;i
++)
403 dprintf("%C",KeyInformation
[0].Name
[i
]);
407 dprintf("NtClose : ");
408 Status
= NtClose( hKey1
);
409 dprintf("\t\t\t\t\tStatus =%x\n",Status
);
418 OBJECT_ATTRIBUTES ObjectAttributes
;
419 UNICODE_STRING KeyName
;
423 dprintf("NtCreateKey non volatile: \n");
424 dprintf(" \\Registry\\Machine\\Software\\test3reactos: ");
425 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\Software\\test3reactos");
426 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
428 Status
= NtCreateKey ( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
429 ,0,NULL
,REG_OPTION_NON_VOLATILE
,NULL
);
430 dprintf("\t\tStatus=%x\n",Status
);
433 dprintf("delete \\Registry\\Machine\\software\\test3reactos ?");
434 ReadConsoleA(InputHandle
, Buffer
, 3, &Result
, NULL
) ;
435 if (Buffer
[0] != 'y' && Buffer
[0] != 'Y') return;
437 dprintf("delete \\Registry\\Machine\\software\\test3reactos ?");
438 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\Software\\test3reactos");
439 InitializeObjectAttributes(&ObjectAttributes
,
441 OBJ_CASE_INSENSITIVE
,
444 dprintf("NtOpenKey : ");
445 Status
=NtOpenKey( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
);
446 dprintf("\t\t\t\tStatus =%x\n",Status
);
447 dprintf("NtDeleteKey : ");
448 Status
=NtDeleteKey(hKey
);
449 dprintf("\t\t\t\tStatus =%x\n",Status
);
455 HKEY hKey
= NULL
,hKey1
;
458 DWORD RegDataType
, RegDataSize
;
459 BOOL GlobalFifoEnable
;
461 DWORD RegDisposition
;
468 DWORD cchMaxValueName
;
469 DWORD cbMaxValueData
;
470 DWORD cbSecurityDescriptor
;
471 FILETIME ftLastWriteTime
;
472 SYSTEMTIME LastWriteTime
;
474 dprintf ("RegOpenKeyExW HKLM\\System\\Setup: ");
475 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
480 dprintf("\t\tdwError =%x\n",dwError
);
481 if (dwError
== ERROR_SUCCESS
)
483 dprintf("RegQueryInfoKeyW: ");
485 dwError
= RegQueryInfoKeyW(hKey1
486 , szClass
, &cchClass
, NULL
, &cSubKeys
487 , &cchMaxSubkey
, &cchMaxClass
, &cValues
, &cchMaxValueName
488 , &cbMaxValueData
, &cbSecurityDescriptor
, &ftLastWriteTime
);
489 dprintf ("\t\t\t\tdwError %x\n", dwError
);
490 FileTimeToSystemTime(&ftLastWriteTime
,&LastWriteTime
);
491 dprintf ("\tnb of subkeys=%d,last write : %d/%d/%d %d:%02.2d'%02.2d''%03.3d\n",cSubKeys
492 ,LastWriteTime
.wMonth
496 ,LastWriteTime
.wMinute
497 ,LastWriteTime
.wSecond
498 ,LastWriteTime
.wMilliseconds
503 dprintf ("RegOpenKeyExW: ");
504 dwError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
505 L
"System\\ControlSet001\\Services\\Serial",
509 dprintf ("\t\t\t\t\tdwError %x\n", dwError
);
510 RegDataSize
= sizeof(GlobalFifoEnable
);
511 if (dwError
== ERROR_SUCCESS
)
513 dprintf ("RegQueryValueExW: ");
514 dwError
= RegQueryValueExW(hKey
,
518 (PBYTE
)&GlobalFifoEnable
,
520 dprintf("\t\t\t\tdwError =%x\n",dwError
);
523 dprintf("\tValue:DT=%d, DS=%d, Value=%d\n"
529 dprintf ("RegCreateKeyExW: ");
530 dwError
= RegCreateKeyExW(hKey
,
531 L
"Parameters\\Serial001",
540 dprintf ("\t\t\t\tdwError %x\n", dwError
);
542 dprintf ("RegCreateKeyExW: ");
543 dwError
= RegCreateKeyExW (HKEY_LOCAL_MACHINE
,
544 L
"Software\\test4reactos\\test",
547 REG_OPTION_NON_VOLATILE
,
553 dprintf ("\t\t\t\tdwError %x ", dwError
);
554 dprintf ("dwDisposition %x\n", dwDisposition
);
555 if (dwError
== ERROR_SUCCESS
)
557 dprintf ("RegSetValueExW: ");
558 dwError
= RegSetValueExW (hKey
,
562 (BYTE
*)L
"TestString",
565 dprintf ("\t\t\t\tdwError %x\n", dwError
);
566 dprintf ("RegCloseKey: ");
567 dwError
= RegCloseKey (hKey
);
568 dprintf ("\t\t\t\t\tdwError %x\n", dwError
);
574 dprintf ("RegCreateKeyExW: ");
575 dwError
= RegCreateKeyExW (HKEY_LOCAL_MACHINE
,
585 dprintf ("\t\t\t\tdwError %x ", dwError
);
586 dprintf ("dwDisposition %x\n", dwDisposition
);
589 if (dwError
== ERROR_SUCCESS
)
591 dprintf("RegQueryInfoKeyW: ");
593 dwError
= RegQueryInfoKeyW(hKey
594 , szClass
, &cchClass
, NULL
, &cSubKeys
595 , &cchMaxSubkey
, &cchMaxClass
, &cValues
, &cchMaxValueName
596 , &cbMaxValueData
, &cbSecurityDescriptor
, &ftLastWriteTime
);
597 dprintf ("\t\t\t\tdwError %x\n", dwError
);
598 FileTimeToSystemTime(&ftLastWriteTime
,&LastWriteTime
);
599 dprintf ("\tnb of subkeys=%d,last write : %d/%d/%d %d:%02.2d'%02.2d''%03.3d\n",cSubKeys
600 ,LastWriteTime
.wMonth
604 ,LastWriteTime
.wMinute
605 ,LastWriteTime
.wSecond
606 ,LastWriteTime
.wMilliseconds
608 dprintf ("RegCloseKey: ");
609 dwError
= RegCloseKey (hKey
);
610 dprintf ("\t\t\t\t\tdwError %x\n", dwError
);
612 dprintf ("\nTests done...\n");
618 OBJECT_ATTRIBUTES ObjectAttributes
;
619 UNICODE_STRING KeyName
;
622 dprintf("NtOpenKey : \n");
623 dprintf(" \\Registry\\Machine\\Software\\reactos : ");
624 RtlRosInitUnicodeStringFromLiteral(&KeyName
,L
"\\Registry\\Machine\\Software\\reactos");
625 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
627 Status
=NtOpenKey( &hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
);
628 dprintf("\t\tStatus=%x\n",Status
);
629 dprintf("NtFlushKey : \n");
630 Status
= NtFlushKey(hKey
);
631 dprintf("\t\tStatus=%x\n",Status
);
632 dprintf("NtCloseKey : \n");
633 Status
=NtClose(hKey
);
634 dprintf("\t\tStatus=%x\n",Status
);
637 /* registry link create test */
641 OBJECT_ATTRIBUTES ObjectAttributes
;
642 UNICODE_STRING KeyName
,ValueName
;
644 KEY_VALUE_FULL_INFORMATION KeyValueInformation
[5];
647 dprintf("Create target key\n");
648 dprintf(" Key: \\Registry\\Machine\\SOFTWARE\\Reactos\n");
649 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\SOFTWARE\\Reactos");
650 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
652 Status
= NtCreateKey(&hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
653 ,0,NULL
, REG_OPTION_VOLATILE
,NULL
);
654 dprintf(" NtCreateKey() called (Status %lx)\n",Status
);
655 if (!NT_SUCCESS(Status
))
658 dprintf("Create target value\n");
659 dprintf(" Value: TestValue = 'Test String'\n");
660 RtlRosInitUnicodeStringFromLiteral(&ValueName
, L
"TestValue");
661 Status
=NtSetValueKey(hKey
,&ValueName
,0,REG_SZ
,(PVOID
)L
"TestString",22);
662 dprintf(" NtSetValueKey() called (Status %lx)\n",Status
);
663 if (!NT_SUCCESS(Status
))
666 dprintf("Close target key\n");
670 dprintf("Create link key\n");
671 dprintf(" Key: \\Registry\\Machine\\SOFTWARE\\Test\n");
672 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\SOFTWARE\\Test");
673 InitializeObjectAttributes(&ObjectAttributes
,
675 OBJ_CASE_INSENSITIVE
| OBJ_OPENLINK
,
678 Status
= NtCreateKey(&hKey
,
679 KEY_ALL_ACCESS
| KEY_CREATE_LINK
,
683 REG_OPTION_VOLATILE
| REG_OPTION_CREATE_LINK
,
685 dprintf(" NtCreateKey() called (Status %lx)\n",Status
);
686 if (!NT_SUCCESS(Status
))
689 dprintf("Create link value\n");
690 dprintf(" Value: SymbolicLinkValue = '\\Registry\\Machine\\SOFTWARE\\Reactos'\n");
691 RtlRosInitUnicodeStringFromLiteral(&ValueName
, L
"SymbolicLinkValue");
692 Status
=NtSetValueKey(hKey
,&ValueName
,0,REG_LINK
,(PVOID
)L
"\\Registry\\Machine\\SOFTWARE\\Reactos",68);
693 dprintf(" NtSetValueKey() called (Status %lx)\n",Status
);
694 if (!NT_SUCCESS(Status
))
696 dprintf("Creating link value failed! Test failed!\n");
701 dprintf("Close link key\n");
704 dprintf("Open link key\n");
705 dprintf(" Key: \\Registry\\Machine\\SOFTWARE\\Test\n");
706 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\SOFTWARE\\Test");
707 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
709 Status
= NtCreateKey(&hKey
, KEY_ALL_ACCESS
, &ObjectAttributes
710 ,0,NULL
, REG_OPTION_VOLATILE
, NULL
);
711 dprintf(" NtCreateKey() called (Status %lx)\n",Status
);
712 if (!NT_SUCCESS(Status
))
715 dprintf("Query value\n");
716 dprintf(" Value: TestValue\n");
717 RtlRosInitUnicodeStringFromLiteral(&ValueName
, L
"TestValue");
718 Status
=NtQueryValueKey(hKey
,
720 KeyValueFullInformation
,
721 &KeyValueInformation
[0],
722 sizeof(KeyValueInformation
),
724 dprintf(" NtQueryValueKey() called (Status %lx)\n",Status
);
725 if (Status
== STATUS_SUCCESS
)
727 dprintf(" Value: Type %d DataLength %d NameLength %d Name '",
728 KeyValueInformation
[0].Type
,
729 KeyValueInformation
[0].DataLength
,
730 KeyValueInformation
[0].NameLength
);
731 for (i
=0; i
< KeyValueInformation
[0].NameLength
/ sizeof(WCHAR
); i
++)
732 dprintf("%C",KeyValueInformation
[0].Name
[i
]);
734 if (KeyValueInformation
[0].Type
== REG_SZ
)
735 dprintf(" Value '%S'\n",
736 KeyValueInformation
[0].Name
+1
737 +KeyValueInformation
[0].NameLength
/2);
740 dprintf("Close link key\n");
743 dprintf("Test successful!\n");
746 /* registry link delete test */
750 OBJECT_ATTRIBUTES ObjectAttributes
;
751 UNICODE_STRING KeyName
,ValueName
;
754 dprintf("Open link key\n");
755 dprintf(" Key: \\Registry\\Machine\\SOFTWARE\\Test\n");
756 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine\\SOFTWARE\\Test");
757 InitializeObjectAttributes(&ObjectAttributes
,
759 OBJ_CASE_INSENSITIVE
| OBJ_OPENIF
| OBJ_OPENLINK
,
762 Status
= NtCreateKey(&hKey
,
767 REG_OPTION_VOLATILE
| REG_OPTION_OPEN_LINK
,
769 dprintf(" NtCreateKey() called (Status %lx)\n",Status
);
770 if (!NT_SUCCESS(Status
))
772 dprintf("Could not open the link key. Please run the link create test first!\n");
776 dprintf("Delete link value\n");
777 RtlRosInitUnicodeStringFromLiteral(&ValueName
, L
"SymbolicLinkValue");
778 Status
= NtDeleteValueKey(hKey
,
780 dprintf(" NtDeleteValueKey() called (Status %lx)\n",Status
);
782 dprintf("Delete link key\n");
783 Status
=NtDeleteKey(hKey
);
784 dprintf(" NtDeleteKey() called (Status %lx)\n",Status
);
786 dprintf("Close link key\n");
793 OBJECT_ATTRIBUTES ObjectAttributes
;
794 UNICODE_STRING KeyName
;
797 TOKEN_PRIVILEGES NewPrivileges
;
801 Status
=NtOpenProcessToken(GetCurrentProcess()
802 ,TOKEN_ADJUST_PRIVILEGES
,&Token
);
803 // ,TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&Token);
804 dprintf("\t\t\t\tStatus =%x\n",Status
);
805 // bRes=LookupPrivilegeValueA(NULL,SE_RESTORE_NAME,&Luid);
806 // dprintf("\t\t\t\tbRes =%x\n",bRes);
807 NewPrivileges
.PrivilegeCount
= 1;
808 NewPrivileges
.Privileges
[0].Luid
= Luid
;
809 // NewPrivileges.Privileges[0].Luid.u.LowPart=18;
810 // NewPrivileges.Privileges[0].Luid.u.HighPart=0;
811 NewPrivileges
.Privileges
[0].Attributes
= SE_PRIVILEGE_ENABLED
;
813 // Status = NtAdjustPrivilegesToken(
814 bRes
= AdjustTokenPrivileges(
822 dprintf("\t\t\t\tbRes =%x\n",bRes
);
824 // Status=NtClose(Token);
825 // dprintf("\t\t\t\tStatus =%x\n",Status);
828 RtlRosInitUnicodeStringFromLiteral(&KeyName
,L
"test5");
829 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
831 Status
= NtLoadKey(HKEY_LOCAL_MACHINE
,&ObjectAttributes
);
832 dprintf("\t\t\t\tStatus =%x\n",Status
);
833 dwError
=RegLoadKey(HKEY_LOCAL_MACHINE
,"def"
835 dprintf("\t\t\t\tdwError =%x\n",dwError
);
837 dprintf("NtOpenKey \\Registry\\Machine : ");
838 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine");
839 InitializeObjectAttributes(&ObjectAttributes
,
841 OBJ_CASE_INSENSITIVE
,
844 Status
=NtOpenKey( &hKey
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
845 dprintf("\t\t\tStatus =%x\n",Status
);
846 RtlRosInitUnicodeStringFromLiteral(&KeyName
,L
"test5");
847 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
849 Status
= NtLoadKey(hKey
,&ObjectAttributes
);
850 dprintf("\t\t\t\tStatus =%x\n",Status
);
855 HKEY hKey
= NULL
, hKey1
;
856 OBJECT_ATTRIBUTES ObjectAttributes
;
858 UNICODE_STRING KeyName
= RTL_CONSTANT_STRING(L
"\\Registry");
859 ULONG Index
,Length
,i
;
860 KEY_BASIC_INFORMATION KeyInformation
[5];
861 KEY_VALUE_FULL_INFORMATION KeyValueInformation
[5];
863 dprintf("NtOpenKey \\Registry : ");
864 InitializeObjectAttributes(&ObjectAttributes
,
866 OBJ_CASE_INSENSITIVE
,
869 Status
=NtOpenKey( &hKey1
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
870 dprintf("\t\t\t\tStatus =%x\n",Status
);
872 dprintf("NtQueryKey : ");
873 Status
= NtQueryKey(hKey1
, KeyBasicInformation
, &KeyInformation
[0], sizeof(KeyInformation
), &Length
);
874 dprintf("\t\t\t\t\tStatus =%x\n",Status
);
875 if (Status
== STATUS_SUCCESS
) {
876 dprintf("\tKey Name = ");
877 for (i
=0;i
<KeyInformation
[0].NameLength
/2;i
++)
878 dprintf("%C",KeyInformation
[0].Name
[i
]);
882 dprintf("NtEnumerateKey : \n");
884 while (Status
== STATUS_SUCCESS
) {
885 Status
= NtEnumerateKey(hKey1
,Index
++,KeyBasicInformation
,&KeyInformation
[0], sizeof(KeyInformation
),&Length
);
886 if (Status
== STATUS_SUCCESS
) {
887 dprintf("\tSubKey Name = ");
888 for (i
= 0; i
< KeyInformation
[0].NameLength
/ 2; i
++)
889 dprintf("%C",KeyInformation
[0].Name
[i
]);
893 dprintf("NtClose : ");
894 Status
= NtClose( hKey1
);
895 dprintf("\t\t\t\t\tStatus =%x\n",Status
);
897 NtClose(hKey
); // RobD - hKey unused so-far, should this have been hKey1 ???
899 dprintf("NtOpenKey \\Registry\\Machine : ");
900 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"\\Registry\\Machine");
901 InitializeObjectAttributes(&ObjectAttributes
,
903 OBJ_CASE_INSENSITIVE
,
906 Status
= NtOpenKey(&hKey1
, MAXIMUM_ALLOWED
, &ObjectAttributes
);
907 dprintf("\t\t\tStatus =%x\n",Status
);
909 //Status of c0000001 opening \Registry\Machine\System\CurrentControlSet\Services\Tcpip\Linkage
911 // dprintf("NtOpenKey System\\CurrentControlSet\\Services\\Tcpip : ");
912 // RtlRosInitUnicodeStringFromLiteral(&KeyName, L"System\\CurrentControlSet\\Services\\Tcpip");
914 dprintf("NtOpenKey System\\ControlSet001\\Services\\Tcpip\\Parameters : ");
915 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"System\\ControlSet001\\Services\\Tcpip\\Parameters");
917 dprintf("NtOpenKey System\\CurrentControlSet\\Services\\Tcpip : ");
918 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"System\\CurrentControlSet\\Services\\Tcpip");
920 InitializeObjectAttributes(&ObjectAttributes
, &KeyName
, OBJ_CASE_INSENSITIVE
, hKey1
, NULL
);
921 Status
= NtOpenKey(&hKey
, KEY_READ
, &ObjectAttributes
);
922 dprintf("\t\t\tStatus =%x\n",Status
);
924 dprintf("NtQueryValueKey : ");
925 RtlRosInitUnicodeStringFromLiteral(&KeyName
, L
"NameServer");
926 Status
= NtQueryValueKey(hKey
, &KeyName
, KeyValueFullInformation
, &KeyValueInformation
[0], sizeof(KeyValueInformation
), &Length
);
927 dprintf("\t\t\t\tStatus =%x\n",Status
);
928 if (Status
== STATUS_SUCCESS
) {
929 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
930 ,KeyValueInformation
[0].DataOffset
931 ,KeyValueInformation
[0].DataLength
932 ,KeyValueInformation
[0].NameLength
);
933 for (i
= 0; i
< 10 && i
< KeyValueInformation
[0].NameLength
/ 2; i
++)
934 dprintf("%C", KeyValueInformation
[0].Name
[i
]);
936 dprintf("\t\tType = %d\n", KeyValueInformation
[0].Type
);
937 if (KeyValueInformation
[0].Type
== REG_SZ
)
938 //dprintf("\t\tValue = %S\n", KeyValueInformation[0].Name + 1 + KeyValueInformation[0].NameLength / 2);
939 dprintf("\t\tValue = %S\n", KeyValueInformation
[0].Name
+ KeyValueInformation
[0].NameLength
/ 2);
941 dprintf("NtEnumerateValueKey : \n");
943 while (Status
== STATUS_SUCCESS
) {
944 Status
= NtEnumerateValueKey(hKey
, Index
++, KeyValueFullInformation
, &KeyValueInformation
[0], sizeof(KeyValueInformation
), &Length
);
945 if (Status
== STATUS_SUCCESS
) {
946 dprintf("\tValue:DO=%d, DL=%d, NL=%d, Name = "
947 ,KeyValueInformation
[0].DataOffset
948 ,KeyValueInformation
[0].DataLength
949 ,KeyValueInformation
[0].NameLength
);
950 for (i
= 0; i
< KeyValueInformation
[0].NameLength
/ 2; i
++)
951 dprintf("%C", KeyValueInformation
[0].Name
[i
]);
952 dprintf(", Type = %d\n", KeyValueInformation
[0].Type
);
953 if (KeyValueInformation
[0].Type
== REG_SZ
)
954 dprintf("\t\tValue = %S\n", ((char*)&KeyValueInformation
[0]+KeyValueInformation
[0].DataOffset
));
955 if (KeyValueInformation
[0].Type
== REG_DWORD
)
956 dprintf("\t\tValue = %X\n", *((DWORD
*)((char*)&KeyValueInformation
[0]+KeyValueInformation
[0].DataOffset
)));
959 dprintf("NtClose : ");
960 Status
= NtClose(hKey
);
961 dprintf("\t\t\t\t\tStatus =%x\n", Status
);
967 int main(int argc
, char* argv
[])
973 InputHandle
= GetStdHandle(STD_INPUT_HANDLE
);
974 OutputHandle
= GetStdHandle(STD_OUTPUT_HANDLE
);
977 dprintf("choose test :\n");
978 dprintf(" 0 = Exit\n");
979 dprintf(" 1 = Create key\n");
980 dprintf(" 2 = Delete key\n");
981 dprintf(" 3 = Enumerate key\n");
982 dprintf(" 4 = Set value (REG_SZ)\n");
983 dprintf(" 5 = Set value (REG_DWORD)\n");
984 dprintf(" 6 = Delete value\n");
985 dprintf(" 7 = Enumerate value\n");
986 ReadConsoleA(InputHandle
, Buffer
, 3, &Result
, NULL
) ;
1017 EnumerateValueTest();