Bearsampp
2026.9.23
Toggle main menu visibility
Loading...
Searching...
No Matches
class.win32ps.php
Go to the documentation of this file.
1
<?php
2
/*
3
*
4
* * Copyright (c) 2022-2025 Bearsampp
5
* * License: GNU General Public License version 3 or later; see LICENSE.txt
6
* * Website: https://bearsampp.com
7
* * Github: https://github.com/Bearsampp
8
*
9
*/
10
18
class
Win32Ps
19
{
20
const
NAME
=
'Name'
;
21
const
PROCESS_ID
=
'ProcessID'
;
22
const
EXECUTABLE_PATH
=
'ExecutablePath'
;
23
const
CAPTION
=
'Caption'
;
24
const
COMMAND_LINE
=
'CommandLine'
;
25
29
public
function
__construct
()
30
{
31
}
32
40
private
static
function
callWin32Ps
($function)
41
{
42
$result
=
false
;
43
44
if
(function_exists($function)) {
45
$result
= @call_user_func($function);
46
}
47
48
return
$result
;
49
}
50
56
public
static
function
getKeys
()
57
{
58
return
array(
59
self::NAME,
60
self::PROCESS_ID,
61
self::EXECUTABLE_PATH,
62
self::CAPTION,
63
self::COMMAND_LINE
64
);
65
}
66
72
public
static
function
getCurrentPid
()
73
{
74
$procInfo =
self::getStatProc
();
75
76
return
isset($procInfo[self::PROCESS_ID]) ? intval($procInfo[self::PROCESS_ID]) : 0;
77
}
78
84
public
static
function
getListProcs
()
85
{
86
$procs =
Win32Native::getProcessList
(self::getKeys());
87
88
// Filter out processes without ExecutablePath (same behavior as old VBS version)
89
if
($procs !==
false
&& is_array($procs)) {
90
$filtered = array();
91
foreach
($procs as
$proc
) {
92
if
(!empty(
$proc
[self::EXECUTABLE_PATH])) {
93
$filtered[] =
$proc
;
94
}
95
}
96
97
return
$filtered;
98
}
99
100
return
$procs;
101
}
102
108
public
static
function
getStatProc
()
109
{
110
$statProc =
self::callWin32Ps
(
'win32_ps_stat_proc'
);
111
112
if
($statProc !==
false
) {
113
return
array(
114
self::PROCESS_ID => $statProc[
'pid'
],
115
self::EXECUTABLE_PATH => $statProc[
'exe'
]
116
);
117
}
118
119
return
null
;
120
}
121
129
public
static
function
exists
($pid)
130
{
131
return
self::findByPid
($pid) !==
false
;
132
}
133
141
public
static
function
findByPid
($pid)
142
{
143
if
(!empty($pid)) {
144
$procs =
self::getListProcs
();
145
if
($procs !==
false
) {
146
foreach
($procs as
$proc
) {
147
if
(
$proc
[self::PROCESS_ID] == $pid) {
148
return
$proc
;
149
}
150
}
151
}
152
}
153
154
return
false
;
155
}
156
164
public
static
function
findByPath
($path)
165
{
166
$path =
Path::formatUnixPath
($path);
167
if
(!empty($path) && is_file($path)) {
168
$procs =
self::getListProcs
();
169
if
($procs !==
false
) {
170
foreach
($procs as
$proc
) {
171
$unixExePath =
Path::formatUnixPath
(
$proc
[self::EXECUTABLE_PATH]);
172
if
($unixExePath == $path) {
173
return
$proc
;
174
}
175
}
176
}
177
}
178
179
return
false
;
180
}
181
187
public
static
function
kill
($pid)
188
{
189
$pid = intval($pid);
190
if
(!empty($pid)) {
191
Win32Native::killProcess
($pid);
192
}
193
}
194
202
public
static
function
killBins
($refreshProcs =
false
)
203
{
204
global
$bearsamppRoot
;
205
$killed = array();
206
207
$procs =
$bearsamppRoot
->getProcs();
208
if
($refreshProcs || $procs ===
null
) {
209
$procs =
self::getListProcs
();
210
}
211
212
if
($procs !==
false
&& $procs !==
null
) {
213
foreach
($procs as
$proc
) {
214
$unixExePath =
Path::formatUnixPath
(
$proc
[self::EXECUTABLE_PATH]);
215
$unixCommandPath =
Path::formatUnixPath
(
$proc
[self::COMMAND_LINE]);
216
217
// Not kill current PID (PHP)
218
if
(
$proc
[self::PROCESS_ID] == self::getCurrentPid()) {
219
continue
;
220
}
221
222
// Not kill bearsampp
223
if
($unixExePath ==
Path::getExeFilePath
()) {
224
continue
;
225
}
226
227
// Not kill inside www
228
if
(
UtilString::startWith
($unixExePath,
Path::getWwwPath
() .
'/'
) ||
UtilString::contains
($unixCommandPath,
Path::getWwwPath
() .
'/'
)) {
229
continue
;
230
}
231
232
// Not kill external process
233
if
(!
UtilString::startWith
($unixExePath,
Path::getRootPath
() .
'/'
) && !
UtilString::contains
($unixCommandPath,
Path::getRootPath
() .
'/'
)) {
234
continue
;
235
}
236
237
self::kill
(
$proc
[self::PROCESS_ID]);
238
$killed[] =
$proc
;
239
}
240
}
241
242
return
$killed;
243
}
244
}
245
$result
$result
Definition
ajax.apache.php:19
$bearsamppRoot
global $bearsamppRoot
Definition
ajax.apache.php:16
$proc
$proc
Definition
ajax.php:130
Path\getExeFilePath
static getExeFilePath($aetrayPath=false)
Definition
class.path.php:475
Path\getRootPath
static getRootPath($aetrayPath=false)
Definition
class.path.php:324
Path\getWwwPath
static getWwwPath($aetrayPath=false)
Definition
class.path.php:1254
Path\formatUnixPath
static formatUnixPath($path)
Definition
class.path.php:166
UtilString\contains
static contains($string, $search)
Definition
class.util.string.php:36
UtilString\startWith
static startWith($string, $search)
Definition
class.util.string.php:53
Win32Native\getProcessList
static getProcessList($properties=[])
Definition
class.win32native.php:97
Win32Native\killProcess
static killProcess($pid)
Definition
class.win32native.php:154
Win32Ps
Definition
class.win32ps.php:19
Win32Ps\__construct
__construct()
Definition
class.win32ps.php:29
Win32Ps\findByPid
static findByPid($pid)
Definition
class.win32ps.php:141
Win32Ps\findByPath
static findByPath($path)
Definition
class.win32ps.php:164
Win32Ps\NAME
const NAME
Definition
class.win32ps.php:20
Win32Ps\getStatProc
static getStatProc()
Definition
class.win32ps.php:108
Win32Ps\getCurrentPid
static getCurrentPid()
Definition
class.win32ps.php:72
Win32Ps\exists
static exists($pid)
Definition
class.win32ps.php:129
Win32Ps\COMMAND_LINE
const COMMAND_LINE
Definition
class.win32ps.php:24
Win32Ps\getListProcs
static getListProcs()
Definition
class.win32ps.php:84
Win32Ps\killBins
static killBins($refreshProcs=false)
Definition
class.win32ps.php:202
Win32Ps\kill
static kill($pid)
Definition
class.win32ps.php:187
Win32Ps\CAPTION
const CAPTION
Definition
class.win32ps.php:23
Win32Ps\callWin32Ps
static callWin32Ps($function)
Definition
class.win32ps.php:40
Win32Ps\EXECUTABLE_PATH
const EXECUTABLE_PATH
Definition
class.win32ps.php:22
Win32Ps\getKeys
static getKeys()
Definition
class.win32ps.php:56
Win32Ps\PROCESS_ID
const PROCESS_ID
Definition
class.win32ps.php:21
sandbox
core
classes
class.win32ps.php
Generated by
1.17.0