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.

255 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. SchoolHouseRockMath.cpp
  5. Abstract:
  6. This shim directs the install to look in the _InstallTo16 and
  7. _InstallFrom16 sections of setup.inf instead of _InstallFrom32 and
  8. _InstallTo32. This is needed because the application tries to use a 16-bit
  9. DLL during gameplay which is allowed in Win9x but produces errors under
  10. Whistler.
  11. History:
  12. 10/18/2000 jdoherty Created
  13. --*/
  14. #include "precomp.h"
  15. // This module has been given an official blessing to use the str routines.
  16. #include "LegalStr.h"
  17. IMPLEMENT_SHIM_BEGIN(SchoolHouseRockMath)
  18. #include "ShimHookMacro.h"
  19. APIHOOK_ENUM_BEGIN
  20. APIHOOK_ENUM_ENTRY(GetPrivateProfileStringA)
  21. APIHOOK_ENUM_ENTRY(GetPrivateProfileStringW)
  22. APIHOOK_ENUM_ENTRY(GetProfileStringA)
  23. APIHOOK_ENUM_ENTRY(GetProfileStringW)
  24. APIHOOK_ENUM_END
  25. /*++
  26. This stub function breaks into GetPrivateProfileString and checks to see the section lpAppName
  27. being referred to is one of the sections in question.
  28. --*/
  29. DWORD
  30. APIHOOK(GetPrivateProfileStringA)(
  31. LPCSTR lpAppName,
  32. LPCSTR lpKeyName,
  33. LPCSTR lpDefault,
  34. LPSTR lpReturnedString,
  35. DWORD nSize,
  36. LPCSTR lpFileName
  37. )
  38. {
  39. DWORD dRet;
  40. int iArraySize = 2;
  41. // The following array specifies what sections to look for and what to
  42. // replace them with when calling GetPrivateProfileString
  43. CHAR *szAppNames[] = {"_INSTALLTO32", "_INSTALLFROM32"};
  44. CHAR *szNewAppNames[] = {"_INSTALLTO16", "_INSTALLFROM16"};
  45. for (int i = 0; i < iArraySize; i++)
  46. {
  47. // Find out if one of the known section names is lpAppName
  48. // if so change lpAppName parameter to new parameter and call API
  49. if ((stristr (szAppNames[i], lpAppName) !=NULL ))
  50. {
  51. return ORIGINAL_API(GetPrivateProfileStringA)(
  52. szNewAppNames[i],
  53. lpKeyName,
  54. lpDefault,
  55. lpReturnedString,
  56. nSize,
  57. lpFileName
  58. );
  59. }
  60. }
  61. return ORIGINAL_API(GetPrivateProfileStringA)(
  62. lpAppName,
  63. lpKeyName,
  64. lpDefault,
  65. lpReturnedString,
  66. nSize,
  67. lpFileName
  68. );
  69. }
  70. /*++
  71. This stub function breaks into GetPrivateProfileString and checks to see the section lpAppName
  72. being referred to is one of the sections in question.
  73. --*/
  74. DWORD
  75. WINAPI
  76. APIHOOK(GetPrivateProfileStringW)(
  77. LPCWSTR lpAppName,
  78. LPCWSTR lpKeyName,
  79. LPCWSTR lpDefault,
  80. LPWSTR lpReturnedString,
  81. DWORD nSize,
  82. LPCWSTR lpFileName
  83. )
  84. {
  85. DWORD dRet;
  86. int iArraySize = 2;
  87. // The following array specifies what sections to look for and what to
  88. // replace them with when calling GetPrivateProfileString
  89. WCHAR *wszAppNames[] = {L"_INSTALLTO32", L"_INSTALLFROM32"};
  90. WCHAR *wszNewAppNames[] = {L"_INSTALLTO16", L"_INSTALLFROM16"};
  91. for (int i = 0; i < iArraySize; i++)
  92. {
  93. // Find out if one of the known section names is lpAppName
  94. // if so change lpAppName parameter to new parameter and call API
  95. if (wcsistr (lpAppName, wszAppNames[i]) != NULL)
  96. {
  97. return ORIGINAL_API(GetPrivateProfileStringW)(
  98. wszNewAppNames[i],
  99. lpKeyName,
  100. lpDefault,
  101. lpReturnedString,
  102. nSize,
  103. lpFileName
  104. );
  105. }
  106. }
  107. return ORIGINAL_API(GetPrivateProfileStringW)(
  108. lpAppName,
  109. lpKeyName,
  110. lpDefault,
  111. lpReturnedString,
  112. nSize,
  113. lpFileName
  114. );
  115. }
  116. /*++
  117. This stub function breaks into GetProfileString and checks to see the section
  118. lpAppName being referred to is one of the sections in question.
  119. --*/
  120. DWORD
  121. APIHOOK(GetProfileStringA)(
  122. LPCSTR lpAppName,
  123. LPCSTR lpKeyName,
  124. LPCSTR lpDefault,
  125. LPSTR lpReturnedString,
  126. DWORD nSize
  127. )
  128. {
  129. DWORD dRet;
  130. int iArraySize = 2;
  131. // The following array specifies what sections to look for and what to
  132. // replace them with when calling GetPrivateProfileString
  133. CHAR *szAppNames[] = {"_INSTALLTO32", "_INSTALLFROM32"};
  134. CHAR *szNewAppNames[] = {"_INSTALLTO16", "_INSTALLFROM16"};
  135. for (int i = 0; i < iArraySize; i++)
  136. {
  137. // Find out if one of the known section names is lpAppName
  138. // if so change lpAppName parameter to new parameter and call API
  139. if (stristr (szAppNames[i], lpAppName) !=NULL )
  140. {
  141. return ORIGINAL_API(GetProfileStringA)(
  142. szNewAppNames[i],
  143. lpKeyName,
  144. lpDefault,
  145. lpReturnedString,
  146. nSize
  147. );
  148. }
  149. }
  150. return ORIGINAL_API(GetProfileStringA)(
  151. lpAppName,
  152. lpKeyName,
  153. lpDefault,
  154. lpReturnedString,
  155. nSize
  156. );
  157. }
  158. /*++
  159. This stub function breaks into GetProfileString and checks to see the section
  160. lpAppName being referred to is one of the sections in question.
  161. --*/
  162. DWORD
  163. APIHOOK(GetProfileStringW)(
  164. LPCWSTR lpAppName,
  165. LPCWSTR lpKeyName,
  166. LPCWSTR lpDefault,
  167. LPWSTR lpReturnedString,
  168. DWORD nSize
  169. )
  170. {
  171. DWORD dRet;
  172. int iArraySize = 2;
  173. // The following array specifies what sections to look for and what to
  174. // replace them with when calling GetPrivateProfileString
  175. WCHAR *wszAppNames[] = {L"_INSTALLTO32", L"_INSTALLFROM32"};
  176. WCHAR *wszNewAppNames[] = {L"_INSTALLTO16", L"_INSTALLFROM16"};
  177. for (int i = 0; i < iArraySize; i++)
  178. {
  179. // Find out if one of the known section names is lpAppName
  180. // if so change lpAppName parameter to new parameter and call API
  181. if (wcsistr (lpAppName, wszAppNames[i]) != NULL)
  182. {
  183. return ORIGINAL_API(GetProfileStringW)(
  184. wszNewAppNames[i],
  185. lpKeyName,
  186. lpDefault,
  187. lpReturnedString,
  188. nSize
  189. );
  190. }
  191. }
  192. return ORIGINAL_API(GetProfileStringW)(
  193. lpAppName,
  194. lpKeyName,
  195. lpDefault,
  196. lpReturnedString,
  197. nSize
  198. );
  199. }
  200. /*++
  201. Register hooked functions
  202. --*/
  203. HOOK_BEGIN
  204. APIHOOK_ENTRY(KERNEL32.DLL, GetPrivateProfileStringA)
  205. APIHOOK_ENTRY(KERNEL32.DLL, GetPrivateProfileStringW)
  206. APIHOOK_ENTRY(KERNEL32.DLL, GetProfileStringA)
  207. APIHOOK_ENTRY(KERNEL32.DLL, GetProfileStringW)
  208. HOOK_END
  209. IMPLEMENT_SHIM_END