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.

160 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. InstallShield6.cpp
  5. Abstract:
  6. - InstallShield6 is using IKernel.exe. The problem is IKernel.exe is an out-of-process
  7. OLE server that is spawned by svchost. IKernel.exe is located in InstallShield common
  8. folder and it's known as InstallShield engine.
  9. - In order to enable us to do matching against app that is using IKernel, we catch
  10. first call to CreateFileA that has "data1.hdr" filename on the path.
  11. We should be able to use matching info available in the path of this data1.hdr.
  12. (which is located in temp folder in current user setting).
  13. Then we call apphelp!ApphelpCheckExe to verify whether there is a match.
  14. If there is a match, it will call shimeng!SE_DynamicShim to dynamically load additional shim
  15. available for this application.
  16. History:
  17. 04/11/2001 andyseti Created
  18. 06/27/2001 andyseti Added code to prevent multiple Dynamic Shimming
  19. --*/
  20. #include "precomp.h"
  21. typedef BOOL (WINAPI *_pfn_CheckExe)(LPCWSTR, BOOL, BOOL, BOOL);
  22. IMPLEMENT_SHIM_BEGIN(InstallShield6)
  23. #include "ShimHookMacro.h"
  24. APIHOOK_ENUM_BEGIN
  25. APIHOOK_ENUM_ENTRY(CreateFileA)
  26. APIHOOK_ENUM_END
  27. HANDLE
  28. APIHOOK(CreateFileA)(
  29. LPSTR lpFileName,
  30. DWORD dwDesiredAccess,
  31. DWORD dwShareMode,
  32. LPSECURITY_ATTRIBUTES lpSecurityAttributes,
  33. DWORD dwCreationDisposition,
  34. DWORD dwFlagsAndAttributes,
  35. HANDLE hTemplateFile
  36. )
  37. {
  38. static _pfn_CheckExe pfnCheckExe = NULL;
  39. static const char Apphelp_ModuleName[] = "Apphelp.dll";
  40. static const char CheckExeProcedureName[] = "ApphelpCheckExe";
  41. HMODULE hmodApphelp = 0;
  42. if (pfnCheckExe != NULL)
  43. {
  44. goto Done;
  45. }
  46. CSTRING_TRY
  47. {
  48. CString csFileName(lpFileName);
  49. csFileName.MakeLower();
  50. if (-1 == csFileName.Find(L"data1.hdr"))
  51. {
  52. // not the one that we are looking for.
  53. goto Done;
  54. }
  55. DPFN(
  56. eDbgLevelInfo,
  57. "[CreateFileA] Accessing %S", csFileName.Get());
  58. // load apphelp & shimengine modules
  59. DPFN(
  60. eDbgLevelInfo,
  61. "[CreateFileA] Loading Apphelp");
  62. hmodApphelp = LoadLibraryA(Apphelp_ModuleName);
  63. if (0 == hmodApphelp)
  64. {
  65. DPFN(
  66. eDbgLevelError,
  67. "[CreateFileA] Failed to get apphelp module handle");
  68. goto Done;
  69. }
  70. // Get procedure addresses
  71. DPFN(
  72. eDbgLevelInfo,
  73. "[CreateFileA] Getting ApphelpCheckExe proc address");
  74. pfnCheckExe = (_pfn_CheckExe) GetProcAddress(hmodApphelp, CheckExeProcedureName);
  75. if (NULL == pfnCheckExe)
  76. {
  77. DPFN(
  78. eDbgLevelError,
  79. "[CreateFileA] Failed to get %s procedure from %s module",
  80. CheckExeProcedureName,Apphelp_ModuleName);
  81. goto Done;
  82. }
  83. DPFN(
  84. eDbgLevelInfo,
  85. "[CreateFileA] Calling CheckExe");
  86. if (FALSE == (*pfnCheckExe)(
  87. (WCHAR *)csFileName.Get(),
  88. FALSE,
  89. TRUE,
  90. FALSE
  91. ))
  92. {
  93. DPFN(
  94. eDbgLevelError,
  95. "[CreateFileA] There is no match for %S",
  96. csFileName.Get());
  97. goto Done;
  98. }
  99. }
  100. CSTRING_CATCH
  101. {
  102. // Do nothing
  103. }
  104. Done:
  105. HANDLE hRet = ORIGINAL_API(CreateFileA)(
  106. lpFileName,
  107. dwDesiredAccess,
  108. dwShareMode,
  109. lpSecurityAttributes,
  110. dwCreationDisposition,
  111. dwFlagsAndAttributes,
  112. hTemplateFile);
  113. return hRet;
  114. }
  115. /*++
  116. Register hooked functions
  117. --*/
  118. HOOK_BEGIN
  119. APIHOOK_ENTRY(KERNEL32.DLL, CreateFileA)
  120. HOOK_END
  121. IMPLEMENT_SHIM_END