build(deps): fix pkg-config skew, libusb include, libplist/libirecovery drift
Sync PKGCONFIG_DEPS with Makefile (add libcurl); normalize <libusb.h> include across 6 files; add compat shims for libplist 2.2/2.3 and libirecovery IRECV_SEND_OPT_DFU_NOTIFY_FINISH; add pacman/zypper/apk installer branches; drop bogus info->pid read in path_b_identity.c in favor of irecv_get_mode(). Extend the mock libirecovery to expose irecv_get_mode() so the mock test build keeps passing against the new call site. Add Makefile compile canaries that emit -DTP_PLIST_HAS_MEM_FREE, -DTP_PLIST_HAS_FMT_ARG, and -DTP_IRECV_HAS_NOTIFY_FINISH plus a .build-flags diagnostic file consumed by tr4mpass doctor. Files modified: - Makefile - start.sh - start-helpers.sh - include/compat/plist_compat.h (new) - include/compat/libirecovery_compat.h (new) - include/util/usb_helpers.h - include/util/plist_helpers.h - include/exploit/dfu_proto.h - include/device/device.h - include/device/usb_dfu.h - include/activation/activation.h - include/activation/record.h - src/bypass/path_b_identity.c - src/bypass/path_b.c - src/bypass/path_a_ramdisk.c - src/activation/session_online.c - tests/mocks/mock_irecv_sym.c - .gitignore Closes: #70, #74, #67, #54, #51, #44, #21, #55, #31, #24, #19
This commit is contained in:
parent
d18b57a66f
commit
9bd1a75b2d
18 changed files with 257 additions and 47 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -10,6 +10,7 @@ itr4m
|
||||||
tr4mpass
|
tr4mpass
|
||||||
tests/run_tests
|
tests/run_tests
|
||||||
tests/run_mock_tests
|
tests/run_mock_tests
|
||||||
|
.build-flags
|
||||||
|
|
||||||
# OS files
|
# OS files
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
|
||||||
59
Makefile
59
Makefile
|
|
@ -11,12 +11,41 @@ LDFLAGS += $(shell pkg-config --libs $(PKG_LIBS) 2>/dev/null)
|
||||||
|
|
||||||
$(foreach lib,$(PKG_LIBS),$(if $(shell pkg-config --exists $(lib) 2>/dev/null && echo ok),,$(warning Library $(lib) not found by pkg-config)))
|
$(foreach lib,$(PKG_LIBS),$(if $(shell pkg-config --exists $(lib) 2>/dev/null && echo ok),,$(warning Library $(lib) not found by pkg-config)))
|
||||||
|
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
# Feature probes for optional library symbols. #
|
||||||
|
# #
|
||||||
|
# libplist 2.3 added plist_mem_free() and a 4-arg plist_from_memory. #
|
||||||
|
# Older libirecovery lacked IRECV_SEND_OPT_DFU_NOTIFY_FINISH. #
|
||||||
|
# We probe by compiling a canary; on success we emit -D flags so the #
|
||||||
|
# include/compat/*.h shims pick the right branch. Results are also #
|
||||||
|
# written to .build-flags for `tr4mpass doctor` (task 005) to #
|
||||||
|
# surface at runtime. #
|
||||||
|
# ------------------------------------------------------------------ #
|
||||||
|
|
||||||
|
PROBE_CFLAGS := $(shell pkg-config --cflags libplist-2.0 libirecovery-1.0 2>/dev/null)
|
||||||
|
|
||||||
|
# `#` is a make comment even inside $(shell ...), so emit the `#include`
|
||||||
|
# via printf's octal escape (\043).
|
||||||
|
HAVE_PLIST_MEM_FREE := $(shell printf '\043include <plist/plist.h>\nint main(void){plist_mem_free((void*)0);return 0;}\n' | $(CC) $(PROBE_CFLAGS) -x c -c - -o /dev/null 2>/dev/null && echo 1 || echo 0)
|
||||||
|
HAVE_PLIST_FROM_MEM4 := $(shell printf '\043include <plist/plist.h>\nint main(void){plist_t p=0; plist_from_memory("",0,&p,(plist_format_t*)0);return 0;}\n' | $(CC) $(PROBE_CFLAGS) -x c -c - -o /dev/null 2>/dev/null && echo 1 || echo 0)
|
||||||
|
HAVE_IRECV_NOTIFY := $(shell printf '\043include <libirecovery.h>\nint main(void){return (int)IRECV_SEND_OPT_DFU_NOTIFY_FINISH;}\n' | $(CC) $(PROBE_CFLAGS) -x c -c - -o /dev/null 2>/dev/null && echo 1 || echo 0)
|
||||||
|
|
||||||
|
ifeq ($(HAVE_PLIST_MEM_FREE),1)
|
||||||
|
CFLAGS += -DTP_PLIST_HAS_MEM_FREE=1
|
||||||
|
endif
|
||||||
|
ifeq ($(HAVE_PLIST_FROM_MEM4),1)
|
||||||
|
CFLAGS += -DTP_PLIST_HAS_FMT_ARG=1
|
||||||
|
endif
|
||||||
|
ifeq ($(HAVE_IRECV_NOTIFY),1)
|
||||||
|
CFLAGS += -DTP_IRECV_HAS_NOTIFY_FINISH=1
|
||||||
|
endif
|
||||||
|
|
||||||
# Auto-discover all C sources under src/
|
# Auto-discover all C sources under src/
|
||||||
SRCS = $(shell find src -name '*.c')
|
SRCS = $(shell find src -name '*.c')
|
||||||
OBJS = $(SRCS:.c=.o)
|
OBJS = $(SRCS:.c=.o)
|
||||||
TARGET = tr4mpass
|
TARGET = tr4mpass
|
||||||
|
|
||||||
all: $(TARGET)
|
all: .build-flags $(TARGET)
|
||||||
|
|
||||||
$(TARGET): $(OBJS)
|
$(TARGET): $(OBJS)
|
||||||
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
@ -24,9 +53,16 @@ $(TARGET): $(OBJS)
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
$(CC) $(CFLAGS) -Iinclude -c -o $@ $<
|
$(CC) $(CFLAGS) -Iinclude -c -o $@ $<
|
||||||
|
|
||||||
|
# .build-flags is a diagnostic file consumed by `tr4mpass doctor`.
|
||||||
|
# It records which optional symbols the probes detected on this host.
|
||||||
|
.build-flags:
|
||||||
|
@printf 'HAVE_PLIST_MEM_FREE=%s\n' '$(HAVE_PLIST_MEM_FREE)' > $@
|
||||||
|
@printf 'HAVE_PLIST_FROM_MEM4=%s\n' '$(HAVE_PLIST_FROM_MEM4)' >> $@
|
||||||
|
@printf 'HAVE_IRECV_NOTIFY_FINISH=%s\n' '$(HAVE_IRECV_NOTIFY)' >> $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
find src -name '*.o' -delete
|
find src -name '*.o' -delete
|
||||||
rm -f $(TARGET) $(TEST_TARGET) $(MOCK_TARGET)
|
rm -f $(TARGET) $(TEST_TARGET) $(MOCK_TARGET) .build-flags
|
||||||
find tests -name '*.o' -delete 2>/dev/null || true
|
find tests -name '*.o' -delete 2>/dev/null || true
|
||||||
|
|
||||||
# ------------------------------------------------------------------ #
|
# ------------------------------------------------------------------ #
|
||||||
|
|
@ -88,10 +124,25 @@ MOCK_TARGET = tests/run_mock_tests
|
||||||
|
|
||||||
# Only link libs that the SUT still needs at runtime and we did NOT mock.
|
# Only link libs that the SUT still needs at runtime and we did NOT mock.
|
||||||
MOCK_PKG_LIBS = libplist-2.0 openssl
|
MOCK_PKG_LIBS = libplist-2.0 openssl
|
||||||
|
# Headers-only pkg-config libs: symbols are mocked so we do NOT link them,
|
||||||
|
# but SUT sources still #include their public headers, so we need the
|
||||||
|
# include paths at compile time. libusb-1.0 lives under
|
||||||
|
# <prefix>/include/libusb-1.0/ on every distro; without the -I flag the
|
||||||
|
# `#include <libusb.h>` in include/device/device.h cannot be resolved.
|
||||||
|
MOCK_HEADER_LIBS = libusb-1.0 libimobiledevice-1.0 libirecovery-1.0 libssh2 libcurl
|
||||||
MOCK_CFLAGS = -Wall -Wextra -std=c99 -D_GNU_SOURCE -O2 \
|
MOCK_CFLAGS = -Wall -Wextra -std=c99 -D_GNU_SOURCE -O2 \
|
||||||
$(shell pkg-config --cflags $(MOCK_PKG_LIBS) 2>/dev/null) \
|
$(shell pkg-config --cflags $(MOCK_PKG_LIBS) $(MOCK_HEADER_LIBS) 2>/dev/null) \
|
||||||
-Iinclude -Itests -Itests/integration -Itests/mocks \
|
-Iinclude -Itests -Itests/integration -Itests/mocks \
|
||||||
-DTEST_MODE -DUNIT_TEST
|
-DTEST_MODE -DUNIT_TEST
|
||||||
|
ifeq ($(HAVE_PLIST_MEM_FREE),1)
|
||||||
|
MOCK_CFLAGS += -DTP_PLIST_HAS_MEM_FREE=1
|
||||||
|
endif
|
||||||
|
ifeq ($(HAVE_PLIST_FROM_MEM4),1)
|
||||||
|
MOCK_CFLAGS += -DTP_PLIST_HAS_FMT_ARG=1
|
||||||
|
endif
|
||||||
|
ifeq ($(HAVE_IRECV_NOTIFY),1)
|
||||||
|
MOCK_CFLAGS += -DTP_IRECV_HAS_NOTIFY_FINISH=1
|
||||||
|
endif
|
||||||
MOCK_LDFLAGS = $(shell pkg-config --libs $(MOCK_PKG_LIBS) 2>/dev/null)
|
MOCK_LDFLAGS = $(shell pkg-config --libs $(MOCK_PKG_LIBS) 2>/dev/null)
|
||||||
|
|
||||||
test-mocks: $(MOCK_TARGET)
|
test-mocks: $(MOCK_TARGET)
|
||||||
|
|
@ -100,4 +151,4 @@ test-mocks: $(MOCK_TARGET)
|
||||||
$(MOCK_TARGET): $(MOCK_ALL_SRCS)
|
$(MOCK_TARGET): $(MOCK_ALL_SRCS)
|
||||||
$(CC) $(MOCK_CFLAGS) -o $@ $^ $(MOCK_LDFLAGS)
|
$(CC) $(MOCK_CFLAGS) -o $@ $^ $(MOCK_LDFLAGS)
|
||||||
|
|
||||||
.PHONY: all clean test test-mocks
|
.PHONY: all clean test test-mocks .build-flags
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <plist/plist.h>
|
#include "compat/plist_compat.h"
|
||||||
#include <libimobiledevice/libimobiledevice.h>
|
#include <libimobiledevice/libimobiledevice.h>
|
||||||
#include <libimobiledevice/mobileactivation.h>
|
#include <libimobiledevice/mobileactivation.h>
|
||||||
#include "device/device.h"
|
#include "device/device.h"
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#define RECORD_H
|
#define RECORD_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <plist/plist.h>
|
#include "compat/plist_compat.h"
|
||||||
#include <libimobiledevice/lockdown.h>
|
#include <libimobiledevice/lockdown.h>
|
||||||
#include "device/device.h"
|
#include "device/device.h"
|
||||||
|
|
||||||
|
|
|
||||||
28
include/compat/libirecovery_compat.h
Normal file
28
include/compat/libirecovery_compat.h
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
#ifndef TP_LIBIRECOVERY_COMPAT_H
|
||||||
|
#define TP_LIBIRECOVERY_COMPAT_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* libirecovery_compat.h -- libirecovery API drift shim.
|
||||||
|
*
|
||||||
|
* Older libirecovery releases lacked IRECV_SEND_OPT_DFU_NOTIFY_FINISH,
|
||||||
|
* the send-flag that instructs irecv_send_file() to terminate a DFU
|
||||||
|
* transfer with a zero-length packet. The Makefile probes for the
|
||||||
|
* symbol and passes -DTP_IRECV_HAS_NOTIFY_FINISH when present.
|
||||||
|
*
|
||||||
|
* When absent we provide a no-op flag value and set
|
||||||
|
* TP_IRECV_NEEDS_MANUAL_ZLP=1 so callers can send the ZLP by hand
|
||||||
|
* after irecv_send_file() returns.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <libirecovery.h>
|
||||||
|
|
||||||
|
#ifdef TP_IRECV_HAS_NOTIFY_FINISH
|
||||||
|
#define TP_IRECV_NEEDS_MANUAL_ZLP 0
|
||||||
|
#else
|
||||||
|
#ifndef IRECV_SEND_OPT_DFU_NOTIFY_FINISH
|
||||||
|
#define IRECV_SEND_OPT_DFU_NOTIFY_FINISH 0
|
||||||
|
#endif
|
||||||
|
#define TP_IRECV_NEEDS_MANUAL_ZLP 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* TP_LIBIRECOVERY_COMPAT_H */
|
||||||
59
include/compat/plist_compat.h
Normal file
59
include/compat/plist_compat.h
Normal file
|
|
@ -0,0 +1,59 @@
|
||||||
|
#ifndef TP_PLIST_COMPAT_H
|
||||||
|
#define TP_PLIST_COMPAT_H
|
||||||
|
|
||||||
|
/*
|
||||||
|
* plist_compat.h -- libplist API drift shim.
|
||||||
|
*
|
||||||
|
* libplist 2.3.0 introduced plist_mem_free() and expanded
|
||||||
|
* plist_from_memory() to a 4-arg form that also reports the parsed
|
||||||
|
* format. Older distros still ship 2.2.x, so we detect both at build
|
||||||
|
* time. The Makefile runs compile canaries and passes
|
||||||
|
* -DTP_PLIST_HAS_MEM_FREE / -DTP_PLIST_HAS_FMT_ARG when the installed
|
||||||
|
* header provides them; the header falls back otherwise.
|
||||||
|
*
|
||||||
|
* Callers should:
|
||||||
|
* - free plist-allocated buffers via plist_mem_free() (falls back
|
||||||
|
* to free() when the symbol is unavailable)
|
||||||
|
* - parse in-memory plists via tp_plist_from_memory(), which maps
|
||||||
|
* to the 3-arg or 4-arg form as detected at build time.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <plist/plist.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#ifndef TP_PLIST_HAS_MEM_FREE
|
||||||
|
/* Pre-2.3: no plist_mem_free(); libplist used plain malloc/free. */
|
||||||
|
#ifndef plist_mem_free
|
||||||
|
#define plist_mem_free(p) free(p)
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static inline void tp_plist_mem_free(void *p)
|
||||||
|
{
|
||||||
|
if (p) plist_mem_free(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef TP_PLIST_HAS_FMT_ARG
|
||||||
|
/* 4-arg form: (data, length, out, format_out). */
|
||||||
|
static inline int tp_plist_from_memory(const char *data,
|
||||||
|
uint32_t length,
|
||||||
|
plist_t *out,
|
||||||
|
plist_format_t *fmt_out)
|
||||||
|
{
|
||||||
|
return (int)plist_from_memory(data, length, out, fmt_out);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
/* Pre-2.3: 3-arg form; format_out is ignored because the older
|
||||||
|
* API cannot report the parsed format.
|
||||||
|
*/
|
||||||
|
static inline int tp_plist_from_memory(const char *data,
|
||||||
|
uint32_t length,
|
||||||
|
plist_t *out,
|
||||||
|
void *fmt_out)
|
||||||
|
{
|
||||||
|
(void)fmt_out;
|
||||||
|
return (int)plist_from_memory(data, length, out);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* TP_PLIST_COMPAT_H */
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <libimobiledevice/libimobiledevice.h>
|
#include <libimobiledevice/libimobiledevice.h>
|
||||||
#include <libimobiledevice/lockdown.h>
|
#include <libimobiledevice/lockdown.h>
|
||||||
#include <libusb-1.0/libusb.h>
|
#include <libusb.h>
|
||||||
|
|
||||||
#define DEVICE_FIELD_LEN 128
|
#define DEVICE_FIELD_LEN 128
|
||||||
#define DEVICE_UDID_LEN 64
|
#define DEVICE_UDID_LEN 64
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <libusb-1.0/libusb.h>
|
#include <libusb.h>
|
||||||
|
|
||||||
/* Apple USB identifiers */
|
/* Apple USB identifiers */
|
||||||
#define APPLE_VID 0x05AC
|
#define APPLE_VID 0x05AC
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <libusb-1.0/libusb.h>
|
#include <libusb.h>
|
||||||
|
|
||||||
/* ------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------ */
|
||||||
/* DFU class-specific request codes (USB DFU 1.1 spec, Table 3.2) */
|
/* DFU class-specific request codes (USB DFU 1.1 spec, Table 3.2) */
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#define PLIST_HELPERS_H
|
#define PLIST_HELPERS_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <plist/plist.h>
|
#include "compat/plist_compat.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Retrieve a string value from a plist dict by key.
|
* Retrieve a string value from a plist dict by key.
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
#define USB_HELPERS_H
|
#define USB_HELPERS_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <libusb-1.0/libusb.h>
|
#include <libusb.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Perform a USB control transfer with a data stage.
|
* Perform a USB control transfer with a data stage.
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
#include <plist/plist.h>
|
#include "compat/plist_compat.h"
|
||||||
|
|
||||||
#include "activation/session.h"
|
#include "activation/session.h"
|
||||||
#include "device/device.h"
|
#include "device/device.h"
|
||||||
|
|
@ -116,7 +116,7 @@ int session_drm_handshake_online(device_info_t *dev, plist_t session_info,
|
||||||
|
|
||||||
log_info("[session_online] Got %zu bytes from drmHandshake", resp.len);
|
log_info("[session_online] Got %zu bytes from drmHandshake", resp.len);
|
||||||
|
|
||||||
plist_from_memory((const char *)resp.data, (uint32_t)resp.len,
|
tp_plist_from_memory((const char *)resp.data, (uint32_t)resp.len,
|
||||||
handshake_response, NULL);
|
handshake_response, NULL);
|
||||||
free(resp.data);
|
free(resp.data);
|
||||||
|
|
||||||
|
|
@ -184,7 +184,7 @@ int session_device_activation_online(device_info_t *dev,
|
||||||
|
|
||||||
log_info("[session_online] Got %zu bytes from deviceActivation", resp.len);
|
log_info("[session_online] Got %zu bytes from deviceActivation", resp.len);
|
||||||
|
|
||||||
plist_from_memory((const char *)resp.data, (uint32_t)resp.len,
|
tp_plist_from_memory((const char *)resp.data, (uint32_t)resp.len,
|
||||||
activation_record, NULL);
|
activation_record, NULL);
|
||||||
free(resp.data);
|
free(resp.data);
|
||||||
|
|
||||||
|
|
@ -292,7 +292,7 @@ int session_probe_albert(device_info_t *dev, plist_t session_info)
|
||||||
if (cb_data && cb_len > 0) {
|
if (cb_data && cb_len > 0) {
|
||||||
/* CollectionBlob bytes are themselves an XML plist */
|
/* CollectionBlob bytes are themselves an XML plist */
|
||||||
plist_t cb_plist = NULL;
|
plist_t cb_plist = NULL;
|
||||||
plist_from_memory(cb_data, (uint32_t)cb_len, &cb_plist, NULL);
|
tp_plist_from_memory(cb_data, (uint32_t)cb_len, &cb_plist, NULL);
|
||||||
|
|
||||||
if (cb_plist) {
|
if (cb_plist) {
|
||||||
plist_t ib = plist_dict_get_item(cb_plist, "IngestBody");
|
plist_t ib = plist_dict_get_item(cb_plist, "IngestBody");
|
||||||
|
|
@ -380,7 +380,7 @@ skip_ingest:
|
||||||
resp.len);
|
resp.len);
|
||||||
|
|
||||||
/* Parse and dump top-level keys of the handshake response */
|
/* Parse and dump top-level keys of the handshake response */
|
||||||
plist_from_memory((const char *)resp.data, (uint32_t)resp.len,
|
tp_plist_from_memory((const char *)resp.data, (uint32_t)resp.len,
|
||||||
&hs_resp, NULL);
|
&hs_resp, NULL);
|
||||||
free(resp.data);
|
free(resp.data);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <libirecovery.h>
|
#include "compat/libirecovery_compat.h"
|
||||||
|
|
||||||
#include "bypass/path_a_internal.h"
|
#include "bypass/path_a_internal.h"
|
||||||
#include "bypass/path_a_ramdisk_internal.h"
|
#include "bypass/path_a_ramdisk_internal.h"
|
||||||
|
|
@ -146,6 +146,14 @@ send_staged_image(irecv_client_t client, const char *path,
|
||||||
label, irecv_strerror(err));
|
label, irecv_strerror(err));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#if TP_IRECV_NEEDS_MANUAL_ZLP
|
||||||
|
/* Older libirecovery cannot request the DFU notify-finish ZLP via
|
||||||
|
* the send flag, so emit one by hand to mark end-of-transfer. */
|
||||||
|
{
|
||||||
|
unsigned char zlp = 0;
|
||||||
|
(void)irecv_send_buffer(client, &zlp, 0, 0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <plist/plist.h>
|
#include <plist/plist.h>
|
||||||
#include <libusb-1.0/libusb.h>
|
#include <libusb.h>
|
||||||
#include <libimobiledevice/libimobiledevice.h>
|
#include <libimobiledevice/libimobiledevice.h>
|
||||||
#include <libirecovery.h>
|
#include <libirecovery.h>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,8 +9,8 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <libusb-1.0/libusb.h>
|
#include <libusb.h>
|
||||||
#include <libirecovery.h>
|
#include "compat/libirecovery_compat.h"
|
||||||
|
|
||||||
#include "bypass/path_b.h"
|
#include "bypass/path_b.h"
|
||||||
#include "device/usb_dfu.h"
|
#include "device/usb_dfu.h"
|
||||||
|
|
@ -30,9 +30,6 @@
|
||||||
/* Maximum USB string descriptor length per USB 2.0 spec */
|
/* Maximum USB string descriptor length per USB 2.0 spec */
|
||||||
#define USB_DESC_MAX_LEN 255
|
#define USB_DESC_MAX_LEN 255
|
||||||
|
|
||||||
/* Apple recovery mode USB product ID */
|
|
||||||
#define APPLE_RECOVERY_PID 0x1281
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* usb_get_string_descriptor -- GET_DESCRIPTOR control transfer for a
|
* usb_get_string_descriptor -- GET_DESCRIPTOR control transfer for a
|
||||||
* USB string descriptor. Returns bytes received, or -1 on error.
|
* USB string descriptor. Returns bytes received, or -1 on error.
|
||||||
|
|
@ -185,7 +182,7 @@ int path_b_write_serial_irecovery(device_info_t *dev, const char *new_serial)
|
||||||
{
|
{
|
||||||
irecv_client_t client = NULL;
|
irecv_client_t client = NULL;
|
||||||
irecv_error_t err;
|
irecv_error_t err;
|
||||||
const struct irecv_device_info *info;
|
int mode = 0;
|
||||||
char cmd[DFU_SERIAL_MAX + 32];
|
char cmd[DFU_SERIAL_MAX + 32];
|
||||||
int rc = -1;
|
int rc = -1;
|
||||||
|
|
||||||
|
|
@ -207,11 +204,15 @@ int path_b_write_serial_irecovery(device_info_t *dev, const char *new_serial)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Verify the device is actually in recovery (not DFU or normal) */
|
/* Verify the device is actually in recovery (not DFU or normal).
|
||||||
info = irecv_get_device_info(client);
|
* struct irecv_device_info has no pid field on any released
|
||||||
if (!info || info->pid != APPLE_RECOVERY_PID) {
|
* libirecovery; query the mode via irecv_get_mode() instead and
|
||||||
log_error("[path_b_id] Device is not in recovery mode (pid=0x%04X)",
|
* accept any of the four recovery-mode PIDs (0x1280..0x1283). */
|
||||||
info ? (unsigned)info->pid : 0);
|
err = irecv_get_mode(client, &mode);
|
||||||
|
if (err != IRECV_E_SUCCESS ||
|
||||||
|
mode < IRECV_K_RECOVERY_MODE_1 || mode > IRECV_K_RECOVERY_MODE_4) {
|
||||||
|
log_error("[path_b_id] Device is not in recovery mode (mode=0x%04X, err=%s)",
|
||||||
|
(unsigned)mode, irecv_strerror(err));
|
||||||
irecv_close(client);
|
irecv_close(client);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,8 +75,12 @@ detect_linux_pm() {
|
||||||
LINUX_PM="dnf"
|
LINUX_PM="dnf"
|
||||||
elif command -v pacman >/dev/null 2>&1; then
|
elif command -v pacman >/dev/null 2>&1; then
|
||||||
LINUX_PM="pacman"
|
LINUX_PM="pacman"
|
||||||
|
elif command -v zypper >/dev/null 2>&1; then
|
||||||
|
LINUX_PM="zypper"
|
||||||
|
elif command -v apk >/dev/null 2>&1; then
|
||||||
|
LINUX_PM="apk"
|
||||||
else
|
else
|
||||||
msg_err "No supported package manager found (need apt, dnf, or pacman)."
|
msg_err "No supported package manager found (need apt, dnf, pacman, zypper, or apk)."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
@ -101,14 +105,32 @@ install_deps_macos() {
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local brew_pkgs="libimobiledevice libirecovery libusb libplist openssl pkg-config libssh2"
|
local brew_pkgs="libimobiledevice libirecovery libusb libplist openssl curl pkg-config libssh2"
|
||||||
msg_info "Installing dependencies via Homebrew..."
|
msg_info "Installing dependencies via Homebrew..."
|
||||||
brew install $brew_pkgs
|
brew install $brew_pkgs
|
||||||
msg_ok "Homebrew dependencies installed."
|
msg_ok "Homebrew dependencies installed."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# openssl and curl are keg-only under Homebrew; their .pc files never
|
||||||
|
# land on the default pkg-config search path. Prepend the two prefixes
|
||||||
|
# so pkg-config can find libcrypto and libcurl without editing the
|
||||||
|
# Makefile.
|
||||||
|
macos_prep_pkgconfig() {
|
||||||
|
if ! command -v brew >/dev/null 2>&1; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
local ossl_prefix curl_prefix extra=""
|
||||||
|
ossl_prefix="$(brew --prefix openssl 2>/dev/null || true)"
|
||||||
|
curl_prefix="$(brew --prefix curl 2>/dev/null || true)"
|
||||||
|
[ -n "$ossl_prefix" ] && extra="${ossl_prefix}/lib/pkgconfig"
|
||||||
|
[ -n "$curl_prefix" ] && extra="${extra:+${extra}:}${curl_prefix}/lib/pkgconfig"
|
||||||
|
if [ -n "$extra" ]; then
|
||||||
|
export PKG_CONFIG_PATH="${extra}${PKG_CONFIG_PATH:+:${PKG_CONFIG_PATH}}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
install_deps_linux_apt() {
|
install_deps_linux_apt() {
|
||||||
local apt_pkgs="libimobiledevice-dev libirecovery-1.0-dev libusb-1.0-0-dev libplist-dev libssl-dev libssh2-1-dev pkg-config build-essential"
|
local apt_pkgs="libimobiledevice-dev libirecovery-1.0-dev libusb-1.0-0-dev libplist-dev libssl-dev libcurl4-openssl-dev libssh2-1-dev pkg-config build-essential"
|
||||||
msg_info "Installing dependencies via apt..."
|
msg_info "Installing dependencies via apt..."
|
||||||
sudo apt-get update -qq
|
sudo apt-get update -qq
|
||||||
sudo apt-get install -y $apt_pkgs
|
sudo apt-get install -y $apt_pkgs
|
||||||
|
|
@ -116,13 +138,38 @@ install_deps_linux_apt() {
|
||||||
}
|
}
|
||||||
|
|
||||||
install_deps_linux_dnf() {
|
install_deps_linux_dnf() {
|
||||||
local dnf_pkgs="libimobiledevice-devel libirecovery-devel libusb1-devel libplist-devel openssl-devel libssh2-devel pkg-config gcc make"
|
local dnf_pkgs="libimobiledevice-devel libirecovery-devel libusb1-devel libplist-devel openssl-devel libcurl-devel libssh2-devel pkg-config gcc make"
|
||||||
msg_info "Installing dependencies via dnf..."
|
msg_info "Installing dependencies via dnf..."
|
||||||
sudo dnf install -y $dnf_pkgs
|
sudo dnf install -y $dnf_pkgs
|
||||||
msg_ok "DNF dependencies installed."
|
msg_ok "DNF dependencies installed."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
install_deps_linux_pacman() {
|
||||||
|
local pacman_pkgs="libimobiledevice libirecovery libusb libplist openssl libssh2 curl pkgconf base-devel"
|
||||||
|
msg_info "Installing dependencies via pacman..."
|
||||||
|
sudo pacman -S --needed --noconfirm $pacman_pkgs
|
||||||
|
msg_ok "pacman dependencies installed."
|
||||||
|
}
|
||||||
|
|
||||||
|
install_deps_linux_zypper() {
|
||||||
|
local zypper_pkgs="libimobiledevice-devel libirecovery-devel libusb-1_0-devel libplist-2_0-devel openssl-devel libssh2-devel libcurl-devel pkg-config gcc make"
|
||||||
|
msg_info "Installing dependencies via zypper..."
|
||||||
|
sudo zypper install -y $zypper_pkgs
|
||||||
|
msg_ok "zypper dependencies installed."
|
||||||
|
}
|
||||||
|
|
||||||
|
install_deps_linux_apk() {
|
||||||
|
local apk_pkgs="libimobiledevice-dev libirecovery-dev libusb-dev libplist-dev openssl-dev libssh2-dev curl-dev pkgconfig gcc make musl-dev"
|
||||||
|
msg_info "Installing dependencies via apk..."
|
||||||
|
sudo apk add --no-cache $apk_pkgs
|
||||||
|
msg_ok "apk dependencies installed."
|
||||||
|
}
|
||||||
|
|
||||||
install_deps() {
|
install_deps() {
|
||||||
|
if [ "$DETECTED_OS" = "macos" ]; then
|
||||||
|
macos_prep_pkgconfig
|
||||||
|
fi
|
||||||
|
|
||||||
if ! command -v pkg-config >/dev/null 2>&1; then
|
if ! command -v pkg-config >/dev/null 2>&1; then
|
||||||
msg_warn "pkg-config not found, installing it first..."
|
msg_warn "pkg-config not found, installing it first..."
|
||||||
case "$DETECTED_OS" in
|
case "$DETECTED_OS" in
|
||||||
|
|
@ -132,7 +179,9 @@ install_deps() {
|
||||||
case "$LINUX_PM" in
|
case "$LINUX_PM" in
|
||||||
apt) sudo apt-get update -qq && sudo apt-get install -y pkg-config ;;
|
apt) sudo apt-get update -qq && sudo apt-get install -y pkg-config ;;
|
||||||
dnf) sudo dnf install -y pkg-config ;;
|
dnf) sudo dnf install -y pkg-config ;;
|
||||||
pacman) sudo pacman -S --noconfirm pkg-config ;;
|
pacman) sudo pacman -S --needed --noconfirm pkgconf ;;
|
||||||
|
zypper) sudo zypper install -y pkg-config ;;
|
||||||
|
apk) sudo apk add --no-cache pkgconfig ;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
@ -148,19 +197,18 @@ install_deps() {
|
||||||
msg_warn "Missing dependencies: ${MISSING_DEPS[*]}"
|
msg_warn "Missing dependencies: ${MISSING_DEPS[*]}"
|
||||||
|
|
||||||
case "$DETECTED_OS" in
|
case "$DETECTED_OS" in
|
||||||
macos) install_deps_macos ;;
|
macos)
|
||||||
|
install_deps_macos
|
||||||
|
macos_prep_pkgconfig
|
||||||
|
;;
|
||||||
linux|wsl)
|
linux|wsl)
|
||||||
detect_linux_pm
|
detect_linux_pm
|
||||||
case "$LINUX_PM" in
|
case "$LINUX_PM" in
|
||||||
apt) install_deps_linux_apt ;;
|
apt) install_deps_linux_apt ;;
|
||||||
dnf) install_deps_linux_dnf ;;
|
dnf) install_deps_linux_dnf ;;
|
||||||
pacman)
|
pacman) install_deps_linux_pacman ;;
|
||||||
msg_warn "Arch Linux detected. Install from AUR:"
|
zypper) install_deps_linux_zypper ;;
|
||||||
msg_info " yay -S libimobiledevice libirecovery libusb libplist openssl libssh2 pkg-config base-devel"
|
apk) install_deps_linux_apk ;;
|
||||||
msg_info " or: paru -S libimobiledevice-git libirecovery-git libssh2"
|
|
||||||
msg_info "Re-run this script after installing."
|
|
||||||
exit 1
|
|
||||||
;;
|
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
@ -170,7 +218,8 @@ install_deps() {
|
||||||
msg_err "Still missing after install: ${MISSING_DEPS[*]}"
|
msg_err "Still missing after install: ${MISSING_DEPS[*]}"
|
||||||
msg_info "Please install them manually and re-run this script."
|
msg_info "Please install them manually and re-run this script."
|
||||||
msg_info " libssh2 is required for Phase 2C SSH jailbreak delivery."
|
msg_info " libssh2 is required for Phase 2C SSH jailbreak delivery."
|
||||||
msg_info " If libssh2 was just installed, re-running should pick it up."
|
msg_info " libcurl is required for Albert activation server calls."
|
||||||
|
msg_info " If either was just installed, re-running should pick it up."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
1
start.sh
1
start.sh
|
|
@ -40,6 +40,7 @@ PKGCONFIG_DEPS=(
|
||||||
"libusb-1.0"
|
"libusb-1.0"
|
||||||
"libplist-2.0"
|
"libplist-2.0"
|
||||||
"openssl"
|
"openssl"
|
||||||
|
"libcurl"
|
||||||
"libssh2"
|
"libssh2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -114,6 +114,18 @@ const struct irecv_device_info *irecv_get_device_info(irecv_client_t client)
|
||||||
return &client->info;
|
return &client->info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
irecv_error_t irecv_get_mode(irecv_client_t client, int *mode)
|
||||||
|
{
|
||||||
|
mock_log_append("irecv_get_mode");
|
||||||
|
if (!client || !mode)
|
||||||
|
return (irecv_error_t)-1;
|
||||||
|
/* Reflect the configured USB product ID: recovery PIDs live in
|
||||||
|
* 0x1280..0x1283, DFU is 0x1227. Callers compare against
|
||||||
|
* IRECV_K_RECOVERY_MODE_[1..4] which are the recovery PIDs. */
|
||||||
|
*mode = (int)g_irecv_info_pid;
|
||||||
|
return IRECV_E_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
irecv_error_t irecv_send_command(irecv_client_t client, const char *command)
|
irecv_error_t irecv_send_command(irecv_client_t client, const char *command)
|
||||||
{
|
{
|
||||||
(void)client;
|
(void)client;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue