Refactor chip ID and app signature checks

Signed-off-by: Niel Nielsen <nieldk@gmail.com>
This commit is contained in:
Niel Nielsen authored and GitHub committed 2026-09-08 13:35:48 +02:00
1 parent b0aa484eba
commit 6e84d4ca8b
1 file changed
+6 -3
+6 -3
View File
@@ -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;