Here, I'll show you how to compile Frida for both rootfull and rootless jailbreaks.
## TL;DR
~On [Dopamine/Fugu15 Max](https://github.com/opa334/Dopamine) or [palera1n](https://github.com/palera1n/palera1n) you can add [my repo](https://miticollo.github.io/repos/) (open the link in your favorite browser on your jailbroken iDevice).~
~The [DEBs](https://github.com/miticollo/miticollo.github.io/tree/main/repos/my/debs/frida) you will install are build using the following instructions.~
### Update 2024-02-29
Starting from version 16.1.5 Frida supports rootless and rootfull JB. So you can add [https://build.frida.re/](https://build.frida.re/) to your package manager.
### New Instructions
If you want to compile a new version of Frida (≥ 16.2.2) you can use my [new guide](https://gist.github.com/miticollo/12e3fff5ba8fab7dd707c874105a508f).
## Build Instructions
### Requirements
- Make sure you have:
- [Python 3](https://github.com/pyenv/pyenv).7+ in your PATH
- [Node.js](https://github.com/nvm-sh/nvm) in your PATH
- [`ldid`](https://github.com/ProcursusTeam/ldid) in your PATH
### macOS
macOS is required because you need to use Apple's proprietary software like Xcode, `lipo`, and `codesign`.
> **Warning**
> Before starting, read carefully up to the end.
#### Build
1. Install the latest version of Xcode with command-line tools from the App Store. Without it, you **won't have** iPhoneOS SDKs.
2. Download Xcode 11.7 directly from Apple at the following link: [Xcode_11.7.xip](https://developer.apple.com/services-account/download?path=/Developer_Tools/Xcode_11.7/Xcode_11.7.xip). You will need to authenticate with your Apple ID to download it.
>
>
>
>
>
> To better manage multiple Xcode versions, you can use a CLI tool called [`xcodes`](https://github.com/XcodesOrg/xcodes).
> Alternatively, if you prefer an equivalent GUI app, you can use [XcodesApp](https://github.com/XcodesOrg/XcodesApp).
3. Once downloaded, opening the .xip archive will begin extracting it. After extraction, rename the app to avoid conflicting with your primary installation of Xcode and move it to `/Applications/` (e.g., `mv Xcode.app /Applications/Xcode-11.7.app`).
4. Download [this script](https://raw.githubusercontent.com/conda-forge/gdb-feedstock/main/recipe/macos-codesign/macos-setup-codesign.sh), change `gdb_codesign` to `frida-cert`, and then run it.
5. Run `brew install dpkg` to install `dpkg-deb`.
6. Clone the project:
```shell
git clone --recurse-submodules https://github.com/frida/frida.git
cd frida
```
7.
(Optional) Check out the latest stable release:
```shell
git checkout "$(git describe --tags $(git rev-list --tags --max-count=1))"
```
To go back to `origin/main`, run `git switch -`.
8.
(Optional) Select your preferred Xcode version:
```shel
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer
```
9. Export the identity previously created in an enviroment variable called `IOS_CERTID`:
```shell
export IOS_CERTID=frida-cert
```
10. Build `frida-server` and `frida-agent.dylib` for 3 different architectures:
- **rootless**
```shell
make build/frida-ios-{arm64e,arm64,arm64eoabi}/var/jb/usr/lib/pkgconfig/frida-core-1.0.pc
```
- **rootfull**
```shell
make build/frida-ios-{arm64e,arm64,arm64eoabi}/usr/lib/pkgconfig/frida-core-1.0.pc
```
> **Note**
> To properly instrument **all applications**, all necessary architectures must be in place.
> For instance, to instrument Safari, the `frida-agent.dylib` for ARM64e is required.
> However, for Spotify, the required architecture is ARM64.
>
> If the `frida-agent.dylib` does not contain both slices, you will likely encounter an `Incompatible Mach-O image` error when using the `frida` CLI tool.
> To check what I said, compare the output of the following two commands:
> ```bash
> file /Applications/MobileSafari.app/MobileSafari
> file /var/containers/Bundle/Application//Spotify.app/Spotify
> ```
11. Make the universal [`frida-server`](https://github.com/frida/frida/blob/1b2bf7cbf86a862597465d57f23e373ddc62104e/.github/workflows/ci.yml#L221-L227) and [`frida-agent.dylib`](https://github.com/frida/frida/blob/1b2bf7cbf86a862597465d57f23e373ddc62104e/.github/workflows/ci.yml#L238-L249)
- **rootless**
```shell
mkdir -vp ./build/frida-ios-universal/var/jb/usr/{bin,lib/frida}/
python ./releng/mkfatmacho.py ./build/frida-ios-{universal,arm64,arm64e,arm64eoabi}/var/jb/usr/bin/frida-server
lipo ./build/frida-ios-{arm64,arm64e}/var/jb/usr/lib/frida/frida-agent.dylib -create -output ./build/frida-ios-universal/var/jb/usr/lib/frida/frida-agent.dylib
install_name_tool -id 'FridaAgent' ./build/frida-ios-universal/var/jb/usr/lib/frida/frida-agent.dylib
codesign -s "$IOS_CERTID" -fv --timestamp=none --generate-entitlement-der ./build/frida-ios-universal/var/jb/usr/lib/frida/frida-agent.dylib
```
- **rootfull**
```shell
mkdir -vp ./build/frida-ios-universal/usr/{bin,lib/frida}/
python ./releng/mkfatmacho.py ./build/frida-ios-{universal,arm64,arm64e,arm64eoabi}/usr/bin/frida-server
lipo ./build/frida-ios-{arm64,arm64e}/usr/lib/frida/frida-agent.dylib -create -output ./build/frida-ios-universal/usr/lib/frida/frida-agent.dylib
install_name_tool -id 'FridaAgent' ./build/frida-ios-universal/usr/lib/frida/frida-agent.dylib
codesign -s "$IOS_CERTID" -fv --timestamp=none --generate-entitlement-der ./build/frida-ios-universal/usr/lib/frida/frida-agent.dylib
```
12.
(Optional) Fake signing `frida-server`:
```shell
ldid -S -M './build/frida-ios-universal/var/jb/usr/bin/frida-server'
```
> **Note**
> I ran this command because otherwise on Dopamine/Fugu15 Max JB `frida-server` was being `Killed: 9`.
13. Package everything into a DEB file:
```shell
export FRIDA_VERSION=$(releng/frida_version.py)
```
- **rootless**
```shell
./frida-core/tools/package-server-fruity.sh 'iphoneos-arm64' build/frida-ios-universal/var/jb build/"frida_${FRIDA_VERSION}_iphoneos-universal.deb"
```
- **rootfull**
```shell
./frida-core/tools/package-server-fruity.sh 'iphoneos-arm' build/frida-ios-universal build/"frida_${FRIDA_VERSION}_iphoneos-universal.deb"
```
14. Check the `build/` directory to find your DEB file. Enjoy!
##### Rootless
To get the rootless version of frida, you need to edit the following files:
- [`Makefile.macos.mk`](https://github.com/frida/frida/blob/main/Makefile.macos.mk)
- [`frida-core/tools/package-server-fruity.sh`](https://github.com/frida/frida-core/blob/main/tools/package-server-fruity.sh) (for Frida 16.1.3 and below)
You can find an example based on Frida 16.1.4 in this gist.
Now go to step [8](#xcode).
#### How to upgrade
1. Go back to `origin/main`
```shell
git switch -
```
2. Pull new commits
```shell
git pull --recurse-submodules
```
3. If necessary solve conflicts.
4. Now go to step [7](#checkout).
#### Clean up
1. Run
```shell
make clean distclean
```
2. Go to step [8](#xcode).