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.

90 lines
2.2 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. Suda2000.cpp
  5. Abstract:
  6. Call to GetTempPathA is not getting enough buffer and it is returning some
  7. garbage value, so GetTempFileNameA fails. This hooked API, GetTempPathA
  8. returns a constant string "%temp%". GetTempFileNameA expands the environment
  9. variable ("%temp%") and returns a valid path name.
  10. History:
  11. 06/15/2001 mamathas Created
  12. --*/
  13. #include "precomp.h"
  14. IMPLEMENT_SHIM_BEGIN(Suda2000)
  15. #include "ShimHookMacro.h"
  16. APIHOOK_ENUM_BEGIN
  17. APIHOOK_ENUM_ENTRY(GetTempPathA)
  18. APIHOOK_ENUM_ENTRY(GetTempFileNameA)
  19. APIHOOK_ENUM_END
  20. /*++
  21. This stub function intercepts all calls to GetTempPathA and sets lpBuffer[out]
  22. with a constant string "%temp%" and returns the length.
  23. --*/
  24. DWORD
  25. APIHOOK(GetTempPathA)(
  26. DWORD nBufferLength,
  27. LPSTR lpBuffer
  28. )
  29. {
  30. LOGN(eDbgLevelError,
  31. "GetTempPathA: Returns invalid Temp Path (%S)\n Changed to %tmp%", lpBuffer);
  32. StringCchCopyA(lpBuffer, nBufferLength, "%temp%");
  33. return strlen(lpBuffer);
  34. }
  35. /*++
  36. This stub function intercepts all calls to GetTempFileNameA and sets lpPathName
  37. with valid path and then calls the original API.
  38. --*/
  39. UINT
  40. APIHOOK(GetTempFileNameA)(
  41. LPCTSTR lpPathName, // directory name
  42. LPCTSTR lpPrefixString, // file name prefix
  43. UINT uUnique, // integer for use in creating the temporary file name
  44. LPTSTR lpTempFileName // file name buffer
  45. )
  46. {
  47. CHAR szDestinationString[MAX_PATH];
  48. ZeroMemory(szDestinationString, MAX_PATH);
  49. ExpandEnvironmentStringsA((LPCSTR)lpPathName, (LPSTR)szDestinationString, MAX_PATH);
  50. LOGN(eDbgLevelInfo,
  51. "ExpandEnvironmentStringsA: Returned the value of environment variable, \"%temp%\" = (%S) ", szDestinationString);
  52. return ORIGINAL_API(GetTempFileNameA)((LPCSTR)szDestinationString, (LPCSTR)lpPrefixString,uUnique,(LPSTR)lpTempFileName);
  53. }
  54. /*++
  55. Register hooked functions
  56. --*/
  57. HOOK_BEGIN
  58. APIHOOK_ENTRY(KERNEL32.DLL, GetTempPathA)
  59. APIHOOK_ENTRY(KERNEL32.DLL, GetTempFileNameA)
  60. HOOK_END
  61. IMPLEMENT_SHIM_END