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.

125 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. EmulateGetProfileString.cpp
  5. Abstract:
  6. GetPrivateProfileString no longer stops parsing at a space or tab
  7. character. When users leave what used to be comments on the tail of the
  8. string the comments are now passed to the app resulting in errors.
  9. Notes:
  10. This is a general purpose shim
  11. History:
  12. 12/30/1999 a-chcoff Created
  13. --*/
  14. #include "precomp.h"
  15. IMPLEMENT_SHIM_BEGIN(EmulateGetProfileString)
  16. #include "ShimHookMacro.h"
  17. APIHOOK_ENUM_BEGIN
  18. APIHOOK_ENUM_ENTRY(GetPrivateProfileStringA)
  19. APIHOOK_ENUM_END
  20. /*++
  21. This stub function cleans up when users leave what used to be comments on
  22. the tail of the string the comments were passed to the app resulting in
  23. errors. Now the string is terminated before the comments therefore
  24. alleviating the errors.
  25. --*/
  26. DWORD
  27. APIHOOK(GetPrivateProfileStringA)(
  28. LPCSTR lpAppName,
  29. LPCSTR lpKeyName,
  30. LPCSTR lpDefault,
  31. LPSTR lpReturnedString,
  32. DWORD nSize,
  33. LPCSTR lpFileName
  34. )
  35. {
  36. DWORD dwRet;
  37. char* pTemp1 = (char*)lpReturnedString;
  38. char* pTemp2 = (char*)lpReturnedString;
  39. //
  40. // First just go get the string.
  41. //
  42. dwRet = ORIGINAL_API(GetPrivateProfileStringA)(
  43. lpAppName,
  44. lpKeyName,
  45. lpDefault,
  46. lpReturnedString,
  47. nSize,
  48. lpFileName);
  49. //
  50. // Look for comment.
  51. //
  52. while (*pTemp1 != ';' && *pTemp1) {
  53. pTemp1++;
  54. }
  55. if ((pTemp1 != pTemp2) && *pTemp1) {
  56. LOGN(
  57. eDbgLevelError,
  58. "[GetPrivateProfileStringA] Comment after data in file \"%s\". Eliminated.",
  59. lpFileName);
  60. //
  61. // Did not make it to end of line better trim it
  62. // back up to ';' char
  63. pTemp1--;
  64. //
  65. // Back up past interposing whitespace.
  66. //
  67. while ((*pTemp1==' ') || (*pTemp1=='\t')) {
  68. pTemp1--;
  69. }
  70. pTemp1++;
  71. //
  72. // Set new length.
  73. //
  74. dwRet = (DWORD)((ULONG_PTR)pTemp1 - (ULONG_PTR)pTemp2);
  75. //
  76. // and NULL term string
  77. //
  78. *pTemp1 = '\0';
  79. }
  80. return dwRet;
  81. }
  82. /*++
  83. Register hooked functions
  84. --*/
  85. HOOK_BEGIN
  86. APIHOOK_ENTRY(KERNEL32.DLL, GetPrivateProfileStringA)
  87. HOOK_END
  88. IMPLEMENT_SHIM_END