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.

452 lines
13 KiB

  1. //---------------------------------------------------------------------------
  2. // ThemeLdr.cpp - entrypoints for routines declared in ThemeLdr.h
  3. //---------------------------------------------------------------------------
  4. #include "stdafx.h"
  5. #include "Services.h"
  6. #include "ThemeServer.h"
  7. #include "loader.h"
  8. //---------------------------------------------------------------------------
  9. // --------------------------------------------------------------------------
  10. // InjectedThreadDispatcherExceptionFilter
  11. //
  12. // Arguments: pExceptionInfo = Exception that happened.
  13. //
  14. // Returns: LONG
  15. //
  16. // Purpose: Filters exceptions that occur when executing injected threads
  17. // into another process context to prevent the process from
  18. // terminating due to unforeseen exceptions.
  19. //
  20. // History: 2000-10-13 vtan created
  21. // 2001-05-18 vtan copied from theme service LPC
  22. // --------------------------------------------------------------------------
  23. LONG WINAPI InjectedThreadExceptionFilter (struct _EXCEPTION_POINTERS *pExceptionInfo)
  24. {
  25. (LONG)RtlUnhandledExceptionFilter(pExceptionInfo);
  26. return(EXCEPTION_EXECUTE_HANDLER);
  27. }
  28. // --------------------------------------------------------------------------
  29. // ::SessionAllocate
  30. //
  31. // Arguments: hProcess = Winlogon process for the session.
  32. // dwServerChangeNumber = Server base change number.
  33. // pfnRegister = Address of register function.
  34. // pfnUnregister = Address of unregister function.
  35. //
  36. // Returns: void*
  37. //
  38. // Purpose: Allocates a CThemeServer object that contains information
  39. // for a theme session. Wrapped in try/except because of
  40. // critical section initialization.
  41. //
  42. // History: 2000-11-11 vtan created
  43. // --------------------------------------------------------------------------
  44. EXTERN_C void* WINAPI SessionAllocate (HANDLE hProcess, DWORD dwServerChangeNumber, void *pfnRegister, void *pfnUnregister, void *pfnClearStockObjects, DWORD dwStackSizeReserve, DWORD dwStackSizeCommit)
  45. {
  46. CThemeServer *pvContext;
  47. __try
  48. {
  49. pvContext = new CThemeServer(hProcess, dwServerChangeNumber, pfnRegister, pfnUnregister, pfnClearStockObjects, dwStackSizeReserve, dwStackSizeCommit);
  50. }
  51. __except (EXCEPTION_EXECUTE_HANDLER)
  52. {
  53. pvContext = NULL;
  54. }
  55. return(pvContext);
  56. }
  57. // --------------------------------------------------------------------------
  58. // ::SessionFree
  59. //
  60. // Arguments: pvContext = CThemeServer this object.
  61. //
  62. // Returns: <none>
  63. //
  64. // Purpose: Destroys the CThemeServer object when the session goes away.
  65. //
  66. // History: 2000-11-11 vtan created
  67. // --------------------------------------------------------------------------
  68. EXTERN_C void WINAPI SessionFree (void *pvContext)
  69. {
  70. delete static_cast<CThemeServer*>(pvContext);
  71. }
  72. // --------------------------------------------------------------------------
  73. // ::ThemeHooksOn
  74. //
  75. // Arguments: pvContext = CThemeServer this object.
  76. //
  77. // Returns: HRESULT
  78. //
  79. // Purpose: Pass thru function.
  80. //
  81. // History: 2000-11-11 vtan created
  82. // --------------------------------------------------------------------------
  83. EXTERN_C HRESULT WINAPI ThemeHooksOn (void *pvContext)
  84. {
  85. return(static_cast<CThemeServer*>(pvContext)->ThemeHooksOn());
  86. }
  87. // --------------------------------------------------------------------------
  88. // ::ThemeHooksOff
  89. //
  90. // Arguments: pvContext = CThemeServer this object.
  91. //
  92. // Returns: HRESULT
  93. //
  94. // Purpose: Pass thru function.
  95. //
  96. // History: 2000-11-11 vtan created
  97. // --------------------------------------------------------------------------
  98. EXTERN_C HRESULT WINAPI ThemeHooksOff (void *pvContext)
  99. {
  100. (HRESULT)static_cast<CThemeServer*>(pvContext)->ThemeHooksOff();
  101. return(S_OK);
  102. }
  103. // --------------------------------------------------------------------------
  104. // ::AreThemeHooksActive
  105. //
  106. // Arguments: pvContext = CThemeServer this object.
  107. //
  108. // Returns: BOOL
  109. //
  110. // Purpose: Pass thru function.
  111. //
  112. // History: 2000-11-11 vtan created
  113. // --------------------------------------------------------------------------
  114. EXTERN_C BOOL WINAPI AreThemeHooksActive (void *pvContext)
  115. {
  116. return(static_cast<CThemeServer*>(pvContext)->AreThemeHooksActive());
  117. }
  118. // --------------------------------------------------------------------------
  119. // ::GetCurrentChangeNumber
  120. //
  121. // Arguments: pvContext = CThemeServer this object.
  122. //
  123. // Returns: int
  124. //
  125. // Purpose: Pass thru function.
  126. //
  127. // History: 2000-11-11 vtan created
  128. // --------------------------------------------------------------------------
  129. EXTERN_C int WINAPI GetCurrentChangeNumber (void *pvContext)
  130. {
  131. return(static_cast<CThemeServer*>(pvContext)->GetCurrentChangeNumber());
  132. }
  133. // --------------------------------------------------------------------------
  134. // ::GetNewChangeNumber
  135. //
  136. // Arguments: pvContext = CThemeServer this object.
  137. //
  138. // Returns: int
  139. //
  140. // Purpose: Pass thru function.
  141. //
  142. // History: 2000-11-11 vtan created
  143. // --------------------------------------------------------------------------
  144. EXTERN_C int WINAPI GetNewChangeNumber (void *pvContext)
  145. {
  146. return(static_cast<CThemeServer*>(pvContext)->GetNewChangeNumber());
  147. }
  148. // --------------------------------------------------------------------------
  149. // ::SetGlobalTheme
  150. //
  151. // Arguments: pvContext = CThemeServer this object.
  152. //
  153. // Returns: HRESULT
  154. //
  155. // Purpose: Pass thru function.
  156. //
  157. // History: 2000-11-11 vtan created
  158. // --------------------------------------------------------------------------
  159. EXTERN_C HRESULT WINAPI SetGlobalTheme (void *pvContext, HANDLE hSection)
  160. {
  161. return(static_cast<CThemeServer*>(pvContext)->SetGlobalTheme(hSection));
  162. }
  163. // --------------------------------------------------------------------------
  164. // ::GetGlobalTheme
  165. //
  166. // Arguments: pvContext = CThemeServer this object.
  167. //
  168. // Returns: HRESULT
  169. //
  170. // Purpose: Pass thru function.
  171. //
  172. // History: 2000-11-11 vtan created
  173. // --------------------------------------------------------------------------
  174. EXTERN_C HRESULT WINAPI GetGlobalTheme (void *pvContext, HANDLE *phSection)
  175. {
  176. return(static_cast<CThemeServer*>(pvContext)->GetGlobalTheme(phSection));
  177. }
  178. // --------------------------------------------------------------------------
  179. // ::LoadTheme
  180. //
  181. // Arguments: pvContext = CThemeServer this object.
  182. //
  183. // Returns: HRESULT
  184. //
  185. // Purpose: Pass thru function.
  186. //
  187. // History: 2000-11-11 vtan created
  188. // --------------------------------------------------------------------------
  189. EXTERN_C HRESULT WINAPI LoadTheme (void *pvContext, HANDLE hSection, HANDLE *phSection, LPCWSTR pszName, LPCWSTR pszColor, LPCWSTR pszSize)
  190. {
  191. return(static_cast<CThemeServer*>(pvContext)->LoadTheme(hSection, phSection, pszName, pszColor, pszSize));
  192. }
  193. // --------------------------------------------------------------------------
  194. // ::InitUserTheme
  195. //
  196. // Arguments: BOOL
  197. //
  198. // Returns: HRESULT
  199. //
  200. // Purpose: Pass thru function.
  201. //
  202. // History: 2000-11-11 vtan created
  203. // --------------------------------------------------------------------------
  204. EXTERN_C HRESULT WINAPI InitUserTheme (BOOL fPolicyCheckOnly)
  205. {
  206. return(CThemeServices::InitUserTheme(fPolicyCheckOnly));
  207. }
  208. // --------------------------------------------------------------------------
  209. // ::InitUserRegistry
  210. //
  211. // Arguments: <none>
  212. //
  213. // Returns: HRESULT
  214. //
  215. // Purpose: Pass thru function.
  216. //
  217. // History: 2000-11-15 vtan created
  218. // --------------------------------------------------------------------------
  219. EXTERN_C HRESULT WINAPI InitUserRegistry (void)
  220. {
  221. return(CThemeServices::InitUserRegistry());
  222. }
  223. // --------------------------------------------------------------------------
  224. // ::ReestablishServerConnection
  225. //
  226. // Arguments: <none>
  227. //
  228. // Returns: <none>
  229. //
  230. // Purpose: Pass thru function.
  231. //
  232. // History: 2000-11-17 vtan created
  233. // --------------------------------------------------------------------------
  234. EXTERN_C HRESULT WINAPI ReestablishServerConnection (void)
  235. {
  236. return(CThemeServices::ReestablishServerConnection());
  237. }
  238. // --------------------------------------------------------------------------
  239. // ::ThemeHooksInstall
  240. //
  241. // Arguments: pvContext = Unused.
  242. //
  243. // Returns: DWORD
  244. //
  245. // Purpose: Pass thru function.
  246. //
  247. // History: 2000-11-11 vtan created
  248. // --------------------------------------------------------------------------
  249. EXTERN_C DWORD WINAPI ThemeHooksInstall (void *pvContext)
  250. {
  251. UNREFERENCED_PARAMETER(pvContext);
  252. DWORD dwResult;
  253. __try
  254. {
  255. dwResult = CThemeServer::ThemeHooksInstall();
  256. }
  257. __except (InjectedThreadExceptionFilter(GetExceptionInformation()))
  258. {
  259. dwResult = 0;
  260. }
  261. ExitThread(dwResult);
  262. }
  263. // --------------------------------------------------------------------------
  264. // ::ThemeHooksRemove
  265. //
  266. // Arguments: pvContext = Unused.
  267. //
  268. // Returns: DWORD
  269. //
  270. // Purpose: Pass thru function.
  271. //
  272. // History: 2000-11-11 vtan created
  273. // --------------------------------------------------------------------------
  274. EXTERN_C DWORD WINAPI ThemeHooksRemove (void *pvContext)
  275. {
  276. UNREFERENCED_PARAMETER(pvContext);
  277. DWORD dwResult;
  278. __try
  279. {
  280. dwResult = CThemeServer::ThemeHooksRemove();
  281. }
  282. __except (InjectedThreadExceptionFilter(GetExceptionInformation()))
  283. {
  284. dwResult = 0;
  285. }
  286. ExitThread(dwResult);
  287. }
  288. // --------------------------------------------------------------------------
  289. // ::ServerClearStockObjects
  290. //
  291. // Arguments: pvContext = ptr to section
  292. //
  293. // Returns: <none>
  294. //
  295. // Purpose: Pass thru function.
  296. //
  297. // History: 2001-05-01 rfernand created
  298. // --------------------------------------------------------------------------
  299. EXTERN_C void WINAPI ServerClearStockObjects (void *pvContext)
  300. {
  301. DWORD dwResult;
  302. __try
  303. {
  304. dwResult = CThemeServer::ClearStockObjects(HANDLE(pvContext));
  305. }
  306. __except (InjectedThreadExceptionFilter(GetExceptionInformation()))
  307. {
  308. dwResult = 0;
  309. }
  310. ExitThread(dwResult);
  311. }
  312. //---------------------------------------------------------------------------
  313. // --------------------------------------------------------------------------
  314. // ::ClearTheme
  315. //
  316. // Arguments: hSection = Theme section to clear.
  317. //
  318. // Returns: HRESULT
  319. //
  320. // Purpose: Clears stock bitmaps in the theme section data and closes it.
  321. //
  322. // History: 2000-11-21 vtan created
  323. // --------------------------------------------------------------------------
  324. HRESULT WINAPI ClearTheme (HANDLE hSection, BOOL fForce)
  325. {
  326. HRESULT hr;
  327. if (hSection != NULL)
  328. {
  329. hr = CThemeServices::ClearStockObjects(hSection, fForce);
  330. }
  331. else
  332. {
  333. hr = S_OK;
  334. }
  335. //---- always close the handle ----
  336. CloseHandle(hSection);
  337. return(hr);
  338. }
  339. // --------------------------------------------------------------------------
  340. // ::MarkSection
  341. //
  342. // Arguments: hSection = Section to change
  343. // dwAdd, dwRemove = Flags to set or clear in the header.
  344. // See loader.h.
  345. //
  346. // Returns: void
  347. //
  348. // Purpose: Update the global section state.
  349. //
  350. // History: 2001-05-08 lmouton created
  351. // --------------------------------------------------------------------------
  352. EXTERN_C void WINAPI MarkSection (HANDLE hSection, DWORD dwAdd, DWORD dwRemove)
  353. {
  354. Log(LOG_TMLOAD, L"MarkSection: Add %d and remove %d on %X", dwAdd, dwRemove, hSection);
  355. void *pV = MapViewOfFile(hSection,
  356. FILE_MAP_WRITE,
  357. 0,
  358. 0,
  359. 0);
  360. if (pV != NULL)
  361. {
  362. THEMEHDR *hdr = reinterpret_cast<THEMEHDR*>(pV);
  363. // Do some validation
  364. if (0 == memcmp(hdr->szSignature, kszBeginCacheFileSignature, kcbBeginSignature)
  365. && hdr->dwVersion == THEMEDATA_VERSION)
  366. {
  367. // Only allow this flag for now
  368. if (dwRemove == SECTION_HASSTOCKOBJECTS)
  369. {
  370. Log(LOG_TMLOAD, L"MarkSection: Previous flags were %d", hdr->dwFlags);
  371. hdr->dwFlags &= ~dwRemove;
  372. }
  373. }
  374. UnmapViewOfFile(pV);
  375. }
  376. #ifdef DEBUG
  377. else
  378. {
  379. Log(LOG_TMLOAD, L"MarkSection: Failed to open write handle for %X", hSection);
  380. }
  381. #endif
  382. }