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.

240 lines
5.9 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. IMPLEMENT_SHIM_BEGIN(SevenKingdoms)
  17. #include "ShimHookMacro.h"
  18. APIHOOK_ENUM_BEGIN
  19. APIHOOK_ENUM_ENTRY(CreateFileA)
  20. APIHOOK_ENUM_ENTRY(ReadFile)
  21. APIHOOK_ENUM_ENTRY(CloseHandle)
  22. APIHOOK_ENUM_END
  23. CHAR *g_pszINI;
  24. DWORD g_dwINIPos = 0;
  25. DWORD g_dwINISize = 0;
  26. /*++
  27. Spoof the international settings in win.ini.
  28. --*/
  29. HANDLE
  30. APIHOOK(CreateFileA)(
  31. LPSTR lpFileName,
  32. DWORD dwDesiredAccess,
  33. DWORD dwShareMode,
  34. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  35. DWORD dwCreationDisposition,
  36. DWORD dwFlagsAndAttributes,
  37. HANDLE hTemplateFile
  38. )
  39. {
  40. HANDLE hRet;
  41. if (lpFileName && (stristr(lpFileName, "win.ini")))
  42. {
  43. g_dwINIPos = 0;
  44. hRet = (HANDLE)0xBAADF00D;
  45. }
  46. else
  47. {
  48. hRet = ORIGINAL_API(CreateFileA)(
  49. lpFileName,
  50. dwDesiredAccess,
  51. dwShareMode,
  52. lpSecurityAttributes,
  53. dwCreationDisposition,
  54. dwFlagsAndAttributes,
  55. hTemplateFile
  56. );
  57. }
  58. return hRet;
  59. }
  60. /*++
  61. Spoof the international settings in win.ini.
  62. --*/
  63. BOOL
  64. APIHOOK(ReadFile)(
  65. HANDLE hFile,
  66. LPVOID lpBuffer,
  67. DWORD nNumberOfBytesToRead,
  68. LPDWORD lpNumberOfBytesRead,
  69. LPOVERLAPPED lpOverlapped
  70. )
  71. {
  72. BOOL bRet;
  73. if (hFile == (HANDLE)0xBAADF00D)
  74. {
  75. //
  76. // We've detected the bogus file, so pretend we are reading it
  77. //
  78. if (g_dwINIPos + nNumberOfBytesToRead >= g_dwINISize)
  79. {
  80. // At the end of the buffer, so return the number of bytes until the end
  81. nNumberOfBytesToRead = g_dwINISize - g_dwINIPos;
  82. }
  83. MoveMemory(lpBuffer, g_pszINI + g_dwINIPos, nNumberOfBytesToRead);
  84. // Move the initial position - like a file pointer
  85. g_dwINIPos += nNumberOfBytesToRead;
  86. if (lpNumberOfBytesRead)
  87. {
  88. // Store the number of bytes read
  89. *lpNumberOfBytesRead = nNumberOfBytesToRead;
  90. }
  91. bRet = nNumberOfBytesToRead > 0;
  92. }
  93. else
  94. {
  95. bRet = ORIGINAL_API(ReadFile)(
  96. hFile,
  97. lpBuffer,
  98. nNumberOfBytesToRead,
  99. lpNumberOfBytesRead,
  100. lpOverlapped);
  101. }
  102. return bRet;
  103. }
  104. /*++
  105. Handle the close of the dummy win.ini file
  106. --*/
  107. BOOL
  108. APIHOOK(CloseHandle)(HANDLE hObject)
  109. {
  110. BOOL bRet;
  111. if (hObject == (HANDLE)0xBAADF00D)
  112. {
  113. // Pretend we closed a real file handle
  114. g_dwINIPos = 0;
  115. bRet = TRUE;
  116. }
  117. else
  118. {
  119. bRet = ORIGINAL_API(CloseHandle)(hObject);
  120. }
  121. return bRet;
  122. }
  123. void AddLocaleInfo(CString & csIni, LCTYPE lctype, const char * iniLine)
  124. {
  125. CString csLocale;
  126. if (csLocale.GetLocaleInfoW(LOCALE_USER_DEFAULT, lctype) > 0)
  127. {
  128. CString csEntry;
  129. csEntry.Format(iniLine, csLocale.GetAnsi());
  130. csIni += csEntry;
  131. }
  132. }
  133. /*++
  134. Register hooked functions
  135. --*/
  136. BOOL
  137. NOTIFY_FUNCTION(
  138. DWORD fdwReason
  139. )
  140. {
  141. if (fdwReason == DLL_PROCESS_ATTACH)
  142. {
  143. //
  144. // Add all the locale settings to a buffer which looks like the [intl]
  145. // group in win.ini on Win9x
  146. //
  147. CSTRING_TRY
  148. {
  149. CString csIni(L"[intl]\r\n");
  150. AddLocaleInfo(csIni, LOCALE_ICOUNTRY, "iCountry=%s\r\n");
  151. AddLocaleInfo(csIni, LOCALE_ICURRDIGITS, "ICurrDigits=%s\r\n");
  152. AddLocaleInfo(csIni, LOCALE_ICURRENCY, "iCurrency=%s\r\n");
  153. AddLocaleInfo(csIni, LOCALE_IDATE, "iDate=%s\r\n");
  154. AddLocaleInfo(csIni, LOCALE_IDIGITS, "iDigits=%s\r\n");
  155. AddLocaleInfo(csIni, LOCALE_ILZERO, "iLZero=%s\r\n");
  156. AddLocaleInfo(csIni, LOCALE_IMEASURE, "iMeasure=%s\r\n");
  157. AddLocaleInfo(csIni, LOCALE_INEGCURR, "iNegCurr=%s\r\n");
  158. AddLocaleInfo(csIni, LOCALE_ITIME, "iTime=%s\r\n");
  159. AddLocaleInfo(csIni, LOCALE_ITLZERO, "iTLZero=%s\r\n");
  160. AddLocaleInfo(csIni, LOCALE_S1159, "s1159=%s\r\n");
  161. AddLocaleInfo(csIni, LOCALE_S2359, "s2359=%s\r\n");
  162. AddLocaleInfo(csIni, LOCALE_SCOUNTRY, "sCountry=%s\r\n");
  163. AddLocaleInfo(csIni, LOCALE_SCURRENCY, "sCurrency=%s\r\n");
  164. AddLocaleInfo(csIni, LOCALE_SDATE, "sDate=%s\r\n");
  165. AddLocaleInfo(csIni, LOCALE_SDECIMAL, "sDecimal=%s\r\n");
  166. AddLocaleInfo(csIni, LOCALE_SLANGUAGE, "sLanguage=%s\r\n");
  167. AddLocaleInfo(csIni, LOCALE_SLIST, "sList=%s\r\n");
  168. AddLocaleInfo(csIni, LOCALE_SLONGDATE, "sLongDate=%s\r\n");
  169. AddLocaleInfo(csIni, LOCALE_SSHORTDATE, "sShortDate=%s\r\n");
  170. AddLocaleInfo(csIni, LOCALE_STHOUSAND, "sThousand=%s\r\n");
  171. AddLocaleInfo(csIni, LOCALE_STIME, "sTime=%s\r\n");
  172. g_pszINI = csIni.ReleaseAnsi();
  173. g_dwINISize = strlen(g_pszINI);
  174. }
  175. CSTRING_CATCH
  176. {
  177. // Failed to initialize the locale block, don't bother shimming.
  178. return FALSE;
  179. }
  180. }
  181. return TRUE;
  182. }
  183. HOOK_BEGIN
  184. CALL_NOTIFY_FUNCTION
  185. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileA)
  186. APIHOOK_ENTRY(KERNEL32.DLL, ReadFile)
  187. APIHOOK_ENTRY(KERNEL32.DLL, CloseHandle)
  188. HOOK_END
  189. IMPLEMENT_SHIM_END