Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. rtqval.c
  5. Abstract:
  6. NT level registry api test program, basic non-error paths.
  7. Do a query on a value.
  8. rtqval <KeyPath> <valuename> [infotypenumber] [bufferlength]
  9. Example:
  10. rtqval \REGISTRY\MACHINE\TEST\bigkey value1 1 100
  11. Author:
  12. Bryan Willman (bryanwi) 9-Apr-92
  13. Revision History:
  14. --*/
  15. #include "cmp.h"
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #define WORK_SIZE 1024
  20. void __cdecl main(int, char *);
  21. void processargs();
  22. UNICODE_STRING WorkName;
  23. WCHAR workbuffer[WORK_SIZE];
  24. UNICODE_STRING WorkName2;
  25. WCHAR workbuffer2[WORK_SIZE];
  26. UCHAR Buffer[1024*64];
  27. ULONG InfoType = KeyValueFullInformation;
  28. ULONG BufferSize = -1;
  29. void
  30. __cdecl main(
  31. int argc,
  32. char *argv[]
  33. )
  34. {
  35. NTSTATUS status;
  36. OBJECT_ATTRIBUTES ObjectAttributes;
  37. HANDLE BaseHandle;
  38. ULONG Sizes[] = { sizeof(KEY_VALUE_BASIC_INFORMATION),
  39. sizeof(KEY_VALUE_FULL_INFORMATION) };
  40. ULONG ResultLength;
  41. PKEY_VALUE_BASIC_INFORMATION pbasic;
  42. PKEY_VALUE_FULL_INFORMATION pfull;
  43. PKEY_VALUE_PARTIAL_INFORMATION ppartial;
  44. //
  45. // Process args
  46. //
  47. WorkName.MaximumLength = WORK_SIZE;
  48. WorkName.Length = 0L;
  49. WorkName.Buffer = &(workbuffer[0]);
  50. WorkName2.MaximumLength = WORK_SIZE;
  51. WorkName2.Length = 0L;
  52. WorkName2.Buffer = &(workbuffer2[0]);
  53. processargs(argc, argv);
  54. //
  55. // Set up and open KeyPath
  56. //
  57. printf("rtqkey: starting\n");
  58. InitializeObjectAttributes(
  59. &ObjectAttributes,
  60. &WorkName,
  61. 0,
  62. (HANDLE)NULL,
  63. NULL
  64. );
  65. ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
  66. status = NtOpenKey(
  67. &BaseHandle,
  68. KEY_QUERY_VALUE,
  69. &ObjectAttributes
  70. );
  71. if (!NT_SUCCESS(status)) {
  72. printf("rtqkey: t0: %08lx\n", status);
  73. exit(1);
  74. }
  75. //
  76. // make test call
  77. //
  78. RtlFillMemory((PVOID)&(Buffer[0]), 1024*64, 0xaa);
  79. if (BufferSize == -1) {
  80. BufferSize = Sizes[InfoType];
  81. }
  82. status = NtQueryValueKey(
  83. BaseHandle,
  84. &WorkName2,
  85. InfoType,
  86. (PVOID)&(Buffer[0]),
  87. BufferSize,
  88. &ResultLength
  89. );
  90. printf("status = %08lx ResultLength = %08lx\n", status, ResultLength);
  91. switch (InfoType) {
  92. case KeyValueBasicInformation:
  93. pbasic = (PKEY_VALUE_BASIC_INFORMATION)Buffer;
  94. printf("TitleIndex: %08lx\n", pbasic->TitleIndex);
  95. printf(" Type: %08lx\n", pbasic->Type);
  96. printf("NameLength: %08lx\n", pbasic->NameLength);
  97. printf(" Name: '%.*ws'\n", pbasic->NameLength/2, &(pbasic->Name));
  98. break;
  99. case KeyValueFullInformation:
  100. pfull = (PKEY_VALUE_FULL_INFORMATION)Buffer;
  101. printf("TitleIndex: %08lx\n", pfull->TitleIndex);
  102. printf(" Type: %08lx\n", pfull->Type);
  103. printf("DataOffset: %08lx\n", pfull->DataOffset);
  104. printf("DataLength: %08lx\n", pfull->DataLength);
  105. printf("NameLength: %08lx\n", pfull->NameLength);
  106. printf(" Name: '%.*ws'\n", pfull->NameLength/2, &(pfull->Name));
  107. printf(" Data: '%.*ws'\n", pfull->DataLength/2,
  108. ((PUCHAR)pfull + pfull->DataOffset) );
  109. break;
  110. case KeyValuePartialInformation:
  111. ppartial = (PKEY_VALUE_PARTIAL_INFORMATION)Buffer;
  112. printf("TitleIndex: %08lx\n", ppartial->TitleIndex);
  113. printf(" Type: %08lx\n", ppartial->Type);
  114. printf("DataLength: %08lx\n", ppartial->DataLength);
  115. printf(" Data: '%.*ws'\n", ppartial->DataLength/2,
  116. ((PUCHAR)&(ppartial->Data)));
  117. break;
  118. }
  119. NtClose(BaseHandle);
  120. exit(0);
  121. }
  122. void
  123. processargs(
  124. int argc,
  125. char *argv[]
  126. )
  127. {
  128. ANSI_STRING temp;
  129. if ( (argc < 2) )
  130. {
  131. printf("Usage: %s <KeyPath> [infotype] [bufferlen]\n",
  132. argv[0]);
  133. exit(1);
  134. }
  135. RtlInitAnsiString(
  136. &temp,
  137. argv[1]
  138. );
  139. RtlAnsiStringToUnicodeString(
  140. &WorkName,
  141. &temp,
  142. TRUE
  143. );
  144. RtlInitAnsiString(
  145. &temp,
  146. argv[2]
  147. );
  148. RtlAnsiStringToUnicodeString(
  149. &WorkName2,
  150. &temp,
  151. TRUE
  152. );
  153. if (argc > 3) {
  154. InfoType = atoi(argv[3]);
  155. }
  156. if (argc > 4) {
  157. BufferSize = atoi(argv[4]);
  158. }
  159. return;
  160. }