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.

192 lines
3.9 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. IE5DOMSetup.cpp
  5. Abstract:
  6. This DLL fixes a problem with Internet Explorer's IE5DOM.EXE package. If
  7. the command line contains /n:v, the package will replace the 128-bit
  8. encryption modules that shipped with Win2K, which can cause serious harm -
  9. no one can log on to the machine.
  10. This shim simply removes /n:v from the command line so that the package
  11. does not replace the encryption DLLs.
  12. History:
  13. 02/01/2000 jarbats Created
  14. --*/
  15. #include "precomp.h"
  16. IMPLEMENT_SHIM_BEGIN(IE5DOMSetup)
  17. #include "ShimHookMacro.h"
  18. APIHOOK_ENUM_BEGIN
  19. APIHOOK_ENUM_END
  20. VOID
  21. StartSecondProcess(LPWSTR lpCommandLine)
  22. {
  23. PROCESS_INFORMATION ProcessInfo;
  24. STARTUPINFOW StartupInfo;
  25. LPWSTR FileName;
  26. LPWSTR CurrentDir;
  27. DWORD Size;
  28. Size=GetCurrentDirectoryW(0,NULL);
  29. CurrentDir=(LPWSTR)ShimMalloc(Size*sizeof(WCHAR));
  30. if(NULL == CurrentDir)
  31. {
  32. //it is better to fail now then go on and bomb the system
  33. ExitProcess(0);
  34. }
  35. GetCurrentDirectoryW(Size,CurrentDir);
  36. FileName=(LPWSTR)ShimMalloc((MAX_PATH+2)*sizeof(WCHAR));
  37. if(NULL == FileName)
  38. {
  39. ExitProcess(0);
  40. }
  41. GetModuleFileNameW(NULL, FileName, MAX_PATH+2);
  42. StartupInfo.cb=sizeof(STARTUPINFO);
  43. StartupInfo.lpReserved=NULL;
  44. StartupInfo.lpDesktop=NULL;
  45. StartupInfo.lpTitle=NULL;
  46. StartupInfo.dwFlags=0;
  47. StartupInfo.cbReserved2=0;
  48. StartupInfo.lpReserved2=NULL;
  49. CreateProcessW(
  50. FileName,
  51. lpCommandLine,
  52. NULL,
  53. NULL,
  54. FALSE,
  55. NORMAL_PRIORITY_CLASS,
  56. NULL,
  57. CurrentDir,
  58. &StartupInfo,
  59. &ProcessInfo
  60. );
  61. ExitProcess(0);
  62. }
  63. VOID CheckCommandLine()
  64. {
  65. LPWSTR lpCommandLine,lpNewCommandLine;
  66. LPWSTR *lpArgV;
  67. LPWSTR lpSwitch={L"/n:v"};
  68. BOOL b;
  69. INT nArgC=0;
  70. INT i, cch;
  71. lpCommandLine=GetCommandLineW();
  72. if(NULL == lpCommandLine)
  73. {
  74. //without arguments this exe is harmless
  75. return;
  76. }
  77. cch = lstrlenW(lpCommandLine)+2;
  78. lpNewCommandLine=(LPWSTR)ShimMalloc( cch*sizeof(WCHAR) );
  79. if(NULL == lpNewCommandLine)
  80. {
  81. ExitProcess(0);
  82. }
  83. lpArgV = _CommandLineToArgvW(lpCommandLine,&nArgC);
  84. if(NULL == lpArgV)
  85. {
  86. //better to fail now
  87. ExitProcess(0);
  88. }
  89. else
  90. {
  91. if( nArgC < 2)
  92. {
  93. //there isn't any chance for /n:v
  94. ShimFree(lpNewCommandLine);
  95. GlobalFree(lpArgV);
  96. return;
  97. }
  98. }
  99. b = FALSE;
  100. for ( i=1; i<nArgC; i++ )
  101. {
  102. if(lstrcmpiW(lpArgV[i],lpSwitch))
  103. {
  104. StringCchCatW(lpNewCommandLine, cch, lpArgV[i]);
  105. }
  106. else
  107. {
  108. b = TRUE;
  109. }
  110. }
  111. if (TRUE == b)
  112. {
  113. StartSecondProcess(lpNewCommandLine);
  114. }
  115. //never gets here because startsecondprocess doesn't return
  116. }
  117. /*++
  118. Handle DLL_PROCESS_ATTACH and DLL_PROCESS_DETACH in your notify function
  119. to do initialization and uninitialization.
  120. IMPORTANT: Make sure you ONLY call NTDLL, KERNEL32 and MSVCRT APIs during
  121. DLL_PROCESS_ATTACH notification. No other DLLs are initialized at that
  122. point.
  123. If your shim cannot initialize properly, return FALSE and none of the
  124. APIs specified will be hooked.
  125. --*/
  126. BOOL
  127. NOTIFY_FUNCTION(
  128. DWORD fdwReason)
  129. {
  130. if (fdwReason == DLL_PROCESS_ATTACH)
  131. {
  132. CheckCommandLine();
  133. }
  134. return TRUE;
  135. }
  136. /*++
  137. Register hooked functions
  138. --*/
  139. HOOK_BEGIN
  140. CALL_NOTIFY_FUNCTION
  141. HOOK_END
  142. IMPLEMENT_SHIM_END