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.

99 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. NetZip.cpp
  5. Abstract:
  6. This App. stops when it is searching for installed browsers. I found that
  7. the App. tries enumerating all processes running using the API call
  8. EnumProcesses(). This is OK and the App. gets the list of PID's. Now, the
  9. App wants to go through each individual Process's modules using
  10. EnumProcessModules. Before that it gets the handle to each process calling
  11. OpenProcess() on each. On the 'System Idle Process', which has a PID of '0',
  12. the call to OpenProcess() returns failure and that is handled. The App then
  13. goes to the next process, which is the 'System' process. The PID is '8'.
  14. The App successfully gets the process handle by a call to OpenProcess() but
  15. when the App. calls EnumProcessModules(), this call returns failure and the
  16. GetLastError( ) returns ERROR_PARTIAL_COPY(0x12b). The App. does not know
  17. how to handle this and it fails.
  18. When I traced into this API, it calls ReadProcessMemory(), which in turn
  19. calls NtReadVirtualMemory(). This is a Kernel call and it returns 8000000d
  20. on Windows 2000. GetLastError() for this translates to
  21. ERROR_PARTIAL_COPY(0x12b). On Windows NT 4.0, the EnumProcessModules() API
  22. calls ReadProcessMemory(), which inturn calls NtReadVirtualMemory() which
  23. returns 0xC0000005. GetLastError() for this translates to
  24. ERROR_NOACCESS(0x3e6) - (Invalid access to a memory location). The App. is
  25. able to handle this. So, the APP should handle both ERROR_NOACCESS and
  26. ERROR_PARTIAL_COPY.
  27. Notes:
  28. This is an app specific shim.
  29. History:
  30. 04/21/2000 prashkud Created
  31. --*/
  32. #include "precomp.h"
  33. IMPLEMENT_SHIM_BEGIN(NetZip)
  34. #include "ShimHookMacro.h"
  35. APIHOOK_ENUM_BEGIN
  36. APIHOOK_ENUM_ENTRY(EnumProcessModules)
  37. APIHOOK_ENUM_END
  38. /*++
  39. This function intercepts EnumProcessModules( ) and and handles the return of
  40. ERROR_PARTIAL_COPY.
  41. --*/
  42. BOOL
  43. APIHOOK(EnumProcessModules)(
  44. HANDLE hProcess, // Handle to process
  45. HMODULE *lphModule, // Array of Handle modules
  46. DWORD cb, // size of array
  47. LPDWORD lpcbNeeded // Number od bytes returned.
  48. )
  49. {
  50. BOOL fRet = FALSE;
  51. fRet = ORIGINAL_API(EnumProcessModules)(
  52. hProcess,
  53. lphModule,
  54. cb,
  55. lpcbNeeded);
  56. if (GetLastError( ) == ERROR_PARTIAL_COPY)
  57. {
  58. SetLastError(ERROR_NOACCESS);
  59. }
  60. return fRet;
  61. }
  62. /*++
  63. Register hooked functions
  64. --*/
  65. HOOK_BEGIN
  66. APIHOOK_ENTRY(PSAPI.DLL, EnumProcessModules )
  67. HOOK_END
  68. IMPLEMENT_SHIM_END