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.

187 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1995-1997 Microsoft Corporation
  3. Module Name:
  4. enummod.cxx
  5. Abstract:
  6. This module implements a remote module enumerator.
  7. Author:
  8. Keith Moore (keithmo) 16-Sep-1997
  9. Revision History:
  10. --*/
  11. #include "inetdbgp.h"
  12. BOOLEAN
  13. EnumModules(
  14. IN PFN_ENUMMODULES EnumProc,
  15. IN PVOID Param
  16. )
  17. /*++
  18. Routine Description:
  19. Enumerates all loaded modules in the debugee.
  20. Arguments:
  21. EnumProc - An enumeration proc that will be invoked for each module.
  22. Param - An uninterpreted parameter passed to the enumeration proc.
  23. Return Value:
  24. BOOLEAN - TRUE if successful, FALSE otherwise.
  25. --*/
  26. {
  27. PROCESS_BASIC_INFORMATION basicInfo;
  28. NTSTATUS status;
  29. PPEB peb;
  30. PPEB_LDR_DATA ldr;
  31. PLIST_ENTRY ldrHead, ldrNext;
  32. PLDR_DATA_TABLE_ENTRY ldrEntry;
  33. LDR_DATA_TABLE_ENTRY ldrEntryData;
  34. WCHAR tmpName[MAX_PATH];
  35. MODULE_INFO moduleInfo;
  36. //
  37. // Get the process info.
  38. //
  39. status = NtQueryInformationProcess(
  40. ExtensionCurrentProcess,
  41. ProcessBasicInformation,
  42. &basicInfo,
  43. sizeof(basicInfo),
  44. NULL
  45. );
  46. if( !NT_SUCCESS(status) ) {
  47. return FALSE;
  48. }
  49. peb = basicInfo.PebBaseAddress;
  50. if( peb == NULL ) {
  51. return FALSE;
  52. }
  53. //
  54. // ldr = peb->Ldr
  55. //
  56. if( !ReadMemory(
  57. (ULONG_PTR)&peb->Ldr,
  58. &ldr,
  59. sizeof(ldr),
  60. NULL
  61. ) ) {
  62. return FALSE;
  63. }
  64. ldrHead = &ldr->InMemoryOrderModuleList;
  65. //
  66. // ldrNext = ldrHead->Flink;
  67. //
  68. if( !ReadMemory(
  69. (ULONG_PTR)&ldrHead->Flink,
  70. &ldrNext,
  71. sizeof(ldrNext),
  72. NULL
  73. ) ) {
  74. return FALSE;
  75. }
  76. while( ldrNext != ldrHead ) {
  77. if( CheckControlC() ) {
  78. break;
  79. }
  80. //
  81. // Read the LDR_DATA_TABLE_ENTRY structure and the module name.
  82. //
  83. ldrEntry = CONTAINING_RECORD(
  84. ldrNext,
  85. LDR_DATA_TABLE_ENTRY,
  86. InMemoryOrderLinks
  87. );
  88. if( !ReadMemory(
  89. (ULONG_PTR)ldrEntry,
  90. &ldrEntryData,
  91. sizeof(ldrEntryData),
  92. NULL
  93. ) ) {
  94. return FALSE;
  95. }
  96. if( !ReadMemory(
  97. (ULONG_PTR)ldrEntryData.BaseDllName.Buffer,
  98. tmpName,
  99. ldrEntryData.BaseDllName.MaximumLength,
  100. NULL
  101. ) ) {
  102. return FALSE;
  103. }
  104. wsprintfA(
  105. moduleInfo.BaseName,
  106. "%ws",
  107. tmpName
  108. );
  109. if( !ReadMemory(
  110. (ULONG_PTR)ldrEntryData.FullDllName.Buffer,
  111. tmpName,
  112. ldrEntryData.FullDllName.MaximumLength,
  113. NULL
  114. ) ) {
  115. return FALSE;
  116. }
  117. wsprintfA(
  118. moduleInfo.FullName,
  119. "%ws",
  120. tmpName
  121. );
  122. moduleInfo.DllBase = (ULONG_PTR)ldrEntryData.DllBase;
  123. moduleInfo.EntryPoint = (ULONG_PTR)ldrEntryData.EntryPoint;
  124. moduleInfo.SizeOfImage = (ULONG)ldrEntryData.SizeOfImage;
  125. //
  126. // Invoke the callback.
  127. //
  128. if( !(EnumProc)(
  129. Param,
  130. &moduleInfo
  131. ) ) {
  132. break;
  133. }
  134. ldrNext = ldrEntryData.InMemoryOrderLinks.Flink;
  135. }
  136. return TRUE;
  137. } // EnumModules