Steven Wilson: update tlist to use new process info struct names

svn path=/trunk/; revision=14975
This commit is contained in:
Maarten Bosma 2005-05-04 18:53:47 +00:00
parent 6039178c86
commit 587ddda1d5

View file

@ -107,8 +107,8 @@ BOOL STDCALL AcquirePrivileges (VOID)
int STDCALL int STDCALL
ProcessHasDescendants ( ProcessHasDescendants (
ULONG Pid, HANDLE Pid,
PSYSTEM_PROCESSES pInfo PSYSTEM_PROCESS_INFORMATION pInfo
) )
{ {
LONG Count = 0; LONG Count = 0;
@ -116,16 +116,16 @@ ProcessHasDescendants (
if (NULL == pInfo) return 0; if (NULL == pInfo) return 0;
do { do {
if (ALREADY_PROCESSED != pInfo->InheritedFromProcessId) if (ALREADY_PROCESSED != (DWORD)pInfo->InheritedFromUniqueProcessId)
{ {
if ((Pid != pInfo->ProcessId) && (Pid == pInfo->InheritedFromProcessId)) if ((Pid != (HANDLE)pInfo->UniqueProcessId) && (Pid == (HANDLE)pInfo->InheritedFromUniqueProcessId))
{ {
++ Count; ++ Count;
} }
} }
pInfo = (PSYSTEM_PROCESSES)((PBYTE)pInfo + pInfo->NextEntryDelta); pInfo = (PSYSTEM_PROCESS_INFORMATION)((PBYTE)pInfo + pInfo->NextEntryOffset);
} while (0 != pInfo->NextEntryDelta); } while (0 != pInfo->NextEntryOffset);
return Count; return Count;
} }
@ -133,18 +133,18 @@ ProcessHasDescendants (
BOOL STDCALL BOOL STDCALL
GetProcessInfo ( GetProcessInfo (
PSYSTEM_PROCESSES pInfo, PSYSTEM_PROCESS_INFORMATION pInfo,
LPWSTR * Module, LPWSTR * Module,
LPWSTR * Title LPWSTR * Title
) )
{ {
*Module = (pInfo->ProcessName.Length ? pInfo->ProcessName.Buffer : L"System process"); *Module = (pInfo->ImageName.Length ? pInfo->ImageName.Buffer : L"System process");
*Title = L""; /* TODO: check if the process has any window */ *Title = L""; /* TODO: check if the process has any window */
return TRUE; return TRUE;
} }
int STDCALL PrintProcessInfoDepth ( int STDCALL PrintProcessInfoDepth (
PSYSTEM_PROCESSES pInfo, PSYSTEM_PROCESS_INFORMATION pInfo,
LONG Depth LONG Depth
) )
{ {
@ -157,8 +157,8 @@ int STDCALL PrintProcessInfoDepth (
wprintf ( wprintf (
L"%s (%d, %d) %s\n", L"%s (%d, %d) %s\n",
Module, Module,
pInfo->ProcessId, pInfo->UniqueProcessId,
pInfo->InheritedFromProcessId, pInfo->InheritedFromUniqueProcessId,
Title Title
); );
return EXIT_SUCCESS; return EXIT_SUCCESS;
@ -166,25 +166,25 @@ int STDCALL PrintProcessInfoDepth (
int STDCALL int STDCALL
PrintProcessAndDescendants ( PrintProcessAndDescendants (
PSYSTEM_PROCESSES pInfo, PSYSTEM_PROCESS_INFORMATION pInfo,
PSYSTEM_PROCESSES pInfoBase, PSYSTEM_PROCESS_INFORMATION pInfoBase,
LONG Depth LONG Depth
) )
{ {
DWORD Pid = 0; HANDLE Pid = 0;
if (NULL == pInfo) return EXIT_FAILURE; if (NULL == pInfo) return EXIT_FAILURE;
/* Print current pInfo process */ /* Print current pInfo process */
PrintProcessInfoDepth (pInfo, Depth ++); PrintProcessInfoDepth (pInfo, Depth ++);
pInfo->InheritedFromProcessId = ALREADY_PROCESSED; pInfo->InheritedFromUniqueProcessId = (HANDLE)ALREADY_PROCESSED;
/* Save current process' PID */ /* Save current process' PID */
Pid = pInfo->ProcessId; Pid = pInfo->UniqueProcessId;
/* Scan and print possible children */ /* Scan and print possible children */
do { do {
if (ALREADY_PROCESSED != pInfo->InheritedFromProcessId) if (ALREADY_PROCESSED != (DWORD)pInfo->InheritedFromUniqueProcessId)
{ {
if (Pid == pInfo->InheritedFromProcessId) if (Pid == pInfo->InheritedFromUniqueProcessId)
{ {
if (ProcessHasDescendants (Pid, pInfoBase)) if (ProcessHasDescendants (Pid, pInfoBase))
{ {
@ -197,21 +197,21 @@ PrintProcessAndDescendants (
else else
{ {
PrintProcessInfoDepth (pInfo, Depth); PrintProcessInfoDepth (pInfo, Depth);
pInfo->InheritedFromProcessId = ALREADY_PROCESSED; pInfo->InheritedFromUniqueProcessId = (HANDLE)ALREADY_PROCESSED;
} }
} }
} }
pInfo = (PSYSTEM_PROCESSES)((PBYTE)pInfo + pInfo->NextEntryDelta); pInfo = (PSYSTEM_PROCESS_INFORMATION)((PBYTE)pInfo + pInfo->NextEntryOffset);
} while (0 != pInfo->NextEntryDelta); } while (0 != pInfo->NextEntryOffset);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
int STDCALL PrintProcessList (BOOL DisplayTree) int STDCALL PrintProcessList (BOOL DisplayTree)
{ {
PSYSTEM_PROCESSES pInfo = NULL; PSYSTEM_PROCESS_INFORMATION pInfo = NULL;
PSYSTEM_PROCESSES pInfoBase = NULL; PSYSTEM_PROCESS_INFORMATION pInfoBase = NULL;
LONG Length = 0; LONG Length = 0;
LPWSTR Module = L""; LPWSTR Module = L"";
LPWSTR Title = L""; LPWSTR Title = L"";
@ -228,15 +228,15 @@ int STDCALL PrintProcessList (BOOL DisplayTree)
GetProcessInfo (pInfo, & Module, & Title); GetProcessInfo (pInfo, & Module, & Title);
wprintf ( wprintf (
L"%4d %-16s %s\n", L"%4d %-16s %s\n",
pInfo->ProcessId, pInfo->UniqueProcessId,
Module, Module,
Title, Title,
pInfo->InheritedFromProcessId pInfo->InheritedFromUniqueProcessId
); );
} }
else else
{ {
if (ALREADY_PROCESSED != pInfo->InheritedFromProcessId) if (ALREADY_PROCESSED != (DWORD)pInfo->InheritedFromUniqueProcessId)
{ {
PrintProcessAndDescendants (pInfo, pInfoBase, 0); PrintProcessAndDescendants (pInfo, pInfoBase, 0);
} }
@ -251,7 +251,7 @@ int STDCALL PrintProcessList (BOOL DisplayTree)
} }
int STDCALL PrintThreads (PSYSTEM_PROCESSES pInfo) int STDCALL PrintThreads (PSYSTEM_PROCESS_INFORMATION pInfo)
{ {
ULONG i = 0; ULONG i = 0;
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
@ -260,15 +260,15 @@ int STDCALL PrintThreads (PSYSTEM_PROCESSES pInfo)
PVOID Win32StartAddress = NULL; PVOID Win32StartAddress = NULL;
THREAD_BASIC_INFORMATION tInfo = {0}; THREAD_BASIC_INFORMATION tInfo = {0};
ULONG ReturnLength = 0; ULONG ReturnLength = 0;
PSYSTEM_THREADS CurThread; PSYSTEM_THREAD_INFORMATION CurThread;
if (NULL == pInfo) return EXIT_FAILURE; if (NULL == pInfo) return EXIT_FAILURE;
CurThread = PsaWalkFirstThread(pInfo); CurThread = PsaWalkFirstThread(pInfo);
wprintf (L" NumberOfThreads: %d\n", pInfo->ThreadCount); wprintf (L" NumberOfThreads: %d\n", pInfo->NumberOfThreads);
for (i = 0; i < pInfo->ThreadCount; i ++, CurThread = PsaWalkNextThread(CurThread)) for (i = 0; i < pInfo->NumberOfThreads; i ++, CurThread = PsaWalkNextThread(CurThread))
{ {
Status = NtOpenThread ( Status = NtOpenThread (
& hThread, & hThread,
@ -314,7 +314,7 @@ int STDCALL PrintThreads (PSYSTEM_PROCESSES pInfo)
CurThread->ClientId.UniqueThread, CurThread->ClientId.UniqueThread,
Win32StartAddress, Win32StartAddress,
0 /* FIXME: ((PTEB) tInfo.TebBaseAddress)->LastErrorValue */, 0 /* FIXME: ((PTEB) tInfo.TebBaseAddress)->LastErrorValue */,
ThreadStateName[CurThread->State] ThreadStateName[CurThread->ThreadState]
); );
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
@ -326,10 +326,10 @@ int STDCALL PrintModules (VOID)
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
PSYSTEM_PROCESSES STDCALL PSYSTEM_PROCESS_INFORMATION STDCALL
GetProcessInfoPid ( GetProcessInfoPid (
PSYSTEM_PROCESSES pInfoBase, PSYSTEM_PROCESS_INFORMATION pInfoBase,
DWORD Pid HANDLE Pid
) )
{ {
if (NULL == pInfoBase) return NULL; if (NULL == pInfoBase) return NULL;
@ -338,7 +338,7 @@ GetProcessInfoPid (
while(pInfoBase) while(pInfoBase)
{ {
if (Pid == pInfoBase->ProcessId) if (Pid == pInfoBase->UniqueProcessId)
{ {
return pInfoBase; return pInfoBase;
} }
@ -375,8 +375,8 @@ int STDCALL PrintProcess (char * PidStr)
ULONG ReturnLength = 0; ULONG ReturnLength = 0;
PROCESS_BASIC_INFORMATION PsBasic; PROCESS_BASIC_INFORMATION PsBasic;
VM_COUNTERS PsVm; VM_COUNTERS PsVm;
PSYSTEM_PROCESSES pInfo = NULL; PSYSTEM_PROCESS_INFORMATION pInfo = NULL;
PSYSTEM_PROCESSES pInfoBase = NULL; PSYSTEM_PROCESS_INFORMATION pInfoBase = NULL;
LONG pInfoBaseLength = 0; LONG pInfoBaseLength = 0;
LPWSTR Module = L""; LPWSTR Module = L"";
LPWSTR Title = L""; LPWSTR Title = L"";
@ -407,7 +407,7 @@ int STDCALL PrintProcess (char * PidStr)
if (!NT_SUCCESS(PsaCaptureProcessesAndThreads (&pInfoBase))) if (!NT_SUCCESS(PsaCaptureProcessesAndThreads (&pInfoBase)))
return EXIT_FAILURE; return EXIT_FAILURE;
pInfo = GetProcessInfoPid (pInfoBase, (DWORD) ClientId.UniqueProcess); pInfo = GetProcessInfoPid (pInfoBase, ClientId.UniqueProcess);
if (NULL == pInfo) return EXIT_FAILURE; if (NULL == pInfo) return EXIT_FAILURE;
GetProcessInfo (pInfo, & Module, & Title); GetProcessInfo (pInfo, & Module, & Title);