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.

134 lines
3.4 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. PanzerCommander.cpp
  5. Abstract:
  6. Panzer Commander launches its readme.txt file with Notepad.exe.
  7. Unfortunately, on the readme file is > 64K so Win9x Notepad will open the
  8. file with write.exe. On Win2000, notepad will open the file just fine,
  9. however the problem is that readme.txt should actually be readme.doc.
  10. We change %windir%\notepad.exe with %windir%\write.exe
  11. Notes:
  12. This is an app specific shim.
  13. History:
  14. 12/12/2000 robkenny Created
  15. 03/13/2001 robkenny Converted to CString
  16. --*/
  17. #include "precomp.h"
  18. IMPLEMENT_SHIM_BEGIN(PanzerCommander)
  19. #include "ShimHookMacro.h"
  20. APIHOOK_ENUM_BEGIN
  21. APIHOOK_ENUM_ENTRY(CreateProcessA)
  22. APIHOOK_ENUM_END
  23. /*++
  24. They use notepad to open a text file that is really a DOC file. Convert
  25. notepad.exe to write.exe
  26. --*/
  27. BOOL
  28. APIHOOK(CreateProcessA)(
  29. LPCSTR lpApplicationName,
  30. LPSTR lpCommandLine,
  31. LPSECURITY_ATTRIBUTES lpProcessAttributes,
  32. LPSECURITY_ATTRIBUTES lpThreadAttributes,
  33. BOOL bInheritHandles,
  34. DWORD dwCreationFlags,
  35. LPVOID lpEnvironment,
  36. LPCSTR lpCurrentDirectory,
  37. LPSTARTUPINFOA lpStartupInfo,
  38. LPPROCESS_INFORMATION lpProcessInformation
  39. )
  40. {
  41. CSTRING_TRY
  42. {
  43. AppAndCommandLine acl(lpApplicationName, lpCommandLine);
  44. CString csAppName(acl.GetApplicationName());
  45. CString csCL(acl.GetCommandlineNoAppName());
  46. BOOL bChangedApp = FALSE;
  47. // If the application is notepad, change it to write
  48. if (!csAppName.CompareNoCase(L"notepad.exe") == 0)
  49. {
  50. csAppName = L"%windir%\\system32\\write.exe";
  51. csAppName.ExpandEnvironmentStringsW();
  52. bChangedApp = TRUE;
  53. }
  54. char * lpcl = csCL.GetAnsi();
  55. UINT uiReturn = ORIGINAL_API(CreateProcessA)(
  56. csAppName.GetAnsiNIE(),
  57. lpcl,
  58. lpProcessAttributes,
  59. lpThreadAttributes,
  60. bInheritHandles,
  61. dwCreationFlags,
  62. lpEnvironment,
  63. lpCurrentDirectory,
  64. lpStartupInfo,
  65. lpProcessInformation);
  66. if (bChangedApp)
  67. {
  68. DPFN(
  69. eDbgLevelInfo,
  70. "PanzerCommander, corrected command line:\n(%s)\n(%s)\n",
  71. lpCommandLine, lpcl);
  72. }
  73. return uiReturn;
  74. }
  75. CSTRING_CATCH
  76. {
  77. // Do nothing
  78. }
  79. UINT uiReturn = ORIGINAL_API(CreateProcessA)(
  80. lpApplicationName,
  81. lpCommandLine,
  82. lpProcessAttributes,
  83. lpThreadAttributes,
  84. bInheritHandles,
  85. dwCreationFlags,
  86. lpEnvironment,
  87. lpCurrentDirectory,
  88. lpStartupInfo,
  89. lpProcessInformation);
  90. return uiReturn;
  91. }
  92. /*++
  93. Register hooked functions
  94. --*/
  95. HOOK_BEGIN
  96. APIHOOK_ENTRY(KERNEL32.DLL, CreateProcessA)
  97. HOOK_END
  98. IMPLEMENT_SHIM_END