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.

314 lines
5.9 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. This module will do the necessary things to setup initial registry for the redirection
  7. purpose.
  8. //
  9. // Test case scenario
  10. // 1. Open a ISN node and list content
  11. // 2. Create a ISN node do 1.
  12. // 3. Open a non ISN node and list
  13. // 4. Create a non ISN node and list content
  14. //
  15. Outstanding issue:
  16. reflector: If Key has been created on one side, we can reflect that on the other side.
  17. Deletion: Without any additional attribute it's impossible to track.
  18. Author:
  19. ATM Shafiqul Khalid (askhalid) 18-Nov-1999
  20. Revision History:
  21. --*/
  22. #include <windows.h>
  23. #include <windef.h>
  24. #include <stdio.h>
  25. #include "wow64reg.h"
  26. #include <assert.h>
  27. #include "..\wow64reg\reflectr.h"
  28. #include <shlwapi.h>
  29. VOID
  30. CleanupWow64NodeKey ()
  31. /*++
  32. Routine Description
  33. Remove the entry for wow64.
  34. Arguments:
  35. None.
  36. Return Value:
  37. None.
  38. --*/
  39. {
  40. DWORD Ret;
  41. HKEY Key;
  42. Ret = RegOpenKey ( HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft", &Key);
  43. if ( Ret == ERROR_SUCCESS ) {
  44. Ret = SHDeleteKey ( Key, L"WOW64");
  45. if ( Ret != ERROR_SUCCESS )
  46. Wow64RegDbgPrint ( ("\n sorry! couldn't delete the key...SOFTWARE\\Microsoft\\WOW64"));
  47. RegCloseKey (Key);
  48. } else
  49. Wow64RegDbgPrint ( ("\nSOFTWARE\\Microsoft\\WOW64 node is missing setup will creat that.") );
  50. }
  51. LPTSTR NextParam (
  52. LPTSTR lpStr
  53. )
  54. /*++
  55. Routine Description
  56. Point to the next parameter in the commandline.
  57. Arguments:
  58. lpStr - pointer to the current command line
  59. Return Value:
  60. TRUE if the function succeed, FALSE otherwise.
  61. --*/
  62. {
  63. WCHAR ch = L' ';
  64. if (lpStr == NULL )
  65. return NULL;
  66. if ( *lpStr == 0 )
  67. return lpStr;
  68. while ( ( *lpStr != 0 ) && ( lpStr[0] != ch )) {
  69. if ( ( lpStr [0] == L'\"') || ( lpStr [0] == L'\'') )
  70. ch = lpStr [0];
  71. lpStr++;
  72. }
  73. if ( ch !=L' ' ) lpStr++;
  74. while ( ( *lpStr != 0 ) && (lpStr[0] == L' ') )
  75. lpStr++;
  76. return lpStr;
  77. }
  78. DWORD CopyParam (
  79. LPTSTR lpDestParam,
  80. LPTSTR lpCommandParam
  81. )
  82. /*++
  83. Routine Description
  84. Copy the current parameter to lpDestParam.
  85. Arguments:
  86. lpDestParam - that receive current parameter
  87. lpCommandParam - pointer to the current command line
  88. Return Value:
  89. TRUE if the function succeed, FALSE otherwise.
  90. --*/
  91. {
  92. DWORD dwLen = 0;
  93. WCHAR ch = L' ';
  94. *lpDestParam = 0;
  95. if ( ( lpCommandParam [0] == L'\"') || ( lpCommandParam [0] == L'\'') ) {
  96. ch = lpCommandParam [0];
  97. lpCommandParam++;
  98. };
  99. while ( ( lpCommandParam [0] ) != ch && ( lpCommandParam [0] !=0 ) ) {
  100. *lpDestParam++ = *lpCommandParam++;
  101. dwLen++;
  102. if ( dwLen>255 ) return FALSE;
  103. }
  104. if ( ch != L' ' && ch != lpCommandParam [0] )
  105. return FALSE;
  106. else lpCommandParam++;
  107. *lpDestParam = 0;
  108. return TRUE;
  109. }
  110. ///////////////////////////////////////////////////////////////////////////////
  111. /////////////////////////////////////////////////////////////////////////////////
  112. BOOL
  113. ParseCommand ()
  114. /*++
  115. Routine Description
  116. Parse command line parameters. Get different options from
  117. command line parameters.
  118. Arguments:
  119. None.
  120. Return Value:
  121. TRUE if the function succeed, FALSE otherwise.
  122. --*/
  123. {
  124. LPTSTR lptCmdLine1 = GetCommandLine ();
  125. LPTSTR lptCmdLine = NextParam ( lptCmdLine1 );
  126. if ( lptCmdLine== NULL || lptCmdLine[0] == 0 )
  127. return FALSE;
  128. printf ("\nRunning Wow64 registry setup program.....\n");
  129. while ( ( lptCmdLine != NULL ) && ( lptCmdLine[0] != 0 ) ) {
  130. if ( lptCmdLine[0] != '-' )
  131. return FALSE;
  132. switch ( lptCmdLine[1] ) {
  133. case L'c':
  134. printf ("\nCopying from 32bit to 64bit isn't implemented yet");
  135. break;
  136. case L'C': // CopyRegistryKey
  137. SetInitialCopy ();
  138. PopulateReflectorTable ();
  139. CreateIsnNode();
  140. break;
  141. case L'd':
  142. printf ("\nRemove all the Keys from 32bit side that were copied from 64bit side");
  143. CleanpRegistry ( );
  144. break;
  145. case L'D':
  146. printf ("\nRemove all the Keys from 32bit side that were copied from 64bit side");
  147. CleanpRegistry ();
  148. break;
  149. case L'p':
  150. case L'P': // populate registry
  151. CleanupWow64NodeKey ();
  152. PopulateReflectorTable ();
  153. break;
  154. case 't':
  155. {
  156. InitializeIsnTableReflector ();
  157. CreateIsnNodeSingle( 4 );
  158. CreateIsnNodeSingle( 5 );
  159. }
  160. break;
  161. case L'r':
  162. case L'R':
  163. //
  164. // run the reflector codes;
  165. //
  166. InitReflector ();
  167. if ( !RegisterReflector () ) {
  168. printf ("\nSorry! reflector couldn't be register");
  169. UnRegisterReflector ();
  170. return FALSE;
  171. }
  172. printf ("\nSleeping for 100 min to test reflector codes ...........\n");
  173. Sleep (1000*60*100);
  174. UnRegisterReflector ();
  175. break;
  176. default:
  177. return FALSE;
  178. break;
  179. }
  180. lptCmdLine = NextParam ( lptCmdLine );
  181. }
  182. return TRUE;
  183. }
  184. int __cdecl
  185. main()
  186. {
  187. if (!ParseCommand ()) {
  188. printf ( "\nUsages: w64setup [-c] [-C] [-d] [-D] [-r]\n");
  189. printf ( "\n -c Copy from 32bit to 64bit side of the registry");
  190. printf ( "\n -C Copy from 64bit to 32bit side of the registry");
  191. printf ( "\n");
  192. printf ( "\n -d Remove all the Keys from 32bit side that were copied from 64bit side");
  193. printf ( "\n -D Remove all the Keys from 64bit side that were copied from 32bit side");
  194. printf ( "\n");
  195. printf ( "\n -r Run reflector thread");
  196. printf ("\n");
  197. return 0;
  198. }
  199. printf ("\nDone.");
  200. return 0;
  201. }