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.

99 lines
2.4 KiB

  1. /*++
  2. Copyright (c) 2002 Microsoft Corporation
  3. Module Name:
  4. ImageCast.cpp
  5. Abstract:
  6. This app tries placing its license DLL 'LicDLL.DLL' in the
  7. %windir%\system32 folder. This was ok on Win2K as there was no duplicate
  8. file in sytem32 but on XP, we have the OS license DLL with the same name.
  9. So, the app cannot place it's dll in the system32 directory as it is
  10. protected.
  11. During registration, the app loads the system registration DLL 'LicDLL.DLL'
  12. and tries to get a proc address that does not obviously exist in the system
  13. DLL and the call fails. So, the app displays all greyed out options.
  14. The solution is to redirect the app's DLL to some other folder and pick it
  15. up from there. This Shim picks up the LicDLL.DLL that was redirected to
  16. %windir% folder.
  17. Notes:
  18. This is an app specific shim.
  19. History:
  20. 01/23/2002 prashkud Created
  21. 02/27/2002 robkenny Security review.
  22. --*/
  23. #include "precomp.h"
  24. IMPLEMENT_SHIM_BEGIN(ImageCast)
  25. #include "ShimHookMacro.h"
  26. APIHOOK_ENUM_BEGIN
  27. APIHOOK_ENUM_ENTRY(LoadLibraryA)
  28. APIHOOK_ENUM_END
  29. /*++
  30. Hooks LoadLibraryA and redirects if the filename is 'LicDLL.DLL' to
  31. %windir%\LicDLL.DLL. The file 'LicDLL.DLL' would be redirected during
  32. the setup to %windir%\system.
  33. --*/
  34. HMODULE
  35. APIHOOK(LoadLibraryA)(
  36. LPCSTR lpFileName
  37. )
  38. {
  39. CSTRING_TRY
  40. {
  41. // Bad string pointers can cause failures in CString.
  42. if (!IsBadStringPtrA(lpFileName, MAX_PATH))
  43. {
  44. //
  45. // We have found 'LicDLL.dll' in the path. Replace with "%windir%\LicDLL.DLL"
  46. //
  47. CString csFileName(lpFileName);
  48. if (csFileName == L"LicDLL.DLL")
  49. {
  50. CString csNewFileName;
  51. csNewFileName.GetWindowsDirectoryW();
  52. csNewFileName.AppendPath(csFileName);
  53. LOGN(eDbgLevelInfo, "[ImageCast] changed %s to (%s)", lpFileName, csNewFileName.GetAnsi());
  54. return ORIGINAL_API(LoadLibraryA)(csNewFileName.GetAnsi());
  55. }
  56. }
  57. }
  58. CSTRING_CATCH
  59. {
  60. }
  61. return ORIGINAL_API(LoadLibraryA)(lpFileName);
  62. }
  63. /*++
  64. Register hooked functions
  65. --*/
  66. HOOK_BEGIN
  67. APIHOOK_ENTRY(KERNEL32.DLL, LoadLibraryA)
  68. HOOK_END
  69. IMPLEMENT_SHIM_END