diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9a8c7c8..d9e007f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,8 +36,8 @@ jobs: - name: Build Documentation run: | make -j$(nproc) docs - mkdir ready - cp docs/*.html docs/mandoc.css docs/palera1n.1 ready + mkdir -p ready/docs + cp docs/*.html docs/mandoc.css docs/palera1n.1 ready/docs - name: Get branch name id: branch-name @@ -317,17 +317,25 @@ jobs: find dep_root -name '*.dylib' -delete find dep_root -name '*.la' -delete gmake -j$(sysctl -n hw.ncpu) - mkdir -p ready - mv src/palera1n palera1n-${{ matrix.os }}-${{ matrix.arch }} + cp src/palera1n palera1n-${{ matrix.os }}-${{ matrix.arch }} dsymutil palera1n-${{ matrix.os }}-${{ matrix.arch }} strip palera1n-${{ matrix.os }}-${{ matrix.arch }} + + - name: Build palera1n (Development) + run: | + CC="${{ matrix.triple }}-gcc" gmake -j$(sysctl -n hw.ncpu) clean + CC="${{ matrix.triple }}-gcc" gmake -j$(sysctl -n hw.ncpu) DEV_BUILD=1 TUI=1 ROOTFUL=1 + cp src/palera1n palera1n-${{ matrix.os }}-${{ matrix.arch }}.development + + - name: Prepare artifact + run: | + mkdir -p ready/build_depends + tar -zcf ready/build_depends/dep_root-${{ matrix.os }}-${{ matrix.arch }}.tgz dep_root if [ "${{ matrix.os }}" == "macosx" ]; then - ldid -S palera1n-${{ matrix.os }}-${{ matrix.arch }} + ldid -S palera1n-${{ matrix.os }}-${{ matrix.arch }}{,.development} else - ldid -Ssrc/usb.xml palera1n-${{ matrix.os }}-${{ matrix.arch }} + ldid -Ssrc/usb.xml palera1n-${{ matrix.os }}-${{ matrix.arch }}{,.development} fi - mkdir -p ready - tar -zcf ready/dep_root-${{ matrix.os }}-${{ matrix.arch }}.tgz dep_root - name: Get branch name id: branch-name @@ -354,6 +362,15 @@ jobs: path: palera1n-${{ matrix.os }}-${{ matrix.arch }} retention-days: 1 + - name: Upload ${{ matrix.os }} thin ${{ matrix.arch }} build (Development) + if: ${{ github.event_name != 'pull_request' }} + uses: actions/upload-artifact@v3 + with: + name: palera1n-${{ matrix.os }}-${{ matrix.arch }}.development + path: palera1n-${{ matrix.os }}-${{ matrix.arch }}.development + retention-days: 1 + + - name: Upload ${{ matrix.os }} thin ${{ matrix.arch }} debug symbols if: ${{ github.event_name != 'pull_request' }} uses: actions/upload-artifact@v3 @@ -384,18 +401,24 @@ jobs: - name: Prepare artifact run: | - find . lipo -create -arch arm64 ./palera1n-macosx-arm64/palera1n-macosx-arm64 -arch x86_64 ./palera1n-macosx-x86_64/palera1n-macosx-x86_64 -output palera1n-macos + lipo -create -arch arm64 ./palera1n-macosx-arm64.development/palera1n-macosx-arm64.development -arch x86_64 ./palera1n-macosx-x86_64.development/palera1n-macosx-x86_64.development -output palera1n-macos.development mkdir -p palera1n-macos.dSYM/Contents/Resources/DWARF cp ./palera1n-macosx-x86_64.dSYM/Contents/Info.plist palera1n-macos.dSYM/Contents lipo -create -arch arm64 palera1n-macosx-arm64.dSYM/Contents/Resources/DWARF/palera1n-macosx-arm64 -arch x86_64 palera1n-macosx-x86_64.dSYM/Contents/Resources/DWARF/palera1n-macosx-x86_64 -output palera1n-macos.dSYM/Contents/Resources/DWARF/palera1n-macos - mkdir ready - cp palera1n-macos ready/palera1n-macos-universal - cp ./palera1n-macosx-x86_64/palera1n-macosx-x86_64 ready/palera1n-macos-x86_64 - cp ./palera1n-macosx-arm64/palera1n-macosx-arm64 ready/palera1n-macos-arm64 - cp ./palera1n-iphoneos-arm64/palera1n-iphoneos-arm64 ready/palera1n-iphoneos-arm64 - zip -r9 ready/palera1n-iphoneos-arm64.dSYM.zip palera1n-iphoneos-arm64.dSYM - zip -r9 ready/palera1n-macos.dSYM.zip palera1n-macos.dSYM + mkdir -p ready/{debian,binaries,debug_symbols,binaries_development} + cp palera1n-macos.development ready/binaries_development/palera1n-macos-universal.development + cp palera1n-macos ready/binaries/palera1n-macos-universal + cp ./palera1n-macosx-x86_64/palera1n-macosx-x86_64 ready/binaries/palera1n-macos-x86_64 + cp ./palera1n-macosx-arm64/palera1n-macosx-arm64 ready/binaries/palera1n-macos-arm64 + cp ./palera1n-iphoneos-arm64/palera1n-iphoneos-arm64 ready/binaries/palera1n-iphoneos-arm64 + cp ./palera1n-macosx-x86_64.development/palera1n-macosx-x86_64.development ready/binaries_development/palera1n-macos-x86_64.development + cp ./palera1n-macosx-arm64.development/palera1n-macosx-arm64.development ready/binaries_development/palera1n-macos-arm64.development + cp ./palera1n-iphoneos-arm64.development/palera1n-iphoneos-arm64.development ready/binaries_development/palera1n-iphoneos-arm64.development + zip -r9 ready/debug_symbols/palera1n-iphoneos-arm64.dSYM.zip palera1n-iphoneos-arm64.dSYM + zip -r9 ready/debug_symbols/palera1n-macosx-arm64.dSYM.zip palera1n-macosx-arm64.dSYM + zip -r9 ready/debug_symbols/palera1n-macosx-x86_64.dSYM.zip palera1n-macosx-x86_64.dSYM + zip -r9 ready/debug_symbols/palera1n-macos.dSYM.zip palera1n-macos.dSYM - name: Build debs run: | @@ -411,12 +434,12 @@ jobs: gsed 's|@DEB_ARCH@|darwin-amd64|g' -i stage/DEBIAN/control gsed "s|@DEB_VERSION@|$version|g" -i stage/DEBIAN/control - ginstall -Dm644 ready/palera1n-macos-x86_64 stage/opt/procursus/bin/palera1n - ginstall -Dm644 docs/palera1n.1 stage/opt/procursus/usr/share/man/man1/palera1n.1 - chmod +x stage/opt/procursus/bin/palera1n + ginstall -Dm644 ready/binaries/palera1n-macos-x86_64 stage/opt/procursus/bin/palera1n + zstd -c19 docs/palera1n.1 > stage/opt/procursus/usr/share/man/man1/palera1n.1.zst + chmod 644 stage/opt/procursus/usr/share/man/man1/palera1n.1.zst + chmod 755 stage/opt/procursus/bin/palera1n - dpkg-deb -Zzstd -b stage palera1n_darwin-amd64.deb - mv palera1n*.deb ready/ + dpkg-deb --root-owner-group -Zzstd -b stage palera1n_darwin-amd64.deb rm -rf stage # Darwin arm64 @@ -428,12 +451,12 @@ jobs: gsed 's|@DEB_ARCH@|darwin-arm64|g' -i stage/DEBIAN/control gsed "s|@DEB_VERSION@|$version|g" -i stage/DEBIAN/control - ginstall -Dm644 ready/palera1n-macos-arm64 stage/opt/procursus/bin/palera1n - ginstall -Dm644 docs/palera1n.1 stage/opt/procursus/usr/share/man/man1/palera1n.1 - chmod +x stage/opt/procursus/bin/palera1n + ginstall -Dm644 ready/binaries/palera1n-macos-arm64 stage/opt/procursus/bin/palera1n + zstd -c19 docs/palera1n.1 > stage/opt/procursus/usr/share/man/man1/palera1n.1.zst + chmod 644 stage/opt/procursus/usr/share/man/man1/palera1n.1.zst + chmod 755 stage/opt/procursus/bin/palera1n - dpkg-deb -Zzstd -b stage palera1n_darwin-arm64.deb - mv palera1n*.deb ready/ + dpkg-deb --root-owner-group -Zzstd -b stage palera1n_darwin-arm64.deb rm -rf stage # iPhoneOS @@ -445,12 +468,12 @@ jobs: gsed 's|@DEB_ARCH@|iphoneos-arm|g' -i stage/DEBIAN/control gsed "s|@DEB_VERSION@|$version|g" -i stage/DEBIAN/control - ginstall -Dm644 ready/palera1n-iphoneos-arm64 stage/usr/bin/palera1n - ginstall -Dm644 docs/palera1n.1 stage/usr/share/man/man1/palera1n.1 - chmod +x stage/usr/bin/palera1n + ginstall -Dm644 ready/binaries/palera1n-iphoneos-arm64 stage/usr/bin/palera1n + zstd -c19 docs/palera1n.1 > stage/usr/share/man/man1/palera1n.1.zst + chmod 644 stage/usr/share/man/man1/palera1n.1.zst + chmod 755 stage/usr/bin/palera1n - dpkg-deb -Zzstd -b stage palera1n_iphoneos-arm.deb - mv palera1n*.deb ready/ + dpkg-deb --root-owner-group -Zzstd -b stage palera1n_iphoneos-arm.deb rm -rf stage # iPhoneOS (rootless) @@ -462,13 +485,15 @@ jobs: gsed 's|@DEB_ARCH@|iphoneos-arm64|g' -i stage/DEBIAN/control gsed "s|@DEB_VERSION@|$version|g" -i stage/DEBIAN/control - ginstall -Dm644 ready/palera1n-iphoneos-arm64 stage/var/jb/usr/bin/palera1n - ginstall -Dm644 docs/palera1n.1 stage/var/jb/usr/share/man/man1/palera1n.1 - chmod +x stage/var/jb/usr/bin/palera1n + ginstall -Dm644 ready/binaries/palera1n-iphoneos-arm64 stage/var/jb/usr/bin/palera1n + zstd -c19 docs/palera1n.1 > stage/var/jb/usr/share/man/man1/palera1n.1.zst + chmod 644 stage/var/jb/usr/share/man/man1/palera1n.1.zst + chmod 755 stage/var/jb/usr/bin/palera1n - dpkg-deb -Zzstd -b stage palera1n_iphoneos-arm64.deb - mv palera1n*.deb ready/ + dpkg-deb --root-owner-group -Zzstd -b stage palera1n_iphoneos-arm64.deb rm -rf stage + + mv palera1n*.deb ready/debian - name: Save build tag run: echo "$(git describe --dirty --tags --abbrev=7 | sed 's|-dirty||')" > build-tag.txt @@ -774,20 +799,28 @@ jobs: find dep_root -name '*.so' -delete find dep_root -name '*.la' -delete CC="${{ matrix.triple }}-gcc" make -j$(nproc) + cp src/palera1n palera1n.release - name: Seperate debug symbols run: | - ${{ matrix.triple }}-objcopy --only-keep-debug src/palera1n palera1n.debug - ${{ matrix.triple }}-strip --strip-debug --strip-unneeded src/palera1n - ${{ matrix.triple }}-objcopy --add-gnu-debuglink=palera1n.debug src/palera1n + ${{ matrix.triple }}-objcopy --only-keep-debug palera1n.release palera1n.debug + ${{ matrix.triple }}-strip --strip-debug --strip-unneeded palera1n.release + ${{ matrix.triple }}-objcopy --add-gnu-debuglink=palera1n.debug palera1n.release chmod -x palera1n.debug + + - name: Build palera1n (Development) + run: | + CC="${{ matrix.triple }}-gcc" make -j$(nproc) clean + CC="${{ matrix.triple }}-gcc" make -j$(nproc) DEV_BUILD=1 TUI=1 ROOTFUL=1 + cp src/palera1n palera1n.development - name: Prepare artifact run: | - mkdir ready usbmuxd-static - mv palera1n.debug ready/palera1n-${{ env.CHECKRA1N_NAME }}.debug - mv src/palera1n ready/palera1n-${{ env.CHECKRA1N_NAME }} - tar -zcf ready/dep_root_${{ matrix.triple }}.tgz dep_root + mkdir -p ready/{binaries,debian,binaries_development,build_depends,debug_symbols} usbmuxd-static + mv palera1n.debug ready/debug_symbols/palera1n-${{ env.CHECKRA1N_NAME }}.debug + mv palera1n.release ready/binaries/palera1n-${{ env.CHECKRA1N_NAME }} + mv palera1n.development ready/binaries_development/palera1n-${{ env.CHECKRA1N_NAME }}.development + tar -zcf ready/build_depends/dep_root_${{ matrix.triple }}.tgz dep_root install -m755 sysroot/${{ env.PREFIX }}/sbin/usbmuxd usbmuxd-static/usbmuxd-${{ env.CHECKRA1N_NAME }} install -m755 sysroot/${{ env.PREFIX }}/sbin/usbmuxd.debug usbmuxd-static/usbmuxd-${{ env.CHECKRA1N_NAME }}.debug @@ -804,12 +837,13 @@ jobs: sed 's|@DEB_ARCH@|${{ env.ARCH_NAME }}|g' -i stage/DEBIAN/control sed "s|@DEB_VERSION@|$version|g" -i stage/DEBIAN/control - install -Dm644 ready/palera1n-${{ env.CHECKRA1N_NAME }} stage/usr/bin/palera1n - install -Dm644 docs/palera1n.1 stage/usr/share/man/man1/palera1n.1 - chmod +x stage/usr/bin/palera1n + install -Dm644 ready/binaries/palera1n-${{ env.CHECKRA1N_NAME }} stage/usr/bin/palera1n + gzip -c9 docs/palera1n.1 > stage/usr/share/man/man1/palera1n.1.gz + chmod 755 stage/usr/bin/palera1n + chmod 644 stage/usr/share/man/man1/palera1n.1.gz - dpkg-deb -b stage palera1n_${{ env.ARCH_NAME }}.deb - mv palera1n*.deb ready/ + dpkg-deb --root-owner-group -b stage palera1n_${{ env.ARCH_NAME }}.deb + mv palera1n*.deb ready/debian rm -rf stage - name: Get branch name @@ -859,8 +893,13 @@ jobs: with: name: build-tag + - uses: geekyeggo/delete-artifact@v2 + with: + name: '*' + failOnError: false + - name: Send Discord build message run: | COMMITMESSAGE=`git log --pretty=format:'- \`%h\` %s' -1 --reverse` && - (curl "${{ secrets.DISCORD_WEBHOOK }}" -sS -H "Content-Type:application/json" -X POST -d "{\"content\":null,\"embeds\":[{\"title\":\"[palera1n:${{ steps.branch-name.outputs.ref_branch }}] Nightly Build ${{ github.run_number }}\",\"url\":\"https://github.com/palera1n/palera1n/actions/runs/${GITHUB_RUN_ID}\",\"color\":2829617,\"fields\":[{\"name\":\"Build tag\",\"value\":\"- \`$(cat build-tag.txt | sed 's|\n||')\`\"},{\"name\":\"Destination\",\"value\":\"- https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}\"},{\"name\":\"Documentation\",\"value\":\"- [palera1n.1.html](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/palera1n.1.html)\"},{\"name\":\"Main Artifacts\",\"value\":\"- [palera1n-iphoneos-arm64](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/palera1n-iphoneos-arm64)\n- [palera1n-linux-arm64](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/palera1n-linux-arm64)\n- [palera1n-linux-armel](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/palera1n-linux-armel)\n- [palera1n-linux-x86](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/$${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/palera1n-linux-x86)\n- [palera1n-linux-x86_64](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/palera1n-linux-x86_64)\n- [palera1n-macos-universal](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/palera1n-macos-universal)\"}],\"footer\":{\"text\":\"${{ github.actor }}\", \"icon_url\": \"https://github.com/${{ github.actor }}.png\",\"timestamp\":\"$(date -u +"%FT%TZ")\"}}],\"username\":\"GitHub Actions\",\"avatar_url\":\"https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png\"}") + (curl "${{ secrets.DISCORD_WEBHOOK }}" -sS -H "Content-Type:application/json" -X POST -d "{\"content\":null,\"embeds\":[{\"title\":\"[palera1n:${{ steps.branch-name.outputs.ref_branch }}] Nightly Build ${{ github.run_number }}\",\"url\":\"https://github.com/palera1n/palera1n/actions/runs/${GITHUB_RUN_ID}\",\"color\":2829617,\"fields\":[{\"name\":\"Build tag\",\"value\":\"- \`$(cat build-tag.txt | sed 's|\n||')\`\"},{\"name\":\"Destination\",\"value\":\"- https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}\"},{\"name\":\"Documentation\",\"value\":\"- [palera1n.1.html](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/docs/palera1n.1.html)\"},{\"name\":\"Main Artifacts\",\"value\":\"- [palera1n-iphoneos-arm64](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/binaries/palera1n-iphoneos-arm64)\n- [palera1n-linux-arm64](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/binaries/palera1n-linux-arm64)\n- [palera1n-linux-armel](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/binaries/palera1n-linux-armel)\n- [palera1n-linux-x86](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/binaries/palera1n-linux-x86)\n- [palera1n-linux-x86_64](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/binaries/palera1n-linux-x86_64)\n- [palera1n-macos-universal](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch }}/${{ github.run_number }}/binaries/palera1n-macos-universal)\"}],\"footer\":{\"text\":\"${{ github.actor }}\", \"icon_url\": \"https://github.com/${{ github.actor }}.png\",\"timestamp\":\"$(date -u +"%FT%TZ")\"}}],\"username\":\"GitHub Actions\",\"avatar_url\":\"https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.png\"}") diff --git a/Makefile b/Makefile index a1b96a8..27a2f26 100644 --- a/Makefile +++ b/Makefile @@ -2,13 +2,16 @@ SRC = $(shell pwd) DEP = $(SRC)/dep_root STRIP = strip CC ?= cc -CFLAGS += -I$(DEP)/include -I$(SRC)/include -I$(SRC) -D_XOPEN_SOURCE=500 -CFLAGS += -Wall -Wextra -Wno-unused-parameter -DPALERAIN_VERSION=\"2.0.0\" +CFLAGS += -isystem $(DEP)/include -I$(SRC)/include -I$(SRC) -D_XOPEN_SOURCE=500 +CFLAGS += -Wall -Wextra -Wno-unused-parameter -DPALERAIN_VERSION=\"2.0.0\" -DHAVE_LIBIMOBILEDEVICE CFLAGS += -Wno-unused-variable -I$(SRC)/src -std=c99 -pedantic-errors -D_C99_SOURCE -D_POSIX_C_SOURCE=200112L LIBS += $(DEP)/lib/libimobiledevice-1.0.a $(DEP)/lib/libirecovery-1.0.a $(DEP)/lib/libusbmuxd-2.0.a LIBS += $(DEP)/lib/libimobiledevice-glue-1.0.a $(DEP)/lib/libplist-2.0.a -pthread -lm ifeq ($(TARGET_OS),) TARGET_OS = $(shell uname -s) +UNAME = $(TARGET_OS) +else +UNAME = $(shell uname -s) endif ifeq ($(TARGET_OS),Darwin) CFLAGS += -Wno-nullability-extension @@ -19,7 +22,7 @@ LDFLAGS += -Wl,-dead_strip LIBS += -framework CoreFoundation -framework IOKit else CFLAGS += -fdata-sections -ffunction-sections -LDFLAGS += -static -no-pie -Wl,--gc-sections +LDFLAGS += -Wl,--gc-sections endif LIBS += $(DEP)/lib/libmbedtls.a $(DEP)/lib/libmbedcrypto.a $(DEP)/lib/libmbedx509.a $(DEP)/lib/libreadline.a @@ -46,6 +49,12 @@ BUILD_STYLE = RELEASE endif LIBS += -lc +ifeq ($(TARGET_OS),Linux) +ifneq ($(shell echo '$(BUILD_STYLE)' | grep -q '[A-Z]\+SAN' && echo 1),1) +LDFLAGS += -static -no-pie +endif +endif + ifneq ($(BAKERAIN_DEVELOPE_R),) CFLAGS += -DBAKERAIN_DEVELOPE_R="\"$(BAKERAIN_DEVELOPE_R)\"" endif @@ -62,7 +71,7 @@ CFLAGS += -DBUILD_WHOAMI="\"$(BUILD_WHOAMI)\"" -DBUILD_TAG="\"$(BUILD_TAG)\"" CFLAGS += -DBUILD_NUMBER="\"$(BUILD_NUMBER)\"" -DBUILD_BRANCH="\"$(BUILD_BRANCH)\"" CFLAGS += -DBUILD_COMMIT="\"$(BUILD_COMMIT)\"" -export SRC DEP CC CFLAGS LDFLAGS LIBS SHELL TARGET_OS DEV_BUILD BUILD_DATE BUILD_TAG BUILD_WHOAMI BUILD_STYLE BUILD_NUMBER BUILD_BRANCH +export SRC DEP UNAME CC CFLAGS LDFLAGS LIBS SHELL TARGET_OS DEV_BUILD BUILD_DATE BUILD_TAG BUILD_WHOAMI BUILD_STYLE BUILD_NUMBER BUILD_BRANCH all: palera1n @@ -74,13 +83,13 @@ clean: $(MAKE) -C docs clean download-deps: - $(MAKE) -C src checkra1n-macos checkra1n-linux-arm64 checkra1n-linux-armel checkra1n-linux-x86 checkra1n-linux-x86_64 checkra1n-kpf-pongo ramdisk.dmg binpack.dmg Pongo.bin + $(MAKE) -C src $(patsubst %, resources/%, checkra1n-macos checkra1n-linux-arm64 checkra1n-linux-armel checkra1n-linux-x86 checkra1n-linux-x86_64 checkra1n-kpf-pongo ramdisk.dmg binpack.dmg Pongo.bin) docs: $(MAKE) -C docs distclean: clean - rm -rf palera1n-* palera1n*.dSYM src/checkra1n-* src/checkra1n-kpf-pongo src/ramdisk.dmg src/binpack.dmg src/Pongo.bin + $(MAKE) -C src distclean .PHONY: all palera1n clean docs distclean diff --git a/include/paleinfo.h b/include/paleinfo.h index e8a77bd..d50a6ff 100644 --- a/include/paleinfo.h +++ b/include/paleinfo.h @@ -18,12 +18,12 @@ typedef uint64_t palerain_option_t; #define palerain_option_rootful (UINT64_C(1) << 0) /* rootful jailbreak */ #define palerain_option_rootless (UINT64_C(1) << 1) /* rootless jailbreak */ #define palerain_option_setup_rootful (UINT64_C(1) << 2) /* create fakefs */ -/* reserved */ +// (UINT64_C(1) << 3) /* Deprecated and removed */ #define palerain_option_setup_partial_root (UINT64_C(1) << 4) /* fakefs creating should be partial */ #define palerain_option_checkrain_is_clone (UINT64_C(1) << 5) /* supplied checkra1n is checkra1n clone */ #define palerain_option_rootless_livefs (UINT64_C(1) << 6) /* mount root livefs on rootless */ -// #define palerain_option_no_ssv (UINT64_C(1) << 7) /* no signed system volume */ -// #define palerain_option_force_fakefs (UINT64_C(1) << 8) /* force fakefs, even without SSV */ +#define palerain_option_ssv (UINT64_C(1) << 7) /* has signed system volume */ +// (UINT64_C(1) << 8) /* reserved */ #define palerain_option_clean_fakefs (UINT64_C(1) << 9) /* clean fakefs, but does not delete it */ #define palerain_option_tui (UINT64_C(1) << 10) /* terminal user interface */ // #define palerain_option_gui (UINT64_C(1) << 11) /* graphical user interface*/ @@ -42,9 +42,10 @@ typedef uint64_t palerain_option_t; #define palerain_option_force_revert (UINT64_C(1) << 24) /* Unjailbreak */ #define palerain_option_safemode (UINT64_C(1) << 25) /* Enter safe mode */ #define palerain_option_verbose_boot (UINT64_C(1) << 26) /* verbose boot */ - -#define palerain_option_jbinit_log_to_file (UINT64_C(1) << 50) /* make ramdisk log to file (jbinit2) */ -#define palerain_option_setup_rootful_forced (UINT64_C(1) << 51) /* create fakefs over an existing one (jbinit2) */ +// #define palerain_option_sf_ssh (UINT64_C(1) << 27) /* safe mode with bootstrap ssh */ +// #define palerain_option_sf_launchdaemons (UINT64_C(1) << 28) /* safe mode with launchdaemons */ +// #define palerain_option_emerg_mode (UINT64_C(1) << 29) /* emergency mode (early boot usb shell) */ +#define palerain_option_jbinit_log_to_file (UINT64_C(1) << 30) /* deprecated (kept for compatibility) */ #define palerain_option_flower_chain (UINT64_C(1) << 61) /* Flower chain */ #define palerain_option_test1 (UINT64_C(1) << 62) /* Developer test option 1 */ @@ -52,6 +53,9 @@ typedef uint64_t palerain_option_t; #define PALEINFO_MAGIC 'PLSH' +#pragma clang diagnostic push +#pragma clang diagnostic warning "-Wpadded" + /* paleinfo version 2, appended to ramdisk */ struct paleinfo { uint32_t magic; /* 'PLSH' */ @@ -60,6 +64,8 @@ struct paleinfo { uint64_t kslide; /* kernel slide */ uint64_t flags; /* unified palera1n flags */ char rootdev[0x10]; /* ex. disk0s1s8 */ -}__attribute__((packed)); +}; + +#pragma clang diagnostic pop #endif diff --git a/include/palerain.h b/include/palerain.h index ec1e5bb..781683f 100644 --- a/include/palerain.h +++ b/include/palerain.h @@ -32,7 +32,7 @@ #define USB_RET_NOT_RESPONDING LIBUSB_ERROR_OTHER #define USB_RET_IO LIBUSB_ERROR_IO #define USB_RET_NO_DEVICE LIBUSB_ERROR_NO_DEVICE -typedef int usb_ret_t; +typedef int32_t usb_ret_t; typedef libusb_device_handle *usb_device_handle_t; typedef struct stuff @@ -80,8 +80,8 @@ usb_ret_t USBBulkUpload(usb_device_handle_t handle, void *data, uint32_t len); #define MH_CIGAM_64 0xcffaedfe #define MH_KEXT_BUNDLE 0xb -typedef int cpu_type_t; -typedef int cpu_subtype_t; +typedef int32_t cpu_type_t; +typedef int32_t cpu_subtype_t; #define CPU_ARCH_ABI64 0x01000000 #define CPU_TYPE_ARM ((cpu_type_t) 12) @@ -131,7 +131,7 @@ typedef struct { typedef struct { int mode; - unsigned int cpid; + int cpid; char product_type[0x20]; char display_name[0x20]; char iboot_ver[0x20]; @@ -140,9 +140,9 @@ typedef struct { typedef struct { uint32_t magic; /* 0xd803b376*/ unsigned char* ptr; /* pointer to the override file in memory */ - unsigned int len; /* length of override file */ + uint32_t len; /* length of override file */ unsigned char* orig_ptr; /* pointer to the overriden file */ - unsigned int orig_len; /* length of the overriden file */ + uint32_t orig_len; /* length of the overriden file */ int fd; /* file descriptor of the override file */ } override_file_t; diff --git a/include/xxd-embedded.h b/include/xxd-embedded.h index 8ac0617..e63d671 100644 --- a/include/xxd-embedded.h +++ b/include/xxd-embedded.h @@ -5,24 +5,26 @@ #include #endif -extern unsigned char checkra1n[]; -extern unsigned int checkra1n_len; +#include -extern unsigned char checkra1n_kpf_pongo[]; -extern unsigned int checkra1n_kpf_pongo_len; +extern uint8_t checkra1n[]; +extern uint32_t checkra1n_len; -extern unsigned char ramdisk_dmg_lzma[]; -extern unsigned int ramdisk_dmg_lzma_len; +extern uint8_t checkra1n_kpf_pongo_lzma[]; +extern uint32_t checkra1n_kpf_pongo_lzma_len; -extern unsigned char binpack_dmg[]; -extern unsigned int binpack_dmg_len; +extern uint8_t ramdisk_dmg_lzma[]; +extern uint32_t ramdisk_dmg_lzma_len; -extern unsigned char Pongo_bin[]; -extern unsigned int Pongo_bin_len; +extern uint8_t binpack_dmg[]; +extern uint32_t binpack_dmg_len; -#if defined(__APPLE__) && (TARGET_OS_IPHONE || defined(DEV_BUILD)) -extern unsigned char libcheckra1nhelper_dylib[]; -extern unsigned int libcheckra1nhelper_dylib_len; +extern uint8_t Pongo_bin[]; +extern uint32_t Pongo_bin_len; + +#if defined(__APPLE__) && (TARGET_OS_IPHONE || defined(DEV_BUILD) || defined(FORCE_HELPER)) +extern uint8_t libcheckra1nhelper_dylib[]; +extern uint32_t libcheckra1nhelper_dylib_len; #endif #endif diff --git a/src/Makefile b/src/Makefile index 3b35254..83a11b2 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,57 +1,57 @@ all: palera1n -OBJECTS = main.o dfuhelper.o devhelper.o lockdown_helper.o -OBJECTS += optparse.o override_file.o log.o lock_vars.o credits.o -OBJECTS += fake_embedded.o exec_checkra1n.o pongo_helper.o -OBJECTS += boyermoore_memmem.o +OBJDIR = obj +GENDIR = gen +RESOURCES_DIR = resources + +C_SRC = $(wildcard *.c) +OBJS = $(patsubst %,$(OBJDIR)/%,$(C_SRC:.c=.c.o)) ifeq (,$(findstring macosx, $(CFLAGS))) ifneq (,$(findstring version-min=, $(CFLAGS))) -OBJECTS += xxd-libcheckra1nhelper.dylib.o +C_SRC += $(GENDIR)/gen-libcheckra1nhelper.dylib.c endif endif ifeq ($(FORCE_HELPER),1) -OBJECTS += xxd-libcheckra1nhelper.dylib.o +C_SRC += $(GENDIR)/gen-libcheckra1nhelper.dylib.c CFLAGS += -DFORCE_HELPER BUILD_OPTIONS += FORCE_HELPER endif ifneq ($(NO_RAMDISK),1) -OBJECTS += xxd-ramdisk.dmg.lzma.o +C_SRC += $(GENDIR)/gen-ramdisk.dmg.lzma.c else CFLAGS += -DNO_RAMDISK -DRAMDISK_COMPRESSED_SIZE=\"0\" BUILD_OPTIONS += NO_RAMDISK endif ifneq ($(NO_KPF),1) -OBJECTS += xxd-checkra1n-kpf-pongo.o +C_SRC += $(GENDIR)/gen-checkra1n-kpf-pongo.lzma.c else CFLAGS += -DNO_KPF BUILD_OPTIONS += NO_KPF endif ifneq ($(NO_OVERLAY),1) -OBJECTS += xxd-binpack.dmg.o +C_SRC += $(GENDIR)/gen-binpack.dmg.c else CFLAGS += -DNO_OVERLAY BUILD_OPTIONS += NO_OVERLAY endif ifneq ($(NO_CHECKRAIN),1) -OBJECTS += xxd-checkra1n.o +C_SRC += $(GENDIR)/gen-checkra1n.c else CFLAGS += -DNO_CHECKRAIN BUILD_OPTIONS += NO_CHECKRAIN endif ifneq ($(NO_CUSTOM_PONGO),1) -OBJECTS += xxd-Pongo.bin.o +C_SRC += $(GENDIR)/gen-Pongo.bin.c else CFLAGS += -DNO_CUSTOM_PONGO BUILD_OPTIONS += NO_CUSTOM_PONGO endif ifeq ($(TUI),1) -OBJECTS += tui_screen_enter_recovery.o tui_screen_enter_dfu.o tui_main.o -OBJECTS += tui_screen_jailbreak.o tui_screen_main.o tui_screen_options.o BUILD_OPTIONS += TUI CFLAGS += -DTUI endif @@ -62,20 +62,18 @@ LDID = ldid ifeq ($(TARGET_OS),Darwin) ifneq ($(USE_LIBUSB),1) -OBJECTS += usb_iokit.o else LIBS += -framework SystemConfiguration -framework Security BUILD_OPTIONS += USE_LIBUSB endif # add lto and debug symbols for lto CFLAGS += -flto=full -g -LDFLAGS += -Wl,-object_path_lto,lto.o +LDFLAGS += -Wl,-object_path_lto,obj/lto.o else USE_LIBUSB = 1 endif ifeq ($(USE_LIBUSB),1) -OBJECTS += usb_libusb.o CFLAGS += -DUSE_LIBUSB=1 LIBS += $(DEP)/lib/libusb-1.0.a endif @@ -91,75 +89,97 @@ endif CFLAGS += -DBUILD_OPTIONS=\""$(BUILD_OPTIONS)"\" -checkra1n-%: - curl -LO https://assets.checkra.in/downloads/preview/$(CHECKRA1N_VERSION)/$@ +ifeq ($(TARGET_OS),Linux) +ifeq ($(UNAME),Linux) +ifeq ($(CHECKRA1N_NAME),) +ifeq ($(shell arch),x86_64) +CHECKRA1N_NAME := linux-x86_64 +else ifeq ($(shell arch | grep -q 'i[3-7]86' && echo 1),1) +CHECKRA1N_NAME := linux-x86 +else ifeq ($(shell arch | grep -v '\(arm\|aarch\)[a-z]\?\+64' | grep -q arm && echo 1),1) +CHECKRA1N_NAME := linux-armel +else ifeq ($(shell arch | grep -q '\(arm\|aarch\)[a-z]\?\+64' && echo 1),1) +CHECKRA1N_NAME := linux-arm64 +endif +endif +endif +endif + +$(RESOURCES_DIR)/checkra1n-%: + curl -Lfo $@ https://assets.checkra.in/downloads/preview/$(CHECKRA1N_VERSION)/$$(echo $@ | cut -d/ -f2) chmod 755 $@ -checkra1n: checkra1n-macos usb.xml +$(RESOURCES_DIR)/checkra1n: $(RESOURCES_DIR)/checkra1n-macos usb.xml ifeq ($(TARGET_OS),Darwin) ifneq (,$(findstring arm64, $(CFLAGS))) - $(LIPO) -thin arm64 -output checkra1n checkra1n-macos + $(LIPO) -thin arm64 -output $(RESOURCES_DIR)/checkra1n $(RESOURCES_DIR)/checkra1n-macos else ifneq (,$(findstring x86_64, $(CFLAGS))) - $(LIPO) -thin x86_64 -output checkra1n checkra1n-macos + $(LIPO) -thin x86_64 -output $(RESOURCES_DIR)/checkra1n $(RESOURCES_DIR)/checkra1n-macos else ifeq ($(shell arch),i386) - $(LIPO) -thin x86_64 -output checkra1n checkra1n-macos + $(LIPO) -thin x86_64 -output $(RESOURCES_DIR)/checkra1n $(RESOURCES_DIR)/checkra1n-macos else - $(LIPO) -thin $(shell arch) -output checkra1n checkra1n-macos + $(LIPO) -thin $(shell arch) -output $(RESOURCES_DIR)/checkra1n $(RESOURCES_DIR)/checkra1n-macos endif ifeq (,$(findstring macosx, $(CFLAGS))) ifneq (,$(findstring version-min=, $(CFLAGS))) - vtool -remove-build-version 1 -replace -output checkra1n checkra1n - vtool -set-build-version $(FAKE_PLATFORM) $(FAKE_MINOS) $(FAKE_SDK) -replace -output checkra1n checkra1n - install_name_tool -change /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit /System/Library/Frameworks/IOKit.framework/IOKit checkra1n - install_name_tool -change /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation checkra1n - $(LDID) -Susb.xml checkra1n + vtool -remove-build-version 1 -replace -output $(RESOURCES_DIR)/checkra1n $(RESOURCES_DIR)/checkra1n + vtool -set-build-version $(FAKE_PLATFORM) $(FAKE_MINOS) $(FAKE_SDK) -replace -output $(RESOURCES_DIR)/checkra1n $(RESOURCES_DIR)/checkra1n + install_name_tool -change /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit /System/Library/Frameworks/IOKit.framework/IOKit $(RESOURCES_DIR)/checkra1n + install_name_tool -change /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation $(RESOURCES_DIR)/checkra1n + $(LDID) -Susb.xml $(RESOURCES_DIR)/checkra1n endif endif else - cp checkra1n-$(CHECKRA1N_NAME) checkra1n + cp $(RESOURCES_DIR)/checkra1n-$(CHECKRA1N_NAME) $(RESOURCES_DIR)/checkra1n endif -xxd-%.c: % - xxd -iC $< > $@ +$(GENDIR)/gen-%.c: $(RESOURCES_DIR)/% + echo '#include ' > $(RESOURCES_DIR)/../$@ + cd $(RESOURCES_DIR) && xxd -iC $$(echo $< | cut -d/ -f2) | sed -e 's/unsigned int/uint32_t/' -e 's/unsigned char/uint8_t/' >> ../$@ -ifneq ($(NO_RAMDISK),1) -pongo_helper.o: pongo_helper.c $(wildcard ../include/*.h) ramdisk.dmg - $(CC) -c $(CFLAGS) -DRAMDISK_UNCOMPRESSED_SIZE="\"$$(wc -c < ramdisk.dmg | tr -d ' ')\"" $< -else -pongo_helper.o: pongo_helper.c $(wildcard ../include/*.h) - $(CC) -c $(CFLAGS) $< -endif -%.o: %.c $(wildcard ../include/*.h) - $(CC) -c $(CFLAGS) $< +$(OBJDIR)/pongo_helper.c.o: pongo_helper.c $(wildcard ../include/*.h) $(RESOURCES_DIR)/ramdisk.dmg $(RESOURCES_DIR)/checkra1n-kpf-pongo + $(CC) -c -o $@ $(CFLAGS) -DRAMDISK_UNCOMPRESSED_SIZE="\"$$(wc -c < $(RESOURCES_DIR)/ramdisk.dmg | tr -d ' ')\"" -DKPF_UNCOMPRESSED_SIZE="\"$$(wc -c < $(RESOURCES_DIR)/checkra1n-kpf-pongo | tr -d ' ')\"" $< -palera1n: $(OBJECTS) - $(CC) $(CFLAGS) $(LDFLAGS) $(OBJECTS) $(LIBS) -o palera1n +$(OBJDIR)/%.c.o: $(GENDIR)/gen-%.c $(wildcard ../include/*.h) + $(CC) $(CFLAGS) -c -o $< + +$(OBJDIR)/%.c.o: %.c $(wildcard ../include/*.h) + $(CC) $(CFLAGS) -c -o $@ $< + +palera1n: $(OBJS) + $(CC) $(CFLAGS) $(LDFLAGS) $(OBJS) $(LIBS) -o palera1n ifeq (,$(findstring macosx, $(CFLAGS))) ifneq (,$(findstring version-min=, $(CFLAGS))) $(LDID) -Susb.xml palera1n endif endif -libcheckra1nhelper.dylib: chkstk.S - $(CC) $(CFLAGS) $(LDFLAGS) -shared chkstk.S -o libcheckra1nhelper.dylib +$(RESOURCES_DIR)/libcheckra1nhelper.dylib: chkstk.S + $(CC) $(CFLAGS) $(LDFLAGS) -shared chkstk.S -o $@ -checkra1n-kpf-pongo: - curl -LO https://cdn.nickchan.lol/palera1n/artifacts/kpf/iOS15/checkra1n-kpf-pongo +$(RESOURCES_DIR)/checkra1n-kpf-pongo: + curl -Lfo $@ https://cdn.nickchan.lol/palera1n/artifacts/kpf/iOS15/checkra1n-kpf-pongo -ramdisk.dmg.lzma: ramdisk.dmg - xz --format=lzma -vf6ekT 0 ramdisk.dmg +$(RESOURCES_DIR)/ramdisk.dmg.lzma: $(RESOURCES_DIR)/ramdisk.dmg + xz --format=lzma -vfc6ekT 0 $< > $@ -ramdisk.dmg: - curl -LO https://cdn.nickchan.lol/palera1n/c-rewrite/deps/ramdisk.dmg +$(RESOURCES_DIR)/checkra1n-kpf-pongo.lzma: $(RESOURCES_DIR)/checkra1n-kpf-pongo + xz --format=lzma -vfc6ekT 0 $< > $@ -binpack.dmg: - curl -LO https://cdn.nickchan.lol/palera1n/c-rewrite/deps/binpack.dmg +$(RESOURCES_DIR)/ramdisk.dmg: + curl -Lfo $@ https://cdn.nickchan.lol/palera1n/c-rewrite/deps/ramdisk.dmg -Pongo.bin: - curl -LO https://cdn.nickchan.lol/palera1n/artifacts/kpf/iOS15/Pongo.bin +$(RESOURCES_DIR)/binpack.dmg: + curl -Lfo $@ https://cdn.nickchan.lol/palera1n/c-rewrite/deps/binpack.dmg + +$(RESOURCES_DIR)/Pongo.bin: + curl -Lfo $@ https://cdn.nickchan.lol/palera1n/artifacts/kpf/iOS15/Pongo.bin clean: - rm -rf *.o palera1n checkra1n checkra1n.c palera1n.dSYM ramdisk.dmg.lzma libcheckra1nhelper.dylib + rm -rf $(OBJDIR)/*.o $(GENDIR)/*.c $(GENDIR)/*.o palera1n palera1n.dSYM libcheckra1nhelper.dylib + +distclean: clean + rm -rf $(RESOURCES_DIR)/* .PHONY: all clean diff --git a/src/devhelper.c b/src/devhelper.c index e05075f..87e5ab2 100644 --- a/src/devhelper.c +++ b/src/devhelper.c @@ -28,8 +28,6 @@ #include #include -#include "lockdown_helper.h" - #ifdef HAVE_LIB_TV_CONTROL #include #endif @@ -104,6 +102,7 @@ int unsubscribe_cmd(void) int devinfo_cmd(devinfo_t *dev, const char *udid) { + int ret; uint64_t this_ecid = 0; char *productType = NULL; char *productVersion = NULL; @@ -112,67 +111,67 @@ int devinfo_cmd(devinfo_t *dev, const char *udid) char *CPUArchitecture = NULL; idevice_t device = NULL; lockdownd_client_t lockdown = NULL; - if (idevice_new(&device, udid) != IDEVICE_E_SUCCESS) + if ((ret = idevice_new_with_options(&device, udid, IDEVICE_LOOKUP_USBMUX)) != IDEVICE_E_SUCCESS) { - LOG(LOG_ERROR, "Error connecting to device."); + LOG(LOG_ERROR, "Error connecting to device: %d (%s)", ret, lockdownd_strerror(ret)); return -1; } - if (lockdownd_client_new(device, &lockdown, "palera1n") != LOCKDOWN_E_SUCCESS) + if ((ret = lockdownd_client_new_with_handshake(device, &lockdown, "palera1n")) != LOCKDOWN_E_SUCCESS) { (void)idevice_free(device); - LOG(LOG_ERROR, "Device is not in normal mode."); + LOG(LOG_ERROR, "Device is not in normal mode: %d (%s)", ret, lockdownd_strerror(ret)); return -1; } plist_t node = NULL; - if (lockdownd_get_value(lockdown, NULL, "UniqueChipID", &node) != LOCKDOWN_E_SUCCESS) + if ((ret = lockdownd_get_value(lockdown, NULL, "UniqueChipID", &node)) != LOCKDOWN_E_SUCCESS) { (void)lockdownd_client_free(lockdown); (void)idevice_free(device); - LOG(LOG_ERROR, "Error getting ECID"); + LOG(LOG_ERROR, "Error getting ECID: %d (%s)", ret, lockdownd_strerror(ret)); return -1; } plist_get_uint_val(node, &this_ecid); plist_free(node); node = NULL; - if (lockdownd_get_value(lockdown, NULL, "ProductType", &node) != LOCKDOWN_E_SUCCESS) + if ((ret = lockdownd_get_value(lockdown, NULL, "ProductType", &node)) != LOCKDOWN_E_SUCCESS) { (void)lockdownd_client_free(lockdown); (void)idevice_free(device); - LOG(LOG_ERROR, "Error getting product type"); + LOG(LOG_ERROR, "Error getting product type: %d (%s)", ret, lockdownd_strerror(ret)); return -1; } plist_get_string_val(node, &productType); plist_free(node); node = NULL; - if (lockdownd_get_value(lockdown, NULL, "CPUArchitecture", &node) != LOCKDOWN_E_SUCCESS) + if ((ret = lockdownd_get_value(lockdown, NULL, "CPUArchitecture", &node)) != LOCKDOWN_E_SUCCESS) { (void)lockdownd_client_free(lockdown); (void)idevice_free(device); - LOG(LOG_ERROR, "Error getting CPU type"); + LOG(LOG_ERROR, "Error getting CPU type: %d (%s)", ret, lockdownd_strerror(ret)); return -1; } plist_get_string_val(node, &CPUArchitecture); plist_free(node); node = NULL; - if (lockdownd_get_value(lockdown, NULL, "ProductVersion", &node) != LOCKDOWN_E_SUCCESS) + if ((ret = lockdownd_get_value(lockdown, NULL, "ProductVersion", &node)) != LOCKDOWN_E_SUCCESS) { (void)lockdownd_client_free(lockdown); (void)idevice_free(device); - LOG(LOG_ERROR, "Error getting product version"); + LOG(LOG_ERROR, "Error getting product version: %d (%s)", ret, lockdownd_strerror(ret)); return -1; } plist_get_string_val(node, &productVersion); plist_free(node); node = NULL; - if (lockdownd_get_value(lockdown, NULL, "BuildVersion", &node) != LOCKDOWN_E_SUCCESS) + if ((ret = lockdownd_get_value(lockdown, NULL, "BuildVersion", &node)) != LOCKDOWN_E_SUCCESS) { (void)lockdownd_client_free(lockdown); (void)idevice_free(device); - LOG(LOG_ERROR, "Error getting build version"); + LOG(LOG_ERROR, "Error getting build version: %d (%s)", ret, lockdownd_strerror(ret)); return -1; } plist_get_string_val(node, &buildVersion); diff --git a/src/dfuhelper.c b/src/dfuhelper.c index 268c278..1ecb234 100644 --- a/src/dfuhelper.c +++ b/src/dfuhelper.c @@ -218,7 +218,7 @@ void irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) { event->mode == IRECV_K_RECOVERY_MODE_3 || event->mode == IRECV_K_RECOVERY_MODE_4) { if (!(palerain_flags & palerain_option_device_info)) - LOG(LOG_VERBOSE, "Recovery mode device %ld connected", event->device_info->ecid); + LOG(LOG_VERBOSE, "Recovery mode device %" PRIu64 " connected", event->device_info->ecid); if ((palerain_flags & palerain_option_exit_recovery)) { ret = exitrecv_cmd(event->device_info->ecid); if (!ret) { @@ -258,7 +258,7 @@ void irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) { pthread_create(&recovery_thread, NULL, (pthread_start_t)connected_recovery_mode, event->device_info); } else if (event->mode == IRECV_K_DFU_MODE) { if (!(palerain_flags & palerain_option_device_info)) - LOG(LOG_VERBOSE, "DFU mode device %ld connected", event->device_info->ecid); + LOG(LOG_VERBOSE, "DFU mode device %" PRIu64 " connected", event->device_info->ecid); if ((palerain_flags & palerain_option_device_info)) { recvinfo_t info; diff --git a/src/exec_checkra1n.c b/src/exec_checkra1n.c index 9cc47fb..9cfe6d3 100644 --- a/src/exec_checkra1n.c +++ b/src/exec_checkra1n.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #if defined(__APPLE__) @@ -42,6 +43,10 @@ int exec_checkra1n(void) { #ifndef NO_CUSTOM_PONGO if (pongo_path == NULL) { pongo_path = malloc(strlen(tmpdir) + 20); + if (pongo_path == NULL) { + LOG(LOG_FATAL, "memory allocation failed\n"); + return -1; + } snprintf(pongo_path, strlen(tmpdir) + 20, "%s/Pongo.bin.XXXXXX", tmpdir); fd_pongo = mkstemp(pongo_path); if (fd_pongo == -1) { @@ -51,7 +56,7 @@ int exec_checkra1n(void) { } ssize_t didWrite_Pongo_bin = write(fd_pongo, Pongo_bin, Pongo_bin_len); if (didWrite_Pongo_bin != (ssize_t)Pongo_bin_len) { - LOG(LOG_FATAL, "Size written to %s does not match expected: %lld != %d: %d (%s)", pongo_path, didWrite_Pongo_bin, Pongo_bin_len, errno, strerror(errno)); + LOG(LOG_FATAL, "Size written to %s does not match expected: %zd != %" PRIu32 ": %d (%s)", pongo_path, didWrite_Pongo_bin, Pongo_bin_len, errno, strerror(errno)); close(fd_pongo); unlink(pongo_path); free(pongo_path); @@ -61,6 +66,10 @@ int exec_checkra1n(void) { } else external_pongo = true; #endif checkra1n_path = malloc(strlen(tmpdir) + 20); + if (checkra1n_path == NULL) { + LOG(LOG_FATAL, "memory allocation failed\n"); + return -1; + } snprintf(checkra1n_path, strlen(tmpdir) + 20, "%s/checkra1n.XXXXXX", tmpdir); fd_checkra1n = mkstemp(checkra1n_path); if (fd_checkra1n == -1) { @@ -71,7 +80,7 @@ int exec_checkra1n(void) { } ssize_t didWrite_checkra1n = write(fd_checkra1n, checkra1n, checkra1n_len); if (didWrite_checkra1n != (ssize_t)checkra1n_len) { - LOG(LOG_FATAL, "Size written to %s does not match expected: %lld != %d: %d (%s)", checkra1n_path, didWrite_checkra1n, checkra1n_len, errno, strerror(errno)); + LOG(LOG_FATAL, "Size written to %s does not match expected: %zd != %" PRIu32 ": %d (%s)", checkra1n_path, didWrite_checkra1n, checkra1n_len, errno, strerror(errno)); close(fd_checkra1n); unlink(checkra1n_path); free(checkra1n_path); @@ -98,6 +107,10 @@ int exec_checkra1n(void) { if (darwinMajor < 20) { #endif libcheckra1nhelper_dylib_path = malloc(strlen(tmpdir) + 40); + if (libcheckra1nhelper_dylib_path == NULL) { + LOG(LOG_FATAL, "memory allocation failed\n"); + return -1; + } snprintf(libcheckra1nhelper_dylib_path, strlen(tmpdir) + 40, "%s/libcheckra1nhelper.dylib.XXXXXX", tmpdir); int helper_fd = mkstemp(libcheckra1nhelper_dylib_path); if (helper_fd == -1) { @@ -106,7 +119,7 @@ int exec_checkra1n(void) { } ssize_t didWrite_libcheckra1nhelper = write(helper_fd, libcheckra1nhelper_dylib, libcheckra1nhelper_dylib_len); if ((unsigned int)didWrite_libcheckra1nhelper != libcheckra1nhelper_dylib_len) { - LOG(LOG_FATAL, "Size written does not match expected: %lld != %d: %d (%s)", didWrite_libcheckra1nhelper, libcheckra1nhelper_dylib_len, errno, strerror(errno)); + LOG(LOG_FATAL, "Size written does not match expected: %zd != %" PRIu32 ": %d (%s)", didWrite_libcheckra1nhelper, libcheckra1nhelper_dylib_len, errno, strerror(errno)); close(helper_fd); unlink(libcheckra1nhelper_dylib_path); return -1; diff --git a/src/fake_embedded.c b/src/fake_embedded.c index 17dd279..5a6715d 100644 --- a/src/fake_embedded.c +++ b/src/fake_embedded.c @@ -1,8 +1,8 @@ #include #ifdef NO_KPF -unsigned char* checkra1n_kpf_pongo = NULL; -unsigned int checkra1n_kpf_pongo_len = 0; +unsigned char* checkra1n_kpf_pongo_lzma = NULL; +unsigned int checkra1n_kpf_pongo_lzma_len = 0; #endif #ifdef NO_RAMDISK diff --git a/src/gen/.gitignore b/src/gen/.gitignore new file mode 100644 index 0000000..5761abc --- /dev/null +++ b/src/gen/.gitignore @@ -0,0 +1 @@ +*.o diff --git a/src/gen/resources b/src/gen/resources new file mode 120000 index 0000000..945c9b4 --- /dev/null +++ b/src/gen/resources @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/src/lockdown_helper.c b/src/lockdown_helper.c deleted file mode 100644 index b7b941c..0000000 --- a/src/lockdown_helper.c +++ /dev/null @@ -1,245 +0,0 @@ -#ifndef HAVE_LIBIMOBILEDEVICE -#include "lockdown_helper.h" -#include -#include -#include -#include -#include -#include -#include - -#ifdef DEBUG -#define log_debug(...) fprintf(stderr, __VA_ARGS__); fputc('\n', stderr) -#else -#define log_debug(...) do {} while (0) -#endif -#define log_error(...) fprintf(stderr, __VA_ARGS__); fputc('\n', stderr) - -int lockdown_connect_handle(uint32_t handle) { - int fd = usbmuxd_connect(handle, 62078); - if (fd < 0) { - log_debug("Can't connect to lockownd on device #%u", handle); - } - return fd; -} - -int lockdown_connect_udid(const char* udid) { - usbmuxd_device_info_t device; - if (usbmuxd_get_device_by_udid(udid, &device) < 0) { - log_debug("Can't find device %s", udid); - return -ENOENT; - } - return lockdown_connect_handle(device.handle); -} - -void lockdown_disconnect(int fd) { - usbmuxd_disconnect(fd); -} - -int lockdown_check_type(int fd, const char* type_match); - -static const char QUERY_TYPE_REQUEST[] = "____Labelpalera1nRequestQueryType"; -static const char GET_VALUE_DOMAIN_REQUEST_FMT[] = "____Labelpalera1nDomain%sKey%sRequestGetValue"; -static const char GET_VALUE_REQUEST_FMT[] = "____Labelpalera1nKey%sRequestGetValue"; -static const char VALUE_KEY_NODE[] = "Value"; -static const char INTEGER_NODE[] = ""; -static const char STRING_NODE[] = ""; -static const char ENTER_RECOVERY_REQUEST[] = "____Labelpalera1nRequestEnterRecovery"; -static const char ERROR_KEY_NODE[] = "Error"; -static const char ENTER_RECOVERY_STRING_NODE[] = "EnterRecovery"; -static const int VALUE_KEY_NODE_SIZE = sizeof(VALUE_KEY_NODE)-1; -static const int INTEGER_NODE_SIZE = sizeof(INTEGER_NODE)-1; -static const int STRING_NODE_SIZE = sizeof(STRING_NODE)-1; -static const int ERROR_KEY_NODE_SIZE = sizeof(ERROR_KEY_NODE)-1; - -static void skip_ws(char** cur, char* end) { - char* p = *cur; - while (p < end && ((*p == ' ') || (*p == '\t') || (*p == '\r') || (*p == '\n'))) { - p++; - } - *cur = p; -} - -static char* _send_request_and_get_reply(int fd, const char* request, uint32_t len, uint32_t* received) { - uint32_t sent_bytes = 0; - usbmuxd_send(fd, request, len, &sent_bytes); - if (sent_bytes != len) { - usbmuxd_disconnect(fd); - log_error("Failed to send data payload"); - return NULL; - } - - uint32_t recv_bytes = 0; - uint32_t besize = 0; - int r = usbmuxd_recv(fd, (char*)&besize, sizeof(besize), &recv_bytes); - if (recv_bytes != sizeof(besize)) { - usbmuxd_disconnect(fd); - log_error("Failed to get size of packet (%d)", r); - return NULL; - } - - uint32_t resp_size = ntohl(besize); - char* resp = (char*)malloc(resp_size+1); - - recv_bytes = 0; - usbmuxd_recv(fd, resp, resp_size, &recv_bytes); - if (recv_bytes != resp_size) { - usbmuxd_disconnect(fd); - free(resp); - log_error("Failed to receive payload"); - return NULL; - } - resp[resp_size] = '\0'; - *received = resp_size; - return resp; -} - -int lockdown_check_type(int fd, const char* type_match) { - unsigned char tmp[512]; - uint32_t len = (uint32_t)snprintf((char*)tmp, 512, QUERY_TYPE_REQUEST); - uint32_t belen = htonl(len-4); - *(uint32_t*)tmp = belen; - uint32_t resp_size = 0; - char* resp = _send_request_and_get_reply(fd, (char*)tmp, len, &resp_size); - if (!resp) { - log_error("Failed to get lockdown type"); - return -1; - } - - int result = (strstr(resp, type_match) == NULL) ? -1 : 0; - free(resp); - - return result; -} - -int lockdown_get_uint_value(int fd, const char* domain, const char* key, uint64_t* value) { - char tmp[1024]; - uint32_t len; - if (domain) { - len = snprintf(tmp, 1024, GET_VALUE_DOMAIN_REQUEST_FMT, domain, key); - } else { - len = snprintf(tmp, 1024, GET_VALUE_REQUEST_FMT, key); - } - *(uint32_t*)&tmp = htonl(len-4); - - uint32_t resp_size = 0; - char* resp = _send_request_and_get_reply(fd, tmp, len, &resp_size); - if (!resp) { - log_error("Failed to get value for key %s", key); - return -1; - } - - char* p = strstr(resp, VALUE_KEY_NODE); - if (!p) { - log_debug("Failed to get Value key node?!"); - return -1; - } - p += VALUE_KEY_NODE_SIZE; - skip_ws(&p, resp+resp_size); - if (p >= resp+resp_size) { - log_debug("Failed to get value node"); - return -1; - } - if (strncmp(p, INTEGER_NODE, INTEGER_NODE_SIZE) != 0) { - log_debug("Failed to parse value node"); - return -1; - } - p += INTEGER_NODE_SIZE; - *value = (uint64_t)strtoll(p, NULL, 10); - free(resp); - - return 0; -} - -int lockdown_get_string_value(int fd, const char* domain, const char* key, char** value) { - char tmp[1024]; - uint32_t len; - if (domain) { - len = snprintf(tmp, 1024, GET_VALUE_DOMAIN_REQUEST_FMT, domain, key); - } else { - len = snprintf(tmp, 1024, GET_VALUE_REQUEST_FMT, key); - } - *(uint32_t*)&tmp = htonl(len-4); - - uint32_t resp_size = 0; - char* resp = _send_request_and_get_reply(fd, tmp, len, &resp_size); - if (!resp) { - log_error("Failed to get value for key %s", key); - return -1; - } - - char* p = strstr(resp, VALUE_KEY_NODE); - if (!p) { - log_debug("Failed to get Value key node?!"); - free(resp); - return -1; - } - p += VALUE_KEY_NODE_SIZE; - skip_ws(&p, resp+resp_size); - if (p >= resp+resp_size) { - log_debug("Failed to get value node"); - free(resp); - return -1; - } - if (strncmp(p, STRING_NODE, STRING_NODE_SIZE) != 0) { - log_debug("Failed to parse value node"); - free(resp); - return -1; - } - p += STRING_NODE_SIZE; - char* str_start = p; - while (*p != '<' && *p != '\0') p++; - if (*p == '\0') { - log_debug("Failed to parse string value node"); - free(resp); - return -1; - } - size_t str_len = p - str_start; - *value = (char*)malloc(str_len + 1); - snprintf(*value, str_len, "%s", str_start); - (*value)[str_len] = '\0'; - free(resp); - - return 0; -} - -int lockdown_enter_recovery(int fd) { - char tmp[512]; - uint32_t len = (uint32_t)snprintf(tmp, 512, ENTER_RECOVERY_REQUEST); - *(uint32_t*)&tmp = htonl(len-4); - uint32_t resp_size = 0; - char* resp = _send_request_and_get_reply(fd, tmp, len, &resp_size); - if (!resp) { - log_error("Failed to enter recover?"); - return -1; - } - - int result = -1; - char* p = strstr(resp, ERROR_KEY_NODE); - if (p) { - char* str_start = NULL; - size_t str_len = 0; - p += ERROR_KEY_NODE_SIZE; - skip_ws(&p, resp+resp_size); - if (*p && !strncmp(p, STRING_NODE, STRING_NODE_SIZE)) { - p += STRING_NODE_SIZE; - str_start = p; - while (*p != '<' && *p != '\0') p++; - if (*p == '<') { - str_len = p - str_start; - } - } - if (str_start && str_len > 0) { - log_error("ERROR: Failed to make device enter recovery mode: %.*s", (int)str_len, str_start); - } else { - log_error("ERROR: Failed to make device enter recovery mode: (unknown error)"); - } - result = -2; - } else { - result = (strstr(resp, ENTER_RECOVERY_STRING_NODE) == NULL) ? -1 : 0; - } - free(resp); - return result; -} - -#endif diff --git a/src/lockdown_helper.h b/src/lockdown_helper.h deleted file mode 100644 index 6c50ff8..0000000 --- a/src/lockdown_helper.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __LOCKDOWN_HELPER_H -#define __LOCKDOWN_HELPER_H - -#ifndef HAVE_LIBIMOBILEDEVICE - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -int lockdown_connect_udid(const char* udid); -int lockdown_connect_handle(uint32_t handle); - -void lockdown_disconnect(int fd); - -int lockdown_check_type(int fd, const char* type_match); - -int lockdown_get_uint_value(int fd, const char* domain, const char* key, uint64_t* value); -int lockdown_get_string_value(int fd, const char* domain, const char* key, char** value); - -int lockdown_enter_recovery(int fd); - -#ifdef __cplusplus -} -#endif - -#endif - -#endif diff --git a/src/main.c b/src/main.c index 7908664..13bc5ac 100644 --- a/src/main.c +++ b/src/main.c @@ -33,10 +33,12 @@ #define OVERRIDE_MAGIC 0xd803b376 unsigned int verbose = 0; -char xargs_cmd[0x270] = "xargs ", palerain_flags_cmd[0x30] = "deadbeef"; +/* we want to write to them so don't use string literals */ +char xargs_cmd[0x270] = { 'x', 'a', 'r', 'g', 's', '\0' }, + palerain_flags_cmd[0x30] = { 'd', 'e', 'a', 'd', 'b', 'e', 'e', 'f', '\0' }; extern char** environ; -niarelap_file_t* kpf_to_upload_1 = &checkra1n_kpf_pongo; +niarelap_file_t* kpf_to_upload_1 = &checkra1n_kpf_pongo_lzma; niarelap_file_t* ramdisk_to_upload_1 = &ramdisk_dmg_lzma; niarelap_file_t* overlay_to_upload_1 = &binpack_dmg; @@ -74,19 +76,6 @@ int build_checks(void) { if (boyermoore_horspool_memmem(&checkra1n[0], checkra1n_len, (const unsigned char *)"[ra1npoc15-part] thanks to", strlen("[ra1npoc15-part] thanks to")) != NULL) { palerain_flags |= palerain_option_checkrain_is_clone; } -#endif -#ifndef NO_KPF - struct mach_header_64 *kpf_hdr = (struct mach_header_64 *)checkra1n_kpf_pongo; - if (kpf_hdr->magic != MH_MAGIC_64 && kpf_hdr->magic != MH_CIGAM_64) { - LOG(LOG_FATAL, "Broken build: Invalid kernel patchfinder: Not thin 64-bit Mach-O"); - return -1; - } else if (kpf_hdr->filetype != MH_KEXT_BUNDLE) { - LOG(LOG_FATAL, "Broken build: Invalid kernel patchfinder: Not a kext bundle"); - return -1; - } else if (kpf_hdr->cputype != CPU_TYPE_ARM64) { - LOG(LOG_FATAL, "Broken build: Invalid kernel patchfinder: CPU type is not arm64"); - return -1; - } #endif return 0; } @@ -135,7 +124,7 @@ int palera1n(int argc, char *argv[]) { if (!(palerain_flags & palerain_option_device_info)) LOG(LOG_INFO, "Waiting for devices"); - if (access("/var/run/usbmuxd", F_OK) != 0) + if (getenv("USBMUXD_SOCKET_ADDRESS") == NULL && access("/var/run/usbmuxd", F_OK) != 0) LOG(LOG_WARNING, "/var/run/usbmuxd not found, normal mode device detection will not work."); pthread_create(&pongo_thread, NULL, pongo_helper, NULL); diff --git a/src/obj/.gitignore b/src/obj/.gitignore new file mode 100644 index 0000000..5761abc --- /dev/null +++ b/src/obj/.gitignore @@ -0,0 +1 @@ +*.o diff --git a/src/obj/gen b/src/obj/gen new file mode 120000 index 0000000..945c9b4 --- /dev/null +++ b/src/obj/gen @@ -0,0 +1 @@ +. \ No newline at end of file diff --git a/src/optparse.c b/src/optparse.c index 6631c97..4993906 100644 --- a/src/optparse.c +++ b/src/optparse.c @@ -200,7 +200,11 @@ int optparse(int argc, char* argv[]) { return -1; } pongo_path = malloc(strlen(optarg) + 1); - strcpy(pongo_path, optarg); + if (pongo_path == NULL) { + LOG(LOG_FATAL, "memory allocation failed"); + return -1; + } + snprintf(pongo_path, strlen(optarg) + 1, "%s", optarg); break; case 'o': if (override_file(&override_overlay, overlay_to_upload, &binpack_dmg_len, optarg)) @@ -211,7 +215,7 @@ int optparse(int argc, char* argv[]) { return 1; break; case 'K': - if (override_file(&override_kpf, kpf_to_upload, &checkra1n_kpf_pongo_len, optarg)) + if (override_file(&override_kpf, kpf_to_upload, &checkra1n_kpf_pongo_lzma_len, optarg)) return 1; struct mach_header_64* hdr = (struct mach_header_64*)override_kpf.ptr; if (hdr->magic != MH_MAGIC_64 && hdr->magic != MH_CIGAM_64) { @@ -323,19 +327,24 @@ int optparse(int argc, char* argv[]) { if ((strstr(xargs_cmd, "serial=") != NULL) && !force_use_verbose_boot && (palerain_flags & palerain_option_setup_rootful)) { palerain_flags &= ~palerain_option_verbose_boot; } + + if ((palerain_flags & (palerain_option_rootless | palerain_option_rootful)) == 0) { + LOG(LOG_FATAL, "must specify -l option"); + return -1; + } snprintf(palerain_flags_cmd, 0x30, "palera1n_flags 0x%" PRIx64, palerain_flags); LOG(LOG_VERBOSE3, "palerain_flags: %s", palerain_flags_cmd); if (override_kpf.magic == OVERRIDE_MAGIC) { - LOG(LOG_VERBOSE4, "kpf override length %u -> %u", override_kpf.orig_len, checkra1n_kpf_pongo_len); + LOG(LOG_VERBOSE4, "kpf override length %" PRIu32 " -> %" PRIu32, override_kpf.orig_len, checkra1n_kpf_pongo_lzma_len); LOG(LOG_VERBOSE4, "kpf override ptr %p -> %p", override_kpf.orig_ptr, **kpf_to_upload); } if (override_ramdisk.magic == OVERRIDE_MAGIC) { - LOG(LOG_VERBOSE4, "ramdisk override length %u -> %u", override_ramdisk.orig_len, ramdisk_dmg_lzma_len); + LOG(LOG_VERBOSE4, "ramdisk override length %" PRIu32 " -> %" PRIu32, override_ramdisk.orig_len, ramdisk_dmg_lzma_len); LOG(LOG_VERBOSE4, "ramdisk override ptr %p -> %p", override_ramdisk.orig_ptr, **ramdisk_to_upload); } if (override_overlay.magic == OVERRIDE_MAGIC) { - LOG(LOG_VERBOSE4, "overlay override length %u -> %u", override_overlay.orig_len, binpack_dmg_len); + LOG(LOG_VERBOSE4, "overlay override length %" PRIu32 " -> %" PRIu32, override_overlay.orig_len, binpack_dmg_len); LOG(LOG_VERBOSE4, "overlay override ptr %p -> %p", override_overlay.orig_ptr, **overlay_to_upload); } @@ -360,7 +369,7 @@ int optparse(int argc, char* argv[]) { if (!((palerain_flags & palerain_option_pongo_exit) || (palerain_flags & palerain_option_pongo_exit))) { #ifdef NO_KPF - if (checkra1n_kpf_pongo_len == 0) + if (checkra1n_kpf_pongo_lzma_len == 0) { LOG(LOG_FATAL, "kernel patchfinder omitted in build but no override specified"); return -1; diff --git a/src/pongo_helper.c b/src/pongo_helper.c index 47323b9..74f5d43 100644 --- a/src/pongo_helper.c +++ b/src/pongo_helper.c @@ -41,20 +41,20 @@ void *pongo_usb_callback(stuff_t *arg) { issue_pongo_command(handle, NULL); issue_pongo_command(handle, "fuse lock"); issue_pongo_command(handle, "sep auto"); - upload_pongo_file(handle, **kpf_to_upload, checkra1n_kpf_pongo_len); - issue_pongo_command(handle, "modload"); - issue_pongo_command(handle, palerain_flags_cmd); - if ((palerain_flags & palerain_option_rootful)) - { - issue_pongo_command(handle, "rootfs"); + upload_pongo_file(handle, **kpf_to_upload, checkra1n_kpf_pongo_lzma_len); + if (*kpf_to_upload == &checkra1n_kpf_pongo_lzma) { + issue_pongo_command(handle, "modload " KPF_UNCOMPRESSED_SIZE); + } else { + issue_pongo_command(handle, "modload"); } + issue_pongo_command(handle, palerain_flags_cmd); #ifdef NO_RAMDISK if (ramdisk_dmg_lzma_len != 0) #endif { - strncat(xargs_cmd, " rootdev=md0", 0x270 - strlen(xargs_cmd) - 1); + // strncat(xargs_cmd, " rootdev=md0", 0x270 - strlen(xargs_cmd) - 1); upload_pongo_file(handle, **ramdisk_to_upload, ramdisk_dmg_lzma_len); - if (&(**ramdisk_to_upload) == &ramdisk_dmg_lzma) + if ((*ramdisk_to_upload) == &ramdisk_dmg_lzma) issue_pongo_command(handle, "ramdisk " RAMDISK_UNCOMPRESSED_SIZE); else { issue_pongo_command(handle, "ramdisk"); diff --git a/src/resources/.gitignore b/src/resources/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/src/resources/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/src/tui_main.c b/src/tui_main.c index 8086122..64e49a0 100644 --- a/src/tui_main.c +++ b/src/tui_main.c @@ -1,3 +1,4 @@ +#ifdef TUI #include #include #include @@ -99,3 +100,7 @@ out: tui_started = false; return 0; } +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; +#endif diff --git a/src/tui_screen_enter_dfu.c b/src/tui_screen_enter_dfu.c index 92d3db3..f6ef518 100644 --- a/src/tui_screen_enter_dfu.c +++ b/src/tui_screen_enter_dfu.c @@ -1,3 +1,4 @@ +#ifdef TUI #include #include #include @@ -13,3 +14,8 @@ #include tui_screen_t tui_screen_enter_dfu(void) { return JAILBREAKING_SCREEN; } + +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; +#endif diff --git a/src/tui_screen_enter_recovery.c b/src/tui_screen_enter_recovery.c index db07ca8..f1e1d5f 100644 --- a/src/tui_screen_enter_recovery.c +++ b/src/tui_screen_enter_recovery.c @@ -1,3 +1,4 @@ +#ifdef TUI #include #include #include @@ -13,3 +14,8 @@ #include tui_screen_t tui_screen_enter_recovery(void) { return ENTER_DFU_SCREEN; } + +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; +#endif diff --git a/src/tui_screen_jailbreak.c b/src/tui_screen_jailbreak.c index 6d6e453..c533180 100644 --- a/src/tui_screen_jailbreak.c +++ b/src/tui_screen_jailbreak.c @@ -1,3 +1,4 @@ +#ifdef TUI #include #include #include @@ -13,3 +14,8 @@ #include tui_screen_t tui_screen_jailbreak(void) { return EXIT_SCREEN; } + +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; +#endif diff --git a/src/tui_screen_main.c b/src/tui_screen_main.c index d3e614a..c74f9ad 100644 --- a/src/tui_screen_main.c +++ b/src/tui_screen_main.c @@ -1,3 +1,4 @@ +#ifdef TUI #include #include #include @@ -45,3 +46,8 @@ tui_screen_t tui_screen_main(void) { newtFormDestroy(form); return ret; } + +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; +#endif diff --git a/src/tui_screen_options.c b/src/tui_screen_options.c index e00eaff..e5f17d2 100644 --- a/src/tui_screen_options.c +++ b/src/tui_screen_options.c @@ -1,3 +1,4 @@ +#ifdef TUI #include #include #include @@ -73,3 +74,8 @@ tui_screen_t tui_screen_options(void) { newtFormDestroy(form); return ret; } + +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; +#endif diff --git a/src/usb_iokit.c b/src/usb_iokit.c index 3481939..59cf59a 100644 --- a/src/usb_iokit.c +++ b/src/usb_iokit.c @@ -24,6 +24,7 @@ * SOFTWARE. * */ +#ifndef USE_LIBUSB #include #include // open #include @@ -250,3 +251,7 @@ int wait_for_pongo(void) { CFRelease(cfdict); return 0; } +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; +#endif diff --git a/src/usb_libusb.c b/src/usb_libusb.c index 3685379..1e8696c 100644 --- a/src/usb_libusb.c +++ b/src/usb_libusb.c @@ -264,4 +264,7 @@ int wait_for_pongo(void) libusb_exit(ctx); return 0; } +#else +/* ISO C forbids an empty translation unit */ +extern char** environ; #endif