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:
parent
443a18f9ad
commit
03d352d7f5
9 changed files with 332 additions and 101 deletions
34
src/main.c
34
src/main.c
|
|
@ -130,20 +130,23 @@ static int parse_args(int argc, char *argv[], cli_opts_t *opts)
|
|||
static int detect_device(device_info_t *dev)
|
||||
{
|
||||
libusb_device_handle *usb_handle = NULL;
|
||||
uint8_t iserial = 0;
|
||||
memset(dev, 0, sizeof(*dev));
|
||||
|
||||
if (usb_dfu_find(&usb_handle) == 0) {
|
||||
log_info("Device found in DFU mode");
|
||||
if (usb_dfu_find(&usb_handle, &iserial) == 0) {
|
||||
log_info("Device found in DFU mode (iSerial index: %u)",
|
||||
(unsigned)iserial);
|
||||
uint32_t cpid = 0;
|
||||
uint64_t ecid = 0;
|
||||
char serial[DFU_SERIAL_MAX] = {0};
|
||||
if (usb_dfu_read_info(usb_handle, &cpid, &ecid,
|
||||
if (usb_dfu_read_info(usb_handle, iserial, &cpid, &ecid,
|
||||
serial, sizeof(serial)) < 0)
|
||||
log_warn("Failed to read DFU serial info");
|
||||
dev->cpid = cpid;
|
||||
dev->ecid = ecid;
|
||||
dev->is_dfu_mode = 1;
|
||||
dev->usb = usb_handle;
|
||||
dev->cpid = cpid;
|
||||
dev->ecid = ecid;
|
||||
dev->is_dfu_mode = 1;
|
||||
dev->usb = usb_handle;
|
||||
dev->iserial_index = iserial;
|
||||
snprintf(dev->serial, sizeof(dev->serial), "%s", serial);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -259,11 +262,22 @@ int main(int argc, char *argv[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
/* Apply CLI overrides for CPID/ECID */
|
||||
/*
|
||||
* Apply CLI overrides for CPID/ECID. This runs after
|
||||
* usb_dfu_read_info() has probed every descriptor index it knows;
|
||||
* gating on `dev.<field> == 0` means overrides only fire when the
|
||||
* device did not surface the value itself (either the descriptor
|
||||
* layout is undocumented or the device is not in true SecureROM
|
||||
* DFU). If either override applied, emit a single "manual
|
||||
* override" line so bug reports show the fallback ran.
|
||||
*/
|
||||
int cpid_from_override = 0;
|
||||
int ecid_from_override = 0;
|
||||
if (opts.has_cpid_override) {
|
||||
if (dev.cpid == 0) {
|
||||
dev.cpid = opts.cpid_override;
|
||||
log_info("CPID overridden: 0x%04X (from --cpid)", dev.cpid);
|
||||
cpid_from_override = 1;
|
||||
} else {
|
||||
log_info("CPID already detected (0x%04X), ignoring --cpid override",
|
||||
dev.cpid);
|
||||
|
|
@ -274,11 +288,15 @@ int main(int argc, char *argv[])
|
|||
dev.ecid = opts.ecid_override;
|
||||
log_info("ECID overridden: 0x%llX (from --ecid)",
|
||||
(unsigned long long)dev.ecid);
|
||||
ecid_from_override = 1;
|
||||
} else {
|
||||
log_info("ECID already detected (0x%llX), ignoring --ecid override",
|
||||
(unsigned long long)dev.ecid);
|
||||
}
|
||||
}
|
||||
if (cpid_from_override || ecid_from_override)
|
||||
log_info("[device] using --cpid=0x%04X --ecid=0x%llX manual override",
|
||||
dev.cpid, (unsigned long long)dev.ecid);
|
||||
|
||||
enrich_chip_info(&dev);
|
||||
device_print_info(&dev);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue