3

When I'm reversing an apk I got .pb file but not .proto file, is there any way to decompiler this file to .proto file or can I just generate java code from this .pb file ?

Kevin
  • 87
  • 2
  • 9
  • The .pb file - is it the *data*? Or is it a compiled descriptor set? If it is data: you'll have to reverse engineer it - there are tools to help, so it isn't necessarily hard. If it is the compiled descriptor set: much easier. Protoc has a tool for looking at raw payloads, as does my online tooling here https://protogen.marcgravell.com/decode – Marc Gravell Jul 29 '19 at 09:39
  • It's the compiled descriptor set. do you mean --decode_raw ? Is there any way I can get .proto file directly ? – Kevin Jul 29 '19 at 10:23
  • question: what do you need the .proto *for*? is it for editing? if it is for code-gen, IIRC protoc will accept the compiled descriptor set as input (or you can invoke the plugins directly - the way plugins work is that the compiled descriptor set is piped to stdin) – Marc Gravell Jul 29 '19 at 10:27
  • For java code generate. Which plugin ? protoc may not be able to generate by this file – Kevin Jul 30 '19 at 01:19

1 Answers1

3

If (as per comments) the file you have is the compiled descriptor set, then you can use protoc to generate any language (that it usually supports) from this; simply use the --descriptor_set_in=FILES option at the command line to specify your file as input (in place of FILES), and use --java_out=OUT_DIR (or whatever) to indicate the output language and location.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • How does this actually work ? When I use the command protoc --description_set_in=./myfile.pb --java_out=. I got an error "Missing input file.". When I add an empty file to the end(no matter it exists or not). I got an error "No such file or directory". – Kevin Jul 30 '19 at 10:54
  • @Kevin `descriptor_set_in`, not `description_set_in` – Marc Gravell Jul 30 '19 at 10:55
  • Sorry. It's typo. What I use is descriptor_set_in – Kevin Jul 30 '19 at 10:58
  • @Kevin oops, my bad - you still need to specify the file - it checks the descriptor sets *before* it tests the file. So: try `protoc --descriptor_set_in=your.pb --java_out=somedir your.proto` - I've just tested this locally, and it worked fine (no `your.proto` in the drive); the only trick is : knowing the name of the file in the descriptor set. I can probably extract that if you can't figure it out – Marc Gravell Jul 30 '19 at 11:04
  • Hm, `Unknown flag: --descriptor_set_in`, version 3.14.0 – Andrii Karaivanskyi Feb 05 '21 at 16:46