1

I call an HTTP request which returns a protobuf response. I don't have the .pb files, so I try to convert that to a readable format such as JSON with indexed fields.

Using protoc and the command protoc --decode-raw < test.bin

The output looks like this:

2: 1623325235623240
4: "\037\213\010\000\000\000\000\000\000\000\265[\tTS\327\272\346\204\220J\324g\232Zz\264\n\251\366\366\272\332K\r\220 \364\3425\377Y\335\272\223\253\200#\333\256\304=VKu\036\254%G\3501k\371^\273ZQ\225fg\030e\342\322"\271\207=\222|\366d/\307\25"
5: 1
7: 1
9 {
  2: "MethodUpdate"
  3 {
    1: "ASfeyGDdgsSDgddSDheyWw"
    2: 0
  }
  4: 11
}

I know that everything is meta data on the file and the actual content is in the field 4. From my knowledge, this is also a protobuf message that should have a similar output. If I copy paste the content of the field 4 and run the protoc command again, I get the error Failed to parse input.

Is there any way to parse the protobuf response to a readable format such as JSON?

I found similar questions, but non of the suggested answers worked in my case.

Tasos
  • 7,325
  • 18
  • 83
  • 176

1 Answers1

0

You ought be able to reverse-engineer the protobuf.

Then, you could use this to decode the message using your preferred language and convert that into JSON.

See Encoding for an overview of how the wire-format is constructed.

DazWilkin
  • 32,823
  • 5
  • 47
  • 88
  • That's the points of getting this to a readable format like the rest of the fields (not the `field 4`. To reverse-engineer the protobuf. Without doing this, there is no way to reverse-engineering – Tasos Jun 09 '21 at 19:02
  • Which is the solution to your question. Use the Encoding guide to determine what field types you're seeing from `protoc --decode-raw`, draft a protobuf, then use it to unmarshal the message and then convert it to JSON. – DazWilkin Jun 09 '21 at 19:47
  • You're jumping to the conclusion that there's only one message. There could be thousands, and it's be really nice to have decode_raw produce a much more standard output. – James Moore Jun 02 '22 at 14:35