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.

1153 lines
29 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. This module
  7. // Test case scenario
  8. // 1. Open implement some test case scenario for regremap module.
  9. //a ISN node and list content
  10. // 2. Create a ISN node do 1.
  11. // 3. Open a non ISN node and list
  12. // 4. Create a non ISN node and list content
  13. //
  14. Author:
  15. ATM Shafiqul Khalid (askhalid) 10-Nov-1999
  16. Revision History:
  17. --*/
  18. #include <windows.h>
  19. #include <windef.h>
  20. #include <stdio.h>
  21. #include "wow64reg.h"
  22. #include "..\wow64reg\reflectr.h"
  23. #define TEST_NODE_NAME L"TEST"
  24. #define GUID_STR L"{00000000-E877-11CE-9F68-00AA00574A40}"
  25. typedef struct _TEST_NODE_TYPE {
  26. HKEY hKey;
  27. WCHAR Name[256];
  28. WCHAR SubKey[256];
  29. }TEST_NODE_TYPE;
  30. TEST_NODE_TYPE TestNodeList [] = {
  31. {HKEY_CLASSES_ROOT, L"test1002", UNICODE_NULL},
  32. {HKEY_CURRENT_USER, L"software\\classes\\test1002", UNICODE_NULL},
  33. {HKEY_LOCAL_MACHINE, L"software\\classes\\test1002", UNICODE_NULL},
  34. //{HKEY_USERS,""""""}
  35. };
  36. #define TEST_NODE_NUM (sizeof (TestNodeList)/sizeof (TEST_NODE_TYPE) )
  37. //should move into right header file
  38. BOOL
  39. NonMergeableValueCLSID (
  40. HKEY SrcKey,
  41. HKEY DestKey
  42. );
  43. BOOL
  44. GetKeyTime (
  45. HKEY SrcKey,
  46. ULONGLONG *Time
  47. );
  48. BOOL
  49. MergeKeySrcDest(
  50. PWCHAR Src,
  51. PWCHAR Dest
  52. );
  53. BOOL
  54. GetWow6432ValueKey (
  55. HKEY hKey,
  56. WOW6432_VALUEKEY *pValue
  57. );
  58. BOOL
  59. MergeK1K2Value (
  60. HKEY SrcKey,
  61. HKEY DestKey,
  62. DWORD dwFlag
  63. );
  64. LONG
  65. Wow64RegCreateKeyEx(
  66. HKEY hKey, // handle to an open key
  67. LPCTSTR lpSubKey, // address of subkey name
  68. DWORD Reserved, // reserved
  69. LPTSTR lpClass, // address of class string
  70. DWORD dwOptions, // special options flag
  71. REGSAM samDesired, // desired security access
  72. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  73. // address of key security structure
  74. PHKEY phkResult, // address of buffer for opened handle
  75. LPDWORD lpdwDisposition // address of disposition value buffer
  76. );
  77. BOOL
  78. AnalyzeNode (
  79. PWCHAR pKeyName,
  80. BOOL bSync
  81. )
  82. {
  83. WCHAR Name[256];
  84. WCHAR Mirror[256];
  85. DWORD AccessFlag;
  86. DWORD Ret;
  87. ULONGLONG Time1, Time2;
  88. WCHAR *GUIDName;
  89. WOW6432_VALUEKEY WowValue1;
  90. WOW6432_VALUEKEY WowValue2;
  91. DWORD dwLen = sizeof (Mirror)/sizeof(Mirror[0]);
  92. HKEY Key1;
  93. HKEY Key2;
  94. if (pKeyName == NULL )
  95. return FALSE;
  96. if (pKeyName[0] == UNICODE_NULL )
  97. return FALSE;
  98. wcscpy (Name, L"\\REGISTRY\\MACHINE\\SOFTWARE\\");
  99. if (_wcsnicmp (pKeyName, L"\\REGISTRY", 9 ) !=0 ) {
  100. wcscat (Name, pKeyName);
  101. } else wcscpy (Name, pKeyName);
  102. printf ("\nAnalyzing key [%S]\n", Name );
  103. //print the time stamp, value on the both side etc
  104. Key1 = OpenNode (Name);
  105. if (Key1 == NULL) {
  106. printf ("\nSorry! couldn't open the Key %S", Name );
  107. return FALSE;
  108. }
  109. //BUGBUG following operation should succeed but don't work for classes\wow6432node\.doc input
  110. //Possible bug in the WOW64RegOpenKeyEx
  111. /*Ret = RegOpenKeyEx(
  112. Key1,
  113. NULL,//NULL,
  114. 0,//OpenOption,
  115. KEY_ALL_ACCESS | ( AccessFlag = Is64bitNode (Name)? KEY_WOW64_32KEY : KEY_WOW64_64KEY ),
  116. &Key2
  117. );
  118. if ( ERROR_SUCCESS != Ret ){
  119. printf ("\nSorry! couldn't open mirror of the Key %S", Name );
  120. return FALSE;
  121. }
  122. HandleToKeyName ( Key2, Mirror, &dwLen );
  123. */
  124. //Need to be removed this section
  125. GetMirrorName (Name, Mirror);
  126. Key2 = OpenNode (Mirror);
  127. if (Key2 == NULL) {
  128. printf ("\nSorry! couldn't open the mirror Key %S", Name );
  129. return FALSE;
  130. }
  131. printf ("\nOpened Mirror Key at %S", Mirror);
  132. //now print all the timing information
  133. printf ("\nExtension Test....");
  134. if ( NonMergeableValueCLSID (Key1, Key2 ))
  135. printf ("\nValue of those keys can't be merged...reasons: 1. not an extension 2. Handler don't exist");
  136. else
  137. printf ("\nValue of those keys will be merged by reflector");
  138. GUIDName = wcsstr (Name, L"\\CLSID\\{");
  139. if ( GUIDName != NULL ) {
  140. HKEY KeyGuid;
  141. DWORD SubkeyNumber=1;
  142. GUIDName +=7;
  143. printf ("\nGUID Test......%S", GUIDName);
  144. *(GUIDName -1) = UNICODE_NULL;
  145. KeyGuid = OpenNode (Name);
  146. *(GUIDName -1) = L'\\';
  147. MarkNonMergeableKey (GUIDName, KeyGuid, &SubkeyNumber);
  148. if ( SubkeyNumber>0)
  149. printf ("\nThe guid will be merged....");
  150. else
  151. printf ("\nthe guid isn't going to be merged");
  152. }
  153. GetKeyTime (Key1, &Time1);
  154. GetKeyTime (Key2, &Time2);
  155. printf ("\nOriginal TimeStamp on Keys Src:%p, Dest:%p", Time1, Time2);
  156. GetWow6432ValueKey ( Key1, &WowValue1);
  157. GetWow6432ValueKey ( Key2, &WowValue2);
  158. printf ("\nWowAttribute associated with Keys Src Value type:%d, Timestamp %p", WowValue1.ValueType, WowValue1.TimeStamp);
  159. printf ("\nWowAttribute associated with Keys Des Value type:%d, Timestamp %p", WowValue2.ValueType, WowValue2.TimeStamp);
  160. printf ("\nValueType 1=>Copy, 2=>Reflected, 3=>NonReflectable..\n(Timestamp,Value)=>0 wow attrib isn't there");
  161. if ( bSync ) {
  162. printf ("\n Merging Value/Keys.....");
  163. //MergeK1K2Value (Key1, Key2, 0);
  164. MergeKeySrcDest(Name, Mirror);
  165. }
  166. /*if ( bSync ) {
  167. printf ("\n Merging Value/Keys.....");
  168. //MergeK1K2Value (Key1, Key2, 0);
  169. MergeKeySrcDest(Name, Mirror);
  170. }
  171. if ( bSync ) {
  172. printf ("\n Merging Value/Keys.....");
  173. //MergeK1K2Value (Key1, Key2, 0);
  174. MergeKeySrcDest(Name, Mirror);
  175. }
  176. Sleep (1000*10);
  177. */
  178. return TRUE;
  179. }
  180. BOOL
  181. DeleteNode (
  182. HKEY hKey,
  183. PWCHAR Name
  184. )
  185. {
  186. return FALSE;
  187. }
  188. LONG
  189. Wow64CreateOpenNode(
  190. HKEY hKey,
  191. PWCHAR Name,
  192. HKEY *phKey,
  193. DWORD dwOption,
  194. WCHAR Mode
  195. )
  196. {
  197. WCHAR Buff [MAX_PATH + 1];
  198. DWORD dwBuffLen = MAX_PATH + 1;
  199. DWORD Ret;
  200. *phKey=NULL;
  201. Ret = Wow64RegCreateKeyEx(
  202. hKey, // handle to an open key
  203. Name, // address of subkey name
  204. 0, // reserved
  205. NULL, // address of class string
  206. REG_OPTION_NON_VOLATILE, // special options flag
  207. KEY_ALL_ACCESS | dwOption, // desired security access
  208. NULL, // address of key security structure
  209. phKey, // address of buffer for opened handle
  210. NULL // address of disposition value buffer
  211. );
  212. Buff[0]=UNICODE_NULL;
  213. if (*phKey == NULL) {
  214. HandleToKeyName ( hKey, Buff, &dwBuffLen );
  215. printf ("\nRegCreateEx failed....error: Flag:%d Ret:%d %S<\\>%S", dwOption, Ret, Buff, Name);
  216. }
  217. else if (Mode==L'V'){
  218. HandleToKeyName ( *phKey, Buff, &dwBuffLen );
  219. printf ("\nWow64RegCreateEx succeeded with ....[%S]", Buff);
  220. }
  221. return Ret;
  222. }
  223. LONG
  224. CreateOpenNode(
  225. HKEY hKey,
  226. PWCHAR Name,
  227. HKEY *phKey,
  228. DWORD dwOption,
  229. WCHAR Mode
  230. )
  231. {
  232. WCHAR Buff [MAX_PATH + 1];
  233. DWORD dwBuffLen = MAX_PATH + 1;
  234. DWORD Ret;
  235. *phKey=NULL;
  236. Ret = RegCreateKeyEx(
  237. hKey, // handle to an open key
  238. Name, // address of subkey name
  239. 0, // reserved
  240. NULL, // address of class string
  241. REG_OPTION_NON_VOLATILE, // special options flag
  242. KEY_ALL_ACCESS | dwOption, // desired security access
  243. NULL, // address of key security structure
  244. phKey, // address of buffer for opened handle
  245. NULL // address of disposition value buffer
  246. );
  247. Buff[0]=UNICODE_NULL;
  248. if (*phKey == NULL) {
  249. HandleToKeyName ( hKey, Buff, &dwBuffLen );
  250. printf ("\nRegCreateEx failed....error: Flag:%d Ret:%d %S<\\>%S", dwOption, Ret, Buff, Name);
  251. }
  252. else if (Mode==L'V'){
  253. HandleToKeyName ( *phKey, Buff, &dwBuffLen );
  254. printf ("\nRegCreateEx succeeded with ....[%S]", Buff);
  255. }
  256. if ( (( dwOption & KEY_WOW64_64KEY )&& ( wcsstr(Buff, L"Wow6432Node") != NULL ) ) ||
  257. ( dwOption & KEY_WOW64_32KEY ) && ( wcsstr(Buff, L"Wow6432Node") == NULL ))
  258. printf ("\nSorry! key was created at wrong location..");
  259. return Ret;
  260. }
  261. OpenKey (
  262. HKEY hKey,
  263. PWCHAR Name,
  264. HKEY *phKey,
  265. DWORD dwOption,
  266. WCHAR Mode
  267. )
  268. {
  269. WCHAR Buff [MAX_PATH + 1];
  270. DWORD dwBuffLen = MAX_PATH + 1;
  271. DWORD Ret;
  272. *phKey=NULL;
  273. Ret = RegOpenKeyEx(
  274. hKey,
  275. Name,
  276. 0,//OpenOption,
  277. KEY_ALL_ACCESS | dwOption ,
  278. phKey
  279. );
  280. Buff[0]=UNICODE_NULL;
  281. if (*phKey == NULL) {
  282. HandleToKeyName ( hKey, Buff, &dwBuffLen );
  283. printf ("\nRegOpenEx failed....error: Flag:%d Ret:%d %S<\\>%S", dwOption, Ret, Buff, Name);
  284. } else if (Mode==L'V'){
  285. HandleToKeyName ( *phKey, Buff, &dwBuffLen );
  286. printf ("\nRegOpenEx succeeded with ....[%S]", Buff);
  287. }
  288. return Ret;
  289. }
  290. BOOL
  291. VerifyNode (
  292. HKEY hKey,
  293. PWCHAR OpenName,
  294. PWCHAR RealName
  295. )
  296. {
  297. return FALSE;
  298. }
  299. HKEY
  300. OpenListNode (
  301. HKEY OpenNode,
  302. WCHAR *NodeName,
  303. DWORD OpenOption
  304. )
  305. {
  306. HKEY Key=NULL;
  307. LONG Ret, lCount =0;
  308. WCHAR Name [MAX_PATH + 1];
  309. DWORD dwBuffLen = MAX_PATH + 1;
  310. if ( NodeName == NULL )
  311. return NULL;
  312. /*
  313. #ifndef _WIN64
  314. //
  315. // just to test the library in the 32bit environment
  316. //
  317. if (OpenOption)
  318. Ret = Wow64RegOpenKeyEx(
  319. OpenNode,
  320. NodeName,
  321. 0,//OpenOption,
  322. KEY_ALL_ACCESS | OpenOption ,
  323. &Key
  324. );
  325. else
  326. #endif
  327. */
  328. Ret = RegOpenKeyEx(
  329. OpenNode,
  330. NodeName,
  331. 0,//OpenOption,
  332. KEY_ALL_ACCESS | OpenOption ,
  333. &Key
  334. );
  335. if ( Key!= NULL )
  336. printf ( "\nOpen Operation successful [%S]", NodeName);
  337. else {
  338. printf ( "\nOpen Operation Failed [%S] %X", NodeName, Ret);
  339. return NULL;
  340. }
  341. //
  342. // Now enumerate some value or key's to see what is there
  343. //
  344. lCount = 0;
  345. for(;;) {
  346. Ret = RegEnumKey( Key, lCount, Name, MAX_PATH);
  347. if ( Ret != ERROR_SUCCESS ) break;
  348. printf ("\nKeyName: [%S]", Name);
  349. lCount++;
  350. }
  351. //
  352. // Print the real name of the Key
  353. //
  354. HandleToKeyName ( Key, Name, &dwBuffLen );
  355. printf ("\nThe Real Name of the Key was [%S]", Name);
  356. return Key;
  357. }
  358. void BasicRegReMapTest()
  359. {
  360. HKEY hSystem;
  361. HKEY Key;
  362. HKEY Key1;
  363. RegOpenKeyEx(
  364. HKEY_LOCAL_MACHINE,
  365. L"SYSTEM",
  366. 0,//OpenOption,
  367. KEY_ALL_ACCESS,
  368. &hSystem
  369. );
  370. printf ("\nHello! Im in the regremap piece this will print different view of a tree\n");
  371. printf ("\nOpening Native tree");
  372. Key = OpenListNode (hSystem, TEST_NODE_NAME, 0);
  373. RegCloseKey(Key);
  374. printf ("\n\nOpening Explicitly 32-bit tree");
  375. Key = OpenListNode (hSystem, TEST_NODE_NAME, KEY_WOW64_32KEY);
  376. {
  377. printf ("\nReopening 64bit key using handle to 32bit Key");
  378. Key1 = OpenListNode (Key, L"64bit Key1", KEY_WOW64_64KEY);
  379. RegCloseKey(Key1);
  380. }
  381. RegCloseKey(Key);
  382. printf ("\n\nOpening Explicitly 64-bit Tree");
  383. Key = OpenListNode (hSystem, TEST_NODE_NAME, KEY_WOW64_64KEY);
  384. {
  385. printf ("\nReopening 32bit key using handle to 64bit Key");
  386. Key1 = OpenListNode (Key, L"32bit Key1", KEY_WOW64_32KEY);
  387. RegCloseKey(Key1);
  388. }
  389. RegCloseKey(Key);
  390. RegCloseKey(hSystem);
  391. printf ("\nDone.");
  392. }
  393. void TestCreateHKCR ()
  394. {
  395. HKEY hCR=NULL;
  396. HKEY Key=NULL;
  397. DWORD Ret;
  398. WCHAR Name [MAX_PATH + 1];
  399. DWORD dwBuffLen = MAX_PATH + 1;
  400. Ret = RegCreateKeyEx(
  401. HKEY_CLASSES_ROOT, // handle to an open key
  402. L".001", // address of subkey name
  403. 0, // reserved
  404. NULL, // address of class string
  405. REG_OPTION_NON_VOLATILE, // special options flag
  406. KEY_ALL_ACCESS, // desired security access
  407. NULL, // address of key security structure
  408. &hCR, // address of buffer for opened handle
  409. NULL // address of disposition value buffer
  410. );
  411. if (Ret == ERROR_SUCCESS ) {
  412. printf ("\nHello! checking key creation at classes root");
  413. HandleToKeyName ( hCR, Name, &dwBuffLen );
  414. printf ("\nThe Real Name of the Key was [%S]", Name);
  415. RegCloseKey(hCR);
  416. }
  417. else printf ("\nCouldn't create key .001 at HKEY_CLASSES_ROOT %d", Ret );
  418. }
  419. void TestOpenHKCR (DWORD x, DWORD y)
  420. {
  421. //
  422. // Need to make it work for true 64bit
  423. //
  424. HKEY hCR=NULL;
  425. HKEY Key=NULL;
  426. DWORD Ret;
  427. WCHAR Name [MAX_PATH + 1];
  428. DWORD dwBuffLen = MAX_PATH + 1;
  429. printf ("\n...Hello....");
  430. Ret = RegOpenKeyEx(
  431. HKEY_CURRENT_USER,
  432. L"Software",//NULL,
  433. 0,//OpenOption,
  434. KEY_ALL_ACCESS | KEY_WOW64_32KEY,
  435. &hCR
  436. );
  437. if (Ret == ERROR_SUCCESS ) {
  438. printf ("\nHello! checking key open at classes root");
  439. HandleToKeyName ( hCR, Name, &dwBuffLen );
  440. printf ("\nThe Real Name of the Key was [%S] %p %p", Name, hCR, HKEY_CLASSES_ROOT);
  441. //RegCloseKey(hCR);
  442. //Name[wcslen(Name)-12]=UNICODE_NULL;
  443. //hCR = OpenNode (Name);
  444. }
  445. else printf ("\nCouldn't open HKEY_CLASSES_ROOT" );
  446. Ret = RegOpenKeyEx(
  447. HKEY_CURRENT_USER,
  448. L"software\\classes\\software\\classes\\abcdef\\xyzw.XYZW.1\\ShellNew",
  449. 0,//OpenOption,
  450. KEY_READ | KEY_WOW64_32KEY,
  451. &Key
  452. );
  453. if (Ret == ERROR_SUCCESS ) {
  454. printf ("\n\nHello! checking key open at subkey under HKEY_CLASSES_ROOT");
  455. HandleToKeyName ( Key, Name, &dwBuffLen );
  456. printf ("\nThe Real Name of the Key was [%S]", Name);
  457. RegCloseKey(Key);
  458. }
  459. else printf ("\nCouldn't open subkey under HKEY_CLASSES_ROOT error%d", Ret);
  460. }
  461. void TestPredefinedHandle ()
  462. {
  463. WCHAR Name [MAX_PATH];
  464. DWORD Ret;
  465. DWORD dwBuffLen = MAX_PATH + 1;
  466. HKEY Key1;
  467. Ret = OpenKey( HKEY_CLASSES_ROOT, NULL, &Key1, KEY_WOW64_64KEY, L'N');
  468. dwBuffLen = MAX_PATH + 1;
  469. HandleToKeyName ( Key1, Name, &dwBuffLen );
  470. RegCloseKey (Key1);
  471. if (!Is64bitNode (Name))
  472. printf ("\nCouldn't get 64bit HKCR using KEY_WOW64_64KEY: %S", Name);
  473. Ret = OpenKey( HKEY_CLASSES_ROOT, NULL, &Key1, KEY_WOW64_32KEY, L'N');
  474. dwBuffLen = MAX_PATH + 1;
  475. HandleToKeyName ( Key1, Name, &dwBuffLen );
  476. RegCloseKey (Key1);
  477. if (Is64bitNode (Name))
  478. printf ("\nCouldn't get 32bit HKCR using KEY_WOW64_32KEY: %S", Name);
  479. Ret = OpenKey( HKEY_CURRENT_USER, L"Software\\Classes", &Key1, KEY_WOW64_64KEY, L'N');
  480. dwBuffLen = MAX_PATH + 1;
  481. HandleToKeyName ( Key1, Name, &dwBuffLen );
  482. RegCloseKey (Key1);
  483. if (!Is64bitNode (Name))
  484. printf ("\nCouldn't get 64bit HKCU Software\\Classes using KEY_WOW64_64KEY: %S", Name);
  485. Ret = OpenKey( HKEY_CURRENT_USER, L"Software\\Classes", &Key1, KEY_WOW64_32KEY, L'N');
  486. dwBuffLen = MAX_PATH + 1;
  487. HandleToKeyName ( Key1, Name, &dwBuffLen );
  488. RegCloseKey (Key1);
  489. if (Is64bitNode (Name))
  490. printf ("\nCouldn't get 32bit HKCU Software\\Classes using KEY_WOW64_32KEY: %S %d", Name, Ret);
  491. }
  492. InProcLocalServerTest ()
  493. {
  494. //
  495. // Create a server on the 64bit side with Inproc, and check on the 32bit if its get reflected.
  496. //
  497. HKEY Key1;
  498. HKEY Key2;
  499. WCHAR KeyName[256];
  500. DWORD Ret=0;
  501. wcscpy (KeyName, L"CLSID\\");
  502. wcscat (KeyName, GUID_STR);
  503. printf ("\nTesting of GUID\\{Inproc Server, Local Server}...");
  504. Ret += CreateOpenNode (HKEY_CLASSES_ROOT, KeyName, &Key1, 0, L'N');
  505. Ret += CreateOpenNode (Key1, L"InprocServer32", &Key2, 0, L'N');
  506. RegCloseKey (Key1);
  507. RegCloseKey (Key2);
  508. //
  509. // Try to open on the 32bit side
  510. //
  511. if (OpenKey (HKEY_CLASSES_ROOT, KeyName, &Key1, KEY_WOW64_32KEY, L'V') == 0) {
  512. RegCloseKey (Key1); //Key Shouldn'e be on the 32bit side
  513. Ret += -1;
  514. }
  515. //
  516. // You Need to add for test of local server...
  517. //
  518. if (Ret ==0)
  519. printf ("\nGUID Test Succeed......");
  520. else printf ("\nGUID test with Inprocserver failed..");
  521. //Delete the Key
  522. }
  523. void
  524. OpenCreateKeyTest ()
  525. {
  526. DWORD Ret=0;
  527. DWORD xx;
  528. HKEY Key1;
  529. HKEY Key2;
  530. InProcLocalServerTest ();
  531. TestPredefinedHandle ();
  532. #define TEST_NODE1 L".0xxxxxx"
  533. printf ("\n//_______________Test 32bit side____________________//");
  534. Ret = 0;
  535. // create 64==>TestNode
  536. Ret += CreateOpenNode( HKEY_CLASSES_ROOT, TEST_NODE1, &Key1, KEY_WOW64_64KEY, L'V');
  537. //create 32==>TestNode\GUIDSTR
  538. Ret += CreateOpenNode(Key1, GUID_STR, &Key2, KEY_WOW64_32KEY, L'V');
  539. RegCloseKey (Key2);
  540. //open 32==>TestNode
  541. Ret += OpenKey( HKEY_CLASSES_ROOT, TEST_NODE1, &Key2, KEY_WOW64_32KEY, L'V' );
  542. //Delete 32\TestNode==>GUID
  543. if ((xx=RegDeleteKey (Key2, GUID_STR ))!= ERROR_SUCCESS )
  544. printf ("\nSorry! couldn't delete key %S Err:%d", GUID_STR, xx);
  545. Ret +=xx;
  546. RegCloseKey(Key2);
  547. RegCloseKey(Key1);
  548. //delete 32==>TestNode
  549. Ret +=OpenKey (HKEY_CLASSES_ROOT, NULL, &Key1, KEY_WOW64_32KEY, L'V');
  550. if ( (xx=RegDeleteKey (Key1, TEST_NODE1))!= ERROR_SUCCESS )
  551. printf ("\nSorry! couldn't delete key from 32bit tree=>%S Err:%d", TEST_NODE1, xx);
  552. Ret +=xx;
  553. RegCloseKey (Key1);
  554. //delete 64==>TestNode
  555. Ret +=OpenKey (HKEY_CLASSES_ROOT, NULL, &Key1, KEY_WOW64_64KEY, L'V');
  556. if ((xx= RegDeleteKey (Key1, TEST_NODE1))!= ERROR_SUCCESS )
  557. printf ("\nSorry! couldn't delete key from 64bit tree=>%S Err:%d", TEST_NODE1, xx);
  558. Ret +=xx;
  559. RegCloseKey (Key1);
  560. if (Ret != ERROR_SUCCESS )
  561. printf ("\nTest failed....");
  562. else
  563. printf ("\nTest succeed...");
  564. printf ("\n//_______________Test 64bit side____________________//");
  565. Ret = 0;
  566. #define TEST_NODE2 L".0000######"
  567. // create 32==>TestNode
  568. Ret += CreateOpenNode( HKEY_CLASSES_ROOT, TEST_NODE2, &Key1, KEY_WOW64_32KEY, L'V');
  569. //create 64==>TestNode\GUIDSTR
  570. Ret += CreateOpenNode(Key1, GUID_STR, &Key2, KEY_WOW64_64KEY, L'V');
  571. RegCloseKey (Key2);
  572. //Open 64==>TestNode
  573. Ret += OpenKey( HKEY_CLASSES_ROOT, TEST_NODE2, &Key2, KEY_WOW64_64KEY, L'V' );
  574. //Delete 64\TestNode==>GUID
  575. if ((xx=RegDeleteKey (Key2, GUID_STR ))!= ERROR_SUCCESS )
  576. printf ("\nSorry! couldn't delete key %S Err:%d", GUID_STR, xx);
  577. Ret +=xx;
  578. RegCloseKey(Key2);
  579. RegCloseKey(Key1);
  580. //Delete 64==>TestNode
  581. Ret +=OpenKey (HKEY_CLASSES_ROOT, NULL, &Key1, KEY_WOW64_64KEY, L'V');
  582. if ((xx= RegDeleteKey (Key1, TEST_NODE2))!= ERROR_SUCCESS )
  583. printf ("\nSorry! couldn't delete key from 64bit tree=>%S Err:%d", TEST_NODE2, xx);
  584. Ret +=xx;
  585. RegCloseKey (Key1);
  586. //Delete 32==>TestNode
  587. Ret +=OpenKey (HKEY_CLASSES_ROOT, NULL, &Key1, KEY_WOW64_32KEY, L'V');
  588. if ( (xx=RegDeleteKey (Key1, TEST_NODE2))!= ERROR_SUCCESS )
  589. printf ("\nSorry! couldn't delete key from 32bit tree=>%S Err:%d", TEST_NODE2, xx);
  590. Ret +=xx;
  591. RegCloseKey (Key1);
  592. if (Ret != ERROR_SUCCESS )
  593. printf ("\nTest failed....");
  594. else
  595. printf ("\nTest succeed...");
  596. }
  597. TestCreateOpenNode ()
  598. {
  599. DWORD Count;
  600. DWORD i;
  601. HKEY hKey=NULL;
  602. DWORD Ret;
  603. Count = TEST_NODE_NUM;
  604. for ( i=0; i<Count;i++) {
  605. Ret = CreateOpenNode (
  606. TestNodeList[i].hKey,
  607. TestNodeList[i].Name,
  608. &hKey,
  609. 0,
  610. L'V'
  611. );
  612. if (hKey == NULL ) {
  613. printf ("\n Couldn't create/open Key %S",TestNodeList[i]);
  614. continue;
  615. }
  616. }
  617. }
  618. VOID
  619. TestSharedResources ()
  620. {
  621. //#define TEST_USER_CLASSES_ROOT L"\\REGISTRY\\MACHINE\\SYSTEM\\TEST345"
  622. #define TEST_USER_CLASSES_ROOT L"\\REGISTRY\\USER\\S-1-5-21-397955417-626881126-188441444-2721867_Classes"
  623. HANDLE hEvent;
  624. WCHAR Name[256];
  625. wcscpy (Name, TEST_USER_CLASSES_ROOT);
  626. if (!CreateNode (Name))
  627. printf ("\nSorry! Couldn't create key.. %S", TEST_USER_CLASSES_ROOT );
  628. Wow64RegNotifyLoadHive ( Name);
  629. //Wow64RegNotifyUnloadHive ( Name );
  630. }
  631. VOID
  632. TestTypeLib ()
  633. {
  634. HKEY SrcKey;
  635. HKEY DestKey;
  636. printf ("\nTesting Typelib copy info...");
  637. SrcKey = OpenNode (L"\\REGISTRY\\MACHINE\\Software\\classes\\TypeLib");
  638. RegCreateKeyEx(
  639. HKEY_LOCAL_MACHINE, // handle to an open key
  640. L"SOFTWARE\\Classes\\Wow6432Node\\TypeLib", // address of subkey name
  641. 0, // reserved
  642. NULL, // address of class string
  643. REG_OPTION_NON_VOLATILE, // special options flag
  644. KEY_ALL_ACCESS, // desired security access
  645. NULL, // address of key security structure
  646. &DestKey, // address of buffer for opened handle
  647. NULL // address of disposition value buffer
  648. );
  649. printf ("\n OpenHandle %p %p", SrcKey, DestKey);
  650. ProcessTypeLib ( SrcKey, DestKey, FALSE );
  651. }
  652. VOID
  653. TestRegReflectKey ()
  654. {
  655. HKEY SrcKey;
  656. printf ("\nTesting RegSyncKey copy info...");
  657. SrcKey = OpenNode (L"\\REGISTRY\\MACHINE\\Software");
  658. printf ("\nRegReflectKey returned with %d", RegReflectKey (SrcKey, L"1\\2\\3", 0) );
  659. RegCloseKey (SrcKey);
  660. }
  661. VOID
  662. Test4()
  663. {
  664. LONG lRes = 0;
  665. HKEY hKey = NULL;
  666. HKEY hKey32 = NULL;
  667. lRes = RegOpenKeyEx(
  668. HKEY_LOCAL_MACHINE,
  669. L"Software",
  670. 0,
  671. KEY_ALL_ACCESS | KEY_WOW64_32KEY,
  672. &hKey
  673. );
  674. if(lRes != ERROR_SUCCESS)
  675. {
  676. return;
  677. }
  678. lRes = RegCreateKeyEx(
  679. hKey,
  680. L"_Key",
  681. 0,
  682. NULL,
  683. REG_OPTION_NON_VOLATILE,
  684. KEY_ALL_ACCESS | KEY_WOW64_32KEY,
  685. NULL,
  686. &hKey32,
  687. NULL
  688. );
  689. if(lRes != 0)
  690. {
  691. printf("key not created\n");
  692. return;
  693. }
  694. RegCloseKey(hKey32);
  695. }
  696. void TestRegistry()
  697. {
  698. HKEY hKey = NULL;
  699. HKEY Key1;
  700. HKEY Key2;
  701. //Test4();
  702. //RegOpenKeyEx ( HKEY_LOCAL_MACHINE, L"Software", 0, KEY_ALL_ACCESS, &hKey );
  703. //hKey = OpenNode (L"\\REGISTRY\\MACHINE");
  704. //CreateOpenNode(hKey, L"Software", &Key1, KEY_WOW64_32KEY, L'V');
  705. //CreateOpenNode(Key1, L"YYYzzz", &Key2, KEY_WOW64_32KEY, L'V');
  706. //TestRegReflectKey ();
  707. //TestSharedResources ();
  708. //TestTypeLib ();
  709. //BasicRegReMapTest();
  710. //TestOpenHKCR(1,2);
  711. printf ("\n\n2nd test.....OpenCreateKeyTest ()");
  712. OpenCreateKeyTest ();
  713. //TestCreateHKCR ();
  714. }
  715. LPTSTR NextParam (
  716. LPTSTR lpStr
  717. )
  718. /*++
  719. Routine Description
  720. Point to the next parameter in the commandline.
  721. Arguments:
  722. lpStr - pointer to the current command line
  723. Return Value:
  724. TRUE if the function succeed, FALSE otherwise.
  725. --*/
  726. {
  727. WCHAR ch = L' ';
  728. if (lpStr == NULL )
  729. return NULL;
  730. if ( *lpStr == 0 )
  731. return lpStr;
  732. while ( ( *lpStr != 0 ) && ( lpStr[0] != ch )) {
  733. if ( ( lpStr [0] == L'\"') || ( lpStr [0] == L'\'') )
  734. ch = lpStr [0];
  735. lpStr++;
  736. }
  737. if ( ch !=L' ' ) lpStr++;
  738. while ( ( *lpStr != 0 ) && (lpStr[0] == L' ') )
  739. lpStr++;
  740. return lpStr;
  741. }
  742. DWORD CopyParam (
  743. LPTSTR lpDestParam,
  744. LPTSTR lpCommandParam
  745. )
  746. /*++
  747. Routine Description
  748. Copy the current parameter to lpDestParam.
  749. Arguments:
  750. lpDestParam - that receive current parameter
  751. lpCommandParam - pointer to the current command line
  752. Return Value:
  753. TRUE if the function succeed, FALSE otherwise.
  754. --*/
  755. {
  756. DWORD dwLen = 0;
  757. WCHAR ch = L' ';
  758. *lpDestParam = 0;
  759. if ( ( lpCommandParam [0] == L'\"') || ( lpCommandParam [0] == L'\'') ) {
  760. ch = lpCommandParam [0];
  761. lpCommandParam++;
  762. };
  763. while ( ( lpCommandParam [0] ) != ch && ( lpCommandParam [0] !=0 ) ) {
  764. *lpDestParam++ = *lpCommandParam++;
  765. dwLen++;
  766. if ( dwLen>255 ) return FALSE;
  767. }
  768. if ( ch != L' ' && ch != lpCommandParam [0] )
  769. return FALSE;
  770. else lpCommandParam++;
  771. *lpDestParam = 0;
  772. return TRUE;
  773. }
  774. ///////////////////////////////////////////////////////////////////////////////
  775. /////////////////////////////////////////////////////////////////////////////////
  776. BOOL
  777. ParseCommand ()
  778. /*++
  779. Routine Description
  780. Parse command line parameters. Get different options from
  781. command line parameters.
  782. Arguments:
  783. None.
  784. Return Value:
  785. TRUE if the function succeed, FALSE otherwise.
  786. --*/
  787. {
  788. BOOL bSync = FALSE;
  789. LPTSTR lptCmdLine1 = GetCommandLine ();
  790. LPTSTR lptCmdLine = NextParam ( lptCmdLine1 );
  791. if ( lptCmdLine[0] == 0 )
  792. return FALSE;
  793. printf ("\nRunning Wow64 registry testing tool\n");
  794. while ( ( lptCmdLine != NULL ) && ( lptCmdLine[0] != 0 ) ) {
  795. if ( lptCmdLine[0] != '-' )
  796. return FALSE;
  797. switch ( lptCmdLine[1] ) {
  798. case L'C': //sync ClsID
  799. case L'c':
  800. Wow64SyncCLSID ();
  801. break;
  802. case L'd':
  803. printf ("\n<TBD>Remove all the Keys from 32bit side that were copied from 64bit side");
  804. //CleanpRegistry ( );
  805. break;
  806. case L'D':
  807. printf ("\n<TBD>Remove all the Keys from 32bit side that were copied from 64bit side");
  808. //CleanpRegistry ();
  809. break;
  810. case L'p':
  811. case L'P': // populate registry
  812. //CleanupWow64NodeKey ();
  813. PopulateReflectorTable ();
  814. break;
  815. case 't':
  816. case 'T':
  817. TestRegistry ();
  818. break;
  819. case L'r':
  820. case L'R':
  821. //
  822. // run the reflector codes;
  823. //
  824. InitReflector ();
  825. if ( !RegisterReflector () ) {
  826. printf ("\nSorry! reflector couldn't be register");
  827. UnRegisterReflector ();
  828. return FALSE;
  829. }
  830. printf ("\nSleeping for 100 min to test reflector codes ...........\n");
  831. Sleep (1000*60*100);
  832. UnRegisterReflector ();
  833. break;
  834. case L's':
  835. case L'S':
  836. bSync = TRUE;
  837. break;
  838. case L'a':
  839. case L'A':
  840. //
  841. // Analyze a key
  842. //
  843. AnalyzeNode (&lptCmdLine[2], bSync);
  844. break;
  845. default:
  846. return FALSE;
  847. break;
  848. }
  849. lptCmdLine = NextParam ( lptCmdLine );
  850. }
  851. return TRUE;
  852. }
  853. int __cdecl
  854. main()
  855. {
  856. if (!ParseCommand ()) {
  857. printf ( "\nUsages: w64setup [-c] [-C] [-d] [-D] [-r]\n");
  858. printf ( "\n -c Copy from 32bit to 64bit side of the registry");
  859. printf ( "\n -C Copy from 64bit to 32bit side of the registry");
  860. printf ( "\n");
  861. printf ( "\n -d Remove all the Keys from 32bit side that were copied from 64bit side");
  862. printf ( "\n -D Remove all the Keys from 64bit side that were copied from 32bit side");
  863. printf ( "\n");
  864. printf ( "\n -r Run reflector thread");
  865. printf ( "\n -A Analyze a key if that going to be reflected");
  866. printf ("\n");
  867. return 0;
  868. }
  869. printf ("\nDone.");
  870. return 0;
  871. }