fix(dfu): read iSerial index at runtime; honor --cpid/--ecid overrides

Retire the three hardcoded DFU_SERIAL_INDEX = 3 constants in
usb_dfu.c, path_b_identity.c, and checkm8_internal.h. usb_dfu_find()
now captures bDeviceDescriptor.iSerialNumber into device_info_t and
usb_dfu_read_info() iterates hint -> 3 -> 4 with the sentinel check
deferred until every probe has returned only the product string. The
checkm8 spray helpers accept the resolved index as a parameter, and
the CLI override log fires whenever --cpid/--ecid populated a field
the descriptor read could not, so A14/A15/A16 devices no longer
strand users on the false NOT-in-SecureROM-DFU diagnostic.

Files modified:
- include/device/device.h
- include/device/usb_dfu.h
- include/exploit/checkm8_internal.h
- src/bypass/path_b_identity.c
- src/device/usb_dfu.c
- src/exploit/checkm8.c
- src/exploit/checkm8_spray.c
- src/main.c
- tests/mocks/mock_hw_stubs.c

Closes: #45, #65, #59, #27, #17, #52, #30, #22, #25, #10, #8, #6, #7
This commit is contained in:
Moussa Ouallaf 2026-07-17 03:03:52 +02:00
parent 443a18f9ad
commit 03d352d7f5
9 changed files with 332 additions and 101 deletions

View file

@ -116,8 +116,8 @@ int checkm8_verify_pwned(device_info_t *dev)
memset(serial, 0, sizeof(serial));
if (usb_dfu_read_info(dev->usb, &cpid, &ecid, serial,
sizeof(serial)) != 0) {
if (usb_dfu_read_info(dev->usb, dev->iserial_index,
&cpid, &ecid, serial, sizeof(serial)) != 0) {
log_error("checkm8_verify_pwned: failed to read USB serial");
return -1;
}
@ -162,10 +162,17 @@ int checkm8_exploit(device_info_t *dev)
log_info("checkm8_exploit: waiting for device reset...");
usleep(USB_RECONNECT_DELAY_USEC);
if (usb_dfu_find(&dev->usb) != 0) {
log_error("checkm8_exploit: DFU device lost after attempt %d, cannot retry",
attempt - 1);
return -1;
{
uint8_t new_iserial = 0;
if (usb_dfu_find(&dev->usb, &new_iserial) != 0) {
log_error("checkm8_exploit: DFU device lost after attempt %d, cannot retry",
attempt - 1);
return -1;
}
/* Re-enumerating can hand back a different iSerial
* index if the device was hot-swapped for a different
* chip family; refresh the cached value. */
dev->iserial_index = new_iserial;
}
log_info("checkm8_exploit: USB handle re-acquired for retry %d", attempt);
}