Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
pyrasite
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
pyrasite
Commits
d9c6da75
Commit
d9c6da75
authored
Mar 12, 2012
by
Luke Macken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pep8 all the things
parent
2f5c59ac
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
189 additions
and
120 deletions
+189
-120
pyrasite/inject.py
pyrasite/inject.py
+1
-0
pyrasite/inspect.py
pyrasite/inspect.py
+1
-0
pyrasite/ipc.py
pyrasite/ipc.py
+4
-1
pyrasite/main.py
pyrasite/main.py
+7
-3
pyrasite/reverse.py
pyrasite/reverse.py
+1
-0
pyrasite/tools/gui.py
pyrasite/tools/gui.py
+157
-105
pyrasite/tools/memory_viewer.py
pyrasite/tools/memory_viewer.py
+5
-3
pyrasite/utils.py
pyrasite/utils.py
+13
-8
No files found.
pyrasite/inject.py
View file @
d9c6da75
...
...
@@ -33,6 +33,7 @@ import warnings
from
utils
import
run
class
CodeInjector
(
object
):
"""Injects code into a running Python process"""
...
...
pyrasite/inspect.py
View file @
d9c6da75
...
...
@@ -17,6 +17,7 @@
from
utils
import
run
class
ObjectInspector
(
object
):
"""Inspects objects in a running Python program"""
...
...
pyrasite/ipc.py
View file @
d9c6da75
...
...
@@ -27,6 +27,7 @@ import pyrasite
from
os.path
import
dirname
,
abspath
,
join
class
PyrasiteIPC
(
object
):
"""Pyrasite Inter-Python Communication.
...
...
@@ -130,7 +131,9 @@ class PyrasiteIPC(object):
self
.
address
=
address
def
cmd
(
self
,
cmd
):
"""Send a python command to exec in the process and return the output"""
"""
Send a python command to exec in the process and return the output
"""
self
.
send
(
cmd
+
'
\
n
'
)
return
self
.
recv
()
...
...
pyrasite/main.py
View file @
d9c6da75
...
...
@@ -15,18 +15,21 @@
#
# Copyright (C) 2011 Red Hat, Inc.
import
os
,
sys
import
os
import
sys
import
argparse
from
inject
import
CodeInjector
from
utils
import
setup_logger
def
main
():
parser
=
argparse
.
ArgumentParser
(
description
=
'pyrasite - inject code into a running python process'
,
epilog
=
"For updates, visit https://github.com/lmacken/pyrasite"
)
parser
.
add_argument
(
'pid'
,
help
=
"The ID of the process to inject code into"
)
parser
.
add_argument
(
'pid'
,
help
=
"The ID of the process to inject code into"
)
parser
.
add_argument
(
'filename'
,
help
=
"The second argument must be a filename"
)
parser
.
add_argument
(
'--gdb-prefix'
,
dest
=
'gdb_prefix'
,
...
...
@@ -58,7 +61,8 @@ def main():
log
.
error
(
"Error: The second argument must be a filename"
)
sys
.
exit
(
4
)
injector
=
CodeInjector
(
pid
,
verbose
=
args
.
verbose
,
gdb_prefix
=
args
.
gdb_prefix
)
injector
=
CodeInjector
(
pid
,
verbose
=
args
.
verbose
,
gdb_prefix
=
args
.
gdb_prefix
)
injector
.
inject
(
filename
)
if
__name__
==
'__main__'
:
...
...
pyrasite/reverse.py
View file @
d9c6da75
...
...
@@ -26,6 +26,7 @@ import threading
from
StringIO
import
StringIO
from
pyrasite.ipc
import
PyrasiteIPC
class
ReverseConnection
(
threading
.
Thread
,
PyrasiteIPC
):
"""A payload that connects to a given host:port and receives commands"""
...
...
pyrasite/tools/gui.py
View file @
d9c6da75
This diff is collapsed.
Click to expand it.
pyrasite/tools/memory_viewer.py
View file @
d9c6da75
...
...
@@ -33,6 +33,7 @@ from meliae import loader
from
pyrasite.inspect
import
ObjectInspector
class
PyrasiteMemoryViewer
(
object
):
palette
=
[
(
'body'
,
'black'
,
'light gray'
,
'standout'
),
...
...
@@ -75,8 +76,9 @@ class PyrasiteMemoryViewer(object):
if
i
in
(
0
,
1
):
rb
=
self
.
create_disabled_radio_button
(
line
)
else
:
obj
=
self
.
summary
.
summaries
[
i
-
2
]
rb
=
self
.
create_radio_button
(
group
,
line
,
obj
,
self
.
display_object
)
obj
=
self
.
summary
.
summaries
[
i
-
2
]
rb
=
self
.
create_radio_button
(
group
,
line
,
obj
,
self
.
display_object
)
buttons
.
append
(
rb
)
return
buttons
...
...
@@ -107,7 +109,7 @@ class PyrasiteMemoryViewer(object):
w
=
urwid
.
Frame
(
header
=
bt
,
body
=
w
)
# Exit message
exit
=
urwid
.
BigText
((
'exit'
,
" Quit? "
),
urwid
.
Thin6x6Font
())
exit
=
urwid
.
BigText
((
'exit'
,
" Quit? "
),
urwid
.
Thin6x6Font
())
exit
=
urwid
.
Overlay
(
exit
,
w
,
'center'
,
None
,
'middle'
,
None
)
return
w
,
exit
...
...
pyrasite/utils.py
View file @
d9c6da75
...
...
@@ -2,14 +2,15 @@
from
__future__
import
division
def
humanize_bytes
(
bytes
,
precision
=
1
):
"""Return a humanized string representation of a number of bytes."""
abbrevs
=
(
(
1
<<
50L
,
'PB'
),
(
1
<<
40L
,
'TB'
),
(
1
<<
30L
,
'GB'
),
(
1
<<
20L
,
'MB'
),
(
1
<<
10L
,
'kB'
),
(
1
<<
50L
,
'PB'
),
(
1
<<
40L
,
'TB'
),
(
1
<<
30L
,
'GB'
),
(
1
<<
20L
,
'MB'
),
(
1
<<
10L
,
'kB'
),
(
1
,
'bytes'
)
)
if
bytes
==
1
:
...
...
@@ -40,6 +41,7 @@ def humanize_bytes(bytes, precision=1):
import
logging
import
subprocess
def
run
(
*
args
,
**
kwargs
):
"""Run a subprocess.
...
...
@@ -54,8 +56,10 @@ def run(*args, **kwargs):
:param args: arguments to be passed to :class:`subprocess.Popen`.
:param kwargs: keyword arguments to be passed to :class:`subprocess.Popen`.
:param communicate: if True, call :meth:`subprocess.Popen.communicate` after creating the subprocess.
:param executable: if present, the path to a program to execute instead of this script.
:param communicate: if True, call :meth:`subprocess.Popen.communicate`
after creating the subprocess.
:param executable: if present, the path to a program to execute instead of
this script.
"""
_kwargs
=
{
"stdin"
:
subprocess
.
PIPE
,
...
...
@@ -82,7 +86,8 @@ def setup_logger(verbose=False):
NullHandler
=
logging
.
NullHandler
except
AttributeError
:
class
NullHandler
(
logging
.
Handler
):
def
emit
(
self
,
record
):
pass
def
emit
(
self
,
record
):
pass
# Add a do-nothing NullHandler to the module logger to prevent "No handlers
# could be found" errors. The calling code can still add other, more useful
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment