Leaked source code of windows server 2003
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.

199 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. rtqkey.c
  5. Abstract:
  6. NT level registry api test program, basic non-error paths.
  7. Do a query on a key.
  8. rtqkey <KeyPath> [infotypenumber] [bufferlength]
  9. Example:
  10. rtqkey \REGISTRY\MACHINE\TEST\bigkey 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. UCHAR Buffer[1024*64];
  25. ULONG InfoType = KeyFullInformation;
  26. ULONG BufferSize = -1;
  27. void
  28. __cdecl main(
  29. int argc,
  30. char *argv[]
  31. )
  32. {
  33. NTSTATUS status;
  34. OBJECT_ATTRIBUTES ObjectAttributes;
  35. HANDLE BaseHandle;
  36. ULONG Sizes[] = { sizeof(KEY_BASIC_INFORMATION),
  37. sizeof(KEY_NODE_INFORMATION),
  38. sizeof(KEY_FULL_INFORMATION) };
  39. ULONG ResultLength;
  40. PKEY_BASIC_INFORMATION pbasic;
  41. PKEY_NODE_INFORMATION pnode;
  42. PKEY_FULL_INFORMATION pfull;
  43. //
  44. // Process args
  45. //
  46. WorkName.MaximumLength = WORK_SIZE;
  47. WorkName.Length = 0L;
  48. WorkName.Buffer = &(workbuffer[0]);
  49. processargs(argc, argv);
  50. //
  51. // Set up and open KeyPath
  52. //
  53. printf("rtqkey: starting\n");
  54. InitializeObjectAttributes(
  55. &ObjectAttributes,
  56. &WorkName,
  57. 0,
  58. (HANDLE)NULL,
  59. NULL
  60. );
  61. ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE;
  62. status = NtOpenKey(
  63. &BaseHandle,
  64. KEY_QUERY_VALUE,
  65. &ObjectAttributes
  66. );
  67. if (!NT_SUCCESS(status)) {
  68. printf("rtqkey: t0: %08lx\n", status);
  69. exit(1);
  70. }
  71. //
  72. // make test call
  73. //
  74. RtlFillMemory((PVOID)&(Buffer[0]), 1024*64, 0xaa);
  75. if (BufferSize == -1) {
  76. BufferSize = Sizes[InfoType];
  77. }
  78. status = NtQueryKey(
  79. BaseHandle,
  80. InfoType,
  81. (PVOID)&(Buffer[0]),
  82. BufferSize,
  83. &ResultLength
  84. );
  85. printf("status = %08lx ResultLength = %08lx\n", status, ResultLength);
  86. switch (InfoType) {
  87. case KeyBasicInformation:
  88. pbasic = (PKEY_BASIC_INFORMATION)Buffer;
  89. printf("LastWriteTime: %08lx:%08lx\n", pbasic->LastWriteTime.HighPart,
  90. pbasic->LastWriteTime.LowPart);
  91. printf("TitleIndex: %08lx\n", pbasic->TitleIndex);
  92. printf("NameLength: %08lx\n", pbasic->NameLength);
  93. printf("Name: '%.*ws'\n", pbasic->NameLength/2, &(pbasic->Name));
  94. break;
  95. case KeyNodeInformation:
  96. pnode = (PKEY_NODE_INFORMATION)Buffer;
  97. printf("LastWriteTime: %08lx:%08lx\n", pnode->LastWriteTime.HighPart,
  98. pnode->LastWriteTime.LowPart);
  99. printf("TitleIndex: %08lx\n", pnode->TitleIndex);
  100. printf("ClassOffset: %08lx\n", pnode->ClassOffset);
  101. printf("ClassLength: %08lx\n", pnode->ClassLength);
  102. printf("NameLength: %08lx\n", pnode->NameLength);
  103. printf("Name: '%.*ws'\n", pnode->NameLength/2, &(pnode->Name));
  104. printf("Class: '%.*ws'\n", pnode->ClassLength/2,
  105. (PWSTR)((PUCHAR)pnode + pnode->ClassOffset));
  106. break;
  107. case KeyFullInformation:
  108. pfull = (PKEY_FULL_INFORMATION)Buffer;
  109. printf("LastWriteTime: %08lx:%08lx\n", pfull->LastWriteTime.HighPart,
  110. pfull->LastWriteTime.LowPart);
  111. printf("TitleIndex: %08lx\n", pfull->TitleIndex);
  112. printf("ClassOffset: %08lx\n", pfull->ClassOffset);
  113. printf("ClassLength: %08lx\n", pfull->ClassLength);
  114. printf("SubKeys: %08lx MaxNameLen: %08lx MaxClassLen: %08lx\n",
  115. pfull->SubKeys, pfull->MaxNameLen, pfull->MaxClassLen);
  116. printf(" Values: %08lx MaxValueNameLen: %08lx MaxValueDataLen: %08lx\n",
  117. pfull->Values, pfull->MaxValueNameLen, pfull->MaxValueDataLen);
  118. printf("Class: '%.*ws'\n", pfull->ClassLength/2, pfull->Class);
  119. break;
  120. }
  121. NtClose(BaseHandle);
  122. exit(0);
  123. }
  124. void
  125. processargs(
  126. int argc,
  127. char *argv[]
  128. )
  129. {
  130. ANSI_STRING temp;
  131. if ( (argc < 2) )
  132. {
  133. printf("Usage: %s <KeyPath> [infotype] [bufferlen]\n",
  134. argv[0]);
  135. exit(1);
  136. }
  137. RtlInitAnsiString(
  138. &temp,
  139. argv[1]
  140. );
  141. RtlAnsiStringToUnicodeString(
  142. &WorkName,
  143. &temp,
  144. TRUE
  145. );
  146. if (argc > 2) {
  147. InfoType = atoi(argv[2]);
  148. }
  149. if (argc > 3) {
  150. BufferSize = atoi(argv[3]);
  151. }
  152. return;
  153. }