mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-25 18:03:50 +00:00
commit
94a7e99fda
@ -85,7 +85,7 @@ libraries. This was tested on a fully patched installation of Ubuntu 16.04.
|
||||
|
||||
.. code:: bash
|
||||
|
||||
sudo apt-get install python3-pip python3-dev libffi-dev libssl-dev libtiff5-dev libjpeg8-dev zlib1g-dev libwebp-dev
|
||||
sudo apt-get install python3-dev python3-pip libffi-dev libssl-dev
|
||||
sudo pip3 install mitmproxy # or pip3 install --user mitmproxy
|
||||
|
||||
On older Ubuntu versions, e.g., **12.04** and **14.04**, you may need to install
|
||||
@ -104,7 +104,7 @@ libraries. This was tested on a fully patched installation of Fedora 24.
|
||||
|
||||
.. code:: bash
|
||||
|
||||
sudo dnf install make gcc redhat-rpm-config python3-pip python3-devel libffi-devel openssl-devel libtiff-devel libjpeg-devel zlib-devel libwebp-devel openjpeg2-devel
|
||||
sudo dnf install make gcc redhat-rpm-config python3-devel python3-pip libffi-devel openssl-devel
|
||||
sudo pip3 install mitmproxy # or pip3 install --user mitmproxy
|
||||
|
||||
Make sure to have an up-to-date version of pip by running ``pip3 install -U pip``.
|
||||
|
@ -18,6 +18,8 @@ class ViewAuto(base.View):
|
||||
return contentviews.content_types_map[ct][0](data, **metadata)
|
||||
elif strutils.is_xml(data):
|
||||
return contentviews.get("XML/HTML")(data, **metadata)
|
||||
elif ct.startswith("image/"):
|
||||
return contentviews.get("Image")(data, **metadata)
|
||||
if metadata.get("query"):
|
||||
return contentviews.get("Query")(data, **metadata)
|
||||
if data and strutils.is_mostly_bin(data):
|
||||
|
@ -1 +1,3 @@
|
||||
from .view import ViewImage # noqa
|
||||
from .view import ViewImage
|
||||
|
||||
__all__ = ["ViewImage"]
|
||||
|
@ -13,9 +13,9 @@ Metadata = typing.List[typing.Tuple[str, str]]
|
||||
def parse_png(data: bytes) -> Metadata:
|
||||
img = png.Png(KaitaiStream(io.BytesIO(data)))
|
||||
parts = [
|
||||
('Format', 'Portable network graphics')
|
||||
('Format', 'Portable network graphics'),
|
||||
('Size', "{0} x {1} px".format(img.ihdr.width, img.ihdr.height))
|
||||
]
|
||||
parts.append(('Size', "{0} x {1} px".format(img.ihdr.width, img.ihdr.height)))
|
||||
for chunk in img.chunks:
|
||||
if chunk.type == 'gAMA':
|
||||
parts.append(('gamma', str(chunk.body.gamma_int / 100000)))
|
||||
@ -34,13 +34,13 @@ def parse_png(data: bytes) -> Metadata:
|
||||
|
||||
def parse_gif(data: bytes) -> Metadata:
|
||||
img = gif.Gif(KaitaiStream(io.BytesIO(data)))
|
||||
parts = [
|
||||
('Format', 'Compuserve GIF')
|
||||
]
|
||||
parts.append(('version', "GIF{0}".format(img.header.version.decode('ASCII'))))
|
||||
descriptor = img.logical_screen_descriptor
|
||||
parts.append(('Size', "{0} x {1} px".format(descriptor.screen_width, descriptor.screen_height)))
|
||||
parts.append(('background', str(descriptor.bg_color_index)))
|
||||
parts = [
|
||||
('Format', 'Compuserve GIF'),
|
||||
('Version', "GIF{}".format(img.header.version.decode('ASCII'))),
|
||||
('Size', "{} x {} px".format(descriptor.screen_width, descriptor.screen_height)),
|
||||
('background', str(descriptor.bg_color_index))
|
||||
]
|
||||
ext_blocks = []
|
||||
for block in img.blocks:
|
||||
if block.block_type.name == 'extension':
|
||||
|
@ -1,55 +1,38 @@
|
||||
import io
|
||||
import imghdr
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from mitmproxy.contentviews import base
|
||||
from mitmproxy.types import multidict
|
||||
from . import image_parser
|
||||
|
||||
from mitmproxy.contentviews import base
|
||||
|
||||
|
||||
class ViewImage(base.View):
|
||||
name = "Image"
|
||||
prompt = ("image", "i")
|
||||
|
||||
# there is also a fallback in the auto view for image/*.
|
||||
content_types = [
|
||||
"image/png",
|
||||
"image/jpeg",
|
||||
"image/gif",
|
||||
"image/vnd.microsoft.icon",
|
||||
"image/x-icon",
|
||||
"image/webp",
|
||||
]
|
||||
|
||||
def __call__(self, data, **metadata):
|
||||
image_type = imghdr.what('', h=data)
|
||||
if image_type == 'png':
|
||||
f = "PNG"
|
||||
parts = image_parser.parse_png(data)
|
||||
fmt = base.format_dict(multidict.MultiDict(parts))
|
||||
return "%s image" % f, fmt
|
||||
image_metadata = image_parser.parse_png(data)
|
||||
elif image_type == 'gif':
|
||||
f = "GIF"
|
||||
parts = image_parser.parse_gif(data)
|
||||
fmt = base.format_dict(multidict.MultiDict(parts))
|
||||
return "%s image" % f, fmt
|
||||
image_metadata = image_parser.parse_gif(data)
|
||||
elif image_type == 'jpeg':
|
||||
f = "JPEG"
|
||||
parts = image_parser.parse_jpeg(data)
|
||||
fmt = base.format_dict(multidict.MultiDict(parts))
|
||||
return "%s image" % f, fmt
|
||||
try:
|
||||
img = Image.open(io.BytesIO(data))
|
||||
except IOError:
|
||||
return None
|
||||
parts = [
|
||||
("Format", str(img.format_description)),
|
||||
("Size", "%s x %s px" % img.size),
|
||||
("Mode", str(img.mode)),
|
||||
]
|
||||
for i in sorted(img.info.keys()):
|
||||
if i != "exif":
|
||||
parts.append(
|
||||
(str(i), str(img.info[i]))
|
||||
)
|
||||
fmt = base.format_dict(multidict.MultiDict(parts))
|
||||
return "%s image" % img.format, fmt
|
||||
image_metadata = image_parser.parse_jpeg(data)
|
||||
else:
|
||||
image_metadata = [
|
||||
("Image Format", image_type or "unknown")
|
||||
]
|
||||
if image_type:
|
||||
view_name = "{} Image".format(image_type.upper())
|
||||
else:
|
||||
view_name = "Unknown Image"
|
||||
return view_name, base.format_dict(multidict.MultiDict(image_metadata))
|
||||
|
2
setup.py
2
setup.py
@ -71,7 +71,6 @@ setup(
|
||||
"hyperframe>=4.0.1, <5",
|
||||
"jsbeautifier>=1.6.3, <1.7",
|
||||
"kaitaistruct>=0.6, <0.7",
|
||||
"Pillow>=3.2, <4.1",
|
||||
"passlib>=1.6.5, <1.8",
|
||||
"pyasn1>=0.1.9, <0.3",
|
||||
"pyOpenSSL>=16.0, <17.0",
|
||||
@ -118,6 +117,7 @@ setup(
|
||||
'examples': [
|
||||
"beautifulsoup4>=4.4.1, <4.6",
|
||||
"pytz>=2015.07.0, <=2016.10",
|
||||
"Pillow>=3.2, <4.1",
|
||||
]
|
||||
}
|
||||
)
|
||||
|
@ -3,5 +3,4 @@ import logging
|
||||
logging.getLogger("hyper").setLevel(logging.WARNING)
|
||||
logging.getLogger("requests").setLevel(logging.WARNING)
|
||||
logging.getLogger("passlib").setLevel(logging.WARNING)
|
||||
logging.getLogger("PIL").setLevel(logging.WARNING)
|
||||
logging.getLogger("tornado").setLevel(logging.WARNING)
|
||||
|
@ -80,7 +80,7 @@ def test_parse_png(filename, metadata):
|
||||
# check comment
|
||||
"mitmproxy/data/image_parser/hopper.gif": [
|
||||
('Format', 'Compuserve GIF'),
|
||||
('version', 'GIF89a'),
|
||||
('Version', 'GIF89a'),
|
||||
('Size', '128 x 128 px'),
|
||||
('background', '0'),
|
||||
('comment', "b'File written by Adobe Photoshop\\xa8 4.0'")
|
||||
@ -88,7 +88,7 @@ def test_parse_png(filename, metadata):
|
||||
# check background
|
||||
"mitmproxy/data/image_parser/chi.gif": [
|
||||
('Format', 'Compuserve GIF'),
|
||||
('version', 'GIF89a'),
|
||||
('Version', 'GIF89a'),
|
||||
('Size', '320 x 240 px'),
|
||||
('background', '248'),
|
||||
('comment', "b'Created with GIMP'")
|
||||
@ -96,7 +96,7 @@ def test_parse_png(filename, metadata):
|
||||
# check working with color table
|
||||
"mitmproxy/data/image_parser/iss634.gif": [
|
||||
('Format', 'Compuserve GIF'),
|
||||
('version', 'GIF89a'),
|
||||
('Version', 'GIF89a'),
|
||||
('Size', '245 x 245 px'),
|
||||
('background', '0')
|
||||
],
|
||||
|
@ -9,9 +9,11 @@ def test_view_image():
|
||||
"mitmproxy/data/image.png",
|
||||
"mitmproxy/data/image.gif",
|
||||
"mitmproxy/data/all.jpeg",
|
||||
"mitmproxy/data/image.ico"
|
||||
# https://bugs.python.org/issue21574
|
||||
# "mitmproxy/data/image.ico",
|
||||
]:
|
||||
with open(tutils.test_data.path(img), "rb") as f:
|
||||
assert v(f.read())
|
||||
viewname, lines = v(f.read())
|
||||
assert img.split(".")[-1].upper() in viewname
|
||||
|
||||
assert not v(b"flibble")
|
||||
assert v(b"flibble") == ('Unknown Image', [[('header', 'Image Format: '), ('text', 'unknown')]])
|
||||
|
@ -30,6 +30,18 @@ def test_view_auto():
|
||||
)
|
||||
assert f[0].startswith("XML")
|
||||
|
||||
f = v(
|
||||
b"<svg></svg>",
|
||||
headers=http.Headers(content_type="image/svg+xml")
|
||||
)
|
||||
assert f[0].startswith("XML")
|
||||
|
||||
f = v(
|
||||
b"verybinary",
|
||||
headers=http.Headers(content_type="image/new-magic-image-format")
|
||||
)
|
||||
assert f[0] == "Unknown Image"
|
||||
|
||||
f = v(b"\xFF" * 30)
|
||||
assert f[0] == "Hex"
|
||||
|
||||
|
@ -23,8 +23,6 @@ logging.getLogger("hyper.packages.hpack.hpack").setLevel(logging.WARNING)
|
||||
logging.getLogger("requests.packages.urllib3.connectionpool").setLevel(logging.WARNING)
|
||||
logging.getLogger("passlib.utils.compat").setLevel(logging.WARNING)
|
||||
logging.getLogger("passlib.registry").setLevel(logging.WARNING)
|
||||
logging.getLogger("PIL.Image").setLevel(logging.WARNING)
|
||||
logging.getLogger("PIL.PngImagePlugin").setLevel(logging.WARNING)
|
||||
|
||||
|
||||
# inspect the log:
|
||||
|
Loading…
Reference in New Issue
Block a user