diff --git a/common/protob/pb2py b/common/protob/pb2py index d6cbbde171e..6be88695d96 100755 --- a/common/protob/pb2py +++ b/common/protob/pb2py @@ -93,7 +93,7 @@ if not PROTOC: PROTOC_PREFIX = Path(PROTOC).resolve().parent.parent -ENUM_ENTRY = c.PrefixedArray(c.Byte, c.Int16ul) +ENUM_ENTRY = c.PrefixedArray(c.Int16ul, c.Int16ul) FIELD_STRUCT = c.Struct( "tag" / c.Byte, diff --git a/core/embed/rust/src/protobuf/defs.rs b/core/embed/rust/src/protobuf/defs.rs index acf4165683d..6b6097af141 100644 --- a/core/embed/rust/src/protobuf/defs.rs +++ b/core/embed/rust/src/protobuf/defs.rs @@ -209,7 +209,7 @@ pub unsafe fn get_msg(msg_offset: u16) -> MsgDef { unsafe fn get_enum(enum_offset: u16) -> EnumDef { // #[repr(C, packed)] // struct EnumDef { - // count: u8, + // count: u16, // vals: [u16], // } @@ -217,8 +217,10 @@ unsafe fn get_enum(enum_offset: u16) -> EnumDef { // definition inside `ENUM_DEFS`. unsafe { let ptr = ENUM_DEFS.as_ptr().add(enum_offset as usize); - let count = ptr.offset(0).read() as usize; - let vals = ptr.offset(1); + let count_lo = ptr.offset(0).read(); + let count_hi = ptr.offset(1).read(); + let count = u16::from_le_bytes([count_lo, count_hi]) as usize; + let vals = ptr.offset(2); EnumDef { values: slice::from_raw_parts(vals.cast(), count),