Permalink
Browse files

Merge branch 'master' of https://github.com/cortesi/mitmproxy

  • Loading branch information...
2 parents 9d4cbeb + 09c29e8 commit 2bd4fb7513ad5629f9675ef0e09a01e4cf696924 @mhils committed Dec 4, 2012
View
@@ -48,7 +48,7 @@ We also have a mailing list, hosted here:
Requirements
------------
-* [Python](http://www.python.org) 2.6.x or 2.7.x.
+* [Python](http://www.python.org) 2.7.x.
* [PyOpenSSL](http://pypi.python.org/pypi/pyOpenSSL) 0.13 or newer.
* [pyasn1](http://pypi.python.org/pypi/pyasn1) 0.1.2 or newer.
* [urwid](http://excess.org/urwid/) version 0.9.8 or newer.
View
@@ -47,7 +47,7 @@ http://groups.google.com/group/mitmproxy
Requirements
------------
-* Python_ 2.6.x or 2.7.x.
+* Python_ 2.7.x.
* PyOpenSSL_ 0.13 or newer.
* pyasn1_ 0.1.2 or newer.
* urwid_ version 0.9.8 or newer.
@@ -431,7 +431,7 @@ def start_stream(self, path):
return str(v)
self.stream_path = path
-
+
def _run_script_method(self, method, s, f):
status, val = s.run(method, f)
if val:
@@ -1007,7 +1007,7 @@ def add_event(self, e, level="info"):
self.eventlist.append(e)
if len(self.eventlist) > EVENTLOG_SIZE:
self.eventlist.pop(0)
- self.eventlist.set_focus(len(self.eventlist))
+ self.eventlist.set_focus(len(self.eventlist)-1)
# Handlers
def handle_log(self, l):
@@ -1,7 +1,12 @@
import re, cStringIO, traceback, json
import urwid
-from PIL import Image
-from PIL.ExifTags import TAGS
+
+try: from PIL import Image
+except ImportError: import Image
+
+try: from PIL.ExifTags import TAGS
+except ImportError: from ExifTags import TAGS
+
import lxml.html, lxml.etree
import netlib.utils
import common
@@ -10,11 +15,10 @@
try:
import pyamf
- from pyamf import remoting
+ from pyamf import remoting, flex
except ImportError: # pragma nocover
pyamf = None
-
VIEW_CUTOFF = 1024*50
@@ -231,30 +235,75 @@ def __call__(self, hdrs, content, limit):
return "Multipart form", r
-class ViewAMF:
- name = "AMF"
- prompt = ("amf", "f")
- content_types = ["application/x-amf"]
- def __call__(self, hdrs, content, limit):
- envelope = remoting.decode(content)
- if not envelope:
- return None
-
- data = {}
- data['amfVersion'] = envelope.amfVersion
- for target, message in iter(envelope):
- one_message = {}
-
- if hasattr(message, 'status'):
- one_message['status'] = message.status
+if pyamf:
+ class DummyObject(dict):
+ def __init__(self, alias):
+ dict.__init__(self)
+
+ def __readamf__(self, input):
+ data = input.readObject()
+ self["data"] = data
+
+ def pyamf_class_loader(s):
+ for i in pyamf.CLASS_LOADERS:
+ if i != pyamf_class_loader:
+ v = i(s)
+ if v:
+ return v
+ return DummyObject
+
+ pyamf.register_class_loader(pyamf_class_loader)
+
+ class ViewAMF:
+ name = "AMF"
+ prompt = ("amf", "f")
+ content_types = ["application/x-amf"]
+
+ def unpack(self, b, seen=set([])):
+ if hasattr(b, "body"):
+ return self.unpack(b.body, seen)
+ if isinstance(b, DummyObject):
+ if id(b) in seen:
+ return "<recursion>"
+ else:
+ seen.add(id(b))
+ for k, v in b.items():
+ b[k] = self.unpack(v, seen)
+ return b
+ elif isinstance(b, dict):
+ for k, v in b.items():
+ b[k] = self.unpack(v, seen)
+ return b
+ elif isinstance(b, list):
+ return [self.unpack(i) for i in b]
+ elif isinstance(b, flex.ArrayCollection):
+ return [self.unpack(i, seen) for i in b]
+ else:
+ return b
+
+ def __call__(self, hdrs, content, limit):
+ envelope = remoting.decode(content, strict=False)
+ if not envelope:
+ return None
- if hasattr(message, 'target'):
- one_message['target'] = message.target
- one_message['body'] = message.body
- data[target] = one_message
- s = json.dumps(data, indent=4)
- return "AMF", _view_text(s[:limit], len(s), limit)
+ txt = []
+ for target, message in iter(envelope):
+ if isinstance(message, pyamf.remoting.Request):
+ txt.append(urwid.Text([
+ ("header", "Request: "),
+ ("text", str(target)),
+ ]))
+ else:
+ txt.append(urwid.Text([
+ ("header", "Response: "),
+ ("text", "%s, code %s"%(target, message.status)),
+ ]))
+
+ s = json.dumps(self.unpack(message), indent=4)
+ txt.extend(_view_text(s[:limit], len(s), limit))
+
+ return "AMF v%s"%envelope.amfVersion, txt
class ViewJavaScript:
@@ -74,13 +74,11 @@ def __init__(self, master):
]
)
self.master = master
- self.focus = 0
def keypress(self, size, key):
if key == "tab":
- self.focus = (self.focus + 1)%len(self.widget_list)
- self.set_focus(self.focus)
- if self.focus == 1:
+ self.focus_position = (self.focus_position + 1)%len(self.widget_list)
+ if self.focus_position == 1:
self.widget_list[1].header = self.active_header
else:
self.widget_list[1].header = self.inactive_header
@@ -102,12 +100,12 @@ def keypress(self, size, key):
class ConnectionItem(common.WWrap):
def __init__(self, master, state, flow, focus):
self.master, self.state, self.flow = master, state, flow
- self.focus = focus
+ self.f = focus
w = self.get_text()
common.WWrap.__init__(self, w)
def get_text(self):
- return common.format_flow(self.flow, self.focus)
+ return common.format_flow(self.flow, self.f)
def selectable(self):
return True
View
@@ -92,7 +92,7 @@ def findPackages(path, dataExclude=[]):
"Topic :: Internet :: Proxy Servers",
"Topic :: Software Development :: Testing"
],
- install_requires=["netlib", "urwid>=1.0", "pyasn1>0.1.2", "pyopenssl>=0.12", "PIL", "lxml"],
+ install_requires=["netlib", "urwid>=1.1", "pyasn1>0.1.2", "pyopenssl>=0.12", "PIL", "lxml"],
dependency_links=[
'https://github.com/cortesi/netlib/tarball/master#egg=netlib-0.1'
],
File renamed without changes.
View
Binary file not shown.
View
Binary file not shown.
@@ -3,6 +3,12 @@
from libmproxy import utils, flow, encoding
import tutils
+try:
+ import pyamf
+except ImportError:
+ pyamf = None
+
+
class TestContentView:
def test_trailer(self):
txt = []
@@ -119,15 +125,6 @@ def test_view_image(self):
assert not v([], "flibble", sys.maxint)
- def test_view_amf(self):
- try:
- import pyamf
- v = cv.ViewAMF()
- p = tutils.test_data.path("data/test.amf")
- assert v([], file(p).read(), sys.maxint)
- except ImportError:
- pass
-
def test_view_multipart(self):
view = cv.ViewMultipart()
v = """
@@ -220,5 +217,21 @@ def test_get_content_view(self):
assert "Raw" in r[0]
+if pyamf:
+ def test_view_amf_request():
+ v = cv.ViewAMF()
+
+ p = tutils.test_data.path("data/amf01")
+ assert v([], file(p).read(), sys.maxint)
+
+ p = tutils.test_data.path("data/amf02")
+ assert v([], file(p).read(), sys.maxint)
+
+ def test_view_amf_response():
+ v = cv.ViewAMF()
+ p = tutils.test_data.path("data/amf03")
+ assert v([], file(p).read(), sys.maxint)
+
+
def test_get_by_shortcut():
assert cv.get_by_shortcut("h")

0 comments on commit 2bd4fb7

Please sign in to comment.