diff options
author | Aldo Cortesi <aldo@corte.si> | 2013-04-19 17:18:44 -0700 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2013-04-19 17:18:44 -0700 |
commit | 793c41a5c475411df0ce8e24adec2219b6909934 (patch) | |
tree | 657c21b37890936a2d318cf00e960622d1d9d38c /libmproxy/console/contentview.py | |
parent | 7c4c6f5912a826efd83dec696b48ce1d9d1496ae (diff) | |
parent | d4cfbbb822f786b7e1f0ab9282dd76ee04ccb178 (diff) | |
download | mitmproxy-793c41a5c475411df0ce8e24adec2219b6909934.tar.gz mitmproxy-793c41a5c475411df0ce8e24adec2219b6909934.tar.bz2 mitmproxy-793c41a5c475411df0ce8e24adec2219b6909934.zip |
Merge pull request #112 from hamstah/protobuf-view
Adds a new view for protocol buffers
Diffstat (limited to 'libmproxy/console/contentview.py')
-rw-r--r-- | libmproxy/console/contentview.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/libmproxy/console/contentview.py b/libmproxy/console/contentview.py index 06710d2c..53841c73 100644 --- a/libmproxy/console/contentview.py +++ b/libmproxy/console/contentview.py @@ -12,7 +12,7 @@ import netlib.utils import common from .. import utils, encoding, flow from ..contrib import jsbeautifier, html2text - +import subprocess try: import pyamf from pyamf import remoting, flex @@ -364,6 +364,38 @@ class ViewImage: ) return "%s image"%img.format, fmt +class ViewProtobuf: + """Human friendly view of protocol buffers + The view uses the protoc compiler to decode the binary + """ + + name = "Protocol Buffer" + prompt = ("protobuf", "p") + content_types = ["application/x-protobuf"] + + @staticmethod + def is_available(): + try: + p = subprocess.Popen(["protoc", "--version"], stdout=subprocess.PIPE) + out, _ = p.communicate() + return out.startswith("libprotoc") + except: + return False + + def decode_protobuf(self, content): + # if Popen raises OSError, it will be caught in + # get_content_view and fall back to Raw + p = subprocess.Popen(['protoc', '--decode_raw'], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + out, _ = p.communicate(input=content) + return out + + def __call__(self, hdrs, content, limit): + decoded = self.decode_protobuf(content) + txt = _view_text(decoded[:limit], len(decoded), limit) + return "Protobuf", txt views = [ ViewAuto(), @@ -381,6 +413,9 @@ views = [ if pyamf: views.append(ViewAMF()) +if ViewProtobuf.is_available(): + views.append(ViewProtobuf()) + content_types_map = {} for i in views: for ct in i.content_types: |