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.

185 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. NetObjectsFusion5.cpp
  5. Abstract:
  6. This shim hooks the CreateFile/WriteFile if the file is corpwiz_loader.html
  7. to write in the required javascript so as to make the appwork if the IE browser
  8. version is > 5.
  9. Notes:
  10. This is an app specific shim.
  11. History:
  12. 01/24/2001 a-leelat Created
  13. 03/13/2001 robkenny Converted to CString
  14. --*/
  15. #include "precomp.h"
  16. // This module has been given an official blessing to use the str routines.
  17. #include "LegalStr.h"
  18. IMPLEMENT_SHIM_BEGIN(NetObjectsFusion5)
  19. #include "ShimHookMacro.h"
  20. APIHOOK_ENUM_BEGIN
  21. APIHOOK_ENUM_ENTRY(CloseHandle)
  22. APIHOOK_ENUM_ENTRY(WriteFile)
  23. APIHOOK_ENUM_ENTRY(CreateFileA)
  24. APIHOOK_ENUM_END
  25. volatile HANDLE g_Handle = NULL;
  26. HANDLE
  27. APIHOOK(CreateFileA)(
  28. LPSTR lpFileName,
  29. DWORD dwDesiredAccess,
  30. DWORD dwShareMode,
  31. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  32. DWORD dwCreationDisposition,
  33. DWORD dwFlagsAndAttributes,
  34. HANDLE hTemplateFile
  35. )
  36. {
  37. CHAR szNameToCheck[] = "corpwiz_loader.html";
  38. HANDLE l_Handle = (HANDLE)ORIGINAL_API(CreateFileA)(
  39. lpFileName,
  40. dwDesiredAccess,
  41. dwShareMode,
  42. lpSecurityAttributes,
  43. dwCreationDisposition,
  44. dwFlagsAndAttributes,
  45. hTemplateFile);
  46. if ( strstr(lpFileName,szNameToCheck) )
  47. {
  48. if (l_Handle != INVALID_HANDLE_VALUE )
  49. g_Handle = l_Handle;
  50. }
  51. else
  52. g_Handle = NULL;
  53. return l_Handle;
  54. }
  55. BOOL
  56. APIHOOK(WriteFile)(
  57. HANDLE hFile,
  58. LPCVOID lpBuffer,
  59. DWORD nNumberOfBytesToWrite,
  60. LPDWORD lpNumberOfBytesWritten,
  61. LPOVERLAPPED lpOverlapped
  62. )
  63. {
  64. BOOL bRet = FALSE;
  65. if ( g_Handle && (hFile == g_Handle) && lpBuffer)
  66. {
  67. CHAR szStringToWrite[] = "\r\n var IsIE6 = navigator.userAgent.indexOf(\"IE 6\") > -1;\r\n\r\n if ( IsIE6 == true ) { IsIE5 = true; }\r\n";
  68. CHAR szStringToCheck[] = "var IsIE5 = navigator.userAgent.indexOf(\"IE 5\") > -1;";
  69. CHAR *szPtr = NULL;
  70. if ((szPtr = strstr((LPCSTR)lpBuffer,szStringToCheck)))
  71. {
  72. int iSize = sizeof(CHAR) * (szPtr - (LPSTR)lpBuffer + _tcslenBytes(szStringToCheck));
  73. DWORD dwTotalBytesWritten;
  74. bRet = ORIGINAL_API(WriteFile)(
  75. hFile,
  76. lpBuffer,
  77. (DWORD)iSize,
  78. lpNumberOfBytesWritten,
  79. lpOverlapped);
  80. dwTotalBytesWritten = *lpNumberOfBytesWritten;
  81. bRet = ORIGINAL_API(WriteFile)(
  82. hFile,
  83. (LPVOID)szStringToWrite,
  84. (DWORD)strlen(szStringToWrite),
  85. lpNumberOfBytesWritten,
  86. lpOverlapped);
  87. CHAR* szrBuf = (LPSTR)lpBuffer + iSize;
  88. bRet = ORIGINAL_API(WriteFile)(
  89. hFile,
  90. (LPVOID)szrBuf,
  91. (nNumberOfBytesToWrite - (DWORD)iSize),
  92. lpNumberOfBytesWritten,
  93. lpOverlapped);
  94. *lpNumberOfBytesWritten += dwTotalBytesWritten;
  95. return bRet;
  96. }//end of if
  97. }
  98. return ORIGINAL_API(WriteFile)(
  99. hFile,
  100. lpBuffer,
  101. nNumberOfBytesToWrite,
  102. lpNumberOfBytesWritten,
  103. lpOverlapped);
  104. }
  105. BOOL
  106. APIHOOK(CloseHandle)(
  107. HANDLE hObject
  108. )
  109. {
  110. if ( g_Handle && (hObject == g_Handle) )
  111. {
  112. g_Handle = NULL;
  113. }
  114. return ORIGINAL_API(CloseHandle)(hObject);
  115. }
  116. /*++
  117. Register hooked functions
  118. --*/
  119. HOOK_BEGIN
  120. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileA)
  121. APIHOOK_ENTRY(KERNEL32.DLL, WriteFile)
  122. APIHOOK_ENTRY(KERNEL32.DLL, CloseHandle)
  123. HOOK_END
  124. IMPLEMENT_SHIM_END