process enumeration and list view items work

git-svn-id: svn://svn.code.sf.net/p/processhacker/code@2315 21ef857c-d57f-4fe0-8362-d861dc6d29cd
This commit is contained in:
wj32
2009-10-25 11:30:46 +00:00
parent 4dd74a9b0e
commit 1fda267dc5
8 changed files with 130 additions and 7 deletions
@@ -362,6 +362,10 @@
RelativePath=".\ntimport.c"
>
</File>
<File
RelativePath=".\process.c"
>
</File>
<File
RelativePath=".\support.c"
>
+16
View File
@@ -42,6 +42,22 @@ INT PhAddListViewColumn(
return ListView_InsertColumn(ListViewHandle, Index, &column);
}
INT PhAddListViewItem(
HWND ListViewHandle,
INT Index,
PWSTR Text
)
{
LVITEM item;
item.mask = LVIF_TEXT;
item.iItem = Index;
item.iSubItem = 0;
item.pszText = Text;
return ListView_InsertItem(ListViewHandle, &item);
}
HWND PhCreateTabControl(
HWND ParentHandle
)
+11
View File
@@ -4,6 +4,17 @@
#include <phbase.h>
#include <stdarg.h>
// process
typedef BOOLEAN (*PPH_ENUM_PROCESSES_CALLBACK)(
__in PSYSTEM_PROCESS_INFORMATION Process
);
NTSTATUS PhEnumProcesses(
__in PPH_ENUM_PROCESSES_CALLBACK Callback,
__out_opt PBOOLEAN Found
);
// support
PVOID PhAllocate(
+6
View File
@@ -65,6 +65,12 @@ INT PhAddListViewColumn(
PWSTR Text
);
INT PhAddListViewItem(
HWND ListViewHandle,
INT Index,
PWSTR Text
);
// Tab Controls
HWND PhCreateTabControl(
+23 -4
View File
@@ -103,6 +103,24 @@ LRESULT CALLBACK PhMainWndProc(
return 0;
}
BOOLEAN ProcessEnumCallback(PSYSTEM_PROCESS_INFORMATION Process)
{
PWSTR buffer;
// LEAK
buffer = PhAllocate(Process->ImageName.Length + sizeof(WCHAR));
memcpy(buffer, Process->ImageName.Buffer, Process->ImageName.Length);
buffer[Process->ImageName.Length / sizeof(WCHAR)] = 0;
PhAddListViewItem(
ProcessListViewHandle,
MAXINT,
buffer
);
return FALSE;
}
VOID PhMainWndOnCreate()
{
TabControlHandle = PhCreateTabControl(PhMainWndHandle);
@@ -111,11 +129,11 @@ VOID PhMainWndOnCreate()
NetworkTabIndex = PhAddTabControlTab(TabControlHandle, 2, L"Network");
ProcessListViewHandle = PhCreateListViewControl(PhMainWndHandle, ID_MAINWND_PROCESSLV);
ListView_SetExtendedListViewStyleEx(ProcessListViewHandle, LVS_EX_DOUBLEBUFFER, LVS_EX_DOUBLEBUFFER);
ListView_SetExtendedListViewStyleEx(ProcessListViewHandle, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER, -1);
ServiceListViewHandle = PhCreateListViewControl(PhMainWndHandle, ID_MAINWND_SERVICELV);
ListView_SetExtendedListViewStyleEx(ServiceListViewHandle, LVS_EX_DOUBLEBUFFER, LVS_EX_DOUBLEBUFFER);
ListView_SetExtendedListViewStyleEx(ServiceListViewHandle, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER, -1);
NetworkListViewHandle = PhCreateListViewControl(PhMainWndHandle, ID_MAINWND_NETWORKLV);
ListView_SetExtendedListViewStyleEx(NetworkListViewHandle, LVS_EX_DOUBLEBUFFER, LVS_EX_DOUBLEBUFFER);
ListView_SetExtendedListViewStyleEx(NetworkListViewHandle, LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER, -1);
PhAddListViewColumn(
ProcessListViewHandle,
@@ -144,12 +162,13 @@ VOID PhMainWndOnCreate()
100,
L"Process Name"
);
PhEnumProcesses(ProcessEnumCallback, NULL);
}
VOID PhMainWndOnLayout()
{
RECT rect;
INT selectedIndex;
// Resize the tab control.
GetClientRect(PhMainWndHandle, &rect);
+2
View File
@@ -39,4 +39,6 @@ BOOLEAN PhInitializeImports()
InitProcReq("ntdll.dll", NtSuspendThread);
InitProcReq("ntdll.dll", NtTerminateProcess);
InitProcReq("ntdll.dll", NtTerminateThread);
return TRUE;
}
+65
View File
@@ -0,0 +1,65 @@
#include <ph.h>
NTSTATUS PhEnumProcesses(
__in PPH_ENUM_PROCESSES_CALLBACK Callback,
__out_opt PBOOLEAN Found
)
{
NTSTATUS status;
PVOID buffer;
ULONG bufferSize = 2048;
PSYSTEM_PROCESS_INFORMATION procInfo;
buffer = PhAllocate(bufferSize);
while (TRUE)
{
if (!buffer)
return STATUS_INSUFFICIENT_RESOURCES;
status = NtQuerySystemInformation(
SystemProcessInformation,
buffer,
bufferSize,
&bufferSize
);
if (NT_SUCCESS(status))
break;
if (status == STATUS_BUFFER_TOO_SMALL || status == STATUS_INFO_LENGTH_MISMATCH)
{
PhFree(buffer);
buffer = PhAllocate(bufferSize);
}
else
{
return status;
}
}
procInfo = (PSYSTEM_PROCESS_INFORMATION)buffer;
while (TRUE)
{
if (Callback(procInfo))
{
if (Found)
*Found = TRUE;
return STATUS_SUCCESS;
}
if (procInfo->NextEntryOffset == 0)
break;
procInfo = (PSYSTEM_PROCESS_INFORMATION)((PCHAR)procInfo + procInfo->NextEntryOffset);
}
PhFree(buffer);
if (Found)
*Found = FALSE;
return STATUS_SUCCESS;
}
+3 -3
View File
@@ -1,21 +1,21 @@
#include <phgui.h>
#include <wchar.h>
PVOID FORCEINLINE PhAllocate(
PVOID PhAllocate(
__in SIZE_T Size
)
{
return HeapAlloc(PhHeapHandle, 0, Size);
}
VOID FORCEINLINE PhFree(
VOID PhFree(
__in PVOID Memory
)
{
HeapFree(PhHeapHandle, 0, Memory);
}
PVOID FORCEINLINE PhReAlloc(
PVOID PhReAlloc(
__in PVOID Memory,
__in SIZE_T Size
)