Bearsampp
2026.7.11
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
26
public
function
__construct
()
27
{
28
}
29
36
private
static
function
callWin32Ps
($function)
37
{
38
$result
=
false
;
39
40
if
(function_exists($function)) {
41
$result
= @call_user_func($function);
42
}
43
44
return
$result
;
45
}
46
52
public
static
function
getKeys
()
53
{
54
return
array(
55
self::NAME,
56
self::PROCESS_ID,
57
self::EXECUTABLE_PATH,
58
self::CAPTION,
59
self::COMMAND_LINE
60
);
61
}
62
68
public
static
function
getCurrentPid
()
69
{
70
$procInfo =
self::getStatProc
();
71
return
isset($procInfo[self::PROCESS_ID]) ? intval($procInfo[self::PROCESS_ID]) : 0;
72
}
73
79
public
static
function
getListProcs
()
80
{
81
$procs =
Win32Native::getProcessList
(self::getKeys());
82
83
// Filter out processes without ExecutablePath (same behavior as old VBS version)
84
if
($procs !==
false
&& is_array($procs)) {
85
$filtered = array();
86
foreach
($procs as
$proc
) {
87
if
(!empty(
$proc
[self::EXECUTABLE_PATH])) {
88
$filtered[] =
$proc
;
89
}
90
}
91
return
$filtered;
92
}
93
94
return
$procs;
95
}
96
102
public
static
function
getStatProc
()
103
{
104
$statProc =
self::callWin32Ps
(
'win32_ps_stat_proc'
);
105
106
if
($statProc !==
false
) {
107
return
array(
108
self::PROCESS_ID => $statProc[
'pid'
],
109
self::EXECUTABLE_PATH => $statProc[
'exe'
]
110
);
111
}
112
113
return
null
;
114
}
115
122
public
static
function
exists
($pid)
123
{
124
return
self::findByPid
($pid) !==
false
;
125
}
126
133
public
static
function
findByPid
($pid)
134
{
135
if
(!empty($pid)) {
136
$procs =
self::getListProcs
();
137
if
($procs !==
false
) {
138
foreach
($procs as
$proc
) {
139
if
(
$proc
[self::PROCESS_ID] == $pid) {
140
return
$proc
;
141
}
142
}
143
}
144
}
145
146
return
false
;
147
}
148
155
public
static
function
findByPath
($path)
156
{
157
$path =
Path::formatUnixPath
($path);
158
if
(!empty($path) && is_file($path)) {
159
$procs =
self::getListProcs
();
160
if
($procs !==
false
) {
161
foreach
($procs as
$proc
) {
162
$unixExePath =
Path::formatUnixPath
(
$proc
[self::EXECUTABLE_PATH]);
163
if
($unixExePath == $path) {
164
return
$proc
;
165
}
166
}
167
}
168
}
169
170
return
false
;
171
}
172
178
public
static
function
kill
($pid)
179
{
180
$pid = intval($pid);
181
if
(!empty($pid)) {
182
Win32Native::killProcess
($pid);
183
}
184
}
185
192
public
static
function
killBins
($refreshProcs =
false
)
193
{
194
global
$bearsamppRoot
;
195
$killed = array();
196
197
$procs =
$bearsamppRoot
->getProcs();
198
if
($refreshProcs || $procs ===
null
) {
199
$procs =
self::getListProcs
();
200
}
201
202
if
($procs !==
false
&& $procs !==
null
) {
203
foreach
($procs as
$proc
) {
204
$unixExePath =
Path::formatUnixPath
(
$proc
[self::EXECUTABLE_PATH]);
205
$unixCommandPath =
Path::formatUnixPath
(
$proc
[self::COMMAND_LINE]);
206
207
// Not kill current PID (PHP)
208
if
(
$proc
[self::PROCESS_ID] == self::getCurrentPid()) {
209
continue
;
210
}
211
212
// Not kill bearsampp
213
if
($unixExePath ==
Path::getExeFilePath
()) {
214
continue
;
215
}
216
217
// Not kill inside www
218
if
(
UtilString::startWith
($unixExePath,
Path::getWwwPath
() .
'/'
) ||
UtilString::contains
($unixCommandPath,
Path::getWwwPath
() .
'/'
)) {
219
continue
;
220
}
221
222
// Not kill external process
223
if
(!
UtilString::startWith
($unixExePath,
Path::getRootPath
() .
'/'
) && !
UtilString::contains
($unixCommandPath,
Path::getRootPath
() .
'/'
)) {
224
continue
;
225
}
226
227
self::kill
(
$proc
[self::PROCESS_ID]);
228
$killed[] =
$proc
;
229
}
230
}
231
232
return
$killed;
233
}
234
}
235
$result
$result
Definition
ajax.apache.php:19
$bearsamppRoot
global $bearsamppRoot
Definition
ajax.apache.php:16
$proc
$proc
Definition
ajax.php:45
Path\getExeFilePath
static getExeFilePath($aetrayPath=false)
Definition
class.path.php:450
Path\getRootPath
static getRootPath($aetrayPath=false)
Definition
class.path.php:309
Path\getWwwPath
static getWwwPath($aetrayPath=false)
Definition
class.path.php:1078
Path\formatUnixPath
static formatUnixPath($path)
Definition
class.path.php:156
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:85
Win32Native\killProcess
static killProcess($pid)
Definition
class.win32native.php:141
Win32Ps
Definition
class.win32ps.php:19
Win32Ps\__construct
__construct()
Definition
class.win32ps.php:26
Win32Ps\findByPid
static findByPid($pid)
Definition
class.win32ps.php:133
Win32Ps\findByPath
static findByPath($path)
Definition
class.win32ps.php:155
Win32Ps\NAME
const NAME
Definition
class.win32ps.php:20
Win32Ps\getStatProc
static getStatProc()
Definition
class.win32ps.php:102
Win32Ps\getCurrentPid
static getCurrentPid()
Definition
class.win32ps.php:68
Win32Ps\exists
static exists($pid)
Definition
class.win32ps.php:122
Win32Ps\COMMAND_LINE
const COMMAND_LINE
Definition
class.win32ps.php:24
Win32Ps\getListProcs
static getListProcs()
Definition
class.win32ps.php:79
Win32Ps\killBins
static killBins($refreshProcs=false)
Definition
class.win32ps.php:192
Win32Ps\kill
static kill($pid)
Definition
class.win32ps.php:178
Win32Ps\CAPTION
const CAPTION
Definition
class.win32ps.php:23
Win32Ps\callWin32Ps
static callWin32Ps($function)
Definition
class.win32ps.php:36
Win32Ps\EXECUTABLE_PATH
const EXECUTABLE_PATH
Definition
class.win32ps.php:22
Win32Ps\getKeys
static getKeys()
Definition
class.win32ps.php:52
Win32Ps\PROCESS_ID
const PROCESS_ID
Definition
class.win32ps.php:21
sandbox
core
classes
class.win32ps.php
Generated by
1.17.0