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.

126 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 2000-2002 Microsoft Corporation
  3. Module Name:
  4. Battleship.cpp
  5. Abstract:
  6. This game is divided into 3 programs:
  7. 1. The launcher (bshipl.exe)
  8. 2. Classic (bship.exe)
  9. 3. Ultimate (bs.exe)
  10. The launcher is the only shortcut exposed to the user and runs the other 2.
  11. However, the launcher and Classic both have a ton of problems that aren't
  12. easily fixed with a shim.
  13. Ultimate, is a complete superset of all the features of Classic and doesn't
  14. appear to have any issues.
  15. Therefore, the fix is to redirect the launcher to Ultimate and prevent
  16. Ultimate from spawning the launcher on quit.
  17. Notes:
  18. This is a specific shim.
  19. History:
  20. 08/03/2000 a-vales Created
  21. 03/13/2001 robkenny Converted to CString
  22. 05/05/2001 linstev Rewrote
  23. 03/07/2002 robkenny Security changes
  24. --*/
  25. #include "precomp.h"
  26. IMPLEMENT_SHIM_BEGIN(Battleship)
  27. #include "ShimHookMacro.h"
  28. APIHOOK_ENUM_BEGIN
  29. APIHOOK_ENUM_ENTRY(CreateProcessA)
  30. APIHOOK_ENUM_END
  31. /*++
  32. Don't allow this program to spawn the launcher.
  33. --*/
  34. BOOL
  35. APIHOOK(CreateProcessA)(
  36. LPCSTR lpApplicationName,
  37. LPSTR lpCommandLine,
  38. LPSECURITY_ATTRIBUTES lpProcessAttributes,
  39. LPSECURITY_ATTRIBUTES lpThreadAttributes,
  40. BOOL bInheritHandles,
  41. DWORD dwCreationFlags,
  42. LPVOID lpEnvironment,
  43. LPCSTR lpCurrentDirectory,
  44. LPSTARTUPINFOA lpStartupInfo,
  45. LPPROCESS_INFORMATION lpProcessInformation
  46. )
  47. {
  48. if (lpCommandLine && (stristr(lpCommandLine, "bshipl.exe") != 0)) {
  49. //
  50. // This is the launcher, so do nothing
  51. //
  52. return TRUE;
  53. }
  54. return ORIGINAL_API(CreateProcessA)(
  55. lpApplicationName,
  56. lpCommandLine,
  57. lpProcessAttributes,
  58. lpThreadAttributes,
  59. bInheritHandles,
  60. dwCreationFlags,
  61. lpEnvironment,
  62. lpCurrentDirectory,
  63. lpStartupInfo,
  64. lpProcessInformation);
  65. }
  66. /*++
  67. Register hooked functions
  68. --*/
  69. BOOL
  70. NOTIFY_FUNCTION(
  71. DWORD fdwReason
  72. )
  73. {
  74. if (fdwReason == DLL_PROCESS_ATTACH) {
  75. //
  76. // Set the current working directory for the launcher so
  77. // the redirectexe shim works with a relative path
  78. //
  79. WCHAR szName[MAX_PATH];
  80. if (GetModuleFileNameW(0, szName, MAX_PATH)) {
  81. WCHAR *p = wcsistr(szName, L"\\bshipl.exe");
  82. if (p) {
  83. *p = L'\0';
  84. SetCurrentDirectoryW(szName);
  85. }
  86. }
  87. }
  88. return TRUE;
  89. }
  90. HOOK_BEGIN
  91. CALL_NOTIFY_FUNCTION
  92. APIHOOK_ENTRY(KERNEL32.DLL, CreateProcessA)
  93. HOOK_END
  94. IMPLEMENT_SHIM_END