1. fixed definition of the DEBUG_MODULE_INFORMATION structure

2. implemented module and heap list enumeration for toolhelp

svn path=/trunk/; revision=11698
This commit is contained in:
Thomas Bluemel 2004-11-19 01:30:35 +00:00
parent c145b0b293
commit cd57e3d41d
9 changed files with 92 additions and 81 deletions

View file

@ -13,6 +13,36 @@ typedef BOOL STDCALL_FUNC
ULONG ul_reason_for_call,
LPVOID lpReserved);
#if defined(__USE_W32API) || defined(__NTDLL__)
/*
* Fu***ng headers hell made me do this...i'm sick of it
*/
typedef struct _LOCK_INFORMATION
{
ULONG LockCount;
DEBUG_LOCK_INFORMATION LockEntry[1];
} LOCK_INFORMATION, *PLOCK_INFORMATION;
typedef struct _HEAP_INFORMATION
{
ULONG HeapCount;
DEBUG_HEAP_INFORMATION HeapEntry[1];
} HEAP_INFORMATION, *PHEAP_INFORMATION;
typedef struct _MODULE_INFORMATION
{
ULONG ModuleCount;
DEBUG_MODULE_INFORMATION ModuleEntry[1];
} MODULE_INFORMATION, *PMODULE_INFORMATION;
NTSTATUS STDCALL
LdrQueryProcessModuleInformation(IN PMODULE_INFORMATION ModuleInformation OPTIONAL,
IN ULONG Size OPTIONAL,
OUT PULONG ReturnedSize);
#endif /* __USE_W32API */
/* Module flags */
#define IMAGE_DLL 0x00000004
#define LOAD_IN_PROGRESS 0x00001000
@ -55,27 +85,6 @@ typedef struct _LDR_SYMBOL_INFO {
#define RVA(m, b) ((ULONG)b + m)
typedef struct _MODULE_ENTRY
{
ULONG Unknown0;
ULONG Unknown1;
PVOID BaseAddress;
ULONG SizeOfImage;
ULONG Flags;
USHORT Unknown2;
USHORT Unknown3;
SHORT LoadCount;
USHORT PathLength;
CHAR ModuleName[256];
} MODULE_ENTRY, *PMODULE_ENTRY;
typedef struct _MODULE_INFORMATION
{
ULONG ModuleCount;
MODULE_ENTRY ModuleEntry[1];
} MODULE_INFORMATION, *PMODULE_INFORMATION;
#ifdef KDBG
VOID
@ -140,11 +149,6 @@ LdrQueryImageFileExecutionOptions (IN PUNICODE_STRING SubKey,
IN ULONG BufferSize,
OUT PULONG RetunedLength OPTIONAL);
NTSTATUS STDCALL
LdrQueryProcessModuleInformation(IN PMODULE_INFORMATION ModuleInformation OPTIONAL,
IN ULONG Size OPTIONAL,
OUT PULONG ReturnedSize);
NTSTATUS STDCALL
LdrShutdownProcess(VOID);

View file

@ -1,4 +1,4 @@
/* $Id: rtl.h,v 1.51 2004/10/30 22:18:16 weiden Exp $
/* $Id: rtl.h,v 1.52 2004/11/19 01:30:34 weiden Exp $
*
*/
@ -54,7 +54,7 @@ typedef struct _DEBUG_BUFFER
typedef struct _DEBUG_MODULE_INFORMATION {
ULONG Reserved[2];
ULONG Base;
PVOID Base;
ULONG Size;
ULONG Flags;
USHORT Index;
@ -65,7 +65,7 @@ typedef struct _DEBUG_MODULE_INFORMATION {
} DEBUG_MODULE_INFORMATION, *PDEBUG_MODULE_INFORMATION;
typedef struct _DEBUG_HEAP_INFORMATION {
ULONG Base;
PVOID Base;
ULONG Flags;
USHORT Granularity;
USHORT Unknown;
@ -120,19 +120,6 @@ typedef LPCRITICAL_SECTION LPRTL_CRITICAL_SECTION;
#endif /* !__USE_W32API */
typedef struct _LOCK_INFORMATION
{
ULONG LockCount;
DEBUG_LOCK_INFORMATION LockEntry[1];
} LOCK_INFORMATION, *PLOCK_INFORMATION;
typedef struct _HEAP_INFORMATION
{
ULONG HeapCount;
DEBUG_HEAP_INFORMATION HeapEntry[1];
} HEAP_INFORMATION, *PHEAP_INFORMATION;
typedef struct _RTL_PROCESS_INFO
{
ULONG Size;

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* $Id: toolhelp.c,v 1.9 2004/11/05 11:51:18 weiden Exp $
/* $Id: toolhelp.c,v 1.10 2004/11/19 01:30:35 weiden Exp $
*
* KERNEL32.DLL toolhelp functions
*
@ -348,8 +348,8 @@ TH32CreateSnapshotSectionInitialize(DWORD dwFlags,
{
HeapListEntry->dwSize = sizeof(HEAPLIST32);
HeapListEntry->th32ProcessID = th32ProcessID;
HeapListEntry->th32HeapID = 0; /* FIXME - use the base address of the heap we're iterating */
HeapListEntry->dwFlags = 0; /* FIXME - use the flags of the heap we're iterating */
HeapListEntry->th32HeapID = (ULONG_PTR)hi->HeapEntry[i].Base;
HeapListEntry->dwFlags = hi->HeapEntry[i].Flags;
HeapListEntry++;
}
@ -366,9 +366,27 @@ TH32CreateSnapshotSectionInitialize(DWORD dwFlags,
for(i = 0; i < nModules; i++)
{
ModuleListEntry->dwSize = sizeof(MODULEENTRY32W);
ModuleListEntry->th32ModuleID = 1; /* no longer used, always set to one! */
ModuleListEntry->th32ProcessID = th32ProcessID;
/* FIXME - fill the MODULEENTRY32W structure */
ModuleListEntry->GlblcntUsage = mi->ModuleEntry[i].LoadCount;
ModuleListEntry->ProccntUsage = mi->ModuleEntry[i].LoadCount;
ModuleListEntry->modBaseAddr = (BYTE*)mi->ModuleEntry[i].Base;
ModuleListEntry->modBaseSize = mi->ModuleEntry[i].Size;
ModuleListEntry->hModule = (HMODULE)mi->ModuleEntry[i].Base;
MultiByteToWideChar(CP_ACP,
0,
&mi->ModuleEntry[i].ImageName[mi->ModuleEntry[i].ModuleNameOffset],
-1,
ModuleListEntry->szModule,
sizeof(ModuleListEntry->szModule) / sizeof(ModuleListEntry->szModule[0]));
MultiByteToWideChar(CP_ACP,
0,
mi->ModuleEntry[i].ImageName,
-1,
ModuleListEntry->szExePath,
sizeof(ModuleListEntry->szExePath) / sizeof(ModuleListEntry->szExePath[0]));
ModuleListEntry++;
}
@ -728,6 +746,9 @@ Module32Next(HANDLE hSnapshot, LPMODULEENTRY32 lpme)
}
/*
* @implemented
*/
BOOL
STDCALL
Module32NextW(HANDLE hSnapshot, LPMODULEENTRY32W lpme)

View file

@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.100 2004/10/30 14:02:03 navaraf Exp $
/* $Id: utils.c,v 1.101 2004/11/19 01:30:35 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -2629,7 +2629,7 @@ LdrQueryProcessModuleInformation(IN PMODULE_INFORMATION ModuleInformation OPTION
PLIST_ENTRY ModuleListHead;
PLIST_ENTRY Entry;
PLDR_MODULE Module;
PMODULE_ENTRY ModulePtr = NULL;
PDEBUG_MODULE_INFORMATION ModulePtr = NULL;
NTSTATUS Status = STATUS_SUCCESS;
ULONG UsedSize = sizeof(ULONG);
ANSI_STRING AnsiString;
@ -2666,31 +2666,30 @@ LdrQueryProcessModuleInformation(IN PMODULE_INFORMATION ModuleInformation OPTION
}
else if (ModuleInformation != NULL)
{
ModulePtr->Unknown0 = 0; // FIXME: ??
ModulePtr->Unknown1 = 0; // FIXME: ??
ModulePtr->BaseAddress = Module->BaseAddress;
ModulePtr->SizeOfImage = Module->SizeOfImage;
ModulePtr->Reserved[0] = ModulePtr->Reserved[1] = 0; // FIXME: ??
ModulePtr->Base = Module->BaseAddress;
ModulePtr->Size = Module->SizeOfImage;
ModulePtr->Flags = Module->Flags;
ModulePtr->Unknown2 = 0; // FIXME: load order index ??
ModulePtr->Unknown3 = 0; // FIXME: ??
ModulePtr->Index = 0; // FIXME: index ??
ModulePtr->Unknown = 0; // FIXME: ??
ModulePtr->LoadCount = Module->LoadCount;
AnsiString.Length = 0;
AnsiString.MaximumLength = 256;
AnsiString.Buffer = ModulePtr->ModuleName;
AnsiString.Buffer = ModulePtr->ImageName;
RtlUnicodeStringToAnsiString(&AnsiString,
&Module->FullDllName,
FALSE);
p = strrchr(ModulePtr->ModuleName, '\\');
p = strrchr(ModulePtr->ImageName, '\\');
if (p != NULL)
ModulePtr->PathLength = p - ModulePtr->ModuleName + 1;
ModulePtr->ModuleNameOffset = p - ModulePtr->ImageName + 1;
else
ModulePtr->PathLength = 0;
ModulePtr->ModuleNameOffset = 0;
ModulePtr++;
ModuleInformation->ModuleCount++;
}
UsedSize += sizeof(MODULE_ENTRY);
UsedSize += sizeof(DEBUG_MODULE_INFORMATION);
Entry = Entry->Flink;
}

View file

@ -103,9 +103,9 @@ RtlDestroyQueryDebugBuffer(IN PDEBUG_BUFFER Buf)
*/
NTSTATUS STDCALL
RtlpQueryRemoteProcessModules(HANDLE ProcessHandle,
IN PMODULE_INFORMATION ModuleInformation OPTIONAL,
IN ULONG Size OPTIONAL,
OUT PULONG ReturnedSize)
IN PMODULE_INFORMATION ModuleInformation OPTIONAL,
IN ULONG Size OPTIONAL,
OUT PULONG ReturnedSize)
{
PROCESS_BASIC_INFORMATION pbiInfo;
PPEB_LDR_DATA ppldLdrData;
@ -113,7 +113,7 @@ RtlpQueryRemoteProcessModules(HANDLE ProcessHandle,
PLIST_ENTRY pleListHead;
PLIST_ENTRY pleCurEntry;
PMODULE_ENTRY ModulePtr = NULL;
PDEBUG_MODULE_INFORMATION ModulePtr = NULL;
NTSTATUS Status = STATUS_SUCCESS;
ULONG UsedSize = sizeof(ULONG);
ANSI_STRING AnsiString;
@ -124,7 +124,7 @@ RtlpQueryRemoteProcessModules(HANDLE ProcessHandle,
/* query the process basic information (includes the PEB address) */
Status = NtQueryInformationProcess ( ProcessHandle,
ProcessBasicInformation,
&pbiInfo,
&pbiInfo,
sizeof(PROCESS_BASIC_INFORMATION),
NULL);
@ -217,32 +217,31 @@ RtlpQueryRemoteProcessModules(HANDLE ProcessHandle,
}
else if (ModuleInformation != NULL)
{
ModulePtr->Unknown0 = 0; // FIXME: ??
ModulePtr->Unknown1 = 0; // FIXME: ??
ModulePtr->BaseAddress = lmModule.BaseAddress;
ModulePtr->SizeOfImage = lmModule.SizeOfImage;
ModulePtr->Reserved[0] = ModulePtr->Reserved[1] = 0; // FIXME: ??
ModulePtr->Base = lmModule.BaseAddress;
ModulePtr->Size = lmModule.SizeOfImage;
ModulePtr->Flags = lmModule.Flags;
ModulePtr->Unknown2 = 0; // FIXME: load order index ??
ModulePtr->Unknown3 = 0; // FIXME: ??
ModulePtr->Index = 0; // FIXME: ??
ModulePtr->Unknown = 0; // FIXME: ??
ModulePtr->LoadCount = lmModule.LoadCount;
AnsiString.Length = 0;
AnsiString.MaximumLength = 256;
AnsiString.Buffer = ModulePtr->ModuleName;
AnsiString.Buffer = ModulePtr->ImageName;
RtlUnicodeStringToAnsiString(&AnsiString,
&Unicode,
FALSE);
p = strrchr(ModulePtr->ModuleName, '\\');
p = strrchr(ModulePtr->ImageName, '\\');
if (p != NULL)
ModulePtr->PathLength = p - ModulePtr->ModuleName + 1;
ModulePtr->ModuleNameOffset = p - ModulePtr->ImageName + 1;
else
ModulePtr->PathLength = 0;
ModulePtr->ModuleNameOffset = 0;
ModulePtr++;
ModuleInformation->ModuleCount++;
}
UsedSize += sizeof(MODULE_ENTRY);
UsedSize += sizeof(DEBUG_MODULE_INFORMATION);
/* address of the next module in the list */
pleCurEntry = lmModule.InLoadOrderModuleList.Flink;

View file

@ -1,4 +1,4 @@
/* $Id: ppb.c,v 1.19 2004/09/29 08:41:39 weiden Exp $
/* $Id: ppb.c,v 1.20 2004/11/19 01:30:35 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -12,6 +12,7 @@
/* INCLUDES ****************************************************************/
#include <ddk/ntddk.h>
#include <windows.h>
#include <ntdll/ldr.h>
#include <napi/teb.h>
#include <ntdll/base.h>

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.35 2003/09/12 17:51:48 vizzini Exp $
/* $Id: process.c,v 1.36 2004/11/19 01:30:35 weiden Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
@ -12,6 +12,7 @@
/* INCLUDES ****************************************************************/
#include <ddk/ntddk.h>
#include <windows.h>
#include <napi/i386/segment.h>
#include <ntdll/ldr.h>
#include <ntdll/base.h>

View file

@ -10,7 +10,6 @@
#include <pe.h>
#include <internal/io.h>
#include <ntdll/ldr.h>
#include <internal/module.h>
#define KERNEL_MODULE_NAME L"ntoskrnl.exe"

View file

@ -1644,7 +1644,7 @@ RtlDestroyQueryDebugBuffer(
typedef struct _DEBUG_MODULE_INFORMATION {
ULONG Reserved[2];
ULONG Base;
PVOID Base;
ULONG Size;
ULONG Flags;
USHORT Index;
@ -1655,7 +1655,7 @@ typedef struct _DEBUG_MODULE_INFORMATION {
} DEBUG_MODULE_INFORMATION, *PDEBUG_MODULE_INFORMATION;
typedef struct _DEBUG_HEAP_INFORMATION {
ULONG Base;
PVOID Base;
ULONG Flags;
USHORT Granularity;
USHORT Unknown;