ReactOS 0.4.15-dev-5673-g06b25bc
modules.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * LICENSE: See LGPL.txt in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: reactos/lib/epsapi/enum/module.c
6 * PURPOSE: Enumerate process modules
7 * PROGRAMMER: KJK::Hyperion <noog@libero.it>
8 * UPDATE HISTORY:
9 * 10/06/2002: Created
10 * 29/08/2002: Generalized the interface to improve reusability,
11 * more efficient use of memory operations
12 * 12/02/2003: malloc and free renamed to PsaiMalloc and PsaiFree,
13 * for better reusability
14 * 02/04/2003: System modules enumeration moved into its own file
15 * 12/04/2003: internal PSAPI renamed EPSAPI (Extended PSAPI) and
16 * isolated in its own library to clear the confusion
17 * and improve reusability
18 */
19
20#include "precomp.h"
21
22#include <ndk/mmfuncs.h>
23#include <ndk/psfuncs.h>
24#include <ndk/rtlfuncs.h>
25
26#define NDEBUG
27#include <debug.h>
28
33{
35
36 /* current process - use direct memory copy */
37 /* FIXME - compare process id instead of a handle */
39 {
40 PLIST_ENTRY ListHead, Current;
41
42#if 0
43 __try
44 {
45#endif
46 ListHead = &(NtCurrentPeb()->Ldr->InLoadOrderModuleList);
47 Current = ListHead->Flink;
48
49 while(Current != ListHead)
50 {
51 PLDR_DATA_TABLE_ENTRY LoaderModule = CONTAINING_RECORD(Current, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks);
52
53 /* return the current module to the callback */
55
56 if(!NT_SUCCESS(Status))
57 {
58 goto Failure;
59 }
60
61 Current = LoaderModule->InLoadOrderLinks.Flink;
62 }
63#if 0
64 }
66 {
67 return GetExceptionCode();
68 }
69#endif
70 }
71 else
72 {
73 PROCESS_BASIC_INFORMATION BasicInformation;
74 PPEB_LDR_DATA LoaderData;
75 LDR_DATA_TABLE_ENTRY LoaderModule;
76 PLIST_ENTRY ListHead, Current;
77
78 /* query the process basic information (includes the PEB address) */
81 &BasicInformation,
82 sizeof(BasicInformation),
83 NULL);
84
85 if(!NT_SUCCESS(Status))
86 {
87 DPRINT(FAILED_WITH_STATUS, "NtQueryInformationProcess", Status);
88 goto Failure;
89 }
90
91 /* get the address of the PE Loader data */
93 &(BasicInformation.PebBaseAddress->Ldr),
94 &LoaderData,
95 sizeof(LoaderData),
96 NULL);
97
98 if(!NT_SUCCESS(Status))
99 {
100 DPRINT(FAILED_WITH_STATUS, "NtReadVirtualMemory", Status);
101 goto Failure;
102 }
103
104 /* head of the module list: the last element in the list will point to this */
105 ListHead = &LoaderData->InLoadOrderModuleList;
106
107 /* get the address of the first element in the list */
109 &(LoaderData->InLoadOrderModuleList.Flink),
110 &Current,
111 sizeof(Current),
112 NULL);
113
114 while(Current != ListHead)
115 {
116 /* read the current module */
118 CONTAINING_RECORD(Current, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks),
119 &LoaderModule,
120 sizeof(LoaderModule),
121 NULL);
122
123 if(!NT_SUCCESS(Status))
124 {
125 DPRINT(FAILED_WITH_STATUS, "NtReadVirtualMemory", Status);
126 goto Failure;
127 }
128
129 /* return the current module to the callback */
130 Status = Callback(ProcessHandle, &LoaderModule, CallbackContext);
131
132 if(!NT_SUCCESS(Status))
133 {
134 goto Failure;
135 }
136
137 /* address of the next module in the list */
138 Current = LoaderModule.InLoadOrderLinks.Flink;
139 }
140 }
141
142 return STATUS_SUCCESS;
143
144Failure:
145 return Status;
146}
147
148/* EOF */
#define NtCurrentPeb()
Definition: FLS.c:22
LONG NTSTATUS
Definition: precomp.h:26
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
@ ProcessBasicInformation
Definition: winternl.h:394
NTSTATUS NTAPI(* PPROCMOD_ENUM_ROUTINE)(IN HANDLE ProcessHandle, IN PLDR_DATA_TABLE_ENTRY CurrentModule, IN OUT PVOID CallbackContext)
Definition: test.h:88
#define FAILED_WITH_STATUS
Definition: test.h:95
NTSTATUS NTAPI PsaEnumerateProcessModules(IN HANDLE ProcessHandle, IN PPROCMOD_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
Definition: modules.c:30
_In_ HANDLE ProcessHandle
Definition: mmfuncs.h:403
#define NtCurrentProcess()
Definition: nt_native.h:1657
NTSTATUS NTAPI NtReadVirtualMemory(IN HANDLE ProcessHandle, IN PVOID BaseAddress, OUT PVOID Buffer, IN SIZE_T NumberOfBytesToRead, OUT PSIZE_T NumberOfBytesRead OPTIONAL)
Definition: virtual.c:2810
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59
#define GetExceptionCode()
Definition: seh.h:27
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:71
Definition: btrfs_drv.h:1876
LIST_ENTRY InLoadOrderLinks
Definition: ldrtypes.h:138
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
LIST_ENTRY InLoadOrderModuleList
Definition: ldrtypes.h:120
PPEB_LDR_DATA Ldr
Definition: btrfs_drv.h:1912
#define NTAPI
Definition: typedefs.h:36
#define IN
Definition: typedefs.h:39
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
#define OUT
Definition: typedefs.h:40
_In_ WDFINTERRUPT _In_ PFN_WDF_INTERRUPT_SYNCHRONIZE Callback
Definition: wdfinterrupt.h:458
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR _In_ ULONGLONG _In_ ULONGLONG _In_opt_ PEVENT_FILTER_DESCRIPTOR _Inout_opt_ PVOID CallbackContext
Definition: wmitypes.h:60