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.

426 lines
8.6 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. FailObsoleteShellAPIs.cpp
  5. Abstract:
  6. Some applications call private shell32 APIs that have been removed since win2k.
  7. To make matters worse, these old ordinals are now used by other shell APIs. To
  8. prevent resulting crashes, we now hand out stubbed out functions that fail when
  9. you call GetProcAddress with these obsolete ordinals.
  10. Notes:
  11. This is a general purpose shim.
  12. History:
  13. 05/31/2001 stevepro Created
  14. --*/
  15. #include "precomp.h"
  16. IMPLEMENT_SHIM_BEGIN(FailObsoleteShellAPIs)
  17. #include "ShimHookMacro.h"
  18. APIHOOK_ENUM_BEGIN
  19. APIHOOK_ENUM_ENTRY(GetProcAddress)
  20. APIHOOK_ENUM_END
  21. HMODULE g_hShell32 = NULL;
  22. /*++
  23. Stubbed out versions of the obsolete APIs. They all return failure codes.
  24. --*/
  25. STDAPI_(BOOL)
  26. FileMenu_HandleNotify(HMENU hmenu, LPCITEMIDLIST * ppidl, LONG lEvent)
  27. {
  28. return FALSE;
  29. }
  30. STDAPI_(UINT)
  31. FileMenu_DeleteAllItems(HMENU hmenu)
  32. {
  33. return 0;
  34. }
  35. STDAPI_(LRESULT)
  36. FileMenu_DrawItem(HWND hwnd, DRAWITEMSTRUCT *pdi)
  37. {
  38. return FALSE;
  39. }
  40. STDAPI_(HMENU)
  41. FileMenu_FindSubMenuByPidl(HMENU hmenu, LPITEMIDLIST pidlFS)
  42. {
  43. return NULL;
  44. }
  45. STDAPI_(BOOL)
  46. FileMenu_GetLastSelectedItemPidls(
  47. IN HMENU hmenu,
  48. OUT LPITEMIDLIST * ppidlFolder, OPTIONAL
  49. OUT LPITEMIDLIST * ppidlItem) OPTIONAL
  50. {
  51. return FALSE;
  52. }
  53. STDAPI_(LRESULT)
  54. FileMenu_HandleMenuChar(HMENU hmenu, TCHAR ch)
  55. {
  56. return E_FAIL;
  57. }
  58. STDAPI_(BOOL)
  59. FileMenu_InitMenuPopup(
  60. IN HMENU hmenu)
  61. {
  62. return FALSE;
  63. }
  64. STDAPI
  65. FileMenu_ComposeA(
  66. IN HMENU hmenu,
  67. IN UINT nMethod,
  68. IN struct FMCOMPOSEA * pfmc)
  69. {
  70. return E_FAIL;
  71. }
  72. STDAPI_(void)
  73. FileMenu_Invalidate(HMENU hmenu)
  74. {
  75. }
  76. STDAPI_(LRESULT)
  77. FileMenu_MeasureItem(HWND hwnd, MEASUREITEMSTRUCT *lpmi)
  78. {
  79. return FALSE;
  80. }
  81. STDAPI
  82. FileMenu_ComposeW(
  83. IN HMENU hmenu,
  84. IN UINT nMethod,
  85. IN struct FMCOMPOSEW * pfmc)
  86. {
  87. return E_FAIL;
  88. }
  89. STDAPI_(HMENU)
  90. FileMenu_Create(COLORREF clr, int cxBmpGap, HBITMAP hbmp, int cySel, DWORD fmf)
  91. {
  92. return NULL;
  93. }
  94. STDAPI_(BOOL)
  95. FileMenu_AppendItem(
  96. HMENU hmenu,
  97. LPTSTR psz,
  98. UINT id,
  99. int iImage,
  100. HMENU hmenuSub,
  101. UINT cyItem)
  102. {
  103. return FALSE;
  104. }
  105. STDAPI_(BOOL)
  106. FileMenu_TrackPopupMenuEx(HMENU hmenu, UINT Flags, int x, int y,
  107. HWND hwndOwner, LPTPMPARAMS lpTpm)
  108. {
  109. return FALSE;
  110. }
  111. STDAPI_(BOOL)
  112. FileMenu_DeleteItemByCmd(HMENU hmenu, UINT id)
  113. {
  114. return FALSE;
  115. }
  116. STDAPI_(void)
  117. FileMenu_Destroy(HMENU hmenu)
  118. {
  119. }
  120. STDAPI_(void)
  121. FileMenu_AbortInitMenu(void)
  122. {
  123. }
  124. STDAPI_(UINT)
  125. FileMenu_AppendFilesForPidl(
  126. HMENU hmenu,
  127. LPITEMIDLIST pidl,
  128. BOOL bInsertSeparator)
  129. {
  130. return 0;
  131. }
  132. STDAPI_(BOOL)
  133. FileMenu_DeleteItemByIndex(HMENU hmenu, UINT iItem)
  134. {
  135. return FALSE;
  136. }
  137. STDAPI_(BOOL)
  138. FileMenu_DeleteMenuItemByFirstID(HMENU hmenu, UINT id)
  139. {
  140. return FALSE;
  141. }
  142. STDAPI_(BOOL)
  143. FileMenu_DeleteSeparator(HMENU hmenu)
  144. {
  145. return FALSE;
  146. }
  147. STDAPI_(BOOL)
  148. FileMenu_EnableItemByCmd(HMENU hmenu, UINT id, BOOL fEnable)
  149. {
  150. return FALSE;
  151. }
  152. STDAPI_(DWORD)
  153. FileMenu_GetItemExtent(HMENU hmenu, UINT iItem)
  154. {
  155. return 0;
  156. }
  157. STDAPI_(BOOL)
  158. FileMenu_ProcessCommand(
  159. IN HWND hwnd,
  160. IN HMENU hmenuBar,
  161. IN UINT idMenu,
  162. IN HMENU hmenu,
  163. IN UINT idCmd)
  164. {
  165. return FALSE;
  166. }
  167. STDAPI_(BOOL)
  168. FileMenu_IsFileMenu(HMENU hmenu)
  169. {
  170. return FALSE;
  171. }
  172. STDAPI_(BOOL)
  173. FileMenu_InsertItem(
  174. IN HMENU hmenu,
  175. IN LPTSTR psz,
  176. IN UINT id,
  177. IN int iImage,
  178. IN HMENU hmenuSub,
  179. IN UINT cyItem,
  180. IN UINT iPos)
  181. {
  182. return FALSE;
  183. }
  184. STDAPI_(BOOL)
  185. FileMenu_InsertSeparator(HMENU hmenu, UINT iPos)
  186. {
  187. return FALSE;
  188. }
  189. STDAPI_(BOOL)
  190. FileMenu_GetPidl(HMENU hmenu, UINT iPos, LPITEMIDLIST *ppidl)
  191. {
  192. return FALSE;
  193. }
  194. STDAPI_(void)
  195. FileMenu_EditMode(BOOL bEdit)
  196. {
  197. }
  198. STDAPI_(BOOL)
  199. FileMenu_HandleMenuSelect(
  200. IN HMENU hmenu,
  201. IN WPARAM wparam,
  202. IN LPARAM lparam)
  203. {
  204. return FALSE;
  205. }
  206. STDAPI_(BOOL)
  207. FileMenu_IsUnexpanded(HMENU hmenu)
  208. {
  209. return FALSE;
  210. }
  211. STDAPI_(void)
  212. FileMenu_DelayedInvalidate(HMENU hmenu)
  213. {
  214. }
  215. STDAPI_(BOOL)
  216. FileMenu_IsDelayedInvalid(HMENU hmenu)
  217. {
  218. return FALSE;
  219. }
  220. STDAPI_(BOOL)
  221. FileMenu_CreateFromMenu(
  222. IN HMENU hmenu,
  223. IN COLORREF clr,
  224. IN int cxBmpGap,
  225. IN HBITMAP hbmp,
  226. IN int cySel,
  227. IN DWORD fmf)
  228. {
  229. return FALSE;
  230. }
  231. /*++
  232. Table associating the obsolete APIs and thier ordinals
  233. --*/
  234. struct ShellStubs
  235. {
  236. PVOID pfnStub;
  237. UINT uiOrd;
  238. };
  239. const ShellStubs g_rgShellStubs[] =
  240. {
  241. { FileMenu_HandleNotify, 101 },
  242. { FileMenu_DeleteAllItems, 104 },
  243. { FileMenu_DrawItem, 105 },
  244. { FileMenu_FindSubMenuByPidl, 106 },
  245. { FileMenu_GetLastSelectedItemPidls, 107 },
  246. { FileMenu_HandleMenuChar, 108 },
  247. { FileMenu_InitMenuPopup, 109 },
  248. { FileMenu_ComposeA, 110 },
  249. { FileMenu_Invalidate, 111 },
  250. { FileMenu_MeasureItem, 112 },
  251. { FileMenu_ComposeW, 113 },
  252. { FileMenu_Create, 114 },
  253. { FileMenu_AppendItem, 115 },
  254. { FileMenu_TrackPopupMenuEx, 116 },
  255. { FileMenu_DeleteItemByCmd, 117 },
  256. { FileMenu_Destroy, 118 },
  257. { FileMenu_AbortInitMenu, 120 },
  258. { FileMenu_AppendFilesForPidl, 124 },
  259. { FileMenu_DeleteItemByIndex, 140 },
  260. { FileMenu_DeleteMenuItemByFirstID, 141 },
  261. { FileMenu_DeleteSeparator, 142 },
  262. { FileMenu_EnableItemByCmd, 143 },
  263. { FileMenu_GetItemExtent, 144 },
  264. { FileMenu_ProcessCommand, 217 },
  265. { FileMenu_IsFileMenu, 216 },
  266. { FileMenu_InsertItem, 218 },
  267. { FileMenu_InsertSeparator, 219 },
  268. { FileMenu_GetPidl, 220 },
  269. { FileMenu_EditMode, 221 },
  270. { FileMenu_HandleMenuSelect, 222 },
  271. { FileMenu_IsUnexpanded, 223 },
  272. { FileMenu_DelayedInvalidate, 224 },
  273. { FileMenu_IsDelayedInvalid, 225 },
  274. { FileMenu_CreateFromMenu, 227 },
  275. /*
  276. May need to add these too. Not needed yet.
  277. { ExtAppListOpenW 228 },
  278. { ExtAppListOpenA 229 },
  279. { ExtAppListClose 230 },
  280. { ExtAppListAddItemsW 231 },
  281. { ExtAppListAddItemsA 232 },
  282. { ExtAppListRemoveItemsW 233 },
  283. { ExtAppListRemoveItemsA 234 },
  284. { ExtAppListItemsFreeStringsW 235 },
  285. { ExtAppListItemsFreeStringsA 236 },
  286. { ExtAppListEnumItemsW 237 },
  287. { ExtAppListEnumItemsA 238 },
  288. { Link_AddExtraDataSection 206 },
  289. { Link_ReadExtraDataSection 207 },
  290. { Link_RemoveExtraDataSection 208 },
  291. { ReceiveAddToRecentDocs 647 },
  292. */
  293. };
  294. /*++
  295. We only want to intercept calls to GetProcAddress and not mess with the
  296. DLL inport tables. This is because the ordinals have been reused
  297. by valid shell APIs and we want LdrGetProcAddress to work normally for these
  298. ordinals. So instead of hooking each of the old APIs using the shim library,
  299. we need to do the work ourselves.
  300. --*/
  301. FARPROC
  302. APIHOOK(GetProcAddress)(
  303. HMODULE hModule,
  304. LPCSTR pszProcName
  305. )
  306. {
  307. // Only intercept shell32 API's referenced by ordinal
  308. if (IS_INTRESOURCE(pszProcName))
  309. {
  310. if (g_hShell32 == NULL)
  311. {
  312. g_hShell32 = GetModuleHandle(L"shell32.dll");
  313. }
  314. if (g_hShell32 && hModule == g_hShell32)
  315. {
  316. UINT uiOrd = (UINT)pszProcName;
  317. // Look for ordinal of obsolete APIs
  318. for (int i=0; i < ARRAYSIZE(g_rgShellStubs); ++i)
  319. {
  320. if (g_rgShellStubs[i].uiOrd == uiOrd)
  321. {
  322. // Found one!
  323. return (FARPROC)g_rgShellStubs[i].pfnStub;
  324. }
  325. }
  326. }
  327. }
  328. // Default to the original API
  329. return ORIGINAL_API(GetProcAddress)(
  330. hModule,
  331. pszProcName);
  332. }
  333. /*++
  334. Register hooked functions
  335. --*/
  336. HOOK_BEGIN
  337. APIHOOK_ENTRY(kernel32.DLL, GetProcAddress)
  338. HOOK_END
  339. IMPLEMENT_SHIM_END