mirror of
https://github.com/palera1n/palera1n.git
synced 2026-10-21 09:47:01 +02:00
Compare commits
190
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
93a0ac8802 | ||
|
|
238c96befe | ||
|
|
5c41f37b39 | ||
|
|
045d11d956 | ||
|
|
0df72933a8 | ||
|
|
f20b5386dd | ||
|
|
3d5600aef4 | ||
|
|
40f50cfc25 | ||
|
|
2d9b3684e5 | ||
|
|
85bda57ef7 | ||
|
|
f0de1ef328 | ||
|
|
7a20bc0ad9 | ||
|
|
0194d5296a | ||
|
|
ef55859eb0 | ||
|
|
b5db51c1ac | ||
|
|
5106372a4b | ||
|
|
6686fdd1a4 | ||
|
|
48eb11ada0 | ||
|
|
f72ad75db2 | ||
|
|
4a8fb113ae | ||
|
|
03a0a5db6b | ||
|
|
8b56b01cee | ||
|
|
52d20c8e5b | ||
|
|
b0ac19e4d1 | ||
|
|
e8d4e857dd | ||
|
|
bf549b8f86 | ||
|
|
b79ac3176f | ||
|
|
e12216dc5e | ||
|
|
f7603371f6 | ||
|
|
f80e2a8849 | ||
|
|
a30e2ef32a | ||
|
|
2825ccaf17 | ||
|
|
e1e0304b98 | ||
|
|
5f4ef51da9 | ||
|
|
98f7d032eb | ||
|
|
5b32d61a1e | ||
|
|
fd80f9e63f | ||
|
|
52ff0b2e62 | ||
|
|
aa0c3a77b3 | ||
|
|
a5fbf1b18b | ||
|
|
7d3bf14ea6 | ||
|
|
a8325474cf | ||
|
|
8a09d2670a | ||
|
|
30d8241e2d | ||
|
|
e33d50860b | ||
|
|
3b4340525d | ||
|
|
e6033f31cc | ||
|
|
c14d93b008 | ||
|
|
ed48d4fcb4 | ||
|
|
2541330a07 | ||
|
|
58aaf508fc | ||
|
|
e6644c0601 | ||
|
|
194f568363 | ||
|
|
963fbb6ed8 | ||
|
|
88185b7a88 | ||
|
|
3c6213774b | ||
|
|
c35d199809 | ||
|
|
67ca5a9d24 | ||
|
|
8edc991786 | ||
|
|
f59ef6dcee | ||
|
|
1ca25ceca8 | ||
|
|
0a0410d506 | ||
|
|
5f8b503ae3 | ||
|
|
9e253f98f4 | ||
|
|
d17af1fbc7 | ||
|
|
f3920b883d | ||
|
|
1abfdf5441 | ||
|
|
1c3613c669 | ||
|
|
627f9b3363 | ||
|
|
388ae6f296 | ||
|
|
24a09bc44d | ||
|
|
5ea3237772 | ||
|
|
9c094fc19f | ||
|
|
2912dfd8c0 | ||
|
|
a3fa59eaa8 | ||
|
|
290bcb143e | ||
|
|
bb9fdde26e | ||
|
|
a9e72b579e | ||
|
|
fe565b97ad | ||
|
|
1422d45a9f | ||
|
|
869f0fc070 | ||
|
|
cc1a865a86 | ||
|
|
5ce2196268 | ||
|
|
fe50b7c966 | ||
|
|
e02d977c5d | ||
|
|
d82965f140 | ||
|
|
2623569d67 | ||
|
|
2637758372 | ||
|
|
87a2f6b60b | ||
|
|
5e1291d7c4 | ||
|
|
1214aed3a7 | ||
|
|
e96cd19295 | ||
|
|
f37643b93e | ||
|
|
2a9f65c870 | ||
|
|
11b594bec6 | ||
|
|
047b334752 | ||
|
|
c2bb49287a | ||
|
|
2d932dd26b | ||
|
|
03e6739bc9 | ||
|
|
b360e8dd02 | ||
|
|
d72e95fccc | ||
|
|
60f241e0db | ||
|
|
9a7d6151ae | ||
|
|
ac34d4d2be | ||
|
|
8cae820cb8 | ||
|
|
b89fd2b915 | ||
|
|
4070ed9da9 | ||
|
|
6c7f666bb3 | ||
|
|
36fc50d2f1 | ||
|
|
15b2372daa | ||
|
|
b7b52febe3 | ||
|
|
a29a279693 | ||
|
|
b693f1af29 | ||
|
|
41f7909597 | ||
|
|
52167fc32d | ||
|
|
a060fe7374 | ||
|
|
f6450e0a5d | ||
|
|
6dec16ff2b | ||
|
|
8807f4775f | ||
|
|
4b0457b6ee | ||
|
|
6e05ecd1f9 | ||
|
|
16cbb134aa | ||
|
|
f267c3e714 | ||
|
|
e4f46c4276 | ||
|
|
67b9b86940 | ||
|
|
3f73bd0b31 | ||
|
|
8aca098801 | ||
|
|
831794f5eb | ||
|
|
5eb0a08727 | ||
|
|
4572ed5984 | ||
|
|
e81a06513a | ||
|
|
c17107da40 | ||
|
|
a8a7fbdae8 | ||
|
|
2990d9ab75 | ||
|
|
132eb393d0 | ||
|
|
8f81f9b523 | ||
|
|
b28e882b9c | ||
|
|
f5cc175adc | ||
|
|
2a7df193ce | ||
|
|
d974100585 | ||
|
|
9bf956e2da | ||
|
|
bb1bef3676 | ||
|
|
da21a56783 | ||
|
|
749578716a | ||
|
|
9153d71626 | ||
|
|
fae5eaf07e | ||
|
|
df0c0f346d | ||
|
|
75ae960d1a | ||
|
|
06be39a71c | ||
|
|
01bcc332cb | ||
|
|
f519162c61 | ||
|
|
21786017b0 | ||
|
|
79c45399b8 | ||
|
|
6f34b90e15 | ||
|
|
520d79b399 | ||
|
|
7f68777418 | ||
|
|
05eb1d791b | ||
|
|
cad3a8d233 | ||
|
|
fe970cfe2c | ||
|
|
d4052bfe6e | ||
|
|
4836b08998 | ||
|
|
fa7e58f45f | ||
|
|
0aec2f123d | ||
|
|
025baf4d74 | ||
|
|
49f0f74338 | ||
|
|
fd75256cbd | ||
|
|
4b4bc0c97e | ||
|
|
118d826f40 | ||
|
|
bfbdc82d22 | ||
|
|
6edcf92e7d | ||
|
|
79d258814e | ||
|
|
87dae1a7e2 | ||
|
|
4043f8534f | ||
|
|
9df5f68590 | ||
|
|
623cd45286 | ||
|
|
366a81407b | ||
|
|
471d828d5e | ||
|
|
5d48b7b38f | ||
|
|
b67c7beb3c | ||
|
|
86e41f1895 | ||
|
|
3fd35cdb94 | ||
|
|
f00cac7672 | ||
|
|
5420853a88 | ||
|
|
fe3b52f020 | ||
|
|
d07875981a | ||
|
|
9a93f9e340 | ||
|
|
1e4906bb5a | ||
|
|
50d3c47369 | ||
|
|
feda997a99 | ||
|
|
992f54c4e1 |
No files matched your search
+209
-47
@@ -11,12 +11,20 @@ on:
|
||||
- 'CMakeLists.txt'
|
||||
- '.github/workflows/build.yml'
|
||||
pull_request:
|
||||
paths:
|
||||
- 'src/**'
|
||||
- 'docs/**'
|
||||
- 'patches/**'
|
||||
- 'include/**'
|
||||
- 'Makefile'
|
||||
- 'CMakeLists.txt'
|
||||
- '.github/workflows/build.yml'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build-docs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
@@ -29,7 +37,11 @@ jobs:
|
||||
run: |
|
||||
make -j$(nproc) docs
|
||||
mkdir ready
|
||||
cp docs/*.html docs/mandoc.css ready
|
||||
cp docs/*.html docs/mandoc.css docs/palera1n.1 ready
|
||||
|
||||
- name: Get branch name
|
||||
id: branch-name
|
||||
uses: tj-actions/branch-names@v7
|
||||
|
||||
- name: Upload artifact
|
||||
if: ${{ github.event_name != 'pull_request' }}
|
||||
@@ -38,11 +50,11 @@ jobs:
|
||||
host: ${{ secrets.NICKCHAN_FTP_HOST }}
|
||||
port: ${{ secrets.NICKCHAN_FTP_PORT }}
|
||||
username: palera1n
|
||||
privateKey: ${{ secrets.NICKCHAN_FTP_KEY }}
|
||||
password: ${{ secrets.NICKCHAN_FTP_PASS }}
|
||||
forceUpload: true
|
||||
dryRun: false
|
||||
localDir: 'ready/'
|
||||
remoteDir: '/palera1n/artifacts/c-rewrite'
|
||||
remoteDir: "/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch || github.ref_name }}/${{ github.run_number }}"
|
||||
|
||||
build-darwin:
|
||||
strategy:
|
||||
@@ -59,10 +71,10 @@ jobs:
|
||||
- arch: arm64
|
||||
gnu_triple: aarch64-apple-darwin
|
||||
os: iphoneos
|
||||
minos: 14.0
|
||||
runs-on: macos-latest
|
||||
minos: 7.0
|
||||
runs-on: macos-12
|
||||
env:
|
||||
MBEDTLS_VERSION: 3.3.0
|
||||
MBEDTLS_VERSION: 3.4.0
|
||||
READLINE_VERSION: 8.2
|
||||
SLANG_VERSION: 2.3.3
|
||||
NEWT_VERSION: 0.52.23
|
||||
@@ -106,6 +118,10 @@ jobs:
|
||||
git clone --depth=1 https://github.com/libimobiledevice/libusbmuxd
|
||||
git clone --depth=1 https://github.com/libimobiledevice/libimobiledevice
|
||||
|
||||
- name: Select correct Xcode
|
||||
run: |
|
||||
sudo xcode-select -s /Applications/Xcode_14.2.app
|
||||
|
||||
- name: Setup environment
|
||||
run: |
|
||||
mkdir sysroot
|
||||
@@ -116,7 +132,7 @@ jobs:
|
||||
echo "CC=$(xcrun --find cc)" >> $GITHUB_ENV
|
||||
echo "CXX=$(xcrun --find c++)" >> $GITHUB_ENV
|
||||
echo "CPP=$(xcrun --find cc) -E" >> $GITHUB_ENV
|
||||
echo "CFLAGS=-g -Os -arch ${{ matrix.arch }} -m${{ matrix.os }}-version-min=${{ matrix.minos }} -isysroot ${{ env.SDK }} -isystem $(pwd)/sysroot/usr/local/include -Os" >> $GITHUB_ENV
|
||||
echo "CFLAGS=-g -Os -arch ${{ matrix.arch }} -m${{ matrix.os }}-version-min=${{ matrix.minos }} -isysroot ${{ env.SDK }} -isystem $(pwd)/sysroot/usr/local/include -Os -g -flto=full -Wl,-object_path_lto,lto.o" >> $GITHUB_ENV
|
||||
echo "CPPFLAGS=-g -Os -arch ${{ matrix.arch }} -m${{ matrix.os }}-version-min=${{ matrix.minos }} -isysroot ${{ env.SDK }} -isystem $(pwd)/sysroot/usr/local/include -Wno-error-implicit-function-declaration -Os" >> $GITHUB_ENV
|
||||
echo "CXXFLAGS=-stdlib=libc++ -g -Os -isysroot ${{ env.SDK }} -arch ${{ matrix.arch }} -m${{ matrix.os }}-version-min=${{ matrix.minos }} -isystem $(pwd)/sysroot/usr/local/include -Os" >> $GITHUB_ENV
|
||||
echo "LDFLAGS=-g -Wl,-dead_strip -arch ${{ matrix.arch }} -isysroot ${{ env.SDK }} -m${{ matrix.os }}-version-min=${{ matrix.minos }} -L$(pwd)/sysroot/usr/local/lib" >> $GITHUB_ENV
|
||||
@@ -127,6 +143,13 @@ jobs:
|
||||
mkdir -p $(pwd)/sysroot/usr/local/lib
|
||||
ln -sf $(pwd)/sysroot/usr/local/lib{,64}
|
||||
|
||||
- name: Prepare iPhoneOS environment
|
||||
if: matrix.os == 'iphoneos'
|
||||
run: |
|
||||
echo "FAKE_PLATFORM=2" >> $GITHUB_ENV
|
||||
echo "FAKE_SDK=7.0" >> $GITHUB_ENV
|
||||
echo "FAKE_MINOS=7.0" >> $GITHUB_ENV
|
||||
|
||||
- name: Prepare headers
|
||||
if: matrix.os != 'macosx'
|
||||
run: |
|
||||
@@ -293,26 +316,23 @@ jobs:
|
||||
cp -a sysroot/${{ env.PREFIX }}/{include,lib} dep_root
|
||||
find dep_root -name '*.dylib' -delete
|
||||
find dep_root -name '*.la' -delete
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DSTATIC=1 -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_CROSSCOMPILING=true \
|
||||
-DCMAKE_SYSTEM_NAME=Darwin \
|
||||
-DCMAKE_C_COMPILER="${{ env.CC }}" \
|
||||
-DCMAKE_C_FLAGS='${{ env.CFLAGS }}' \
|
||||
-DCMAKE_FIND_ROOT_PATH="${{ env.DESTDIR }}" \
|
||||
-DCMAKE_INSTALL_PREFIX="${{ env.PREFIX }}" \
|
||||
-DSTATIC=1
|
||||
make -j$(sysctl -n hw.ncpu)
|
||||
cd ..
|
||||
gmake -j$(sysctl -n hw.ncpu)
|
||||
mkdir -p ready
|
||||
mv build/src/palera1n palera1n-${{ matrix.os }}-${{ matrix.arch }}
|
||||
mv src/palera1n palera1n-${{ matrix.os }}-${{ matrix.arch }}
|
||||
dsymutil palera1n-${{ matrix.os }}-${{ matrix.arch }}
|
||||
strip palera1n-${{ matrix.os }}-${{ matrix.arch }}
|
||||
ldid -s palera1n-${{ matrix.os }}-${{ matrix.arch }}
|
||||
if [ "${{ matrix.os }}" == "macosx" ]; then
|
||||
ldid -S palera1n-${{ matrix.os }}-${{ matrix.arch }}
|
||||
else
|
||||
ldid -Ssrc/usb.xml palera1n-${{ matrix.os }}-${{ matrix.arch }}
|
||||
fi
|
||||
mkdir -p ready
|
||||
tar -zcf ready/dep_root-${{ matrix.os }}-${{ matrix.arch }}.tgz dep_root
|
||||
|
||||
- name: Get branch name
|
||||
id: branch-name
|
||||
uses: tj-actions/branch-names@v7
|
||||
|
||||
- name: Upload artifact
|
||||
if: ${{ github.event_name != 'pull_request' }}
|
||||
uses: wangyucode/[email protected]
|
||||
@@ -320,11 +340,11 @@ jobs:
|
||||
host: ${{ secrets.NICKCHAN_FTP_HOST }}
|
||||
port: ${{ secrets.NICKCHAN_FTP_PORT }}
|
||||
username: palera1n
|
||||
privateKey: ${{ secrets.NICKCHAN_FTP_KEY }}
|
||||
password: ${{ secrets.NICKCHAN_FTP_PASS }}
|
||||
forceUpload: true
|
||||
dryRun: false
|
||||
localDir: 'ready/'
|
||||
remoteDir: '/palera1n/artifacts/c-rewrite'
|
||||
remoteDir: "/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch || github.ref }}/${{ github.run_number }}"
|
||||
|
||||
- name: Upload ${{ matrix.os }} thin ${{ matrix.arch }} build
|
||||
if: ${{ github.event_name != 'pull_request' }}
|
||||
@@ -341,12 +361,24 @@ jobs:
|
||||
name: palera1n-${{ matrix.os }}-${{ matrix.arch }}.dSYM
|
||||
path: palera1n-${{ matrix.os }}-${{ matrix.arch }}.dSYM
|
||||
retention-days: 1
|
||||
|
||||
|
||||
darwin-dist:
|
||||
if: ${{ github.event_name != 'pull_request' }}
|
||||
runs-on: macos-latest
|
||||
needs: build-darwin
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup Procursus
|
||||
uses: beerpiss/[email protected]
|
||||
with:
|
||||
packages: sed coreutils
|
||||
cache: true
|
||||
mirror: 'https://procursus.itsnebula.net/'
|
||||
|
||||
- name: Download all Darwin artifacts
|
||||
uses: actions/download-artifact@v3
|
||||
|
||||
@@ -361,10 +393,96 @@ jobs:
|
||||
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-ios
|
||||
zip -r9 ready/palera1n-ios.dSYM.zip palera1n-iphoneos-arm64.dSYM
|
||||
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
|
||||
|
||||
- name: Build debs
|
||||
run: |
|
||||
make -j$(sysctl -n hw.ncpu) docs
|
||||
version=$(git describe --dirty --tags --abbrev=7 | sed 's|^v||' | sed 's|-beta|~beta|')
|
||||
|
||||
# Darwin x86_64
|
||||
mkdir -p stage/DEBIAN
|
||||
mkdir -p stage/opt/procursus/bin
|
||||
mkdir -p stage/opt/procursus/usr/share/man/man1
|
||||
cp packaging/control.macosx stage/DEBIAN/control
|
||||
|
||||
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
|
||||
|
||||
dpkg-deb -Zzstd -b stage palera1n_darwin-amd64.deb
|
||||
mv palera1n*.deb ready/
|
||||
rm -rf stage
|
||||
|
||||
# Darwin arm64
|
||||
mkdir -p stage/DEBIAN
|
||||
mkdir -p stage/opt/procursus/bin
|
||||
mkdir -p stage/opt/procursus/usr/share/man/man1
|
||||
cp packaging/control.macosx stage/DEBIAN/control
|
||||
|
||||
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
|
||||
|
||||
dpkg-deb -Zzstd -b stage palera1n_darwin-arm64.deb
|
||||
mv palera1n*.deb ready/
|
||||
rm -rf stage
|
||||
|
||||
# iPhoneOS
|
||||
mkdir -p stage/DEBIAN
|
||||
mkdir -p stage/usr/bin
|
||||
mkdir -p stage/usr/share/man/man1
|
||||
cp packaging/control stage/DEBIAN/control
|
||||
|
||||
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
|
||||
|
||||
dpkg-deb -Zzstd -b stage palera1n_iphoneos-arm.deb
|
||||
mv palera1n*.deb ready/
|
||||
rm -rf stage
|
||||
|
||||
# iPhoneOS (rootless)
|
||||
mkdir -p stage/DEBIAN
|
||||
mkdir -p stage/var/jb/usr/bin
|
||||
mkdir -p stage/var/jb/usr/share/man/man1
|
||||
cp packaging/control stage/DEBIAN/control
|
||||
|
||||
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
|
||||
|
||||
dpkg-deb -Zzstd -b stage palera1n_iphoneos-arm64.deb
|
||||
mv palera1n*.deb ready/
|
||||
rm -rf stage
|
||||
|
||||
- name: Save build tag
|
||||
run: echo "$(git describe --dirty --tags --abbrev=7 | sed 's|-dirty||')" > build-tag.txt
|
||||
|
||||
- name: Upload build tag
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: build-tag
|
||||
path: build-tag.txt
|
||||
|
||||
- name: Get branch name
|
||||
id: branch-name
|
||||
uses: tj-actions/branch-names@v7
|
||||
|
||||
- name: Upload artifact
|
||||
if: ${{ github.event_name != 'pull_request' }}
|
||||
uses: wangyucode/[email protected]
|
||||
@@ -372,11 +490,11 @@ jobs:
|
||||
host: ${{ secrets.NICKCHAN_FTP_HOST }}
|
||||
port: ${{ secrets.NICKCHAN_FTP_PORT }}
|
||||
username: palera1n
|
||||
privateKey: ${{ secrets.NICKCHAN_FTP_KEY }}
|
||||
password: ${{ secrets.NICKCHAN_FTP_PASS }}
|
||||
forceUpload: true
|
||||
dryRun: false
|
||||
localDir: 'ready/'
|
||||
remoteDir: '/palera1n/artifacts/c-rewrite'
|
||||
remoteDir: "/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch || github.ref }}/${{ github.run_number }}"
|
||||
|
||||
build-Linux:
|
||||
strategy:
|
||||
@@ -388,7 +506,7 @@ jobs:
|
||||
- aarch64-linux-musl
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
MBEDTLS_VERSION: 3.3.0
|
||||
MBEDTLS_VERSION: 3.4.0
|
||||
LIBUSB_VERSION: 1.0.26
|
||||
READLINE_VERSION: 8.2
|
||||
SLANG_VERSION: 2.3.3
|
||||
@@ -405,7 +523,7 @@ jobs:
|
||||
- name: Install build dependencies (packages)
|
||||
run: |
|
||||
sudo apt-get remove -y libssl-dev libreadline-dev
|
||||
sudo apt-get install -y pkg-config autoconf automake autopoint
|
||||
sudo apt-get install -y pkg-config autoconf automake autopoint mandoc
|
||||
sudo pip3 install jsonschema jinja2
|
||||
|
||||
- name: Download toolchain checksum
|
||||
@@ -433,15 +551,19 @@ jobs:
|
||||
case ${{ matrix.triple }} in
|
||||
i486-linux-musl)
|
||||
echo "CHECKRA1N_NAME=linux-x86" >> $GITHUB_ENV
|
||||
echo "ARCH_NAME=i386" >> $GITHUB_ENV
|
||||
;;
|
||||
x86_64-linux-musl)
|
||||
echo "CHECKRA1N_NAME=linux-x86_64" >> $GITHUB_ENV
|
||||
echo "ARCH_NAME=amd64" >> $GITHUB_ENV
|
||||
;;
|
||||
armel-linux-musleabi)
|
||||
echo "CHECKRA1N_NAME=linux-armel" >> $GITHUB_ENV
|
||||
echo "ARCH_NAME=armel" >> $GITHUB_ENV
|
||||
;;
|
||||
aarch64-linux-musl)
|
||||
echo "CHECKRA1N_NAME=linux-arm64" >> $GITHUB_ENV
|
||||
echo "ARCH_NAME=arm64" >> $GITHUB_ENV
|
||||
;;
|
||||
esac
|
||||
echo "PKG_CONFIG_PATH=$(pwd)/sysroot/usr/local/lib/pkgconfig" >> $GITHUB_ENV
|
||||
@@ -455,6 +577,7 @@ jobs:
|
||||
echo "CROSS_COMPILE=${{ matrix.triple }}-" >> $GITHUB_ENV
|
||||
mkdir -p $(pwd)/sysroot/usr/local/lib
|
||||
ln -sf $(pwd)/sysroot/usr/local/lib{,64}
|
||||
|
||||
- name: Download dependencies (source code)
|
||||
run: |
|
||||
curl -LOOOOOOO \
|
||||
@@ -632,31 +755,47 @@ jobs:
|
||||
cp -a sysroot/${{ env.PREFIX }}/{include,lib} dep_root
|
||||
find dep_root -name '*.so' -delete
|
||||
find dep_root -name '*.la' -delete
|
||||
mkdir build
|
||||
cd build
|
||||
CC="${{ matrix.triple }}-gcc" cmake .. -DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_INSTALL_PREFIX=${{ env.PREFIX }} \
|
||||
-DCMAKE_FIND_ROOT_PATH=${{ env.DESTDIR }}${{ env.PREFIX }} \
|
||||
-DCMAKE_FIND_ROOT_PATH_MODE_PROGRAM=NEVER -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
|
||||
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY \
|
||||
-DCMAKE_C_FLAGS="-I${{ env.DESTDIR }}${{ env.PREFIX }}/include \
|
||||
-L${{ env.DESTDIR }}${{ env.PREFIX }}/lib -Wl,-rpath,${{ env.PREFIX }}/lib" -DSTATIC=1
|
||||
make -j$(nproc) CC="${{ matrix.triple }}-gcc"
|
||||
CC="${{ matrix.triple }}-gcc" make -j$(nproc)
|
||||
|
||||
- name: Seperate debug symbols
|
||||
run: |
|
||||
${{ matrix.triple }}-objcopy --only-keep-debug build/src/palera1n palera1n.debug
|
||||
${{ matrix.triple }}-strip --strip-debug --strip-unneeded build/src/palera1n
|
||||
${{ matrix.triple }}-objcopy --add-gnu-debuglink=palera1n.debug build/src/palera1n
|
||||
${{ 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
|
||||
chmod -x palera1n.debug
|
||||
|
||||
- name: Prepare artifact
|
||||
run: |
|
||||
mkdir ready
|
||||
mv palera1n.debug ready/palera1n-${{ env.CHECKRA1N_NAME }}.debug
|
||||
mv build/src/palera1n ready/palera1n-${{ env.CHECKRA1N_NAME }}
|
||||
mv src/palera1n ready/palera1n-${{ env.CHECKRA1N_NAME }}
|
||||
tar -zcf ready/dep_root_${{ matrix.triple }}.tgz dep_root
|
||||
|
||||
- name: Build debs
|
||||
run: |
|
||||
version=$(git describe --dirty --tags --abbrev=7 | sed 's|^v||' | sed 's|-beta|~beta|')
|
||||
|
||||
make -j$(nproc) docs
|
||||
mkdir -p stage/DEBIAN
|
||||
mkdir -p stage/usr/bin
|
||||
mkdir -p stage/usr/share/man/man1
|
||||
cp packaging/control stage/DEBIAN/control
|
||||
|
||||
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
|
||||
|
||||
dpkg-deb -b stage palera1n_${{ env.ARCH_NAME }}.deb
|
||||
mv palera1n*.deb ready/
|
||||
rm -rf stage
|
||||
|
||||
- name: Get branch name
|
||||
id: branch-name
|
||||
uses: tj-actions/branch-names@v7
|
||||
|
||||
- name: Upload artifact
|
||||
if: ${{ github.event_name != 'pull_request' }}
|
||||
uses: wangyucode/[email protected]
|
||||
@@ -664,8 +803,31 @@ jobs:
|
||||
host: ${{ secrets.NICKCHAN_FTP_HOST }}
|
||||
port: ${{ secrets.NICKCHAN_FTP_PORT }}
|
||||
username: palera1n
|
||||
privateKey: ${{ secrets.NICKCHAN_FTP_KEY }}
|
||||
password: ${{ secrets.NICKCHAN_FTP_PASS }}
|
||||
forceUpload: true
|
||||
dryRun: false
|
||||
localDir: 'ready/'
|
||||
remoteDir: '/palera1n/artifacts/c-rewrite'
|
||||
remoteDir: "/palera1n/artifacts/c-rewrite/${{ steps.branch-name.outputs.ref_branch || github.ref }}/${{ github.run_number }}"
|
||||
|
||||
finish-build:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event_name != 'pull_request' }}
|
||||
needs: [build-docs, build-darwin, darwin-dist, build-Linux]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Get branch name
|
||||
id: branch-name
|
||||
uses: tj-actions/branch-names@v7
|
||||
|
||||
- name: Download build tag
|
||||
uses: actions/download-artifact@v3
|
||||
with:
|
||||
name: build-tag
|
||||
|
||||
- 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\"}")
|
||||
|
||||
@@ -8,6 +8,7 @@ contrib/
|
||||
checkra1n*
|
||||
payload.c
|
||||
src/palera1n
|
||||
src/palera1n.exe
|
||||
!xxd-embedded.h
|
||||
src/binpack.dmg
|
||||
src/ramdisk.dmg
|
||||
@@ -20,3 +21,8 @@ docs/*.html
|
||||
build
|
||||
src/*.dmg.c
|
||||
.idea
|
||||
src/stage2/
|
||||
src/libcheckra1nhelper.dylib*
|
||||
payloads/Pongo.bin
|
||||
src/*.dSYM
|
||||
include/payloads
|
||||
@@ -1,22 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.14)
|
||||
project(palera1n)
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
|
||||
set(CMAKE_CXX_STANDARD 99)
|
||||
set(SRC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(DEP ${SRC}/dep_root)
|
||||
set(CMAKE_C_STANDARD 99)
|
||||
set(STATIC 0)
|
||||
set(CMAKE_SUPPRESS_REGENERATION ON)
|
||||
|
||||
set(CMAKE_BUILD_TYPE BUILD_TYPE)
|
||||
|
||||
|
||||
add_custom_target(distclean
|
||||
COMMAND sh -c "find src -name '*.o' -type f -delete"
|
||||
COMMAND sh -c "find src -perm -u+x -type f -delete"
|
||||
)
|
||||
#add_custom_target(distclean
|
||||
# COMMAND sh -c "rm -rf *"
|
||||
# )
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(docs)
|
||||
@@ -1,37 +1,54 @@
|
||||
NAME = Dusk
|
||||
|
||||
SRC = $(shell pwd)
|
||||
DEP = $(SRC)/dep_root
|
||||
STRIP = strip
|
||||
CC ?= cc
|
||||
CFLAGS += -I$(DEP)/include -I$(SRC)/include -I$(SRC)
|
||||
CFLAGS += -Wall -Wextra -DPALERAIN_VERSION=\"2.0.0\" -Wall -Wextra -Wno-unused-parameter
|
||||
CFLAGS += -Wno-unused-variable -I$(SRC)/src -std=c99 -pedantic-errors -D_C99_SOURCE -D_POSIX_C_SOURCE=199506L -D_DARWIN_C_SOURCE
|
||||
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
|
||||
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 += -Wno-unused-variable -I$(SRC)/src -std=c99 -pedantic-errors -D_C99_SOURCE -D_POSIX_C_SOURCE=200112L
|
||||
ifeq ($(TARGET_OS),)
|
||||
TARGET_OS = $(shell uname -s)
|
||||
endif
|
||||
ifeq ($(findstring MINGW64,$(TARGET_OS)),MINGW64)
|
||||
TARGET_OS = Windows
|
||||
CFLAGS += -DWIN
|
||||
LIBS = -limobiledevice-1.0 -lirecovery-1.0 -lusbmuxd-2.0 -limobiledevice-glue-1.0 -lplist-2.0 -lssl -lcrypto -lusb-1.0 -lreadline -pthread -lm
|
||||
LIBS += -lws2_32 -liphlpapi -lsetupapi -lwinusb
|
||||
else
|
||||
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
|
||||
LIBS += $(DEP)/lib/libmbedtls.a $(DEP)/lib/libmbedcrypto.a $(DEP)/lib/libmbedx509.a $(DEP)/lib/libreadline.a
|
||||
endif
|
||||
ifeq ($(TARGET_OS),Darwin)
|
||||
CFLAGS += -Wno-nullability-extension
|
||||
ifeq (,$(findstring version-min=, $(CFLAGS)))
|
||||
CFLAGS += -mmacosx-version-min=10.8
|
||||
endif
|
||||
LDFLAGS += -Wl,-dead_strip
|
||||
LIBS += -framework CoreFoundation -framework SystemConfiguration -framework IOKit -framework Security
|
||||
LIBS += -framework CoreFoundation -framework IOKit
|
||||
else
|
||||
CFLAGS += -fdata-sections -ffunction-sections
|
||||
LDFLAGS += -static -no-pie -Wl,--gc-sections
|
||||
LDFLAGS += -no-pie -Wl,--gc-sections
|
||||
ifneq ($(TARGET_OS),Windows)
|
||||
LDFLAGS += -static
|
||||
endif
|
||||
endif
|
||||
LIBS += $(DEP)/lib/libmbedtls.a $(DEP)/lib/libmbedcrypto.a $(DEP)/lib/libmbedx509.a $(DEP)/lib/libreadline.a
|
||||
|
||||
ifeq ($(DEV_BUILD),1)
|
||||
ifeq ($(TUI),1)
|
||||
LIBS += $(DEP)/lib/libnewt.a $(DEP)/lib/libpopt.a $(DEP)/lib/libslang.a
|
||||
ifeq ($(TARGET_OS),Linux)
|
||||
LIBS += $(DEP)/lib/libgpm.a
|
||||
endif
|
||||
endif
|
||||
ifeq ($(DEV_BUILD),1)
|
||||
CFLAGS += -O0 -g -DDEV_BUILD -fno-omit-frame-pointer
|
||||
ifeq ($(ASAN),1)
|
||||
BUILD_STYLE=ASAN
|
||||
CFLAGS += -fsanitize=address,undefined -fsanitize-address-use-after-return=runtime
|
||||
else ifeq ($(TSAN),1)
|
||||
BUILD_STYLE=TSAN
|
||||
CFLAGS += -fsanitize=thread,undefined
|
||||
else
|
||||
BUILD_STYLE = DEVELOPMENT
|
||||
endif
|
||||
@@ -39,31 +56,55 @@ else
|
||||
CFLAGS += -Os -g
|
||||
BUILD_STYLE = RELEASE
|
||||
endif
|
||||
ifneq ($(TARGET_OS),Windows)
|
||||
LIBS += -lc
|
||||
endif
|
||||
|
||||
ifneq ($(BAKERAIN_DEVELOPE_R),)
|
||||
CFLAGS += -DBAKERAIN_DEVELOPE_R="\"$(BAKERAIN_DEVELOPE_R)\""
|
||||
endif
|
||||
|
||||
BUILD_DATE := $(shell LANG=C date)
|
||||
BUILD_NUMBER := $(shell git rev-list --count HEAD)
|
||||
BUILD_TAG := $(shell git describe --dirty --tags --abbrev=7)
|
||||
BUILD_WHOAMI := $(shell whoami)
|
||||
BUILD_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
||||
BUILD_COMMIT := $(shell git rev-parse HEAD)
|
||||
|
||||
CFLAGS += -DBUILD_STYLE=\"$(BUILD_STYLE)\" -DBUILD_DATE="\"$(BUILD_DATE)\"" -DBUILD_WHOAMI=\"$(BUILD_WHOAMI)\" -DBUILD_TAG=\"$(BUILD_TAG)\"
|
||||
CFLAGS += -DBUILD_STYLE="\"$(BUILD_STYLE)\"" -DBUILD_DATE="\"$(BUILD_DATE)\""
|
||||
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 TARGET_OS DEV_BUILD BUILD_DATE BUILD_TAG BUILD_WHOAMI BUILD_STYLE
|
||||
export SRC DEP CC CFLAGS LDFLAGS LIBS TARGET_OS DEV_BUILD BUILD_DATE BUILD_TAG BUILD_WHOAMI BUILD_STYLE BUILD_NUMBER BUILD_BRANCH
|
||||
|
||||
all: palera1n
|
||||
|
||||
palera1n: download-deps
|
||||
xxd-payloads: download-deps
|
||||
mkdir -p include/payloads
|
||||
for file in payloads/*; do \
|
||||
xxd -i $$file > include/$$file.h; \
|
||||
done
|
||||
|
||||
palera1n: download-deps xxd-payloads
|
||||
$(MAKE) -C src
|
||||
|
||||
clean:
|
||||
$(MAKE) -C src 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
|
||||
download-deps: Pongo.bin
|
||||
$(MAKE) -C src checkra1n-kpf-pongo ramdisk.dmg binpack.dmg
|
||||
|
||||
docs:
|
||||
$(MAKE) -C docs
|
||||
|
||||
Pongo.bin:
|
||||
rm -f payloads/Pongo.bin
|
||||
curl -Lo payloads/Pongo.bin https://cdn.nickchan.lol/palera1n/artifacts/kpf/Pongo.bin
|
||||
|
||||
distclean: clean
|
||||
rm -rf palera1n-* palera1n*.dSYM src/checkra1n-* src/checkra1n-kpf-pongo src/ramdisk.dmg src/binpack.dmg
|
||||
rm -rf palera1n-* palera1n*.dSYM src/checkra1n-* src/checkra1n-kpf-pongo src/ramdisk.dmg src/binpack.dmg payloads/Pongo.bin include/payloads
|
||||
|
||||
.PHONY: all palera1n clean docs distclean
|
||||
.PHONY: all xxd-payloads palera1n clean docs distclean
|
||||
|
||||
@@ -1,97 +1,54 @@
|
||||
<h1 align="center">
|
||||
palera1n
|
||||
</h1>
|
||||
<center>
|
||||
<a href="#"><img src="https://cdn.discordapp.com/attachments/1103485261196832779/1126450758523572285/pxd.png" alt="Logo"></a>
|
||||
</center>
|
||||
|
||||
<p align="center">
|
||||
<a href="#">
|
||||
<img src="https://img.shields.io/badge/made%20with-love-E760A4.svg" alt="Made with love"></img>
|
||||
</a>
|
||||
<a href="https://github.com/palera1n/palera1n-c/blob/main/LICENSE" target="_blank">
|
||||
<img src="https://img.shields.io/github/license/palera1n/palera1n-c.svg" alt="License"></img>
|
||||
</a>
|
||||
<a href="https://github.com/palera1n/palera1n-c/graphs/contributors" target="_blank">
|
||||
<img src="https://img.shields.io/github/contributors/palera1n/palera1n-c.svg" alt="Contributors"></img>
|
||||
</a>
|
||||
<a href="https://github.com/palera1n/palera1n-c/commits/main" target="_blank">
|
||||
<img src="https://img.shields.io/github/commit-activity/w/palera1n/palera1n-c.svg" alt="Commits"></img>
|
||||
</a>
|
||||
<img src="https://img.shields.io/github/search/palera1n/palera1n-c/goto.svg" alt="goto counter"></img>
|
||||
<a href="https://dsc.gg/palera1n" target="_blank">
|
||||
<img src="https://img.shields.io/discord/1028398973452570725?label=discord" alt="Discord"></img>
|
||||
</a>
|
||||
<a href="https://cdn.nickchan.lol/palera1n/c-rewrite/releases/v2.0.0-beta.7/palera1n.1.html">Documentation</a> •
|
||||
<a href="https://ios.cfw.guide/installing-palera1n">Installation Guide</a> •
|
||||
<a href="#requirements">Requirements</a> •
|
||||
<a href="https://discord.gg/palera1n">Support Discord</a> •
|
||||
<a href="https://palera.in">Website</a>
|
||||
</p>
|
||||
|
||||
<p align="center">
|
||||
iOS 15.0-16.3 work in progress, semi-tethered checkm8 jailbreak
|
||||
</p>
|
||||
## Information
|
||||
This is the official repo for the palera1n project, a jailbreak for arm64 devices on iOS 15.0+
|
||||
|
||||
# BEFORE YOU USE
|
||||
- Loader application used in palera1n can be found [here](https://github.com/palera1n/loader).
|
||||
- palera1ns jbinit can be found [here](https://github.com/palera1n/jbinit).
|
||||
- palera1ns custom PongoOS can be found [here](https://github.com/palera1n/pongoos).
|
||||
|
||||
This is mainly for ROOTLESS, and is NOT READY. It was made public so you can contribute and explore the code. This is not the final product.
|
||||
Website & credits can be found at https://palera.in (scroll down for credits).
|
||||
|
||||
This version of palera1n supports booting fakefs setups with the `-f` option. No arguments required.
|
||||
## Warnings
|
||||
We are **NOT** responsible for any data loss, or the result of a device being bricked. The user of this program accepts responsibility should something happen to their device. While nothing should happen, jailbreaking has risks in itself.
|
||||
- If your device is stuck in recovery, please run futurerestore `--exit-recovery`, or use `irecovery -n`.
|
||||
|
||||
This version of palera1n is able to create fakefs with the `-c` option, however as of right now if the `/jbin/loader.app`
|
||||
doesn't exist (which is true for any fakefs created with this version of palera1n), the loader that appears would be rootless.
|
||||
- If you're unable to get out of recovery via these methods please restore with iTunes or Finder.
|
||||
|
||||
Loader app does appear on rootless, and you can use the SSH server listening at 127.0.0.1:44 (IPv4) or ::1:44 (IPv6).
|
||||
- palera1n will never work in VirtualBox, VMware or any virtual machine that doesn't support PCI passthrough.
|
||||
|
||||
If the device is previously jailbroken, the jailbreak environment is automatically prepared.
|
||||
You can use the `-s` option to skip this behaviour.
|
||||
## Requirements
|
||||
- A checkm8 vulnerable iOS device on iOS 15+ (`A8` - `A11`)
|
||||
- On `A11`, **you must disable your passcode while in the jailbroken state** (on iOS 16, you need to **reset your device** before proceeding with palera1n).
|
||||
|
||||
Usbmuxd is only required for starting in normal mode, it is not required when started from recovery or DFU mode. (Usbmuxd is preinstalled with macOS)
|
||||
- **USB-A** cables are recommended to use, USB-C may have issues with palera1n and getting into DFU mode.<details><summary>Technical explanation</summary>The BootROM will only enter DFU if it detects USB voltage, which boils down to checking whether a certain pin is asserted from the Tristar chip. The Tristar does this based on the cable's accessory ID, and apparently USB-A and USB-C cables have different accessory IDs, and the one of the USB-C cables makes the Tristar not assert the USB voltage pin.</details>
|
||||
|
||||
You can obtain the latest build of palera1n-c [here](https://cdn.nickchan.lol/palera1n/artifacts/c-rewrite/).
|
||||
- A Linux or macOS computer
|
||||
- AMD CPUs (not AMD Mobile) have an issue [with (likely) their USB controllers] that causes them to have a very low success rate with checkm8. It is not recommended that you use them with palera1n.
|
||||
- If your device does not successfully jailbreak, try a computer with an Intel or other CPU
|
||||
|
||||
- Apple Silicon Macs with USB-C
|
||||
- USB-C port on Apple Silicon Macs may require manual unplugging and replugging of the lightning cable after checkm8 exploit.
|
||||
- This problem may be solved by connecting via USB hub, though extensions can vary.
|
||||
|
||||
# This is a work in progress.
|
||||
## Need help?
|
||||
|
||||
Read this throughly, feel free to ask questions, know the risks. If you want to ask questions, either:
|
||||
Make sure you provide full details on your device, such as:
|
||||
- iDevice
|
||||
- iOS Version
|
||||
- Passcode enabled?
|
||||
- Logs, if panicked then send latest `panic-full` log from your iDevice.
|
||||
|
||||
1. Ask in the [palera1n Discord](https://discord.gg/4S3yUMxuQH)
|
||||
2. Ask in the r/jailbreak Discord #palera1n channel
|
||||
Using `-VvL` would help with debugging.
|
||||
|
||||
Please, please, please, provide necessary info:
|
||||
|
||||
- iOS version and device (eg. iPhone 7+ 15.1, iPhone 6s 15.3.1)
|
||||
- Computer's OS and version (eg. Ubuntu 22.04, macOS 13.0)
|
||||
- The command you ran
|
||||
|
||||
**DO NOT** harass tweak devs if tweaks don't work. Refer to [here](https://github.com/itsnebulalol/ios15-tweaks) for compatiblity.
|
||||
|
||||
# Patreons
|
||||
|
||||
Thank you so much to our Patreons that make the future development possible! You may sub [here](https://patreon.com/palera1n), if you'd like to. If you subscribe, please message [Nebula](https://twitter.com/itsnebulalol) in any way preferred to have you put here.
|
||||
|
||||
<a href="https://github.com/samh06"><img width=64 src="https://user-images.githubusercontent.com/18669106/206333607-881d7ca1-f3bf-4e18-b620-25de0c527315.png"></img></a>
|
||||
<a href="https://havoc.app"><img width=64 src="https://docs.havoc.app/img/standard_icon.png"></img></a>
|
||||
<a href="https://twitter.com/yyyyyy_public"><img width=64 src="https://pbs.twimg.com/profile_images/1429332550112079876/dQQgsURc_400x400.jpg"></img></a>
|
||||
<a href="https://twitter.com/0xSp00kyb0t"><img width=64 src="https://pbs.twimg.com/profile_images/1603601553226620935/1t4yD1bD_400x400.jpg"></img></a>
|
||||
<a href="https://chariz.com"><img width=64 src="https://chariz.com/img/favicon.png"></img></a>
|
||||
<a href="https://twitter.com/stars6220"><img width=64 src="https://pbs.twimg.com/profile_images/1606990218925670400/Y4JBl6OS_400x400.jpg"></img></a>
|
||||
<a href="https://github.com/beast9265"><img width=64 src="https://avatars.githubusercontent.com/u/79794946?v=4"></img></a>
|
||||
|
||||
# What does this do?
|
||||
|
||||
It boots the device with patches for the jailbreak.
|
||||
|
||||
**WARNING**: I am NOT responsible for any data loss. The user of this program accepts responsibility should something happen to their device. While nothing should happen, jailbreaking has risks in itself. If your device is stuck in recovery, please run `futurerestore --exit-recovery`, or use `irecovery -n`.
|
||||
|
||||
On A11, you **must disable your passcode while in the jailbroken state**. We don't have an A11 SEP exploit yet.
|
||||
|
||||
<!--# Usage
|
||||
See the [wiki](https://github.com/palera1n/palera1n-c/wiki).-->
|
||||
|
||||
# Credits
|
||||
|
||||
- [Nebula](https://github.com/itsnebulalol), palera1n owner and Python rewrite lead developer
|
||||
- [Nathan](https://github.com/verygenericname)
|
||||
- [Mineek](https://github.com/mineek)
|
||||
- [Nick Chan](https://github.com/asdfugil)
|
||||
- [Amy](https://github.com/elihwyma) for the [Pogo](https://github.com/elihwyma/Pogo) app
|
||||
- [checkra1n](https://github.com/checkra1n) for the base of the kpf
|
||||
- [the Procursus Team](https://github.com/ProcursusTeam) for the amazing [bootstrap](https://github.com/ProcursusTeam/Procursus)
|
||||
- [F121](https://github.com/F121Live) for helping test
|
||||
- [Tom](https://github.com/guacaplushy) for a couple patches and bugfixes
|
||||
- [Nick Chan](https://github.com/asdfugil) general help with patches and jbinit
|
||||
- [Serena](https://github.com/SerenaKit) for helping with boot ramdisk
|
||||
- [Évelyne](https://github.com/evelyneee) for ElleKit, rootless tweak injection
|
||||
Join the [Support Discord](https://dsc.gg/palera1n), and create a thread in [#support](https://discord.com/channels/1028398973452570725/1028730487700738130) or ask in [#general](https://discord.com/channels/1028398973452570725/1028398976640229380).
|
||||
@@ -1,4 +0,0 @@
|
||||
add_custom_target(
|
||||
docs
|
||||
COMMAND sh -c "mandoc -T html -O style=mandoc.css palera1n.1 > palera1n.1.html"
|
||||
)
|
||||
+38
-86
@@ -2,33 +2,27 @@
|
||||
.\" Copyright (c) 2023 Nick Chan
|
||||
.\" SPDX-License-Identifier: MIT
|
||||
.\"
|
||||
.Dd "06 February 2023"
|
||||
.Dt "Nick Chan utilities manual" 1 "palera1n"
|
||||
.Dd "2 July 2023"
|
||||
.Dt palera1n 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm palera1n
|
||||
.Nd iOS 15+ arm64 iOS/iPadOS jailbreaking tool
|
||||
.Nd iOS 15.0-16.5.1 arm64 iOS/iPadOS jailbreaking tool
|
||||
.Sh SYNOPSIS
|
||||
.Nm
|
||||
.Op Fl cCdDEfhlnLOpRsvV
|
||||
.Op Fl dDEhILnpRsSvV
|
||||
.Op Fl e Ar Boot arguments
|
||||
.Op Fl k Ar Pongo image
|
||||
.Op Fl o Ar overlay file
|
||||
.Op Fl r Ar ramdisk file
|
||||
.Op Fl K Ar KPF file
|
||||
.Op Fl i Ar checkra1n file
|
||||
.Op Fl -version
|
||||
.Op Fl -force-revert
|
||||
.Sh DESCRIPTION
|
||||
.Nm
|
||||
jailbreaks any iOS/iPadOS device with an arm64 (arm64e excluded) on iOS 15+,
|
||||
jailbreaks any iOS/iPadOS device with an arm64 (arm64e excluded) on iOS 15.0-16.5.1,
|
||||
utilizing the
|
||||
.Em checkm8
|
||||
bootROM exploit.
|
||||
.Pp
|
||||
.Nm
|
||||
is able to jailbreak the device in fakefs-rootful mode, where /
|
||||
is writable, as well as rootless mode, where / cannot be written to.
|
||||
.Pp
|
||||
Due to the nature of the
|
||||
.Em checkm8
|
||||
exploit,
|
||||
@@ -48,8 +42,11 @@ On iOS 16, the passcode must be off since restore, and
|
||||
from settings app counts as a restore.
|
||||
A backup may be used in this case.
|
||||
.Pp
|
||||
In the remainder of this document, the term "iOS" and "iPadOS" will be used interchangably
|
||||
as the difference is negligible as far as the jailbreak is concerened.
|
||||
.Pp
|
||||
.Sh SUPPORTED DEVICES
|
||||
As described above, arm64 iOS/iPadOS 15+ devices are supported, here is an explicit
|
||||
As described above, arm64 iOS 15.0-16.5.1 devices are supported, here is an explicit
|
||||
list of supported devicecs:
|
||||
|
||||
.Bl -tag -compact
|
||||
@@ -92,26 +89,10 @@ Prints the program version and exit.
|
||||
Remove the jailbreak while keeping user data. Some jailbreak files may remain
|
||||
after running this command. Additionally, jailbreak apps will remain on the
|
||||
home screen on for a while even when the files are deleted as the icon cache
|
||||
still has their icons. When used with
|
||||
.Fl f , -fakefs ,
|
||||
this will actually boot the device in rootless mode then delete the jailbreak
|
||||
files. As a result, using the loader app to install the jailbreak environment
|
||||
is not supported when this option is used together with
|
||||
.Fl f , -fakefs
|
||||
\[char46]
|
||||
.It Fl c , -setup-fakefs
|
||||
When used with
|
||||
.Fl f , -fakefs ,
|
||||
Create the new APFS volume required for rootful. Will fail if one already exists.
|
||||
.It Fl C , -setup-fakefs-forced
|
||||
When used with
|
||||
.Fl f , -fakefs ,
|
||||
behaves like
|
||||
.Fl c , -setup-fakefs ,
|
||||
but existing fakefs, if exists, will be overwritten instead.
|
||||
still has their icons.
|
||||
.It Fl d , -demote
|
||||
Set the effective production fuse to 0, so as to enable hardware debugging features.
|
||||
.It Fl D , -dfuhelper-only
|
||||
.It Fl D , -dfuhelper
|
||||
Execute the DFU helper to guide the user into putting the device into DFU mode
|
||||
then exit.
|
||||
.It Fl e , -boot-args Ar boot arguments
|
||||
@@ -119,38 +100,29 @@ Specify custom XNU kernel command line. The
|
||||
.Em rootdev=md0
|
||||
argument is used by
|
||||
.Nm
|
||||
and cannot be overriden. Additionally, the
|
||||
.Em wdt=-1
|
||||
argument is used during fakefs setup.
|
||||
and cannot be overriden.
|
||||
.It Fl E , -enter-recovery
|
||||
Exit after entering recovery mode.q
|
||||
.It Fl f , -fakefs
|
||||
Jailbreak in rootful mode.
|
||||
Exit after entering recovery mode.
|
||||
.It Fl h , -help
|
||||
Prints help text.
|
||||
.It Fl i , -checkra1n-file Ar checkra1n file
|
||||
Specify the path to a custom checkra1n file.
|
||||
.It Fl k , -override-pongo Ar pongo file
|
||||
Override PongoOS image. The raw image, named
|
||||
.Em Pongo.bin
|
||||
when built, should be used. PongoOS 2.6.0 or later is required.
|
||||
.It Fl K , -override-kpf Ar KPF file
|
||||
Override the kernel patchfinder PongoOS module. The module is required to support setting
|
||||
root filesystem in paleinfo with
|
||||
.Em rootfs
|
||||
command. If in doubt, use
|
||||
.Sy https://github.com/guacaplushy/PongoOS
|
||||
.Sy https://github.com/palera1n/PongoOS
|
||||
iOS15 branch or your own fork of it.
|
||||
.It Fl l , -rootless
|
||||
Jailbreak in rootless mode, this is the default when neither
|
||||
.Fl l , -rootless
|
||||
and
|
||||
.Fl f , -fakefs
|
||||
is specified.
|
||||
.Fl L , -jbinit-log-to-file
|
||||
Makes jbinit log to
|
||||
.Em /cores/jbinit.log
|
||||
This file may be viewed from sandboxed applications while jailbroken.
|
||||
.It Fl l , -rootless
|
||||
Proceed in rootless mode, this is the default when neither
|
||||
.Fl l , -rootless
|
||||
and
|
||||
.Fl f , -fakefs
|
||||
is specified.
|
||||
>>>>>>> a8e6075 (paleinfo v2)
|
||||
.It Fl n , -exit-recovery
|
||||
Exit recovery mode and exit.
|
||||
.It Fl o , -override-overlay Ar overlay file
|
||||
@@ -162,8 +134,6 @@ at the root of it, as well as a dmg named
|
||||
.Em loader.dmg
|
||||
at the root of it. Otherwise, the device will not boot. It is also expected that it
|
||||
contains a shell, a ssh server, and various command line utilities.
|
||||
.It Fl O , -disable-ohio
|
||||
Disable ohio (disable analytics)
|
||||
.It Fl p , -pongo-shell
|
||||
Exit after booting into a clean PongoOS shell
|
||||
.It Fl P , -pongo-full
|
||||
@@ -184,14 +154,18 @@ specified (see
|
||||
.Sy FILES
|
||||
section below) will be executed. The loader app and the built in SSH server can still be used,
|
||||
as well as any jailbreak-specific apps you have installed.
|
||||
.It Fl S , -no-colors
|
||||
Disable colors on the command line. External programs like checkra1n clones may still output colors.
|
||||
.It Fl v , -debug-logging
|
||||
Enable debug logging. The option may be repeated for extra verbosity.
|
||||
.It Fl V , -verbose-boot
|
||||
Boots the device in verbose mode, allowing boot logs to be seen.
|
||||
.It Fl I , -device-info
|
||||
Prints info about device and exits.
|
||||
.El
|
||||
.Sh ENVIRONMENTAL VARIABLES
|
||||
.Bl -tag -width -indent
|
||||
.It TMPDIR
|
||||
.It Ev TMPDIR
|
||||
This environmental variable should contain the a directory for temporary
|
||||
files. Without the
|
||||
.Fl i , -override-checkra1n
|
||||
@@ -203,28 +177,10 @@ To (re-)jailbreak in rootless mode:
|
||||
.Pp
|
||||
.Dl "palera1n"
|
||||
.Pp
|
||||
To setup fakefs for rootful mode:
|
||||
.Pp
|
||||
.Dl "palera1n -fc"
|
||||
.Ppq
|
||||
After the device has rebooted, follow the following example.
|
||||
.Pp
|
||||
To re-jailbreak in rootful mode:
|
||||
.Pp
|
||||
.Dl "palera1n -f"
|
||||
.Pp
|
||||
To remove the jailbreak in rootful mode:
|
||||
.Pp
|
||||
.Dl "palera1n --force-revert -f"
|
||||
.Pp
|
||||
To remove the jailbreak in rootless mode:
|
||||
.Pp
|
||||
.Dl "palera1n --force-revert"
|
||||
.Pp
|
||||
To verbose boot in rootful mode:
|
||||
.Pp
|
||||
.Dl "palera1n -Vf"
|
||||
.Pp
|
||||
To exit recovery mode:
|
||||
.Pp
|
||||
.Dl "palera1n -n"
|
||||
@@ -232,14 +188,12 @@ To exit recovery mode:
|
||||
.Sh CAVEATS
|
||||
.Pp
|
||||
.Em -v
|
||||
is not a real XNU boot argument. It is intercepted by iBoot. However, since XNU
|
||||
is not a real XNU boot argument. It is interpreted by iBoot. However, since XNU
|
||||
boot arguments are set in PongoOS, which is ran after iBoot has ran, it does nothing.
|
||||
To verbose boot, use the
|
||||
.Fl V , -verbose-boot
|
||||
option when jailbreaking.
|
||||
.Pp
|
||||
Fakefs takes up around 5-10 GB of storage, and take up to 10 minutes to setup.
|
||||
.Pp
|
||||
iOS 15.0 requires DER entitlements, and iOS 15.1 requires hash agility in code signatures.
|
||||
As a result, binaries with the old code signature format need to be resigned with a recent
|
||||
version of the Procursus fork of
|
||||
@@ -247,11 +201,11 @@ version of the Procursus fork of
|
||||
before they can be ran on a device jailbroken with
|
||||
.Nm
|
||||
\[char46]
|
||||
.Sh POST INSTLLATION
|
||||
.Sh POST INSTALLATION
|
||||
The palera1n loader app will take up to 30 seconds to appear on the homescreen after the
|
||||
device has booted. If it does not appear, you can try using the shortcut:
|
||||
.Pp
|
||||
.Sy https://www.icloud.com/shortcuts/8cd5f489c8854ee0ab9ee38f2e62f87d
|
||||
.Lk https://www.icloud.com/shortcuts/8cd5f489c8854ee0ab9ee38f2e62f87d
|
||||
.Pp
|
||||
to open it. After opening the loader app, press install to install a bootstrap as well as
|
||||
the
|
||||
@@ -271,18 +225,11 @@ The location of the temporary filesystem where jailbreak files are stash during
|
||||
When
|
||||
.Fl L
|
||||
is used, the log file of jbinit.
|
||||
.It Pa /Library/LaunchDaemons
|
||||
The directory where jailbreak-specific
|
||||
.Xr launchd.plist 5
|
||||
property list files should be placed on rootful.
|
||||
The log file of jbinit.
|
||||
.It Pa /var/jb/Library/LaunchDaemons
|
||||
The directory where jailbreak-specific
|
||||
.Xr launchd.plist 5
|
||||
property list files should be placed on rootless.
|
||||
.It Pa /etc/rc.d
|
||||
The directory where executable filse that needs to be executed during boot, before
|
||||
daemons are launched, are placed rootful. They are executed after all filesystems
|
||||
has been mounted.
|
||||
.It Pa /var/jb/etc/rc.d
|
||||
The directory where executable files that needs to be executed during boot, before
|
||||
daemons are launched, are placed on rootless. They are executed after all filesystems
|
||||
@@ -292,14 +239,19 @@ has been mounted.
|
||||
.Nm
|
||||
may crash if the machine it is running on:
|
||||
.Pp
|
||||
.Dl "- Has no USB ports"
|
||||
.Pp
|
||||
.Dl "- Has non-compliant USB devices plugged in"
|
||||
.Pp
|
||||
The exploit may also work less reliably on some hosts, like AMD desktops, or some MediaTek devices.
|
||||
.Pp
|
||||
The device may randomly crash and reboot due to launchd exiting with code 7.
|
||||
.Sh NOTES
|
||||
.Nm
|
||||
injects a dylib into launchd to allow the
|
||||
.Sy launchctl runstats
|
||||
command to be used on the device.
|
||||
.Sh DEPRECATED AND REMOVED FUNCTIONALITY
|
||||
.Pp
|
||||
The fakefs functionality was removed.
|
||||
.Sh SEE ALSO
|
||||
.Xr launchd 8
|
||||
.Xr launchd.plist 5
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
curl -LOOOOOO \
|
||||
https://github.com/Mbed-TLS/mbedtls/archive/refs/tags/v3.3.0.tar.gz \
|
||||
https://github.com/libusb/libusb/releases/download/1.0.26/libusb-1.0.26.tar.bz2 \
|
||||
https://mirror-hk.koddos.net/gnu/readline/readline-8.2.tar.gz \
|
||||
https://www.jedsoft.org/releases/slang/slang-2.3.3.tar.bz2 \
|
||||
https://releases.pagure.org/newt/newt-0.52.23.tar.gz \
|
||||
https://github.com/rpm-software-management/popt/archive/master-release.tar.gz
|
||||
|
||||
tar xf master.tar.gz
|
||||
tar xf libusb-1.0.26.tar.bz2
|
||||
tar xf readline-8.2.tar.gz
|
||||
tar xf slang-2.3.3.tar.bz2
|
||||
tar xf newt-0.52.23.tar.gz
|
||||
tar xf master-release.tar.gz
|
||||
|
||||
git clone --depth=1 https://github.com/libimobiledevice/libplist
|
||||
git clone --depth=1 https://github.com/libimobiledevice/libimobiledevice-glue
|
||||
git clone --depth=1 https://github.com/libimobiledevice/libirecovery
|
||||
git clone --depth=1 https://github.com/libimobiledevice/libusbmuxd
|
||||
git clone --depth=1 https://github.com/libimobiledevice/libimobiledevice
|
||||
@@ -78,7 +78,6 @@
|
||||
#define BHWHT "\033[1;97m"
|
||||
|
||||
//Reset
|
||||
#define reset "\033[0m"
|
||||
#define CRESET "\033[0m"
|
||||
#define COLOR_RESET "\033[0m"
|
||||
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
* pongoOS - https://checkra.in
|
||||
*
|
||||
* Copyright (C) 2019-2022 checkra1n team
|
||||
*
|
||||
* This file is part of pongoOS.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
#ifndef _KERNINFO_H
|
||||
#define _KERNINFO_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define MAX_BOOTARGS_LEN 256
|
||||
|
||||
#define checkrain_option_none 0x00000000
|
||||
#define checkrain_option_all 0x7fffffff
|
||||
#define checkrain_option_failure 0x80000000
|
||||
|
||||
// Host options
|
||||
#define checkrain_option_verbose_logging (1 << 0)
|
||||
#define checkrain_option_demote (1 << 1)
|
||||
#define checkrain_option_early_exit (1 << 2)
|
||||
#define checkrain_option_quick_mode (1 << 3)
|
||||
#define checkrain_option_pongo_shell (1 << 4)
|
||||
#define checkrain_option_pongo_full (1 << 5)
|
||||
|
||||
// KPF options
|
||||
#define checkrain_option_verbose_boot (1 << 0)
|
||||
|
||||
// Global options
|
||||
#define checkrain_option_safemode (1 << 0)
|
||||
#define checkrain_option_bind_mount (1 << 1)
|
||||
#define checkrain_option_overlay (1 << 2)
|
||||
#define checkrain_option_force_revert (1 << 7) /* keep this at 7 */
|
||||
|
||||
// palera1n option
|
||||
#define palerain_option_rootful (1 << 0) /* rootful jailbreak */
|
||||
#define palerain_option_jbinit_log_to_file (1 << 1) /* log to /cores/jbinit.log */
|
||||
#define palerain_option_setup_rootful (1 << 2) /* create fakefs */
|
||||
#define palerain_option_setup_rootful_forced (1 << 3) /* create fakefs over an existing one */
|
||||
|
||||
#ifdef DEV_BUILD
|
||||
#define palerain_option_test1 (1 << 29)
|
||||
#define palerain_option_test2 (1 << 30)
|
||||
#endif
|
||||
|
||||
// palerain host options
|
||||
#define host_option_dfuhelper_only (1 << 0) /* dfuhelper only */
|
||||
#define host_option_pongo_exit (1 << 1) /* boot to clean pongo shell */
|
||||
#ifdef DEV_BUILD
|
||||
#define host_option_tui (1 << 2) /* use terminal user interface */
|
||||
#else
|
||||
#define host_option_res1 (1 << 2) /* reserved */
|
||||
#endif
|
||||
#define host_option_demote (1 << 3) /* Demote effective production fuse status */
|
||||
#define host_option_no_ohio (1 << 4) /* Disable Ohio (Analytics) */
|
||||
#define host_option_pongo_full (1 << 5) /* Boot to pongo with default images and options */
|
||||
#define host_option_palerain_version (1 << 6) /* Print version */
|
||||
#define host_option_exit_recovery (1 << 7) /* Exit recovery mode */
|
||||
#define host_option_reboot_device (1 << 8) /* Reboot device in normal mode */
|
||||
#define host_option_enter_recovery (1 << 9) /* Enter recovery mode */
|
||||
|
||||
#define PALEINFO_MAGIC 'PLSH'
|
||||
#define PALEINFO_CIGAM 'HSLP'
|
||||
|
||||
typedef uint32_t checkrain_option_t, *checkrain_option_p;
|
||||
|
||||
typedef enum {
|
||||
jailbreak_capability_tfp0 = 1 << 0,
|
||||
jailbreak_capability_userspace_reboot = 1 << 1,
|
||||
jailbreak_capability_dyld_ignore_os = 1 << 2, // TODO: This needs a better name
|
||||
} jailbreak_capability_t, *jailbreak_capability_p;
|
||||
|
||||
#define DEFAULT_CAPABILITIES (jailbreak_capability_tfp0|jailbreak_capability_userspace_reboot)
|
||||
struct kerninfo {
|
||||
uint64_t size;
|
||||
uint64_t base;
|
||||
uint64_t slide;
|
||||
checkrain_option_t flags;
|
||||
};
|
||||
struct paleinfo {
|
||||
uint32_t magic; // 'PLSH' / 0x504c5348
|
||||
uint32_t version; // 1
|
||||
checkrain_option_t flags;
|
||||
char rootdev[0x10];
|
||||
};
|
||||
struct kpfinfo {
|
||||
struct kerninfo k;
|
||||
checkrain_option_t kpf_flags;
|
||||
char bootargs[MAX_BOOTARGS_LEN];
|
||||
};
|
||||
|
||||
#define checkrain_set_option(options, option, enabled) do { \
|
||||
if (enabled) \
|
||||
options = (checkrain_option_t)(options | option); \
|
||||
else \
|
||||
options = (checkrain_option_t)(options & ~option); \
|
||||
} while (0);
|
||||
|
||||
static inline bool checkrain_option_enabled(checkrain_option_t flags, checkrain_option_t opt)
|
||||
{
|
||||
if(flags == checkrain_option_failure)
|
||||
{
|
||||
switch(opt)
|
||||
{
|
||||
case checkrain_option_safemode:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return (flags & opt) != 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,860 @@
|
||||
/*
|
||||
* LZ4 - Fast LZ compression algorithm
|
||||
* Header File
|
||||
* Copyright (C) 2011-2020, Yann Collet.
|
||||
|
||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
You can contact the author at :
|
||||
- LZ4 homepage : http://www.lz4.org
|
||||
- LZ4 source repository : https://github.com/lz4/lz4
|
||||
*/
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef LZ4_H_2983827168210
|
||||
#define LZ4_H_2983827168210
|
||||
|
||||
/* --- Dependency --- */
|
||||
#include <stddef.h> /* size_t */
|
||||
|
||||
|
||||
/**
|
||||
Introduction
|
||||
|
||||
LZ4 is lossless compression algorithm, providing compression speed >500 MB/s per core,
|
||||
scalable with multi-cores CPU. It features an extremely fast decoder, with speed in
|
||||
multiple GB/s per core, typically reaching RAM speed limits on multi-core systems.
|
||||
|
||||
The LZ4 compression library provides in-memory compression and decompression functions.
|
||||
It gives full buffer control to user.
|
||||
Compression can be done in:
|
||||
- a single step (described as Simple Functions)
|
||||
- a single step, reusing a context (described in Advanced Functions)
|
||||
- unbounded multiple steps (described as Streaming compression)
|
||||
|
||||
lz4.h generates and decodes LZ4-compressed blocks (doc/lz4_Block_format.md).
|
||||
Decompressing such a compressed block requires additional metadata.
|
||||
Exact metadata depends on exact decompression function.
|
||||
For the typical case of LZ4_decompress_safe(),
|
||||
metadata includes block's compressed size, and maximum bound of decompressed size.
|
||||
Each application is free to encode and pass such metadata in whichever way it wants.
|
||||
|
||||
lz4.h only handle blocks, it can not generate Frames.
|
||||
|
||||
Blocks are different from Frames (doc/lz4_Frame_format.md).
|
||||
Frames bundle both blocks and metadata in a specified manner.
|
||||
Embedding metadata is required for compressed data to be self-contained and portable.
|
||||
Frame format is delivered through a companion API, declared in lz4frame.h.
|
||||
The `lz4` CLI can only manage frames.
|
||||
*/
|
||||
|
||||
/*^***************************************************************
|
||||
* Export parameters
|
||||
*****************************************************************/
|
||||
/*
|
||||
* LZ4_DLL_EXPORT :
|
||||
* Enable exporting of functions when building a Windows DLL
|
||||
* LZ4LIB_VISIBILITY :
|
||||
* Control library symbols visibility.
|
||||
*/
|
||||
#ifndef LZ4LIB_VISIBILITY
|
||||
# if defined(__GNUC__) && (__GNUC__ >= 4)
|
||||
# define LZ4LIB_VISIBILITY __attribute__ ((visibility ("default")))
|
||||
# else
|
||||
# define LZ4LIB_VISIBILITY
|
||||
# endif
|
||||
#endif
|
||||
#if defined(LZ4_DLL_EXPORT) && (LZ4_DLL_EXPORT==1)
|
||||
# define LZ4LIB_API __declspec(dllexport) LZ4LIB_VISIBILITY
|
||||
#elif defined(LZ4_DLL_IMPORT) && (LZ4_DLL_IMPORT==1)
|
||||
# define LZ4LIB_API __declspec(dllimport) LZ4LIB_VISIBILITY /* It isn't required but allows to generate better code, saving a function pointer load from the IAT and an indirect jump.*/
|
||||
#else
|
||||
# define LZ4LIB_API LZ4LIB_VISIBILITY
|
||||
#endif
|
||||
|
||||
/*! LZ4_FREESTANDING :
|
||||
* When this macro is set to 1, it enables "freestanding mode" that is
|
||||
* suitable for typical freestanding environment which doesn't support
|
||||
* standard C library.
|
||||
*
|
||||
* - LZ4_FREESTANDING is a compile-time switch.
|
||||
* - It requires the following macros to be defined:
|
||||
* LZ4_memcpy, LZ4_memmove, LZ4_memset.
|
||||
* - It only enables LZ4/HC functions which don't use heap.
|
||||
* All LZ4F_* functions are not supported.
|
||||
* - See tests/freestanding.c to check its basic setup.
|
||||
*/
|
||||
#if defined(LZ4_FREESTANDING) && (LZ4_FREESTANDING == 1)
|
||||
# define LZ4_HEAPMODE 0
|
||||
# define LZ4HC_HEAPMODE 0
|
||||
# define LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION 1
|
||||
# if !defined(LZ4_memcpy)
|
||||
# error "LZ4_FREESTANDING requires macro 'LZ4_memcpy'."
|
||||
# endif
|
||||
# if !defined(LZ4_memset)
|
||||
# error "LZ4_FREESTANDING requires macro 'LZ4_memset'."
|
||||
# endif
|
||||
# if !defined(LZ4_memmove)
|
||||
# error "LZ4_FREESTANDING requires macro 'LZ4_memmove'."
|
||||
# endif
|
||||
#elif ! defined(LZ4_FREESTANDING)
|
||||
# define LZ4_FREESTANDING 0
|
||||
#endif
|
||||
|
||||
|
||||
/*------ Version ------*/
|
||||
#define LZ4_VERSION_MAJOR 1 /* for breaking interface changes */
|
||||
#define LZ4_VERSION_MINOR 9 /* for new (non-breaking) interface capabilities */
|
||||
#define LZ4_VERSION_RELEASE 4 /* for tweaks, bug-fixes, or development */
|
||||
|
||||
#define LZ4_VERSION_NUMBER (LZ4_VERSION_MAJOR *100*100 + LZ4_VERSION_MINOR *100 + LZ4_VERSION_RELEASE)
|
||||
|
||||
#define LZ4_LIB_VERSION LZ4_VERSION_MAJOR.LZ4_VERSION_MINOR.LZ4_VERSION_RELEASE
|
||||
#define LZ4_QUOTE(str) #str
|
||||
#define LZ4_EXPAND_AND_QUOTE(str) LZ4_QUOTE(str)
|
||||
#define LZ4_VERSION_STRING LZ4_EXPAND_AND_QUOTE(LZ4_LIB_VERSION) /* requires v1.7.3+ */
|
||||
|
||||
LZ4LIB_API int LZ4_versionNumber (void); /**< library version number; useful to check dll version; requires v1.3.0+ */
|
||||
LZ4LIB_API const char* LZ4_versionString (void); /**< library version string; useful to check dll version; requires v1.7.5+ */
|
||||
|
||||
|
||||
/*-************************************
|
||||
* Tuning parameter
|
||||
**************************************/
|
||||
#define LZ4_MEMORY_USAGE_MIN 10
|
||||
#define LZ4_MEMORY_USAGE_DEFAULT 14
|
||||
#define LZ4_MEMORY_USAGE_MAX 20
|
||||
|
||||
/*!
|
||||
* LZ4_MEMORY_USAGE :
|
||||
* Memory usage formula : N->2^N Bytes (examples : 10 -> 1KB; 12 -> 4KB ; 16 -> 64KB; 20 -> 1MB; )
|
||||
* Increasing memory usage improves compression ratio, at the cost of speed.
|
||||
* Reduced memory usage may improve speed at the cost of ratio, thanks to better cache locality.
|
||||
* Default value is 14, for 16KB, which nicely fits into Intel x86 L1 cache
|
||||
*/
|
||||
#ifndef LZ4_MEMORY_USAGE
|
||||
# define LZ4_MEMORY_USAGE LZ4_MEMORY_USAGE_DEFAULT
|
||||
#endif
|
||||
|
||||
#if (LZ4_MEMORY_USAGE < LZ4_MEMORY_USAGE_MIN)
|
||||
# error "LZ4_MEMORY_USAGE is too small !"
|
||||
#endif
|
||||
|
||||
#if (LZ4_MEMORY_USAGE > LZ4_MEMORY_USAGE_MAX)
|
||||
# error "LZ4_MEMORY_USAGE is too large !"
|
||||
#endif
|
||||
|
||||
/*-************************************
|
||||
* Simple Functions
|
||||
**************************************/
|
||||
/*! LZ4_compress_default() :
|
||||
* Compresses 'srcSize' bytes from buffer 'src'
|
||||
* into already allocated 'dst' buffer of size 'dstCapacity'.
|
||||
* Compression is guaranteed to succeed if 'dstCapacity' >= LZ4_compressBound(srcSize).
|
||||
* It also runs faster, so it's a recommended setting.
|
||||
* If the function cannot compress 'src' into a more limited 'dst' budget,
|
||||
* compression stops *immediately*, and the function result is zero.
|
||||
* In which case, 'dst' content is undefined (invalid).
|
||||
* srcSize : max supported value is LZ4_MAX_INPUT_SIZE.
|
||||
* dstCapacity : size of buffer 'dst' (which must be already allocated)
|
||||
* @return : the number of bytes written into buffer 'dst' (necessarily <= dstCapacity)
|
||||
* or 0 if compression fails
|
||||
* Note : This function is protected against buffer overflow scenarios (never writes outside 'dst' buffer, nor read outside 'source' buffer).
|
||||
*/
|
||||
LZ4LIB_API int LZ4_compress_default(const char* src, char* dst, int srcSize, int dstCapacity);
|
||||
|
||||
/*! LZ4_decompress_safe() :
|
||||
* @compressedSize : is the exact complete size of the compressed block.
|
||||
* @dstCapacity : is the size of destination buffer (which must be already allocated),
|
||||
* is an upper bound of decompressed size.
|
||||
* @return : the number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
|
||||
* If destination buffer is not large enough, decoding will stop and output an error code (negative value).
|
||||
* If the source stream is detected malformed, the function will stop decoding and return a negative result.
|
||||
* Note 1 : This function is protected against malicious data packets :
|
||||
* it will never writes outside 'dst' buffer, nor read outside 'source' buffer,
|
||||
* even if the compressed block is maliciously modified to order the decoder to do these actions.
|
||||
* In such case, the decoder stops immediately, and considers the compressed block malformed.
|
||||
* Note 2 : compressedSize and dstCapacity must be provided to the function, the compressed block does not contain them.
|
||||
* The implementation is free to send / store / derive this information in whichever way is most beneficial.
|
||||
* If there is a need for a different format which bundles together both compressed data and its metadata, consider looking at lz4frame.h instead.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_decompress_safe (const char* src, char* dst, int compressedSize, int dstCapacity);
|
||||
|
||||
|
||||
/*-************************************
|
||||
* Advanced Functions
|
||||
**************************************/
|
||||
#define LZ4_MAX_INPUT_SIZE 0x7E000000 /* 2 113 929 216 bytes */
|
||||
#define LZ4_COMPRESSBOUND(isize) ((unsigned)(isize) > (unsigned)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
|
||||
|
||||
/*! LZ4_compressBound() :
|
||||
Provides the maximum size that LZ4 compression may output in a "worst case" scenario (input data not compressible)
|
||||
This function is primarily useful for memory allocation purposes (destination buffer size).
|
||||
Macro LZ4_COMPRESSBOUND() is also provided for compilation-time evaluation (stack memory allocation for example).
|
||||
Note that LZ4_compress_default() compresses faster when dstCapacity is >= LZ4_compressBound(srcSize)
|
||||
inputSize : max supported value is LZ4_MAX_INPUT_SIZE
|
||||
return : maximum output size in a "worst case" scenario
|
||||
or 0, if input size is incorrect (too large or negative)
|
||||
*/
|
||||
LZ4LIB_API int LZ4_compressBound(int inputSize);
|
||||
|
||||
/*! LZ4_compress_fast() :
|
||||
Same as LZ4_compress_default(), but allows selection of "acceleration" factor.
|
||||
The larger the acceleration value, the faster the algorithm, but also the lesser the compression.
|
||||
It's a trade-off. It can be fine tuned, with each successive value providing roughly +~3% to speed.
|
||||
An acceleration value of "1" is the same as regular LZ4_compress_default()
|
||||
Values <= 0 will be replaced by LZ4_ACCELERATION_DEFAULT (currently == 1, see lz4.c).
|
||||
Values > LZ4_ACCELERATION_MAX will be replaced by LZ4_ACCELERATION_MAX (currently == 65537, see lz4.c).
|
||||
*/
|
||||
LZ4LIB_API int LZ4_compress_fast (const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
||||
|
||||
/*! LZ4_compress_fast_extState() :
|
||||
* Same as LZ4_compress_fast(), using an externally allocated memory space for its state.
|
||||
* Use LZ4_sizeofState() to know how much memory must be allocated,
|
||||
* and allocate it on 8-bytes boundaries (using `malloc()` typically).
|
||||
* Then, provide this buffer as `void* state` to compression function.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_sizeofState(void);
|
||||
LZ4LIB_API int LZ4_compress_fast_extState (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
||||
|
||||
|
||||
/*! LZ4_compress_destSize() :
|
||||
* Reverse the logic : compresses as much data as possible from 'src' buffer
|
||||
* into already allocated buffer 'dst', of size >= 'targetDestSize'.
|
||||
* This function either compresses the entire 'src' content into 'dst' if it's large enough,
|
||||
* or fill 'dst' buffer completely with as much data as possible from 'src'.
|
||||
* note: acceleration parameter is fixed to "default".
|
||||
*
|
||||
* *srcSizePtr : will be modified to indicate how many bytes where read from 'src' to fill 'dst'.
|
||||
* New value is necessarily <= input value.
|
||||
* @return : Nb bytes written into 'dst' (necessarily <= targetDestSize)
|
||||
* or 0 if compression fails.
|
||||
*
|
||||
* Note : from v1.8.2 to v1.9.1, this function had a bug (fixed un v1.9.2+):
|
||||
* the produced compressed content could, in specific circumstances,
|
||||
* require to be decompressed into a destination buffer larger
|
||||
* by at least 1 byte than the content to decompress.
|
||||
* If an application uses `LZ4_compress_destSize()`,
|
||||
* it's highly recommended to update liblz4 to v1.9.2 or better.
|
||||
* If this can't be done or ensured,
|
||||
* the receiving decompression function should provide
|
||||
* a dstCapacity which is > decompressedSize, by at least 1 byte.
|
||||
* See https://github.com/lz4/lz4/issues/859 for details
|
||||
*/
|
||||
LZ4LIB_API int LZ4_compress_destSize (const char* src, char* dst, int* srcSizePtr, int targetDstSize);
|
||||
|
||||
/*! LZ4_decompress_safe_partial() :
|
||||
* Decompress an LZ4 compressed block, of size 'srcSize' at position 'src',
|
||||
* into destination buffer 'dst' of size 'dstCapacity'.
|
||||
* Up to 'targetOutputSize' bytes will be decoded.
|
||||
* The function stops decoding on reaching this objective.
|
||||
* This can be useful to boost performance
|
||||
* whenever only the beginning of a block is required.
|
||||
*
|
||||
* @return : the number of bytes decoded in `dst` (necessarily <= targetOutputSize)
|
||||
* If source stream is detected malformed, function returns a negative result.
|
||||
*
|
||||
* Note 1 : @return can be < targetOutputSize, if compressed block contains less data.
|
||||
*
|
||||
* Note 2 : targetOutputSize must be <= dstCapacity
|
||||
*
|
||||
* Note 3 : this function effectively stops decoding on reaching targetOutputSize,
|
||||
* so dstCapacity is kind of redundant.
|
||||
* This is because in older versions of this function,
|
||||
* decoding operation would still write complete sequences.
|
||||
* Therefore, there was no guarantee that it would stop writing at exactly targetOutputSize,
|
||||
* it could write more bytes, though only up to dstCapacity.
|
||||
* Some "margin" used to be required for this operation to work properly.
|
||||
* Thankfully, this is no longer necessary.
|
||||
* The function nonetheless keeps the same signature, in an effort to preserve API compatibility.
|
||||
*
|
||||
* Note 4 : If srcSize is the exact size of the block,
|
||||
* then targetOutputSize can be any value,
|
||||
* including larger than the block's decompressed size.
|
||||
* The function will, at most, generate block's decompressed size.
|
||||
*
|
||||
* Note 5 : If srcSize is _larger_ than block's compressed size,
|
||||
* then targetOutputSize **MUST** be <= block's decompressed size.
|
||||
* Otherwise, *silent corruption will occur*.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_decompress_safe_partial (const char* src, char* dst, int srcSize, int targetOutputSize, int dstCapacity);
|
||||
|
||||
|
||||
/*-*********************************************
|
||||
* Streaming Compression Functions
|
||||
***********************************************/
|
||||
typedef union LZ4_stream_u LZ4_stream_t; /* incomplete type (defined later) */
|
||||
|
||||
/**
|
||||
Note about RC_INVOKED
|
||||
|
||||
- RC_INVOKED is predefined symbol of rc.exe (the resource compiler which is part of MSVC/Visual Studio).
|
||||
https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros
|
||||
|
||||
- Since rc.exe is a legacy compiler, it truncates long symbol (> 30 chars)
|
||||
and reports warning "RC4011: identifier truncated".
|
||||
|
||||
- To eliminate the warning, we surround long preprocessor symbol with
|
||||
"#if !defined(RC_INVOKED) ... #endif" block that means
|
||||
"skip this block when rc.exe is trying to read it".
|
||||
*/
|
||||
#if !defined(RC_INVOKED) /* https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros */
|
||||
#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
|
||||
LZ4LIB_API LZ4_stream_t* LZ4_createStream(void);
|
||||
LZ4LIB_API int LZ4_freeStream (LZ4_stream_t* streamPtr);
|
||||
#endif /* !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION) */
|
||||
#endif
|
||||
|
||||
/*! LZ4_resetStream_fast() : v1.9.0+
|
||||
* Use this to prepare an LZ4_stream_t for a new chain of dependent blocks
|
||||
* (e.g., LZ4_compress_fast_continue()).
|
||||
*
|
||||
* An LZ4_stream_t must be initialized once before usage.
|
||||
* This is automatically done when created by LZ4_createStream().
|
||||
* However, should the LZ4_stream_t be simply declared on stack (for example),
|
||||
* it's necessary to initialize it first, using LZ4_initStream().
|
||||
*
|
||||
* After init, start any new stream with LZ4_resetStream_fast().
|
||||
* A same LZ4_stream_t can be re-used multiple times consecutively
|
||||
* and compress multiple streams,
|
||||
* provided that it starts each new stream with LZ4_resetStream_fast().
|
||||
*
|
||||
* LZ4_resetStream_fast() is much faster than LZ4_initStream(),
|
||||
* but is not compatible with memory regions containing garbage data.
|
||||
*
|
||||
* Note: it's only useful to call LZ4_resetStream_fast()
|
||||
* in the context of streaming compression.
|
||||
* The *extState* functions perform their own resets.
|
||||
* Invoking LZ4_resetStream_fast() before is redundant, and even counterproductive.
|
||||
*/
|
||||
LZ4LIB_API void LZ4_resetStream_fast (LZ4_stream_t* streamPtr);
|
||||
|
||||
/*! LZ4_loadDict() :
|
||||
* Use this function to reference a static dictionary into LZ4_stream_t.
|
||||
* The dictionary must remain available during compression.
|
||||
* LZ4_loadDict() triggers a reset, so any previous data will be forgotten.
|
||||
* The same dictionary will have to be loaded on decompression side for successful decoding.
|
||||
* Dictionary are useful for better compression of small data (KB range).
|
||||
* While LZ4 accept any input as dictionary,
|
||||
* results are generally better when using Zstandard's Dictionary Builder.
|
||||
* Loading a size of 0 is allowed, and is the same as reset.
|
||||
* @return : loaded dictionary size, in bytes (necessarily <= 64 KB)
|
||||
*/
|
||||
LZ4LIB_API int LZ4_loadDict (LZ4_stream_t* streamPtr, const char* dictionary, int dictSize);
|
||||
|
||||
/*! LZ4_compress_fast_continue() :
|
||||
* Compress 'src' content using data from previously compressed blocks, for better compression ratio.
|
||||
* 'dst' buffer must be already allocated.
|
||||
* If dstCapacity >= LZ4_compressBound(srcSize), compression is guaranteed to succeed, and runs faster.
|
||||
*
|
||||
* @return : size of compressed block
|
||||
* or 0 if there is an error (typically, cannot fit into 'dst').
|
||||
*
|
||||
* Note 1 : Each invocation to LZ4_compress_fast_continue() generates a new block.
|
||||
* Each block has precise boundaries.
|
||||
* Each block must be decompressed separately, calling LZ4_decompress_*() with relevant metadata.
|
||||
* It's not possible to append blocks together and expect a single invocation of LZ4_decompress_*() to decompress them together.
|
||||
*
|
||||
* Note 2 : The previous 64KB of source data is __assumed__ to remain present, unmodified, at same address in memory !
|
||||
*
|
||||
* Note 3 : When input is structured as a double-buffer, each buffer can have any size, including < 64 KB.
|
||||
* Make sure that buffers are separated, by at least one byte.
|
||||
* This construction ensures that each block only depends on previous block.
|
||||
*
|
||||
* Note 4 : If input buffer is a ring-buffer, it can have any size, including < 64 KB.
|
||||
*
|
||||
* Note 5 : After an error, the stream status is undefined (invalid), it can only be reset or freed.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_compress_fast_continue (LZ4_stream_t* streamPtr, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
||||
|
||||
/*! LZ4_saveDict() :
|
||||
* If last 64KB data cannot be guaranteed to remain available at its current memory location,
|
||||
* save it into a safer place (char* safeBuffer).
|
||||
* This is schematically equivalent to a memcpy() followed by LZ4_loadDict(),
|
||||
* but is much faster, because LZ4_saveDict() doesn't need to rebuild tables.
|
||||
* @return : saved dictionary size in bytes (necessarily <= maxDictSize), or 0 if error.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_saveDict (LZ4_stream_t* streamPtr, char* safeBuffer, int maxDictSize);
|
||||
|
||||
|
||||
/*-**********************************************
|
||||
* Streaming Decompression Functions
|
||||
* Bufferless synchronous API
|
||||
************************************************/
|
||||
typedef union LZ4_streamDecode_u LZ4_streamDecode_t; /* tracking context */
|
||||
|
||||
/*! LZ4_createStreamDecode() and LZ4_freeStreamDecode() :
|
||||
* creation / destruction of streaming decompression tracking context.
|
||||
* A tracking context can be re-used multiple times.
|
||||
*/
|
||||
#if !defined(RC_INVOKED) /* https://docs.microsoft.com/en-us/windows/win32/menurc/predefined-macros */
|
||||
#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
|
||||
LZ4LIB_API LZ4_streamDecode_t* LZ4_createStreamDecode(void);
|
||||
LZ4LIB_API int LZ4_freeStreamDecode (LZ4_streamDecode_t* LZ4_stream);
|
||||
#endif /* !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION) */
|
||||
#endif
|
||||
|
||||
/*! LZ4_setStreamDecode() :
|
||||
* An LZ4_streamDecode_t context can be allocated once and re-used multiple times.
|
||||
* Use this function to start decompression of a new stream of blocks.
|
||||
* A dictionary can optionally be set. Use NULL or size 0 for a reset order.
|
||||
* Dictionary is presumed stable : it must remain accessible and unmodified during next decompression.
|
||||
* @return : 1 if OK, 0 if error
|
||||
*/
|
||||
LZ4LIB_API int LZ4_setStreamDecode (LZ4_streamDecode_t* LZ4_streamDecode, const char* dictionary, int dictSize);
|
||||
|
||||
/*! LZ4_decoderRingBufferSize() : v1.8.2+
|
||||
* Note : in a ring buffer scenario (optional),
|
||||
* blocks are presumed decompressed next to each other
|
||||
* up to the moment there is not enough remaining space for next block (remainingSize < maxBlockSize),
|
||||
* at which stage it resumes from beginning of ring buffer.
|
||||
* When setting such a ring buffer for streaming decompression,
|
||||
* provides the minimum size of this ring buffer
|
||||
* to be compatible with any source respecting maxBlockSize condition.
|
||||
* @return : minimum ring buffer size,
|
||||
* or 0 if there is an error (invalid maxBlockSize).
|
||||
*/
|
||||
LZ4LIB_API int LZ4_decoderRingBufferSize(int maxBlockSize);
|
||||
#define LZ4_DECODER_RING_BUFFER_SIZE(maxBlockSize) (65536 + 14 + (maxBlockSize)) /* for static allocation; maxBlockSize presumed valid */
|
||||
|
||||
/*! LZ4_decompress_safe_continue() :
|
||||
* This decoding function allows decompression of consecutive blocks in "streaming" mode.
|
||||
* The difference with the usual independent blocks is that
|
||||
* new blocks are allowed to find references into former blocks.
|
||||
* A block is an unsplittable entity, and must be presented entirely to the decompression function.
|
||||
* LZ4_decompress_safe_continue() only accepts one block at a time.
|
||||
* It's modeled after `LZ4_decompress_safe()` and behaves similarly.
|
||||
*
|
||||
* @LZ4_streamDecode : decompression state, tracking the position in memory of past data
|
||||
* @compressedSize : exact complete size of one compressed block.
|
||||
* @dstCapacity : size of destination buffer (which must be already allocated),
|
||||
* must be an upper bound of decompressed size.
|
||||
* @return : number of bytes decompressed into destination buffer (necessarily <= dstCapacity)
|
||||
* If destination buffer is not large enough, decoding will stop and output an error code (negative value).
|
||||
* If the source stream is detected malformed, the function will stop decoding and return a negative result.
|
||||
*
|
||||
* The last 64KB of previously decoded data *must* remain available and unmodified
|
||||
* at the memory position where they were previously decoded.
|
||||
* If less than 64KB of data has been decoded, all the data must be present.
|
||||
*
|
||||
* Special : if decompression side sets a ring buffer, it must respect one of the following conditions :
|
||||
* - Decompression buffer size is _at least_ LZ4_decoderRingBufferSize(maxBlockSize).
|
||||
* maxBlockSize is the maximum size of any single block. It can have any value > 16 bytes.
|
||||
* In which case, encoding and decoding buffers do not need to be synchronized.
|
||||
* Actually, data can be produced by any source compliant with LZ4 format specification, and respecting maxBlockSize.
|
||||
* - Synchronized mode :
|
||||
* Decompression buffer size is _exactly_ the same as compression buffer size,
|
||||
* and follows exactly same update rule (block boundaries at same positions),
|
||||
* and decoding function is provided with exact decompressed size of each block (exception for last block of the stream),
|
||||
* _then_ decoding & encoding ring buffer can have any size, including small ones ( < 64 KB).
|
||||
* - Decompression buffer is larger than encoding buffer, by a minimum of maxBlockSize more bytes.
|
||||
* In which case, encoding and decoding buffers do not need to be synchronized,
|
||||
* and encoding ring buffer can have any size, including small ones ( < 64 KB).
|
||||
*
|
||||
* Whenever these conditions are not possible,
|
||||
* save the last 64KB of decoded data into a safe buffer where it can't be modified during decompression,
|
||||
* then indicate where this data is saved using LZ4_setStreamDecode(), before decompressing next block.
|
||||
*/
|
||||
LZ4LIB_API int
|
||||
LZ4_decompress_safe_continue (LZ4_streamDecode_t* LZ4_streamDecode,
|
||||
const char* src, char* dst,
|
||||
int srcSize, int dstCapacity);
|
||||
|
||||
|
||||
/*! LZ4_decompress_safe_usingDict() :
|
||||
* Works the same as
|
||||
* a combination of LZ4_setStreamDecode() followed by LZ4_decompress_safe_continue()
|
||||
* However, it's stateless: it doesn't need any LZ4_streamDecode_t state.
|
||||
* Dictionary is presumed stable : it must remain accessible and unmodified during decompression.
|
||||
* Performance tip : Decompression speed can be substantially increased
|
||||
* when dst == dictStart + dictSize.
|
||||
*/
|
||||
LZ4LIB_API int
|
||||
LZ4_decompress_safe_usingDict(const char* src, char* dst,
|
||||
int srcSize, int dstCapacity,
|
||||
const char* dictStart, int dictSize);
|
||||
|
||||
/*! LZ4_decompress_safe_partial_usingDict() :
|
||||
* Behaves the same as LZ4_decompress_safe_partial()
|
||||
* with the added ability to specify a memory segment for past data.
|
||||
* Performance tip : Decompression speed can be substantially increased
|
||||
* when dst == dictStart + dictSize.
|
||||
*/
|
||||
LZ4LIB_API int
|
||||
LZ4_decompress_safe_partial_usingDict(const char* src, char* dst,
|
||||
int compressedSize,
|
||||
int targetOutputSize, int maxOutputSize,
|
||||
const char* dictStart, int dictSize);
|
||||
|
||||
#endif /* LZ4_H_2983827168210 */
|
||||
|
||||
|
||||
/*^*************************************
|
||||
* !!!!!! STATIC LINKING ONLY !!!!!!
|
||||
***************************************/
|
||||
|
||||
/*-****************************************************************************
|
||||
* Experimental section
|
||||
*
|
||||
* Symbols declared in this section must be considered unstable. Their
|
||||
* signatures or semantics may change, or they may be removed altogether in the
|
||||
* future. They are therefore only safe to depend on when the caller is
|
||||
* statically linked against the library.
|
||||
*
|
||||
* To protect against unsafe usage, not only are the declarations guarded,
|
||||
* the definitions are hidden by default
|
||||
* when building LZ4 as a shared/dynamic library.
|
||||
*
|
||||
* In order to access these declarations,
|
||||
* define LZ4_STATIC_LINKING_ONLY in your application
|
||||
* before including LZ4's headers.
|
||||
*
|
||||
* In order to make their implementations accessible dynamically, you must
|
||||
* define LZ4_PUBLISH_STATIC_FUNCTIONS when building the LZ4 library.
|
||||
******************************************************************************/
|
||||
|
||||
#ifdef LZ4_STATIC_LINKING_ONLY
|
||||
|
||||
#ifndef LZ4_STATIC_3504398509
|
||||
#define LZ4_STATIC_3504398509
|
||||
|
||||
#ifdef LZ4_PUBLISH_STATIC_FUNCTIONS
|
||||
#define LZ4LIB_STATIC_API LZ4LIB_API
|
||||
#else
|
||||
#define LZ4LIB_STATIC_API
|
||||
#endif
|
||||
|
||||
|
||||
/*! LZ4_compress_fast_extState_fastReset() :
|
||||
* A variant of LZ4_compress_fast_extState().
|
||||
*
|
||||
* Using this variant avoids an expensive initialization step.
|
||||
* It is only safe to call if the state buffer is known to be correctly initialized already
|
||||
* (see above comment on LZ4_resetStream_fast() for a definition of "correctly initialized").
|
||||
* From a high level, the difference is that
|
||||
* this function initializes the provided state with a call to something like LZ4_resetStream_fast()
|
||||
* while LZ4_compress_fast_extState() starts with a call to LZ4_resetStream().
|
||||
*/
|
||||
LZ4LIB_STATIC_API int LZ4_compress_fast_extState_fastReset (void* state, const char* src, char* dst, int srcSize, int dstCapacity, int acceleration);
|
||||
|
||||
/*! LZ4_attach_dictionary() :
|
||||
* This is an experimental API that allows
|
||||
* efficient use of a static dictionary many times.
|
||||
*
|
||||
* Rather than re-loading the dictionary buffer into a working context before
|
||||
* each compression, or copying a pre-loaded dictionary's LZ4_stream_t into a
|
||||
* working LZ4_stream_t, this function introduces a no-copy setup mechanism,
|
||||
* in which the working stream references the dictionary stream in-place.
|
||||
*
|
||||
* Several assumptions are made about the state of the dictionary stream.
|
||||
* Currently, only streams which have been prepared by LZ4_loadDict() should
|
||||
* be expected to work.
|
||||
*
|
||||
* Alternatively, the provided dictionaryStream may be NULL,
|
||||
* in which case any existing dictionary stream is unset.
|
||||
*
|
||||
* If a dictionary is provided, it replaces any pre-existing stream history.
|
||||
* The dictionary contents are the only history that can be referenced and
|
||||
* logically immediately precede the data compressed in the first subsequent
|
||||
* compression call.
|
||||
*
|
||||
* The dictionary will only remain attached to the working stream through the
|
||||
* first compression call, at the end of which it is cleared. The dictionary
|
||||
* stream (and source buffer) must remain in-place / accessible / unchanged
|
||||
* through the completion of the first compression call on the stream.
|
||||
*/
|
||||
LZ4LIB_STATIC_API void
|
||||
LZ4_attach_dictionary(LZ4_stream_t* workingStream,
|
||||
const LZ4_stream_t* dictionaryStream);
|
||||
|
||||
|
||||
/*! In-place compression and decompression
|
||||
*
|
||||
* It's possible to have input and output sharing the same buffer,
|
||||
* for highly constrained memory environments.
|
||||
* In both cases, it requires input to lay at the end of the buffer,
|
||||
* and decompression to start at beginning of the buffer.
|
||||
* Buffer size must feature some margin, hence be larger than final size.
|
||||
*
|
||||
* |<------------------------buffer--------------------------------->|
|
||||
* |<-----------compressed data--------->|
|
||||
* |<-----------decompressed size------------------>|
|
||||
* |<----margin---->|
|
||||
*
|
||||
* This technique is more useful for decompression,
|
||||
* since decompressed size is typically larger,
|
||||
* and margin is short.
|
||||
*
|
||||
* In-place decompression will work inside any buffer
|
||||
* which size is >= LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(decompressedSize).
|
||||
* This presumes that decompressedSize > compressedSize.
|
||||
* Otherwise, it means compression actually expanded data,
|
||||
* and it would be more efficient to store such data with a flag indicating it's not compressed.
|
||||
* This can happen when data is not compressible (already compressed, or encrypted).
|
||||
*
|
||||
* For in-place compression, margin is larger, as it must be able to cope with both
|
||||
* history preservation, requiring input data to remain unmodified up to LZ4_DISTANCE_MAX,
|
||||
* and data expansion, which can happen when input is not compressible.
|
||||
* As a consequence, buffer size requirements are much higher,
|
||||
* and memory savings offered by in-place compression are more limited.
|
||||
*
|
||||
* There are ways to limit this cost for compression :
|
||||
* - Reduce history size, by modifying LZ4_DISTANCE_MAX.
|
||||
* Note that it is a compile-time constant, so all compressions will apply this limit.
|
||||
* Lower values will reduce compression ratio, except when input_size < LZ4_DISTANCE_MAX,
|
||||
* so it's a reasonable trick when inputs are known to be small.
|
||||
* - Require the compressor to deliver a "maximum compressed size".
|
||||
* This is the `dstCapacity` parameter in `LZ4_compress*()`.
|
||||
* When this size is < LZ4_COMPRESSBOUND(inputSize), then compression can fail,
|
||||
* in which case, the return code will be 0 (zero).
|
||||
* The caller must be ready for these cases to happen,
|
||||
* and typically design a backup scheme to send data uncompressed.
|
||||
* The combination of both techniques can significantly reduce
|
||||
* the amount of margin required for in-place compression.
|
||||
*
|
||||
* In-place compression can work in any buffer
|
||||
* which size is >= (maxCompressedSize)
|
||||
* with maxCompressedSize == LZ4_COMPRESSBOUND(srcSize) for guaranteed compression success.
|
||||
* LZ4_COMPRESS_INPLACE_BUFFER_SIZE() depends on both maxCompressedSize and LZ4_DISTANCE_MAX,
|
||||
* so it's possible to reduce memory requirements by playing with them.
|
||||
*/
|
||||
|
||||
#define LZ4_DECOMPRESS_INPLACE_MARGIN(compressedSize) (((compressedSize) >> 8) + 32)
|
||||
#define LZ4_DECOMPRESS_INPLACE_BUFFER_SIZE(decompressedSize) ((decompressedSize) + LZ4_DECOMPRESS_INPLACE_MARGIN(decompressedSize)) /**< note: presumes that compressedSize < decompressedSize. note2: margin is overestimated a bit, since it could use compressedSize instead */
|
||||
|
||||
#ifndef LZ4_DISTANCE_MAX /* history window size; can be user-defined at compile time */
|
||||
# define LZ4_DISTANCE_MAX 65535 /* set to maximum value by default */
|
||||
#endif
|
||||
|
||||
#define LZ4_COMPRESS_INPLACE_MARGIN (LZ4_DISTANCE_MAX + 32) /* LZ4_DISTANCE_MAX can be safely replaced by srcSize when it's smaller */
|
||||
#define LZ4_COMPRESS_INPLACE_BUFFER_SIZE(maxCompressedSize) ((maxCompressedSize) + LZ4_COMPRESS_INPLACE_MARGIN) /**< maxCompressedSize is generally LZ4_COMPRESSBOUND(inputSize), but can be set to any lower value, with the risk that compression can fail (return code 0(zero)) */
|
||||
|
||||
#endif /* LZ4_STATIC_3504398509 */
|
||||
#endif /* LZ4_STATIC_LINKING_ONLY */
|
||||
|
||||
|
||||
|
||||
#ifndef LZ4_H_98237428734687
|
||||
#define LZ4_H_98237428734687
|
||||
|
||||
/*-************************************************************
|
||||
* Private Definitions
|
||||
**************************************************************
|
||||
* Do not use these definitions directly.
|
||||
* They are only exposed to allow static allocation of `LZ4_stream_t` and `LZ4_streamDecode_t`.
|
||||
* Accessing members will expose user code to API and/or ABI break in future versions of the library.
|
||||
**************************************************************/
|
||||
#define LZ4_HASHLOG (LZ4_MEMORY_USAGE-2)
|
||||
#define LZ4_HASHTABLESIZE (1 << LZ4_MEMORY_USAGE)
|
||||
#define LZ4_HASH_SIZE_U32 (1 << LZ4_HASHLOG) /* required as macro for static allocation */
|
||||
|
||||
#if defined(__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
|
||||
# include <stdint.h>
|
||||
typedef int8_t LZ4_i8;
|
||||
typedef uint8_t LZ4_byte;
|
||||
typedef uint16_t LZ4_u16;
|
||||
typedef uint32_t LZ4_u32;
|
||||
#else
|
||||
typedef signed char LZ4_i8;
|
||||
typedef unsigned char LZ4_byte;
|
||||
typedef unsigned short LZ4_u16;
|
||||
typedef unsigned int LZ4_u32;
|
||||
#endif
|
||||
|
||||
/*! LZ4_stream_t :
|
||||
* Never ever use below internal definitions directly !
|
||||
* These definitions are not API/ABI safe, and may change in future versions.
|
||||
* If you need static allocation, declare or allocate an LZ4_stream_t object.
|
||||
**/
|
||||
|
||||
typedef struct LZ4_stream_t_internal LZ4_stream_t_internal;
|
||||
struct LZ4_stream_t_internal {
|
||||
LZ4_u32 hashTable[LZ4_HASH_SIZE_U32];
|
||||
const LZ4_byte* dictionary;
|
||||
const LZ4_stream_t_internal* dictCtx;
|
||||
LZ4_u32 currentOffset;
|
||||
LZ4_u32 tableType;
|
||||
LZ4_u32 dictSize;
|
||||
/* Implicit padding to ensure structure is aligned */
|
||||
};
|
||||
|
||||
#define LZ4_STREAM_MINSIZE ((1UL << LZ4_MEMORY_USAGE) + 32) /* static size, for inter-version compatibility */
|
||||
union LZ4_stream_u {
|
||||
char minStateSize[LZ4_STREAM_MINSIZE];
|
||||
LZ4_stream_t_internal internal_donotuse;
|
||||
}; /* previously typedef'd to LZ4_stream_t */
|
||||
|
||||
|
||||
/*! LZ4_initStream() : v1.9.0+
|
||||
* An LZ4_stream_t structure must be initialized at least once.
|
||||
* This is automatically done when invoking LZ4_createStream(),
|
||||
* but it's not when the structure is simply declared on stack (for example).
|
||||
*
|
||||
* Use LZ4_initStream() to properly initialize a newly declared LZ4_stream_t.
|
||||
* It can also initialize any arbitrary buffer of sufficient size,
|
||||
* and will @return a pointer of proper type upon initialization.
|
||||
*
|
||||
* Note : initialization fails if size and alignment conditions are not respected.
|
||||
* In which case, the function will @return NULL.
|
||||
* Note2: An LZ4_stream_t structure guarantees correct alignment and size.
|
||||
* Note3: Before v1.9.0, use LZ4_resetStream() instead
|
||||
**/
|
||||
LZ4LIB_API LZ4_stream_t* LZ4_initStream (void* buffer, size_t size);
|
||||
|
||||
|
||||
/*! LZ4_streamDecode_t :
|
||||
* Never ever use below internal definitions directly !
|
||||
* These definitions are not API/ABI safe, and may change in future versions.
|
||||
* If you need static allocation, declare or allocate an LZ4_streamDecode_t object.
|
||||
**/
|
||||
typedef struct {
|
||||
const LZ4_byte* externalDict;
|
||||
const LZ4_byte* prefixEnd;
|
||||
size_t extDictSize;
|
||||
size_t prefixSize;
|
||||
} LZ4_streamDecode_t_internal;
|
||||
|
||||
#define LZ4_STREAMDECODE_MINSIZE 32
|
||||
union LZ4_streamDecode_u {
|
||||
char minStateSize[LZ4_STREAMDECODE_MINSIZE];
|
||||
LZ4_streamDecode_t_internal internal_donotuse;
|
||||
} ; /* previously typedef'd to LZ4_streamDecode_t */
|
||||
|
||||
|
||||
|
||||
/*-************************************
|
||||
* Obsolete Functions
|
||||
**************************************/
|
||||
|
||||
/*! Deprecation warnings
|
||||
*
|
||||
* Deprecated functions make the compiler generate a warning when invoked.
|
||||
* This is meant to invite users to update their source code.
|
||||
* Should deprecation warnings be a problem, it is generally possible to disable them,
|
||||
* typically with -Wno-deprecated-declarations for gcc
|
||||
* or _CRT_SECURE_NO_WARNINGS in Visual.
|
||||
*
|
||||
* Another method is to define LZ4_DISABLE_DEPRECATE_WARNINGS
|
||||
* before including the header file.
|
||||
*/
|
||||
#ifdef LZ4_DISABLE_DEPRECATE_WARNINGS
|
||||
# define LZ4_DEPRECATED(message) /* disable deprecation warnings */
|
||||
#else
|
||||
# if defined (__cplusplus) && (__cplusplus >= 201402) /* C++14 or greater */
|
||||
# define LZ4_DEPRECATED(message) [[deprecated(message)]]
|
||||
# elif defined(_MSC_VER)
|
||||
# define LZ4_DEPRECATED(message) __declspec(deprecated(message))
|
||||
# elif defined(__clang__) || (defined(__GNUC__) && (__GNUC__ * 10 + __GNUC_MINOR__ >= 45))
|
||||
# define LZ4_DEPRECATED(message) __attribute__((deprecated(message)))
|
||||
# elif defined(__GNUC__) && (__GNUC__ * 10 + __GNUC_MINOR__ >= 31)
|
||||
# define LZ4_DEPRECATED(message) __attribute__((deprecated))
|
||||
# else
|
||||
# pragma message("WARNING: LZ4_DEPRECATED needs custom implementation for this compiler")
|
||||
# define LZ4_DEPRECATED(message) /* disabled */
|
||||
# endif
|
||||
#endif /* LZ4_DISABLE_DEPRECATE_WARNINGS */
|
||||
|
||||
/*! Obsolete compression functions (since v1.7.3) */
|
||||
LZ4_DEPRECATED("use LZ4_compress_default() instead") LZ4LIB_API int LZ4_compress (const char* src, char* dest, int srcSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_default() instead") LZ4LIB_API int LZ4_compress_limitedOutput (const char* src, char* dest, int srcSize, int maxOutputSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") LZ4LIB_API int LZ4_compress_withState (void* state, const char* source, char* dest, int inputSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_fast_extState() instead") LZ4LIB_API int LZ4_compress_limitedOutput_withState (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") LZ4LIB_API int LZ4_compress_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_fast_continue() instead") LZ4LIB_API int LZ4_compress_limitedOutput_continue (LZ4_stream_t* LZ4_streamPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||
|
||||
/*! Obsolete decompression functions (since v1.8.0) */
|
||||
LZ4_DEPRECATED("use LZ4_decompress_fast() instead") LZ4LIB_API int LZ4_uncompress (const char* source, char* dest, int outputSize);
|
||||
LZ4_DEPRECATED("use LZ4_decompress_safe() instead") LZ4LIB_API int LZ4_uncompress_unknownOutputSize (const char* source, char* dest, int isize, int maxOutputSize);
|
||||
|
||||
/* Obsolete streaming functions (since v1.7.0)
|
||||
* degraded functionality; do not use!
|
||||
*
|
||||
* In order to perform streaming compression, these functions depended on data
|
||||
* that is no longer tracked in the state. They have been preserved as well as
|
||||
* possible: using them will still produce a correct output. However, they don't
|
||||
* actually retain any history between compression calls. The compression ratio
|
||||
* achieved will therefore be no better than compressing each chunk
|
||||
* independently.
|
||||
*/
|
||||
LZ4_DEPRECATED("Use LZ4_createStream() instead") LZ4LIB_API void* LZ4_create (char* inputBuffer);
|
||||
LZ4_DEPRECATED("Use LZ4_createStream() instead") LZ4LIB_API int LZ4_sizeofStreamState(void);
|
||||
LZ4_DEPRECATED("Use LZ4_resetStream() instead") LZ4LIB_API int LZ4_resetStreamState(void* state, char* inputBuffer);
|
||||
LZ4_DEPRECATED("Use LZ4_saveDict() instead") LZ4LIB_API char* LZ4_slideInputBuffer (void* state);
|
||||
|
||||
/*! Obsolete streaming decoding functions (since v1.7.0) */
|
||||
LZ4_DEPRECATED("use LZ4_decompress_safe_usingDict() instead") LZ4LIB_API int LZ4_decompress_safe_withPrefix64k (const char* src, char* dst, int compressedSize, int maxDstSize);
|
||||
LZ4_DEPRECATED("use LZ4_decompress_fast_usingDict() instead") LZ4LIB_API int LZ4_decompress_fast_withPrefix64k (const char* src, char* dst, int originalSize);
|
||||
|
||||
/*! Obsolete LZ4_decompress_fast variants (since v1.9.0) :
|
||||
* These functions used to be faster than LZ4_decompress_safe(),
|
||||
* but this is no longer the case. They are now slower.
|
||||
* This is because LZ4_decompress_fast() doesn't know the input size,
|
||||
* and therefore must progress more cautiously into the input buffer to not read beyond the end of block.
|
||||
* On top of that `LZ4_decompress_fast()` is not protected vs malformed or malicious inputs, making it a security liability.
|
||||
* As a consequence, LZ4_decompress_fast() is strongly discouraged, and deprecated.
|
||||
*
|
||||
* The last remaining LZ4_decompress_fast() specificity is that
|
||||
* it can decompress a block without knowing its compressed size.
|
||||
* Such functionality can be achieved in a more secure manner
|
||||
* by employing LZ4_decompress_safe_partial().
|
||||
*
|
||||
* Parameters:
|
||||
* originalSize : is the uncompressed size to regenerate.
|
||||
* `dst` must be already allocated, its size must be >= 'originalSize' bytes.
|
||||
* @return : number of bytes read from source buffer (== compressed size).
|
||||
* The function expects to finish at block's end exactly.
|
||||
* If the source stream is detected malformed, the function stops decoding and returns a negative result.
|
||||
* note : LZ4_decompress_fast*() requires originalSize. Thanks to this information, it never writes past the output buffer.
|
||||
* However, since it doesn't know its 'src' size, it may read an unknown amount of input, past input buffer bounds.
|
||||
* Also, since match offsets are not validated, match reads from 'src' may underflow too.
|
||||
* These issues never happen if input (compressed) data is correct.
|
||||
* But they may happen if input data is invalid (error or intentional tampering).
|
||||
* As a consequence, use these functions in trusted environments with trusted data **only**.
|
||||
*/
|
||||
LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe() instead")
|
||||
LZ4LIB_API int LZ4_decompress_fast (const char* src, char* dst, int originalSize);
|
||||
LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_continue() instead")
|
||||
LZ4LIB_API int LZ4_decompress_fast_continue (LZ4_streamDecode_t* LZ4_streamDecode, const char* src, char* dst, int originalSize);
|
||||
LZ4_DEPRECATED("This function is deprecated and unsafe. Consider using LZ4_decompress_safe_usingDict() instead")
|
||||
LZ4LIB_API int LZ4_decompress_fast_usingDict (const char* src, char* dst, int originalSize, const char* dictStart, int dictSize);
|
||||
|
||||
/*! LZ4_resetStream() :
|
||||
* An LZ4_stream_t structure must be initialized at least once.
|
||||
* This is done with LZ4_initStream(), or LZ4_resetStream().
|
||||
* Consider switching to LZ4_initStream(),
|
||||
* invoking LZ4_resetStream() will trigger deprecation warnings in the future.
|
||||
*/
|
||||
LZ4LIB_API void LZ4_resetStream (LZ4_stream_t* streamPtr);
|
||||
|
||||
|
||||
#endif /* LZ4_H_98237428734687 */
|
||||
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,413 @@
|
||||
/*
|
||||
LZ4 HC - High Compression Mode of LZ4
|
||||
Header File
|
||||
Copyright (C) 2011-2020, Yann Collet.
|
||||
BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
You can contact the author at :
|
||||
- LZ4 source repository : https://github.com/lz4/lz4
|
||||
- LZ4 public forum : https://groups.google.com/forum/#!forum/lz4c
|
||||
*/
|
||||
#ifndef LZ4_HC_H_19834876238432
|
||||
#define LZ4_HC_H_19834876238432
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* --- Dependency --- */
|
||||
/* note : lz4hc requires lz4.h/lz4.c for compilation */
|
||||
#include "lz4.h" /* stddef, LZ4LIB_API, LZ4_DEPRECATED */
|
||||
|
||||
|
||||
/* --- Useful constants --- */
|
||||
#define LZ4HC_CLEVEL_MIN 3
|
||||
#define LZ4HC_CLEVEL_DEFAULT 9
|
||||
#define LZ4HC_CLEVEL_OPT_MIN 10
|
||||
#define LZ4HC_CLEVEL_MAX 12
|
||||
|
||||
|
||||
/*-************************************
|
||||
* Block Compression
|
||||
**************************************/
|
||||
/*! LZ4_compress_HC() :
|
||||
* Compress data from `src` into `dst`, using the powerful but slower "HC" algorithm.
|
||||
* `dst` must be already allocated.
|
||||
* Compression is guaranteed to succeed if `dstCapacity >= LZ4_compressBound(srcSize)` (see "lz4.h")
|
||||
* Max supported `srcSize` value is LZ4_MAX_INPUT_SIZE (see "lz4.h")
|
||||
* `compressionLevel` : any value between 1 and LZ4HC_CLEVEL_MAX will work.
|
||||
* Values > LZ4HC_CLEVEL_MAX behave the same as LZ4HC_CLEVEL_MAX.
|
||||
* @return : the number of bytes written into 'dst'
|
||||
* or 0 if compression fails.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_compress_HC (const char* src, char* dst, int srcSize, int dstCapacity, int compressionLevel);
|
||||
|
||||
|
||||
/* Note :
|
||||
* Decompression functions are provided within "lz4.h" (BSD license)
|
||||
*/
|
||||
|
||||
|
||||
/*! LZ4_compress_HC_extStateHC() :
|
||||
* Same as LZ4_compress_HC(), but using an externally allocated memory segment for `state`.
|
||||
* `state` size is provided by LZ4_sizeofStateHC().
|
||||
* Memory segment must be aligned on 8-bytes boundaries (which a normal malloc() should do properly).
|
||||
*/
|
||||
LZ4LIB_API int LZ4_sizeofStateHC(void);
|
||||
LZ4LIB_API int LZ4_compress_HC_extStateHC(void* stateHC, const char* src, char* dst, int srcSize, int maxDstSize, int compressionLevel);
|
||||
|
||||
|
||||
/*! LZ4_compress_HC_destSize() : v1.9.0+
|
||||
* Will compress as much data as possible from `src`
|
||||
* to fit into `targetDstSize` budget.
|
||||
* Result is provided in 2 parts :
|
||||
* @return : the number of bytes written into 'dst' (necessarily <= targetDstSize)
|
||||
* or 0 if compression fails.
|
||||
* `srcSizePtr` : on success, *srcSizePtr is updated to indicate how much bytes were read from `src`
|
||||
*/
|
||||
LZ4LIB_API int LZ4_compress_HC_destSize(void* stateHC,
|
||||
const char* src, char* dst,
|
||||
int* srcSizePtr, int targetDstSize,
|
||||
int compressionLevel);
|
||||
|
||||
|
||||
/*-************************************
|
||||
* Streaming Compression
|
||||
* Bufferless synchronous API
|
||||
**************************************/
|
||||
typedef union LZ4_streamHC_u LZ4_streamHC_t; /* incomplete type (defined later) */
|
||||
|
||||
/*! LZ4_createStreamHC() and LZ4_freeStreamHC() :
|
||||
* These functions create and release memory for LZ4 HC streaming state.
|
||||
* Newly created states are automatically initialized.
|
||||
* A same state can be used multiple times consecutively,
|
||||
* starting with LZ4_resetStreamHC_fast() to start a new stream of blocks.
|
||||
*/
|
||||
LZ4LIB_API LZ4_streamHC_t* LZ4_createStreamHC(void);
|
||||
LZ4LIB_API int LZ4_freeStreamHC (LZ4_streamHC_t* streamHCPtr);
|
||||
|
||||
/*
|
||||
These functions compress data in successive blocks of any size,
|
||||
using previous blocks as dictionary, to improve compression ratio.
|
||||
One key assumption is that previous blocks (up to 64 KB) remain read-accessible while compressing next blocks.
|
||||
There is an exception for ring buffers, which can be smaller than 64 KB.
|
||||
Ring-buffer scenario is automatically detected and handled within LZ4_compress_HC_continue().
|
||||
|
||||
Before starting compression, state must be allocated and properly initialized.
|
||||
LZ4_createStreamHC() does both, though compression level is set to LZ4HC_CLEVEL_DEFAULT.
|
||||
|
||||
Selecting the compression level can be done with LZ4_resetStreamHC_fast() (starts a new stream)
|
||||
or LZ4_setCompressionLevel() (anytime, between blocks in the same stream) (experimental).
|
||||
LZ4_resetStreamHC_fast() only works on states which have been properly initialized at least once,
|
||||
which is automatically the case when state is created using LZ4_createStreamHC().
|
||||
|
||||
After reset, a first "fictional block" can be designated as initial dictionary,
|
||||
using LZ4_loadDictHC() (Optional).
|
||||
|
||||
Invoke LZ4_compress_HC_continue() to compress each successive block.
|
||||
The number of blocks is unlimited.
|
||||
Previous input blocks, including initial dictionary when present,
|
||||
must remain accessible and unmodified during compression.
|
||||
|
||||
It's allowed to update compression level anytime between blocks,
|
||||
using LZ4_setCompressionLevel() (experimental).
|
||||
|
||||
'dst' buffer should be sized to handle worst case scenarios
|
||||
(see LZ4_compressBound(), it ensures compression success).
|
||||
In case of failure, the API does not guarantee recovery,
|
||||
so the state _must_ be reset.
|
||||
To ensure compression success
|
||||
whenever `dst` buffer size cannot be made >= LZ4_compressBound(),
|
||||
consider using LZ4_compress_HC_continue_destSize().
|
||||
|
||||
Whenever previous input blocks can't be preserved unmodified in-place during compression of next blocks,
|
||||
it's possible to copy the last blocks into a more stable memory space, using LZ4_saveDictHC().
|
||||
Return value of LZ4_saveDictHC() is the size of dictionary effectively saved into 'safeBuffer' (<= 64 KB)
|
||||
|
||||
After completing a streaming compression,
|
||||
it's possible to start a new stream of blocks, using the same LZ4_streamHC_t state,
|
||||
just by resetting it, using LZ4_resetStreamHC_fast().
|
||||
*/
|
||||
|
||||
LZ4LIB_API void LZ4_resetStreamHC_fast(LZ4_streamHC_t* streamHCPtr, int compressionLevel); /* v1.9.0+ */
|
||||
LZ4LIB_API int LZ4_loadDictHC (LZ4_streamHC_t* streamHCPtr, const char* dictionary, int dictSize);
|
||||
|
||||
LZ4LIB_API int LZ4_compress_HC_continue (LZ4_streamHC_t* streamHCPtr,
|
||||
const char* src, char* dst,
|
||||
int srcSize, int maxDstSize);
|
||||
|
||||
/*! LZ4_compress_HC_continue_destSize() : v1.9.0+
|
||||
* Similar to LZ4_compress_HC_continue(),
|
||||
* but will read as much data as possible from `src`
|
||||
* to fit into `targetDstSize` budget.
|
||||
* Result is provided into 2 parts :
|
||||
* @return : the number of bytes written into 'dst' (necessarily <= targetDstSize)
|
||||
* or 0 if compression fails.
|
||||
* `srcSizePtr` : on success, *srcSizePtr will be updated to indicate how much bytes were read from `src`.
|
||||
* Note that this function may not consume the entire input.
|
||||
*/
|
||||
LZ4LIB_API int LZ4_compress_HC_continue_destSize(LZ4_streamHC_t* LZ4_streamHCPtr,
|
||||
const char* src, char* dst,
|
||||
int* srcSizePtr, int targetDstSize);
|
||||
|
||||
LZ4LIB_API int LZ4_saveDictHC (LZ4_streamHC_t* streamHCPtr, char* safeBuffer, int maxDictSize);
|
||||
|
||||
|
||||
|
||||
/*^**********************************************
|
||||
* !!!!!! STATIC LINKING ONLY !!!!!!
|
||||
***********************************************/
|
||||
|
||||
/*-******************************************************************
|
||||
* PRIVATE DEFINITIONS :
|
||||
* Do not use these definitions directly.
|
||||
* They are merely exposed to allow static allocation of `LZ4_streamHC_t`.
|
||||
* Declare an `LZ4_streamHC_t` directly, rather than any type below.
|
||||
* Even then, only do so in the context of static linking, as definitions may change between versions.
|
||||
********************************************************************/
|
||||
|
||||
#define LZ4HC_DICTIONARY_LOGSIZE 16
|
||||
#define LZ4HC_MAXD (1<<LZ4HC_DICTIONARY_LOGSIZE)
|
||||
#define LZ4HC_MAXD_MASK (LZ4HC_MAXD - 1)
|
||||
|
||||
#define LZ4HC_HASH_LOG 15
|
||||
#define LZ4HC_HASHTABLESIZE (1 << LZ4HC_HASH_LOG)
|
||||
#define LZ4HC_HASH_MASK (LZ4HC_HASHTABLESIZE - 1)
|
||||
|
||||
|
||||
/* Never ever use these definitions directly !
|
||||
* Declare or allocate an LZ4_streamHC_t instead.
|
||||
**/
|
||||
typedef struct LZ4HC_CCtx_internal LZ4HC_CCtx_internal;
|
||||
struct LZ4HC_CCtx_internal
|
||||
{
|
||||
LZ4_u32 hashTable[LZ4HC_HASHTABLESIZE];
|
||||
LZ4_u16 chainTable[LZ4HC_MAXD];
|
||||
const LZ4_byte* end; /* next block here to continue on current prefix */
|
||||
const LZ4_byte* prefixStart; /* Indexes relative to this position */
|
||||
const LZ4_byte* dictStart; /* alternate reference for extDict */
|
||||
LZ4_u32 dictLimit; /* below that point, need extDict */
|
||||
LZ4_u32 lowLimit; /* below that point, no more dict */
|
||||
LZ4_u32 nextToUpdate; /* index from which to continue dictionary update */
|
||||
short compressionLevel;
|
||||
LZ4_i8 favorDecSpeed; /* favor decompression speed if this flag set,
|
||||
otherwise, favor compression ratio */
|
||||
LZ4_i8 dirty; /* stream has to be fully reset if this flag is set */
|
||||
const LZ4HC_CCtx_internal* dictCtx;
|
||||
};
|
||||
|
||||
#define LZ4_STREAMHC_MINSIZE 262200 /* static size, for inter-version compatibility */
|
||||
union LZ4_streamHC_u {
|
||||
char minStateSize[LZ4_STREAMHC_MINSIZE];
|
||||
LZ4HC_CCtx_internal internal_donotuse;
|
||||
}; /* previously typedef'd to LZ4_streamHC_t */
|
||||
|
||||
/* LZ4_streamHC_t :
|
||||
* This structure allows static allocation of LZ4 HC streaming state.
|
||||
* This can be used to allocate statically on stack, or as part of a larger structure.
|
||||
*
|
||||
* Such state **must** be initialized using LZ4_initStreamHC() before first use.
|
||||
*
|
||||
* Note that invoking LZ4_initStreamHC() is not required when
|
||||
* the state was created using LZ4_createStreamHC() (which is recommended).
|
||||
* Using the normal builder, a newly created state is automatically initialized.
|
||||
*
|
||||
* Static allocation shall only be used in combination with static linking.
|
||||
*/
|
||||
|
||||
/* LZ4_initStreamHC() : v1.9.0+
|
||||
* Required before first use of a statically allocated LZ4_streamHC_t.
|
||||
* Before v1.9.0 : use LZ4_resetStreamHC() instead
|
||||
*/
|
||||
LZ4LIB_API LZ4_streamHC_t* LZ4_initStreamHC(void* buffer, size_t size);
|
||||
|
||||
|
||||
/*-************************************
|
||||
* Deprecated Functions
|
||||
**************************************/
|
||||
/* see lz4.h LZ4_DISABLE_DEPRECATE_WARNINGS to turn off deprecation warnings */
|
||||
|
||||
/* deprecated compression functions */
|
||||
LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC (const char* source, char* dest, int inputSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC_limitedOutput (const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC2 (const char* source, char* dest, int inputSize, int compressionLevel);
|
||||
LZ4_DEPRECATED("use LZ4_compress_HC() instead") LZ4LIB_API int LZ4_compressHC2_limitedOutput(const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
|
||||
LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC_withStateHC (void* state, const char* source, char* dest, int inputSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC_limitedOutput_withStateHC (void* state, const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC2_withStateHC (void* state, const char* source, char* dest, int inputSize, int compressionLevel);
|
||||
LZ4_DEPRECATED("use LZ4_compress_HC_extStateHC() instead") LZ4LIB_API int LZ4_compressHC2_limitedOutput_withStateHC(void* state, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
|
||||
LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize);
|
||||
LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC_limitedOutput_continue (LZ4_streamHC_t* LZ4_streamHCPtr, const char* source, char* dest, int inputSize, int maxOutputSize);
|
||||
|
||||
/* Obsolete streaming functions; degraded functionality; do not use!
|
||||
*
|
||||
* In order to perform streaming compression, these functions depended on data
|
||||
* that is no longer tracked in the state. They have been preserved as well as
|
||||
* possible: using them will still produce a correct output. However, use of
|
||||
* LZ4_slideInputBufferHC() will truncate the history of the stream, rather
|
||||
* than preserve a window-sized chunk of history.
|
||||
*/
|
||||
#if !defined(LZ4_STATIC_LINKING_ONLY_DISABLE_MEMORY_ALLOCATION)
|
||||
LZ4_DEPRECATED("use LZ4_createStreamHC() instead") LZ4LIB_API void* LZ4_createHC (const char* inputBuffer);
|
||||
LZ4_DEPRECATED("use LZ4_freeStreamHC() instead") LZ4LIB_API int LZ4_freeHC (void* LZ4HC_Data);
|
||||
#endif
|
||||
LZ4_DEPRECATED("use LZ4_saveDictHC() instead") LZ4LIB_API char* LZ4_slideInputBufferHC (void* LZ4HC_Data);
|
||||
LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC2_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int compressionLevel);
|
||||
LZ4_DEPRECATED("use LZ4_compress_HC_continue() instead") LZ4LIB_API int LZ4_compressHC2_limitedOutput_continue (void* LZ4HC_Data, const char* source, char* dest, int inputSize, int maxOutputSize, int compressionLevel);
|
||||
LZ4_DEPRECATED("use LZ4_createStreamHC() instead") LZ4LIB_API int LZ4_sizeofStreamStateHC(void);
|
||||
LZ4_DEPRECATED("use LZ4_initStreamHC() instead") LZ4LIB_API int LZ4_resetStreamStateHC(void* state, char* inputBuffer);
|
||||
|
||||
|
||||
/* LZ4_resetStreamHC() is now replaced by LZ4_initStreamHC().
|
||||
* The intention is to emphasize the difference with LZ4_resetStreamHC_fast(),
|
||||
* which is now the recommended function to start a new stream of blocks,
|
||||
* but cannot be used to initialize a memory segment containing arbitrary garbage data.
|
||||
*
|
||||
* It is recommended to switch to LZ4_initStreamHC().
|
||||
* LZ4_resetStreamHC() will generate deprecation warnings in a future version.
|
||||
*/
|
||||
LZ4LIB_API void LZ4_resetStreamHC (LZ4_streamHC_t* streamHCPtr, int compressionLevel);
|
||||
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LZ4_HC_H_19834876238432 */
|
||||
|
||||
|
||||
/*-**************************************************
|
||||
* !!!!! STATIC LINKING ONLY !!!!!
|
||||
* Following definitions are considered experimental.
|
||||
* They should not be linked from DLL,
|
||||
* as there is no guarantee of API stability yet.
|
||||
* Prototypes will be promoted to "stable" status
|
||||
* after successful usage in real-life scenarios.
|
||||
***************************************************/
|
||||
#ifdef LZ4_HC_STATIC_LINKING_ONLY /* protection macro */
|
||||
#ifndef LZ4_HC_SLO_098092834
|
||||
#define LZ4_HC_SLO_098092834
|
||||
|
||||
#define LZ4_STATIC_LINKING_ONLY /* LZ4LIB_STATIC_API */
|
||||
#include "lz4.h"
|
||||
|
||||
#if defined (__cplusplus)
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*! LZ4_setCompressionLevel() : v1.8.0+ (experimental)
|
||||
* It's possible to change compression level
|
||||
* between successive invocations of LZ4_compress_HC_continue*()
|
||||
* for dynamic adaptation.
|
||||
*/
|
||||
LZ4LIB_STATIC_API void LZ4_setCompressionLevel(
|
||||
LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
|
||||
|
||||
/*! LZ4_favorDecompressionSpeed() : v1.8.2+ (experimental)
|
||||
* Opt. Parser will favor decompression speed over compression ratio.
|
||||
* Only applicable to levels >= LZ4HC_CLEVEL_OPT_MIN.
|
||||
*/
|
||||
LZ4LIB_STATIC_API void LZ4_favorDecompressionSpeed(
|
||||
LZ4_streamHC_t* LZ4_streamHCPtr, int favor);
|
||||
|
||||
/*! LZ4_resetStreamHC_fast() : v1.9.0+
|
||||
* When an LZ4_streamHC_t is known to be in a internally coherent state,
|
||||
* it can often be prepared for a new compression with almost no work, only
|
||||
* sometimes falling back to the full, expensive reset that is always required
|
||||
* when the stream is in an indeterminate state (i.e., the reset performed by
|
||||
* LZ4_resetStreamHC()).
|
||||
*
|
||||
* LZ4_streamHCs are guaranteed to be in a valid state when:
|
||||
* - returned from LZ4_createStreamHC()
|
||||
* - reset by LZ4_resetStreamHC()
|
||||
* - memset(stream, 0, sizeof(LZ4_streamHC_t))
|
||||
* - the stream was in a valid state and was reset by LZ4_resetStreamHC_fast()
|
||||
* - the stream was in a valid state and was then used in any compression call
|
||||
* that returned success
|
||||
* - the stream was in an indeterminate state and was used in a compression
|
||||
* call that fully reset the state (LZ4_compress_HC_extStateHC()) and that
|
||||
* returned success
|
||||
*
|
||||
* Note:
|
||||
* A stream that was last used in a compression call that returned an error
|
||||
* may be passed to this function. However, it will be fully reset, which will
|
||||
* clear any existing history and settings from the context.
|
||||
*/
|
||||
LZ4LIB_STATIC_API void LZ4_resetStreamHC_fast(
|
||||
LZ4_streamHC_t* LZ4_streamHCPtr, int compressionLevel);
|
||||
|
||||
/*! LZ4_compress_HC_extStateHC_fastReset() :
|
||||
* A variant of LZ4_compress_HC_extStateHC().
|
||||
*
|
||||
* Using this variant avoids an expensive initialization step. It is only safe
|
||||
* to call if the state buffer is known to be correctly initialized already
|
||||
* (see above comment on LZ4_resetStreamHC_fast() for a definition of
|
||||
* "correctly initialized"). From a high level, the difference is that this
|
||||
* function initializes the provided state with a call to
|
||||
* LZ4_resetStreamHC_fast() while LZ4_compress_HC_extStateHC() starts with a
|
||||
* call to LZ4_resetStreamHC().
|
||||
*/
|
||||
LZ4LIB_STATIC_API int LZ4_compress_HC_extStateHC_fastReset (
|
||||
void* state,
|
||||
const char* src, char* dst,
|
||||
int srcSize, int dstCapacity,
|
||||
int compressionLevel);
|
||||
|
||||
/*! LZ4_attach_HC_dictionary() :
|
||||
* This is an experimental API that allows for the efficient use of a
|
||||
* static dictionary many times.
|
||||
*
|
||||
* Rather than re-loading the dictionary buffer into a working context before
|
||||
* each compression, or copying a pre-loaded dictionary's LZ4_streamHC_t into a
|
||||
* working LZ4_streamHC_t, this function introduces a no-copy setup mechanism,
|
||||
* in which the working stream references the dictionary stream in-place.
|
||||
*
|
||||
* Several assumptions are made about the state of the dictionary stream.
|
||||
* Currently, only streams which have been prepared by LZ4_loadDictHC() should
|
||||
* be expected to work.
|
||||
*
|
||||
* Alternatively, the provided dictionary stream pointer may be NULL, in which
|
||||
* case any existing dictionary stream is unset.
|
||||
*
|
||||
* A dictionary should only be attached to a stream without any history (i.e.,
|
||||
* a stream that has just been reset).
|
||||
*
|
||||
* The dictionary will remain attached to the working stream only for the
|
||||
* current stream session. Calls to LZ4_resetStreamHC(_fast) will remove the
|
||||
* dictionary context association from the working stream. The dictionary
|
||||
* stream (and source buffer) must remain in-place / accessible / unchanged
|
||||
* through the lifetime of the stream session.
|
||||
*/
|
||||
LZ4LIB_STATIC_API void LZ4_attach_HC_dictionary(
|
||||
LZ4_streamHC_t *working_stream,
|
||||
const LZ4_streamHC_t *dictionary_stream);
|
||||
|
||||
#if defined (__cplusplus)
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* LZ4_HC_SLO_098092834 */
|
||||
#endif /* LZ4_HC_STATIC_LINKING_ONLY */
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* jbinit - https://github.com/palera1n/jbinit
|
||||
*
|
||||
* This file is part of jbinit
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*/
|
||||
|
||||
#ifndef PALEINFO_H
|
||||
#define PALEINFO_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define PALEINFO_VERSION 2U
|
||||
typedef uint64_t palerain_option_t;
|
||||
|
||||
// unified palera1n options
|
||||
#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 */
|
||||
#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_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*/
|
||||
#define palerain_option_dfuhelper_only (UINT64_C(1) << 12) /* dfuhelper only */
|
||||
#define palerain_option_pongo_exit (UINT64_C(1) << 13) /* boot to clean pongo shell */
|
||||
#define palerain_option_demote (UINT64_C(1) << 14) /* Demote effective production fuse status */
|
||||
#define palerain_option_pongo_full (UINT64_C(1) << 15) /* Boot to pongo with default images and options */
|
||||
#define palerain_option_palerain_version (UINT64_C(1) << 16) /* Print version */
|
||||
#define palerain_option_exit_recovery (UINT64_C(1) << 17) /* Exit recovery mode */
|
||||
#define palerain_option_reboot_device (UINT64_C(1) << 18) /* Reboot device in normal mode */
|
||||
#define palerain_option_enter_recovery (UINT64_C(1) << 19) /* Enter recovery mode */
|
||||
#define palerain_option_device_info (UINT64_C(1) << 20) /* Print device info */
|
||||
#define palerain_option_no_colors (UINT64_C(1) << 21) /* no colors */
|
||||
#define palerain_option_bind_mount (UINT64_C(1) << 22) /* bind mounts should be used (always true iOS 15+)*/
|
||||
#define palerain_option_overlay (UINT64_C(1) << 23) /* there is an overlay (should always be true) */
|
||||
#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_flower_chain (UINT64_C(1) << 61) /* Flower chain */
|
||||
#define palerain_option_test1 (UINT64_C(1) << 62) /* Developer test option 1 */
|
||||
#define palerain_option_test2 (UINT64_C(1) << 63) /* Developer test option 2 */
|
||||
|
||||
#define PALEINFO_MAGIC 'PLSH'
|
||||
|
||||
/* paleinfo version 2, appended to ramdisk */
|
||||
struct paleinfo {
|
||||
uint32_t magic; /* 'PLSH' */
|
||||
uint32_t version; /* 2 */
|
||||
uint64_t kbase; /* kernel base */
|
||||
uint64_t kslide; /* kernel slide */
|
||||
uint64_t flags; /* unified palera1n flags */
|
||||
char rootdev[0x10]; /* ex. disk0s1s8 */
|
||||
}__attribute__((packed));
|
||||
|
||||
#endif
|
||||
+30
-28
@@ -2,11 +2,11 @@
|
||||
#define PALERAIN_H
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#define _DARWIN_C_SOURCE 1
|
||||
#define NSIG __DARWIN_NSIG
|
||||
#endif
|
||||
|
||||
#include "xxd-embedded.h"
|
||||
#include "kerninfo.h"
|
||||
#include "paleinfo.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
@@ -14,6 +14,7 @@
|
||||
#include <usbmuxd.h>
|
||||
#include <libirecovery.h>
|
||||
#include <libimobiledevice/libimobiledevice.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#define LOG(loglevel, ...) p1_log(loglevel, __FILE__, __LINE__, __func__, __VA_ARGS__)
|
||||
#define CLEAR() printf("\33[2K\r");
|
||||
@@ -31,6 +32,7 @@
|
||||
#define USB_RET_SUCCESS LIBUSB_SUCCESS
|
||||
#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 libusb_device_handle *usb_device_handle_t;
|
||||
|
||||
@@ -51,7 +53,8 @@ usb_ret_t USBBulkUpload(usb_device_handle_t handle, void *data, int len);
|
||||
|
||||
#define USB_RET_SUCCESS KERN_SUCCESS
|
||||
#define USB_RET_NOT_RESPONDING kIOReturnNotResponding
|
||||
#define USB_RET_IO kIOReturnNotResponding
|
||||
#define USB_RET_IO kIOReturnNotReady
|
||||
#define USB_RET_NO_DEVICE kIOReturnNoDevice
|
||||
|
||||
typedef IOReturn usb_ret_t;
|
||||
typedef IOUSBInterfaceInterface245 **usb_device_handle_t;
|
||||
@@ -98,6 +101,8 @@ struct mach_header_64
|
||||
};
|
||||
#endif
|
||||
|
||||
typedef void *(*pthread_start_t)(void *);
|
||||
|
||||
// Keep in sync with Pongo
|
||||
#define PONGO_USB_VENDOR 0x05ac
|
||||
#define PONGO_USB_PRODUCT 0x4141
|
||||
@@ -146,13 +151,12 @@ typedef unsigned char niarelap_file_t[];
|
||||
|
||||
extern unsigned int verbose;
|
||||
|
||||
extern char* pongo_path;
|
||||
#ifdef DEV_BUILD
|
||||
#ifdef TUI
|
||||
extern bool tui_started;
|
||||
#endif
|
||||
|
||||
extern checkrain_option_t host_flags;
|
||||
extern checkrain_option_p host_flags_p;
|
||||
extern uint64_t palerain_flags;
|
||||
extern uint64_t* palerain_flags_p;
|
||||
|
||||
extern pthread_t dfuhelper_thread, pongo_thread;
|
||||
extern int pongo_thr_running, dfuhelper_thr_running;
|
||||
@@ -161,7 +165,7 @@ extern niarelap_file_t *kpf_to_upload_1, *ramdisk_to_upload_1, *overlay_to_uploa
|
||||
extern niarelap_file_t **kpf_to_upload, **ramdisk_to_upload, **overlay_to_upload;
|
||||
extern override_file_t override_ramdisk, override_kpf, override_overlay;
|
||||
|
||||
extern uint32_t checkrain_flags, palerain_flags, kpf_flags;
|
||||
extern uint64_t palerain_flags;
|
||||
extern pthread_mutex_t log_mutex;
|
||||
|
||||
extern pthread_mutex_t spin_mutex, found_pongo_mutex, ecid_dfu_wait_mutex;
|
||||
@@ -169,22 +173,17 @@ extern pthread_mutex_t spin_mutex, found_pongo_mutex, ecid_dfu_wait_mutex;
|
||||
extern int pongo_thr_running, dfuhelper_thr_running;
|
||||
extern bool device_has_booted;
|
||||
extern char xargs_cmd[0x270];
|
||||
extern char checkrain_flags_cmd[0x20];
|
||||
extern char palerain_flags_cmd[0x20];
|
||||
extern char kpf_flags_cmd[0x20];
|
||||
extern char dtpatch_cmd[0x20];
|
||||
extern char rootfs_cmd[512];
|
||||
extern char* ext_checkra1n;
|
||||
extern char palerain_flags_cmd[0x30];
|
||||
|
||||
void thr_cleanup(void* ptr);
|
||||
void* dfuhelper(void* ptr);
|
||||
int p1_log(log_level_t loglevel, const char *fname, int lineno, const char *fxname, char* __restrict format, ...);
|
||||
int p1_log(log_level_t loglevel, const char *fname, int lineno, const char *fxname, const char* __restrict format, ...);
|
||||
/* devhelper helpers */
|
||||
void devinfo_free(devinfo_t *dev);
|
||||
bool cpid_is_arm64(unsigned int cpid);
|
||||
/* devhelper commands */
|
||||
int subscribe_cmd(usbmuxd_event_cb_t device_event_cb, irecv_device_event_cb_t irecv_event_cb);
|
||||
int unsubscribe_cmd();
|
||||
int unsubscribe_cmd(void);
|
||||
int devinfo_cmd(devinfo_t *dev, const char *udid);
|
||||
int enter_recovery_cmd(const char* udid);
|
||||
int reboot_cmd(const char* udid);
|
||||
@@ -193,37 +192,40 @@ int recvinfo_cmd(recvinfo_t* info, const uint64_t ecid);
|
||||
int autoboot_cmd(const uint64_t ecid);
|
||||
int exitrecv_cmd(const uint64_t ecid);
|
||||
|
||||
int exec_checkra1n();
|
||||
int exec_checkm8(void);
|
||||
int override_file(override_file_t *finfo, niarelap_file_t** orig, unsigned int *orig_len, char *filename);
|
||||
void* pongo_helper(void* ptr);
|
||||
const unsigned char *
|
||||
boyermoore_horspool_memmem(const unsigned char* haystack, size_t hlen,
|
||||
const unsigned char* needle, size_t nlen);
|
||||
|
||||
|
||||
extern void* pongo_usb_callback(void* arg);
|
||||
extern void* pongo_usb_callback(stuff_t* arg);
|
||||
usb_ret_t USBControlTransfer(usb_device_handle_t handle, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, uint32_t wLength, void *data, uint32_t *wLenDone);
|
||||
const char *usb_strerror(usb_ret_t err);
|
||||
int wait_for_pongo();
|
||||
int issue_pongo_command();
|
||||
int upload_pongo_file();
|
||||
int tui();
|
||||
int wait_for_pongo(void);
|
||||
int upload_pongo_file(usb_device_handle_t, unsigned char*, unsigned int);
|
||||
int issue_pongo_command(usb_device_handle_t, char*);
|
||||
int tui(void);
|
||||
int optparse(int argc, char* argv[]);
|
||||
|
||||
bool get_spin();
|
||||
bool get_spin(void);
|
||||
bool set_spin(bool val);
|
||||
bool get_found_pongo();
|
||||
bool get_found_pongo(void);
|
||||
void* pongo_helper(void* _);
|
||||
bool set_found_pongo(bool val);
|
||||
uint64_t get_ecid_wait_for_dfu();
|
||||
uint64_t get_ecid_wait_for_dfu(void);
|
||||
uint64_t set_ecid_wait_for_dfu(uint64_t ecid);
|
||||
|
||||
void write_stdout(char *buf, uint32_t len);
|
||||
void io_start(stuff_t *stuff);
|
||||
void io_stop(stuff_t *stuff);
|
||||
|
||||
void print_credits();
|
||||
void print_credits(void);
|
||||
|
||||
#ifdef DEV_BUILD
|
||||
#ifdef TUI
|
||||
#include <newt.h>
|
||||
newtComponent get_tui_log();
|
||||
newtComponent get_tui_log(void);
|
||||
newtComponent set_tui_log(newtComponent co);
|
||||
#endif
|
||||
#endif
|
||||
+10
-9
@@ -11,6 +11,7 @@
|
||||
#include <locale.h>
|
||||
#include <unistd.h>
|
||||
#include <newt.h>
|
||||
#include <paleinfo.h>
|
||||
|
||||
#define WIDTH 76
|
||||
#define HEIGHT 19
|
||||
@@ -19,7 +20,7 @@
|
||||
#define PI_STEP_CURRENT NEWT_COLORSET_CUSTOM(1)
|
||||
#define PI_STEP_OTHER NEWT_COLORSET_CUSTOM(2)
|
||||
|
||||
#define CHECKBOX_STATE(flags, opt) checkrain_option_enabled(flags, opt) ? '*' : ' '
|
||||
#define CHECKBOX_STATE(flags, opt) (flags & opt) != 0 ? '*' : ' '
|
||||
|
||||
typedef enum tui_screens {
|
||||
ERROR_SCREEN = -1,
|
||||
@@ -32,17 +33,17 @@ typedef enum tui_screens {
|
||||
} tui_screen_t;
|
||||
|
||||
typedef struct bitfield_checkbox_info {
|
||||
checkrain_option_p flags_p;
|
||||
checkrain_option_t opt;
|
||||
uint64_t* flags_p;
|
||||
uint64_t opt;
|
||||
} tui_bit_info_t;
|
||||
|
||||
tui_screen_t tui_screen_main();
|
||||
tui_screen_t tui_screen_options();
|
||||
tui_screen_t tui_screen_enter_recovery();
|
||||
tui_screen_t tui_screen_enter_dfu();
|
||||
tui_screen_t tui_screen_jailbreak();
|
||||
tui_screen_t tui_screen_main(void);
|
||||
tui_screen_t tui_screen_options(void);
|
||||
tui_screen_t tui_screen_enter_recovery(void);
|
||||
tui_screen_t tui_screen_enter_dfu(void);
|
||||
tui_screen_t tui_screen_jailbreak(void);
|
||||
|
||||
int redraw_screen();
|
||||
int redraw_screen(void);
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,8 +1,9 @@
|
||||
#ifndef XXD_EMBEDDED_H
|
||||
#define XXD_EMBEDDED_H
|
||||
|
||||
extern unsigned char checkra1n[];
|
||||
extern unsigned int checkra1n_len;
|
||||
#if defined(__APPLE__)
|
||||
#include <TargetConditionals.h>
|
||||
#endif
|
||||
|
||||
extern unsigned char checkra1n_kpf_pongo[];
|
||||
extern unsigned int checkra1n_kpf_pongo_len;
|
||||
@@ -13,4 +14,9 @@ extern unsigned int ramdisk_dmg_len;
|
||||
extern unsigned char binpack_dmg[];
|
||||
extern unsigned int binpack_dmg_len;
|
||||
|
||||
#if defined(__APPLE__) && (TARGET_OS_IPHONE || defined(DEV_BUILD))
|
||||
extern unsigned char libcheckra1nhelper_dylib[];
|
||||
extern unsigned int libcheckra1nhelper_dylib_len;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,17 @@
|
||||
Package: palera1n
|
||||
Name: palera1n
|
||||
Version: @DEB_VERSION@
|
||||
Architecture: @DEB_ARCH@
|
||||
Maintainer: palera1n team
|
||||
Author: palera1n team
|
||||
Depends: usbmuxd
|
||||
Section: Utilities
|
||||
Priority: optional
|
||||
Homepage: https://palera.in
|
||||
Description: iOS 15.0-16.5.1 semi-tethered checkm8 jailbreak
|
||||
palera1n is an iOS/iPadOS 15.0-16.5.1 semi tethered jailbreak
|
||||
based on the checkm8 exploit.
|
||||
.
|
||||
palera1n is able to jailbreak the device in fakefs-rootful mode,
|
||||
where / is writable, as well as rootless mode, where / cannot be
|
||||
written to.
|
||||
@@ -0,0 +1,16 @@
|
||||
Package: palera1n
|
||||
Name: palera1n
|
||||
Version: @DEB_VERSION@
|
||||
Architecture: @DEB_ARCH@
|
||||
Maintainer: palera1n team
|
||||
Author: palera1n team
|
||||
Section: Utilities
|
||||
Priority: optional
|
||||
Homepage: https://palera.in
|
||||
Description: iOS 15.0-16.5 semi-tethered checkm8 jailbreak
|
||||
palera1n is an iOS/iPadOS 15.0-16.5 semi tethered jailbreak
|
||||
based on the checkm8 exploit.
|
||||
.
|
||||
palera1n is able to jailbreak the device in fakefs-rootful mode,
|
||||
where / is writable, as well as rootless mode, where / cannot be
|
||||
written to.
|
||||
@@ -1,6 +1,6 @@
|
||||
From 632cdb6de3f1693fb90d60d81552b723e8dd5e84 Mon Sep 17 00:00:00 2001
|
||||
From a2d012f3ba459f6debe636b576ad9aeab7b3c2aa Mon Sep 17 00:00:00 2001
|
||||
From: Nick Chan <[email protected]>
|
||||
Date: Wed, 25 Jan 2023 01:53:00 +0800
|
||||
Date: Sat, 27 May 2023 23:50:23 +0800
|
||||
Subject: [PATCH] Allow empty x509 cert issuer
|
||||
|
||||
---
|
||||
@@ -8,25 +8,24 @@ Subject: [PATCH] Allow empty x509 cert issuer
|
||||
1 file changed, 4 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/library/x509_crt.c b/library/x509_crt.c
|
||||
index 0eee97cb6..46702f683 100644
|
||||
index cf62532f2..ef25b3d77 100644
|
||||
--- a/library/x509_crt.c
|
||||
+++ b/library/x509_crt.c
|
||||
@@ -1185,14 +1185,14 @@ static int x509_crt_parse_der_core( mbedtls_x509_crt *crt,
|
||||
if( ( ret = mbedtls_asn1_get_tag( &p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE ) ) != 0 )
|
||||
{
|
||||
- mbedtls_x509_crt_free( crt );
|
||||
- return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) );
|
||||
+ // mbedtls_x509_crt_free( crt );
|
||||
+ // return( MBEDTLS_ERROR_ADD( MBEDTLS_ERR_X509_INVALID_FORMAT, ret ) );
|
||||
@@ -1061,13 +1061,13 @@ static int x509_crt_parse_der_core(mbedtls_x509_crt *crt,
|
||||
|
||||
if ((ret = mbedtls_asn1_get_tag(&p, end, &len,
|
||||
MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE)) != 0) {
|
||||
- mbedtls_x509_crt_free(crt);
|
||||
- return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);
|
||||
+ /*mbedtls_x509_crt_free(crt);
|
||||
+ return MBEDTLS_ERROR_ADD(MBEDTLS_ERR_X509_INVALID_FORMAT, ret);*/
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_x509_get_name( &p, p + len, &crt->issuer ) ) != 0 )
|
||||
{
|
||||
- mbedtls_x509_crt_free( crt );
|
||||
- return( ret );
|
||||
+ // mbedtls_x509_crt_free( crt );
|
||||
+ // return( ret );
|
||||
if ((ret = mbedtls_x509_get_name(&p, p + len, &crt->issuer)) != 0) {
|
||||
- mbedtls_x509_crt_free(crt);
|
||||
- return ret;
|
||||
+ /*mbedtls_x509_crt_free(crt);
|
||||
+ return ret;*/
|
||||
}
|
||||
|
||||
crt->issuer_raw.len = p - crt->issuer_raw.p;
|
||||
|
||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
@@ -1,344 +0,0 @@
|
||||
#execute_process(COMMAND sh -c "cd ../dep_root && sh ../download_deps.sh")
|
||||
set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")
|
||||
|
||||
|
||||
#set(SRC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
#set(DEP ${SRC}/../dep_root)
|
||||
|
||||
cmake_parse_arguments(palera1n "" "" "-arch" ${ARGN})
|
||||
|
||||
set(CHECKRA1N_VERSION 0.1337.1)
|
||||
if( ${LDID})
|
||||
set(LDID ldid)
|
||||
endif()
|
||||
if( ${LIPO})
|
||||
set(LIPO lipo)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
set(CHECKRA1N_FILE_NAME checkra1n-macos)
|
||||
else()
|
||||
set(CHECKRA1N_FILE_NAME checkra1n-linux-${CMAKE_SYSTEM_PROCESSOR})
|
||||
endif()
|
||||
|
||||
add_executable(palera1n
|
||||
binpack.dmg.c
|
||||
checkra1n-kpf-pongo.c
|
||||
checkra1n.c
|
||||
devhelper.c
|
||||
dfuhelper.c
|
||||
exec_checkra1n.c
|
||||
lock_vars.c
|
||||
lockdown_helper.c
|
||||
log.c
|
||||
main.c
|
||||
optparse.c
|
||||
override_file.c
|
||||
pongo_helper.c
|
||||
credits.c
|
||||
ramdisk.dmg.c
|
||||
../include/kerninfo.h
|
||||
../include/palerain.h
|
||||
../include/ANSI-color-codes.h
|
||||
../include/tui.h
|
||||
../include/xxd-embedded.h
|
||||
)
|
||||
|
||||
add_compile_options(-Wall -Wextra -Wno-unused-parameter -pedantic-errors -g)
|
||||
|
||||
# adds dev mode files
|
||||
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
get_property(MY_TARGET_SOURCES TARGET palera1n PROPERTY SOURCES)
|
||||
list(APPEND MY_TARGET_SOURCES tui_main.c
|
||||
tui_screen_enter_dfu.c
|
||||
tui_screen_enter_recovery.c
|
||||
tui_screen_jailbreak.c
|
||||
tui_screen_main.c
|
||||
tui_screen_options.c)
|
||||
set_property(TARGET palera1n PROPERTY SOURCES ${MY_TARGET_SOURCES})
|
||||
|
||||
|
||||
elseif(CMAKE_BUILD_TYPE STREQUAL "ASAN")
|
||||
get_property(MY_TARGET_SOURCES TARGET palera1n PROPERTY SOURCES)
|
||||
list(APPEND MY_TARGET_SOURCES tui_main.c
|
||||
tui_screen_enter_dfu.c
|
||||
tui_screen_enter_recovery.c
|
||||
tui_screen_jailbreak.c
|
||||
tui_screen_main.c
|
||||
tui_screen_options.c)
|
||||
set_property(TARGET palera1n PROPERTY SOURCES ${MY_TARGET_SOURCES})
|
||||
add_compile_options(-fsanitize=address,undefined -fsanitize-address-use-after-return=runtime)
|
||||
elseif(CMAKE_BUILD_TYPE STREQUAL "TSAN")
|
||||
get_property(MY_TARGET_SOURCES TARGET palera1n PROPERTY SOURCES)
|
||||
list(APPEND MY_TARGET_SOURCES tui_main.c
|
||||
tui_screen_enter_dfu.c
|
||||
tui_screen_enter_recovery.c
|
||||
tui_screen_jailbreak.c
|
||||
tui_screen_main.c
|
||||
tui_screen_options.c)
|
||||
set_property(TARGET palera1n PROPERTY SOURCES ${MY_TARGET_SOURCES})
|
||||
add_compile_options(-fsanitize=thread,undefined)
|
||||
else()
|
||||
set(CMAKE_BUILD_TYPE "Release")
|
||||
endif()
|
||||
|
||||
#message("Testing for Clang/LLVM")
|
||||
#string(TOLOWER CMAKE_C_COMPILER_ID COMPILER)
|
||||
|
||||
#if(CMAKE_C_COMPILER_ID MATCHES "AppleClang" OR CMAKE_C_COMPILER_ID MATCHES "Clang")
|
||||
# message("Using clang/llvm! Enabling -flto=full! Please make sure clang is up to date, or else compile will fail")
|
||||
# add_compile_options(-flto=full)
|
||||
#else()
|
||||
# message("Not using clang/llvm! Using normal lto/no lto!")
|
||||
# add_compile_options(-flto)
|
||||
#endif()
|
||||
|
||||
|
||||
|
||||
#add_custom_command(TARGET palera1n
|
||||
# COMMAND sh -c "curl -LO https://assets.checkra.in/downloads/preview/${CHECKRA1N_VERSION}/${CHECKRA1N_FILE_NAME} && chmod 755 ${CHECKRA1N_FILE_NAME}"
|
||||
# )
|
||||
#
|
||||
#if(APPLE)
|
||||
# add_custom_command(TARGET palera1n
|
||||
# COMMAND sh -c "ldid -Scheckra1n.plist checkra1n"
|
||||
# )
|
||||
# add_custom_command(TARGET palera1n
|
||||
# COMMAND lipo -thin ${CMAKE_SYSTEM_PROCESSOR} -output checkra1n checkra1n-macos
|
||||
# )
|
||||
# if(CFLAGS MATCHES "version-min=")
|
||||
# add_custom_command(TARGET palera1n
|
||||
# COMMAND sh -c "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"
|
||||
# )
|
||||
# endif()
|
||||
#else()
|
||||
# execute_process(
|
||||
# COMMAND cp ${CHECKRA1N_FILE_NAME} ../src/checkra1n
|
||||
# )
|
||||
#endif()
|
||||
|
||||
#ifneq (,$(findstring arm64, $(CFLAGS)))
|
||||
#$(LIPO) -thin arm64 -output checkra1n checkra1n-macos
|
||||
#else ifneq (,$(findstring x86_64, $(CFLAGS)))
|
||||
#$(LIPO) -thin x86_64 -output checkra1n checkra1n-macos
|
||||
#else ifeq ($(shell arch),i386)
|
||||
#$(LIPO) -thin x86_64 -output checkra1n checkra1n-macos
|
||||
#else
|
||||
#$(LIPO) -thin $(shell arch) -output checkra1n checkra1n-
|
||||
|
||||
if(APPLE)
|
||||
if(${LIBUSB})
|
||||
target_compile_definitions(palera1n PRIVATE -DUSE_LIBUSB)
|
||||
get_property(MY_TARGET_SOURCES TARGET palera1n PROPERTY SOURCES)
|
||||
list(APPEND MY_TARGET_SOURCES
|
||||
usb_libusb.c)
|
||||
set_property(TARGET palera1n PROPERTY SOURCES ${MY_TARGET_SOURCES})
|
||||
target_link_libraries(palera1n
|
||||
${DEP}/lib/libusb-1.0.a
|
||||
)
|
||||
else()
|
||||
get_property(MY_TARGET_SOURCES TARGET palera1n PROPERTY SOURCES)
|
||||
list(APPEND MY_TARGET_SOURCES
|
||||
usb_iokit.c)
|
||||
set_property(TARGET palera1n PROPERTY SOURCES ${MY_TARGET_SOURCES})
|
||||
endif()
|
||||
|
||||
|
||||
|
||||
if(IOS AND CMAKE_C_FLAGS MATCHES "arm64")
|
||||
add_custom_command(
|
||||
COMMAND sh -c "curl -Lo checkra1n-macos https://assets.checkra.in/downloads/preview/0.1337.1/${CHECKRA1N_FILE_NAME} "
|
||||
COMMAND lipo -thin arm64 -output checkra1n checkra1n-macos
|
||||
COMMAND sh -c "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"
|
||||
COMMAND sh -c "curl -Lo binpack.dmg https://cdn.nickchan.lol/palera1n/c-rewrite/deps/binpack.dmg"
|
||||
COMMAND sh -c "curl -Lo ramdisk.dmg https://cdn.nickchan.lol/palera1n/c-rewrite/deps/ramdisk.dmg"
|
||||
COMMAND sh -c "curl -Lo checkra1n-kpf-pongo https://github.com/guacaplushy/checkp4le/raw/main/binaries/checkra1n-kpf-pongo"
|
||||
COMMAND pwd
|
||||
COMMAND xxd -iC checkra1n checkra1n.c
|
||||
COMMAND xxd -iC binpack.dmg binpack.dmg.c
|
||||
COMMAND xxd -iC ramdisk.dmg ramdisk.dmg.c
|
||||
COMMAND xxd -iC checkra1n-kpf-pongo checkra1n-kpf-pongo.c
|
||||
OUTPUT checkra1n.c checkra1n-kpf-pongo.c ramdisk.dmg.c binpack.dmg.c binpack.dmg ramdisk.dmg checkra1n-kpf-pongo
|
||||
)
|
||||
elseif(CMAKE_C_FLAGS MATCHES "arm64")
|
||||
add_custom_command(
|
||||
COMMAND sh -c "curl -Lo checkra1n-macos https://assets.checkra.in/downloads/preview/0.1337.1/${CHECKRA1N_FILE_NAME} "
|
||||
COMMAND lipo -thin arm64 -output checkra1n checkra1n-macos
|
||||
COMMAND sh -c "curl -Lo binpack.dmg https://cdn.nickchan.lol/palera1n/c-rewrite/deps/binpack.dmg"
|
||||
COMMAND sh -c "curl -Lo ramdisk.dmg https://cdn.nickchan.lol/palera1n/c-rewrite/deps/ramdisk.dmg"
|
||||
COMMAND sh -c "curl -Lo checkra1n-kpf-pongo https://github.com/guacaplushy/checkp4le/raw/main/binaries/checkra1n-kpf-pongo"
|
||||
COMMAND pwd
|
||||
COMMAND xxd -iC checkra1n checkra1n.c
|
||||
COMMAND xxd -iC binpack.dmg binpack.dmg.c
|
||||
COMMAND xxd -iC ramdisk.dmg ramdisk.dmg.c
|
||||
COMMAND xxd -iC checkra1n-kpf-pongo checkra1n-kpf-pongo.c
|
||||
OUTPUT checkra1n.c checkra1n-kpf-pongo.c ramdisk.dmg.c binpack.dmg.c binpack.dmg ramdisk.dmg checkra1n-kpf-pongo
|
||||
)
|
||||
else()
|
||||
add_custom_command(
|
||||
COMMAND sh -c "curl -Lo checkra1n-macos https://assets.checkra.in/downloads/preview/0.1337.1/${CHECKRA1N_FILE_NAME} "
|
||||
COMMAND lipo -thin x86_64 -output checkra1n checkra1n-macos
|
||||
COMMAND sh -c "curl -Lo binpack.dmg https://cdn.nickchan.lol/palera1n/c-rewrite/deps/binpack.dmg"
|
||||
COMMAND sh -c "curl -Lo ramdisk.dmg https://cdn.nickchan.lol/palera1n/c-rewrite/deps/ramdisk.dmg"
|
||||
COMMAND sh -c "curl -Lo checkra1n-kpf-pongo https://github.com/guacaplushy/checkp4le/raw/main/binaries/checkra1n-kpf-pongo"
|
||||
COMMAND pwd
|
||||
COMMAND xxd -iC checkra1n checkra1n.c
|
||||
COMMAND xxd -iC binpack.dmg binpack.dmg.c
|
||||
COMMAND xxd -iC ramdisk.dmg ramdisk.dmg.c
|
||||
COMMAND xxd -iC checkra1n-kpf-pongo checkra1n-kpf-pongo.c
|
||||
OUTPUT checkra1n.c checkra1n-kpf-pongo.c ramdisk.dmg.c binpack.dmg.c binpack.dmg ramdisk.dmg checkra1n-kpf-pongo
|
||||
)
|
||||
endif()
|
||||
else()
|
||||
add_custom_command(
|
||||
COMMAND sh -c "curl -Lo checkra1n https://assets.checkra.in/downloads/preview/0.1337.1/${CHECKRA1N_FILE_NAME} "
|
||||
COMMAND sh -c "curl -Lo binpack.dmg https://cdn.nickchan.lol/palera1n/c-rewrite/deps/binpack.dmg"
|
||||
COMMAND sh -c "curl -Lo ramdisk.dmg https://cdn.nickchan.lol/palera1n/c-rewrite/deps/ramdisk.dmg"
|
||||
COMMAND sh -c "curl -Lo checkra1n-kpf-pongo https://github.com/guacaplushy/checkp4le/raw/main/binaries/checkra1n-kpf-pongo"
|
||||
COMMAND pwd
|
||||
COMMAND xxd -iC checkra1n checkra1n.c
|
||||
COMMAND xxd -iC binpack.dmg binpack.dmg.c
|
||||
COMMAND xxd -iC ramdisk.dmg ramdisk.dmg.c
|
||||
COMMAND xxd -iC checkra1n-kpf-pongo checkra1n-kpf-pongo.c
|
||||
OUTPUT checkra1n.c checkra1n-kpf-pongo.c ramdisk.dmg.c binpack.dmg.c binpack.dmg ramdisk.dmg checkra1n-kpf-pongo
|
||||
)
|
||||
target_compile_definitions(palera1n PRIVATE -DUSE_LIBUSB)
|
||||
get_property(MY_TARGET_SOURCES TARGET palera1n PROPERTY SOURCES)
|
||||
list(APPEND MY_TARGET_SOURCES
|
||||
usb_libusb.c)
|
||||
set_property(TARGET palera1n PROPERTY SOURCES ${MY_TARGET_SOURCES})
|
||||
target_link_libraries(palera1n
|
||||
${DEP}/lib/libusb-1.0.a
|
||||
)
|
||||
target_compile_definitions(palera1n PRIVATE -DUSE_LIBUSB)
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
../include
|
||||
${SRC}
|
||||
)
|
||||
|
||||
|
||||
target_compile_definitions(palera1n PRIVATE -DPALERAIN_VERSION=\"2.0.0\")
|
||||
|
||||
target_include_directories(palera1n PRIVATE
|
||||
${SRC}/include
|
||||
${SRC}
|
||||
${DEP}/include
|
||||
)
|
||||
|
||||
#if(${STATIC})
|
||||
target_link_libraries(palera1n
|
||||
${DEP}/lib/libimobiledevice-1.0.a
|
||||
${DEP}/lib/libirecovery-1.0.a
|
||||
${DEP}/lib/libusbmuxd-2.0.a
|
||||
${DEP}/lib/libimobiledevice-glue-1.0.a
|
||||
${DEP}/lib/libplist-2.0.a
|
||||
${DEP}/lib/libmbedtls.a
|
||||
${DEP}/lib/libmbedcrypto.a
|
||||
${DEP}/lib/libmbedx509.a
|
||||
${DEP}/lib/libreadline.a
|
||||
)
|
||||
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
if(NOT APPLE)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "-static")
|
||||
endif()
|
||||
#else()
|
||||
# find_library(LIBIMOBILEDEVICE libimobiledevice)
|
||||
# if (NOT CORE_FOUNDATION)
|
||||
# message(FATAL_ERROR "libimobiledevice not found")
|
||||
# endif()
|
||||
# target_link_libraries(palera1n ${LIBIMOBILEDEVICE})
|
||||
#
|
||||
# find_library(LIR libirecovery)
|
||||
# if (NOT SYSCONF)
|
||||
# message(FATAL_ERROR "libirecovery not found")
|
||||
# endif()
|
||||
# target_link_libraries(palera1n ${LIR})
|
||||
#
|
||||
# find_library(USBMUXD usbmuxd)
|
||||
# if (NOT SEC)
|
||||
# message(FATAL_ERROR "usbmuxd not found")
|
||||
# endif()
|
||||
# target_link_libraries(palera1n ${USBMUXD})
|
||||
#
|
||||
# find_library(GLUE libimobiledevice-glue)
|
||||
# if (NOT IOKIT)
|
||||
# message(FATAL_ERROR "libimobiledevice-glue not found")
|
||||
# endif()
|
||||
# target_link_libraries(palera1n ${GLUE})
|
||||
#
|
||||
## target_link_libraries(palera1n
|
||||
## imobiledevice-1.0
|
||||
## irecovery-1.0
|
||||
## usbmuxd-2.0
|
||||
## imobiledevice-glue-1.0
|
||||
## plist-2.0
|
||||
## mbedtls
|
||||
## mbedcrypto
|
||||
## mbedx509
|
||||
## readline
|
||||
## usb-1.0
|
||||
## )
|
||||
#endif()
|
||||
#if(APPLE)
|
||||
# add_compile_options(palera1n
|
||||
# -framework CoreFoundation
|
||||
# -framework SystemConfiguration
|
||||
# -framework IOKit
|
||||
# -framework Security
|
||||
# )
|
||||
#endif()
|
||||
|
||||
if(APPLE)
|
||||
find_library(CORE_FOUNDATION CoreFoundation)
|
||||
if (NOT CORE_FOUNDATION)
|
||||
message(FATAL_ERROR "CoreFoundation not found")
|
||||
endif()
|
||||
target_link_libraries(palera1n ${CORE_FOUNDATION})
|
||||
|
||||
find_library(SYSCONF SystemConfiguration)
|
||||
if (NOT SYSCONF)
|
||||
message(FATAL_ERROR "SystemConfiguration not found")
|
||||
endif()
|
||||
target_link_libraries(palera1n ${SYSCONF})
|
||||
|
||||
find_library(SEC Security)
|
||||
if (NOT SEC)
|
||||
message(FATAL_ERROR "Security not found")
|
||||
endif()
|
||||
target_link_libraries(palera1n ${SEC})
|
||||
|
||||
find_library(IOKIT IOKit)
|
||||
if (NOT IOKIT)
|
||||
message(FATAL_ERROR "IOKit not found")
|
||||
endif()
|
||||
target_link_libraries(palera1n ${IOKIT})
|
||||
endif()
|
||||
add_compile_options(palera1n
|
||||
-static -no-pie -Wl,--gc-sections
|
||||
)
|
||||
|
||||
|
||||
if(!BUILD_DATE)
|
||||
execute_process(COMMAND date OUTPUT_VARIABLE BUILD_DATE)
|
||||
endif()
|
||||
if(!BUILD_TAG)
|
||||
execute_process(COMMAND git describe --dirty --tags --abbrev=7 OUTPUT_VARIABLE BUILD_TAG)
|
||||
endif()
|
||||
if(!BUILD_WHOAMI)
|
||||
execute_process(COMMAND whoami OUTPUT_VARIABLE BUILD_WHOAMI)
|
||||
endif ()
|
||||
|
||||
set(INCLUDE_DIR /usr/local/include)
|
||||
include_directories (${INCLUDE_DIR})
|
||||
|
||||
|
||||
add_compile_definitions(
|
||||
BUILD_DATE="${BUILD_DATE}"
|
||||
BUILD_TAG="${BUILD_TAG}"
|
||||
BUILD_WHOAMI="${BUILD_WHOAMI}"
|
||||
BUILD_STYLE="${CMAKE_BUILD_TYPE}"
|
||||
)
|
||||
+46
-38
@@ -2,81 +2,86 @@ 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 += fake_embedded.o checkm8.o pongo_helper.o
|
||||
OBJECTS += boyermoore_memmem.o
|
||||
|
||||
ifeq (,$(findstring macosx, $(CFLAGS)))
|
||||
ifneq (,$(findstring version-min=, $(CFLAGS)))
|
||||
OBJECTS += xxd-libcheckra1nhelper.dylib.o
|
||||
endif
|
||||
endif
|
||||
|
||||
ifeq ($(FORCE_HELPER),1)
|
||||
OBJECTS += xxd-libcheckra1nhelper.dylib.o
|
||||
CFLAGS += -DFORCE_HELPER
|
||||
BUILD_OPTIONS += FORCE_HELPER
|
||||
endif
|
||||
|
||||
ifneq ($(NO_RAMDISK),1)
|
||||
OBJECTS += xxd-ramdisk.dmg.o
|
||||
else
|
||||
CFLAGS += -DNO_RAMDISK
|
||||
BUILD_OPTIONS += NO_RAMDISK
|
||||
endif
|
||||
ifneq ($(NO_KPF),1)
|
||||
OBJECTS += xxd-checkra1n-kpf-pongo.o
|
||||
else
|
||||
CFLAGS += -DNO_KPF
|
||||
BUILD_OPTIONS += NO_KPF
|
||||
endif
|
||||
ifneq ($(NO_BINPACK),1)
|
||||
ifneq ($(NO_OVERLAY),1)
|
||||
OBJECTS += xxd-binpack.dmg.o
|
||||
else
|
||||
CFLAGS += -DNO_BINPACK
|
||||
endif
|
||||
ifneq ($(NO_CHECKRAIN),1)
|
||||
OBJECTS += xxd-checkra1n.o
|
||||
else
|
||||
CFLAGS += -DNO_CHECKRAIN
|
||||
CFLAGS += -DNO_OVERLAY
|
||||
BUILD_OPTIONS += NO_OVERLAY
|
||||
endif
|
||||
|
||||
ifeq ($(DEV_BUILD),1)
|
||||
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
|
||||
|
||||
CHECKRA1N_VERSION ?= 0.1337.1
|
||||
LIPO = lipo
|
||||
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
|
||||
else
|
||||
USE_LIBUSB = 1
|
||||
endif
|
||||
|
||||
ifeq ($(USE_LIBUSB),1)
|
||||
OBJECTS += usb_libusb.o
|
||||
CFLAGS += -DUSE_LIBUSB=1
|
||||
CFLAGS += -DHAVE_LIBUSB -DUSE_LIBUSB=1
|
||||
ifeq ($(TARGET_OS),Windows)
|
||||
LIBS += -lusb-1.0
|
||||
else
|
||||
LIBS += $(DEP)/lib/libusb-1.0.a
|
||||
endif
|
||||
endif
|
||||
|
||||
checkra1n-%:
|
||||
curl -LO https://assets.checkra.in/downloads/preview/$(CHECKRA1N_VERSION)/$@
|
||||
chmod 755 $@
|
||||
ifeq ($(ROOTFUL),1)
|
||||
CFLAGS += -DROOTFUL=1
|
||||
BUILD_OPTIONS += ROOTFUL
|
||||
endif
|
||||
|
||||
checkra1n: checkra1n-macos usb.xml
|
||||
ifeq ($(TARGET_OS),Darwin)
|
||||
ifneq (,$(findstring arm64, $(CFLAGS)))
|
||||
$(LIPO) -thin arm64 -output checkra1n checkra1n-macos
|
||||
else ifneq (,$(findstring x86_64, $(CFLAGS)))
|
||||
$(LIPO) -thin x86_64 -output checkra1n checkra1n-macos
|
||||
else ifeq ($(shell arch),i386)
|
||||
$(LIPO) -thin x86_64 -output checkra1n checkra1n-macos
|
||||
else
|
||||
$(LIPO) -thin $(shell arch) -output checkra1n 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
|
||||
endif
|
||||
endif
|
||||
else
|
||||
cp checkra1n-$(CHECKRA1N_NAME) checkra1n
|
||||
ifeq ($(BUILD_OPTIONS),)
|
||||
BUILD_OPTIONS = (none)
|
||||
endif
|
||||
|
||||
LIBS += lz4/lz4.c lz4/lz4hc.c
|
||||
CFLAGS += -DBUILD_OPTIONS=\""$(BUILD_OPTIONS)"\" -Wno-pointer-sign -Wno-pointer-arith -Wno-pedantic
|
||||
|
||||
xxd-%.c: %
|
||||
xxd -iC $< > $@
|
||||
|
||||
@@ -91,8 +96,11 @@ ifneq (,$(findstring version-min=, $(CFLAGS)))
|
||||
endif
|
||||
endif
|
||||
|
||||
libcheckra1nhelper.dylib: chkstk.S
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -shared chkstk.S -o libcheckra1nhelper.dylib
|
||||
|
||||
checkra1n-kpf-pongo:
|
||||
curl -LO https://github.com/guacaplushy/checkp4le/raw/main/binaries/checkra1n-kpf-pongo
|
||||
curl -LO https://cdn.nickchan.lol/palera1n/artifacts/kpf/checkra1n-kpf-pongo
|
||||
|
||||
ramdisk.dmg:
|
||||
curl -LO https://cdn.nickchan.lol/palera1n/c-rewrite/deps/ramdisk.dmg
|
||||
@@ -101,6 +109,6 @@ binpack.dmg:
|
||||
curl -LO https://cdn.nickchan.lol/palera1n/c-rewrite/deps/binpack.dmg
|
||||
|
||||
clean:
|
||||
rm -rf *.o palera1n checkra1n checkra1n.c palera1n.dSYM
|
||||
rm -rf *.o palera1n checkra1n checkra1n.c palera1n.dSYM libcheckra1nhelper.dylib
|
||||
|
||||
.PHONY: all clean
|
||||
@@ -0,0 +1,59 @@
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
const unsigned char *
|
||||
boyermoore_horspool_memmem(const unsigned char* haystack, size_t hlen,
|
||||
const unsigned char* needle, size_t nlen)
|
||||
{
|
||||
size_t scan = 0;
|
||||
size_t bad_char_skip[UCHAR_MAX + 1]; /* Officially called:
|
||||
* bad character shift */
|
||||
|
||||
/* Sanity checks on the parameters */
|
||||
if (nlen <= 0 || !haystack || !needle)
|
||||
return NULL;
|
||||
|
||||
/* ---- Preprocess ---- */
|
||||
/* Initialize the table to default value */
|
||||
/* When a character is encountered that does not occur
|
||||
* in the needle, we can safely skip ahead for the whole
|
||||
* length of the needle.
|
||||
*/
|
||||
for (scan = 0; scan <= UCHAR_MAX; scan = scan + 1)
|
||||
bad_char_skip[scan] = nlen;
|
||||
|
||||
/* C arrays have the first byte at [0], therefore:
|
||||
* [nlen - 1] is the last byte of the array. */
|
||||
size_t last = nlen - 1;
|
||||
|
||||
/* Then populate it with the analysis of the needle */
|
||||
for (scan = 0; scan < last; scan = scan + 1)
|
||||
bad_char_skip[needle[scan]] = last - scan;
|
||||
|
||||
/* ---- Do the matching ---- */
|
||||
|
||||
/* Search the haystack, while the needle can still be within it. */
|
||||
while (hlen >= nlen)
|
||||
{
|
||||
/* scan from the end of the needle */
|
||||
for (scan = last; haystack[scan] == needle[scan]; scan = scan - 1)
|
||||
if (scan == 0) /* If the first byte matches, we've found it. */
|
||||
{
|
||||
return haystack;
|
||||
}
|
||||
|
||||
/* otherwise, we need to skip some bytes and start again.
|
||||
Note that here we are getting the skip value based on the last byte
|
||||
of needle, no matter where we didn't match. So if needle is: "abcd"
|
||||
then we are skipping based on 'd' and that value will be 4, and
|
||||
for "abcdd" we again skip on 'd' but the value will be only 1.
|
||||
The alternative of pretending that the mismatched character was
|
||||
the last character is slower in the normal case (E.g. finding
|
||||
"abcd" in "...azcd..." gives 4 by using 'd' but only
|
||||
4-2==2 using 'z'. */
|
||||
hlen -= bad_char_skip[haystack[last]];
|
||||
haystack += bad_char_skip[haystack[last]];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
+1058
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,65 @@
|
||||
#define _PTHREAD_STRUCT_DIRECT_STACKADDR_OFFSET -48
|
||||
#define _PTHREAD_STRUCT_DIRECT_STACKBOTTOM_OFFSET -40
|
||||
|
||||
.align 4
|
||||
_thread_chkstk_darwin:
|
||||
.globl ___chkstk_darwin
|
||||
___chkstk_darwin: // %w9/x9 == alloca size
|
||||
stp x10, x11, [sp, #-16]
|
||||
|
||||
// validate that the frame pointer is on our stack (no alt stack)
|
||||
mrs x10, TPIDRRO_EL0
|
||||
|
||||
// (%sp - pthread_self()->stackaddr) > 0 ?
|
||||
#if defined(__ARM64_ARCH_8_32__)
|
||||
ubfx x9, x9, #0, #32
|
||||
ldur w11, [x10, _PTHREAD_STRUCT_DIRECT_STACKADDR_OFFSET]
|
||||
#else
|
||||
ldur x11, [x10, _PTHREAD_STRUCT_DIRECT_STACKADDR_OFFSET]
|
||||
#endif
|
||||
subs x11, sp, x11
|
||||
b.hs Lprobe
|
||||
|
||||
// %sp <= pthread_self()->stackbottom ?
|
||||
#if defined(__ARM64_ARCH_8_32__)
|
||||
ldur w11, [x10, _PTHREAD_STRUCT_DIRECT_STACKBOTTOM_OFFSET]
|
||||
#else
|
||||
ldur x11, [x10, _PTHREAD_STRUCT_DIRECT_STACKBOTTOM_OFFSET]
|
||||
#endif
|
||||
mov x10, sp
|
||||
cmp x10, x11
|
||||
b.ls Lprobe
|
||||
|
||||
// %sp - (uintptr_t)%x9 < pthread_self()->stackbottom ?
|
||||
subs x10, x10, x9
|
||||
b.lo Lcrash
|
||||
cmp x10, x11
|
||||
b.lo Lcrash
|
||||
|
||||
Lexit:
|
||||
ldp x10, x11, [sp, #-16]
|
||||
ret
|
||||
|
||||
Lcrash:
|
||||
// POSIX mandates that stack overflow crashes with SIGSEGV
|
||||
// so load an address in the guard page and dereference it
|
||||
//
|
||||
// x11 contains pthread_self()->stackbottom already
|
||||
ldr x11, [x11, #-8]
|
||||
// if main_thread caused stack growth with setrlimit()
|
||||
// fall into Lprobe and eventually cause SIGSEGV.
|
||||
|
||||
Lprobe:
|
||||
mov x10, sp
|
||||
cmp x9, #0x1000
|
||||
b.lo Lend
|
||||
Lloop:
|
||||
sub x10, x10, #0x1000
|
||||
ldr x11, [x10]
|
||||
sub x9, x9, #0x1000
|
||||
cmp x9, #0x1000
|
||||
b.hi Lloop
|
||||
Lend:
|
||||
sub x10, x10, x9
|
||||
ldr x11, [x10]
|
||||
b Lexit
|
||||
+19
-16
@@ -1,19 +1,22 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#define EE fprintf
|
||||
#define Q }
|
||||
#define P print_credits() {
|
||||
#define BAKERAIN_DEVELOPER "dora2ios"
|
||||
#define O void
|
||||
#define Y )
|
||||
#define Z (
|
||||
#define R stdout
|
||||
#define S ,
|
||||
#define T ;
|
||||
#define A "# == palera1n-c == \n#\n"
|
||||
#define B "# Made by: Nick Chan, Tom, Mineek, Nebula, llsc12\n#\n"
|
||||
#define C "# Thanks to: " BAKERAIN_DEVELOPER ", pythonplayer, tihmstar, nikias\n"
|
||||
#define D "# (libimobiledevice), checkra1n team (Siguza, axi0mx, littlelailo\n"
|
||||
#define E "# et al.), Procursus Team (Hayden Seay, Cameron Katri, Keto et.al)\n\n"
|
||||
#ifndef BAKERAIN_DEVELOPE_R
|
||||
#define BAKERAIN_DEVELOPE_R "kok3shidoll"
|
||||
#endif
|
||||
|
||||
O P EE Z R S A B C D E Y T Q
|
||||
#define T void
|
||||
#define R print_credits(void) {
|
||||
#define O fprintf
|
||||
#define U (
|
||||
#define B stderr
|
||||
#define L ,
|
||||
#define E "# == palera1n-c == \n#\n"
|
||||
#define M "# Made by: Nick Chan, Ploosh, Samara, Nebula, staturnz, " BAKERAIN_DEVELOPE_R ", Mineek\n#\n"
|
||||
#define A "# Thanks to: pythonplayer123, llsc12, tihmstar, nikias\n"
|
||||
#define K "# (libimobiledevice), checkra1n team (Siguza, axi0mx, littlelailo\n"
|
||||
#define I "# et al.), Procursus Team (Hayden Seay, Cameron Katri, Keto et.al)\n\n"
|
||||
#define N )
|
||||
#define G ;
|
||||
#define S }
|
||||
|
||||
T R O U B L E M A K I N G S
|
||||
+83
-78
@@ -7,9 +7,9 @@
|
||||
#include <stddef.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
#ifdef WIN32
|
||||
#include <windows.h>
|
||||
#ifdef WIN
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/select.h>
|
||||
#include <sys/socket.h>
|
||||
@@ -37,6 +37,7 @@
|
||||
#include <palerain.h>
|
||||
|
||||
irecv_device_event_context_t irecvctx = NULL;
|
||||
usbmuxd_subscription_context_t usbmuxdctx = NULL;
|
||||
|
||||
void devinfo_free(devinfo_t *dev) {
|
||||
free(dev->buildVersion);
|
||||
@@ -75,28 +76,29 @@ bool cpid_is_arm64(unsigned int cpid) {
|
||||
* ========== 0x8960 ===========
|
||||
* (ARM64) A7
|
||||
*/
|
||||
if (
|
||||
cpid == 0x8960 || cpid == 0x7000 || cpid == 0x7001
|
||||
|| cpid == 0x8000 || cpid == 0x8001 || cpid == 0x8003
|
||||
|| cpid == 0x8010 || cpid == 0x8011 || cpid == 0x8012
|
||||
|| cpid == 0x8015
|
||||
|
||||
) return true;
|
||||
return false;
|
||||
return (
|
||||
cpid == 0x8960 || cpid == 0x7000 || cpid == 0x7001 ||
|
||||
cpid == 0x8000 || cpid == 0x8001 || cpid == 0x8003 ||
|
||||
cpid == 0x8010 || cpid == 0x8011 || cpid == 0x8012 ||
|
||||
cpid == 0x8015
|
||||
);
|
||||
}
|
||||
|
||||
int subscribe_cmd(usbmuxd_event_cb_t device_event_cb, irecv_device_event_cb_t irecv_event_cb)
|
||||
{
|
||||
usbmuxd_subscribe(device_event_cb, NULL);
|
||||
irecv_device_event_subscribe(&irecvctx, irecv_event_cb, NULL);
|
||||
int ret;
|
||||
if ((ret = usbmuxd_events_subscribe(&usbmuxdctx, device_event_cb, NULL))) return ret;
|
||||
if ((ret = irecv_device_event_subscribe(&irecvctx, irecv_event_cb, NULL))) return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int unsubscribe_cmd()
|
||||
int unsubscribe_cmd(void)
|
||||
{
|
||||
usbmuxd_unsubscribe();
|
||||
irecv_device_event_unsubscribe(irecvctx);
|
||||
int ret;
|
||||
if ((ret = usbmuxd_events_unsubscribe(usbmuxdctx))) return ret;
|
||||
if ((ret = irecv_device_event_unsubscribe(irecvctx))) return ret;
|
||||
irecvctx = NULL;
|
||||
usbmuxdctx = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -117,15 +119,15 @@ int devinfo_cmd(devinfo_t *dev, const char *udid)
|
||||
}
|
||||
if (lockdownd_client_new(device, &lockdown, "palera1n") != LOCKDOWN_E_SUCCESS)
|
||||
{
|
||||
idevice_free(device);
|
||||
(void)idevice_free(device);
|
||||
LOG(LOG_ERROR, "Device is not in normal mode.");
|
||||
return -1;
|
||||
}
|
||||
plist_t node = NULL;
|
||||
if (lockdownd_get_value(lockdown, NULL, "UniqueChipID", &node) != LOCKDOWN_E_SUCCESS)
|
||||
{
|
||||
lockdownd_client_free(lockdown);
|
||||
idevice_free(device);
|
||||
(void)lockdownd_client_free(lockdown);
|
||||
(void)idevice_free(device);
|
||||
LOG(LOG_ERROR, "Error getting ECID");
|
||||
return -1;
|
||||
}
|
||||
@@ -135,8 +137,8 @@ int devinfo_cmd(devinfo_t *dev, const char *udid)
|
||||
node = NULL;
|
||||
if (lockdownd_get_value(lockdown, NULL, "ProductType", &node) != LOCKDOWN_E_SUCCESS)
|
||||
{
|
||||
lockdownd_client_free(lockdown);
|
||||
idevice_free(device);
|
||||
(void)lockdownd_client_free(lockdown);
|
||||
(void)idevice_free(device);
|
||||
LOG(LOG_ERROR, "Error getting product type");
|
||||
return -1;
|
||||
}
|
||||
@@ -146,8 +148,8 @@ int devinfo_cmd(devinfo_t *dev, const char *udid)
|
||||
node = NULL;
|
||||
if (lockdownd_get_value(lockdown, NULL, "CPUArchitecture", &node) != LOCKDOWN_E_SUCCESS)
|
||||
{
|
||||
lockdownd_client_free(lockdown);
|
||||
idevice_free(device);
|
||||
(void)lockdownd_client_free(lockdown);
|
||||
(void)idevice_free(device);
|
||||
LOG(LOG_ERROR, "Error getting CPU type");
|
||||
return -1;
|
||||
}
|
||||
@@ -157,8 +159,8 @@ int devinfo_cmd(devinfo_t *dev, const char *udid)
|
||||
node = NULL;
|
||||
if (lockdownd_get_value(lockdown, NULL, "ProductVersion", &node) != LOCKDOWN_E_SUCCESS)
|
||||
{
|
||||
lockdownd_client_free(lockdown);
|
||||
idevice_free(device);
|
||||
(void)lockdownd_client_free(lockdown);
|
||||
(void)idevice_free(device);
|
||||
LOG(LOG_ERROR, "Error getting product version");
|
||||
return -1;
|
||||
}
|
||||
@@ -168,21 +170,21 @@ int devinfo_cmd(devinfo_t *dev, const char *udid)
|
||||
node = NULL;
|
||||
if (lockdownd_get_value(lockdown, NULL, "BuildVersion", &node) != LOCKDOWN_E_SUCCESS)
|
||||
{
|
||||
lockdownd_client_free(lockdown);
|
||||
idevice_free(device);
|
||||
(void)lockdownd_client_free(lockdown);
|
||||
(void)idevice_free(device);
|
||||
LOG(LOG_ERROR, "Error getting build version");
|
||||
return -1;
|
||||
}
|
||||
plist_get_string_val(node, &buildVersion);
|
||||
plist_free(node);
|
||||
lockdownd_client_free(lockdown);
|
||||
idevice_free(device);
|
||||
(void)lockdownd_client_free(lockdown);
|
||||
(void)idevice_free(device);
|
||||
|
||||
irecv_device_t rcvydev;
|
||||
if (irecv_devices_get_device_by_product_type(productType, &rcvydev) == IRECV_E_SUCCESS)
|
||||
{
|
||||
displayName = rcvydev->display_name;
|
||||
}
|
||||
else
|
||||
} else
|
||||
{
|
||||
displayName = productType;
|
||||
}
|
||||
@@ -207,23 +209,22 @@ int enter_recovery_cmd(const char* udid) {
|
||||
LOG(LOG_ERROR, "Could not connect to lockdownd: %s", lockdownd_strerror(ldret));
|
||||
return -1;
|
||||
}
|
||||
do {
|
||||
ldret = lockdownd_enter_recovery(lockdown);
|
||||
if (ldret == LOCKDOWN_E_SESSION_INACTIVE) {
|
||||
lockdownd_client_free(lockdown);
|
||||
lockdown = NULL;
|
||||
if (LOCKDOWN_E_SUCCESS != (ldret = lockdownd_client_new_with_handshake(device, &lockdown, "palera1n"))) {
|
||||
LOG(LOG_ERROR, "Could not connect to lockdownd: %s", lockdownd_strerror(ldret));
|
||||
return -1;
|
||||
}
|
||||
ldret = lockdownd_enter_recovery(lockdown);
|
||||
}
|
||||
ldret = lockdownd_enter_recovery(lockdown);
|
||||
if (ldret == LOCKDOWN_E_SESSION_INACTIVE) {
|
||||
lockdownd_client_free(lockdown);
|
||||
lockdown = NULL;
|
||||
ldret = lockdownd_client_new_with_handshake(device, &lockdown, "palera1n");
|
||||
if (ldret != LOCKDOWN_E_SUCCESS) {
|
||||
LOG(LOG_ERROR, "Could not trigger entering recovery mode: %s", lockdownd_strerror(ldret));
|
||||
LOG(LOG_ERROR, "Could not connect to lockdownd: %s", lockdownd_strerror(ldret));
|
||||
return -1;
|
||||
}
|
||||
lockdownd_client_free(lockdown);
|
||||
} while (0);
|
||||
ldret = lockdownd_enter_recovery(lockdown);
|
||||
}
|
||||
if (ldret != LOCKDOWN_E_SUCCESS) {
|
||||
LOG(LOG_ERROR, "Could not trigger entering recovery mode: %s", lockdownd_strerror(ldret));
|
||||
return -1;
|
||||
}
|
||||
lockdownd_client_free(lockdown);
|
||||
idevice_free(device);
|
||||
return 0;
|
||||
}
|
||||
@@ -240,8 +241,8 @@ int reboot_cmd(const char* udid) {
|
||||
if (diagnostics_relay_restart(diag, DIAGNOSTICS_RELAY_ACTION_FLAG_WAIT_FOR_DISCONNECT) != DIAGNOSTICS_RELAY_E_SUCCESS) {
|
||||
LOG(LOG_ERROR, "Could not reboot device.");
|
||||
}
|
||||
diagnostics_relay_goodbye(diag);
|
||||
diagnostics_relay_client_free(diag);
|
||||
(void)diagnostics_relay_goodbye(diag);
|
||||
(void)diagnostics_relay_client_free(diag);
|
||||
} else {
|
||||
LOG(LOG_ERROR, "Could not connect to device.");
|
||||
return -1;
|
||||
@@ -300,9 +301,9 @@ int passstat_cmd(unsigned char* status, const char* udid) {
|
||||
derr = diagnostics_relay_query_mobilegestalt(diagnostics_client, keys, &node);
|
||||
|
||||
plist_free(keys);
|
||||
diagnostics_relay_client_free(diagnostics_client);
|
||||
lockdownd_service_descriptor_free(service);
|
||||
idevice_free(dev);
|
||||
(void)diagnostics_relay_client_free(diagnostics_client);
|
||||
(void)lockdownd_service_descriptor_free(service);
|
||||
(void)idevice_free(dev);
|
||||
|
||||
if (derr != DIAGNOSTICS_RELAY_E_SUCCESS || !node)
|
||||
{
|
||||
@@ -320,7 +321,7 @@ int passstat_cmd(unsigned char* status, const char* udid) {
|
||||
plist_get_string_val(status_node, &passstat_status);
|
||||
if (!status || strncmp(passstat_status, "Succ", 4))
|
||||
{
|
||||
if (passstat_status)
|
||||
if (passstat_status)
|
||||
free(passstat_status);
|
||||
passstat_status = NULL;
|
||||
plist_free(node);
|
||||
@@ -347,20 +348,16 @@ int passstat_cmd(unsigned char* status, const char* udid) {
|
||||
int recvinfo_cmd(recvinfo_t* info, const uint64_t ecid) {
|
||||
irecv_client_t client = NULL;
|
||||
irecv_error_t err = irecv_open_with_ecid(&client, ecid);
|
||||
if (err != IRECV_E_SUCCESS) {
|
||||
LOG(LOG_ERROR, "libirecovery error: %d (%s)", err, irecv_strerror(err));
|
||||
return -1;
|
||||
}
|
||||
if (err != IRECV_E_SUCCESS) goto err;
|
||||
int mode = 0;
|
||||
irecv_get_mode(client, &mode);
|
||||
err = irecv_get_mode(client, &mode);
|
||||
if (err != IRECV_E_SUCCESS) goto err;
|
||||
char *ibootver = NULL;
|
||||
irecv_getenv(client, "build-version", &ibootver);
|
||||
err = irecv_getenv(client, "build-version", &ibootver);
|
||||
if (err != IRECV_E_SUCCESS) goto err;
|
||||
irecv_device_t device;
|
||||
err = irecv_devices_get_device_by_client(client, &device);
|
||||
if (err != IRECV_E_SUCCESS) {
|
||||
LOG(LOG_ERROR, "libirecovery error: %d (%s)", err, irecv_strerror(err));
|
||||
return -1;
|
||||
}
|
||||
if (err != IRECV_E_SUCCESS) goto err;
|
||||
info->mode = mode;
|
||||
info->cpid = device->chip_id;
|
||||
snprintf(info->product_type, 0x20, "%s", device->product_type);
|
||||
@@ -369,33 +366,41 @@ int recvinfo_cmd(recvinfo_t* info, const uint64_t ecid) {
|
||||
free(ibootver);
|
||||
irecv_close(client);
|
||||
return 0;
|
||||
err:
|
||||
LOG(LOG_ERROR, "libirecovery error: %d (%s)", err, irecv_strerror(err));
|
||||
return -1;
|
||||
}
|
||||
|
||||
int autoboot_cmd(const uint64_t ecid) {
|
||||
irecv_client_t client = NULL;
|
||||
irecv_error_t err = irecv_open_with_ecid(&client, ecid);
|
||||
if (err == IRECV_E_SUCCESS) {
|
||||
irecv_setenv(client, "auto-boot", "true");
|
||||
irecv_saveenv(client);
|
||||
irecv_close(client);
|
||||
return 0;
|
||||
} else {
|
||||
LOG(LOG_ERROR, "libirecovery error: %d (%s)", err, irecv_strerror(err));
|
||||
if (err != IRECV_E_SUCCESS) goto err;
|
||||
err = irecv_setenv(client, "auto-boot", "true");
|
||||
if (err != IRECV_E_SUCCESS) goto err;
|
||||
err = irecv_saveenv(client);
|
||||
if (err != IRECV_E_SUCCESS) goto err;
|
||||
err = irecv_close(client);
|
||||
if (err != IRECV_E_SUCCESS) goto err;
|
||||
return 0;
|
||||
err:
|
||||
LOG(LOG_ERROR, "libirecovery error: %d (%s)", err, irecv_strerror(err));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int exitrecv_cmd(const uint64_t ecid) {
|
||||
irecv_client_t client = NULL;
|
||||
irecv_error_t err = irecv_open_with_ecid(&client, ecid);
|
||||
if (err == IRECV_E_SUCCESS) {
|
||||
irecv_setenv(client, "auto-boot", "true");
|
||||
irecv_saveenv(client);
|
||||
irecv_reboot(client);
|
||||
irecv_close(client);
|
||||
return 0;
|
||||
} else {
|
||||
LOG(LOG_ERROR, "libirecovery error: %d (%s)", err, irecv_strerror(err));
|
||||
return -1;
|
||||
}
|
||||
if (err != IRECV_E_SUCCESS) goto err;
|
||||
err = irecv_setenv(client, "auto-boot", "true");
|
||||
if (err != IRECV_E_SUCCESS) goto err;
|
||||
err = irecv_saveenv(client);
|
||||
if (err != IRECV_E_SUCCESS) goto err;
|
||||
err = irecv_reboot(client);
|
||||
if (err != IRECV_E_SUCCESS) goto err;
|
||||
err = irecv_close(client);
|
||||
if (err != IRECV_E_SUCCESS) goto err;
|
||||
return 0;
|
||||
err:
|
||||
LOG(LOG_ERROR, "libirecovery error: %d (%s)", err, irecv_strerror(err));
|
||||
return -1;
|
||||
}
|
||||
+135
-51
@@ -8,11 +8,16 @@
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef WIN
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/select.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
@@ -36,12 +41,20 @@ int dfuhelper_thr_running = false;
|
||||
|
||||
void step(int time, int time2, char *text, bool (*cond)(uint64_t), uint64_t cond_arg) {
|
||||
for (int i = time2; i < time; i++) {
|
||||
printf(CYN "\r\033[K%s (%d)" CRESET, text, time - i + time2);
|
||||
printf(
|
||||
(palerain_flags & palerain_option_no_colors)
|
||||
? "\r\033[K%s (%d)"
|
||||
: BCYN "\r\033[K%s (%d)" CRESET, text, time - i + time2
|
||||
);
|
||||
fflush(stdout);
|
||||
sleep(1);
|
||||
if (cond != NULL && cond(cond_arg)) pthread_exit(NULL);
|
||||
}
|
||||
printf(CYN "\r%s (%d)" CRESET, text, time2);
|
||||
printf(
|
||||
(palerain_flags & palerain_option_no_colors)
|
||||
? "\r%s (%d)"
|
||||
: CYN "\r%s (%d)" CRESET, text, time2
|
||||
);
|
||||
if (time2 == 0) puts("");
|
||||
}
|
||||
|
||||
@@ -53,13 +66,15 @@ int connected_normal_mode(const usbmuxd_device_info_t *usbmuxd_device) {
|
||||
LOG(LOG_ERROR, "Unable to get device information");
|
||||
return 0;
|
||||
}
|
||||
if (strcmp(dev.CPUArchitecture, "arm64")) {
|
||||
if (strncmp(dev.CPUArchitecture, "arm64", strlen("arm64"))) {
|
||||
devinfo_free(&dev);
|
||||
LOG(LOG_WARNING, "Ignoring non-arm64 device...");
|
||||
LOG(LOG_WARNING, "palera1n doesn't and never will work on A12+ (arm64e)");
|
||||
return -1;
|
||||
}
|
||||
if (!strncmp(dev.productType, "iPhone10,", strlen("iPhone10,"))) {
|
||||
LOG(LOG_VERBOSE2, "Product %s requires passcode to be disabled", dev.productType);
|
||||
if (!(palerain_flags & palerain_option_device_info))
|
||||
LOG(LOG_VERBOSE2, "Product %s requires passcode to be disabled", dev.productType);
|
||||
unsigned char passcode_state = 0;
|
||||
ret = passstat_cmd(&passcode_state, usbmuxd_device->udid);
|
||||
if (ret != 0) {
|
||||
@@ -69,15 +84,35 @@ int connected_normal_mode(const usbmuxd_device_info_t *usbmuxd_device) {
|
||||
}
|
||||
if (passcode_state) {
|
||||
LOG(LOG_ERROR, "Passcode must be disabled on this device");
|
||||
LOG(LOG_ERROR, "Additionally, passcode must never be set since restore on iOS 16+");
|
||||
if (!(palerain_flags & palerain_option_device_info))
|
||||
LOG(LOG_ERROR, "Additionally, passcode must never be set since a restore on iOS 16+");
|
||||
devinfo_free(&dev);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
LOG(LOG_INFO, "Telling device with udid %s to enter recovery mode immediately", usbmuxd_device->udid);
|
||||
|
||||
if ((palerain_flags & palerain_option_device_info)) {
|
||||
printf("Mode: normal\n");
|
||||
printf("ProductType: %s\n", dev.productType);
|
||||
printf("Architecture: %s\n", dev.CPUArchitecture);
|
||||
printf("Version: %s\n", dev.productVersion);
|
||||
printf("DisplayName: %s\n", dev.displayName);
|
||||
|
||||
device_has_booted = true;
|
||||
set_spin(0);
|
||||
unsubscribe_cmd();
|
||||
return 0;
|
||||
}
|
||||
if (verbose > 1) {
|
||||
/* (LOG_VERBOSE - 3) or below*/
|
||||
LOG(LOG_INFO, "Telling device with udid %s to enter recovery mode immediately", usbmuxd_device->udid);
|
||||
} else {
|
||||
/* At least (LOG_VERBOSE2 - 3) */
|
||||
LOG(LOG_INFO, "Entering recovery mode");
|
||||
}
|
||||
enter_recovery_cmd(usbmuxd_device->udid);
|
||||
devinfo_free(&dev);
|
||||
if (checkrain_option_enabled(host_flags, host_option_enter_recovery)) {
|
||||
if ((palerain_flags & palerain_option_enter_recovery)) {
|
||||
device_has_booted = true;
|
||||
set_spin(0);
|
||||
unsubscribe_cmd();
|
||||
@@ -96,12 +131,13 @@ void* connected_recovery_mode(struct irecv_device_info* info) {
|
||||
cpid = info->cpid;
|
||||
ecid = info->ecid;
|
||||
bdid = info->bdid;
|
||||
if (!cpid_is_arm64(info->cpid)) {
|
||||
info = NULL;
|
||||
if (!cpid_is_arm64(cpid)) {
|
||||
LOG(LOG_WARNING, "Ignoring non-arm64 device...");
|
||||
return NULL;
|
||||
}
|
||||
sleep(1);
|
||||
ret = autoboot_cmd(info->ecid);
|
||||
ret = autoboot_cmd(ecid);
|
||||
if (ret) {
|
||||
LOG(LOG_ERROR, "Cannot set auto-boot back to true");
|
||||
return NULL;
|
||||
@@ -113,26 +149,22 @@ void* connected_recovery_mode(struct irecv_device_info* info) {
|
||||
step(4, 2, "Hold volume down + side button", NULL, 0);
|
||||
else
|
||||
step(4, 2, "Hold home + power button", NULL, 0);
|
||||
set_ecid_wait_for_dfu(info->ecid);
|
||||
ret = exitrecv_cmd(info->ecid);
|
||||
info = NULL;
|
||||
set_ecid_wait_for_dfu(ecid);
|
||||
ret = exitrecv_cmd(ecid);
|
||||
if (ret) {
|
||||
LOG(LOG_ERROR, "Cannot exit recovery mode");
|
||||
set_ecid_wait_for_dfu(0);
|
||||
return NULL;
|
||||
}
|
||||
printf("\r\033[K");
|
||||
bool nohome = NOHOME;
|
||||
if (nohome)
|
||||
if (NOHOME) {
|
||||
step(2, 0, "Hold volume down + side button", NULL, 0);
|
||||
else
|
||||
step(2, 0, "Hold home + power Button", NULL, 0);
|
||||
if (nohome)
|
||||
step(10, 0, "Hold volume down button", conditional, ecid);
|
||||
else
|
||||
step(10, 0, "Hold home button", conditional, ecid);
|
||||
if (get_ecid_wait_for_dfu() != ecid) {
|
||||
} else {
|
||||
step(2, 0, "Hold home + power button", NULL, 0);
|
||||
step(10, 0, "Hold home button", conditional, ecid);
|
||||
}
|
||||
if (get_ecid_wait_for_dfu() == ecid) {
|
||||
LOG(LOG_WARNING, "Whoops, device did not enter DFU mode");
|
||||
LOG(LOG_INFO, "Waiting for device to reconnect...");
|
||||
set_ecid_wait_for_dfu(0);
|
||||
@@ -160,13 +192,15 @@ void device_event_cb(const usbmuxd_event_t *event, void* userdata) {
|
||||
switch (event->event) {
|
||||
case UE_DEVICE_ADD:
|
||||
LOG(LOG_VERBOSE, "Normal mode device connected");
|
||||
if (checkrain_option_enabled(host_flags, host_option_exit_recovery)) {
|
||||
if ((palerain_flags & palerain_option_exit_recovery)) {
|
||||
break;
|
||||
} else if (checkrain_option_enabled(host_flags, host_option_reboot_device)) {
|
||||
reboot_cmd(event->device.udid);
|
||||
LOG(LOG_INFO, "Restarted device");
|
||||
set_spin(0);
|
||||
unsubscribe_cmd();
|
||||
} else if ((palerain_flags & palerain_option_reboot_device)) {
|
||||
int ret = reboot_cmd(event->device.udid);
|
||||
if (!ret) {
|
||||
LOG(LOG_INFO, "Restarted device");
|
||||
set_spin(0);
|
||||
unsubscribe_cmd();
|
||||
}
|
||||
pthread_exit(NULL);
|
||||
break;
|
||||
}
|
||||
@@ -180,35 +214,85 @@ void device_event_cb(const usbmuxd_event_t *event, void* userdata) {
|
||||
|
||||
void irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) {
|
||||
pthread_t recovery_thread, dfu_thread;
|
||||
int ret;
|
||||
|
||||
switch(event->type) {
|
||||
case IRECV_DEVICE_ADD:
|
||||
if (event->mode == IRECV_K_RECOVERY_MODE_1 || event->mode == IRECV_K_RECOVERY_MODE_2 || event->mode == IRECV_K_RECOVERY_MODE_3 || event->mode == IRECV_K_RECOVERY_MODE_4) {
|
||||
LOG(LOG_VERBOSE, "Recovery mode device %ld connected", event->device_info->ecid);
|
||||
if (checkrain_option_enabled(host_flags, host_option_exit_recovery)) {
|
||||
exitrecv_cmd(event->device_info->ecid);
|
||||
LOG(LOG_INFO, "Exited recovery mode");
|
||||
device_has_booted = true;
|
||||
set_spin(0);
|
||||
unsubscribe_cmd();
|
||||
if (dfuhelper_thr_running) pthread_cancel(dfuhelper_thread);
|
||||
pthread_exit(NULL);
|
||||
break;
|
||||
}
|
||||
if (checkrain_option_enabled(host_flags, host_option_enter_recovery) ||
|
||||
checkrain_option_enabled(host_flags, host_option_reboot_device)) return;
|
||||
pthread_create(&recovery_thread, NULL, (void* (*)(void*))connected_recovery_mode, event->device_info);
|
||||
} else if (event->mode == IRECV_K_DFU_MODE) {
|
||||
LOG(LOG_VERBOSE, "DFU mode device %ld connected", event->device_info->ecid);
|
||||
if (
|
||||
checkrain_option_enabled(host_flags, host_option_exit_recovery) ||
|
||||
checkrain_option_enabled(host_flags, host_option_enter_recovery) ||
|
||||
checkrain_option_enabled(host_flags, host_option_reboot_device)) {
|
||||
if (event->mode == IRECV_K_RECOVERY_MODE_1 ||
|
||||
event->mode == IRECV_K_RECOVERY_MODE_2 ||
|
||||
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);
|
||||
if ((palerain_flags & palerain_option_exit_recovery)) {
|
||||
ret = exitrecv_cmd(event->device_info->ecid);
|
||||
if (!ret) {
|
||||
LOG(LOG_INFO, "Exited recovery mode");
|
||||
device_has_booted = true;
|
||||
set_spin(0);
|
||||
unsubscribe_cmd();
|
||||
} else {
|
||||
LOG(LOG_WARNING, "Could not exit recovery mode");
|
||||
}
|
||||
if (dfuhelper_thr_running) pthread_cancel(dfuhelper_thread);
|
||||
pthread_exit(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((palerain_flags & palerain_option_device_info)) {
|
||||
recvinfo_t info;
|
||||
ret = recvinfo_cmd(&info, event->device_info->ecid);
|
||||
if (ret) {
|
||||
LOG(LOG_WARNING, "Could not get info from device");
|
||||
} else {
|
||||
printf("Mode: Recovery\n");
|
||||
printf("ProductType: %s\n", info.product_type);
|
||||
printf("DisplayName: %s\n", info.display_name);
|
||||
|
||||
device_has_booted = true;
|
||||
set_spin(0);
|
||||
unsubscribe_cmd();
|
||||
}
|
||||
if (dfuhelper_thr_running) pthread_cancel(dfuhelper_thread);
|
||||
pthread_exit(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((palerain_flags & palerain_option_enter_recovery) ||
|
||||
(palerain_flags & palerain_option_reboot_device)) return;
|
||||
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);
|
||||
|
||||
if ((palerain_flags & palerain_option_device_info)) {
|
||||
recvinfo_t info;
|
||||
ret = recvinfo_cmd(&info, event->device_info->ecid);
|
||||
if (ret) {
|
||||
LOG(LOG_WARNING, "Could not get info from device");
|
||||
} else {
|
||||
printf("Mode: DFU\n");
|
||||
printf("ProductType: %s\n", info.product_type);
|
||||
printf("DisplayName: %s\n", info.display_name);
|
||||
|
||||
device_has_booted = true;
|
||||
set_spin(0);
|
||||
unsubscribe_cmd();
|
||||
}
|
||||
if (dfuhelper_thr_running) pthread_cancel(dfuhelper_thread);
|
||||
pthread_exit(NULL);
|
||||
break;
|
||||
}
|
||||
|
||||
if (
|
||||
(palerain_flags & palerain_option_exit_recovery) ||
|
||||
(palerain_flags & palerain_option_enter_recovery) ||
|
||||
(palerain_flags & palerain_option_reboot_device)) {
|
||||
break;
|
||||
}
|
||||
pthread_create(&dfu_thread, NULL, (pthread_start_t)connected_dfu_mode, event->device_info);
|
||||
}
|
||||
pthread_create(&dfu_thread, NULL, (void* (*)(void*))connected_dfu_mode, event->device_info);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case IRECV_DEVICE_REMOVE:
|
||||
LOG(LOG_VERBOSE, "Recovery mode device disconnected");
|
||||
break;
|
||||
@@ -217,8 +301,8 @@ void irecv_device_event_cb(const irecv_device_event_t *event, void* userdata) {
|
||||
|
||||
void *dfuhelper(void* ptr) {
|
||||
dfuhelper_thr_running = true;
|
||||
subscribe_cmd(device_event_cb, irecv_device_event_cb);
|
||||
set_spin(1);
|
||||
subscribe_cmd(device_event_cb, irecv_device_event_cb);
|
||||
while (get_spin()) {
|
||||
sleep(1);
|
||||
};
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <unistd.h>
|
||||
#include <spawn.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
extern char **environ;
|
||||
|
||||
#include <palerain.h>
|
||||
#include <xxd-embedded.h>
|
||||
char* pongo_path = NULL;
|
||||
char* ext_checkra1n = NULL;
|
||||
|
||||
#define tmpdir getenv("TMPDIR") == NULL ? "/tmp" : getenv("TMPDIR")
|
||||
|
||||
int exec_checkra1n() {
|
||||
LOG(LOG_INFO, "About to execute checkra1n");
|
||||
int fd, ret;
|
||||
char* checkra1n_path = NULL;
|
||||
if (ext_checkra1n != NULL) {
|
||||
checkra1n_path = ext_checkra1n;
|
||||
goto checkra1n_exec;
|
||||
}
|
||||
checkra1n_path = malloc(strlen(tmpdir) + 20);
|
||||
snprintf(checkra1n_path, strlen(tmpdir) + 20, "%s/checkra1n.XXXXXX", tmpdir);
|
||||
fd = mkstemp(checkra1n_path);
|
||||
if (fd == -1) {
|
||||
LOG(LOG_FATAL, "Cannot open temporary file: %d (%s)", errno, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
ssize_t didWrite = write(fd, checkra1n, checkra1n_len);
|
||||
if (didWrite != (ssize_t)checkra1n_len) {
|
||||
LOG(LOG_FATAL, "Size written does not match expected: %lld != %d: %d (%s)", didWrite, checkra1n_len, errno, strerror(errno));
|
||||
close(fd);
|
||||
unlink(checkra1n_path);
|
||||
return -1;
|
||||
}
|
||||
close(fd);
|
||||
ret = chmod(checkra1n_path, 0700);
|
||||
if (ret) {
|
||||
LOG(LOG_FATAL, "Cannot chmod %s: %d (%s)", checkra1n_path, errno, strerror(errno));
|
||||
unlink(checkra1n_path);
|
||||
return -1;
|
||||
}
|
||||
checkra1n_exec: {};
|
||||
char args[0x10] = "-pE";
|
||||
if (checkrain_option_enabled(host_flags, host_option_demote)) strncat(args, "d", 0xf);
|
||||
if (verbose >= 2) strncat(args, "v", 0xf);
|
||||
if (pongo_path != NULL) strncat(args, "k", 0xf); // keep this at last
|
||||
pid_t pid;
|
||||
char* checkra1n_argv[] = {
|
||||
checkra1n_path,
|
||||
args,
|
||||
pongo_path,
|
||||
NULL
|
||||
};
|
||||
ret = posix_spawn(&pid, checkra1n_path, NULL, NULL, checkra1n_argv, environ);
|
||||
if (pongo_path != NULL) free(pongo_path);
|
||||
pongo_path = NULL;
|
||||
if (ret) {
|
||||
LOG(LOG_FATAL, "Cannot posix spawn %s: %d (%s)", checkra1n_path, errno, strerror(errno));
|
||||
if (ext_checkra1n != NULL) unlink(checkra1n_path);
|
||||
return -1;
|
||||
}
|
||||
LOG(LOG_VERBOSE2, "%s spawned successfully", checkra1n_path);
|
||||
sleep(2);
|
||||
if (ext_checkra1n == NULL) {
|
||||
unlink(checkra1n_path);
|
||||
free(checkra1n_path);
|
||||
checkra1n_path = NULL;
|
||||
}
|
||||
waitpid(pid, NULL, 0);
|
||||
return 0;
|
||||
}
|
||||
+1
-6
@@ -10,12 +10,7 @@ unsigned char* ramdisk_dmg = NULL;
|
||||
unsigned int ramdisk_dmg_len = 0;
|
||||
#endif
|
||||
|
||||
#ifdef NO_CHECKRAIN
|
||||
unsigned char* checkra1n = NULL;
|
||||
unsigned int checkra1n_len = 0;
|
||||
#endif
|
||||
|
||||
#ifdef NO_BINPACK
|
||||
#ifdef NO_OVERLAY
|
||||
unsigned char* binpack_dmg = NULL;
|
||||
unsigned int binpack_dmg_len = 0;
|
||||
#endif
|
||||
+34
-33
@@ -9,17 +9,22 @@
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef WIN
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/select.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <spawn.h>
|
||||
#include <sys/mman.h>
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#include <pthread.h>
|
||||
#include <inttypes.h>
|
||||
#include <getopt.h>
|
||||
#include <errno.h>
|
||||
#include <spawn.h>
|
||||
#include <sys/mman.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <libimobiledevice/libimobiledevice.h>
|
||||
@@ -27,10 +32,10 @@
|
||||
#include <ANSI-color-codes.h>
|
||||
#include <palerain.h>
|
||||
#include <xxd-embedded.h>
|
||||
#include <kerninfo.h>
|
||||
#include <paleinfo.h>
|
||||
|
||||
pthread_mutex_t spin_mutex, found_pongo_mutex, ecid_dfu_wait_mutex;
|
||||
#ifdef DEV_BUILD
|
||||
#ifdef TUI
|
||||
#include <newt.h>
|
||||
pthread_mutex_t tui_log_mutex;
|
||||
newtComponent tui_log_output = NULL;
|
||||
@@ -39,43 +44,39 @@ newtComponent tui_log_output = NULL;
|
||||
bool spin, found_pongo = 0;
|
||||
uint64_t ecid_wait_for_dfu = 0;
|
||||
|
||||
bool get_spin() {
|
||||
LOG(LOG_VERBOSE5, "locking spin mutex for get");
|
||||
pthread_mutex_lock(&spin_mutex);
|
||||
bool ret = spin;
|
||||
LOG(LOG_VERBOSE5, "UN-locking spin mutex, spin value is %d", spin);
|
||||
pthread_mutex_unlock(&spin_mutex);
|
||||
static bool get_locked_bool(bool* val, pthread_mutex_t* mutex) {
|
||||
// fprintf(stderr, "%s: val = %p mutex = %p\n", __func__, (void*)val, (void*)mutex);
|
||||
pthread_mutex_lock(mutex);
|
||||
bool ret = *val;
|
||||
pthread_mutex_unlock(mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool set_spin(bool val) {
|
||||
LOG(LOG_VERBOSE5, "locking spin mutex for set spin = %d", val);
|
||||
pthread_mutex_lock(&spin_mutex);
|
||||
spin = val;
|
||||
LOG(LOG_VERBOSE5, "UN-locking spin mutex after setting spin\n");
|
||||
pthread_mutex_unlock(&spin_mutex);
|
||||
return val;
|
||||
static bool set_locked_bool(bool* val, bool newval, pthread_mutex_t* mutex) {
|
||||
// fprintf(stderr, "%s: val = %p mutex = %p, newval = %d\n", __func__, (void*)val, (void*)mutex, newval);
|
||||
pthread_mutex_lock(mutex);
|
||||
*val = newval;
|
||||
pthread_mutex_unlock(mutex);
|
||||
return newval;
|
||||
}
|
||||
|
||||
bool get_found_pongo() {
|
||||
LOG(LOG_VERBOSE5, "locking found pongo mutex for get");
|
||||
pthread_mutex_lock(&found_pongo_mutex);
|
||||
bool ret = found_pongo;
|
||||
LOG(LOG_VERBOSE5, "UN-locking pongo mutex, found_pongo value is %d", found_pongo);
|
||||
pthread_mutex_unlock(&found_pongo_mutex);
|
||||
return ret;
|
||||
bool get_spin(void) {
|
||||
return get_locked_bool(&spin, &spin_mutex);
|
||||
}
|
||||
|
||||
bool set_spin(bool newval) {
|
||||
return set_locked_bool(&spin, newval, &spin_mutex);
|
||||
}
|
||||
|
||||
bool get_found_pongo(void) {
|
||||
return get_locked_bool(&found_pongo, &found_pongo_mutex);
|
||||
}
|
||||
|
||||
bool set_found_pongo(bool val) {
|
||||
LOG(LOG_VERBOSE5, "locking found pongo mutex for set found_pongo = %d", val);
|
||||
pthread_mutex_lock(&found_pongo_mutex);
|
||||
found_pongo = val;
|
||||
LOG(LOG_VERBOSE5, "UN-locking pongo mutex after setting found_pongo");
|
||||
pthread_mutex_unlock(&found_pongo_mutex);
|
||||
return val;
|
||||
return set_locked_bool(&found_pongo, val, &found_pongo_mutex);
|
||||
}
|
||||
|
||||
uint64_t get_ecid_wait_for_dfu() {
|
||||
uint64_t get_ecid_wait_for_dfu(void) {
|
||||
LOG(LOG_VERBOSE5, "locking ecid wait for dfu mutex for get");
|
||||
pthread_mutex_lock(&ecid_dfu_wait_mutex);
|
||||
uint64_t ret = ecid_wait_for_dfu;
|
||||
@@ -93,8 +94,8 @@ uint64_t set_ecid_wait_for_dfu(uint64_t ecid) {
|
||||
return ecid;
|
||||
}
|
||||
|
||||
#ifdef DEV_BUILD
|
||||
newtComponent get_tui_log() {
|
||||
#ifdef TUI
|
||||
newtComponent get_tui_log(void) {
|
||||
pthread_mutex_lock(&tui_log_mutex);
|
||||
newtComponent ret = tui_log_output;
|
||||
pthread_mutex_unlock(&tui_log_mutex);
|
||||
|
||||
+15
-20
@@ -1,7 +1,12 @@
|
||||
#ifndef HAVE_LIBIMOBILEDEVICE
|
||||
#include "lockdown_helper.h"
|
||||
#include <usbmuxd.h>
|
||||
#ifdef WIN
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@@ -11,22 +16,19 @@
|
||||
#ifdef DEBUG
|
||||
#define log_debug(...) fprintf(stderr, __VA_ARGS__); fputc('\n', stderr)
|
||||
#else
|
||||
#define log_debug(...)
|
||||
#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 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;
|
||||
}
|
||||
return fd;
|
||||
}
|
||||
|
||||
int lockdown_connect_udid(const char* udid)
|
||||
{
|
||||
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);
|
||||
@@ -35,8 +37,7 @@ int lockdown_connect_udid(const char* udid)
|
||||
return lockdown_connect_handle(device.handle);
|
||||
}
|
||||
|
||||
void lockdown_disconnect(int fd)
|
||||
{
|
||||
void lockdown_disconnect(int fd) {
|
||||
usbmuxd_disconnect(fd);
|
||||
}
|
||||
|
||||
@@ -56,8 +57,7 @@ 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)
|
||||
{
|
||||
static void skip_ws(char** cur, char* end) {
|
||||
char* p = *cur;
|
||||
while (p < end && ((*p == ' ') || (*p == '\t') || (*p == '\r') || (*p == '\n'))) {
|
||||
p++;
|
||||
@@ -65,8 +65,7 @@ static void skip_ws(char** cur, char* end)
|
||||
*cur = p;
|
||||
}
|
||||
|
||||
static char* _send_request_and_get_reply(int fd, const char* request, uint32_t len, uint32_t* received)
|
||||
{
|
||||
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) {
|
||||
@@ -100,8 +99,7 @@ static char* _send_request_and_get_reply(int fd, const char* request, uint32_t l
|
||||
return resp;
|
||||
}
|
||||
|
||||
int lockdown_check_type(int fd, const char* type_match)
|
||||
{
|
||||
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);
|
||||
@@ -119,8 +117,7 @@ int lockdown_check_type(int fd, const char* type_match)
|
||||
return result;
|
||||
}
|
||||
|
||||
int lockdown_get_uint_value(int fd, const char* domain, const char* key, uint64_t* value)
|
||||
{
|
||||
int lockdown_get_uint_value(int fd, const char* domain, const char* key, uint64_t* value) {
|
||||
char tmp[1024];
|
||||
uint32_t len;
|
||||
if (domain) {
|
||||
@@ -159,8 +156,7 @@ int lockdown_get_uint_value(int fd, const char* domain, const char* key, uint64_
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lockdown_get_string_value(int fd, const char* domain, const char* key, char** value)
|
||||
{
|
||||
int lockdown_get_string_value(int fd, const char* domain, const char* key, char** value) {
|
||||
char tmp[1024];
|
||||
uint32_t len;
|
||||
if (domain) {
|
||||
@@ -212,8 +208,7 @@ int lockdown_get_string_value(int fd, const char* domain, const char* key, char*
|
||||
return 0;
|
||||
}
|
||||
|
||||
int lockdown_enter_recovery(int fd)
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
#include <ANSI-color-codes.h>
|
||||
#include <palerain.h>
|
||||
|
||||
int p1_log(log_level_t loglevel, const char *fname, int lineno, const char *fxname, char *__restrict format, ...)
|
||||
int p1_log(log_level_t loglevel, const char *fname, int lineno, const char *fxname, const char *__restrict format, ...)
|
||||
{
|
||||
if (verbose >= 5
|
||||
#ifdef DEV_BUILD
|
||||
&& !checkrain_option_enabled(host_flags, host_option_tui)
|
||||
#ifdef TUI
|
||||
&& !(palerain_flags & palerain_option_tui)
|
||||
#endif
|
||||
) fprintf(stderr, "p1_log: loglevel %d from %s:%d:%s()\n", loglevel, fname, lineno, fxname);
|
||||
int ret = 0;
|
||||
@@ -23,7 +23,7 @@ int p1_log(log_level_t loglevel, const char *fname, int lineno, const char *fxna
|
||||
va_start(args, format);
|
||||
if (verbose < (loglevel - 3) && loglevel > LOG_INFO) {
|
||||
if (verbose >= 5
|
||||
#ifdef DEV_BUILD
|
||||
#ifdef TUI
|
||||
&& !tui_started
|
||||
#endif
|
||||
) fprintf(stderr, "p1_log: hid log with high log level (%d < %d)\n", verbose, loglevel - 3);
|
||||
@@ -57,8 +57,12 @@ int p1_log(log_level_t loglevel, const char *fname, int lineno, const char *fxna
|
||||
snprintf(colour_bold, 0x10, "%s", BWHT);
|
||||
break;
|
||||
}
|
||||
#ifdef DEV_BUILD
|
||||
if (checkrain_option_enabled(host_flags, host_option_tui) && tui_started) {
|
||||
if ((palerain_flags & palerain_option_no_colors)) {
|
||||
colour[0] = '\0';
|
||||
colour_bold[0] = '\0';
|
||||
}
|
||||
#ifdef TUI
|
||||
if ((palerain_flags & palerain_option_tui) && tui_started) {
|
||||
newtComponent co = get_tui_log();
|
||||
if (co == NULL) {
|
||||
return 0; /* 0 bytes printed */
|
||||
@@ -75,20 +79,31 @@ int p1_log(log_level_t loglevel, const char *fname, int lineno, const char *fxna
|
||||
time_t curtime;
|
||||
time(&curtime);
|
||||
struct tm* timeinfo = localtime(&curtime);
|
||||
snprintf(timestring, 0x80, "%s[%s%02d/%02d/%d %02d:%02d:%02d%s]", CRESET, HBLK, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_year - 100, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, CRESET);
|
||||
if (verbose >= 2) {
|
||||
if (!(palerain_flags & palerain_option_no_colors))
|
||||
snprintf(timestring, 0x80, "%s[%s%02d/%02d/%d %02d:%02d:%02d%s]", CRESET, HBLK, timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_year - 100, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec, CRESET);
|
||||
else
|
||||
snprintf(timestring, 0x80, "[%02d/%02d/%d %02d:%02d:%02d]", timeinfo->tm_mon + 1, timeinfo->tm_mday, timeinfo->tm_year - 100, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
|
||||
if (verbose >= 2 && !(palerain_flags & palerain_option_no_colors)) {
|
||||
printf("%s| - %s%s <%s> " CRESET "%s" HBLU "%s" CRESET ":" BLU "%d" CRESET ":" BMAG "%s()" CRESET ": \n%s| ----> ", colour_bold, timestring, colour_bold, type, WHT, fname, lineno, fxname, colour_bold);
|
||||
} else {
|
||||
} else if (!(palerain_flags & palerain_option_no_colors)) {
|
||||
printf(" - %s %s<%s>%s: ", timestring, colour_bold, type, CRESET);
|
||||
} else if (verbose >= 2 && (palerain_flags & palerain_option_no_colors)) {
|
||||
printf("%s| - %s%s <%s> %s:%d:%s(): \n%s| ----> ", colour_bold, timestring, colour_bold, type, fname, lineno, fxname, colour_bold);
|
||||
} else if ((palerain_flags & palerain_option_no_colors)) {
|
||||
printf(" - %s %s<%s>: ", timestring, colour_bold, type);
|
||||
}
|
||||
printf("%s", colour);
|
||||
ret = vprintf(format, args);
|
||||
va_end(args);
|
||||
|
||||
if (verbose < 2)
|
||||
if (verbose < 2 && !(palerain_flags & palerain_option_no_colors))
|
||||
printf(CRESET "\n");
|
||||
else
|
||||
else if (!(palerain_flags & palerain_option_no_colors))
|
||||
printf("\n%s-%s\n", colour, CRESET);
|
||||
else if (verbose < 2)
|
||||
printf("\n");
|
||||
else
|
||||
printf("\n%s-\n", colour);
|
||||
fflush(stdout);
|
||||
}
|
||||
pthread_mutex_unlock(&log_mutex);
|
||||
|
||||
+2764
File diff suppressed because it is too large.
Load diff
+1637
File diff suppressed because it is too large.
Load diff
+60
-61
@@ -7,19 +7,24 @@
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef WIN
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/select.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <signal.h>
|
||||
#include <pthread.h>
|
||||
#include <inttypes.h>
|
||||
#include <getopt.h>
|
||||
#include <errno.h>
|
||||
#include <spawn.h>
|
||||
#include <sys/mman.h>
|
||||
#include <signal.h>
|
||||
#endif
|
||||
#include <pthread.h>
|
||||
#include <inttypes.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <libimobiledevice/libimobiledevice.h>
|
||||
@@ -27,14 +32,13 @@
|
||||
#include <ANSI-color-codes.h>
|
||||
#include <palerain.h>
|
||||
#include <xxd-embedded.h>
|
||||
#include <kerninfo.h>
|
||||
#include <paleinfo.h>
|
||||
|
||||
#define CMD_LEN_MAX 512
|
||||
#define OVERRIDE_MAGIC 0xd803b376
|
||||
|
||||
unsigned int verbose = 0;
|
||||
char xargs_cmd[0x270] = "xargs ", checkrain_flags_cmd[0x20] = "deadbeef", palerain_flags_cmd[0x20] = "deadbeef";
|
||||
char kpf_flags_cmd[0x20] = "deadbeef", dtpatch_cmd[0x20] = "deadbeef", rootfs_cmd[512] = "deadbeef";
|
||||
char xargs_cmd[0x270] = "xargs ", palerain_flags_cmd[0x30] = "deadbeef";
|
||||
extern char** environ;
|
||||
|
||||
niarelap_file_t* kpf_to_upload_1 = &checkra1n_kpf_pongo;
|
||||
@@ -47,7 +51,7 @@ niarelap_file_t** overlay_to_upload = &overlay_to_upload_1;
|
||||
|
||||
override_file_t override_ramdisk, override_kpf, override_overlay;
|
||||
|
||||
uint32_t checkrain_flags = 0, palerain_flags = 0, kpf_flags = 0;
|
||||
uint64_t palerain_flags = 0;
|
||||
|
||||
pthread_mutex_t log_mutex;
|
||||
pthread_t dfuhelper_thread, pongo_thread;
|
||||
@@ -56,27 +60,13 @@ void thr_cleanup(void* ptr) {
|
||||
*(int*)ptr = 0;
|
||||
}
|
||||
|
||||
int build_checks() {
|
||||
#if defined(__APPLE__)
|
||||
#ifndef NO_CHECKRAIN
|
||||
struct mach_header_64* c1_header = (struct mach_header_64*)&checkra1n[0];
|
||||
if (c1_header->magic != MH_MAGIC_64 && c1_header->magic != MH_CIGAM_64) {
|
||||
LOG(LOG_FATAL, "Broken build: checkra1n is not a thin Mach-O");
|
||||
return -1;
|
||||
}
|
||||
if (c1_header->cputype != _mh_execute_header.cputype) {
|
||||
LOG(LOG_FATAL, "Broken build: checkra1n CPU type does not match palera1n CPU type");
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
int build_checks(void) {
|
||||
#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) {
|
||||
} 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) {
|
||||
@@ -87,41 +77,67 @@ int build_checks() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef DEV_BUILD
|
||||
#ifdef TUI
|
||||
bool tui_started = false;
|
||||
#endif
|
||||
|
||||
#ifdef USE_LIBUSB
|
||||
void log_cb(libusb_context *ctx, enum libusb_log_level level, const char *str) {
|
||||
LOG(level + 0, str);
|
||||
}
|
||||
#endif
|
||||
|
||||
int palera1n(int argc, char *argv[]) {
|
||||
print_credits();
|
||||
int ret = 0;
|
||||
pthread_mutex_init(&log_mutex, NULL);
|
||||
pthread_mutex_init(&spin_mutex, NULL);
|
||||
pthread_mutex_init(&found_pongo_mutex, NULL);
|
||||
pthread_mutex_init(&ecid_dfu_wait_mutex, NULL);
|
||||
if ((ret = build_checks())) return ret;
|
||||
print_credits();
|
||||
if ((ret = optparse(argc, argv))) goto cleanup;
|
||||
if (checkrain_option_enabled(host_flags, host_option_palerain_version)) goto normal_exit;
|
||||
#ifdef DEV_BUILD
|
||||
if (checkrain_option_enabled(host_flags, host_option_tui)) {
|
||||
if (!(palerain_flags & palerain_option_device_info) && (palerain_flags & palerain_option_palerain_version)) goto normal_exit;
|
||||
#ifdef TUI
|
||||
if ((palerain_flags & palerain_option_tui)) {
|
||||
ret = tui();
|
||||
if (ret) goto cleanup;
|
||||
else goto normal_exit;
|
||||
}
|
||||
#endif
|
||||
LOG(LOG_INFO, "Waiting for devices");
|
||||
#ifdef USE_LIBUSB
|
||||
{
|
||||
libusb_set_log_cb(NULL, log_cb, LIBUSB_LOG_CB_GLOBAL);
|
||||
libusb_context* ctx = NULL;
|
||||
int test_libusb = libusb_init(&ctx);
|
||||
if (test_libusb) {
|
||||
LOG(LOG_ERROR, "cannot initialize libusb: %d (%s)\n", test_libusb, libusb_strerror(test_libusb));
|
||||
libusb_exit(ctx);
|
||||
goto cleanup;
|
||||
}
|
||||
libusb_exit(ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!(palerain_flags & palerain_option_device_info))
|
||||
LOG(LOG_INFO, "Waiting for devices");
|
||||
|
||||
if (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);
|
||||
pthread_create(&dfuhelper_thread, NULL, dfuhelper, NULL);
|
||||
pthread_join(dfuhelper_thread, NULL);
|
||||
set_spin(0);
|
||||
if (checkrain_option_enabled(host_flags, host_option_dfuhelper_only) ||
|
||||
checkrain_option_enabled(host_flags, host_option_reboot_device) ||
|
||||
checkrain_option_enabled(host_flags, host_option_exit_recovery) ||
|
||||
checkrain_option_enabled(host_flags, host_option_enter_recovery) ||
|
||||
device_has_booted)
|
||||
if ((palerain_flags & (palerain_option_dfuhelper_only |
|
||||
palerain_option_reboot_device |
|
||||
palerain_option_exit_recovery |
|
||||
palerain_option_enter_recovery |
|
||||
palerain_option_device_info)
|
||||
) || device_has_booted)
|
||||
goto normal_exit;
|
||||
if (exec_checkra1n()) goto cleanup;
|
||||
if (exec_checkm8()) goto cleanup;
|
||||
|
||||
if (checkrain_option_enabled(host_flags, host_option_pongo_exit) || checkrain_option_enabled(host_flags, host_option_demote))
|
||||
if ((palerain_flags & (palerain_option_pongo_exit | palerain_option_demote)))
|
||||
goto normal_exit;
|
||||
set_spin(1);
|
||||
sleep(2);
|
||||
@@ -132,41 +148,25 @@ int palera1n(int argc, char *argv[]) {
|
||||
sleep(1);
|
||||
}
|
||||
normal_exit:
|
||||
if (access("/usr/bin/curl", F_OK) == 0 && !checkrain_option_enabled(host_flags, host_option_no_ohio)) {
|
||||
LOG(LOG_VERBOSE4, "Ohio");
|
||||
char* ohio_argv[] = {
|
||||
"/usr/bin/curl",
|
||||
"-sX",
|
||||
"POST",
|
||||
"-d",
|
||||
"{\"app_name\": \"palera1n_c-rewrite\"}",
|
||||
"-H",
|
||||
"Content-Type: application/json",
|
||||
"-H",
|
||||
"User-Agent: python-requests/99 palera1n-c-rewrite/0",
|
||||
"-o",
|
||||
"/dev/null",
|
||||
"https://ohio.itsnebula.net/hit",
|
||||
NULL
|
||||
};
|
||||
pid_t pid;
|
||||
posix_spawn(&pid, ohio_argv[0], NULL, NULL, ohio_argv, environ);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (override_kpf.magic == OVERRIDE_MAGIC) {
|
||||
#ifndef WIN
|
||||
munmap(override_kpf.ptr, (size_t)override_kpf.len);
|
||||
#endif
|
||||
close(override_kpf.fd);
|
||||
}
|
||||
if (override_ramdisk.magic == OVERRIDE_MAGIC) {
|
||||
#ifndef WIN
|
||||
munmap(override_ramdisk.ptr, (size_t)override_ramdisk.len);
|
||||
#endif
|
||||
close(override_ramdisk.fd);
|
||||
}
|
||||
if (override_overlay.magic == OVERRIDE_MAGIC) {
|
||||
#ifndef WIN
|
||||
munmap(override_overlay.ptr, (size_t)override_overlay.len);
|
||||
#endif
|
||||
close(override_overlay.fd);
|
||||
}
|
||||
if (ext_checkra1n != NULL) free(ext_checkra1n);
|
||||
pthread_mutex_destroy(&log_mutex);
|
||||
pthread_mutex_destroy(&spin_mutex);
|
||||
pthread_mutex_destroy(&found_pongo_mutex);
|
||||
@@ -174,7 +174,6 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char* argv[]) {
|
||||
return palera1n(argc, argv);
|
||||
}
|
||||
+107
-87
@@ -9,15 +9,21 @@
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <getopt.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include <palerain.h>
|
||||
#ifndef WIN
|
||||
#include <sys/mman.h>
|
||||
#endif
|
||||
#include <inttypes.h>
|
||||
|
||||
checkrain_option_t host_flags = 0;
|
||||
checkrain_option_p host_flags_p = &host_flags;
|
||||
uint64_t* palerain_flags_p = &palerain_flags;
|
||||
static bool force_use_verbose_boot = false;
|
||||
|
||||
static struct option longopts[] = {
|
||||
{"setup-partial-fakefs", no_argument, NULL, 'B'},
|
||||
{"setup-fakefs", no_argument, NULL, 'c'},
|
||||
{"setup-fakefs-forced", no_argument, NULL, 'C'},
|
||||
{"clean-fakefs", no_argument, NULL, 'c'},
|
||||
{"dfuhelper", no_argument, NULL, 'D'},
|
||||
{"help", no_argument, NULL, 'h'},
|
||||
{"pongo-shell", no_argument, NULL, 'p'},
|
||||
@@ -27,23 +33,24 @@ static struct option longopts[] = {
|
||||
{"boot-args", required_argument, NULL, 'e'},
|
||||
{"fakefs", no_argument, NULL, 'f'},
|
||||
{"rootless", no_argument, NULL, 'l'},
|
||||
{"jbinit-log-to-file", no_argument, NULL, 'L'},
|
||||
{"demote", no_argument, NULL, 'd'},
|
||||
{"force-revert", no_argument, NULL, palerain_option_case_force_revert},
|
||||
{"no-colors", no_argument, NULL, 'S'},
|
||||
{"safe-mode", no_argument, NULL, 's'},
|
||||
{"version", no_argument, NULL, palerain_option_case_version},
|
||||
{"override-pongo", required_argument, NULL, 'k'},
|
||||
{"override-overlay", required_argument, NULL, 'o'},
|
||||
{"override-ramdisk", required_argument, NULL, 'r'},
|
||||
{"override-kpf", required_argument, NULL, 'K'},
|
||||
{"disable-ohio", no_argument, NULL, 'O'},
|
||||
{"override-checkra1n", required_argument, NULL, 'i'},
|
||||
{"reboot-device", no_argument, NULL, 'R'},
|
||||
{"exit-recovery", no_argument, NULL, 'n'},
|
||||
{"enter-recovery", no_argument, NULL, 'E'},
|
||||
{"device-info", no_argument, NULL, 'I'},
|
||||
#ifdef DEV_BUILD
|
||||
{"test1", no_argument, NULL, '1'},
|
||||
{"test2", no_argument, NULL, '2'},
|
||||
#endif
|
||||
#ifdef TUI
|
||||
{"tui", no_argument, NULL, 't'},
|
||||
#endif
|
||||
{NULL, 0, NULL, 0}
|
||||
@@ -52,46 +59,59 @@ static struct option longopts[] = {
|
||||
static int usage(int e, char* prog_name)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"Usage: %s [-"
|
||||
"DEhpvVdsSLRnPI"
|
||||
#ifdef DEV_BUILD
|
||||
"Usage: %s [-12cCdDEfhlLnOpRstvV]"
|
||||
#else
|
||||
"Usage: %s [-cCdDEfhlLnOpRsvV]"
|
||||
"12"
|
||||
#endif
|
||||
" [-e boot arguments] [-k Pongo image] [-o overlay file] [-r ramdisk file] [-K KPF file] [-i checkra1n file]\n"
|
||||
#ifdef ROOTFUL
|
||||
"cCfBl"
|
||||
#endif
|
||||
#ifdef TUI
|
||||
"t"
|
||||
#endif
|
||||
"] [-e boot arguments] [-k Pongo image] [-o overlay file] [-r ramdisk file] [-K KPF file]\n"
|
||||
"Copyright (C) 2023, palera1n team, All Rights Reserved.\n\n"
|
||||
"iOS/iPadOS 15+ arm64 jailbreaking tool\n\n"
|
||||
"iOS/iPadOS 15.0-16.5.1 arm64 jailbreaking tool\n\n"
|
||||
"\t--version\t\t\t\tPrint version\n"
|
||||
"\t--force-revert\t\t\t\tRemove jailbreak\n"
|
||||
#ifdef DEV_BUILD
|
||||
"\t-1, --test1\t\t\t\tSet palerain_option_test1\n"
|
||||
"\t-2, --test2\t\t\t\tSet palerain_option_test2\n"
|
||||
#endif
|
||||
#ifdef ROOTFUL
|
||||
"\t-B, --setup-partial-fakefs\t\tSetup partial fakefs\n"
|
||||
"\t-c, --setup-fakefs\t\t\tSetup fakefs\n"
|
||||
"\t-C, --setup-fakefs-forced\t\tSetup fakefs and overwrite any existing ones\n"
|
||||
"\t-C, --clean-fakefs\t\t\tClean fakefs\n"
|
||||
#endif
|
||||
"\t-d, --demote\t\t\t\tDemote\n"
|
||||
"\t-D, --dfuhelper-only\t\t\tExit after entering DFU\n"
|
||||
"\t-D, --dfuhelper\t\t\t\tExit after entering DFU\n"
|
||||
"\t-e, --boot-args <boot arguments>\tXNU boot arguments\n"
|
||||
"\t-E, --enter-recovery\t\t\tEnter recovery mode\n"
|
||||
#ifdef ROOTFUL
|
||||
"\t-f, --fakefs \t\t\t\tBoots fakefs\n"
|
||||
#endif
|
||||
"\t-h, --help\t\t\t\tShow this help\n"
|
||||
"\t-i, --override-checkra1n <file>\t\tOverride checkra1n\n"
|
||||
"\t-k, --override-pongo <file>\t\tOverride Pongo image\n"
|
||||
"\t-K, --override-kpf <file>\t\tOverride kernel patchfinder\n"
|
||||
#ifdef ROOTFUL
|
||||
"\t-l, --rootless\t\t\t\tBoots rootless. This is the default\n"
|
||||
#endif
|
||||
"\t-L, --jbinit-log-to-file\t\tMake jbinit log to /cores/jbinit.log (can be read from sandbox while jailbroken)\n"
|
||||
"\t-n, --exit-recovery\t\t\tExit recovery mode\n"
|
||||
"\t-I, --device-info\t\t\tPrint info about the connected device\n"
|
||||
"\t-o, --override-overlay <file>\t\tOverride overlay\n"
|
||||
"\t-O, --disable-ohio\t\t\tDisable Ohio\n"
|
||||
"\t-p, --pongo-shell\t\t\tBoots to PongoOS shell\n"
|
||||
"\t-P, --pongo-full\t\t\tBoots to a PongoOS shell with default images already uploaded\n"
|
||||
"\t-r, --override-ramdisk <file>\t\tOverride ramdisk\n"
|
||||
"\t-R, --reboot-device\t\t\tReboot connected device in normal mode\n"
|
||||
"\t-s, --safe-mode\t\t\t\tEnter safe mode\n"
|
||||
"\t-S, --no-colors\t\t\t\tDisable colors on the command line\n"
|
||||
"\t-v, --debug-logging\t\t\tEnable debug logging\n"
|
||||
"\t\tThis option can be repeated for extra verbosity.\n"
|
||||
"\t-V, --verbose-boot\t\t\tVerbose boot\n"
|
||||
|
||||
#ifdef DEV_BUILD
|
||||
#ifdef TUI
|
||||
"\t-t, --tui\t\t\t\tTerminal user interface\n"
|
||||
#endif
|
||||
"\nEnvironmental variables:\n"
|
||||
@@ -104,32 +124,35 @@ static int usage(int e, char* prog_name)
|
||||
int optparse(int argc, char* argv[]) {
|
||||
int opt;
|
||||
int index;
|
||||
while ((opt = getopt_long(argc, argv,
|
||||
while ((opt = getopt_long(argc, argv,
|
||||
"DEhpvVlLdsStRnPIe:o:r:K:k:i:"
|
||||
#ifdef DEV_BUILD
|
||||
"12cCDEhpvVldsOLftRnPe:o:r:K:k:i:",
|
||||
#else
|
||||
"cCDEhpvVldsOLfRnPe:o:r:K:k:i:",
|
||||
"12"
|
||||
#endif
|
||||
longopts, NULL)) != -1)
|
||||
"fCcB"
|
||||
,longopts, NULL)) != -1)
|
||||
{
|
||||
switch (opt) {
|
||||
case 'B':
|
||||
palerain_flags |= palerain_option_setup_partial_root;
|
||||
palerain_flags |= palerain_option_setup_rootful;
|
||||
palerain_flags |= palerain_option_verbose_boot;
|
||||
break;
|
||||
case 'c':
|
||||
palerain_flags |= palerain_option_setup_rootful;
|
||||
kpf_flags |= checkrain_option_verbose_boot;
|
||||
palerain_flags |= palerain_option_verbose_boot;
|
||||
break;
|
||||
case 'C':
|
||||
palerain_flags |= palerain_option_setup_rootful;
|
||||
palerain_flags |= palerain_option_setup_rootful_forced;
|
||||
kpf_flags |= checkrain_option_verbose_boot;
|
||||
palerain_flags |= palerain_option_clean_fakefs;
|
||||
break;
|
||||
case 'p':
|
||||
host_flags |= host_option_pongo_exit;
|
||||
palerain_flags |= palerain_option_pongo_exit;
|
||||
break;
|
||||
case 'P':
|
||||
host_flags |= host_option_pongo_full;
|
||||
palerain_flags |= palerain_option_pongo_full;
|
||||
break;
|
||||
case 'D':
|
||||
host_flags |= host_option_dfuhelper_only;
|
||||
palerain_flags |= palerain_option_dfuhelper_only;
|
||||
break;
|
||||
case 'h':
|
||||
usage(0, argv[0]);
|
||||
@@ -138,7 +161,8 @@ int optparse(int argc, char* argv[]) {
|
||||
verbose++;
|
||||
break;
|
||||
case 'V':
|
||||
kpf_flags |= checkrain_option_verbose_boot;
|
||||
palerain_flags |= palerain_option_verbose_boot;
|
||||
force_use_verbose_boot = true;
|
||||
break;
|
||||
case 'e':
|
||||
if (strstr(optarg, "rootdev=") != NULL) {
|
||||
@@ -151,32 +175,24 @@ int optparse(int argc, char* argv[]) {
|
||||
snprintf(xargs_cmd, sizeof(xargs_cmd), "xargs %s", optarg);
|
||||
break;
|
||||
case 'f':
|
||||
snprintf(rootfs_cmd, sizeof(rootfs_cmd), "rootfs %s", optarg);
|
||||
snprintf(dtpatch_cmd, 0x20, "dtpatch %s", optarg);
|
||||
palerain_flags |= palerain_option_rootful;
|
||||
palerain_flags &= ~palerain_option_rootless;
|
||||
break;
|
||||
case 'l':
|
||||
palerain_flags &= ~palerain_option_rootful;
|
||||
palerain_flags |= palerain_option_rootless;
|
||||
break;
|
||||
case 'L':
|
||||
palerain_flags |= palerain_option_jbinit_log_to_file;
|
||||
break;
|
||||
case 'd':
|
||||
host_flags |= host_option_demote;
|
||||
palerain_flags |= palerain_option_demote;
|
||||
break;
|
||||
case 'E':
|
||||
host_flags |= host_option_enter_recovery;
|
||||
palerain_flags |= palerain_option_enter_recovery;
|
||||
break;
|
||||
case 's':
|
||||
checkrain_flags |= checkrain_option_safemode;
|
||||
break;
|
||||
case 'k':
|
||||
if (access(optarg, F_OK) != 0) {
|
||||
LOG(LOG_FATAL, "Cannot access pongo file at %s: %d (%s)", optarg, errno, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
pongo_path = malloc(strlen(optarg) + 1);
|
||||
strcpy(pongo_path, optarg);
|
||||
palerain_flags |= palerain_option_safemode;
|
||||
break;
|
||||
case 'o':
|
||||
if (override_file(&override_overlay, overlay_to_upload, &binpack_dmg_len, optarg))
|
||||
@@ -201,31 +217,24 @@ int optparse(int argc, char* argv[]) {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case 'i': {};
|
||||
struct stat st;
|
||||
if (stat(optarg, &st) != 0) {
|
||||
LOG(LOG_FATAL, "cannot stat external checkra1n file: %d (%s)", errno, strerror(errno));
|
||||
return -1;
|
||||
} else if (!(st.st_mode & S_IXUSR) && !(st.st_mode & S_IXGRP) && !(st.st_mode & S_IXOTH)) {
|
||||
LOG(LOG_FATAL, "%s is not executable", optarg);
|
||||
return -1;
|
||||
};
|
||||
ext_checkra1n = calloc(1, strlen(optarg) + 1);
|
||||
snprintf(ext_checkra1n, strlen(optarg) + 1, "%s", optarg);
|
||||
break;
|
||||
case 'R':
|
||||
host_flags |= host_option_reboot_device;
|
||||
palerain_flags |= palerain_option_reboot_device;
|
||||
break;
|
||||
case 'n':
|
||||
host_flags |= host_option_exit_recovery;
|
||||
palerain_flags |= palerain_option_exit_recovery;
|
||||
break;
|
||||
case 'O':
|
||||
host_flags |= host_option_no_ohio;
|
||||
case 'I':
|
||||
palerain_flags |= palerain_option_device_info;
|
||||
break;
|
||||
#ifdef DEV_BUILD
|
||||
case 'S':
|
||||
palerain_flags |= palerain_option_no_colors;
|
||||
break;
|
||||
#ifdef TUI
|
||||
case 't':
|
||||
host_flags |= host_option_tui;
|
||||
palerain_flags |= palerain_option_tui;
|
||||
break;
|
||||
#endif
|
||||
#ifdef DEV_BUILD
|
||||
case '1':
|
||||
palerain_flags |= palerain_option_test1;
|
||||
break;
|
||||
@@ -234,32 +243,40 @@ int optparse(int argc, char* argv[]) {
|
||||
break;
|
||||
#endif
|
||||
case palerain_option_case_force_revert:
|
||||
checkrain_flags |= checkrain_option_force_revert;
|
||||
palerain_flags |= palerain_option_force_revert;
|
||||
break;
|
||||
case palerain_option_case_version:
|
||||
host_flags |= host_option_palerain_version;
|
||||
palerain_flags |= palerain_option_palerain_version;
|
||||
break;
|
||||
default:
|
||||
usage(1, argv[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (checkrain_option_enabled(host_flags, host_option_palerain_version)) {
|
||||
printf("palera1n version " PALERAIN_VERSION ": " BUILD_DATE "; " BUILD_WHOAMI ":" BUILD_TAG "/" BUILD_STYLE "\n");
|
||||
if ((palerain_flags & palerain_option_palerain_version)) {
|
||||
printf(
|
||||
"palera1n " PALERAIN_VERSION "\n"
|
||||
BUILD_COMMIT " " BUILD_NUMBER " (" BUILD_BRANCH ")\n\n"
|
||||
"Build date: " BUILD_DATE "\n"
|
||||
"Build style: " BUILD_STYLE "\n"
|
||||
"Build tag: " BUILD_TAG "\n"
|
||||
"Built by: " BUILD_WHOAMI "\n"
|
||||
#ifdef USE_LIBUSB
|
||||
"USB backend: libusb\n"
|
||||
#else
|
||||
"USB backend: IOKit\n"
|
||||
#endif
|
||||
"Build options: " BUILD_OPTIONS "\n"
|
||||
);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (checkrain_option_enabled(checkrain_flags, checkrain_option_force_revert) && checkrain_option_enabled(palerain_flags, palerain_option_setup_rootful)) {
|
||||
LOG(LOG_WARNING, "force revert and setup rootful requested at the same time, behaviour here is undefined");
|
||||
if ((strstr(xargs_cmd, "serial=") != NULL) && !force_use_verbose_boot && (palerain_flags & palerain_option_setup_rootful)) {
|
||||
palerain_flags &= ~palerain_option_verbose_boot;
|
||||
}
|
||||
|
||||
snprintf(checkrain_flags_cmd, 0x20, "checkra1n_flags 0x%x", checkrain_flags);
|
||||
snprintf(palerain_flags_cmd, 0x20, "palera1n_flags 0x%x", palerain_flags);
|
||||
snprintf(kpf_flags_cmd, 0x20, "kpf_flags 0x%x", kpf_flags);
|
||||
LOG(LOG_VERBOSE3, "checkrain_flags: %s", checkrain_flags_cmd);
|
||||
|
||||
snprintf(palerain_flags_cmd, 0x30, "palera1n_flags 0x%" PRIx64, palerain_flags);
|
||||
LOG(LOG_VERBOSE3, "palerain_flags: %s", palerain_flags_cmd);
|
||||
LOG(LOG_VERBOSE3, "kpf_flags: %s", kpf_flags_cmd);
|
||||
LOG(LOG_VERBOSE3, "host_flags: 0x%x", host_flags);
|
||||
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 ptr %p -> %p", override_kpf.orig_ptr, **kpf_to_upload);
|
||||
@@ -273,25 +290,19 @@ int optparse(int argc, char* argv[]) {
|
||||
LOG(LOG_VERBOSE4, "overlay override ptr %p -> %p", override_overlay.orig_ptr, **overlay_to_upload);
|
||||
}
|
||||
|
||||
if (!checkrain_option_enabled(palerain_flags, palerain_option_rootful)) {
|
||||
if (checkrain_option_enabled(palerain_flags, palerain_option_setup_rootful) || checkrain_option_enabled(palerain_flags, palerain_option_setup_rootful_forced)) {
|
||||
if (!(palerain_flags & palerain_option_rootful)) {
|
||||
if ((palerain_flags & palerain_option_setup_rootful)) {
|
||||
LOG(LOG_FATAL, "Cannot setup rootful when rootless is requested. Use -f to enable rootful mode.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (!(
|
||||
checkrain_option_enabled(host_flags, host_option_dfuhelper_only) ||
|
||||
checkrain_option_enabled(host_flags, host_option_enter_recovery) ||
|
||||
checkrain_option_enabled(host_flags, host_option_exit_recovery) ||
|
||||
checkrain_option_enabled(host_flags, host_option_reboot_device)))
|
||||
(palerain_flags & palerain_option_dfuhelper_only) ||
|
||||
(palerain_flags & palerain_option_enter_recovery) ||
|
||||
(palerain_flags & palerain_option_exit_recovery) ||
|
||||
(palerain_flags & palerain_option_reboot_device)))
|
||||
{
|
||||
#ifdef NO_CHECKRAIN
|
||||
if (checkra1n_len == 0 && ext_checkra1n == NULL)
|
||||
{
|
||||
LOG(LOG_FATAL, "checkra1n omitted in build but no override specified");
|
||||
return -1;
|
||||
}
|
||||
if (!(checkrain_option_enabled(host_flags, host_option_pongo_exit) || checkrain_option_enabled(host_flags, host_option_pongo_exit)))
|
||||
if (!((palerain_flags & palerain_option_pongo_exit) || (palerain_flags & palerain_option_pongo_exit)))
|
||||
{
|
||||
#ifdef NO_KPF
|
||||
if (checkra1n_kpf_pongo_len == 0)
|
||||
@@ -301,7 +312,6 @@ int optparse(int argc, char* argv[]) {
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
for (index = optind; index < argc; index++)
|
||||
@@ -319,17 +329,27 @@ int optparse(int argc, char* argv[]) {
|
||||
usage(1, argv[0]);
|
||||
}
|
||||
}
|
||||
#ifndef WIN
|
||||
if (verbose >= 2) setenv("LIBUSB_DEBUG", "1", 1);
|
||||
#endif
|
||||
|
||||
if (verbose >= 3)
|
||||
{
|
||||
libusbmuxd_set_debug_level(verbose - 2);
|
||||
irecv_set_debug_level(1);
|
||||
#ifndef WIN
|
||||
setenv("LIBUSB_DEBUG", "2", 1);
|
||||
#endif
|
||||
}
|
||||
if (verbose >= 4) {
|
||||
idevice_set_debug_level(1);
|
||||
#ifndef WIN
|
||||
setenv("LIBUSB_DEBUG", "3", 1);
|
||||
#endif
|
||||
}
|
||||
#ifndef WIN
|
||||
if (verbose >= 5)
|
||||
setenv("LIBUSB_DEBUG", "4", 1);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@@ -11,7 +11,12 @@
|
||||
#include <ctype.h>
|
||||
#include <assert.h>
|
||||
#include <getopt.h>
|
||||
#ifndef WIN
|
||||
#include <sys/mman.h>
|
||||
#else
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
@@ -31,11 +36,19 @@ int override_file(override_file_t *finfo, niarelap_file_t** orig, unsigned int *
|
||||
return errno;
|
||||
}
|
||||
LOG(LOG_VERBOSE5, "override_file: fstat fd %d succeeded!", fd);
|
||||
#ifdef WIN
|
||||
void *addr = VirtualAlloc(NULL, st.st_size, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
|
||||
if (addr == NULL) {
|
||||
LOG(LOG_ERROR, "Failed to map file %s: %d (%s)", filename, errno, strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
#else
|
||||
void *addr = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
if (addr == MAP_FAILED) {
|
||||
LOG(LOG_ERROR, "Failed to map file %s: %d (%s)", filename, errno, strerror(errno));
|
||||
return errno;
|
||||
}
|
||||
#endif
|
||||
LOG(LOG_VERBOSE5, "override_file: Override file mapped successfully");
|
||||
finfo->magic = OVERRIDE_MAGIC;
|
||||
finfo->fd = fd;
|
||||
|
||||
+42
-17
@@ -7,10 +7,13 @@
|
||||
#include <stdlib.h> // exit, strtoull
|
||||
#include <string.h> // strlen, strerror, memcpy, memmove
|
||||
#include <unistd.h> // close
|
||||
#ifndef WIN
|
||||
#include <sys/mman.h> // mmap, munmap
|
||||
#include <sys/stat.h> // fstst
|
||||
#endif
|
||||
|
||||
#include <palerain.h>
|
||||
#include <ANSI-color-codes.h>
|
||||
|
||||
bool device_has_booted = 0;
|
||||
int pongo_thr_running = 0;
|
||||
@@ -28,24 +31,22 @@ void* pongo_helper(void* ptr) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *pongo_usb_callback(void *arg) {
|
||||
void *pongo_usb_callback(stuff_t *arg) {
|
||||
if (get_found_pongo())
|
||||
return NULL;
|
||||
set_found_pongo(1);
|
||||
if (checkrain_option_enabled(palerain_flags, palerain_option_setup_rootful)) {
|
||||
if ((palerain_flags & palerain_option_setup_rootful)) {
|
||||
strncat(xargs_cmd, " wdt=-1", 0x270 - strlen(xargs_cmd) - 1);
|
||||
}
|
||||
LOG(LOG_INFO, "Found PongoOS USB Device");
|
||||
usb_device_handle_t handle = *(usb_device_handle_t *)arg;
|
||||
usb_device_handle_t handle = arg->handle;
|
||||
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, kpf_flags_cmd);
|
||||
issue_pongo_command(handle, checkrain_flags_cmd);
|
||||
issue_pongo_command(handle, palerain_flags_cmd);
|
||||
if (checkrain_option_enabled(palerain_flags, palerain_option_rootful))
|
||||
if ((palerain_flags & palerain_option_rootful))
|
||||
{
|
||||
issue_pongo_command(handle, "rootfs");
|
||||
}
|
||||
@@ -57,7 +58,7 @@ void *pongo_usb_callback(void *arg) {
|
||||
upload_pongo_file(handle, **ramdisk_to_upload, ramdisk_dmg_len);
|
||||
issue_pongo_command(handle, "ramdisk");
|
||||
}
|
||||
#ifdef NO_BINPACK
|
||||
#ifdef NO_OVERLAY
|
||||
if (binpack_dmg_len != 0)
|
||||
#endif
|
||||
{
|
||||
@@ -65,15 +66,25 @@ void *pongo_usb_callback(void *arg) {
|
||||
issue_pongo_command(handle, "overlay");
|
||||
}
|
||||
issue_pongo_command(handle, xargs_cmd);
|
||||
if (checkrain_option_enabled(host_flags, host_option_pongo_full)) goto done;
|
||||
if ((palerain_flags & palerain_option_pongo_full)) goto done;
|
||||
issue_pongo_command(handle, "bootx");
|
||||
LOG(LOG_INFO, "Booting Kernel...");
|
||||
if ((palerain_flags & palerain_option_setup_partial_root)) {
|
||||
LOG(LOG_INFO, "Please wait up to 5 minutes for the bindfs to be created.");
|
||||
LOG(LOG_INFO, "Once the device boots up to iOS, run again without the -B (Create BindFS) option to jailbreak.");
|
||||
} else if ((palerain_flags & palerain_option_setup_rootful)) {
|
||||
LOG(LOG_INFO, "Please wait up to 10 minutes for the fakefs to be created.");
|
||||
LOG(LOG_INFO, "Once the device boots up to iOS, run again without the -c (Create FakeFS) option to jailbreak.");
|
||||
}
|
||||
if (dfuhelper_thr_running) {
|
||||
pthread_cancel(dfuhelper_thread);
|
||||
dfuhelper_thr_running = false;
|
||||
}
|
||||
done:
|
||||
device_has_booted = true;
|
||||
#ifdef USE_LIBUSB
|
||||
libusb_unref_device(arg->dev);
|
||||
#endif
|
||||
set_spin(0);
|
||||
return NULL;
|
||||
}
|
||||
@@ -129,10 +140,10 @@ fetch_output:
|
||||
bad:
|
||||
if (ret != USB_RET_SUCCESS)
|
||||
{
|
||||
if (ret == USB_RET_NOT_RESPONDING)
|
||||
return 0;
|
||||
if (command != NULL && (!strncmp("boot", command, 4) && ret == USB_RET_IO))
|
||||
return 0;
|
||||
if (command != NULL && (!strncmp("boot", command, 4))) {
|
||||
if (ret == USB_RET_IO || ret == USB_RET_NO_DEVICE || ret == USB_RET_NOT_RESPONDING)
|
||||
return 0;
|
||||
}
|
||||
LOG(LOG_ERROR, "USB error: %s", usb_strerror(ret));
|
||||
return ret;
|
||||
}
|
||||
@@ -149,19 +160,28 @@ int upload_pongo_file(usb_device_handle_t handle, unsigned char *buf, unsigned i
|
||||
ret = USBBulkUpload(handle, buf, buf_len);
|
||||
if (ret == USB_RET_SUCCESS)
|
||||
{
|
||||
LOG(LOG_VERBOSE, "Uploaded %llu bytes to PongoOS", (unsigned long long)buf_len);
|
||||
if (verbose < 3 || verbose > 4) {
|
||||
LOG(LOG_VERBOSE, "Uploaded %llu bytes to PongoOS", (unsigned long long)buf_len);
|
||||
} else {
|
||||
if ((palerain_flags & palerain_option_no_colors))
|
||||
printf("/send mem:%p:%p\nUploaded %llu bytes]\n", (void*)buf, (void*)(buf + buf_len), (unsigned long long)buf_len);
|
||||
else
|
||||
printf("/send mem:%p:%p\n" BCYN "[Uploaded %llu bytes]\n" CRESET, (void*)buf, (void*)(buf + buf_len), (unsigned long long)buf_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (verbose >= 3) printf("pongoOS> ");
|
||||
return ret;
|
||||
}
|
||||
|
||||
void io_start(stuff_t *stuff)
|
||||
{
|
||||
int r = pthread_create(&stuff->th, NULL, &pongo_usb_callback, &stuff->handle);
|
||||
int r = pthread_create(&stuff->th, NULL, (pthread_start_t)pongo_usb_callback, stuff);
|
||||
if(r != 0)
|
||||
{
|
||||
ERR("pthread_create: %s", strerror(r));
|
||||
exit(-1); // TODO: ok with libusb?
|
||||
set_spin(0);
|
||||
return;
|
||||
}
|
||||
pthread_join(stuff->th, NULL);
|
||||
}
|
||||
@@ -172,14 +192,19 @@ void io_stop(stuff_t *stuff)
|
||||
if(r != 0)
|
||||
{
|
||||
ERR("pthread_cancel: %s", strerror(r));
|
||||
exit(-1); // TODO: ok with libusb?
|
||||
set_spin(0);
|
||||
return;
|
||||
}
|
||||
r = pthread_join(stuff->th, NULL);
|
||||
if(r != 0)
|
||||
{
|
||||
ERR("pthread_join: %s", strerror(r));
|
||||
exit(-1); // TODO: ok with libusb?
|
||||
set_spin(0);
|
||||
return;
|
||||
}
|
||||
#ifdef USE_LIBUSB
|
||||
libusb_unref_device(stuff->dev);
|
||||
#endif
|
||||
}
|
||||
|
||||
void write_stdout(char *buf, uint32_t len)
|
||||
|
||||
+4
-4
@@ -12,15 +12,15 @@
|
||||
#include <palerain.h>
|
||||
#include <tui.h>
|
||||
|
||||
int redraw_screen() {
|
||||
int redraw_screen(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int destroy_window() {
|
||||
int destroy_window(void) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int init_window() {
|
||||
int init_window(void) {
|
||||
setlocale(LC_ALL, NULL);
|
||||
setenv(
|
||||
"NEWT_COLORS",
|
||||
@@ -61,7 +61,7 @@ int init_window() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tui() {
|
||||
int tui(void) {
|
||||
int ret = 0;
|
||||
if ((ret = init_window())) return ret;
|
||||
ret = MAIN_SCREEN;
|
||||
|
||||
@@ -12,4 +12,4 @@
|
||||
#include <palerain.h>
|
||||
#include <tui.h>
|
||||
|
||||
tui_screen_t tui_screen_enter_dfu() { return JAILBREAKING_SCREEN; }
|
||||
tui_screen_t tui_screen_enter_dfu(void) { return JAILBREAKING_SCREEN; }
|
||||
@@ -12,4 +12,4 @@
|
||||
#include <palerain.h>
|
||||
#include <tui.h>
|
||||
|
||||
tui_screen_t tui_screen_enter_recovery() { return ENTER_DFU_SCREEN; }
|
||||
tui_screen_t tui_screen_enter_recovery(void) { return ENTER_DFU_SCREEN; }
|
||||
@@ -12,4 +12,4 @@
|
||||
#include <palerain.h>
|
||||
#include <tui.h>
|
||||
|
||||
tui_screen_t tui_screen_jailbreak() { return EXIT_SCREEN; }
|
||||
tui_screen_t tui_screen_jailbreak(void) { return EXIT_SCREEN; }
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <palerain.h>
|
||||
#include <tui.h>
|
||||
|
||||
tui_screen_t tui_screen_main() {
|
||||
tui_screen_t tui_screen_main(void) {
|
||||
int ret = MAIN_SCREEN;
|
||||
bool can_start = false;
|
||||
newtCenteredWindow(WIDTH, HEIGHT, NULL);
|
||||
|
||||
@@ -21,16 +21,14 @@ void bitfield_check_cb(newtComponent box, void* data) {
|
||||
}
|
||||
|
||||
|
||||
tui_screen_t tui_screen_options() {
|
||||
tui_bit_info_t verbose_info = { &kpf_flags, checkrain_option_verbose_boot };
|
||||
tui_screen_t tui_screen_options(void) {
|
||||
tui_bit_info_t verbose_info = { &palerain_flags, palerain_option_verbose_boot };
|
||||
tui_bit_info_t rootful_info = { &palerain_flags, palerain_option_rootful };
|
||||
tui_bit_info_t setup_rootful_info = { &palerain_flags, palerain_option_setup_rootful };
|
||||
tui_bit_info_t force_revert_info = { &checkrain_flags, checkrain_option_force_revert };
|
||||
tui_bit_info_t safemode_info = { &checkrain_flags, checkrain_option_safemode };
|
||||
tui_bit_info_t force_revert_info = { &palerain_flags, palerain_option_force_revert };
|
||||
tui_bit_info_t safemode_info = { &palerain_flags, palerain_option_safemode };
|
||||
tui_bit_info_t flower_chain_info = { &palerain_flags, palerain_option_flower_chain };
|
||||
|
||||
static checkrain_option_t flower_flags = 0, flower_option_flower_chain = (1 << 0);
|
||||
tui_bit_info_t flower_chain_info = { &flower_flags, flower_option_flower_chain };
|
||||
|
||||
const char* bootargs_entered = NULL;
|
||||
int ret = MAIN_SCREEN;
|
||||
|
||||
@@ -41,11 +39,11 @@ tui_screen_t tui_screen_options() {
|
||||
newtTextboxSetText(optionsNotice, "You may set the following options. If you don't know what they mean you'll probably have no reason to set them.");
|
||||
// newtTextboxSetColors(optionsNotice, NEWT_COLORSET_LABEL, NEWT_COLORSET_LABEL);
|
||||
|
||||
newtComponent verboseBootBox = newtCheckbox(1, 3, "Verbose boot", CHECKBOX_STATE(kpf_flags, checkrain_option_verbose_boot), NULL, NULL);
|
||||
newtComponent verboseBootBox = newtCheckbox(1, 3, "Verbose boot", CHECKBOX_STATE(palerain_flags, palerain_option_verbose_boot), NULL, NULL);
|
||||
newtComponent rootfulBox = newtCheckbox(1, 4, "Rootful", CHECKBOX_STATE(palerain_flags, palerain_option_rootful), NULL, NULL);
|
||||
newtComponent rootfulSetupBox = newtCheckbox(1, 5, "Setup fakefs", CHECKBOX_STATE(palerain_flags, palerain_option_setup_rootful), NULL, NULL);
|
||||
newtComponent forceRevertBox = newtCheckbox(1, 6, "Restore system", CHECKBOX_STATE(checkrain_flags, checkrain_option_force_revert), NULL, NULL);
|
||||
newtComponent safeModeBox = newtCheckbox(1, 7, "Safe mode", CHECKBOX_STATE(checkrain_flags, checkrain_option_safemode), NULL, NULL);
|
||||
newtComponent forceRevertBox = newtCheckbox(1, 6, "Restore system", CHECKBOX_STATE(palerain_flags, palerain_option_force_revert), NULL, NULL);
|
||||
newtComponent safeModeBox = newtCheckbox(1, 7, "Safe mode", CHECKBOX_STATE(palerain_flags, palerain_option_safemode), NULL, NULL);
|
||||
|
||||
newtComponentAddCallback(verboseBootBox, bitfield_check_cb, &verbose_info);
|
||||
newtComponentAddCallback(rootfulBox, bitfield_check_cb, &rootful_info);
|
||||
@@ -56,7 +54,7 @@ tui_screen_t tui_screen_options() {
|
||||
newtComponent bootCmdlineLabel = newtLabel(1, 8, "Kernel command line:");
|
||||
newtComponent bootCmdlineEntry = newtEntry(1, 9, &xargs_cmd[6], WIDTH - 2, &bootargs_entered, NEWT_ENTRY_SCROLL);
|
||||
|
||||
newtComponent flowerChainBox = newtCheckbox(1, 10, "Flower chain", CHECKBOX_STATE(flower_flags, flower_option_flower_chain), NULL, NULL);
|
||||
newtComponent flowerChainBox = newtCheckbox(1, 10, "Flower chain", CHECKBOX_STATE(palerain_flags, palerain_option_flower_chain), NULL, NULL);
|
||||
newtComponentAddCallback(flowerChainBox, bitfield_check_cb, &flower_chain_info);
|
||||
|
||||
|
||||
|
||||
+61
-58
@@ -34,11 +34,13 @@
|
||||
#include <stdlib.h> // exit, strtoull
|
||||
#include <string.h> // strlen, strerror, memcpy, memmove
|
||||
#include <unistd.h> // close
|
||||
#ifndef WIN
|
||||
#include <sys/mman.h> // mmap, munmap
|
||||
#include <sys/stat.h> // fstst
|
||||
#endif
|
||||
|
||||
#include <palerain.h>
|
||||
#define ERR(...) LOG(LOG_VERBOSE, __VA_ARGS__)
|
||||
#define ERR(...) LOG(LOG_ERROR, __VA_ARGS__)
|
||||
|
||||
void io_start(stuff_t *stuff);
|
||||
void io_stop(stuff_t *stuff);
|
||||
@@ -114,12 +116,12 @@ usb_ret_t USBBulkUpload(usb_device_handle_t handle, void *data, int len)
|
||||
|
||||
static int FoundDevice(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *arg)
|
||||
{
|
||||
LOG(LOG_VERBOSE, "PongoOS USB Device connected");
|
||||
stuff_t *stuff = arg;
|
||||
if(stuff->handle)
|
||||
{
|
||||
return LIBUSB_SUCCESS;
|
||||
}
|
||||
LOG(LOG_VERBOSE, "PongoOS USB Device connected");
|
||||
|
||||
libusb_device_handle *handle;
|
||||
int r = libusb_open(dev, &handle);
|
||||
@@ -162,15 +164,16 @@ static int FoundDevice(libusb_context *ctx, libusb_device *dev, libusb_hotplug_e
|
||||
|
||||
static int LostDevice(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *arg)
|
||||
{
|
||||
LOG(LOG_VERBOSE, "PongoOS USB Device disconnected");
|
||||
stuff_t *stuff = arg;
|
||||
if(stuff->dev != dev)
|
||||
{
|
||||
return LIBUSB_SUCCESS;
|
||||
}
|
||||
LOG(LOG_VERBOSE, "PongoOS USB Device disconnected");
|
||||
|
||||
io_stop(stuff);
|
||||
libusb_close(stuff->handle);
|
||||
libusb_unref_device(dev);
|
||||
stuff->handle = NULL;
|
||||
stuff->dev = NULL;
|
||||
|
||||
@@ -180,9 +183,11 @@ static int LostDevice(libusb_context *ctx, libusb_device *dev, libusb_hotplug_ev
|
||||
int wait_for_pongo(void)
|
||||
{
|
||||
stuff_t stuff;
|
||||
stuff.handle = NULL;
|
||||
libusb_hotplug_callback_handle hp[2];
|
||||
libusb_context* ctx = NULL;
|
||||
|
||||
int r = libusb_init(NULL);
|
||||
int r = libusb_init(&ctx);
|
||||
if(r != LIBUSB_SUCCESS)
|
||||
{
|
||||
ERR("libusb_init: %s", libusb_error_name(r));
|
||||
@@ -192,75 +197,73 @@ int wait_for_pongo(void)
|
||||
if(!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG))
|
||||
{
|
||||
ERR("libusb: no hotplug capability");
|
||||
libusb_exit(NULL);
|
||||
libusb_exit(ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
r = libusb_hotplug_register_callback(NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED, 0, PONGO_USB_VENDOR, PONGO_USB_PRODUCT, LIBUSB_HOTPLUG_MATCH_ANY, FoundDevice, &stuff, &hp[0]);
|
||||
r = libusb_hotplug_register_callback(ctx, LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, 0, PONGO_USB_VENDOR, PONGO_USB_PRODUCT, LIBUSB_HOTPLUG_MATCH_ANY, LostDevice, &stuff, &hp[1]);
|
||||
if(r != LIBUSB_SUCCESS)
|
||||
{
|
||||
ERR("libusb_hotplug: %s", libusb_error_name(r));
|
||||
libusb_exit(NULL);
|
||||
libusb_exit(ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
r = libusb_hotplug_register_callback(NULL, LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT, 0, PONGO_USB_VENDOR, PONGO_USB_PRODUCT, LIBUSB_HOTPLUG_MATCH_ANY, LostDevice, &stuff, &hp[1]);
|
||||
if(r != LIBUSB_SUCCESS)
|
||||
{
|
||||
ERR("libusb_hotplug: %s", libusb_error_name(r));
|
||||
libusb_exit(NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
libusb_device **list;
|
||||
ssize_t sz = libusb_get_device_list(NULL, &list);
|
||||
if(sz < 0)
|
||||
{
|
||||
ERR("libusb_get_device_list: %s", libusb_error_name((int)sz));
|
||||
libusb_exit(NULL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(ssize_t i = 0; i < sz; ++i)
|
||||
{
|
||||
struct libusb_device_descriptor desc;
|
||||
r = libusb_get_device_descriptor(list[i], &desc);
|
||||
if(r != LIBUSB_SUCCESS)
|
||||
{
|
||||
ERR("libusb_get_device_descriptor: %s", libusb_error_name(r));
|
||||
// continue anyway
|
||||
}
|
||||
if(desc.idVendor != PONGO_USB_VENDOR || desc.idProduct != PONGO_USB_PRODUCT)
|
||||
{
|
||||
libusb_unref_device(list[i]);
|
||||
continue;
|
||||
}
|
||||
r = FoundDevice(NULL, list[i], LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED, &stuff);
|
||||
for(ssize_t j = i + 1; j < sz; ++j)
|
||||
{
|
||||
libusb_unref_device(list[j]);
|
||||
}
|
||||
if(r != LIBUSB_SUCCESS)
|
||||
{
|
||||
libusb_free_device_list(list, 0);
|
||||
libusb_exit(NULL);
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
libusb_free_device_list(list, 0);
|
||||
|
||||
while(get_spin())
|
||||
{
|
||||
r = libusb_handle_events(NULL);
|
||||
while (1) {
|
||||
r = libusb_handle_events(ctx);
|
||||
if(r != LIBUSB_SUCCESS)
|
||||
{
|
||||
ERR("libusb_handle_events: %s", libusb_error_name(r));
|
||||
break;
|
||||
}
|
||||
|
||||
libusb_device **list;
|
||||
ssize_t sz = libusb_get_device_list(ctx, &list);
|
||||
bool done = false;
|
||||
if(sz < 0)
|
||||
{
|
||||
ERR("libusb_get_device_list: %s", libusb_error_name((int)sz));
|
||||
libusb_exit(ctx);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for(ssize_t i = 0; i < sz; ++i)
|
||||
{
|
||||
struct libusb_device_descriptor desc;
|
||||
r = libusb_get_device_descriptor(list[i], &desc);
|
||||
if(r != LIBUSB_SUCCESS)
|
||||
{
|
||||
ERR("libusb_get_device_descriptor: %s", libusb_error_name(r));
|
||||
// continue anyway
|
||||
}
|
||||
if(desc.idVendor != PONGO_USB_VENDOR || desc.idProduct != PONGO_USB_PRODUCT)
|
||||
{
|
||||
libusb_unref_device(list[i]);
|
||||
continue;
|
||||
}
|
||||
r = FoundDevice(ctx, list[i], LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED, &stuff);
|
||||
for (ssize_t j = i; j < sz; ++j) {
|
||||
libusb_unref_device(list[j]);
|
||||
}
|
||||
|
||||
if(r != LIBUSB_SUCCESS)
|
||||
{
|
||||
libusb_free_device_list(list, 0);
|
||||
libusb_exit(ctx);
|
||||
return -1;
|
||||
} else {
|
||||
done = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
libusb_free_device_list(list, 0);
|
||||
|
||||
if (done) goto end;
|
||||
}
|
||||
|
||||
libusb_exit(NULL);
|
||||
return 0;
|
||||
end:
|
||||
libusb_exit(ctx);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user