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.

249 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. enumtree.c
  5. Abstract:
  6. Performs a test of the file enumeration code.
  7. Author:
  8. Jim Schmidt (jimschm) 14-Jan-1998
  9. Revision History:
  10. <alias> <date> <comments>
  11. --*/
  12. #include "pch.h"
  13. VOID
  14. DumpValue (
  15. PCTSTR ValName,
  16. PBYTE Val,
  17. UINT ValSize,
  18. DWORD Type
  19. );
  20. VOID
  21. HelpAndExit (
  22. VOID
  23. )
  24. {
  25. printf ("Command line syntax:\n\n"
  26. "regdump <root> [-b]\n\n"
  27. "<root> Specifies root key to enumerate, such as HKCU\\Control Panel\n"
  28. "-b Forces keys to be dumped as binary values\n"
  29. );
  30. exit(0);
  31. }
  32. BOOL
  33. WINAPI
  34. MigUtil_Entry (
  35. HINSTANCE hinstDLL,
  36. DWORD fdwReason,
  37. LPVOID lpvReserved
  38. );
  39. HANDLE g_hHeap;
  40. HINSTANCE g_hInst;
  41. INT
  42. pCallMains (
  43. DWORD Reason
  44. )
  45. {
  46. if (!MigUtil_Entry (g_hInst, Reason, NULL)) {
  47. _ftprintf (stderr, TEXT("MigUtil_Entry error!\n"));
  48. return 254;
  49. }
  50. return 0;
  51. }
  52. INT
  53. __cdecl
  54. _tmain (
  55. INT argc,
  56. TCHAR *argv[]
  57. )
  58. {
  59. PCTSTR Root = NULL;
  60. INT i;
  61. REGTREE_ENUM e;
  62. REGVALUE_ENUM ev;
  63. PBYTE Data;
  64. BOOL AllBinary = FALSE;
  65. for (i = 1 ; i < argc ; i++) {
  66. if (argv[i][0] == TEXT('-') || argv[i][0] == TEXT('/')) {
  67. switch (tolower (argv[i][1])) {
  68. case TEXT('b'):
  69. if (AllBinary) {
  70. HelpAndExit();
  71. }
  72. AllBinary = TRUE;
  73. break;
  74. default:
  75. HelpAndExit();
  76. }
  77. } else if (!Root) {
  78. Root = argv[i];
  79. } else {
  80. HelpAndExit();
  81. }
  82. }
  83. if (!Root) {
  84. HelpAndExit();
  85. }
  86. //
  87. // Init migutil
  88. //
  89. g_hHeap = GetProcessHeap();
  90. g_hInst = GetModuleHandle (NULL);
  91. pCallMains (DLL_PROCESS_ATTACH);
  92. //
  93. // Enumerate via reg wrappers
  94. //
  95. if (EnumFirstRegKeyInTree (&e, Root)) {
  96. do {
  97. _tprintf (TEXT("%s\n"), e.FullKeyName);
  98. //
  99. // Enumerate all values
  100. //
  101. if (EnumFirstRegValue (&ev, e.CurrentKey->KeyHandle)) {
  102. do {
  103. Data = GetRegValueData (ev.KeyHandle, ev.ValueName);
  104. if (Data) {
  105. DumpValue (
  106. ev.ValueName,
  107. Data,
  108. ev.DataSize,
  109. AllBinary ? REG_BINARY : ev.Type
  110. );
  111. MemFree (g_hHeap, 0, Data);
  112. }
  113. } while (EnumNextRegValue (&ev));
  114. }
  115. } while (EnumNextRegKeyInTree (&e));
  116. } else {
  117. _ftprintf (stderr, TEXT("%s not found\n"), Root);
  118. }
  119. //
  120. // Terminate libs and exit
  121. //
  122. pCallMains (DLL_PROCESS_DETACH);
  123. return 0;
  124. }
  125. VOID
  126. DumpValue (
  127. PCTSTR ValName,
  128. PBYTE Val,
  129. UINT ValSize,
  130. DWORD Type
  131. )
  132. {
  133. PBYTE Array;
  134. UINT j, k, l;
  135. PCTSTR p;
  136. if (!ValName[0]) {
  137. if (!ValSize) {
  138. return;
  139. }
  140. ValName = TEXT("[Default Value]");
  141. }
  142. if (Type == REG_DWORD) {
  143. _tprintf (TEXT(" REG_DWORD %s=%u (0%Xh)\n"), ValName, *((DWORD *) Val), *((DWORD *) Val));
  144. } else if (Type == REG_SZ) {
  145. _tprintf (TEXT(" REG_SZ %s=%s\n"), ValName, Val);
  146. } else if (Type == REG_EXPAND_SZ) {
  147. _tprintf (TEXT(" REG_EXPAND_SZ %s=%s\n"), ValName, Val);
  148. } else if (Type == REG_MULTI_SZ) {
  149. _tprintf (TEXT(" REG_MULTI_SZ %s:\n"), ValName);
  150. p = (PCTSTR) Val;
  151. while (*p) {
  152. _tprintf (TEXT(" %s\n"), p);
  153. p = GetEndOfString (p) + 1;
  154. }
  155. _tprintf (TEXT("\n"));
  156. } else if (Type == REG_LINK) {
  157. _tprintf (TEXT(" REG_LINK %s=%s\n"), ValName, Val);
  158. } else {
  159. if (Type == REG_NONE) {
  160. _tprintf (TEXT(" REG_NONE %s"), ValName);
  161. } else if (Type == REG_BINARY) {
  162. _tprintf (TEXT(" REG_NONE %s"), ValName);
  163. } else {
  164. _tprintf (TEXT(" Unknown reg type %s"), ValName);
  165. }
  166. _tprintf (TEXT(" (%u byte%s)\n"), ValSize, ValSize == 1 ? "" : "s");
  167. Array = Val;
  168. for (j = 0 ; j < ValSize ; j += 16) {
  169. _tprintf(TEXT(" %04X "), j);
  170. l = min (j + 16, ValSize);
  171. for (k = j ; k < l ; k++) {
  172. _tprintf (TEXT("%02X "), Array[k]);
  173. }
  174. for ( ; k < j + 16 ; k++) {
  175. _tprintf (TEXT(" "));
  176. }
  177. for (k = j ; k < l ; k++) {
  178. _tprintf (TEXT("%c"), isprint(Array[k]) ? Array[k] : TEXT('.'));
  179. }
  180. _tprintf (TEXT("\n"));
  181. }
  182. _tprintf (TEXT("\n"));
  183. }
  184. }