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.

182 lines
4.4 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. IMPLEMENT_SHIM_BEGIN(NetObjectsFusion5)
  17. #include "ShimHookMacro.h"
  18. APIHOOK_ENUM_BEGIN
  19. APIHOOK_ENUM_ENTRY(CloseHandle)
  20. APIHOOK_ENUM_ENTRY(WriteFile)
  21. APIHOOK_ENUM_ENTRY(CreateFileA)
  22. APIHOOK_ENUM_END
  23. volatile HANDLE g_Handle = NULL;
  24. HANDLE
  25. APIHOOK(CreateFileA)(
  26. LPSTR lpFileName,
  27. DWORD dwDesiredAccess,
  28. DWORD dwShareMode,
  29. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  30. DWORD dwCreationDisposition,
  31. DWORD dwFlagsAndAttributes,
  32. HANDLE hTemplateFile
  33. )
  34. {
  35. CHAR szNameToCheck[] = "corpwiz_loader.html";
  36. HANDLE l_Handle = (HANDLE)ORIGINAL_API(CreateFileA)(
  37. lpFileName,
  38. dwDesiredAccess,
  39. dwShareMode,
  40. lpSecurityAttributes,
  41. dwCreationDisposition,
  42. dwFlagsAndAttributes,
  43. hTemplateFile);
  44. if ( strstr(lpFileName,szNameToCheck) )
  45. {
  46. if (l_Handle != INVALID_HANDLE_VALUE )
  47. g_Handle = l_Handle;
  48. }
  49. else
  50. g_Handle = NULL;
  51. return l_Handle;
  52. }
  53. BOOL
  54. APIHOOK(WriteFile)(
  55. HANDLE hFile,
  56. LPCVOID lpBuffer,
  57. DWORD nNumberOfBytesToWrite,
  58. LPDWORD lpNumberOfBytesWritten,
  59. LPOVERLAPPED lpOverlapped
  60. )
  61. {
  62. BOOL bRet = FALSE;
  63. if ( g_Handle && (hFile == g_Handle) && lpBuffer)
  64. {
  65. CHAR szStringToWrite[] = "\r\n var IsIE6 = navigator.userAgent.indexOf(\"IE 6\") > -1;\r\n\r\n if ( IsIE6 == true ) { IsIE5 = true; }\r\n";
  66. CHAR szStringToCheck[] = "var IsIE5 = navigator.userAgent.indexOf(\"IE 5\") > -1;";
  67. CHAR *szPtr = NULL;
  68. if ((szPtr = strstr((LPCSTR)lpBuffer,szStringToCheck)))
  69. {
  70. int iSize = sizeof(CHAR) * (szPtr - (LPSTR)lpBuffer + strlen(szStringToCheck));
  71. DWORD dwTotalBytesWritten;
  72. bRet = ORIGINAL_API(WriteFile)(
  73. hFile,
  74. lpBuffer,
  75. (DWORD)iSize,
  76. lpNumberOfBytesWritten,
  77. lpOverlapped);
  78. dwTotalBytesWritten = *lpNumberOfBytesWritten;
  79. bRet = ORIGINAL_API(WriteFile)(
  80. hFile,
  81. (LPVOID)szStringToWrite,
  82. (DWORD)strlen(szStringToWrite),
  83. lpNumberOfBytesWritten,
  84. lpOverlapped);
  85. CHAR* szrBuf = (LPSTR)lpBuffer + iSize;
  86. bRet = ORIGINAL_API(WriteFile)(
  87. hFile,
  88. (LPVOID)szrBuf,
  89. (nNumberOfBytesToWrite - (DWORD)iSize),
  90. lpNumberOfBytesWritten,
  91. lpOverlapped);
  92. *lpNumberOfBytesWritten += dwTotalBytesWritten;
  93. return bRet;
  94. }//end of if
  95. }
  96. return ORIGINAL_API(WriteFile)(
  97. hFile,
  98. lpBuffer,
  99. nNumberOfBytesToWrite,
  100. lpNumberOfBytesWritten,
  101. lpOverlapped);
  102. }
  103. BOOL
  104. APIHOOK(CloseHandle)(
  105. HANDLE hObject
  106. )
  107. {
  108. if ( g_Handle && (hObject == g_Handle) )
  109. {
  110. g_Handle = NULL;
  111. }
  112. return ORIGINAL_API(CloseHandle)(hObject);
  113. }
  114. /*++
  115. Register hooked functions
  116. --*/
  117. HOOK_BEGIN
  118. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileA)
  119. APIHOOK_ENTRY(KERNEL32.DLL, WriteFile)
  120. APIHOOK_ENTRY(KERNEL32.DLL, CloseHandle)
  121. HOOK_END
  122. IMPLEMENT_SHIM_END