tr4mpass/Makefile
Moussa Ouallaf 54c0ad652c fix(chip-db): rebuild chip_db_table*.h from gaster canonical + strict canary
Rewrite the .name / .marketing fields and banner comments in
include/device/chip_db_table.h and chip_db_table_rop.h from gaster's
canonical SecureROM SRTG -> offset table (gaster.c:519-808), so the
CLI announces the physical chip that is actually plugged in. Each
row carries a "gaster.c:NNN" comment marker traceable to the source
of truth. Offsets, CPIDs and struct layout are unchanged.

Relabels: 0x8947 (was "A7 / iPhone 5s", now S5L8947 = A5 Rev B /
Apple TV 3rd gen rev A); 0x8950 / 0x8955 (were "A5-class Apple TV",
now A6 / A6X); 0x8960 (was "A10 / iPhone 7", now A7 / iPhone 5s);
0x8002 (was "S3 / Watch Series 3", now S1P/S2/T1 covering Watch
Series 1/2 and MacBook Pro Touch Bar T1); 0x8004 GPS+Cellular
qualifier dropped; 0x8000 / 0x8003 A9 Samsung/TSMC labels swapped
to match APL0898 / APL1022; 0x8010 / 0x8011 marketing broadened to
cover the full ship list.

Add tests/chip_db_canary.c, wired as a build-time prerequisite of
tr4mpass via the new Makefile .chip-db-canary target. The probe
walks a golden expected (cpid, name-substr, marketing-substr,
checkm8) table and fails the build on drift, defeating a repeat of
issue #53. STRICT_CHIP_DB=1 by default; make STRICT_CHIP_DB=0
bypasses the probe for distro-package chip-table update races
(T5 "Chip-DB canary strictness" note).

Files modified:
- include/device/chip_db_table.h
- include/device/chip_db_table_rop.h
- Makefile
- .gitignore
- tests/chip_db_canary.c (new)

Closes: #53
2026-07-17 02:30:38 +02:00

124 lines
5.5 KiB
Makefile

CC = cc
CFLAGS = -Wall -Wextra -std=c99 -D_GNU_SOURCE -O2
LDFLAGS =
# Library discovery via pkg-config (warn but do not fail if missing)
PKG_LIBS = libimobiledevice-1.0 libirecovery-1.0 libusb-1.0 \
libplist-2.0 openssl libcurl libssh2
CFLAGS += $(shell pkg-config --cflags $(PKG_LIBS) 2>/dev/null)
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)))
# Auto-discover all C sources under src/
SRCS = $(shell find src -name '*.c')
OBJS = $(SRCS:.c=.o)
TARGET = tr4mpass
all: $(TARGET)
$(TARGET): .chip-db-canary $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS) $(LDFLAGS)
%.o: %.c
$(CC) $(CFLAGS) -Iinclude -c -o $@ $<
clean:
find src -name '*.o' -delete
rm -f $(TARGET) $(TEST_TARGET) $(MOCK_TARGET) $(CHIP_DB_CANARY_BIN)
find tests -name '*.o' -delete 2>/dev/null || true
# ------------------------------------------------------------------ #
# Chip DB integrity canary (T5, issue #53). #
# #
# Rebuilt and re-run on every $(TARGET) build. If any well-known #
# row in include/device/chip_db_table*.h diverges from tests/ #
# chip_db_canary.c's expected (name, marketing, checkm8) tuple, the #
# probe exits non-zero and the whole build fails -- guarding against #
# a repeat of the 0x8947/0x8960 mislabel bug where the CLI announced #
# the wrong device family. Bypass with STRICT_CHIP_DB=0 only when a #
# distro-packaged chip table has legitimately diverged. #
# ------------------------------------------------------------------ #
STRICT_CHIP_DB ?= 1
CHIP_DB_CANARY_BIN = tests/chip_db_canary.bin
.chip-db-canary: tests/chip_db_canary.c include/device/chip_db_table.h \
include/device/chip_db_table_rop.h include/device/chip_db.h
@$(CC) -Wall -Wextra -std=c99 -D_GNU_SOURCE -O2 -Iinclude \
-DSTRICT_CHIP_DB=$(STRICT_CHIP_DB) \
tests/chip_db_canary.c -o $(CHIP_DB_CANARY_BIN)
@./$(CHIP_DB_CANARY_BIN)
.PHONY: all clean test test-mocks .chip-db-canary
# ------------------------------------------------------------------ #
# Test target: compile only hardware-independent units #
# No mocks, no real library linkage required for the SUT code. #
# ------------------------------------------------------------------ #
TEST_UNITS = src/device/chip_db.c src/bypass/bypass.c src/util/log.c \
src/util/env_config.c
# Sections linked by both `make test` (hw-independent) and `make test-mocks`.
TEST_SECT_CORE = tests/test_main.c tests/test_parsing.c tests/test_chip_db.c \
tests/test_bypass_probe.c tests/test_constants.c \
tests/test_cert_extract.c tests/test_signer.c \
tests/test_env_config.c
# Sections that require the mocked hardware libraries -- only used by
# `make test-mocks`. Include stub definitions of their entry points in
# TEST_SECT_STUBS so the hw-independent target still links.
TEST_SECT_MOCK = tests/test_ramdisk.c tests/test_ssh_jailbreak.c
# Aggregate for the mock build: real section bodies.
TEST_SECT = $(TEST_SECT_CORE) $(TEST_SECT_MOCK)
TEST_TARGET = tests/run_tests
TEST_CFLAGS = $(CFLAGS) -Iinclude -Itests -DUNIT_TEST
test: $(TEST_TARGET)
./$(TEST_TARGET)
# The hw-independent target replaces the mock-only sections with empty
# stubs so run_tests still finds run_ramdisk_tests / run_ssh_jailbreak_tests.
$(TEST_TARGET): $(TEST_SECT_CORE) $(TEST_UNITS) tests/mock_section_stubs.c
$(CC) $(TEST_CFLAGS) -o $@ $^
# ------------------------------------------------------------------ #
# Mock test target: full suite against mocked hardware libraries. #
# #
# Links the test sections + all tests/mocks/*.c + the production #
# sources we want to exercise (everything under src/ except main.c #
# and the hardware-specific checkm8/dfu exploit code). The real #
# hardware libs (libimobiledevice/libirecovery/libusb/libssh2/curl) #
# are NOT linked -- the mocks satisfy those symbols. libplist, #
# openssl, and pthread remain real. #
# ------------------------------------------------------------------ #
MOCK_SRCS = $(shell find tests/mocks -name '*.c')
# Phase 3: pick up end-to-end integration test sources. `find` is
# guarded so `make` still works before the directory exists.
INT_SRCS = $(shell find tests/integration -name '*.c' 2>/dev/null)
# Production sources to include in the mock build. We exclude:
# - src/main.c (has its own main())
# - src/exploit/* and src/device/usb_dfu.c (direct DFU/checkm8 h/w code)
MOCK_SUT_SRCS = $(shell find src -name '*.c' \
-not -path 'src/main.c' \
-not -path 'src/exploit/*' \
-not -path 'src/device/usb_dfu.c')
MOCK_ALL_SRCS = $(TEST_SECT) $(MOCK_SRCS) $(INT_SRCS) $(MOCK_SUT_SRCS)
MOCK_TARGET = tests/run_mock_tests
# Only link libs that the SUT still needs at runtime and we did NOT mock.
MOCK_PKG_LIBS = libplist-2.0 openssl
MOCK_CFLAGS = -Wall -Wextra -std=c99 -D_GNU_SOURCE -O2 \
$(shell pkg-config --cflags $(MOCK_PKG_LIBS) 2>/dev/null) \
-Iinclude -Itests -Itests/integration -Itests/mocks \
-DTEST_MODE -DUNIT_TEST
MOCK_LDFLAGS = $(shell pkg-config --libs $(MOCK_PKG_LIBS) 2>/dev/null)
test-mocks: $(MOCK_TARGET)
./$(MOCK_TARGET)
$(MOCK_TARGET): $(MOCK_ALL_SRCS)
$(CC) $(MOCK_CFLAGS) -o $@ $^ $(MOCK_LDFLAGS)