Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenmodules.c
Go to the documentation of this file.
00001 /* $Id: modules.c 52985 2011-07-28 16:21:48Z akhaldi $ 00002 */ 00003 /* 00004 * COPYRIGHT: See COPYING in the top level directory 00005 * LICENSE: See LGPL.txt in the top level directory 00006 * PROJECT: ReactOS system libraries 00007 * FILE: reactos/lib/epsapi/enum/module.c 00008 * PURPOSE: Enumerate process modules 00009 * PROGRAMMER: KJK::Hyperion <noog@libero.it> 00010 * UPDATE HISTORY: 00011 * 10/06/2002: Created 00012 * 29/08/2002: Generalized the interface to improve reusability, 00013 * more efficient use of memory operations 00014 * 12/02/2003: malloc and free renamed to PsaiMalloc and PsaiFree, 00015 * for better reusability 00016 * 02/04/2003: System modules enumeration moved into its own file 00017 * 12/04/2003: internal PSAPI renamed EPSAPI (Extended PSAPI) and 00018 * isolated in its own library to clear the confusion 00019 * and improve reusability 00020 */ 00021 00022 #include "precomp.h" 00023 00024 #define NDEBUG 00025 #include <debug.h> 00026 00027 NTSTATUS NTAPI 00028 PsaEnumerateProcessModules(IN HANDLE ProcessHandle, 00029 IN PPROCMOD_ENUM_ROUTINE Callback, 00030 IN OUT PVOID CallbackContext) 00031 { 00032 NTSTATUS Status; 00033 00034 /* current process - use direct memory copy */ 00035 /* FIXME - compare process id instead of a handle */ 00036 if(ProcessHandle == NtCurrentProcess()) 00037 { 00038 PLIST_ENTRY ListHead, Current; 00039 00040 #if 0 00041 __try 00042 { 00043 #endif 00044 ListHead = &(NtCurrentPeb()->Ldr->InLoadOrderModuleList); 00045 Current = ListHead->Flink; 00046 00047 while(Current != ListHead) 00048 { 00049 PLDR_DATA_TABLE_ENTRY LoaderModule = CONTAINING_RECORD(Current, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks); 00050 00051 /* return the current module to the callback */ 00052 Status = Callback(ProcessHandle, LoaderModule, CallbackContext); 00053 00054 if(!NT_SUCCESS(Status)) 00055 { 00056 goto Failure; 00057 } 00058 00059 Current = LoaderModule->InLoadOrderLinks.Flink; 00060 } 00061 #if 0 00062 } 00063 __except(EXCEPTION_EXECUTE_HANDLER) 00064 { 00065 return GetExceptionCode(); 00066 } 00067 #endif 00068 } 00069 else 00070 { 00071 PROCESS_BASIC_INFORMATION BasicInformation; 00072 PPEB_LDR_DATA LoaderData; 00073 LDR_DATA_TABLE_ENTRY LoaderModule; 00074 PLIST_ENTRY ListHead, Current; 00075 00076 /* query the process basic information (includes the PEB address) */ 00077 Status = NtQueryInformationProcess(ProcessHandle, 00078 ProcessBasicInformation, 00079 &BasicInformation, 00080 sizeof(BasicInformation), 00081 NULL); 00082 00083 if(!NT_SUCCESS(Status)) 00084 { 00085 DPRINT(FAILED_WITH_STATUS, "NtQueryInformationProcess", Status); 00086 goto Failure; 00087 } 00088 00089 /* get the address of the PE Loader data */ 00090 Status = NtReadVirtualMemory(ProcessHandle, 00091 &(BasicInformation.PebBaseAddress->Ldr), 00092 &LoaderData, 00093 sizeof(LoaderData), 00094 NULL); 00095 00096 if(!NT_SUCCESS(Status)) 00097 { 00098 DPRINT(FAILED_WITH_STATUS, "NtReadVirtualMemory", Status); 00099 goto Failure; 00100 } 00101 00102 /* head of the module list: the last element in the list will point to this */ 00103 ListHead = &LoaderData->InLoadOrderModuleList; 00104 00105 /* get the address of the first element in the list */ 00106 Status = NtReadVirtualMemory(ProcessHandle, 00107 &(LoaderData->InLoadOrderModuleList.Flink), 00108 &Current, 00109 sizeof(Current), 00110 NULL); 00111 00112 while(Current != ListHead) 00113 { 00114 /* read the current module */ 00115 Status = NtReadVirtualMemory(ProcessHandle, 00116 CONTAINING_RECORD(Current, LDR_DATA_TABLE_ENTRY, InLoadOrderLinks), 00117 &LoaderModule, 00118 sizeof(LoaderModule), 00119 NULL); 00120 00121 if(!NT_SUCCESS(Status)) 00122 { 00123 DPRINT(FAILED_WITH_STATUS, "NtReadVirtualMemory", Status); 00124 goto Failure; 00125 } 00126 00127 /* return the current module to the callback */ 00128 Status = Callback(ProcessHandle, &LoaderModule, CallbackContext); 00129 00130 if(!NT_SUCCESS(Status)) 00131 { 00132 goto Failure; 00133 } 00134 00135 /* address of the next module in the list */ 00136 Current = LoaderModule.InLoadOrderLinks.Flink; 00137 } 00138 } 00139 00140 return STATUS_SUCCESS; 00141 00142 Failure: 00143 return Status; 00144 } 00145 00146 /* EOF */ Generated on Sat May 26 2012 04:35:03 for ReactOS by
1.7.6.1
|