Source code of Windows XP (NT5)
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.

77 lines
1.4 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. RCenter.cpp
  5. Abstract:
  6. RCenter attempts to compare file extensions from a CD's root against known media
  7. types. When they get the file's extension, they get ".txt" and then add one to the
  8. pointer to leave "txt".
  9. The trouble is that if a file has no extension they end up with a null pointer for
  10. the extension string, add one to it, and then pass it into lstrcmpiA. lstrcmpiA
  11. can handle null pointers, but not "1" pointers.
  12. This shim treats bad pointers as the shortest possible string:
  13. lstrcmpi(BAD_PTR, "Hello World") == LESS_THAN
  14. lstrcmpi("Hello World", BAD_PTR) == GREATER_THAN
  15. lstrcmpi(BAD_PTR, BAD_PTR) == EQUAL
  16. Notes:
  17. This is an app specific shim.
  18. History:
  19. 11/13/2001 astritz Created
  20. --*/
  21. #include "precomp.h"
  22. IMPLEMENT_SHIM_BEGIN(RCenter)
  23. #include "ShimHookMacro.h"
  24. APIHOOK_ENUM_BEGIN
  25. APIHOOK_ENUM_ENTRY(lstrcmpiA)
  26. APIHOOK_ENUM_END
  27. /*++
  28. Hook lstrcmpiA to handle NULL pointers as above.
  29. --*/
  30. BOOL
  31. APIHOOK(lstrcmpiA)(
  32. LPCSTR lpString1,
  33. LPCSTR lpString2
  34. )
  35. {
  36. if (IsBadReadPtr(lpString1, 1)) {
  37. if (IsBadReadPtr(lpString2, 1)) {
  38. return 0;
  39. } else {
  40. return -1;
  41. }
  42. } else if (IsBadReadPtr(lpString2, 1)) {
  43. return 1;
  44. }
  45. return ORIGINAL_API(lstrcmpiA)(lpString1, lpString2);
  46. }
  47. /*++
  48. Register hooked functions
  49. --*/
  50. HOOK_BEGIN
  51. APIHOOK_ENTRY(KERNEL32.DLL, lstrcmpiA)
  52. HOOK_END
  53. IMPLEMENT_SHIM_END