Support base64-encoded nested messages#10
Open
girst wants to merge 1 commit into
Open
Conversation
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.
Owner
|
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 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 |
Author
|
On Sun, Dec 13, 2020 at 10:28:55AM -0800, Alba Mendez wrote:
hi, thanks for the patch! it's a pretty specific use-case (urlsafe
base64 encoded, missing padding) so I'm not sure it's a good fit to
Note that the way I've implemented this, it works for any of the
following combinations:
- urlencoded / not urlencoded
- urlsafe base64 (-_) / normal base64 (+/)
- with padding / without padding
In other words, I tried to keep it as non-special-case as possible.
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.
Correct. In my use case (reverse engineering) i don't know the field
numbers beforehand.
How about a command line flag (passed to the StandardParser class) that
enables additional heuristics (maybe someone else has other needs that
could be added to it)? I can't think of a good name, but something like
--try-harder or something?
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_ajaxAPI, 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