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.

94 lines
1.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. TimeSlip.cpp
  5. Abstract:
  6. Convert the command line to use short path names for both the app and the first (and only) argument.
  7. Example:
  8. C:\program files\accessories\wordpad.exe c:\program files\some app\some data.txt
  9. C:\Progra~1\access~1\wordpad.exe C:\Progra~1\someap~1\someda~1.txt
  10. Created:
  11. 01/23/2001 robkenny Created
  12. 03/13/2001 robkenny Converted to CString
  13. --*/
  14. #include "precomp.h"
  15. IMPLEMENT_SHIM_BEGIN(TimeSlips)
  16. #include "ShimHookMacro.h"
  17. APIHOOK_ENUM_BEGIN
  18. APIHOOK_ENUM_ENTRY(GetCommandLineA)
  19. APIHOOK_ENUM_END
  20. char * g_lpCommandLine = NULL;
  21. /*++
  22. Convert the application name to the short path to remove any spaces.
  23. --*/
  24. LPSTR
  25. APIHOOK(GetCommandLineA)(
  26. void
  27. )
  28. {
  29. if (g_lpCommandLine == NULL)
  30. {
  31. LPSTR lpszOldCmdLine = ORIGINAL_API(GetCommandLineA)();
  32. AppAndCommandLine appCmdLine(NULL, lpszOldCmdLine);
  33. CString csArg1 = appCmdLine.GetCommandlineNoAppName();
  34. csArg1.GetShortPathNameW();
  35. CString csCL = appCmdLine.GetApplicationName();
  36. csCL.GetShortPathNameW();
  37. csCL += L" ";
  38. csCL += csArg1;
  39. if (csCL.IsEmpty())
  40. {
  41. // We didn't change the CL, use the system value.
  42. g_lpCommandLine = lpszOldCmdLine;
  43. }
  44. else
  45. {
  46. g_lpCommandLine = csCL.ReleaseAnsi();
  47. LOGN(
  48. eDbgLevelError,
  49. "[GetCommandLineA] Changed \"%s\" to \"%s\".",
  50. lpszOldCmdLine, g_lpCommandLine);
  51. }
  52. }
  53. return g_lpCommandLine;
  54. }
  55. /*++
  56. Register hooked functions
  57. --*/
  58. HOOK_BEGIN
  59. APIHOOK_ENTRY(KERNEL32.DLL, GetCommandLineA)
  60. HOOK_END
  61. IMPLEMENT_SHIM_END