Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support base64-encoded nested messages #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions protobuf_inspector/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from .parser import Parser, fg0, fg1, fg2, fg3, fg4, fg5, fg6, fg7, fg8, fg9, dim, bold
from struct import unpack
from io import BytesIO
from base64 import urlsafe_b64decode
from urllib.parse import unquote

# Code that implements and registers the usual native types (high
# level parsing and formatting) into the barebones Parser.
Expand Down Expand Up @@ -122,6 +124,15 @@ def parse_chunk(self, file, type):
except Exception:
pass

# Attempt to decode as urlencoded, possibly unpadded, (urlsafe-)base64 encoded message
try:
return "%s => base64 encoded %s" % (
fg2('"%s"' % chunk.decode('ascii')),
self.parse_message(BytesIO(urlsafe_b64decode(unquote(chunk) + "==")), "message")
)
except Exception as e:
pass

# Attempt to decode packed repeated chunks
try:
if len(chunk) >= 5:
Expand Down