ImHex-Patterns icon indicating copy to clipboard operation
ImHex-Patterns copied to clipboard

Protobuf pattern does not support field numbers > 15

Open prosenkranz opened this issue 1 year ago • 1 comments

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.

prosenkranz avatar Aug 14 '23 08:08 prosenkranz

This can be solved by replacing the bitfield with a uleb128 and logical bit shifts

jumanji144 avatar Aug 14 '23 09:08 jumanji144