feat(#6): add --cpid and --ecid CLI override flags
Resolves #6: set values for cpid ecid manually When DFU mode fails to extract CPID/ECID from the USB serial string, users can now pass --cpid 0xNNNN and --ecid 0xNNNN to set them manually. Overrides only apply when the detected value is 0 (missing). Files modified: - src/main.c Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
904ac4523c
commit
8a79d8e61c
1 changed files with 79 additions and 101 deletions
168
src/main.c
168
src/main.c
|
|
@ -1,13 +1,8 @@
|
||||||
/*
|
/* main.c -- tr4mpass entry point and orchestration. */
|
||||||
* main.c -- tr4mpass entry point and orchestration.
|
|
||||||
*
|
|
||||||
* CLI argument parsing, device detection (DFU via libusb first, then
|
|
||||||
* libimobiledevice), chip database lookup, module registration, and
|
|
||||||
* bypass execution. Orchestration only -- no business logic.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
|
|
||||||
|
|
@ -26,36 +21,46 @@ typedef struct {
|
||||||
int detect_only;
|
int detect_only;
|
||||||
int force_path_a;
|
int force_path_a;
|
||||||
int force_path_b;
|
int force_path_b;
|
||||||
|
uint32_t cpid_override;
|
||||||
|
uint64_t ecid_override;
|
||||||
|
int has_cpid_override;
|
||||||
|
int has_ecid_override;
|
||||||
} cli_opts_t;
|
} cli_opts_t;
|
||||||
|
|
||||||
static void print_banner(void)
|
static void print_banner(void)
|
||||||
{
|
{
|
||||||
printf("========================================\n");
|
printf("========================================\n"
|
||||||
printf(" tr4mpass v%s\n", TR4MPASS_VERSION);
|
" tr4mpass v%s\n"
|
||||||
printf(" Activation lock bypass research tool\n");
|
" Activation lock bypass research tool\n"
|
||||||
printf("========================================\n\n");
|
"========================================\n\n", TR4MPASS_VERSION);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_usage(const char *prog)
|
static void print_usage(const char *prog)
|
||||||
{
|
{
|
||||||
printf("Usage: %s [OPTIONS]\n\n", prog);
|
printf("Usage: %s [OPTIONS]\n\n"
|
||||||
printf("Options:\n");
|
"Options:\n"
|
||||||
printf(" -v, --verbose Enable debug logging\n");
|
" -v, --verbose Enable debug logging\n"
|
||||||
printf(" -n, --dry-run Show what would run, do not execute\n");
|
" -n, --dry-run Show what would run, do not execute\n"
|
||||||
printf(" -d, --detect-only Detect device and exit\n");
|
" -d, --detect-only Detect device and exit\n"
|
||||||
printf(" -a, --force-path-a Force Path A (checkm8, A5-A11)\n");
|
" -a, --force-path-a Force Path A (checkm8, A5-A11)\n"
|
||||||
printf(" -b, --force-path-b Force Path B (identity, A12+)\n");
|
" -b, --force-path-b Force Path B (identity, A12+)\n"
|
||||||
printf(" -h, --help Show this help message\n");
|
" --cpid <hex> Override CPID (e.g. --cpid 0x8960)\n"
|
||||||
|
" --ecid <hex> Override ECID (e.g. --ecid 0x1F70CB1331C)\n"
|
||||||
|
" -h, --help Show this help message\n", prog);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int parse_args(int argc, char *argv[], cli_opts_t *opts)
|
static int parse_args(int argc, char *argv[], cli_opts_t *opts)
|
||||||
{
|
{
|
||||||
|
enum { OPT_CPID = 256, OPT_ECID = 257 };
|
||||||
|
|
||||||
static const struct option longopts[] = {
|
static const struct option longopts[] = {
|
||||||
{ "verbose", no_argument, NULL, 'v' },
|
{ "verbose", no_argument, NULL, 'v' },
|
||||||
{ "dry-run", no_argument, NULL, 'n' },
|
{ "dry-run", no_argument, NULL, 'n' },
|
||||||
{ "detect-only", no_argument, NULL, 'd' },
|
{ "detect-only", no_argument, NULL, 'd' },
|
||||||
{ "force-path-a", no_argument, NULL, 'a' },
|
{ "force-path-a", no_argument, NULL, 'a' },
|
||||||
{ "force-path-b", no_argument, NULL, 'b' },
|
{ "force-path-b", no_argument, NULL, 'b' },
|
||||||
|
{ "cpid", required_argument, NULL, OPT_CPID },
|
||||||
|
{ "ecid", required_argument, NULL, OPT_ECID },
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, NULL, 'h' },
|
||||||
{ NULL, 0, NULL, 0 }
|
{ NULL, 0, NULL, 0 }
|
||||||
};
|
};
|
||||||
|
|
@ -70,6 +75,14 @@ static int parse_args(int argc, char *argv[], cli_opts_t *opts)
|
||||||
case 'd': opts->detect_only = 1; break;
|
case 'd': opts->detect_only = 1; break;
|
||||||
case 'a': opts->force_path_a = 1; break;
|
case 'a': opts->force_path_a = 1; break;
|
||||||
case 'b': opts->force_path_b = 1; break;
|
case 'b': opts->force_path_b = 1; break;
|
||||||
|
case OPT_CPID:
|
||||||
|
opts->cpid_override = (uint32_t)strtoul(optarg, NULL, 16);
|
||||||
|
opts->has_cpid_override = 1;
|
||||||
|
break;
|
||||||
|
case OPT_ECID:
|
||||||
|
opts->ecid_override = (uint64_t)strtoull(optarg, NULL, 16);
|
||||||
|
opts->has_ecid_override = 1;
|
||||||
|
break;
|
||||||
case 'h': print_usage(argv[0]); return 1;
|
case 'h': print_usage(argv[0]); return 1;
|
||||||
default: print_usage(argv[0]); return -1;
|
default: print_usage(argv[0]); return -1;
|
||||||
}
|
}
|
||||||
|
|
@ -83,49 +96,34 @@ static int parse_args(int argc, char *argv[], cli_opts_t *opts)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Device detection: DFU first, then libimobiledevice */
|
|
||||||
static int detect_device(device_info_t *dev)
|
static int detect_device(device_info_t *dev)
|
||||||
{
|
{
|
||||||
libusb_device_handle *usb_handle = NULL;
|
libusb_device_handle *usb_handle = NULL;
|
||||||
|
|
||||||
memset(dev, 0, sizeof(*dev));
|
memset(dev, 0, sizeof(*dev));
|
||||||
|
|
||||||
/* Try DFU mode first */
|
|
||||||
if (usb_dfu_find(&usb_handle) == 0) {
|
if (usb_dfu_find(&usb_handle) == 0) {
|
||||||
log_info("Device found in DFU mode");
|
log_info("Device found in DFU mode");
|
||||||
|
|
||||||
uint32_t cpid = 0;
|
uint32_t cpid = 0;
|
||||||
uint64_t ecid = 0;
|
uint64_t ecid = 0;
|
||||||
char serial[DFU_SERIAL_MAX] = {0};
|
char serial[DFU_SERIAL_MAX] = {0};
|
||||||
|
|
||||||
if (usb_dfu_read_info(usb_handle, &cpid, &ecid,
|
if (usb_dfu_read_info(usb_handle, &cpid, &ecid,
|
||||||
serial, sizeof(serial)) < 0) {
|
serial, sizeof(serial)) < 0)
|
||||||
log_warn("Failed to read DFU serial info");
|
log_warn("Failed to read DFU serial info");
|
||||||
}
|
|
||||||
|
|
||||||
dev->cpid = cpid;
|
dev->cpid = cpid;
|
||||||
dev->ecid = ecid;
|
dev->ecid = ecid;
|
||||||
dev->is_dfu_mode = 1;
|
dev->is_dfu_mode = 1;
|
||||||
dev->usb = usb_handle;
|
dev->usb = usb_handle;
|
||||||
|
|
||||||
/* Copy serial into device serial field */
|
|
||||||
snprintf(dev->serial, sizeof(dev->serial), "%s", serial);
|
snprintf(dev->serial, sizeof(dev->serial), "%s", serial);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Fallback: normal mode via libimobiledevice */
|
|
||||||
log_info("No DFU device found, trying normal mode...");
|
log_info("No DFU device found, trying normal mode...");
|
||||||
|
|
||||||
if (device_detect(dev) < 0) {
|
if (device_detect(dev) < 0) {
|
||||||
log_error("No device detected. Is it connected via USB?");
|
log_error("No device detected. Is it connected via USB?");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (device_query_info(dev) < 0)
|
||||||
if (device_query_info(dev) < 0) {
|
|
||||||
log_warn("Incomplete device info (partial data may be available)");
|
log_warn("Incomplete device info (partial data may be available)");
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,7 +133,6 @@ static void enrich_chip_info(device_info_t *dev)
|
||||||
log_warn("CPID not available, chip lookup skipped");
|
log_warn("CPID not available, chip lookup skipped");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const chip_info_t *chip = chip_db_lookup(dev->cpid);
|
const chip_info_t *chip = chip_db_lookup(dev->cpid);
|
||||||
if (!chip) {
|
if (!chip) {
|
||||||
log_warn("CPID 0x%04X not found in chip database", dev->cpid);
|
log_warn("CPID 0x%04X not found in chip database", dev->cpid);
|
||||||
|
|
@ -143,10 +140,8 @@ static void enrich_chip_info(device_info_t *dev)
|
||||||
dev->checkm8_vulnerable = 0;
|
dev->checkm8_vulnerable = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(dev->chip_name, sizeof(dev->chip_name), "%s", chip->name);
|
snprintf(dev->chip_name, sizeof(dev->chip_name), "%s", chip->name);
|
||||||
dev->checkm8_vulnerable = chip->checkm8_vulnerable;
|
dev->checkm8_vulnerable = chip->checkm8_vulnerable;
|
||||||
|
|
||||||
log_debug("Chip: %s (CPID 0x%04X) -- checkm8 %s",
|
log_debug("Chip: %s (CPID 0x%04X) -- checkm8 %s",
|
||||||
chip->name, chip->cpid,
|
chip->name, chip->cpid,
|
||||||
chip->checkm8_vulnerable ? "vulnerable" : "not vulnerable");
|
chip->checkm8_vulnerable ? "vulnerable" : "not vulnerable");
|
||||||
|
|
@ -158,52 +153,33 @@ static void register_modules(void)
|
||||||
log_warn("Failed to register Path A module");
|
log_warn("Failed to register Path A module");
|
||||||
if (bypass_register(&path_b_module) < 0)
|
if (bypass_register(&path_b_module) < 0)
|
||||||
log_warn("Failed to register Path B module");
|
log_warn("Failed to register Path B module");
|
||||||
|
|
||||||
log_debug("Registered %d bypass module(s)", bypass_count());
|
log_debug("Registered %d bypass module(s)", bypass_count());
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_module_diagnostics(const device_info_t *dev)
|
static void print_module_diagnostics(const device_info_t *dev)
|
||||||
{
|
{
|
||||||
log_error("No compatible bypass module for this device");
|
log_error("No compatible bypass module for this device");
|
||||||
log_error("--- Diagnostic info ---");
|
log_error(" DFU=%s CPID=0x%04X Chip=%s checkm8=%s Product=%s",
|
||||||
log_error(" DFU mode: %s", dev->is_dfu_mode ? "YES" : "NO");
|
dev->is_dfu_mode ? "YES" : "NO", dev->cpid,
|
||||||
log_error(" CPID: 0x%04X", dev->cpid);
|
dev->chip_name[0] ? dev->chip_name : "(unknown)",
|
||||||
log_error(" Chip: %s", dev->chip_name[0] ? dev->chip_name : "(unknown)");
|
dev->checkm8_vulnerable ? "YES" : "NO",
|
||||||
log_error(" checkm8: %s", dev->checkm8_vulnerable ? "vulnerable" : "not vulnerable");
|
dev->product_type[0] ? dev->product_type : "(unknown)");
|
||||||
log_error(" Product: %s", dev->product_type[0] ? dev->product_type : "(unknown)");
|
|
||||||
|
|
||||||
if (!dev->is_dfu_mode) {
|
if (!dev->is_dfu_mode)
|
||||||
log_error("Both bypass paths require DFU mode.");
|
log_error("Both paths require DFU mode. Use ./start.sh or enter DFU manually.");
|
||||||
log_error("Run ./start.sh for guided DFU entry, or enter DFU manually.");
|
else if (dev->cpid == 0)
|
||||||
} else if (dev->cpid == 0) {
|
log_error("CPID is 0x0000 -- try --cpid to set manually.");
|
||||||
log_error("CPID is 0x0000 -- device chip not identified.");
|
else if (dev->chip_name[0] == '\0' || strcmp(dev->chip_name, "Unknown") == 0)
|
||||||
log_error("Ensure device is properly in DFU mode (screen must be BLACK).");
|
log_error("Chip CPID 0x%04X not in database.", dev->cpid);
|
||||||
} else if (dev->chip_name[0] == '\0' ||
|
|
||||||
strcmp(dev->chip_name, "Unknown") == 0) {
|
|
||||||
log_error("Chip CPID 0x%04X not found in database.", dev->cpid);
|
|
||||||
}
|
|
||||||
|
|
||||||
log_error("-----------------------");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const bypass_module_t *select_module(device_info_t *dev,
|
static const bypass_module_t *select_module(device_info_t *dev,
|
||||||
const cli_opts_t *opts)
|
const cli_opts_t *opts)
|
||||||
{
|
{
|
||||||
if (opts->force_path_a) {
|
if (opts->force_path_a) { log_info("Path A forced"); return &path_a_module; }
|
||||||
log_info("Path A forced by user");
|
if (opts->force_path_b) { log_info("Path B forced"); return &path_b_module; }
|
||||||
return &path_a_module;
|
|
||||||
}
|
|
||||||
if (opts->force_path_b) {
|
|
||||||
log_info("Path B forced by user");
|
|
||||||
return &path_b_module;
|
|
||||||
}
|
|
||||||
|
|
||||||
const bypass_module_t *mod = bypass_select(dev);
|
const bypass_module_t *mod = bypass_select(dev);
|
||||||
if (!mod) {
|
if (!mod) { print_module_diagnostics(dev); return NULL; }
|
||||||
print_module_diagnostics(dev);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
log_info("Auto-selected module: %s", mod->name);
|
log_info("Auto-selected module: %s", mod->name);
|
||||||
return mod;
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
@ -226,51 +202,57 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
print_banner();
|
print_banner();
|
||||||
|
|
||||||
/* Parse CLI arguments */
|
|
||||||
ret = parse_args(argc, argv, &opts);
|
ret = parse_args(argc, argv, &opts);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return (ret > 0) ? 0 : 1; /* help = 0, error = 1 */
|
return (ret > 0) ? 0 : 1;
|
||||||
|
|
||||||
if (opts.verbose)
|
if (opts.verbose)
|
||||||
log_set_level(LOG_DEBUG);
|
log_set_level(LOG_DEBUG);
|
||||||
|
|
||||||
/* Initialize libusb */
|
|
||||||
if (usb_dfu_init() < 0) {
|
if (usb_dfu_init() < 0) {
|
||||||
log_error("Failed to initialize USB subsystem");
|
log_error("Failed to initialize USB subsystem");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Detect device */
|
|
||||||
if (detect_device(&dev) < 0) {
|
if (detect_device(&dev) < 0) {
|
||||||
usb_dfu_cleanup();
|
usb_dfu_cleanup();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enrich with chip database */
|
/* Apply CLI overrides for CPID/ECID */
|
||||||
enrich_chip_info(&dev);
|
if (opts.has_cpid_override) {
|
||||||
|
if (dev.cpid == 0) {
|
||||||
|
dev.cpid = opts.cpid_override;
|
||||||
|
log_info("CPID overridden: 0x%04X (from --cpid)", dev.cpid);
|
||||||
|
} else {
|
||||||
|
log_info("CPID already detected (0x%04X), ignoring --cpid override",
|
||||||
|
dev.cpid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (opts.has_ecid_override) {
|
||||||
|
if (dev.ecid == 0) {
|
||||||
|
dev.ecid = opts.ecid_override;
|
||||||
|
log_info("ECID overridden: 0x%llX (from --ecid)",
|
||||||
|
(unsigned long long)dev.ecid);
|
||||||
|
} else {
|
||||||
|
log_info("ECID already detected (0x%llX), ignoring --ecid override",
|
||||||
|
(unsigned long long)dev.ecid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Print device info */
|
enrich_chip_info(&dev);
|
||||||
device_print_info(&dev);
|
device_print_info(&dev);
|
||||||
|
|
||||||
/* Early exit for detect-only mode */
|
|
||||||
if (opts.detect_only) {
|
if (opts.detect_only) {
|
||||||
log_info("Detect-only mode, exiting");
|
log_info("Detect-only mode, exiting");
|
||||||
cleanup(&dev);
|
cleanup(&dev);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register bypass modules */
|
|
||||||
register_modules();
|
register_modules();
|
||||||
bypass_list();
|
bypass_list();
|
||||||
|
|
||||||
/* Select module */
|
|
||||||
const bypass_module_t *mod = select_module(&dev, &opts);
|
const bypass_module_t *mod = select_module(&dev, &opts);
|
||||||
if (!mod) {
|
if (!mod) { cleanup(&dev); return 1; }
|
||||||
cleanup(&dev);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Dry-run: show what would execute */
|
|
||||||
if (opts.dry_run) {
|
if (opts.dry_run) {
|
||||||
printf("[dry-run] Would execute: %s\n", mod->name);
|
printf("[dry-run] Would execute: %s\n", mod->name);
|
||||||
printf("[dry-run] Description: %s\n", mod->description);
|
printf("[dry-run] Description: %s\n", mod->description);
|
||||||
|
|
@ -278,17 +260,13 @@ int main(int argc, char *argv[])
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Execute bypass */
|
|
||||||
log_info("Executing module: %s", mod->name);
|
log_info("Executing module: %s", mod->name);
|
||||||
ret = bypass_execute(mod, &dev);
|
ret = bypass_execute(mod, &dev);
|
||||||
|
if (ret == 0)
|
||||||
if (ret == 0) {
|
|
||||||
printf("\n[+] Bypass completed successfully.\n");
|
printf("\n[+] Bypass completed successfully.\n");
|
||||||
} else {
|
else
|
||||||
printf("\n[-] Bypass failed (error %d).\n", ret);
|
printf("\n[-] Bypass failed (error %d).\n", ret);
|
||||||
}
|
|
||||||
|
|
||||||
/* Cleanup */
|
|
||||||
cleanup(&dev);
|
cleanup(&dev);
|
||||||
return (ret == 0) ? 0 : 1;
|
return (ret == 0) ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue