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.

306 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. <TODO: fill in abstract>
  7. Author:
  8. TODO: <full name> (<alias>) <date>
  9. Revision History:
  10. <full name> (<alias>) <date> <comments>
  11. --*/
  12. #include "pch.h"
  13. #include <conio.h>
  14. HANDLE g_hHeap;
  15. HINSTANCE g_hInst;
  16. BOOL
  17. pCallEntryPoints (
  18. DWORD Reason
  19. )
  20. {
  21. //
  22. // Initialize the common libs
  23. //
  24. if (Reason == DLL_PROCESS_ATTACH) {
  25. UtInitialize (NULL);
  26. if (!RegInitialize ()) {
  27. return FALSE;
  28. }
  29. } else {
  30. RegTerminate();
  31. UtTerminate ();
  32. }
  33. return TRUE;
  34. }
  35. BOOL
  36. Init (
  37. VOID
  38. )
  39. {
  40. g_hHeap = GetProcessHeap();
  41. g_hInst = GetModuleHandle (NULL);
  42. return pCallEntryPoints (DLL_PROCESS_ATTACH);
  43. }
  44. VOID
  45. Terminate (
  46. VOID
  47. )
  48. {
  49. pCallEntryPoints (DLL_PROCESS_DETACH);
  50. }
  51. VOID
  52. HelpAndExit (
  53. VOID
  54. )
  55. {
  56. //
  57. // This routine is called whenever command line args are wrong
  58. //
  59. fprintf (
  60. stderr,
  61. "Command Line Syntax:\n\n"
  62. //
  63. // TODO: Describe command line syntax(es), indent 2 spaces
  64. //
  65. " regenum [/N] [/S] [/W] [/F] [/L:MaxSubLevel] [/X] <Node Pattern> <Leaf Pattern>\n"
  66. "\nDescription:\n\n"
  67. //
  68. // TODO: Describe tool, indent 2 spaces
  69. //
  70. " Enumerates the part of registry that matches <Pattern>.\n"
  71. " Uses C:\\exclude.inf if present and /X not specified to determine what keys/values\n"
  72. " are excluded.\n"
  73. "\nArguments:\n\n"
  74. //
  75. // TODO: Describe args, indent 2 spaces, say optional if necessary
  76. //
  77. " /N Specifies exclusion of key names from enumeration; optional\n"
  78. " /S Specifies sub-keys to be enumerated before values for any key; optional\n"
  79. " /W Specifies enumeration should be width-first; optional\n"
  80. " /F Specifies output should use \"key <value>\" format; optional\n"
  81. " /L:MaxSubLevel Specifies the maximum sub-level starting from the root of enum;\n"
  82. " -1 = all levels (default), 0 = only the root level etc.; optional\n"
  83. " /X Specifies to use exclusions in C:\\exclude.inf; optional\n"
  84. " <Pattern> Specifies the file/dir pattern; must have the form \"DirPattern <FilePattern>\"\n"
  85. " the <FilePattern> part is optional; quotes required if both parts are specified\n"
  86. );
  87. exit (1);
  88. }
  89. BOOL
  90. BuildExclusionList (
  91. IN PCTSTR FileName
  92. )
  93. {
  94. HINF h;
  95. INFCONTEXT ic;
  96. TCHAR buf[256];
  97. h = SetupOpenInfFile (FileName, NULL, INF_STYLE_WIN4 | INF_STYLE_OLDNT, NULL);
  98. if (h == INVALID_HANDLE_VALUE) {
  99. return FALSE;
  100. }
  101. if (SetupFindFirstLine (h, TEXT("RegKeys"), NULL, &ic)) {
  102. do {
  103. if (SetupGetStringField (&ic, 0, buf, DWSIZEOF (buf) / DWSIZEOF (TCHAR), NULL)) {
  104. //ElAdd (ELT_REGKEY, buf);
  105. }
  106. } while (SetupFindNextLine (&ic, &ic));
  107. }
  108. if (SetupFindFirstLine (h, TEXT("RegValues"), NULL, &ic)) {
  109. do {
  110. if (SetupGetStringField (&ic, 0, buf, DWSIZEOF (buf) / DWSIZEOF (TCHAR), NULL)) {
  111. //ElAdd (ELT_REGVALUE, buf);
  112. }
  113. } while (SetupFindNextLine (&ic, &ic));
  114. }
  115. SetupCloseInfFile (h);
  116. return TRUE;
  117. }
  118. BOOL
  119. RegEnumCallback (
  120. IN PREGNODE RegNode OPTIONAL
  121. )
  122. {
  123. BOOL b;
  124. if (!RegNode) {
  125. _ftprintf (stderr, TEXT("\nOut of memory\n"));
  126. return FALSE;
  127. }
  128. _ftprintf (stderr, TEXT("Error creating key node: %s; continue anyway ? (yn):"), RegNode->KeyName);
  129. b = _totupper(_getche ()) == TEXT('Y');
  130. _ftprintf (stderr, TEXT("\n"));
  131. return b;
  132. }
  133. INT
  134. __cdecl
  135. _tmain (
  136. INT argc,
  137. PCTSTR argv[]
  138. )
  139. {
  140. INT i;
  141. PCTSTR patternNode = NULL;
  142. PCTSTR patternLeaf = NULL;
  143. PTSTR p;
  144. PCTSTR level;
  145. BOOL enumKeyNames = TRUE;
  146. BOOL valuesFirst = TRUE;
  147. BOOL depthFirst = TRUE;
  148. BOOL nativeFormat = TRUE;
  149. UINT maxSubLevel = -1;
  150. BOOL exclusions = FALSE;
  151. INT pos;
  152. REGTREE_ENUM e;
  153. PCTSTR pattern;
  154. //
  155. // TODO: Parse command line here
  156. //
  157. if (argc < 2) {
  158. HelpAndExit ();
  159. }
  160. for (i = 1 ; i < argc ; i++) {
  161. if (argv[i][0] == TEXT('/') || argv[i][0] == TEXT('-')) {
  162. switch (_totlower (_tcsnextc (&argv[i][1]))) {
  163. case TEXT('x'):
  164. exclusions = TRUE;
  165. break;
  166. case TEXT('n'):
  167. enumKeyNames = FALSE;
  168. break;
  169. case TEXT('s'):
  170. valuesFirst = FALSE;
  171. break;
  172. case TEXT('w'):
  173. depthFirst = FALSE;
  174. break;
  175. case TEXT('f'):
  176. nativeFormat = FALSE;
  177. break;
  178. case TEXT('l'):
  179. if (argv[i][2] == TEXT(':')) {
  180. level = &argv[i][3];
  181. } else if (i + 1 < argc) {
  182. level = argv[++i];
  183. } else {
  184. HelpAndExit();
  185. }
  186. if (!_stscanf (level, TEXT("%ld%n"), &maxSubLevel, &pos) || level[pos]) {
  187. HelpAndExit();
  188. }
  189. break;
  190. default:
  191. HelpAndExit();
  192. }
  193. } else {
  194. //
  195. // Parse other args that don't require / or -
  196. //
  197. if (!patternNode) {
  198. patternNode = argv[i];
  199. } else if (!patternLeaf) {
  200. patternLeaf = argv[i];
  201. } else {
  202. HelpAndExit();
  203. }
  204. }
  205. }
  206. //
  207. // Begin processing
  208. //
  209. if (!Init()) {
  210. return 2;
  211. }
  212. if (!patternLeaf) {
  213. HelpAndExit ();
  214. }
  215. pattern = ObsBuildEncodedObjectStringEx (patternNode, patternLeaf, FALSE);
  216. //
  217. // TODO: Do work here
  218. //
  219. if (exclusions) {
  220. BuildExclusionList (TEXT("C:\\exclude.inf"));
  221. }
  222. if (EnumFirstRegObjectInTreeEx (
  223. &e,
  224. pattern,
  225. enumKeyNames,
  226. TRUE,
  227. valuesFirst,
  228. depthFirst,
  229. maxSubLevel,
  230. exclusions,
  231. FALSE,
  232. RegEnumDefaultCallback
  233. )) {
  234. do {
  235. _tprintf (
  236. TEXT("%s - %s\n"),
  237. nativeFormat ? e.NativeFullName : e.EncodedFullName,
  238. (e.Attributes & REG_ATTRIBUTE_KEY) ? TEXT("Key") : TEXT("Value")
  239. );
  240. } while (EnumNextRegObjectInTree (&e));
  241. }
  242. //
  243. // End of processing
  244. //
  245. if (exclusions) {
  246. ElRemoveAll ();
  247. }
  248. Terminate();
  249. return 0;
  250. }