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
|
|
@ -48,6 +48,18 @@ typedef struct {
|
|||
|
||||
/* USB handle for DFU mode (NULL when not in DFU) */
|
||||
libusb_device_handle *usb;
|
||||
|
||||
/*
|
||||
* DFU serial-string descriptor index reported by the device
|
||||
* (bDeviceDescriptor.iSerialNumber). Populated by usb_dfu_find()
|
||||
* when the device is enumerated. Pre-A9 devices report 3; A14+
|
||||
* devices report 4 (product string moved to index 3). A value of
|
||||
* 0 means the device did not advertise a serial descriptor and
|
||||
* callers must fall back to the legacy probe order (3, then 4).
|
||||
* Kept at end of struct so appending it is a source-compatible ABI
|
||||
* addition.
|
||||
*/
|
||||
uint8_t iserial_index;
|
||||
} device_info_t;
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -36,20 +36,35 @@ void usb_dfu_cleanup(void);
|
|||
|
||||
/*
|
||||
* Find an Apple device in DFU mode (VID=0x05AC, PID=0x1227).
|
||||
* On success, *handle is set to an opened device handle and 0 is returned.
|
||||
* On failure, *handle is set to NULL and -1 is returned.
|
||||
* On success, *handle is set to an opened device handle and 0 is
|
||||
* returned. On failure, *handle is set to NULL and -1 is returned.
|
||||
*
|
||||
* If iserial_out is non-NULL, the device's bDeviceDescriptor.iSerialNumber
|
||||
* (the actual USB string index that carries CPID/ECID) is written to it.
|
||||
* A value of 0 means the descriptor did not advertise a serial index --
|
||||
* usb_dfu_read_info() will fall back through the legacy probe order.
|
||||
*/
|
||||
int usb_dfu_find(libusb_device_handle **handle);
|
||||
int usb_dfu_find(libusb_device_handle **handle, uint8_t *iserial_out);
|
||||
|
||||
/*
|
||||
* Read device info from the DFU serial string descriptor.
|
||||
* Parses CPID and ECID as hex values from the key:value pairs.
|
||||
* Copies the full serial string to serial (up to serial_len bytes).
|
||||
* Missing fields are set to 0 / empty string.
|
||||
*
|
||||
* iserial_hint is the index reported by bDeviceDescriptor.iSerialNumber
|
||||
* (usually populated by usb_dfu_find). Pass 0 when the caller has no
|
||||
* hint; the function will still try the legacy indices 3 and 4.
|
||||
* The read attempts, in order: (a) iserial_hint if non-zero,
|
||||
* (b) 3 (pre-A9 default), (c) 4 (A14+ default). Duplicate indices are
|
||||
* skipped. The "device is not in SecureROM DFU" sentinel is only
|
||||
* raised when every probe returned the product string.
|
||||
*
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
int usb_dfu_read_info(libusb_device_handle *handle, uint32_t *cpid,
|
||||
uint64_t *ecid, char *serial, size_t serial_len);
|
||||
int usb_dfu_read_info(libusb_device_handle *handle, uint8_t iserial_hint,
|
||||
uint32_t *cpid, uint64_t *ecid,
|
||||
char *serial, size_t serial_len);
|
||||
|
||||
/*
|
||||
* Send data to the DFU device via control transfer (DFU_DNLOAD).
|
||||
|
|
|
|||
|
|
@ -37,11 +37,12 @@
|
|||
#define USB_ABORT_TIMEOUT_MIN 0
|
||||
|
||||
/*
|
||||
* Apple DFU devices report serial number at descriptor index 3.
|
||||
* USB_MAX_STRING_DESCRIPTOR_IDX (10) is used as wIndex in GET_DESCRIPTOR
|
||||
* requests to trigger the string descriptor allocation path.
|
||||
* requests to trigger the string descriptor allocation path. The DFU
|
||||
* serial descriptor index itself is no longer a compile-time constant
|
||||
* -- it is read at runtime from bDeviceDescriptor.iSerialNumber and
|
||||
* threaded through the spray helpers by their caller.
|
||||
*/
|
||||
#define DFU_SERIAL_IDX 3
|
||||
#define USB_MAX_STRING_DESC_IDX 10
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
|
@ -217,8 +218,11 @@ int checkm8_usb_request_stall(libusb_device_handle *usb);
|
|||
/*
|
||||
* checkm8_usb_request_leak -- Async GET_DESCRIPTOR with 1ms timeout
|
||||
* and EP0_MAX_PACKET_SZ length. Returns 1 if sz==0, 0 otherwise.
|
||||
* `iserial_idx` is the descriptor index that populates the low byte
|
||||
* of wValue -- the caller reads it from bDeviceDescriptor.iSerialNumber
|
||||
* (via device_info_t::iserial_index) rather than assuming a constant.
|
||||
*/
|
||||
int checkm8_usb_request_leak(libusb_device_handle *usb);
|
||||
int checkm8_usb_request_leak(libusb_device_handle *usb, uint8_t iserial_idx);
|
||||
|
||||
/*
|
||||
* checkm8_stall -- Repeatedly send GET_DESCRIPTOR with variable abort
|
||||
|
|
@ -226,12 +230,12 @@ int checkm8_usb_request_leak(libusb_device_handle *usb);
|
|||
* successful leak request. Matches gaster's checkm8_stall().
|
||||
* Returns 0 on success, -1 if MAX_STALL_RETRIES is exceeded.
|
||||
*/
|
||||
int checkm8_stall(libusb_device_handle *usb);
|
||||
int checkm8_stall(libusb_device_handle *usb, uint8_t iserial_idx);
|
||||
|
||||
/*
|
||||
* checkm8_no_leak -- Async GET_DESCRIPTOR with 1ms timeout and
|
||||
* (3*EP0_MAX_PACKET_SZ + 1) length. Returns 1 if sz==0, 0 otherwise.
|
||||
*/
|
||||
int checkm8_no_leak(libusb_device_handle *usb);
|
||||
int checkm8_no_leak(libusb_device_handle *usb, uint8_t iserial_idx);
|
||||
|
||||
#endif /* CHECKM8_INTERNAL_H */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue