Skip to content

Instantly share code, notes, and snippets.

@fynngodau
Last active March 12, 2024 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fynngodau/bba7b2d11a17d01f8439979f3cfe4fb9 to your computer and use it in GitHub Desktop.
Save fynngodau/bba7b2d11a17d01f8439979f3cfe4fb9 to your computer and use it in GitHub Desktop.
Decode one grpc message
# * provide a grpc encoded file as parameter: `python parseGrpc.py $FILE`
# * grpc compression must not be enabled
# * output: $FILE.dec is the first grpc message
# based on mitmproxy grpc parser:
# https://github.com/mitmproxy/mitmproxy/blob/a26013908a95a270291de4c462d4074477b9a8d2/mitmproxy/contentviews/grpc.py#L866-L888
import struct
import sys
assert len(sys.argv) == 2
with open(sys.argv[1], "rb") as file:
data = file.read()
msg_is_compressed, length = struct.unpack("!?i", data[:5])
assert msg_is_compressed == False
decoded_message = struct.unpack("!%is" % length, data[5 : 5 + length])[0]
with open(sys.argv[1] + ".dec", "wb") as out_file:
out_file.write(decoded_message)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment