mirror of https://github.com/n1nj4sec/pupy.git
pupyps: do not use as_dict without args (can crash process)
This commit is contained in:
parent
9e66080760
commit
712dc6dcde
|
@ -24,6 +24,19 @@ socktypes = {
|
|||
v:k[5:] for k,v in socket.__dict__.iteritems() if k.startswith('SOCK_')
|
||||
}
|
||||
|
||||
KNOWN_FIELDS = [
|
||||
'cmdline', 'connections', 'cpu_percent', 'cpu_times', 'create_time',
|
||||
'cwd', 'environ', 'exe', 'io_counters', 'memory_info',
|
||||
'memory_maps', 'memory_percent', 'name', 'nice', 'num_handles',
|
||||
'num_threads', 'open_files', 'pid', 'ppid', 'status', 'threads', 'username'
|
||||
]
|
||||
|
||||
if sys.platform.startswith('linux'):
|
||||
KNOWN_FIELDS.extend([
|
||||
'terminal', 'uids', 'gids', 'num_fds', 'ionice'
|
||||
])
|
||||
|
||||
|
||||
def to_unicode(x):
|
||||
tx = type(x)
|
||||
if tx == unicode:
|
||||
|
@ -35,9 +48,6 @@ def to_unicode(x):
|
|||
|
||||
def psinfo(pids):
|
||||
data = {}
|
||||
garbage = (
|
||||
'num_ctx_switches', 'memory_full_info', 'cpu_affinity'
|
||||
)
|
||||
|
||||
for pid in pids:
|
||||
try:
|
||||
|
@ -46,10 +56,7 @@ def psinfo(pids):
|
|||
continue
|
||||
|
||||
info = {}
|
||||
for key, val in process.as_dict().iteritems():
|
||||
if key in garbage:
|
||||
continue
|
||||
|
||||
for key, val in process.as_dict(KNOWN_FIELDS).iteritems():
|
||||
newv = None
|
||||
if type(val) == list:
|
||||
newv = []
|
||||
|
|
Loading…
Reference in New Issue