且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

解析没有 .proto 文件的协议缓冲区

更新时间:2023-11-13 10:11:46

当您编写 .proto 文件时,您可以将选项 optimize_for 设置为 LITE_RUNTIME(请参阅此处),这将省略来自生成的代码以减少二进制文件的大小.我相信这是移动开发的常见做法,因为代码大小在该环境中是一种稀缺资源.这可以解释为什么您只找到一个 .proto 文件.应用程序实际上不太可能使用 descriptor.proto 传输任何数据,因为这主要是协议缓冲区库的实现细节.

When you write a .proto file you can set an option optimize_for to LITE_RUNTIME (see here) and this will omit the descriptors from the generated code to reduce the size of the binary. I believe this is a common practice for mobile development since code size is a scarce resource in that environment. This may explain why you found only a single .proto file. It is unlikely that the app is actually transferring any data using descriptor.proto since that is mostly an implementation detail of the protocol buffers library.

如果您找不到任何其他描述符,***的办法可能是尝试在没有它们的情况下解释协议缓冲区.您可以在此处了解协议缓冲区有线格式.一个简单的入门方法是创建一个不包含字段的 proto2 消息类型,并尝试将数据解析为该类型.然后,您可以使用反射 API 检查消息中所谓的未知字段",并尝试找出它们代表什么.

If you cannot find any other descriptors, your best bet might be to try to interpret the protocol buffers without them. You can read about the protocol buffers wire format here. An easy way to get started would be to create a proto2 message type containing no fields and attempt to parse the data as that type. You can then use the reflection API to examine what are known as the "unknown fields" in the message and try to figure out what they represent.