From 89ba2caa13e353b6401169d454e2a93cd75cbe53 Mon Sep 17 00:00:00 2001 From: Mohammad Abdul Sahil <127765312+abdulsaheel@users.noreply.github.com> Date: Sat, 19 Sep 2026 15:41:21 +0530 Subject: [PATCH] gate GET_HELLO gen5 decode on profile cmdGetHelloModern sends the same 0x91 opcode with a gen4 profile, but the response decoder ran every 0x91 reply through Gen5HelloInfo.parse unconditionally. a gen4 reply that happens to be >=104 bytes would get its fields read at gen5's byte offsets (wrong serial/fw/battery), and a shorter one would just get dropped. gate it on profile.isGen5 like every other shared-opcode branch already does. --- lib/src/control.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/src/control.dart b/lib/src/control.dart index 0369444..8b408b1 100644 --- a/lib/src/control.dart +++ b/lib/src/control.dart @@ -829,13 +829,22 @@ CmdResponse? parseCommandResponse(Uint8List inner, // (pay[93]==body[91] is the fw MAJOR byte, which is only why the old // ==50 gate happened to hold). Both are superseded by the full map. // + // PROFILE-GATED: this same opcode is also how gen4 answers + // cmdGetHelloModern (see commands.dart), whose reply body shape is NOT + // confirmed to match gen5's fixed Gen5HelloInfo map. Running a gen4 + // reply through that map would misattribute its fields at gen5's byte + // offsets — a confidently wrong serial/firmware/battery reading for a + // device that isn't gen5, or a silently dropped reply if it's shorter + // than gen5's 104-byte body. Until gen4's modern-hello layout is + // verified, this branch stays gen5-only and emits nothing for gen4. + // // STATUS-GATED, like the battery and clock reads above/below: hello // answers PENDING (2) before its terminal result, and FAILURE (0) / // UNSUPPORTED (3) are real wire cases. A non-success reply does not // populate the body, so its bytes are whatever the buffer held last — // parsing them would mint a confident serial, battery and firmware version // out of stale memory. - if (status == 1) { + if (profile.isGen5 && status == 1) { final body = payload.length >= 2 ? Uint8List.sublistView(payload, 2) : payload; final h = Gen5HelloInfo.parse(body);