better ps
This commit is contained in:
1 parent
325149006c
commit
c1a291c4c9
8 files changed
+228
-26
No files matched your search
@@ -10,6 +10,7 @@
|
||||
#include <kernel/ob_object.h>
|
||||
#include <kernel/ke_cpu.h>
|
||||
#include <kernel/hal/hal_apic.h>
|
||||
#include <ntlite/syscall.h>
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Global process list
|
||||
@@ -64,15 +65,86 @@ KSTATUS KeCreateSystemProcess(PROCESS** out) {
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
size_t KeCopyProcessIds(uint32_t* pidsOut, size_t maxCount) {
|
||||
static uint32_t KiCountProcessHandlesLocked(PROCESS* process) {
|
||||
uint32_t count = 0;
|
||||
if (!process) return 0;
|
||||
|
||||
for (uint32_t i = 1; i < HANDLE_TABLE_SIZE; i++) {
|
||||
if (process->Handles[i].Object) count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
static void KiCopyTruncatedString(char* dst, size_t dstSize, const char* src, size_t srcLen) {
|
||||
if (!dst || dstSize == 0) return;
|
||||
size_t n = 0;
|
||||
if (src) {
|
||||
while (n + 1 < dstSize && n < srcLen && src[n]) {
|
||||
dst[n] = src[n];
|
||||
n++;
|
||||
}
|
||||
}
|
||||
dst[n] = '\0';
|
||||
}
|
||||
|
||||
size_t KeCopyProcessInfo(struct SYS_PROCESS_INFO* infoOut, size_t maxCount) {
|
||||
KiProcessInit();
|
||||
|
||||
PROCESS* current = KeGetCurrentProcess();
|
||||
PROCESS* system = KeGetSystemProcess();
|
||||
|
||||
uintptr_t flags = KeAcquireSpinlock(&gProcessListLock);
|
||||
size_t count = 0;
|
||||
LIST_ENTRY* head = &gProcessList;
|
||||
for (LIST_ENTRY* node = head->Fwd; node != head; node = node->Fwd) {
|
||||
PROCESS* p = CONTAINING_RECORD(node, PROCESS, GlobalLink);
|
||||
if (pidsOut && count < maxCount) pidsOut[count] = p->ProcessId;
|
||||
if (infoOut && count < maxCount) {
|
||||
SYS_PROCESS_INFO* info = &infoOut[count];
|
||||
memset(info, 0, sizeof(*info));
|
||||
info->Size = sizeof(*info);
|
||||
info->ProcessId = p->ProcessId;
|
||||
info->ImageBase = p->ImageBase;
|
||||
info->ImageSize = p->ImageSize;
|
||||
info->PebBase = p->UserPebBase;
|
||||
info->ModuleCount = p->ModuleCount;
|
||||
|
||||
uintptr_t handleFlags = KeAcquireSpinlock(&p->HandleLock);
|
||||
uint32_t threadCount = p->ThreadCount;
|
||||
uint32_t handleCount = KiCountProcessHandlesLocked(p);
|
||||
int exitCode = p->ExitCode;
|
||||
long terminating = p->Terminating;
|
||||
long exited = p->Exited;
|
||||
KeReleaseSpinlock(&p->HandleLock, handleFlags);
|
||||
|
||||
info->ThreadCount = threadCount;
|
||||
info->HandleCount = handleCount;
|
||||
info->ExitCode = exitCode;
|
||||
|
||||
if (exited) {
|
||||
info->State = SYS_PROCESS_STATE_EXITED;
|
||||
info->Flags |= SYS_PROCESS_FLAG_EXITED;
|
||||
} else if (terminating) {
|
||||
info->State = SYS_PROCESS_STATE_TERMINATING;
|
||||
info->Flags |= SYS_PROCESS_FLAG_TERMINATING;
|
||||
} else {
|
||||
info->State = SYS_PROCESS_STATE_RUNNING;
|
||||
}
|
||||
|
||||
if (p == system) info->Flags |= SYS_PROCESS_FLAG_SYSTEM;
|
||||
if (p == current) info->Flags |= SYS_PROCESS_FLAG_CURRENT;
|
||||
|
||||
MmQueryProcessUserMemory(p, &info->UserRegionCount,
|
||||
&info->UserReservedBytes,
|
||||
&info->UserCommittedBytes);
|
||||
|
||||
KiCopyTruncatedString(info->Name, sizeof(info->Name), p->Name, sizeof(p->Name));
|
||||
|
||||
uintptr_t cwdFlags = KeAcquireSpinlock(&p->CwdLock);
|
||||
info->CurrentDrive = p->CurrentDrive;
|
||||
KiCopyTruncatedString(info->CurrentDirectory, sizeof(info->CurrentDirectory),
|
||||
p->CurrentDirectory, p->CurrentDirectoryLength);
|
||||
KeReleaseSpinlock(&p->CwdLock, cwdFlags);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
KeReleaseSpinlock(&gProcessListLock, flags);
|
||||
|
||||
Reference in new issue
Block a user