ReactOS 0.4.16-dev-334-g4d9f67c
modules.c File Reference
#include "precomp.h"
#include <ndk/mmfuncs.h>
#include <ndk/psfuncs.h>
#include <ndk/rtlfuncs.h>
#include <debug.h>
Include dependency graph for modules.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS NTAPI PsaEnumerateProcessModules (IN HANDLE ProcessHandle, IN PPROCMOD_ENUM_ROUTINE Callback, IN OUT PVOID CallbackContext)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 26 of file modules.c.

Function Documentation

◆ PsaEnumerateProcessModules()

NTSTATUS NTAPI PsaEnumerateProcessModules ( IN HANDLE  ProcessHandle,
IN PPROCMOD_ENUM_ROUTINE  Callback,
IN OUT PVOID  CallbackContext 
)

Definition at line 30 of file modules.c.

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}
#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:33
Status
Definition: gdiplustypes.h:25
@ ProcessBasicInformation
Definition: winternl.h:394
#define GetExceptionCode
Definition: excpt.h:83
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:90
#define FAILED_WITH_STATUS
Definition: test.h:95
_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:2816
NTSTATUS NTAPI NtQueryInformationProcess(_In_ HANDLE ProcessHandle, _In_ PROCESSINFOCLASS ProcessInformationClass, _Out_ PVOID ProcessInformation, _In_ ULONG ProcessInformationLength, _Out_opt_ PULONG ReturnLength)
Definition: query.c:59
#define __try
Definition: pseh2_64.h:172
#define __except
Definition: pseh2_64.h:173
#define STATUS_SUCCESS
Definition: shellext.h:65
#define DPRINT
Definition: sndvol32.h:73
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 CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_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