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
d5d36028
Commit
d5d36028
authored
Jun 27, 2013
by
Luke Macken
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' of
ssh://github.com/lmacken/pyrasite
into develop
parents
a57b1736
9204781a
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
147 additions
and
27 deletions
+147
-27
.coveragerc
.coveragerc
+11
-0
.travis.yml
.travis.yml
+14
-4
README.rst
README.rst
+9
-0
pyrasite/inspector.py
pyrasite/inspector.py
+5
-1
pyrasite/tests/test_cli.py
pyrasite/tests/test_cli.py
+84
-0
pyrasite/tests/test_code_injection.py
pyrasite/tests/test_code_injection.py
+2
-4
pyrasite/tests/test_ipc.py
pyrasite/tests/test_ipc.py
+8
-7
pyrasite/tests/utils.py
pyrasite/tests/utils.py
+0
-5
pyrasite/tools/memory_viewer.py
pyrasite/tools/memory_viewer.py
+11
-0
setup.py
setup.py
+0
-3
tox.ini
tox.ini
+3
-3
No files found.
.coveragerc
0 → 100644
View file @
d5d36028
[run]
source = pyrasite
omit =
pyrasite/payloads/*
pyrasite/tools/*
[report]
exclude_lines =
pragma: no cover
def __repr__
if __name__ == .__main__.:
.travis.yml
View file @
d5d36028
language
:
python
python
:
-
2.5
-
2.6
-
2.7
-
3.2
-
3.3
install
:
python setup.py install
install
:
-
sudo apt-get install -qq gdb python${TRAVIS_PYTHON_VERSION}-dbg
-
python setup.py install
-
if [[ $TRAVIS_PYTHON_VERSION != '2.5' ]]; then pip install coveralls --use-mirrors && export HAS_COVERALLS=1; fi
script
:
-
pip install --use-mirrors unittest2
-
sudo apt-get install gdb
-
sudo unit2 discover
-
nosetests -q --with-coverage --cover-erase --cover-package=pyrasite
after_success
:
-
if [[ $HAS_COVERALLS ]]; then coveralls; fi
notifications
:
irc
:
"
chat.freenode.net#pyrasite"
README.rst
View file @
d5d36028
pyrasite
========
.. image:: https://api.travis-ci.org/lmacken/pyrasite.png?branch=develop
:target: http://travis-ci.org/lmacken/pyrasite
.. image:: https://coveralls.io/repos/lmacken/pyrasite/badge.png?branch=develop
:target: https://coveralls.io/r/lmacken/pyrasite
.. image:: https://pypip.in/v/pyrasite/badge.png
:target: https://crate.io/packages/pyrasite
.. image:: https://pypip.in/d/pyrasite/badge.png
:target: https://crate.io/packages/pyrasite
.. split here
Tools for injecting arbitrary code into running Python processes.
...
...
pyrasite/inspector.py
View file @
d5d36028
...
...
@@ -15,8 +15,12 @@
#
# Copyright (C) 2011-2013 Red Hat, Inc., Luke Macken <lmacken@redhat.com>
import
sys
import
subprocess
encoding
=
sys
.
getdefaultencoding
()
def
inspect
(
pid
,
address
):
"Return the value of an object in a given process at the specified address"
cmd
=
' '
.
join
([
...
...
@@ -24,6 +28,6 @@ def inspect(pid, address):
'-eval-command="print (PyObject *)%s"'
%
address
,
])
p
=
subprocess
.
Popen
(
cmd
,
shell
=
True
,
stdout
=
subprocess
.
PIPE
)
for
line
in
p
.
communicate
()[
0
].
split
(
'
\
n
'
):
for
line
in
p
.
communicate
()[
0
].
decode
(
encoding
).
split
(
'
\
n
'
):
if
line
.
startswith
(
'$1 = '
):
return
line
[
5
:]
pyrasite/tests/test_cli.py
0 → 100644
View file @
d5d36028
# This file is part of pyrasite.
#
# pyrasite is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# pyrasite is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with pyrasite. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright (C) 2013 Red Hat, Inc., Luke Macken <lmacken@redhat.com>
import
os
import
sys
try
:
from
StringIO
import
StringIO
except
ImportError
:
from
io
import
StringIO
from
pyrasite.main
import
main
class
TestCLI
(
object
):
def
test_usage
(
self
):
sys
.
argv
=
[
'pyrasite'
]
try
:
main
()
except
SystemExit
:
exit_code
=
sys
.
exc_info
()[
1
].
code
assert
exit_code
==
1
,
exit_code
def
test_list_payloads
(
self
):
sys
.
argv
=
[
'pyrasite'
,
'-l'
]
stdout
=
sys
.
stdout
sys
.
stdout
=
StringIO
()
try
:
main
()
except
SystemExit
:
pass
value
=
sys
.
stdout
.
getvalue
()
sys
.
stdout
=
stdout
assert
'Available payloads:'
in
value
,
repr
(
value
)
assert
'helloworld.py'
in
value
,
repr
(
value
)
def
test_invalid_pid
(
self
):
sys
.
argv
=
[
'pyrasite'
,
'foo'
,
'bar'
]
stdout
=
sys
.
stdout
sys
.
stdout
=
StringIO
()
try
:
main
()
except
SystemExit
:
exit_code
=
sys
.
exc_info
()[
1
].
code
assert
exit_code
==
2
,
exit_code
value
=
sys
.
stdout
.
getvalue
()
sys
.
stdout
=
stdout
assert
'Error: The first argument must be a pid'
in
value
,
repr
(
value
)
def
test_invalid_payload
(
self
):
sys
.
argv
=
[
'pyrasite'
,
str
(
os
.
getpid
()),
'foo'
]
stdout
=
sys
.
stdout
sys
.
stdout
=
StringIO
()
try
:
main
()
except
SystemExit
:
exit_code
=
sys
.
exc_info
()[
1
].
code
assert
exit_code
==
3
,
exit_code
value
=
sys
.
stdout
.
getvalue
()
sys
.
stdout
=
stdout
assert
"Error: Invalid path or file doesn't exist"
in
value
,
repr
(
value
)
def
test_injection
(
self
):
sys
.
argv
=
[
'pyrasite'
,
str
(
os
.
getpid
()),
'helloworld.py'
]
stdout
=
sys
.
stdout
sys
.
stdout
=
StringIO
()
main
()
value
=
sys
.
stdout
.
getvalue
()
sys
.
stdout
=
stdout
assert
"Hello World!"
in
value
,
repr
(
value
)
pyrasite/tests/test_code_injection.py
View file @
d5d36028
...
...
@@ -22,10 +22,10 @@ import subprocess
import
pyrasite
from
pyrasite.tests.utils
import
generate_program
,
run_program
,
stop_program
,
\
interpreters
,
unittest
interpreters
class
TestCodeInjection
(
unittest
.
TestCase
):
class
TestCodeInjection
(
object
):
def
assert_output_contains
(
self
,
stdout
,
stderr
,
text
):
assert
text
in
str
(
stdout
),
\
...
...
@@ -81,5 +81,3 @@ class TestCodeInjection(unittest.TestCase):
finally
:
os
.
unlink
(
program
)
if
__name__
==
'__main__'
:
unittest
.
main
()
pyrasite/tests/test_ipc.py
View file @
d5d36028
...
...
@@ -18,11 +18,13 @@
import
os
import
sys
from
nose.plugins.skip
import
SkipTest
import
pyrasite
from
pyrasite.tests.utils
import
run_program
,
generate_program
,
stop_program
,
unittest
from
pyrasite.tests.utils
import
run_program
,
generate_program
,
stop_program
class
TestIPCContextManager
(
unittest
.
TestCase
):
class
TestIPCContextManager
(
object
):
def
setUp
(
self
):
self
.
prog
=
generate_program
()
...
...
@@ -37,7 +39,7 @@ class TestIPCContextManager(unittest.TestCase):
info
=
sys
.
version_info
major
,
minor
=
info
[
0
],
info
[
1
]
if
major
<=
2
and
minor
<=
5
:
self
.
s
kipTest
(
"Context Managers not supported on Python<=2.5"
)
raise
S
kipTest
(
"Context Managers not supported on Python<=2.5"
)
# Otherwise import a module which contains modern syntax.
# It really contains our test case, but we have pushed it out into
...
...
@@ -46,7 +48,7 @@ class TestIPCContextManager(unittest.TestCase):
pyrasite
.
tests
.
context_manager_case
.
context_manager_business
(
self
)
class
TestIPC
(
unittest
.
TestCase
):
class
TestIPC
(
object
):
def
setUp
(
self
):
self
.
prog
=
generate_program
()
...
...
@@ -91,6 +93,5 @@ class TestIPC(unittest.TestCase):
def
test_repr
(
self
):
assert
repr
(
self
.
ipc
)
if
__name__
==
'__main__'
:
unittest
.
main
()
def
test_title
(
self
):
assert
self
.
ipc
.
title
pyrasite/tests/utils.py
View file @
d5d36028
...
...
@@ -22,11 +22,6 @@ import time
import
textwrap
import
tempfile
import
subprocess
import
unittest
if
sys
.
version_info
[
0
]
==
2
:
if
sys
.
version_info
[
1
]
<
7
:
import
unittest2
as
unittest
def
generate_program
(
threads
=
1
):
...
...
pyrasite/tools/memory_viewer.py
View file @
d5d36028
...
...
@@ -24,6 +24,8 @@ the value of the object itself.
__version__
=
'1.0'
import
os
import
re
import
sys
import
urwid
import
urwid.raw_display
...
...
@@ -147,6 +149,15 @@ def main():
pyrasite
.
inject
(
pid
,
payload
)
filename
=
'/tmp/pyrasite-%d-objects.json'
%
pid
# Work around bug caused by meliae dumping unicode strings:
# https://bugs.launchpad.net/meliae/+bug/876810
with
open
(
filename
)
as
sample_file
,
open
(
filename
+
'.tmp'
,
'w'
)
as
output_file
:
pattern
=
re
.
compile
(
r"(?<!\\)\\u([dD][0-9a-fA-F]{3,3})"
)
for
line
in
sample_file
:
output_file
.
write
(
pattern
.
sub
(
"#S
\
g<
1
>"
,
line
))
os
.
rename
(
filename
+
'.tmp'
,
filename
)
objects
=
loader
.
load
(
filename
)
objects
.
compute_referrers
()
...
...
setup.py
View file @
d5d36028
...
...
@@ -26,9 +26,6 @@ elif sys.version_info[0] == 2:
requirements
.
append
(
'argparse'
)
tests_require
=
[
'nose'
]
if
sys
.
version_info
[
0
]
==
2
:
if
sys
.
version_info
[
1
]
<
7
:
tests_require
.
append
(
'unittest2'
)
class
build_py
(
_build_py
):
def
run
(
self
):
...
...
tox.ini
View file @
d5d36028
...
...
@@ -4,8 +4,8 @@
# and then run "tox" from this directory.
[tox]
envlist
=
py26, py27
envlist
=
py26, py27
, py33
[testenv]
commands
=
sudo {envbindir}/unit2 discover
deps
=
unittest2
commands
=
nosetests
deps
=
nose
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