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.

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