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.

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