diff --git a/client/src/cmdhw.c b/client/src/cmdhw.c index 831b44eb0..7d33f7245 100644 --- a/client/src/cmdhw.c +++ b/client/src/cmdhw.c @@ -2545,15 +2545,18 @@ static int CmdBWMUpgrade(const char *Cmd) { free(fw); return PM3_EFILE; } - uint16_t chip_id = (uint16_t)(fw[0x0C] | (fw[0x0D] << 8)); + + // Check Chip ID at offset 0x0C (2 bytes, little-endian) + uint16_t chip_id = MemLeToUint2byte(fw + 0x0C); if (chip_id != 0x000C) { PrintAndLogEx(FAILED, "refusing to flash: image chip_id " _YELLOW_("0x%04X") " is not ESP32-C2 (0x000C)", chip_id); free(fw); return PM3_EFILE; } - uint32_t app_sign = (uint32_t)(fw[0x20] | (fw[0x21] << 8) | (fw[0x22] << 16) | ((uint32_t)fw[0x23] << 24)); - if (app_sign != 0xABCD5432) { + // Check Application Signature at offset 0x20 (4 bytes, little-endian) + uint32_t app_sign = MemLeToUint4byte(fw + 0x20); + if (app_sign != 0xABCD5432) { PrintAndLogEx(FAILED, "refusing to flash: image app_sign " _YELLOW_("0x%08X") " is invalid (expected 0xABCD5432)", app_sign); free(fw); return PM3_EFILE;