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.

118 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. SuperBike.cpp
  5. Abstract:
  6. The application attempts to convert the path to the executable into the directory
  7. containing the executable by replacing the last \ in the path with NULL.
  8. Unfortunately, they start not at the end of the string, but at the max length
  9. of the string. On Win9x the extra memory doesn't (coincidentally) have a \,
  10. so the proper string is passed as the CWD to CreateProcessA. On Whistler,
  11. the extra memory contains a \ so they end up changing nothing.
  12. History:
  13. 10/26/2000 robkenny Created
  14. 03/13/2001 robkenny Converted to CString
  15. --*/
  16. #include "precomp.h"
  17. IMPLEMENT_SHIM_BEGIN(SuperBike)
  18. #include "ShimHookMacro.h"
  19. APIHOOK_ENUM_BEGIN
  20. APIHOOK_ENUM_ENTRY(CreateProcessA)
  21. APIHOOK_ENUM_END
  22. /*++
  23. Make sure lpCurrentDirectory points to a directory, not an executable
  24. --*/
  25. BOOL
  26. APIHOOK(CreateProcessA)(
  27. LPCSTR lpApplicationName,
  28. LPSTR lpCommandLine,
  29. LPSECURITY_ATTRIBUTES lpProcessAttributes,
  30. LPSECURITY_ATTRIBUTES lpThreadAttributes,
  31. BOOL bInheritHandles,
  32. DWORD dwCreationFlags,
  33. LPVOID lpEnvironment,
  34. LPCSTR lpCurrentDirectory,
  35. LPSTARTUPINFOA lpStartupInfo,
  36. LPPROCESS_INFORMATION lpProcessInformation
  37. )
  38. {
  39. CSTRING_TRY
  40. {
  41. CString csDir(lpCurrentDirectory);
  42. char * duplicate = NULL;
  43. if (!csDir.IsEmpty())
  44. {
  45. DWORD dwFileAttr = GetFileAttributesW(csDir);
  46. if (dwFileAttr != -1 && // Doesn't exist
  47. ( ! (FILE_ATTRIBUTE_DIRECTORY & dwFileAttr))) // Is not a directory
  48. {
  49. csDir.StripPath();
  50. }
  51. BOOL bStat = ORIGINAL_API(CreateProcessA)(
  52. lpApplicationName,
  53. lpCommandLine,
  54. lpProcessAttributes,
  55. lpThreadAttributes,
  56. bInheritHandles,
  57. dwCreationFlags,
  58. lpEnvironment,
  59. csDir.GetAnsiNIE(), // our corrected value
  60. lpStartupInfo,
  61. lpProcessInformation);
  62. return bStat;
  63. }
  64. }
  65. CSTRING_CATCH
  66. {
  67. // Do nothing
  68. }
  69. BOOL bStat = ORIGINAL_API(CreateProcessA)(
  70. lpApplicationName,
  71. lpCommandLine,
  72. lpProcessAttributes,
  73. lpThreadAttributes,
  74. bInheritHandles,
  75. dwCreationFlags,
  76. lpEnvironment,
  77. lpCurrentDirectory,
  78. lpStartupInfo,
  79. lpProcessInformation);
  80. return bStat;
  81. }
  82. /*++
  83. Register hooked functions
  84. --*/
  85. HOOK_BEGIN
  86. APIHOOK_ENTRY(KERNEL32.DLL, CreateProcessA)
  87. HOOK_END
  88. IMPLEMENT_SHIM_END