ImHex-Patterns
ImHex-Patterns copied to clipboard
Protobuf pattern does not support field numbers > 15
As per Protobuf Documentation, "Tags" (Keys) of Records/Keys are encoded as VarInts / LEB128.
However the current Protobuf pattern assumes Keys are always 1 byte: https://github.com/WerWolv/ImHex-Patterns/blob/6baae925532a8e3fb557fd07273063c306e5bc5b/patterns/protobuf.hexpat#L34
This assumption will not work anymore for larger (>15) field numbers, where the varint will be 2 bytes long:
CodedOutputStream stream = ...;
stream.writeUInt(16, 0);
The output binary will be:
80 01 00
The value byte here is expected to be 0. The current pattern will incorrectly interpret the second byte as the value 1.
This can be solved by replacing the bitfield with a uleb128 and logical bit shifts