forked from yavfast/dbg-spider
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuProcessList.pas
128 lines (109 loc) · 3.07 KB
/
uProcessList.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
unit uProcessList;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, ExtCtrls, ActnList, StdCtrls, Buttons,
PlatformDefaultStyleActnCtrls, ActnMan, ActnCtrls, ToolWin, ComCtrls,
RibbonSilverStyleActnCtrls, System.Actions;
type
TfrmProcessList = class(TForm)
sgProcessList: TStringGrid;
AL: TActionList;
acOk: TAction;
acCancel: TAction;
acRefresh: TAction;
cbTop: TCoolBar;
actbTop: TActionToolBar;
pActions: TPanel;
btnAttach: TBitBtn;
btnCancel: TBitBtn;
acmgr1: TActionManager;
procedure acRefreshExecute(Sender: TObject);
procedure acOkExecute(Sender: TObject);
procedure acCancelExecute(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
function GetSelProcessID: DWORD;
function GetSelProcessName: String;
end;
var
frmProcessList: TfrmProcessList;
implementation
uses PsAPI, uShareData;
procedure GetProcessList(List: TStringList);
var
PIDArray: array [0..1023] of DWORD;
cb: DWORD;
I: Integer;
ProcCount: Integer;
hMod: HMODULE;
hProcess: THandle;
ProcessID: DWORD;
ModuleName: array [0..300] of Char;
begin
if List = nil then Exit;
if EnumProcesses(@PIDArray, SizeOf(PIDArray), cb) then
begin
ProcCount := cb div SizeOf(DWORD);
for I := 0 to ProcCount - 1 do
begin
ProcessID := PIDArray[I];
hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, False, ProcessID);
if (hProcess <> 0) then
begin
EnumProcessModules(hProcess, @hMod, SizeOf(hMod), cb);
GetModuleFilenameEx(hProcess, hMod, ModuleName, SizeOf(ModuleName));
List.AddObject(ModuleName, TObject(ProcessID));
CloseHandle(hProcess);
end;
end;
end;
end;
{$R *.dfm}
procedure TfrmProcessList.acCancelExecute(Sender: TObject);
begin
ModalResult := mrCancel;
end;
procedure TfrmProcessList.acOkExecute(Sender: TObject);
begin
ModalResult := mrOk;
end;
procedure TfrmProcessList.acRefreshExecute(Sender: TObject);
var
PL: TStringList;
I: Integer;
begin
PL := TStringList.Create;
try
GetProcessList(PL);
sgProcessList.RowCount := PL.Count + 1;
sgProcessList.Cells[0, 0] := 'Process name';
for I := 0 to PL.Count - 1 do
begin
sgProcessList.Cells[0, I + 1] := PL.Strings[I];
sgProcessList.Objects[0, I + 1] := PL.Objects[I];
end;
finally
FreeAndNil(PL);
end;
end;
procedure TfrmProcessList.FormCreate(Sender: TObject);
begin
actbTop.ParentBackground := True;
end;
procedure TfrmProcessList.FormShow(Sender: TObject);
begin
acRefresh.Execute;
end;
function TfrmProcessList.GetSelProcessID: DWORD;
begin
Result := DWORD(sgProcessList.Objects[sgProcessList.Col, sgProcessList.Row]);
end;
function TfrmProcessList.GetSelProcessName: String;
begin
Result := sgProcessList.Cells[sgProcessList.Col, sgProcessList.Row];
end;
end.