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

Conversation

girst
Copy link

@girst girst commented Dec 13, 2020

This is not part of the spec, but youtube loves to pass base64 encoded
messages in string fields of other messages. So when a string is
encountered, attempt decoding and recursing into it.

Hope that's understandable, I'm not too familiar with protobuf's terminology. In essence, I'm doing some reversing of youtube's internal browse_ajax API, which is littered with this idiosyncrasy. So to decode such a message, I currently have to pass the protobuf-message to your tool, copy-paste the base64-encoded submessage, decode it, and pass it through again (often multiple times).

Here's how such a message is displayed currently:

and now with my patch applied:

both times invoked with echo '4qmFsgJSEhhVQ1Y1dkNpM2pQSmRVUlp3QU9PX0ZOZlEaNkVnWjJhV1JsYjNNWUF5QUFNQUU0QWVvREUwTm5RVk5EWjJsVmFXOWZRVzVoTWtJdFZ6USUzRA=='|base64 -d|./main.py

This is not part of the spec, but youtube loves to pass base64 encoded
messages in string fields of other messages. So when a string is
encountered, attempt decoding and recursing into it.
@mildsunrise
Copy link
Owner

mildsunrise commented Dec 13, 2020

hi, thanks for the patch! it's a pretty specific use-case (quoted, urlsafe base64 encoded, missing padding) so I'm not sure it's a good fit to have it by default. However, the config system already allows the user to specify custom handlers for fields, so you could go ahead and define one for base64-encoded nested messages. If you place this in protobuf_config.py:

types = {
  "root": {
    80226972: "msg1",
  },
  "msg1": {
    3: "base64_message",
  },
}

def parse_base64_message(x, type):
  from urllib.parse import unquote
  from subprocess import run
  import base64

  x = unquote(x.read().decode('ascii')) + '=='
  x = base64.urlsafe_b64decode(x)
  output = run('./main.py', input=x, capture_output=True).stdout
  return "base64 encoded message => " + output.decode().rstrip()

native_types = {
  "base64_message": (parse_base64_message, 2),
}

You'll get the desired output. But I understand you want this to happen in the chunk handler to avoid having to explicitely specify it for fields... this can't be easily done for now, I'll think of the best way to make it possible.

@girst
Copy link
Author

girst commented Dec 13, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants