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.

202 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. EmulateLZHandles.cpp
  5. Abstract:
  6. This shim hooks all of the LZ api calls and increments/decrements the
  7. handles so that a valid handle from the app's perspective is always > 0
  8. instead of >= 0.
  9. Fixes apps that treated a handle value of zero as an error; Win9x never
  10. returned handles of zero.
  11. History:
  12. 07/25/2000 t-adams Created
  13. --*/
  14. #include "precomp.h"
  15. IMPLEMENT_SHIM_BEGIN(EmulateLZHandles)
  16. #include "ShimHookMacro.h"
  17. APIHOOK_ENUM_BEGIN
  18. APIHOOK_ENUM_ENTRY(LZClose)
  19. APIHOOK_ENUM_ENTRY(LZCopy)
  20. APIHOOK_ENUM_ENTRY(LZInit)
  21. APIHOOK_ENUM_ENTRY(LZOpenFile)
  22. APIHOOK_ENUM_ENTRY(LZRead)
  23. APIHOOK_ENUM_ENTRY(LZSeek)
  24. APIHOOK_ENUM_END
  25. #define KEY_SIZE_STEP MAX_PATH
  26. /*++
  27. Abstract:
  28. This function decrements the handles on the way in and increments
  29. handles that are passed back to the app
  30. History:
  31. 07/25/2000 t-adams Created
  32. --*/
  33. VOID
  34. APIHOOK(LZClose)(INT hFile)
  35. {
  36. ORIGINAL_API(LZClose)(--hFile);
  37. }
  38. /*++
  39. Abstract:
  40. This function decrements the handles on the way in and increments
  41. handles that are passed back to the app
  42. History:
  43. 07/25/2000 t-adams Created
  44. --*/
  45. LONG
  46. APIHOOK(LZCopy)(
  47. INT hSource,
  48. INT hDest
  49. )
  50. {
  51. return ORIGINAL_API(LZCopy)(--hSource, --hDest);
  52. }
  53. /*++
  54. Abstract:
  55. This function does not decrement the handle passed in to it
  56. because the handle passed in is supposed to be a regular HANDLE
  57. created by CreateFile. It does decrement handles that are
  58. passed back to the app because they represent LZ file handles.
  59. The differences between the handles are poorly documented in MSDN.
  60. History:
  61. 07/25/2000 t-adams Created
  62. --*/
  63. INT
  64. APIHOOK(LZInit)(INT hfSource)
  65. {
  66. INT iRet = 0;
  67. // Don't decrement handle. See above.
  68. iRet = ORIGINAL_API(LZInit)(hfSource);
  69. // If there was an error, don't increment the error.
  70. if(iRet < 0) {
  71. return iRet;
  72. }
  73. return ++iRet;
  74. }
  75. /*++
  76. Abstract:
  77. This function decrements the handles on the way in and increments
  78. handles that are passed back to the app
  79. History:
  80. 07/25/2000 t-adams Created
  81. --*/
  82. INT
  83. APIHOOK(LZOpenFile)(
  84. LPSTR lpFileName,
  85. LPOFSTRUCT lpReOpenBuf,
  86. WORD wStyle
  87. )
  88. {
  89. INT iRet = 0;
  90. iRet = ORIGINAL_API(LZOpenFile)(lpFileName, lpReOpenBuf, wStyle);
  91. // If there was an error, don't increment the error.
  92. if( iRet < 0 ) {
  93. return iRet;
  94. }
  95. return ++iRet;
  96. }
  97. /*++
  98. Abstract:
  99. This function decrements the handles on the way in and increments
  100. handles that are passed back to the app
  101. History:
  102. 07/25/2000 t-adams Created
  103. --*/
  104. INT
  105. APIHOOK(LZRead)(
  106. INT hFile,
  107. LPSTR lpBuffer,
  108. INT cbRead
  109. )
  110. {
  111. return ORIGINAL_API(LZRead)(--hFile, lpBuffer, cbRead);
  112. }
  113. /*++
  114. Abstract:
  115. This function decrements the handles on the way in and increments
  116. handles that are passed back to the app
  117. History:
  118. 07/25/2000 t-adams Created
  119. --*/
  120. LONG
  121. APIHOOK(LZSeek)(
  122. INT hFile,
  123. LONG lOffset,
  124. INT iOrigin
  125. )
  126. {
  127. return ORIGINAL_API(LZSeek)(--hFile, lOffset, iOrigin);
  128. }
  129. /*++
  130. Register hooked functions
  131. --*/
  132. HOOK_BEGIN
  133. APIHOOK_ENTRY(LZ32.DLL, LZClose)
  134. APIHOOK_ENTRY(LZ32.DLL, LZCopy)
  135. APIHOOK_ENTRY(LZ32.DLL, LZInit)
  136. APIHOOK_ENTRY(LZ32.DLL, LZOpenFile)
  137. APIHOOK_ENTRY(LZ32.DLL, LZRead)
  138. APIHOOK_ENTRY(LZ32.DLL, LZSeek)
  139. HOOK_END
  140. IMPLEMENT_SHIM_END