From ae37c4c06b6c9086cb0afe0f94e25dc021e3acfe Mon Sep 17 00:00:00 2001 From: "stanislav.rozum" Date: Thu, 21 May 2026 20:33:59 +0200 Subject: [PATCH] improved regex to support empty size modifiers in DfuSeFormat Signed-off-by: stanislav.rozum --- DeviceProgramming/Dfu/Device.cs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/DeviceProgramming/Dfu/Device.cs b/DeviceProgramming/Dfu/Device.cs index 01f0d45..111c31c 100644 --- a/DeviceProgramming/Dfu/Device.cs +++ b/DeviceProgramming/Dfu/Device.cs @@ -635,7 +635,7 @@ private Status SeErase(uint address) private static readonly Regex SeMemoryLayoutRegex = new Regex( @"^@(?[\w\s]*[\w]+)\s* /0x(?
[A-F0-9]{1,8}) - /(\d+)\*(\d+)([\x20KM]{1})([a-g]{1})(?:,(\d+)\*(\d+)([\x20KM]{1})([a-g]{1}))*$", + /(\d+)\*(\d+)([\x20KM]?)([a-g]{1})(?:,(\d+)\*(\d+)([\x20KM]?)([a-g]{1}))*$", RegexOptions.Compiled | RegexOptions.IgnorePatternWhitespace); /// @@ -671,17 +671,22 @@ private NamedLayout ParseLayout(string dfuSeFormat) uint blockNo = UInt32.Parse(result.Groups[groupoff + 1].Captures[i].Value); uint blockSize = UInt32.Parse(result.Groups[groupoff + 2].Captures[i].Value); - // size modifiers (K for kilo-, M for Mega) - switch (result.Groups[groupoff + 3].Captures[i].Value[0]) + string sizeModifier = result.Groups[groupoff + 3].Captures[i].Value; + + if (!string.IsNullOrEmpty(sizeModifier)) { - case 'K': - blockSize <<= 10; - break; - case 'M': - blockSize <<= 20; - break; - default: - break; + // size modifiers (K for kilo-, M for Mega) + switch (sizeModifier[0]) + { + case 'K': + blockSize <<= 10; + break; + case 'M': + blockSize <<= 20; + break; + default: + break; + } } // the permissions are encoded in the lowest 3 bits of the ASCII character...