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.

161 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Gangsters.cpp
  5. Abstract:
  6. This shim hooks FindFirstFileA and FindNextFileA to simulate the
  7. finding of files named "$$$$$$$$.$$$" 8 times in total. Gangsters
  8. apparently changed the FAT on their CD to make it appear to Win9x
  9. as if there were 8 of these files on the CD.
  10. It also hooks mciSendCommand to return 10 as the number of tracks
  11. on the CD instead of 11.
  12. History:
  13. 07/12/2000 t-adams Created
  14. --*/
  15. #include "precomp.h"
  16. #include <mmsystem.h>
  17. // This module has been given an official blessing to use the str routines.
  18. #include "LegalStr.h"
  19. IMPLEMENT_SHIM_BEGIN(Gangsters)
  20. #include "ShimHookMacro.h"
  21. APIHOOK_ENUM_BEGIN
  22. APIHOOK_ENUM_ENTRY(FindFirstFileA)
  23. APIHOOK_ENUM_ENTRY(FindNextFileA)
  24. APIHOOK_ENUM_ENTRY(mciSendCommandA)
  25. APIHOOK_ENUM_END
  26. int g_iTimesFound = 0;
  27. HANDLE g_hIntercept = INVALID_HANDLE_VALUE;
  28. /*++
  29. Abstract:
  30. Pass the FindFirstFile call through, but if it was trying to find a file
  31. named "$$$$$$$$.$$$" then remember the handle to be returned so that we
  32. can intercept subsequent attempts to find more files with the same name.
  33. History:
  34. 07/12/2000 t-adams Created
  35. --*/
  36. HANDLE APIHOOK(FindFirstFileA)(
  37. LPCSTR lpFileName,
  38. LPWIN32_FIND_DATAA lpFindFileData) {
  39. HANDLE hRval;
  40. hRval = ORIGINAL_API(FindFirstFileA)(lpFileName, lpFindFileData);
  41. if( strcmp(&lpFileName[3], "$$$$$$$$.$$$") == 0 ) {
  42. DPFN( eDbgLevelSpew, "FindFirstFileA: Beginning spoof of \"$$$$$$$$.$$$\"");
  43. g_hIntercept = hRval;
  44. g_iTimesFound = 1;
  45. }
  46. return hRval;
  47. }
  48. /*++
  49. Abstract:
  50. If the handle is of the search that we are intercepting, then report
  51. that a match has been found up to eight times. Don't bother changing
  52. lpFindFileData because Gangsters only checks for the existance of the
  53. files, not for any information about them.
  54. Otherwise, just pass the call through.
  55. History:
  56. 07/12/2000 t-adams Created
  57. --*/
  58. BOOL APIHOOK(FindNextFileA)(
  59. HANDLE hFindFile,
  60. LPWIN32_FIND_DATAA lpFindFileData) {
  61. BOOL bRval;
  62. if( hFindFile == g_hIntercept ) {
  63. if( 8 == g_iTimesFound ) {
  64. SetLastError(ERROR_NO_MORE_FILES);
  65. bRval = FALSE;
  66. } else {
  67. g_iTimesFound++;
  68. DPFN( eDbgLevelSpew, "FindNextFileA: Spoofing \"$$$$$$$$.$$$\" occurrence %d", g_iTimesFound);
  69. bRval = TRUE;
  70. }
  71. } else {
  72. bRval = ORIGINAL_API(FindNextFileA)(hFindFile, lpFindFileData);
  73. }
  74. return bRval;
  75. }
  76. /*++
  77. Abstract:
  78. If the app is trying to find the number of tracks on the CD, return 10.
  79. Otherwise, pass through.
  80. History:
  81. 07/13/2000 t-adams Created
  82. --*/
  83. MCIERROR APIHOOK(mciSendCommandA)(
  84. MCIDEVICEID IDDevice,
  85. UINT uMsg,
  86. DWORD fdwCommand,
  87. DWORD dwParam) {
  88. MCIERROR rval;
  89. rval = ORIGINAL_API(mciSendCommandA)(IDDevice, uMsg, fdwCommand, dwParam);
  90. if( uMsg==MCI_STATUS && fdwCommand==MCI_STATUS_ITEM &&
  91. ((LPMCI_STATUS_PARMS)dwParam)->dwItem==MCI_STATUS_NUMBER_OF_TRACKS)
  92. {
  93. DPFN( eDbgLevelSpew, "MCI_STATUS_NUMBER_OF_TRACKS -> 10");
  94. ((LPMCI_STATUS_PARMS)dwParam)->dwReturn = 10;
  95. }
  96. return rval;
  97. }
  98. /*++
  99. Register hooked functions
  100. --*/
  101. HOOK_BEGIN
  102. APIHOOK_ENTRY(KERNEL32.DLL, FindFirstFileA)
  103. APIHOOK_ENTRY(KERNEL32.DLL, FindNextFileA)
  104. APIHOOK_ENTRY(WINMM.DLL, mciSendCommandA)
  105. HOOK_END
  106. IMPLEMENT_SHIM_END