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.

262 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. nttool.c
  5. Abstract:
  6. Implements a stub tool that is designed to run with NT-side
  7. upgrade code.
  8. Author:
  9. <full name> (<alias>) <date>
  10. Revision History:
  11. <alias> <date> <comments>
  12. --*/
  13. #include "pch.h"
  14. PBYTE
  15. FilterRegValue (
  16. IN PBYTE Data,
  17. IN DWORD DataSize,
  18. IN DWORD DataType,
  19. IN PCTSTR KeyForDbgMsg, OPTIONAL
  20. OUT PDWORD NewDataSize
  21. );
  22. VOID
  23. pFixUpMemDb2 (
  24. VOID
  25. );
  26. BOOL
  27. Init (
  28. VOID
  29. )
  30. {
  31. HINSTANCE hInstance;
  32. DWORD dwReason;
  33. PVOID lpReserved;
  34. //
  35. // Simulate DllMain
  36. //
  37. hInstance = GetModuleHandle (NULL);
  38. dwReason = DLL_PROCESS_ATTACH;
  39. lpReserved = NULL;
  40. //
  41. // Initialize DLL globals
  42. //
  43. if (!FirstInitRoutine (hInstance)) {
  44. return FALSE;
  45. }
  46. //
  47. // Initialize all libraries
  48. //
  49. if (!InitLibs (hInstance, dwReason, lpReserved)) {
  50. return FALSE;
  51. }
  52. //
  53. // Final initialization
  54. //
  55. if (!FinalInitRoutine ()) {
  56. return FALSE;
  57. }
  58. return TRUE;
  59. }
  60. VOID
  61. Terminate (
  62. VOID
  63. )
  64. {
  65. HINSTANCE hInstance;
  66. DWORD dwReason;
  67. PVOID lpReserved;
  68. //
  69. // Simulate DllMain
  70. //
  71. hInstance = GetModuleHandle (NULL);
  72. dwReason = DLL_PROCESS_DETACH;
  73. lpReserved = NULL;
  74. //
  75. // Call the cleanup routine that requires library APIs
  76. //
  77. FirstCleanupRoutine();
  78. //
  79. // Clean up all libraries
  80. //
  81. TerminateLibs (hInstance, dwReason, lpReserved);
  82. //
  83. // Do any remaining clean up
  84. //
  85. FinalCleanupRoutine();
  86. }
  87. VOID
  88. Test (
  89. IN PCTSTR CmdLine
  90. )
  91. {
  92. static PTSTR ValueData = NULL;
  93. DWORD NewSize;
  94. ValueData = ReuseAlloc (g_hHeap, ValueData, SizeOfString (CmdLine));
  95. StringCopy (ValueData, CmdLine);
  96. ValueData = (PTSTR) FilterRegValue (
  97. (PBYTE) ValueData,
  98. SizeOfString (ValueData),
  99. REG_SZ,
  100. TEXT("foo"),
  101. &NewSize
  102. );
  103. _tprintf (TEXT("[%s]\n"), ValueData);
  104. }
  105. INT
  106. __cdecl
  107. wmain (
  108. INT argc,
  109. WCHAR *argv[]
  110. )
  111. {
  112. if (!Init()) {
  113. wprintf (L"Unable to initialize!\n");
  114. return 255;
  115. }
  116. MemDbLoad (TEXT("c:\\public\\ntsetup.dat"));
  117. pFixUpMemDb2();
  118. Test (TEXT("C:\\WINDOWS\\PBRUSH.EXE"));
  119. Test (TEXT("C:\\WINDOWS\\SendTo\\Fax Recipient.lnk"));
  120. Test (TEXT("notepad C:\\WINDOWS\\ShellNew\\WORDPFCT.WPG"));
  121. Test (TEXT("c:\\command.com"));
  122. Test (TEXT("C:\\PROGRA~1\\NETMEE~1\\WB32.EXE"));
  123. Test (TEXT("C:\\WINDOWS\\Start Menu\\Programs\\Internet Explorer.lnk"));
  124. Test (TEXT("SCRNSAVE.EXE c:\\WINDOWS\\SYSTEM\\3D Text.scr"));
  125. Test (TEXT("SCRNSAVE.EXE \"c:\\WINDOWS\\SYSTEM\\3D Text.scr\""));
  126. Test (TEXT("c:\\WINDOWS\\MPLAYER.EXE FOO.WAV"));
  127. Test (TEXT("C:\\PROGRA~1\\ACCESS~1\\WORDPAD.EXE"));
  128. Test (TEXT("notepad,C:\\WINDOWS\\Start Menu\\Programs\\Internet Explorer.lnk"));
  129. Test (TEXT("TEST C:\\WINDOWS\\SYSTEM\\ICWSCRPT.EXE"));
  130. Test (TEXT("C:\\WINDOWS\\PBRUSH.EXE C:\\PROGRA~1\\ACCESS~1\\WORDPAD.EXE"));
  131. Test (TEXT("C:\\WINDOWS\\PBRUSH.EXE,C:\\PROGRA~1\\ACCESS~1\\WORDPAD.EXE"));
  132. Terminate();
  133. return 0;
  134. }
  135. PCTSTR
  136. pGetProfilePathForUser (
  137. IN PCTSTR User
  138. )
  139. {
  140. static TCHAR Path[MAX_TCHAR_PATH];
  141. wsprintf (Path, TEXT("c:\\windows\\profiles\\%s"), User);
  142. return Path;
  143. }
  144. VOID
  145. pFixUpDynamicPaths2 (
  146. PCTSTR Category
  147. )
  148. {
  149. MEMDB_ENUM e;
  150. TCHAR Pattern[MEMDB_MAX];
  151. PTSTR p;
  152. GROWBUFFER Roots = GROWBUF_INIT;
  153. MULTISZ_ENUM e2;
  154. TCHAR NewRoot[MEMDB_MAX];
  155. PCTSTR ProfilePath;
  156. //
  157. // Collect all the roots that need to be renamed
  158. //
  159. StringCopy (Pattern, Category);
  160. p = AppendWack (Pattern);
  161. StringCopy (p, TEXT("*"));
  162. if (MemDbEnumFirstValue (&e, Pattern, MEMDB_THIS_LEVEL_ONLY, MEMDB_ALL_BUT_PROXY)) {
  163. do {
  164. if (_tcsnextc (e.szName) == TEXT('>')) {
  165. StringCopy (p, e.szName);
  166. MultiSzAppend (&Roots, Pattern);
  167. }
  168. } while (MemDbEnumNextValue (&e));
  169. }
  170. //
  171. // Now change each root
  172. //
  173. if (EnumFirstMultiSz (&e2, (PCTSTR) Roots.Buf)) {
  174. do {
  175. //
  176. // Compute NewRoot
  177. //
  178. StringCopy (NewRoot, e2.CurrentString);
  179. p = _tcschr (NewRoot, TEXT('>'));
  180. MYASSERT (p);
  181. ProfilePath = pGetProfilePathForUser (_tcsinc (p));
  182. if (!ProfilePath) {
  183. DEBUGMSG ((DBG_WARNING, "Dynamic path for %s could not be resolved", e2.CurrentString));
  184. } else {
  185. StringCopy (p, ProfilePath);
  186. MemDbMoveTree (e2.CurrentString, NewRoot);
  187. }
  188. } while (EnumNextMultiSz (&e2));
  189. }
  190. FreeGrowBuffer (&Roots);
  191. }
  192. VOID
  193. pFixUpMemDb2 (
  194. VOID
  195. )
  196. {
  197. pFixUpDynamicPaths2 (MEMDB_CATEGORY_DATA);
  198. pFixUpDynamicPaths2 (MEMDB_CATEGORY_USERFILEMOVE_DEST);
  199. }