How to Read a .pb File Without the Schema

You have a .pb file sitting on your disk. It came out of a gRPC service, a packet capture, or a mobile app someone asked you to debug. The question is what is actually in it, and the standard answer is always the same: get the .proto schema, run protoc, and you will have your JSON. Except the schema is on a server that has been rewritten twice, or the other side is a vendor who answers tickets slowly, or the file is from a version of the app that shipped a year ago. Sometimes you just need to look at the bytes first.

Here is the thing that makes that possible: the protobuf wire format is almost embarrassingly simple. Every field in the file is a tag followed by a value. The tag is a single varint that packs two numbers together: the field number and a three-bit wire type. The wire type tells you how the value is stored. There are only four of them: varint for integers and booleans, a fixed 64-bit little-endian blob, a length-delimited chunk (strings, bytes, nested messages), and a fixed 32-bit value. That is the whole grammar. A .pb file is just a list of tag-then-value pairs, read left to right until the bytes run out.

So what do you get without the schema? You get the shape of the message. Field 1 is a 20-byte length-delimited blob that happens to be valid UTF-8, so it is almost certainly a string. Field 2 is a small varint, so probably a counter or an enum. Field 3 is a length-delimited chunk that itself parses as a clean run of tag-value pairs that consume the buffer exactly, so it is a nested message, and you can step inside it. Do that pass and you can usually reconstruct the .proto well enough to decode the rest properly, which is the actual reverse-engineering job. The raw decode tab at proto.datajutsu.com does exactly this: it walks the wire bytes, shows every field number and wire type with a best-effort value, and recurses into nested messages when one is hiding inside. If you have the schema, you paste it next to the binary and the decoding becomes deterministic instead of forensic.

One more angle that bites people: even with the schema, the JSON mapping has rules you have to know. 64-bit integers serialize as strings because JavaScript numbers drop precision past 2 to the 53. Empty repeated fields encode to zero bytes, so a list you never set will not exist after a round trip. snake_case field names come out as camelCase. If you are also trying to go the other way (JSON to binary, or sample data to a drafted .proto), the same tool does that and verifies the draft against your original data field for field. I wrote it up in this protobuf to JSON post.

Everything runs in your browser, nothing you paste is uploaded, and a share link puts your inputs in the URL so you can hand someone the exact case you are stuck on. Free, no account, no protoc install, no waiting on the vendor's ticket queue.

Subscribe to Data Jutsu

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe