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.

295 lines
6.2 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. "regdmp95 <win95path> <root> [-u:userpath] [-b]\n\n"
  27. "<win95path> Specifies path to Win95 %%windir%%\n"
  28. "<root> Specifies root key to enumerate\n"
  29. "-u Specifies optional path to user.dat (excluding file name)\n"
  30. "-b Force values to be displayed as binary\n"
  31. );
  32. exit(0);
  33. }
  34. BOOL
  35. WINAPI
  36. Win95Reg_Entry (
  37. IN HINSTANCE hinstDLL,
  38. IN DWORD dwReason,
  39. IN LPVOID lpv
  40. );
  41. BOOL
  42. WINAPI
  43. MigUtil_Entry (
  44. HINSTANCE hinstDLL,
  45. DWORD fdwReason,
  46. LPVOID lpvReserved
  47. );
  48. HANDLE g_hHeap;
  49. HINSTANCE g_hInst;
  50. INT
  51. pCallMains (
  52. DWORD Reason
  53. )
  54. {
  55. if (!MigUtil_Entry (g_hInst, Reason, NULL)) {
  56. _ftprintf (stderr, TEXT("MigUtil_Entry error!\n"));
  57. return 254;
  58. }
  59. if (!Win95Reg_Entry (g_hInst, Reason, NULL)) {
  60. _ftprintf (stderr, TEXT("Win95Reg_Entry error!\n"));
  61. return 254;
  62. }
  63. return 0;
  64. }
  65. INT
  66. __cdecl
  67. _tmain (
  68. INT argc,
  69. TCHAR *argv[]
  70. )
  71. {
  72. PCTSTR Path = NULL, Root = NULL;
  73. PCTSTR UserPath = NULL;
  74. INT i;
  75. BOOL EnumFlag = TRUE;
  76. REGTREE_ENUM e;
  77. REGVALUE_ENUM ev;
  78. PBYTE Data;
  79. BOOL AllBinary = FALSE;
  80. for (i = 1 ; i < argc ; i++) {
  81. if (argv[i][0] == TEXT('-') || argv[i][0] == TEXT('/')) {
  82. switch (tolower (argv[i][1])) {
  83. case TEXT('b'):
  84. AllBinary = TRUE;
  85. break;
  86. case TEXT('u'):
  87. if (UserPath) {
  88. HelpAndExit();
  89. }
  90. if (argv[i][2] == TEXT(':')) {
  91. UserPath = &argv[i][3];
  92. } else {
  93. i++;
  94. if (i == argc) {
  95. HelpAndExit();
  96. }
  97. UserPath = argv[i];
  98. }
  99. break;
  100. default:
  101. HelpAndExit();
  102. }
  103. } else if (!Path) {
  104. Path = argv[i];
  105. } else if (!Root) {
  106. Root = argv[i];
  107. } else {
  108. HelpAndExit();
  109. }
  110. }
  111. if (!Root) {
  112. HelpAndExit();
  113. }
  114. //
  115. // Init migutil and win95reg
  116. //
  117. g_hHeap = GetProcessHeap();
  118. g_hInst = GetModuleHandle (NULL);
  119. pCallMains (DLL_PROCESS_ATTACH);
  120. //
  121. // Map in the Win95 registry
  122. //
  123. if (Win95RegInit (Path, TRUE) != ERROR_SUCCESS) {
  124. _ftprintf (stderr, TEXT("Can't map in Win98 registry at %s\n"), Path);
  125. EnumFlag = FALSE;
  126. } else {
  127. if (UserPath) {
  128. if (Win95RegSetCurrentUser (NULL, UserPath, NULL) != ERROR_SUCCESS) {
  129. _ftprintf (stderr, TEXT("Can't map in Win95 user hive path %s\n"), UserPath);
  130. EnumFlag = FALSE;
  131. }
  132. }
  133. }
  134. if (EnumFlag) {
  135. if (EnumFirstRegKeyInTree95 (&e, Root)) {
  136. do {
  137. _tprintf (TEXT("%s\n"), e.FullKeyName);
  138. //
  139. // Enumerate all values
  140. //
  141. if (EnumFirstRegValue95 (&ev, e.CurrentKey->KeyHandle)) {
  142. do {
  143. Data = GetRegValueData95 (ev.KeyHandle, ev.ValueName);
  144. if (Data) {
  145. DumpValue (
  146. ev.ValueName,
  147. Data,
  148. ev.DataSize,
  149. AllBinary ? REG_BINARY : ev.Type
  150. );
  151. MemFree (g_hHeap, 0, Data);
  152. }
  153. } while (EnumNextRegValue95 (&ev));
  154. }
  155. } while (EnumNextRegKeyInTree95 (&e));
  156. } else {
  157. _ftprintf (stderr, TEXT("%s not found\n"), Root);
  158. }
  159. }
  160. //
  161. // Terminate libs and exit
  162. //
  163. pCallMains (DLL_PROCESS_DETACH);
  164. return 0;
  165. }
  166. VOID
  167. DumpValue (
  168. PCTSTR ValName,
  169. PBYTE Val,
  170. UINT ValSize,
  171. DWORD Type
  172. )
  173. {
  174. PBYTE Array;
  175. UINT j, k, l;
  176. PCTSTR p;
  177. if (!ValName[0]) {
  178. if (!ValSize) {
  179. return;
  180. }
  181. ValName = TEXT("[Default Value]");
  182. }
  183. if (Type == REG_DWORD) {
  184. _tprintf (TEXT(" REG_DWORD %s=%u (0%Xh)\n"), ValName, *((DWORD *) Val), *((DWORD *) Val));
  185. } else if (Type == REG_SZ) {
  186. _tprintf (TEXT(" REG_SZ %s=%s\n"), ValName, Val);
  187. } else if (Type == REG_EXPAND_SZ) {
  188. _tprintf (TEXT(" REG_EXPAND_SZ %s=%s\n"), ValName, Val);
  189. } else if (Type == REG_MULTI_SZ) {
  190. _tprintf (TEXT(" REG_MULTI_SZ %s:\n"), ValName);
  191. p = (PCTSTR) Val;
  192. while (*p) {
  193. _tprintf (TEXT(" %s\n"), p);
  194. p = GetEndOfString (p) + 1;
  195. }
  196. _tprintf (TEXT("\n"));
  197. } else if (Type == REG_LINK) {
  198. _tprintf (TEXT(" REG_LINK %s=%s\n"), ValName, Val);
  199. } else {
  200. if (Type == REG_NONE) {
  201. _tprintf (TEXT(" REG_NONE %s"), ValName);
  202. } else if (Type == REG_BINARY) {
  203. _tprintf (TEXT(" REG_NONE %s"), ValName);
  204. } else {
  205. _tprintf (TEXT(" Unknown reg type %s"), ValName);
  206. }
  207. _tprintf (TEXT(" (%u byte%s)\n"), ValSize, ValSize == 1 ? "" : "s");
  208. Array = Val;
  209. for (j = 0 ; j < ValSize ; j += 16) {
  210. _tprintf(TEXT(" %04X "), j);
  211. l = min (j + 16, ValSize);
  212. for (k = j ; k < l ; k++) {
  213. _tprintf (TEXT("%02X "), Array[k]);
  214. }
  215. for ( ; k < j + 16 ; k++) {
  216. _tprintf (TEXT(" "));
  217. }
  218. for (k = j ; k < l ; k++) {
  219. _tprintf (TEXT("%c"), isprint(Array[k]) ? Array[k] : TEXT('.'));
  220. }
  221. _tprintf (TEXT("\n"));
  222. }
  223. _tprintf (TEXT("\n"));
  224. }
  225. }