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.

273 lines
7.3 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. SevenKingdoms.cpp
  5. Abstract:
  6. The problem is in the installer that ships with some versions: specifically
  7. the double pack: i.e. Seven Kingdoms and another. This installer reads
  8. win.ini and parses it for localization settings.
  9. Notes:
  10. This is an app specific shim.
  11. History:
  12. 07/24/2000 linstev Created
  13. --*/
  14. #include "precomp.h"
  15. #include <stdio.h>
  16. // This module has been given an official blessing to use the str routines.
  17. #include "LegalStr.h"
  18. IMPLEMENT_SHIM_BEGIN(SevenKingdoms)
  19. #include "ShimHookMacro.h"
  20. APIHOOK_ENUM_BEGIN
  21. APIHOOK_ENUM_ENTRY(CreateFileA)
  22. APIHOOK_ENUM_ENTRY(ReadFile)
  23. APIHOOK_ENUM_ENTRY(CloseHandle)
  24. APIHOOK_ENUM_END
  25. CHAR *g_pszINI;
  26. DWORD g_dwINIPos = 0;
  27. DWORD g_dwINISize = 0;
  28. /*++
  29. Spoof the international settings in win.ini.
  30. --*/
  31. HANDLE
  32. APIHOOK(CreateFileA)(
  33. LPSTR lpFileName,
  34. DWORD dwDesiredAccess,
  35. DWORD dwShareMode,
  36. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  37. DWORD dwCreationDisposition,
  38. DWORD dwFlagsAndAttributes,
  39. HANDLE hTemplateFile
  40. )
  41. {
  42. HANDLE hRet;
  43. if (lpFileName && (stristr(lpFileName, "win.ini")))
  44. {
  45. g_dwINIPos = 0;
  46. hRet = (HANDLE)0xBAADF00D;
  47. }
  48. else
  49. {
  50. hRet = ORIGINAL_API(CreateFileA)(
  51. lpFileName,
  52. dwDesiredAccess,
  53. dwShareMode,
  54. lpSecurityAttributes,
  55. dwCreationDisposition,
  56. dwFlagsAndAttributes,
  57. hTemplateFile
  58. );
  59. }
  60. return hRet;
  61. }
  62. /*++
  63. Spoof the international settings in win.ini.
  64. --*/
  65. BOOL
  66. APIHOOK(ReadFile)(
  67. HANDLE hFile,
  68. LPVOID lpBuffer,
  69. DWORD nNumberOfBytesToRead,
  70. LPDWORD lpNumberOfBytesRead,
  71. LPOVERLAPPED lpOverlapped
  72. )
  73. {
  74. BOOL bRet;
  75. if (hFile == (HANDLE)0xBAADF00D)
  76. {
  77. //
  78. // We've detected the bogus file, so pretend we are reading it
  79. //
  80. if (g_dwINIPos + nNumberOfBytesToRead >= g_dwINISize)
  81. {
  82. // At the end of the buffer, so return the number of bytes until the end
  83. nNumberOfBytesToRead = g_dwINISize - g_dwINIPos;
  84. }
  85. MoveMemory(lpBuffer, g_pszINI + g_dwINIPos, nNumberOfBytesToRead);
  86. // Move the initial position - like a file pointer
  87. g_dwINIPos += nNumberOfBytesToRead;
  88. if (lpNumberOfBytesRead)
  89. {
  90. // Store the number of bytes read
  91. *lpNumberOfBytesRead = nNumberOfBytesToRead;
  92. }
  93. bRet = nNumberOfBytesToRead > 0;
  94. }
  95. else
  96. {
  97. bRet = ORIGINAL_API(ReadFile)(
  98. hFile,
  99. lpBuffer,
  100. nNumberOfBytesToRead,
  101. lpNumberOfBytesRead,
  102. lpOverlapped);
  103. }
  104. return bRet;
  105. }
  106. /*++
  107. Handle the close of the dummy win.ini file
  108. --*/
  109. BOOL
  110. APIHOOK(CloseHandle)(HANDLE hObject)
  111. {
  112. BOOL bRet;
  113. if (hObject == (HANDLE)0xBAADF00D)
  114. {
  115. // Pretend we closed a real file handle
  116. g_dwINIPos = 0;
  117. bRet = TRUE;
  118. }
  119. else
  120. {
  121. bRet = ORIGINAL_API(CloseHandle)(hObject);
  122. }
  123. return bRet;
  124. }
  125. /*++
  126. Register hooked functions
  127. --*/
  128. BOOL
  129. NOTIFY_FUNCTION(
  130. DWORD fdwReason
  131. )
  132. {
  133. if (fdwReason == DLL_PROCESS_ATTACH)
  134. {
  135. CHAR szLocale[MAX_PATH];
  136. g_pszINI = (CHAR *) malloc(1024);
  137. if (g_pszINI)
  138. {
  139. //
  140. // Add all the locale settings to a buffer which looks like the [intl]
  141. // group in win.ini on Win9x
  142. //
  143. int j = sprintf(g_pszINI, "[intl]\r\n");
  144. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_ICOUNTRY, szLocale, MAX_PATH))
  145. j += sprintf(g_pszINI + j, "iCountry=%s\r\n", szLocale);
  146. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_ICURRDIGITS, szLocale, MAX_PATH))
  147. j += sprintf(g_pszINI + j, "ICurrDigits=%s\r\n", szLocale);
  148. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_ICURRENCY, szLocale, MAX_PATH))
  149. j += sprintf(g_pszINI + j, "iCurrency=%s\r\n", szLocale);
  150. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IDATE, szLocale, MAX_PATH))
  151. j += sprintf(g_pszINI + j, "iDate=%s\r\n", szLocale);
  152. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IDIGITS, szLocale, MAX_PATH))
  153. j += sprintf(g_pszINI + j, "iDigits=%s\r\n", szLocale);
  154. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_ILZERO, szLocale, MAX_PATH))
  155. j += sprintf(g_pszINI + j, "iLZero=%s\r\n", szLocale);
  156. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, szLocale, MAX_PATH))
  157. j += sprintf(g_pszINI + j, "iMeasure=%s\r\n", szLocale);
  158. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_INEGCURR, szLocale, MAX_PATH))
  159. j += sprintf(g_pszINI + j, "iNegCurr=%s\r\n", szLocale);
  160. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_ITIME, szLocale, MAX_PATH))
  161. j += sprintf(g_pszINI + j, "iTime=%s\r\n", szLocale);
  162. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_ITLZERO, szLocale, MAX_PATH))
  163. j += sprintf(g_pszINI + j, "iTLZero=%s\r\n", szLocale);
  164. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_S1159, szLocale, MAX_PATH))
  165. j += sprintf(g_pszINI + j, "s1159=%s\r\n", szLocale);
  166. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_S2359, szLocale, MAX_PATH))
  167. j += sprintf(g_pszINI + j, "s2359=%s\r\n", szLocale);
  168. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SCOUNTRY, szLocale, MAX_PATH))
  169. j += sprintf(g_pszINI + j, "sCountry=%s\r\n", szLocale);
  170. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SCURRENCY, szLocale, MAX_PATH))
  171. j += sprintf(g_pszINI + j, "sCurrency=%s\r\n", szLocale);
  172. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDATE, szLocale, MAX_PATH))
  173. j += sprintf(g_pszINI + j, "sDate=%s\r\n", szLocale);
  174. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SDECIMAL, szLocale, MAX_PATH))
  175. j += sprintf(g_pszINI + j, "sDecimal=%s\r\n", szLocale);
  176. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SLANGUAGE, szLocale, MAX_PATH))
  177. j += sprintf(g_pszINI + j, "sLanguage=%s\r\n", szLocale);
  178. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SLIST, szLocale, MAX_PATH))
  179. j += sprintf(g_pszINI + j, "sList=%s\r\n", szLocale);
  180. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, szLocale, MAX_PATH))
  181. j += sprintf(g_pszINI + j, "sLongDate=%s\r\n", szLocale);
  182. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_SSHORTDATE, szLocale, MAX_PATH))
  183. j += sprintf(g_pszINI + j, "sShortDate=%s\r\n", szLocale);
  184. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, szLocale, MAX_PATH))
  185. j += sprintf(g_pszINI + j, "sThousand=%s\r\n", szLocale);
  186. if (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_STIME, szLocale, MAX_PATH))
  187. j += sprintf(g_pszINI + j, "sTime=%s\r\n", szLocale);
  188. g_dwINISize = j;
  189. }
  190. }
  191. return TRUE;
  192. }
  193. HOOK_BEGIN
  194. CALL_NOTIFY_FUNCTION
  195. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileA)
  196. APIHOOK_ENTRY(KERNEL32.DLL, ReadFile)
  197. APIHOOK_ENTRY(KERNEL32.DLL, CloseHandle)
  198. HOOK_END
  199. IMPLEMENT_SHIM_END