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.

1587 lines
50 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation
  3. Module Name:
  4. sxsdebug.cpp
  5. Abstract:
  6. testing API for sxstest
  7. Author:
  8. Xiaoyu Wu (xiaoyuw) April 2000
  9. Revision History:
  10. --*/
  11. #include "stdinc.h"
  12. #include "xmlparser.hxx"
  13. #include "xmlparsertest.hxx"
  14. #include "sxsinstall.h"
  15. #include "sxsprotect.h"
  16. #include <sxsapi.h>
  17. #include "fusiontrace.h"
  18. #include "sxsasmname.h"
  19. #include "strongname.h"
  20. #include "cassemblyrecoveryinfo.h"
  21. #include "protectionui.h"
  22. #include "sxscabinet.h"
  23. #define CONFIG_FILE_EXTENSION L".config"
  24. BOOL TestExpandCabinetFileToTemp(PCWSTR pcwszCabinetPath, PCWSTR pcwszTargetPath)
  25. {
  26. /*
  27. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  28. remove this from sxs.dll, statically link sxstest.exe instead
  29. large frame
  30. */
  31. FN_PROLOG_WIN32
  32. #if 0
  33. CStringBuffer buffCabinet;
  34. CStringBuffer buffTarget;
  35. CCabinetData cabData;
  36. CImpersonationData impData;
  37. IFW32FALSE_EXIT(buffCabinet.Win32Assign(pcwszCabinetPath, ::wcslen(pcwszCabinetPath)));
  38. IFW32FALSE_EXIT(buffTarget.Win32Assign(pcwszTargetPath, ::wcslen(pcwszTargetPath)));
  39. IFW32FALSE_EXIT(cabData.Initialize(buffTarget, true));
  40. IFW32FALSE_EXIT(::SxspExpandCabinetIntoTemp(
  41. 0,
  42. buffCabinet,
  43. impData,
  44. &cabData));
  45. #endif
  46. FN_EPILOG
  47. }
  48. BOOL TestReparsePointOnFullQualifiedPath(PCWSTR basePath, PCWSTR fullPath)
  49. {
  50. /*
  51. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  52. remove this from sxs.dll, statically link sxstest.exe instead
  53. */
  54. FN_PROLOG_WIN32
  55. #if 0
  56. BOOL CrossesReparsePoint = FALSE;
  57. IFW32FALSE_EXIT(
  58. ::SxspDoesPathCrossReparsePoint(
  59. basePath,
  60. wcslen(basePath),
  61. fullPath,
  62. wcslen(fullPath),
  63. CrossesReparsePoint));
  64. #endif
  65. FN_EPILOG
  66. }
  67. HRESULT TestAssemblyNameQueryAssemblyInfo()
  68. {
  69. /*
  70. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  71. remove this from sxs.dll, statically link sxstest.exe instead
  72. it is bad to have these hard coded strings in shipping files
  73. */
  74. HRESULT hr = S_OK;
  75. FN_TRACE_HR(hr);
  76. #if 0
  77. PCWSTR manifest_files[] = {
  78. L"Z:\\tests\\footest\\cdfiles\\cards_0001\\cards.manifest",
  79. L"Z:\\tests\\footest\\cdfiles\\policy\\policy1\\asmpol.MANIFEST"
  80. };
  81. PCWSTR pwszAssemblyIdentity[] = {
  82. L"Cards_0000,language=\"en-us\",processorArchitecture=\"X86\",publicKeyToken=\"6595b64144ccf1df\",type=\"win32\",version=\"1.0.0.0\"",
  83. L"policy.1.0.dynamicdll,processorArchitecture=\"x86\",publicKeyToken=\"75e377300ab7b886\",type=\"win32-policy\",version=\"1.1.1.1\""
  84. };
  85. SXS_UNINSTALLW Uninstall = {sizeof(Uninstall)};
  86. DWORD dwDisposition = 0;
  87. //
  88. // install
  89. //
  90. for (DWORD i = 0; i < NUMBER_OF(manifest_files); i++)
  91. {
  92. SXS_INSTALLW Info = {sizeof(Info)};
  93. SXS_INSTALL_REFERENCEW Reference = {sizeof(Reference)};
  94. Info.dwFlags = SXS_INSTALL_FLAG_REPLACE_EXISTING |
  95. SXS_INSTALL_FLAG_REFERENCE_VALID |
  96. SXS_INSTALL_FLAG_CODEBASE_URL_VALID |
  97. SXS_INSTALL_FLAG_LOG_FILE_NAME_VALID;
  98. Info.lpManifestPath = manifest_files[i];
  99. Info.lpCodebaseURL = Info.lpManifestPath;
  100. Info.lpReference = &Reference;
  101. Info.lpLogFileName = L"c:\\thelogfile";
  102. Reference.guidScheme = SXS_INSTALL_REFERENCE_SCHEME_OPAQUESTRING;
  103. Reference.lpIdentifier = L"Sxs installation";
  104. IFW32FALSE_EXIT(::SxsInstallW(&Info));
  105. }
  106. //
  107. // QueryInfo
  108. //
  109. for ( i =0; i < NUMBER_OF(manifest_files); i++)
  110. {
  111. IAssemblyCache * pCache = NULL;
  112. WCHAR buf[MAX_PATH];
  113. ASSEMBLY_INFO iasm;
  114. //IFCOMFAILED_EXIT(GetTextualAssemblyIdentityFromManifest(&sbTextualAssembly, manifest_files[i]));
  115. IFCOMFAILED_EXIT(::CreateAssemblyCache(&pCache, 0));
  116. ZeroMemory(&iasm, sizeof(iasm));
  117. iasm.cchBuf = MAX_PATH;
  118. iasm.pszCurrentAssemblyPathBuf = buf;
  119. IFCOMFAILED_EXIT(pCache->QueryAssemblyInfo(0, pwszAssemblyIdentity[i], &iasm));
  120. }
  121. //
  122. // Uninstall
  123. //
  124. Uninstall.dwFlags = SXS_UNINSTALL_FLAG_USE_INSTALL_LOG;
  125. Uninstall.lpInstallLogFile = L"c:\\thelogfile";
  126. if (!(*SxsUninstallW)(&Uninstall, &dwDisposition))
  127. {
  128. goto Exit;
  129. }
  130. #endif
  131. FN_EPILOG
  132. }
  133. HRESULT TestAssemblyName()
  134. {
  135. /*
  136. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  137. remove this from sxs.dll, statically link sxstest.exe instead
  138. it is bad to have these hard coded strings in shipping files
  139. */
  140. HRESULT hr = NOERROR;
  141. FN_TRACE_HR(hr);
  142. #if 0
  143. //const WCHAR super_simple_inputstring[] = L"cards,version=\"1.0.0.0\",processorArchitecture=\"x86\",language=\"0409\",whatever=\"whatever\"";
  144. const WCHAR super_simple_inputstring[] = L"cards,version=\"1.0.0.0\",processorArchitecture=\"x86\",language=\"0409\"";
  145. //const WCHAR super_simple_inputstring[] = L"cards,,,,,";
  146. // const WCHAR simple_inputstring[] = L"ca&#x2c;r&#x2c;d&#x22;s,http://fusion:whatever=\"&#x22;&#x2c;0&#x2c;&#x22;\",http://fusion:processorarchitecture=\"x86\",http://neptune:language=\"0409\"";
  147. // const WCHAR complex_inputstring[] = L"firstcards&#x22;secondcards,http://fusion:version=\"1.0.0.0\",http://www.shuku.net/novels/prose/zxfjdsw:whatever=\"what&#x2c;ever\"";
  148. CAssemblyName * pAsmName = NULL;
  149. IAssemblyName * pIAsmName = NULL;
  150. LPWSTR szDisplayName = NULL ;
  151. ULONG ccDisplayName = 0;
  152. LPWSTR psz = NULL;
  153. CSmartRef<IAssemblyCache> pCache;
  154. CStringBuffer bufPath;
  155. PCWSTR szAssemblyStr = super_simple_inputstring;
  156. IFCOMFAILED_EXIT(::CreateAssemblyCache(&pCache, 0));
  157. // parse : convert string from Darwin to Fusion
  158. IFCOMFAILED_EXIT(::CreateAssemblyNameObject(&pIAsmName, szAssemblyStr, CANOF_PARSE_DISPLAY_NAME, NULL));
  159. pAsmName = reinterpret_cast<CAssemblyName*>(pIAsmName);
  160. ccDisplayName = static_cast<ULONG>(wcslen(szAssemblyStr));
  161. ccDisplayName ++; // for worst case
  162. szDisplayName = NEW (WCHAR[ccDisplayName]);
  163. if (!szDisplayName)
  164. goto Exit;
  165. // GetDisplayName: convert string from Fusion to Darwin
  166. IFCOMFAILED_EXIT(pAsmName->GetDisplayName(szDisplayName, &ccDisplayName, 0));
  167. //ASSERT(wcscmp(szDisplayName, szAssemblyStr) == 0);
  168. IFCOMFAILED_EXIT(pAsmName->GetInstalledAssemblyName(0, SXSP_GENERATE_SXS_PATH_PATHTYPE_ASSEMBLY, bufPath));
  169. hr = NOERROR;
  170. Exit:
  171. if (pAsmName)
  172. pAsmName->Release();
  173. delete[] szDisplayName;
  174. delete[] psz ;
  175. #endif
  176. return hr;
  177. }
  178. BOOL
  179. SxspManifestSchemaCheck(
  180. PCWSTR parameterstring // this must be a full-qualified filename of a manifest file
  181. )
  182. {
  183. /*
  184. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  185. remove this from sxs.dll, statically link sxstest.exe instead
  186. */
  187. BOOL fSuccess = FALSE;
  188. FN_TRACE_WIN32(fSuccess);
  189. #if 0
  190. ACTCTXGENCTX ActCtxGenCtx;
  191. ULONG ManifestFlags = 0;
  192. CProbedAssemblyInformation AssemblyInformation;
  193. CImpersonationData ImpersonationData;
  194. PCWSTR Slash = NULL;
  195. PASSEMBLY Asm = NULL;
  196. CStringBuffer buffManifestPath;
  197. USHORT ProcessorArchitecture = ::SxspGetSystemProcessorArchitecture();
  198. LANGID LangId = ::GetUserDefaultLangID();
  199. // BUGBUG xiaoyuw@09/17/00 : disable to set Name and version from the command line for simplicity
  200. PARAMETER_CHECK(parameterstring != NULL);
  201. IFW32FALSE_EXIT(AssemblyInformation.Initialize(&ActCtxGenCtx));
  202. IFW32FALSE_EXIT(buffManifestPath.Win32Assign(parameterstring, ::wcslen(parameterstring)));
  203. IFW32FALSE_EXIT(
  204. ::SxspInitActCtxGenCtx(
  205. &ActCtxGenCtx, // context out
  206. MANIFEST_OPERATION_VALIDATE_SYNTAX,
  207. 0,
  208. 0,
  209. ImpersonationData,
  210. ProcessorArchitecture,
  211. LangId,
  212. ACTIVATION_CONTEXT_PATH_TYPE_NONE,
  213. 0,
  214. NULL));
  215. // get manifestpath, manifestName, manifestVersion
  216. Slash = wcsrchr(buffManifestPath, L'\\');
  217. PARAMETER_CHECK(Slash != NULL);
  218. IFALLOCFAILED_EXIT(Asm = new ASSEMBLY);
  219. ManifestFlags = ASSEMBLY_MANIFEST_FILETYPE_FILE;
  220. IFW32FALSE_EXIT(AssemblyInformation.SetManifestPath(ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE, buffManifestPath));
  221. IFW32FALSE_EXIT(AssemblyInformation.SetManifestFlags(ManifestFlags));
  222. IFW32FALSE_EXIT(AssemblyInformation.SetManifestLastWriteTime(ImpersonationData)); // using default parameter-value
  223. IFW32FALSE_EXIT(::SxspInitAssembly(Asm, AssemblyInformation));
  224. IFW32FALSE_EXIT(::SxspIncorporateAssembly(&ActCtxGenCtx, Asm));
  225. IFW32FALSE_EXIT(::SxspFireActCtxGenEnding(&ActCtxGenCtx));
  226. fSuccess = TRUE;
  227. Exit:
  228. if (Asm != NULL)
  229. Asm->Release();
  230. #endif
  231. return fSuccess;
  232. }
  233. #if SXS_PRECOMPILED_MANIFESTS_ENABLED
  234. HRESULT
  235. GetPCMWorkingTime(PCWSTR filename, LARGE_INTEGER* pcmtime)
  236. {
  237. /*
  238. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  239. remove this from sxs.dll, statically link sxstest.exe instead
  240. */
  241. HRESULT hr = NOERROR;
  242. FN_TRACE_HR(hr);
  243. #if 0
  244. CStringBuffer buf;
  245. CSmartRef<XMLParserTestFactory> factory;
  246. CSmartRef<CPrecompiledManifestReader> pPCMReader;
  247. LARGE_INTEGER timestart = {0};
  248. ULONG i = 0;
  249. ULONG j = 0;
  250. buf.Assign(filename, ::wcslen(filename));
  251. buf.Append(L".pcm", 4);
  252. factory = new XMLParserTestFactory;
  253. if (! factory) {
  254. ::FusionpDbgPrintEx(
  255. FUSION_DBG_LEVEL_INFO,
  256. "SxsDebug:: fail to new XMLParserTestFactory, out of memory\n");
  257. hr = E_OUTOFMEMORY;
  258. goto Exit;
  259. }
  260. pPCMReader = new CPrecompiledManifestReader);
  261. if (! pPCMReader) {
  262. hr = E_OUTOFMEMORY;
  263. goto Exit;
  264. }
  265. for (j=0; j<10; j++) {
  266. ::QueryPerformanceCounter(&timestart);
  267. for (i = 0 ; i < 10; i++) {
  268. hr = pPCMReader->InvokeNodeFactory(buf, factory);
  269. if (FAILED(hr))
  270. goto Exit;
  271. }
  272. ::QueryPerformanceCounter(&pcmtime[j]);
  273. pcmtime[j].QuadPart -= timestart.QuadPart;
  274. }
  275. hr = NOERROR;
  276. Exit:
  277. #endif
  278. return hr;
  279. }
  280. #endif // SXS_PRECOMPILED_MANIFESTS_ENABLED
  281. HRESULT GetParserWorkingTime(PCWSTR filename, LARGE_INTEGER* parsertime)
  282. {
  283. /*
  284. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  285. remove this from sxs.dll, statically link sxstest.exe instead
  286. */
  287. HRESULT hr = S_OK;
  288. FN_TRACE_HR(hr);
  289. #if 0
  290. LARGE_INTEGER t1[10], t2[10];
  291. LARGE_INTEGER timestart;
  292. ULONG i = 0;
  293. ULONG j = 0;
  294. CSmartRef<IXMLParser> pIXMLParser;
  295. XMLParser * pXMLParser;
  296. CSmartRef<XMLParserTestFactory> factory;
  297. CSmartRef<XMLParserTestFileStream> filestream;
  298. filestream = NEW (XMLParserTestFileStream());
  299. if (!filestream) {
  300. ::FusionpDbgPrintEx(
  301. FUSION_DBG_LEVEL_INFO,
  302. "SxsDebug:: fail to new XMLParserTestFileStream, out of memory\n");
  303. hr = E_OUTOFMEMORY;
  304. goto Exit;
  305. }
  306. if (! filestream->open(filename))
  307. {
  308. ::FusionpDbgPrintEx(
  309. FUSION_DBG_LEVEL_INFO,
  310. "SxsDebug:: fail to call XMLParserTestFileStream::open\n");
  311. hr = E_UNEXPECTED;
  312. goto Exit;
  313. }
  314. factory = new XMLParserTestFactory;
  315. if (! factory) {
  316. ::FusionpDbgPrintEx(
  317. FUSION_DBG_LEVEL_INFO,
  318. "SxsDebug:: fail to new XMLParserTestFactory, out of memory\n");
  319. hr = E_OUTOFMEMORY;
  320. goto Exit;
  321. }
  322. pXMLParser = NEW(XMLParser);
  323. pIXMLParser = pXMLParser;
  324. if (pIXMLParser == NULL)
  325. {
  326. hr = E_OUTOFMEMORY;
  327. ::FusionpDbgPrintEx(
  328. FUSION_DBG_LEVEL_ERROR,
  329. "SXS.DLL: Attempt to instantiate XML parser failed\n");
  330. goto Exit;
  331. }
  332. if (FAILED(hr = pXMLParser->HrInitialize()))
  333. goto Exit;
  334. hr = pIXMLParser->SetInput(filestream); // filestream's RefCount=2
  335. if (! SUCCEEDED(hr))
  336. goto Exit;
  337. hr = pIXMLParser->SetFactory(factory); // factory's RefCount=2
  338. if (! SUCCEEDED(hr))
  339. goto Exit;
  340. for (j =0; j<10; j++) {
  341. ::QueryPerformanceCounter(&timestart);
  342. for (i = 0 ; i< 10; i++) {
  343. hr = pIXMLParser->Run(-1);
  344. if (FAILED(hr))
  345. goto Exit;
  346. pIXMLParser->Reset();
  347. pIXMLParser->SetFactory(factory);
  348. filestream->close();
  349. filestream->open(filename);
  350. pIXMLParser->SetInput(filestream);
  351. }
  352. ::QueryPerformanceCounter(&t1[j]);
  353. t1[j].QuadPart -= timestart.QuadPart;
  354. ::QueryPerformanceCounter(&timestart);
  355. for (i = 0 ; i< 10; i++) {
  356. hr = NOERROR;
  357. if (FAILED(hr))
  358. goto Exit;
  359. pIXMLParser->Reset();
  360. pIXMLParser->SetFactory(factory);
  361. filestream->close();
  362. filestream->open(filename);
  363. pIXMLParser->SetInput(filestream);
  364. }
  365. ::QueryPerformanceCounter(&t2[j]);
  366. t2[j].QuadPart -= timestart.QuadPart;
  367. parsertime[j].QuadPart = t1[j].QuadPart - t2[j].QuadPart;
  368. }
  369. hr = NOERROR;
  370. Exit:
  371. #endif
  372. return hr;
  373. }
  374. #if SXS_PRECOMPILED_MANIFESTS_ENABLED
  375. HRESULT TestPCMTime(PCWSTR manifestfilename)
  376. {
  377. /*
  378. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  379. remove this from sxs.dll, statically link sxstest.exe instead
  380. */
  381. HRESULT hr = NOERROR;
  382. FN_TRACE_HR(hr);
  383. LARGE_INTEGER tmp1 = {0};
  384. LARGE_INTEGER tmp2 = {0};
  385. LARGE_INTEGER parsertime[10] = {0}, pcmtime[10] = {0};
  386. ULONG i = 0;
  387. hr = GetParserWorkingTime(manifestfilename, parsertime);
  388. if (FAILED(hr))
  389. goto Exit;
  390. hr = GetPCMWorkingTime(manifestfilename, pcmtime);
  391. if (FAILED(hr))
  392. goto Exit;
  393. for (i= 0 ; i < 10; i ++){
  394. tmp1.QuadPart = tmp1.QuadPart + parsertime[i].QuadPart;
  395. tmp2.QuadPart = tmp2.QuadPart + pcmtime[i].QuadPart;
  396. }
  397. tmp1.QuadPart = tmp1.QuadPart/10;
  398. tmp2.QuadPart = tmp2.QuadPart/10;
  399. ::FusionpDbgPrintEx(
  400. FUSION_DBG_LEVEL_INFO,
  401. "SxsDebug::TestPCMTime Result:\n\tXMLParser uses %d,\n\tPCM uses %d,\n\tthe difference is %d.\n",
  402. tmp1.QuadPart, tmp2.QuadPart, tmp1.QuadPart-tmp2.QuadPart);
  403. hr = NOERROR;
  404. Exit:
  405. return hr;
  406. }
  407. /* ---------------------------------------------------------------------------
  408. Two steps :
  409. 1. paring the manifest file,
  410. generate the NodeFactory print-out file1,
  411. generate the precompiled-manifest
  412. 2. using precompiled-manifest and call NodeFactory to generate pcm-printout file2
  413. 3. Compare file1 and file2
  414. --------------------------------------------------------------------------- */
  415. HRESULT
  416. PrecompiledManifestTest(PCWSTR filename) // this is a manifest file name
  417. {
  418. /*
  419. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  420. remove this from sxs.dll, statically link sxstest.exe instead
  421. */
  422. HRESULT hr = S_OK;
  423. FN_TRACE_HR(hr);
  424. #if 0
  425. CSmartRef<IXMLParser> pIXMLParser;
  426. CSmartRef<PCMTestFactory> wfactory;
  427. CSmartRef<PCMTestFactory> rfactory;
  428. CSmartRef<XMLParserTestFileStream> filestream;
  429. CStringBuffer buf;
  430. CSmartRef<CPrecompiledManifestWriter> pPCMWriter;
  431. CSmartRef<CPrecompiledManifestReader> pPCMReader;
  432. FILE *fp = NULL;
  433. if (!filename) {
  434. hr = E_INVALIDARG;
  435. goto Exit;
  436. }
  437. buf.Assign(filename, ::wcslen(filename));
  438. buf.Append(L".pcm", 4);
  439. // create filestream for xmlparser ...
  440. filestream = NEW (XMLParserTestFileStream());
  441. if (!filestream) {
  442. ::FusionpDbgPrintEx(
  443. FUSION_DBG_LEVEL_INFO,
  444. "SxsDebug:: fail to new XMLParserTestFileStream, out of memory\n");
  445. hr = E_OUTOFMEMORY;
  446. goto Exit;
  447. }
  448. if (! filestream->open(filename))
  449. {
  450. ::FusionpDbgPrintEx(
  451. FUSION_DBG_LEVEL_INFO,
  452. "SxsDebug:: fail to call XMLParserTestFileStream::open\n");
  453. hr = E_UNEXPECTED;
  454. goto Exit;
  455. }
  456. // create PCMWriter for xmlparser
  457. wfactory = new PCMTestFactory(L"e:\\manifest.out"));
  458. if (wfactory == NULL)
  459. {
  460. ::FusionpDbgPrintEx(
  461. FUSION_DBG_LEVEL_INFO,
  462. "SxsDebug:: fail to new XMLParserTestFactory, out of memory\n");
  463. hr = E_OUTOFMEMORY;
  464. goto Exit;
  465. }
  466. pPCMWriter = new CPrecompiledManifestWriter);
  467. if (! pPCMWriter)
  468. {
  469. hr = E_OUTOFMEMORY;
  470. goto Exit;
  471. }
  472. pPCMWriter->Initialize(buf);
  473. pPCMWriter->SetFactory(wfactory);
  474. // Create XMLParser
  475. pIXMLParser = NEW(XMLParser);
  476. if (pIXMLParser == NULL){
  477. ::FusionpDbgPrintEx(
  478. FUSION_DBG_LEVEL_ERROR,
  479. "SXS.DLL: Attempt to instantiate XML parser failed\n");
  480. goto Exit;
  481. }
  482. if (FAILED(hr = pIXMLParser->HrInitialize()))
  483. goto Exit;
  484. hr = pIXMLParser->SetInput(filestream); // filestream's RefCount=2
  485. if (! SUCCEEDED(hr))
  486. goto Exit;
  487. hr = pIXMLParser->SetFactory(pPCMWriter); // wfactory's RefCount=2
  488. if (! SUCCEEDED(hr))
  489. goto Exit;
  490. hr = pIXMLParser->Run(-1);
  491. if (FAILED(hr))
  492. goto Exit;
  493. hr = pPCMWriter->Close();
  494. if (FAILED(hr))
  495. goto Exit;
  496. CSimpleFileStream::printf(L"PCM has been generated!!!\n\n");
  497. // PCM Reader
  498. pPCMReader = new CPrecompiledManifestReader);
  499. if (pPCMReader == NULL)
  500. {
  501. hr = E_OUTOFMEMORY;
  502. goto Exit;
  503. }
  504. rfactory = new PCMTestFactory(L"e:\\pcm.out"));
  505. if (rfactory == NULL)
  506. {
  507. ::FusionpDbgPrintEx(
  508. FUSION_DBG_LEVEL_INFO,
  509. "SxsDebug:: fail to new XMLParserTestFactory, out of memory\n");
  510. hr = E_OUTOFMEMORY;
  511. goto Exit;
  512. }
  513. hr = pPCMReader->InvokeNodeFactory(buf, rfactory);
  514. if (FAILED(hr))
  515. goto Exit;
  516. hr = NOERROR;
  517. Exit:
  518. #endif
  519. return hr;
  520. }
  521. #endif // SXS_PRECOMPILED_MANIFESTS_ENABLED
  522. BOOL CreateMultiLevelDirectoryTest(PCWSTR pwszNewDirs)
  523. {
  524. /*
  525. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  526. remove this from sxs.dll, statically link sxstest.exe instead
  527. */
  528. BOOL fSuccess = TRUE;
  529. FN_TRACE_WIN32(fSuccess);
  530. #if 0
  531. const static WCHAR CurrentDirectory[]=L"e:\\tmp\\tmp";
  532. IFW32FALSE_EXIT(::SxspCreateMultiLevelDirectory(CurrentDirectory, pwszNewDirs));
  533. fSuccess = TRUE;
  534. Exit:
  535. #endif
  536. return fSuccess;
  537. }
  538. BOOL TestCopyDirectory()
  539. {
  540. /*
  541. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  542. remove this from sxs.dll, statically link sxstest.exe instead
  543. large frame
  544. */
  545. BOOL fSuccess = FALSE;
  546. FN_TRACE_WIN32(fSuccess);
  547. #if 0
  548. CSmallStringBuffer m1;
  549. CSmallStringBuffer m2;
  550. IFW32FALSE_EXIT(m1.Win32Assign(L"Z:\\tmp\\tmp", NUMBER_OF(L"Z:\\tmp\\tmp")-1));
  551. IFW32FALSE_EXIT(m2.Win32Assign(L"Z:\\tests\\tmp", NUMBER_OF(L"Z:\\tests\\tmp")-1));
  552. IFW32FALSE_EXIT(::SxspInstallMoveFileExW(m1, m2, MOVEFILE_REPLACE_EXISTING));
  553. fSuccess = TRUE;
  554. Exit:
  555. #endif
  556. return fSuccess;
  557. }
  558. BOOL TestSxsGeneratePath()
  559. {
  560. /*
  561. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  562. remove this from sxs.dll, statically link sxstest.exe instead
  563. large frame
  564. it is bad to have these hard coded strings in shipping files
  565. */
  566. //
  567. // the result is as below
  568. //
  569. //path is c:\winnt\winsxs\Manifests\x86_dynamicdll_b54bc117ce08a1e8_1.1.0.0_en-us_fb8e827d.Manifest
  570. //path is Manifests\x86_dynamicdll_b54bc117ce08a1e8_1.1.0.0_en-us_fb8e827d.Manifest
  571. //path is c:\winnt\winsxs\Manifests\
  572. //path is Manifests\x86_dynamicdll_b54bc117ce08a1e8_en-us_2ffeb063.Manifest
  573. //---------------------------------------
  574. //path is c:\winnt\winsxs\x86_policy.1.0.dynamicdll_b54bc117ce08a1e8_1.1.0.0_en-us_d51541cb\
  575. //path is x86_policy.1.0.dynamicdll_b54bc117ce08a1e8_1.1.0.0_en-us_d51541cb\
  576. //path is c:\winnt\winsxs\
  577. //path is x86_policy.1.0.dynamicdll_b54bc117ce08a1e8_en-us_b74d3d95\
  578. //---------------------------------------
  579. //path is c:\winnt\winsxs\Policies\x86_policy.1.0.dynamicdll_b54bc117ce08a1e8_en-us_b74d3d95\1.1.0.0.Policy
  580. //path is Policies\x86_policy.1.0.dynamicdll_b54bc117ce08a1e8_en-us_b74d3d95\1.1.0.0.Policy
  581. //path is c:\winnt\winsxs\Policies\
  582. //path is Policies\x86_policy.1.0.dynamicdll_b54bc117ce08a1e8_en-us_b74d3d95\1.1.0.0.Policy
  583. // if the assembly does not have version, flag=0 and pathType=policy would generate "policy store"
  584. // c:\winnt\winsxs\Policies\x86_policy.1.0.dynamicdll_b54bc117ce08a1e8_en-us_b74d3d95
  585. //
  586. BOOL fSuccess = FALSE;
  587. FN_TRACE_WIN32(fSuccess);
  588. #if 0
  589. CTinyStringBuffer PathBuffer;
  590. PASSEMBLY_IDENTITY pAssemblyIdentity = NULL;
  591. //WCHAR szDisplayName[]=L"policy.1.0.dynamicdll,type=\"win32-policy\",publicKeyToken=\"b54bc117ce08a1e8\",version=\"1.1.0.0\",language=\"en-us\",processorArchitecture=\"x86\"";
  592. PWSTR szDisplayName[]= {
  593. L"dynamicdll,type=\"win32\",publicKeyToken=\"b54bc117ce08a1e8\",version=\"1.1.0.0\",language=\"en-us\",processorArchitecture=\"x86\"",
  594. L"policy.1.0.dynamicdll,type=\"win32-policy\",publicKeyToken=\"b54bc117ce08a1e8\",version=\"1.1.0.0\",language=\"en-us\",processorArchitecture=\"x86\"",
  595. L"policy.1.0.dynamicdll,type=\"win32-policy\",publicKeyToken=\"b54bc117ce08a1e8\",version=\"1.1.0.0\",language=\"en-us\",processorArchitecture=\"x86\""
  596. };
  597. DWORD j, dwPathType;
  598. DWORD flags[]={
  599. 0,
  600. SXSP_GENERATE_SXS_PATH_FLAG_OMIT_ROOT,
  601. SXSP_GENERATE_SXS_PATH_FLAG_PARTIAL_PATH,
  602. SXSP_GENERATE_SXS_PATH_FLAG_OMIT_ROOT | SXSP_GENERATE_SXS_PATH_FLAG_OMIT_VERSION};
  603. printf("---------------------------------------\n");
  604. for (dwPathType = SXSP_GENERATE_SXS_PATH_PATHTYPE_MANIFEST; dwPathType <= SXSP_GENERATE_SXS_PATH_PATHTYPE_POLICY; dwPathType++)
  605. //for (dwPathType = SXSP_GENERATE_SXS_PATH_PATHTYPE_ASSEMBLY; dwPathType <= SXSP_GENERATE_SXS_PATH_PATHTYPE_POLICY; dwPathType++)
  606. {
  607. IFW32FALSE_EXIT(::SxspCreateAssemblyIdentityFromTextualString(
  608. szDisplayName[dwPathType - 1],
  609. &pAssemblyIdentity));
  610. for (j = 0 ; j < NUMBER_OF(flags); j++)
  611. {
  612. IFW32FALSE_EXIT(::SxspGenerateSxsPath(
  613. flags[j],
  614. dwPathType,
  615. L"c:\\winnt\\winsxs",
  616. wcslen(L"c:\\winnt\\winsxs"),
  617. pAssemblyIdentity,
  618. NULL,
  619. PathBuffer));
  620. printf("path is %S\n", static_cast<PCWSTR>(PathBuffer));
  621. }
  622. printf("---------------------------------------\n");
  623. ::SxsDestroyAssemblyIdentity(pAssemblyIdentity);
  624. pAssemblyIdentity = NULL;
  625. }
  626. fSuccess = TRUE;
  627. Exit:
  628. if (pAssemblyIdentity)
  629. ::SxsDestroyAssemblyIdentity(pAssemblyIdentity);
  630. #endif
  631. return fSuccess;
  632. }
  633. BOOL ManifestProbeTest()
  634. {
  635. /*
  636. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  637. remove this from sxs.dll, statically link sxstest.exe instead
  638. it is bad to have these hard coded strings in shipping files
  639. */
  640. BOOL fSuccess = FALSE;
  641. FN_TRACE_WIN32(fSuccess);
  642. #if 0
  643. DWORD index = 0;
  644. CTinyStringBuffer PathBuffer;
  645. PASSEMBLY_IDENTITY pAssemblyIdentity = NULL;
  646. PROBING_ATTRIBUTE_CACHE pac = { 0 };
  647. ASSEMBLY_IDENTITY_ATTRIBUTE AttributeName;
  648. ASSEMBLY_IDENTITY_ATTRIBUTE AttributeVersion;
  649. ASSEMBLY_IDENTITY_ATTRIBUTE AttributeLangID;
  650. ASSEMBLY_IDENTITY_ATTRIBUTE AttributeProcessorArchitecture;
  651. PASSEMBLY_IDENTITY_ATTRIBUTE Attributes[] = {
  652. &AttributeName, &AttributeVersion,
  653. &AttributeLangID, &AttributeProcessorArchitecture};
  654. AttributeName.Flags = 0; // reserved flags : must be 0;
  655. AttributeName.NamespaceCch = 0;
  656. AttributeName.NameCch = 4;
  657. AttributeName.ValueCch = 7;
  658. AttributeName.Namespace = NULL;
  659. AttributeName.Name = L"name";
  660. AttributeName.Value = L"foo.mui";
  661. AttributeVersion.Flags = 0; // reserved flags : must be 0;
  662. AttributeVersion.NamespaceCch = 0;
  663. AttributeVersion.NameCch = 7;
  664. AttributeVersion.ValueCch = 7;
  665. AttributeVersion.Namespace = NULL;
  666. AttributeVersion.Name = L"version";
  667. AttributeVersion.Value = L"1.1.1.1";
  668. AttributeLangID.Flags = 0; // reserved flags : must be 0;
  669. AttributeLangID.NamespaceCch = 0;
  670. AttributeLangID.NameCch = 8;
  671. AttributeLangID.ValueCch = 5;
  672. AttributeLangID.Namespace = NULL;
  673. AttributeLangID.Name = L"language";
  674. AttributeLangID.Value = L"en-us";
  675. AttributeProcessorArchitecture .Flags = 0; // reserved flags : must be 0;
  676. AttributeProcessorArchitecture .NamespaceCch = 0;
  677. AttributeProcessorArchitecture .NameCch = 21;
  678. AttributeProcessorArchitecture .ValueCch = 3;
  679. AttributeProcessorArchitecture .Namespace = NULL;
  680. AttributeProcessorArchitecture .Name = L"processorArchitecture";
  681. AttributeProcessorArchitecture .Value = L"x86";
  682. IFW32FALSE_EXIT(::SxsCreateAssemblyIdentity(
  683. 0, // DWORD Flags,
  684. ASSEMBLY_IDENTITY_TYPE_DEFINITION, // ULONG Type,
  685. &pAssemblyIdentity,
  686. 4, // ULONG AttributeCount,
  687. Attributes)); // PCASSEMBLY_IDENTITY_ATTRIBUTE const *Attributes
  688. while(1) {// run until we run out of probing-path
  689. bool fDone = false;
  690. if (!::SxspGenerateManifestPathForProbing(
  691. index,
  692. 0,
  693. NULL,
  694. 0,
  695. ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE,
  696. L"E:\\APPBASE\\",
  697. 11,
  698. pAssemblyIdentity,
  699. &pac,
  700. PathBuffer,
  701. NULL,
  702. fDone))
  703. {
  704. goto Exit;
  705. }
  706. if (fDone)
  707. break;
  708. PathBuffer.Clear();
  709. index ++;
  710. }
  711. fSuccess = TRUE;
  712. Exit:
  713. if (pAssemblyIdentity)
  714. ::SxsDestroyAssemblyIdentity(pAssemblyIdentity);
  715. if (!fSuccess) {
  716. DWORD dwLastError = ::FusionpGetLastWin32Error();
  717. if (dwLastError == BASESRV_SXS_RETURN_RESULT_SYSTEM_DEFAULT_DEPENDENCY_ASSEMBLY_NOT_FOUND){
  718. ::FusionpSetLastWin32Error(0);
  719. fSuccess = TRUE;
  720. }
  721. }
  722. #endif
  723. return fSuccess;
  724. }
  725. #define WATCHBUCKET_NOTIFYSIZE (1024)
  726. typedef struct _tWATCH_BUCKET
  727. {
  728. HANDLE hFile;
  729. HANDLE hCompleteEvent;
  730. PCSXS_PROTECT_DIRECTORY pProtectInfo;
  731. OVERLAPPED olapInfo;
  732. BYTE NotifyInfo[WATCHBUCKET_NOTIFYSIZE];
  733. DWORD dwBytesBack;
  734. }
  735. WATCH_BUCKET, *PWATCH_BUCKET;
  736. HRESULT
  737. TryWatchingDirectories()
  738. {
  739. /*
  740. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  741. remove this from sxs.dll, statically link sxstest.exe instead
  742. */
  743. HRESULT hrSuccess = E_FAIL;
  744. FN_TRACE_HR(hrSuccess);
  745. #if 0
  746. PCSXS_PROTECT_DIRECTORY pWatchList;
  747. SIZE_T cWatchList = 0;
  748. DWORD dwWhichSignalled = 0;
  749. DWORD dw = 0;
  750. PWATCH_BUCKET pWatchBuckets = 0;
  751. HANDLE* pHandleList = 0;
  752. IFW32FALSE_EXIT(::SxsProtectionGatherEntriesW(&pWatchList, &cWatchList));
  753. pWatchBuckets = FUSION_NEW_ARRAY(WATCH_BUCKET, cWatchList);
  754. pHandleList = FUSION_NEW_ARRAY(HANDLE, cWatchList);
  755. //
  756. // Fill in the list with handles to directories
  757. //
  758. for (dw = 0; dw < cWatchList; dw++)
  759. {
  760. PWATCH_BUCKET pbTemp = pWatchBuckets + dw;
  761. ZeroMemory(pbTemp, sizeof(*pbTemp));
  762. pbTemp->pProtectInfo = pWatchList + dw;
  763. pbTemp->hFile = ::CreateFileW(
  764. pWatchList[dw].pwszDirectory,
  765. FILE_LIST_DIRECTORY,
  766. FILE_SHARE_READ | FILE_SHARE_DELETE | FILE_SHARE_WRITE,
  767. NULL,
  768. OPEN_EXISTING,
  769. FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED,
  770. NULL);
  771. pHandleList[dw] = CreateEventW(NULL, FALSE, FALSE, NULL);
  772. pbTemp->hCompleteEvent = pHandleList[dw];
  773. pbTemp->olapInfo.hEvent = pHandleList[dw];
  774. ::ReadDirectoryChangesW(
  775. pbTemp->hFile,
  776. (PVOID)(&pbTemp->NotifyInfo),
  777. WATCHBUCKET_NOTIFYSIZE,
  778. pbTemp->pProtectInfo->ulRecursiveFlag & SXS_PROTECT_RECURSIVE,
  779. SXS_PROTECT_FILTER_DEFAULT,
  780. &pbTemp->dwBytesBack,
  781. &pbTemp->olapInfo,
  782. NULL);
  783. }
  784. //
  785. // We now have a list of directories that we need to watch for changes.
  786. //
  787. while (true)
  788. {
  789. dwWhichSignalled = WaitForMultipleObjects(static_cast<DWORD>(cWatchList), pHandleList, FALSE, INFINITE);
  790. dwWhichSignalled -= WAIT_OBJECT_0;
  791. if (dwWhichSignalled < cWatchList)
  792. {
  793. //
  794. // Somebody went and fiddled with a directory!
  795. //
  796. dwWhichSignalled -= WAIT_OBJECT_0;
  797. ::FusionpDbgPrintEx(
  798. FUSION_DBG_LEVEL_INFO,
  799. "Someone changed: %ls\n",
  800. pWatchBuckets[dwWhichSignalled].pProtectInfo->pwszDirectory);
  801. ResetEvent(pHandleList[dwWhichSignalled]);
  802. PFILE_NOTIFY_INFORMATION pCursor;
  803. pCursor = (PFILE_NOTIFY_INFORMATION) pWatchBuckets[dwWhichSignalled].NotifyInfo;
  804. while (true)
  805. {
  806. ::SxsProtectionNotifyW(
  807. (PVOID)pWatchBuckets[dwWhichSignalled].pProtectInfo,
  808. pCursor->FileName,
  809. pCursor->FileNameLength / sizeof(pCursor->FileName[0]),
  810. pCursor->Action);
  811. if (pCursor->NextEntryOffset)
  812. pCursor = (PFILE_NOTIFY_INFORMATION)(((PBYTE)pCursor) + pCursor->NextEntryOffset);
  813. else
  814. break;
  815. }
  816. ::ReadDirectoryChangesW(
  817. pWatchBuckets[dwWhichSignalled].hFile,
  818. (PVOID)(&pWatchBuckets[dwWhichSignalled].NotifyInfo),
  819. WATCHBUCKET_NOTIFYSIZE,
  820. pWatchBuckets[dwWhichSignalled].pProtectInfo->ulRecursiveFlag & SXS_PROTECT_RECURSIVE,
  821. SXS_PROTECT_FILTER_DEFAULT,
  822. &pWatchBuckets[dwWhichSignalled].dwBytesBack,
  823. &pWatchBuckets[dwWhichSignalled].olapInfo,
  824. NULL);
  825. }
  826. }
  827. hrSuccess = S_OK;
  828. Exit:
  829. #endif
  830. return hrSuccess;
  831. }
  832. BOOL
  833. DllRedirectionTest(
  834. PCWSTR manifestFileName
  835. )
  836. {
  837. /*
  838. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  839. remove this from sxs.dll, statically link sxstest.exe instead
  840. */
  841. BOOL fSuccess = FALSE;
  842. FN_TRACE_WIN32(fSuccess);
  843. CFileStream manifestFileStream;
  844. CResourceStream ResourceStream;
  845. CFileStream policyFileStream;
  846. SXS_GENERATE_ACTIVATION_CONTEXT_PARAMETERS parameters = {0};
  847. CTinyStringBuffer assemblyDirectory;
  848. CTinyStringBuffer CandidatePolicyPathBuffer;
  849. BOOL fPolicyExist = FALSE;
  850. PWSTR p = NULL;
  851. p = wcsrchr(manifestFileName, L'.');
  852. if (p && ((_wcsicmp(p, L".dll") ==0) || (_wcsicmp(p, L".exe") ==0))) // manifest is from a resource of a DLL or EXE
  853. {
  854. IFW32FALSE_EXIT(ResourceStream.Initialize(manifestFileName, MAKEINTRESOURCEW(RT_MANIFEST)));
  855. parameters.Manifest.Path = manifestFileName;
  856. parameters.Manifest.Stream = &ResourceStream;
  857. parameters.Manifest.PathType = ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE;
  858. IFW32FALSE_EXIT(assemblyDirectory.Win32Assign(manifestFileName, ::wcslen(manifestFileName)));
  859. IFW32FALSE_EXIT(assemblyDirectory.Win32RemoveLastPathElement());
  860. parameters.AssemblyDirectory = assemblyDirectory;
  861. }
  862. else
  863. {
  864. IFW32FALSE_EXIT(
  865. manifestFileStream.OpenForRead(
  866. manifestFileName,
  867. CImpersonationData(),
  868. FILE_SHARE_READ,
  869. OPEN_EXISTING,
  870. FILE_FLAG_SEQUENTIAL_SCAN));
  871. parameters.Manifest.Path = manifestFileName;
  872. parameters.Manifest.Stream = &manifestFileStream;
  873. parameters.Manifest.PathType = ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE;
  874. IFW32FALSE_EXIT(assemblyDirectory.Win32Assign(manifestFileName, ::wcslen(manifestFileName)));
  875. IFW32FALSE_EXIT(assemblyDirectory.Win32RemoveLastPathElement());
  876. parameters.AssemblyDirectory = assemblyDirectory;
  877. }
  878. // look for policy file in the same dir as the manifest path
  879. IFW32FALSE_EXIT(CandidatePolicyPathBuffer.Win32Assign(manifestFileName, ::wcslen(manifestFileName)));
  880. IFW32FALSE_EXIT(CandidatePolicyPathBuffer.Win32ChangePathExtension(CONFIG_FILE_EXTENSION, NUMBER_OF(CONFIG_FILE_EXTENSION) - 1, eErrorIfNoExtension));
  881. if (::GetFileAttributesW(CandidatePolicyPathBuffer) != -1) { // policy file exists
  882. fPolicyExist = TRUE;
  883. IFW32FALSE_EXIT(
  884. policyFileStream.OpenForRead(
  885. CandidatePolicyPathBuffer,
  886. CImpersonationData(),
  887. FILE_SHARE_READ,
  888. OPEN_EXISTING,
  889. FILE_FLAG_SEQUENTIAL_SCAN));
  890. parameters.Policy.Path = CandidatePolicyPathBuffer;
  891. parameters.Policy.Stream = &policyFileStream;
  892. }
  893. parameters.ProcessorArchitecture = 0 ;
  894. parameters.LangId = GetUserDefaultUILanguage();
  895. parameters.Flags = SXS_GENERATE_ACTIVATION_CONTEXT_FLAG_APP_RUNNING_IN_SAFEMODE;
  896. IFW32FALSE_EXIT(::SxsGenerateActivationContext(&parameters));
  897. fSuccess = TRUE;
  898. Exit:
  899. CSxsPreserveLastError ple;
  900. ::CloseHandle(parameters.SectionObjectHandle);
  901. ple.Restore();
  902. return fSuccess;
  903. }
  904. BOOL SxspDebugTestFusionArray(PCWSTR dir1, PCWSTR dir2)
  905. {
  906. BOOL fSuccess = FALSE;
  907. FN_TRACE_WIN32(fSuccess);
  908. #if 0
  909. CTinyStringBuffer sbDir1;
  910. CTinyStringBuffer sbDir2;
  911. CFusionDirectoryDifference dirResult;
  912. IFW32FALSE_EXIT(sbDir1.Win32Assign(dir1, wcslen(dir1)));
  913. IFW32FALSE_EXIT(sbDir2.Win32Assign(dir2, wcslen(dir2)));
  914. IFW32FALSE_EXIT(
  915. ::FusionpCompareDirectoriesSizewiseRecursively(
  916. &dirResult,
  917. sbDir1,
  918. sbDir2));
  919. fSuccess = TRUE;
  920. Exit:
  921. #endif
  922. return fSuccess;
  923. }
  924. //
  925. // this function is written for Testing team to generate pAssemblyIdentity
  926. // there are two ways to generate assemblyIdentity, one is insert one attribute each time,
  927. // another way is to make all attributes to be inserted ready in an array and call
  928. // SxsCreateAssemblyIdentity. The con and pro for both approaches are obvious,
  929. // the input string must be in a format as "ns1:n1=v1;ns2:n2=v2;",
  930. // the whole string ending with a trailing ";", ns could be NULL
  931. // this fucntion does not deal with complicate case such as ns/name/value string contains
  932. // special chars. let me know if you do need deal with it...
  933. //
  934. // xiaoyuw@09/26/2000
  935. //
  936. BOOL
  937. SxspGenerateManifestPathOnAssemblyIdentity(
  938. PCWSTR str,
  939. PWSTR pszOut,
  940. ULONG *pCchstr,
  941. PASSEMBLY_IDENTITY *ppAssemblyIdentity
  942. )
  943. {
  944. BOOL fSuccess = FALSE;
  945. FN_TRACE_WIN32(fSuccess);
  946. PASSEMBLY_IDENTITY pAssemblyIdentity = NULL;
  947. CStringBuffer PathBuffer;
  948. if (ppAssemblyIdentity)
  949. *ppAssemblyIdentity = NULL;
  950. PARAMETER_CHECK(str != NULL);
  951. PARAMETER_CHECK(pCchstr != NULL);
  952. IFW32FALSE_EXIT(
  953. ::SxspCreateAssemblyIdentityFromTextualString(
  954. str,
  955. &pAssemblyIdentity));
  956. // AssemblyIdentity is created, now generate the path
  957. IFW32FALSE_EXIT(
  958. ::SxspGenerateSxsPath(
  959. SXSP_GENERATE_SXS_PATH_FLAG_OMIT_ROOT,
  960. SXSP_GENERATE_SXS_PATH_PATHTYPE_ASSEMBLY,
  961. NULL,
  962. 0,
  963. pAssemblyIdentity,
  964. NULL,
  965. PathBuffer));
  966. IFW32FALSE_EXIT(PathBuffer.Win32CopyStringOut(pszOut, pCchstr));
  967. if (ppAssemblyIdentity != NULL)
  968. {
  969. *ppAssemblyIdentity = pAssemblyIdentity ;
  970. pAssemblyIdentity = NULL;
  971. }
  972. fSuccess = TRUE;
  973. Exit:
  974. if (pAssemblyIdentity != NULL)
  975. SxsDestroyAssemblyIdentity(pAssemblyIdentity);
  976. return fSuccess ;
  977. }
  978. /* --------------------------------------------------------------------------------
  979. POLICY_PATH_FLAG_POLICY_IDENTITY_TEXTUAL_FORMAT : x86_policy.1.0.dynamicdll_b54bc117ce08a1e8_en-us_d51541cb
  980. POLICY_PATH_FLAG_FULL_QUALIFIED_POLICIES_DIR : c:\winnt\winsxs\policies
  981. POLICY_PATH_FLAG_FULL_QUALIFIED_POLICY_FILE_NAME : c:\winnt\winsxs\policies\x86_policy.1.0.dynamicdll_b54bc117ce08a1e8_en-us_d51541cb\1.1.0.0.policy, for .cat, you have to replace it manually
  982. -------------------------------------------------------------------------------- */
  983. BOOL
  984. SxspGeneratePolicyPathOnAssemblyIdentity(
  985. DWORD dwFlag,
  986. PCWSTR str,
  987. PWSTR pszOut,
  988. ULONG *pCchstr,
  989. PASSEMBLY_IDENTITY *ppAssemblyIdentity
  990. )
  991. {
  992. /*
  993. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  994. */
  995. BOOL fSuccess = FALSE;
  996. FN_TRACE_WIN32(fSuccess);
  997. PASSEMBLY_IDENTITY pAssemblyIdentity;
  998. DWORD dwPathType = 0;
  999. DWORD dwGenerateFlag = 0;
  1000. CTinyStringBuffer PathBuffer;
  1001. CTinyStringBuffer bufAssemblyRootDirectory;
  1002. IFW32FALSE_EXIT(
  1003. ::SxspCreateAssemblyIdentityFromTextualString(
  1004. str,
  1005. &pAssemblyIdentity));
  1006. switch (dwFlag)
  1007. {
  1008. case POLICY_PATH_FLAG_POLICY_IDENTITY_TEXTUAL_FORMAT:
  1009. dwPathType = SXSP_GENERATE_SXS_PATH_PATHTYPE_ASSEMBLY;
  1010. dwGenerateFlag = SXSP_GENERATE_SXS_PATH_FLAG_OMIT_ROOT | SXSP_GENERATE_SXS_PATH_FLAG_OMIT_VERSION;
  1011. break;
  1012. case POLICY_PATH_FLAG_FULL_QUALIFIED_POLICIES_DIR:
  1013. {
  1014. IFW32FALSE_EXIT(SxspGetAssemblyRootDirectory(bufAssemblyRootDirectory));
  1015. dwPathType = SXSP_GENERATE_SXS_PATH_PATHTYPE_POLICY;
  1016. dwGenerateFlag = SXSP_GENERATE_SXS_PATH_FLAG_PARTIAL_PATH;
  1017. }
  1018. break;
  1019. case POLICY_PATH_FLAG_FULL_QUALIFIED_POLICY_FILE_NAME:
  1020. {
  1021. IFW32FALSE_EXIT(SxspGetAssemblyRootDirectory(bufAssemblyRootDirectory));
  1022. dwPathType = SXSP_GENERATE_SXS_PATH_PATHTYPE_POLICY;
  1023. dwGenerateFlag = 0;
  1024. }
  1025. break;
  1026. default:
  1027. ::FusionpSetLastWin32Error(ERROR_INVALID_PARAMETER);
  1028. goto Exit;
  1029. }
  1030. IFW32FALSE_EXIT(
  1031. ::SxspGenerateSxsPath(
  1032. dwGenerateFlag,
  1033. dwPathType,
  1034. bufAssemblyRootDirectory,
  1035. bufAssemblyRootDirectory.Cch(),
  1036. pAssemblyIdentity,
  1037. NULL,
  1038. PathBuffer));
  1039. IFW32FALSE_EXIT(PathBuffer.Win32CopyStringOut(pszOut, pCchstr));
  1040. if (ppAssemblyIdentity != NULL)
  1041. {
  1042. *ppAssemblyIdentity = pAssemblyIdentity ;
  1043. pAssemblyIdentity = NULL;
  1044. }
  1045. fSuccess = TRUE;
  1046. Exit:
  1047. if (pAssemblyIdentity != NULL)
  1048. SxsDestroyAssemblyIdentity(pAssemblyIdentity);
  1049. return fSuccess ;
  1050. }
  1051. BOOL SxspDebugTestAssemblyIdentityHash()
  1052. {
  1053. /*
  1054. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  1055. remove this from sxs.dll, statically link sxstest.exe instead
  1056. it is bad to have these hard coded strings in shipping files
  1057. */
  1058. BOOL fSuccess = FALSE;
  1059. FN_TRACE_WIN32(fSuccess);
  1060. #if 0
  1061. ULONG hash1 = 0;
  1062. ULONG hash2 = 0;
  1063. PASSEMBLY_IDENTITY pAssemblyIdentity = NULL;
  1064. ASSEMBLY_IDENTITY_ATTRIBUTE Attribute;
  1065. IFW32FALSE_EXIT(::SxsCreateAssemblyIdentity(0, ASSEMBLY_IDENTITY_TYPE_DEFINITION, &pAssemblyIdentity, 0, NULL));
  1066. Attribute.Flags = 0;
  1067. Attribute.NamespaceCch = 18;
  1068. Attribute.Namespace = L"http://interesting";
  1069. Attribute.NameCch = 8;
  1070. Attribute.Name = L"whatever";
  1071. Attribute.ValueCch = 32;
  1072. Attribute.Value = L"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_";
  1073. IFW32FALSE_EXIT(::SxsInsertAssemblyIdentityAttribute(0, pAssemblyIdentity, &Attribute));
  1074. IFW32FALSE_EXIT(SxsHashAssemblyIdentity(0, pAssemblyIdentity, &hash1));
  1075. ::SxsDestroyAssemblyIdentity(pAssemblyIdentity);
  1076. // create second assembly identity
  1077. IFW32FALSE_EXIT(::SxsCreateAssemblyIdentity(0, ASSEMBLY_IDENTITY_TYPE_DEFINITION, &pAssemblyIdentity, 0, NULL));
  1078. Attribute.Flags = 0;
  1079. Attribute.NamespaceCch = 18;
  1080. Attribute.Namespace = L"http://interesting";
  1081. Attribute.NameCch = 8;
  1082. Attribute.Name = L"whatever";
  1083. Attribute.ValueCch = 32;
  1084. Attribute.Value = L"/>BABCDGHGHKLMNMNOPSTUVUVYZYZ[\\_`";
  1085. IFW32FALSE_EXIT(::SxsInsertAssemblyIdentityAttribute(0, pAssemblyIdentity, &Attribute));
  1086. IFW32FALSE_EXIT(SxsHashAssemblyIdentity(0, pAssemblyIdentity, &hash2));
  1087. ::SxsDestroyAssemblyIdentity(pAssemblyIdentity);
  1088. fSuccess = TRUE;
  1089. Exit:
  1090. if (pAssemblyIdentity)
  1091. ::SxsDestroyAssemblyIdentity(pAssemblyIdentity);
  1092. #endif
  1093. return fSuccess;
  1094. }
  1095. BOOL
  1096. SxspDebugTestNewCatalogSignerThingy(
  1097. PCWSTR pcwszCatalog
  1098. )
  1099. {
  1100. /*
  1101. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  1102. remove this from sxs.dll, statically link sxstest.exe instead
  1103. */
  1104. BOOL fSuccess = FALSE;
  1105. ULONG ulKeyLength = 0;
  1106. CPublicKeyInformation CatalogInformation;
  1107. CTinyStringBuffer sbSignerString;
  1108. CTinyStringBuffer sbCatalogName;
  1109. FN_TRACE_WIN32(fSuccess);
  1110. IFW32FALSE_EXIT(sbCatalogName.Win32Assign(pcwszCatalog, ::wcslen(pcwszCatalog)));
  1111. IFW32FALSE_EXIT(CatalogInformation.Initialize(sbCatalogName));
  1112. IFW32FALSE_EXIT(CatalogInformation.GetStrongNameString(sbSignerString));
  1113. IFW32FALSE_EXIT(CatalogInformation.GetPublicKeyBitLength(ulKeyLength));
  1114. ::FusionpDbgPrintEx(
  1115. FUSION_DBG_LEVEL_INFO,
  1116. "Strong name of catalog signer: %ls\n"
  1117. "Key: %ls (length %ld)\n",
  1118. static_cast<PCWSTR>(sbSignerString),
  1119. ulKeyLength);
  1120. fSuccess = TRUE;
  1121. Exit:
  1122. return fSuccess;
  1123. };
  1124. BOOL TestSystemDefaultActCtxGeneration()
  1125. {
  1126. /*
  1127. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  1128. remove this from sxs.dll, statically link sxstest.exe instead
  1129. large frame
  1130. it is bad to have these hard coded strings in shipping files
  1131. */
  1132. BOOL fSuccess = FALSE;
  1133. FN_TRACE_WIN32(fSuccess);
  1134. #if 0
  1135. SXS_GENERATE_ACTIVATION_CONTEXT_PARAMETERS Parameter = {0};
  1136. WCHAR pszTextualAssemblyIdentity[] =
  1137. L"Microsoft.Windows.SystemCompatible,publicKeyToken=\"6595b64144ccf1df\",version=\"5.1.1.0\",type=\"win32\",processorArchitecture=\"x86\"\0";
  1138. CStringBuffer AssemblyDirectory;
  1139. IFW32FALSE_EXIT(::SxspGetAssemblyRootDirectory(AssemblyDirectory));
  1140. IFW32FALSE_EXIT(AssemblyDirectory.Win32EnsureTrailingPathSeparator());
  1141. Parameter.ProcessorArchitecture = 0 ;
  1142. Parameter.LangId = 0x0409;
  1143. Parameter.Flags = SXS_GENERATE_ACTIVATION_CONTEXT_FLAG_SYSTEM_DEFAULT_TEXTUAL_ASSEMBLY_IDENTITY;
  1144. Parameter.TextualAssemblyIdentity = pszTextualAssemblyIdentity;
  1145. Parameter.AssemblyDirectory = AssemblyDirectory;
  1146. IFW32FALSE_EXIT(SxsGenerateActivationContext(&Parameter));
  1147. fSuccess = TRUE;
  1148. Exit:
  1149. // check LastError
  1150. if (Parameter.SectionObjectHandle != NULL)
  1151. ::CloseHandle(Parameter.SectionObjectHandle);
  1152. if (Parameter.Manifest.Stream)
  1153. Parameter.Manifest.Stream->Release();
  1154. #endif
  1155. return fSuccess;
  1156. }
  1157. BOOL
  1158. TestSfcUIPopup()
  1159. {
  1160. /*
  1161. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  1162. remove this from sxs.dll, statically link sxstest.exe instead
  1163. large frame
  1164. it is bad to have these hard coded strings in shipping files
  1165. */
  1166. BOOL fSuccess = FALSE;
  1167. FN_TRACE_WIN32(fSuccess);
  1168. #if 0
  1169. CAssemblyRecoveryInfo RecoverInfo;
  1170. CSXSMediaPromptDialog PromptDialog;
  1171. CTinyStringBuffer sbAssemblyName;
  1172. const static WCHAR wchTestName[] = L"x86_Microsoft.Tools.VisualCPlusPlus.Runtime-Libraries_6595b64144ccf1df_6.0.0.0_x-ww_ff9986d7";
  1173. bool fNoAssembly = false;
  1174. IFW32FALSE_EXIT(RecoverInfo.Initialize());
  1175. IFW32FALSE_EXIT(sbAssemblyName.Win32Assign(wchTestName, NUMBER_OF(wchTestName) - 1));
  1176. IFW32FALSE_EXIT(RecoverInfo.AssociateWithAssembly(sbAssemblyName, fNoAssembly));
  1177. fSuccess = TRUE;
  1178. Exit:
  1179. #endif
  1180. return fSuccess;
  1181. }
  1182. BOOL
  1183. TestPolicyPathGeneration()
  1184. {
  1185. /*
  1186. NTRAID#NTBUG9-591177-2002/03/31-JayKrell
  1187. remove this from sxs.dll, statically link sxstest.exe instead
  1188. it is bad to have these hard coded strings in shipping files
  1189. */
  1190. #if 0
  1191. WCHAR str[] = L"policy.1.0.ms-sxstest-folder1,processorArchitecture=\"x86\",type=\"win32-policy\",language=\"en\",version=\"2.2.2.2\",publicKeyToken=\"75e377300ab7b886\"";
  1192. WCHAR pszOut[1024];
  1193. ULONG Cchstr = 0;
  1194. for (DWORD dwFlag=0; dwFlag<3; dwFlag++)
  1195. {
  1196. SxspGeneratePolicyPathOnAssemblyIdentity(
  1197. dwFlag,
  1198. str,
  1199. pszOut,
  1200. &Cchstr,
  1201. NULL);
  1202. };
  1203. #endif
  1204. return TRUE;
  1205. }
  1206. BOOL
  1207. SxspDebug(
  1208. ULONG iOperation,
  1209. DWORD dwFlags,
  1210. PCWSTR pszParameter1,
  1211. PVOID pvParameter2)
  1212. {
  1213. BOOL fSuccess = FALSE;
  1214. FN_TRACE_WIN32(fSuccess);
  1215. switch (iOperation)
  1216. {
  1217. case SXS_DEBUG_SYSTEM_DEFAULT_ACTCTX_GENERATION:
  1218. IFW32FALSE_EXIT(::TestSystemDefaultActCtxGeneration());
  1219. break;
  1220. case SXS_DEBUG_SFC_UI_TEST:
  1221. IFW32FALSE_EXIT( TestSfcUIPopup() );
  1222. break;
  1223. case SXS_DEBUG_CATALOG_SIGNER_CHECK:
  1224. IFW32FALSE_EXIT(::SxspDebugTestNewCatalogSignerThingy(pszParameter1));
  1225. break;
  1226. case SXS_DEBUG_ASSEMBLY_IDENTITY_HASH:
  1227. IFW32FALSE_EXIT(::SxspDebugTestAssemblyIdentityHash());
  1228. break;
  1229. case SXS_DEBUG_ASSEMBLYNAME_CONVERSION:
  1230. //IFCOMFAILED_EXIT(TestAssemblyName());
  1231. //IFCOMFAILED_EXIT(::TestDeleteInstalledAssemblyBasedOnAssemblyName());
  1232. //IFW32FALSE_EXIT(::TestPolicyPathGeneration());
  1233. IFCOMFAILED_EXIT(TestAssemblyNameQueryAssemblyInfo());
  1234. break;
  1235. case SXS_DEBUG_GET_STRONGNAME:
  1236. {
  1237. CPublicKeyInformation pkInfo;
  1238. CFusionArray<BYTE> PublicKeyBytes;
  1239. CStringBuffer *pStringBuffers = (CStringBuffer*) pvParameter2;
  1240. PCCERT_CONTEXT pContext = (PCCERT_CONTEXT) pszParameter1;
  1241. PARAMETER_CHECK(pszParameter1 != NULL);
  1242. PARAMETER_CHECK(pvParameter2 != NULL);
  1243. IFW32FALSE_EXIT(pkInfo.Initialize(pContext));
  1244. IFW32FALSE_EXIT(pkInfo.GetSignerNiceName(pStringBuffers[0]));
  1245. IFW32FALSE_EXIT(pkInfo.GetStrongNameString(pStringBuffers[1]));
  1246. IFW32FALSE_EXIT(pkInfo.GetWrappedPublicKeyBytes(PublicKeyBytes));
  1247. IFW32FALSE_EXIT(::SxspHashBytesToString(PublicKeyBytes.GetArrayPtr(), PublicKeyBytes.GetSize(), pStringBuffers[2]));
  1248. break;
  1249. }
  1250. case SXS_DEBUG_FUSION_REPARSEPOINT:
  1251. PARAMETER_CHECK(pszParameter1 != NULL);
  1252. PARAMETER_CHECK(pvParameter2 != NULL);
  1253. IFW32FALSE_EXIT(::TestReparsePointOnFullQualifiedPath(pszParameter1, (PCWSTR)pvParameter2));
  1254. break;
  1255. case SXS_DEBUG_FOLDERNAME_FROM_ASSEMBLYIDENTITY_GENERATION:
  1256. {
  1257. WCHAR pstr[1024];
  1258. ULONG cch = NUMBER_OF(pstr);
  1259. PARAMETER_CHECK(pszParameter1 != NULL);
  1260. IFW32FALSE_EXIT(SxspGenerateManifestPathOnAssemblyIdentity(pszParameter1, pstr, &cch, NULL));
  1261. }
  1262. break;
  1263. case SXS_DEBUG_FUSION_ARRAY:
  1264. PARAMETER_CHECK(pszParameter1 != NULL);
  1265. PARAMETER_CHECK(pvParameter2 != NULL);
  1266. IFW32FALSE_EXIT(SxspDebugTestFusionArray(pszParameter1, reinterpret_cast<PCWSTR>(pvParameter2)));
  1267. break;
  1268. case SXS_DEBUG_FORCE_LEAK:
  1269. {
  1270. //
  1271. // Leaking memory intentionally - do not fix!
  1272. // - if pvParameter2 is NULL, then leaks one byte
  1273. // - Otherwise, assumes pvParameter2 is a PDWORD that is now many bytes
  1274. // should be leaked.
  1275. //
  1276. // Uses new[] to interact with the heap; might want to use the flags to
  1277. // indicate use of the Fusion heap or whatnot.
  1278. //
  1279. DWORD dwLeakCount = pvParameter2 ? *((PDWORD)pvParameter2) : 1;
  1280. PCHAR pLeaked = NEW(CHAR[ dwLeakCount ]);
  1281. if (pLeaked)
  1282. {
  1283. ::FusionpDbgPrintEx(
  1284. FUSION_DBG_LEVEL_INFO,
  1285. "SxsDebug::ForceLeak allocates %d bytes\n",
  1286. dwLeakCount);
  1287. fSuccess = TRUE;
  1288. }
  1289. else
  1290. {
  1291. ::FusionpDbgPrintEx(
  1292. FUSION_DBG_LEVEL_INFO,
  1293. "SxsDebug::ForceLeak didn't allocate anything, new failed\n");
  1294. }
  1295. break;
  1296. }
  1297. case SXS_DEBUG_EXPAND_CAB_FILE:
  1298. IFW32FALSE_EXIT(TestExpandCabinetFileToTemp(pszParameter1, static_cast<PCWSTR>(pvParameter2)));
  1299. break;
  1300. case SXS_DEBUG_SFC_SCANNER:
  1301. IFW32FALSE_EXIT(SxsProtectionPerformScanNow(NULL, TRUE, TRUE));
  1302. break;
  1303. case SXS_DEBUG_DLL_REDIRECTION:
  1304. PARAMETER_CHECK(pszParameter1 != NULL);
  1305. IFW32FALSE_EXIT(::DllRedirectionTest(pszParameter1));
  1306. break;
  1307. case SXS_DEBUG_DIRECTORY_WATCHER:
  1308. IFCOMFAILED_EXIT(TryWatchingDirectories());
  1309. break;
  1310. case SXS_DEBUG_CREAT_MULTILEVEL_DIRECTORY:
  1311. PARAMETER_CHECK(pszParameter1 != NULL);
  1312. IFW32FALSE_EXIT(CreateMultiLevelDirectoryTest(pszParameter1));
  1313. break;
  1314. case SXS_DEBUG_PROBE_MANIFST:
  1315. //IFW32FALSE_EXIT(ManifestProbeTest());
  1316. //IFW32FALSE_EXIT(TestSxsGeneratePath());
  1317. IFW32FALSE_EXIT(TestCopyDirectory());
  1318. break;
  1319. case SXS_DEBUG_XML_PARSER:
  1320. PARAMETER_CHECK(pszParameter1 != NULL);
  1321. IFCOMFAILED_EXIT(::XMLParserTest(pszParameter1));
  1322. break;
  1323. case SXS_DEBUG_CHECK_MANIFEST_SCHEMA:
  1324. PARAMETER_CHECK(pszParameter1 != NULL);
  1325. IFW32FALSE_EXIT(::SxspManifestSchemaCheck(pszParameter1));
  1326. break;
  1327. #if SXS_PRECOMPILED_MANIFESTS_ENABLED
  1328. case SXS_DEBUG_PRECOMPILED_MANIFEST:
  1329. PARAMETER_CHECK(pszParameter1 != NULL);
  1330. IFCOMFAILED_EXIT(::PrecompiledManifestTest(pszParameter1));
  1331. break;
  1332. case SXS_DEBUG_TIME_PCM:
  1333. PARAMETER_CHECK(pszParameter1 != NULL);
  1334. IFCOMFAILED_EXIT(::TestPCMTime(const_cast<LPWSTR>(pszParameter1)));
  1335. break;
  1336. #endif // SXS_PRECOMPILED_MANIFESTS_ENABLED
  1337. case SXS_DEBUG_SET_ASSEMBLY_STORE_ROOT:
  1338. {
  1339. PWSTR pszTemp = NULL;
  1340. PCWSTR pszTemp2 = NULL;
  1341. PARAMETER_CHECK(pszParameter1 != NULL);
  1342. // Make a copy of the input string
  1343. IFW32FALSE_EXIT(::FusionDupString(&pszTemp, pszParameter1, ::wcslen(pszParameter1)));
  1344. pszTemp2 = ::SxspInterlockedExchange(&g_AlternateAssemblyStoreRoot, (PCWSTR)pszTemp);
  1345. if (pszTemp2 != NULL)
  1346. FUSION_DELETE_ARRAY(pszTemp2);
  1347. break;
  1348. }
  1349. case SXS_DEBUG_EXIT_PROCESS:
  1350. ExitProcess(123);
  1351. break;
  1352. case SXS_DEBUG_TERMINATE_PROCESS:
  1353. TerminateProcess(GetCurrentProcess(), 456);
  1354. break;
  1355. } // end of switch
  1356. fSuccess = TRUE;
  1357. Exit:
  1358. return fSuccess;
  1359. }// end of SxspDebug