feat(core): Add main entry point and start.sh guided wrapper
CLI entry point with --verbose, --dry-run, --detect-only, and --force-path-a/b flags. Detects DFU mode via libusb first, falls back to libimobiledevice. Registers Path A and Path B bypass modules. start.sh guides user through DFU mode entry. Files created: - src/main.c - start.sh Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ef6bff0999
commit
7b7a307ab1
2 changed files with 388 additions and 0 deletions
271
src/main.c
Normal file
271
src/main.c
Normal file
|
|
@ -0,0 +1,271 @@
|
||||||
|
/*
|
||||||
|
* main.c -- Itr4m 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _GNU_SOURCE
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
|
#include "itr4m.h"
|
||||||
|
#include "device/device.h"
|
||||||
|
#include "device/usb_dfu.h"
|
||||||
|
#include "device/chip_db.h"
|
||||||
|
#include "bypass/bypass.h"
|
||||||
|
#include "bypass/path_a.h"
|
||||||
|
#include "bypass/path_b.h"
|
||||||
|
#include "util/log.h"
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int verbose;
|
||||||
|
int dry_run;
|
||||||
|
int detect_only;
|
||||||
|
int force_path_a;
|
||||||
|
int force_path_b;
|
||||||
|
} cli_opts_t;
|
||||||
|
|
||||||
|
static void print_banner(void)
|
||||||
|
{
|
||||||
|
printf("========================================\n");
|
||||||
|
printf(" Itr4m v%s\n", ITR4M_VERSION);
|
||||||
|
printf(" Activation lock bypass research tool\n");
|
||||||
|
printf("========================================\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void print_usage(const char *prog)
|
||||||
|
{
|
||||||
|
printf("Usage: %s [OPTIONS]\n\n", prog);
|
||||||
|
printf("Options:\n");
|
||||||
|
printf(" -v, --verbose Enable debug logging\n");
|
||||||
|
printf(" -n, --dry-run Show what would run, do not execute\n");
|
||||||
|
printf(" -d, --detect-only Detect device and exit\n");
|
||||||
|
printf(" -a, --force-path-a Force Path A (checkm8, A5-A11)\n");
|
||||||
|
printf(" -b, --force-path-b Force Path B (identity, A12+)\n");
|
||||||
|
printf(" -h, --help Show this help message\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
static int parse_args(int argc, char *argv[], cli_opts_t *opts)
|
||||||
|
{
|
||||||
|
static const struct option longopts[] = {
|
||||||
|
{ "verbose", no_argument, NULL, 'v' },
|
||||||
|
{ "dry-run", no_argument, NULL, 'n' },
|
||||||
|
{ "detect-only", no_argument, NULL, 'd' },
|
||||||
|
{ "force-path-a", no_argument, NULL, 'a' },
|
||||||
|
{ "force-path-b", no_argument, NULL, 'b' },
|
||||||
|
{ "help", no_argument, NULL, 'h' },
|
||||||
|
{ NULL, 0, NULL, 0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
memset(opts, 0, sizeof(*opts));
|
||||||
|
|
||||||
|
int c;
|
||||||
|
while ((c = getopt_long(argc, argv, "vndabh", longopts, NULL)) != -1) {
|
||||||
|
switch (c) {
|
||||||
|
case 'v': opts->verbose = 1; break;
|
||||||
|
case 'n': opts->dry_run = 1; break;
|
||||||
|
case 'd': opts->detect_only = 1; break;
|
||||||
|
case 'a': opts->force_path_a = 1; break;
|
||||||
|
case 'b': opts->force_path_b = 1; break;
|
||||||
|
case 'h': print_usage(argv[0]); return 1;
|
||||||
|
default: print_usage(argv[0]); return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opts->force_path_a && opts->force_path_b) {
|
||||||
|
log_error("Cannot force both Path A and Path B simultaneously");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Device detection: DFU first, then libimobiledevice */
|
||||||
|
static int detect_device(device_info_t *dev)
|
||||||
|
{
|
||||||
|
libusb_device_handle *usb_handle = NULL;
|
||||||
|
|
||||||
|
memset(dev, 0, sizeof(*dev));
|
||||||
|
|
||||||
|
/* Try DFU mode first */
|
||||||
|
if (usb_dfu_find(&usb_handle) == 0) {
|
||||||
|
log_info("Device found in DFU mode");
|
||||||
|
|
||||||
|
uint32_t cpid = 0;
|
||||||
|
uint64_t ecid = 0;
|
||||||
|
char serial[DFU_SERIAL_MAX] = {0};
|
||||||
|
|
||||||
|
if (usb_dfu_read_info(usb_handle, &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;
|
||||||
|
|
||||||
|
/* Copy serial into device serial field */
|
||||||
|
snprintf(dev->serial, sizeof(dev->serial), "%s", serial);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Fallback: normal mode via libimobiledevice */
|
||||||
|
log_info("No DFU device found, trying normal mode...");
|
||||||
|
|
||||||
|
if (device_detect(dev) < 0) {
|
||||||
|
log_error("No device detected. Is it connected via USB?");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (device_query_info(dev) < 0) {
|
||||||
|
log_warn("Incomplete device info (partial data may be available)");
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void enrich_chip_info(device_info_t *dev)
|
||||||
|
{
|
||||||
|
if (dev->cpid == 0) {
|
||||||
|
log_warn("CPID not available, chip lookup skipped");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const chip_info_t *chip = chip_db_lookup(dev->cpid);
|
||||||
|
if (!chip) {
|
||||||
|
log_warn("CPID 0x%04X not found in chip database", dev->cpid);
|
||||||
|
snprintf(dev->chip_name, sizeof(dev->chip_name), "Unknown");
|
||||||
|
dev->checkm8_vulnerable = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(dev->chip_name, sizeof(dev->chip_name), "%s", chip->name);
|
||||||
|
dev->checkm8_vulnerable = chip->checkm8_vulnerable;
|
||||||
|
|
||||||
|
log_debug("Chip: %s (CPID 0x%04X) -- checkm8 %s",
|
||||||
|
chip->name, chip->cpid,
|
||||||
|
chip->checkm8_vulnerable ? "vulnerable" : "not vulnerable");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void register_modules(void)
|
||||||
|
{
|
||||||
|
if (bypass_register(&path_a_module) < 0)
|
||||||
|
log_warn("Failed to register Path A module");
|
||||||
|
if (bypass_register(&path_b_module) < 0)
|
||||||
|
log_warn("Failed to register Path B module");
|
||||||
|
|
||||||
|
log_debug("Registered %d bypass module(s)", bypass_count());
|
||||||
|
}
|
||||||
|
|
||||||
|
static const bypass_module_t *select_module(device_info_t *dev,
|
||||||
|
const cli_opts_t *opts)
|
||||||
|
{
|
||||||
|
if (opts->force_path_a) {
|
||||||
|
log_info("Path A forced by user");
|
||||||
|
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);
|
||||||
|
if (!mod) {
|
||||||
|
log_error("No compatible bypass module for this device");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
log_info("Auto-selected module: %s", mod->name);
|
||||||
|
return mod;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cleanup(device_info_t *dev)
|
||||||
|
{
|
||||||
|
if (dev->usb) {
|
||||||
|
usb_dfu_close(dev->usb);
|
||||||
|
dev->usb = NULL;
|
||||||
|
}
|
||||||
|
device_free(dev);
|
||||||
|
usb_dfu_cleanup();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
cli_opts_t opts;
|
||||||
|
device_info_t dev;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
print_banner();
|
||||||
|
|
||||||
|
/* Parse CLI arguments */
|
||||||
|
ret = parse_args(argc, argv, &opts);
|
||||||
|
if (ret != 0)
|
||||||
|
return (ret > 0) ? 0 : 1; /* help = 0, error = 1 */
|
||||||
|
|
||||||
|
if (opts.verbose)
|
||||||
|
log_set_level(LOG_DEBUG);
|
||||||
|
|
||||||
|
/* Initialize libusb */
|
||||||
|
if (usb_dfu_init() < 0) {
|
||||||
|
log_error("Failed to initialize USB subsystem");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Detect device */
|
||||||
|
if (detect_device(&dev) < 0) {
|
||||||
|
usb_dfu_cleanup();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Enrich with chip database */
|
||||||
|
enrich_chip_info(&dev);
|
||||||
|
|
||||||
|
/* Print device info */
|
||||||
|
device_print_info(&dev);
|
||||||
|
|
||||||
|
/* Early exit for detect-only mode */
|
||||||
|
if (opts.detect_only) {
|
||||||
|
log_info("Detect-only mode, exiting");
|
||||||
|
cleanup(&dev);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Register bypass modules */
|
||||||
|
register_modules();
|
||||||
|
bypass_list();
|
||||||
|
|
||||||
|
/* Select module */
|
||||||
|
const bypass_module_t *mod = select_module(&dev, &opts);
|
||||||
|
if (!mod) {
|
||||||
|
cleanup(&dev);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Dry-run: show what would execute */
|
||||||
|
if (opts.dry_run) {
|
||||||
|
printf("[dry-run] Would execute: %s\n", mod->name);
|
||||||
|
printf("[dry-run] Description: %s\n", mod->description);
|
||||||
|
cleanup(&dev);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Execute bypass */
|
||||||
|
log_info("Executing module: %s", mod->name);
|
||||||
|
ret = bypass_execute(mod, &dev);
|
||||||
|
|
||||||
|
if (ret == 0) {
|
||||||
|
printf("\n[+] Bypass completed successfully.\n");
|
||||||
|
} else {
|
||||||
|
printf("\n[-] Bypass failed (error %d).\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cleanup */
|
||||||
|
cleanup(&dev);
|
||||||
|
return (ret == 0) ? 0 : 1;
|
||||||
|
}
|
||||||
117
start.sh
Executable file
117
start.sh
Executable file
|
|
@ -0,0 +1,117 @@
|
||||||
|
#!/bin/bash
|
||||||
|
# Itr4m -- Guided activation lock bypass wrapper
|
||||||
|
# Detects device mode, guides DFU entry if needed, runs itr4m binary.
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
BINARY="$SCRIPT_DIR/itr4m"
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
# Banner #
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
|
||||||
|
print_banner() {
|
||||||
|
echo "========================================"
|
||||||
|
echo " Itr4m v0.1.0"
|
||||||
|
echo " Activation lock bypass research tool"
|
||||||
|
echo "========================================"
|
||||||
|
echo ""
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
# Dependency checks #
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
|
||||||
|
check_deps() {
|
||||||
|
if [ ! -x "$BINARY" ]; then
|
||||||
|
echo "[-] Binary not found: $BINARY"
|
||||||
|
echo " Run 'make' first to build the project."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
# Device detection #
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
|
||||||
|
check_dfu() {
|
||||||
|
# Look for Apple DFU device (PID 0x1227) in system USB data
|
||||||
|
if system_profiler SPUSBDataType 2>/dev/null | grep -q "0x1227"; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
check_normal() {
|
||||||
|
# Check if libimobiledevice can see a device
|
||||||
|
if command -v idevice_id >/dev/null 2>&1; then
|
||||||
|
local devices
|
||||||
|
devices="$(idevice_id -l 2>/dev/null || true)"
|
||||||
|
if [ -n "$devices" ]; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
# DFU mode guide #
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
|
||||||
|
guide_dfu() {
|
||||||
|
echo "[*] No device detected in normal or DFU mode."
|
||||||
|
echo ""
|
||||||
|
echo "To enter DFU mode:"
|
||||||
|
echo ""
|
||||||
|
echo " For iPhone 7 / iPad (Home button):"
|
||||||
|
echo " 1. Connect device to Mac via USB"
|
||||||
|
echo " 2. Power off the device completely"
|
||||||
|
echo " 3. Hold Power + Home for 10 seconds"
|
||||||
|
echo " 4. Release Power, keep holding Home for 5 more seconds"
|
||||||
|
echo " 5. Screen must be BLACK (not Apple logo)"
|
||||||
|
echo ""
|
||||||
|
echo " For iPhone 8+ / iPad Pro (Face ID):"
|
||||||
|
echo " 1. Connect device to Mac via USB"
|
||||||
|
echo " 2. Quick-press Volume Up, then Volume Down"
|
||||||
|
echo " 3. Hold Side button until screen goes black"
|
||||||
|
echo " 4. Hold Side + Volume Down for 5 seconds"
|
||||||
|
echo " 5. Release Side, keep holding Volume Down for 10 seconds"
|
||||||
|
echo " 6. Screen must be BLACK (not Apple logo)"
|
||||||
|
echo ""
|
||||||
|
echo "If you see the Apple logo, you are in recovery mode (not DFU)."
|
||||||
|
echo "Start over from step 2."
|
||||||
|
echo ""
|
||||||
|
echo "Press Enter when the device is in DFU mode..."
|
||||||
|
read -r
|
||||||
|
}
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
# Main #
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
|
||||||
|
print_banner
|
||||||
|
check_deps
|
||||||
|
|
||||||
|
if check_dfu; then
|
||||||
|
echo "[+] Device detected in DFU mode"
|
||||||
|
elif check_normal; then
|
||||||
|
echo "[+] Device detected in normal mode"
|
||||||
|
else
|
||||||
|
guide_dfu
|
||||||
|
|
||||||
|
# Re-check after user claims DFU entry
|
||||||
|
if check_dfu; then
|
||||||
|
echo "[+] Device detected in DFU mode"
|
||||||
|
else
|
||||||
|
echo "[-] Device not detected in DFU mode."
|
||||||
|
echo " Verify the USB connection and try again."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "[*] Starting itr4m..."
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
exec "$BINARY" "$@"
|
||||||
Loading…
Add table
Add a link
Reference in a new issue