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.

237 lines
6.3 KiB

  1. // AppSearch
  2. //
  3. // Tool for searching a user's hard drives and locating
  4. // applications that can be patched
  5. //
  6. // Author: t-michkr (9 June 2000)
  7. //
  8. // shiminfo.cpp
  9. // Display information on the shims used by an app.
  10. #include <windows.h>
  11. extern "C"
  12. {
  13. #include <shimdb.h>
  14. }
  15. #include <assert.h>
  16. #include <tchar.h>
  17. #include "main.h"
  18. #include "resource.h"
  19. HSDB g_hSDBx;
  20. struct SShimInfo
  21. {
  22. TCHAR* szName;
  23. TCHAR* szDesc;
  24. SShimInfo() : szName(0), szDesc(0) {}
  25. ~SShimInfo()
  26. {
  27. if(szName)
  28. delete szName;
  29. if(szDesc)
  30. delete szDesc;
  31. szName = szDesc = 0;
  32. }
  33. };
  34. const int c_nMaxShimList = 16;
  35. static int nNumShims = 0;
  36. static SShimInfo* apShimInfo[c_nMaxShimList];
  37. // Shim dialog proc.
  38. BOOL CALLBACK ShimInfoDialogProc(HWND hwnd, UINT uiMsg, WPARAM wParam,
  39. LPARAM lParam);
  40. // Shim dialog message handlers.
  41. BOOL HandleShimInfoInitDialog(HWND hwnd, TCHAR* szAppPath);
  42. void HandleShimInfoCommand(HWND hwnd, UINT uiCtrl, UINT uiNotify);
  43. // ShowShimInfo
  44. // Display dialog box showing which shims are imported by an app.
  45. void ShowShimInfo(HWND hwnd, TCHAR* szAppPath)
  46. {
  47. if((g_hSDBx = SdbInitDatabase(0, NULL)) == NULL)
  48. return;
  49. DialogBoxParam(g_hinst, MAKEINTRESOURCE(IDD_SHIMINFO), hwnd,
  50. ShimInfoDialogProc, reinterpret_cast<LPARAM>(szAppPath));
  51. for(int i = 0; i < nNumShims; i++)
  52. {
  53. if(apShimInfo[i])
  54. delete apShimInfo[i];
  55. }
  56. nNumShims = 0;
  57. SdbReleaseDatabase(g_hSDBx);
  58. }
  59. // Dialog proc for shim info dialog.
  60. BOOL CALLBACK ShimInfoDialogProc(HWND hwnd, UINT uiMsg, WPARAM wParam,
  61. LPARAM lParam)
  62. {
  63. switch(uiMsg)
  64. {
  65. case WM_INITDIALOG:
  66. return HandleShimInfoInitDialog(hwnd, reinterpret_cast<TCHAR*>(lParam));
  67. break;
  68. case WM_COMMAND:
  69. HandleShimInfoCommand(hwnd, LOWORD(wParam), HIWORD(wParam));
  70. break;
  71. default:
  72. return FALSE;
  73. }
  74. return TRUE;
  75. }
  76. // Init dialog, add all shims used by app.
  77. BOOL HandleShimInfoInitDialog(HWND hwnd, TCHAR* szAppPath)
  78. {
  79. DWORD dwNumExes = 0;
  80. assert(szAppPath);
  81. TCHAR szBuffer[c_nMaxStringLength];
  82. GetWindowText(hwnd, szBuffer, c_nMaxStringLength);
  83. lstrcat(szBuffer, TEXT(" - "));
  84. if(_tcsrchr(szAppPath, TEXT('\\')))
  85. lstrcat(szBuffer, _tcsrchr(szAppPath, TEXT('\\'))+1);
  86. else
  87. lstrcat(szBuffer, szAppPath);
  88. SetWindowText(hwnd, szBuffer);
  89. // Find the EXE in the database
  90. SDBQUERYRESULT sdbQuery;
  91. ZeroMemory(&sdbQuery, sizeof(SDBQUERYRESULT));
  92. SdbGetMatchingExe(g_hSDBx, szAppPath, NULL, NULL, SDBGMEF_IGNORE_ENVIRONMENT, &sdbQuery);
  93. for (dwNumExes = 0; dwNumExes < SDB_MAX_EXES; ++dwNumExes) {
  94. if (sdbQuery.atrExes[dwNumExes] == TAGREF_NULL) {
  95. break;
  96. }
  97. }
  98. if (dwNumExes)
  99. {
  100. //
  101. // for now, just get the info for the last exe in the list, which will
  102. // be the one with specific info for this app.
  103. // BUGBUG -- is this the right thing to do? dmunsil
  104. //
  105. TAGREF trExe = sdbQuery.atrExes[dwNumExes - 1];
  106. // Get all shims used by this app.
  107. TAGREF trShimDLL = SdbFindFirstTagRef(g_hSDBx, trExe, TAG_SHIM_REF);
  108. while(trShimDLL)
  109. {
  110. // Get the name of the shim.
  111. TCHAR szBuffer[c_nMaxStringLength];
  112. TAGREF trName = SdbFindFirstTagRef(g_hSDBx, trShimDLL, TAG_NAME);
  113. if(SdbReadStringTagRef(g_hSDBx, trName, szBuffer, c_nMaxStringLength))
  114. {
  115. SShimInfo* pShim = new SShimInfo;
  116. if(!pShim)
  117. return FALSE;
  118. pShim->szName = new TCHAR[lstrlen(szBuffer)+1];
  119. if(!pShim->szName)
  120. {
  121. delete pShim;
  122. return FALSE;
  123. }
  124. lstrcpy(pShim->szName, szBuffer);
  125. // Have to read description from
  126. // actual DLL entry, not the reference.
  127. TAGREF trRealDLL = SdbGetShimFromShimRef(g_hSDBx, trShimDLL);
  128. if(trRealDLL)
  129. {
  130. TAGREF trDesc = SdbFindFirstTagRef(g_hSDBx, trRealDLL, TAG_DESCRIPTION);
  131. if(SdbReadStringTagRef(g_hSDBx, trDesc, szBuffer, c_nMaxStringLength))
  132. {
  133. pShim->szDesc = new TCHAR[lstrlen(szBuffer)+1];
  134. if(!pShim->szDesc)
  135. {
  136. delete pShim;
  137. return FALSE;
  138. }
  139. lstrcpy(pShim->szDesc, szBuffer);
  140. }
  141. }
  142. // Add the shim to the list
  143. HWND hwList = GetDlgItem(hwnd, IDC_SHIMLIST);
  144. if(hwList)
  145. {
  146. int i = SendMessage(hwList, LB_ADDSTRING, 0,
  147. reinterpret_cast<LPARAM>(pShim->szName));
  148. if(i != LB_ERR)
  149. {
  150. SendMessage(hwList, LB_SETITEMDATA, i, nNumShims);
  151. apShimInfo[nNumShims] = pShim;
  152. nNumShims++;
  153. }
  154. else
  155. delete pShim;
  156. }
  157. }
  158. // Move to next shim.
  159. trShimDLL = SdbFindNextTagRef(g_hSDBx, trExe, trShimDLL);
  160. }
  161. }
  162. return TRUE;
  163. }
  164. // Handle command messages
  165. void HandleShimInfoCommand(HWND hwnd, UINT uiCtrl, UINT uiNotify)
  166. {
  167. HWND hwList, hwDesc;
  168. int iItem, iShim;
  169. switch(uiCtrl)
  170. {
  171. case IDOK:
  172. EndDialog(hwnd, 0);
  173. break;
  174. case IDC_SHIMLIST:
  175. switch(uiNotify)
  176. {
  177. case LBN_SELCHANGE:
  178. // On a sel change, show the new shim description.
  179. hwList = GetDlgItem(hwnd, IDC_SHIMLIST);
  180. iItem = SendMessage(hwList, LB_GETCURSEL, 0, 0);
  181. if(iItem == LB_ERR)
  182. break;
  183. iShim = SendMessage(hwList, LB_GETITEMDATA, iItem, 0);
  184. if(iShim == LB_ERR)
  185. break;
  186. hwDesc = GetDlgItem(hwnd, IDC_SHIMDESC);
  187. SetWindowText(hwDesc, apShimInfo[iShim]->szDesc);
  188. break;
  189. }
  190. break;
  191. }
  192. }