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.

160 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1989-2000 Microsoft Corporation
  3. Module Name:
  4. match.c
  5. Abstract:
  6. This module implements ...
  7. Author:
  8. vadimb created sometime in 2000
  9. Revision History:
  10. clupu cleanup 12/27/2000
  11. --*/
  12. #include "apphelp.h"
  13. // global Hinst
  14. HINSTANCE ghInstance;
  15. CRITICAL_SECTION g_csDynShimInfo;
  16. BOOL
  17. DllMain(
  18. HANDLE hModule,
  19. DWORD ul_reason,
  20. LPVOID lpReserved
  21. )
  22. /*++
  23. Return: TRUE on success, FALSE otherwise.
  24. Desc: apphelp.dll entry point.
  25. --*/
  26. {
  27. switch (ul_reason) {
  28. case DLL_PROCESS_ATTACH:
  29. ghInstance = hModule;
  30. if (!NT_SUCCESS(RtlInitializeCriticalSectionAndSpinCount(&g_csDynShimInfo, 0x80000000))) {
  31. return FALSE;
  32. }
  33. break;
  34. case DLL_THREAD_ATTACH:
  35. break;
  36. case DLL_THREAD_DETACH:
  37. break;
  38. case DLL_PROCESS_DETACH:
  39. break;
  40. }
  41. return TRUE;
  42. }
  43. BOOL
  44. GetExeSxsData(
  45. IN HSDB hSDB, // handle to the database channel
  46. IN TAGREF trExe, // tagref of an exe entry
  47. OUT PVOID* ppSxsData, // pointer to the SXS data
  48. OUT DWORD* pcbSxsData // pointer to the SXS data size
  49. )
  50. /*++
  51. Return: TRUE on success, FALSE otherwise.
  52. Desc: Gets SXS (Fusion) data for the specified EXE from the database.
  53. --*/
  54. {
  55. TAGID tiExe;
  56. TAGID tiSxsManifest;
  57. PDB pdb;
  58. WCHAR* pszManifest;
  59. DWORD dwManifestLength = 0; // in chars
  60. PVOID pSxsData = NULL;
  61. BOOL bReturn = FALSE;
  62. if (trExe == TAGREF_NULL) {
  63. goto exit;
  64. }
  65. if (!SdbTagRefToTagID(hSDB, trExe, &pdb, &tiExe)) {
  66. DBGPRINT((sdlError,
  67. "GetExeSxsData",
  68. "Failed to get the database the TAGREF 0x%x belongs to.\n",
  69. trExe));
  70. goto exit;
  71. }
  72. tiSxsManifest = SdbFindFirstTag(pdb, tiExe, TAG_SXS_MANIFEST);
  73. if (!tiSxsManifest) {
  74. DBGPRINT((sdlInfo,
  75. "GetExeSxsData",
  76. "No SXS data for TAGREF 0x%x.\n",
  77. trExe));
  78. goto exit;
  79. }
  80. pszManifest = SdbGetStringTagPtr(pdb, tiSxsManifest);
  81. if (pszManifest == NULL) {
  82. DBGPRINT((sdlError,
  83. "GetExeSxsData",
  84. "Failed to get manifest string tagid 0x%lx\n",
  85. tiSxsManifest));
  86. goto exit;
  87. }
  88. dwManifestLength = wcslen(pszManifest);
  89. //
  90. // check if this is just a query for existance of the data tag
  91. //
  92. if (ppSxsData == NULL) {
  93. bReturn = TRUE;
  94. goto exit;
  95. }
  96. //
  97. // Allocate the string and return it. NOTE: SXS.DLL cannot handle
  98. // a NULL terminator at the end of the string. We must provide the
  99. // string without the NULL terminator.
  100. //
  101. pSxsData = (PVOID)RtlAllocateHeap(RtlProcessHeap(),
  102. HEAP_ZERO_MEMORY,
  103. dwManifestLength * sizeof(WCHAR));
  104. if (pSxsData == NULL) {
  105. DBGPRINT((sdlError,
  106. "GetExeSxsData",
  107. "Failed to allocate %d bytes\n",
  108. dwManifestLength * sizeof(WCHAR)));
  109. goto exit;
  110. }
  111. RtlMoveMemory(pSxsData, pszManifest, dwManifestLength * sizeof(WCHAR));
  112. bReturn = TRUE;
  113. exit:
  114. if (ppSxsData != NULL) {
  115. *ppSxsData = pSxsData;
  116. }
  117. if (pcbSxsData != NULL) {
  118. *pcbSxsData = dwManifestLength * sizeof(WCHAR);
  119. }
  120. return bReturn;
  121. }