<p align="center">
<img src="media/logo.svg" alt="ipatool-rs logo" width="136">
</p>
<h1 align="center">ipatool-rs — App Store IPA Downloader TUI & CLI</h1>
<p align="center">
Search, purchase, and download <strong>iOS App Store IPA files</strong> — including <strong>older app versions</strong> — straight from your terminal.<br>
A fast, low-memory Rust alternative to <a href="https://github.com/majd/ipatool">ipatool</a> featuring an interactive TUI, streaming downloads, and a lightweight <code>auth/v1/native</code> + <code>X-Apple-AMD</code> signing engine.
</p>
<p align="center">
<a href="https://crates.io/crates/ipatool-rs"><img src="https://img.shields.io/crates/v/ipatool-rs.svg?label=crates.io" alt="Crates.io"></a>
<a href="https://github.com/Kosthi/ipatool-rs/releases/latest"><img src="https://img.shields.io/github/v/release/Kosthi/ipatool-rs?label=Release" alt="Latest Release"></a>
<a href="https://github.com/Kosthi/ipatool-rs/releases"><img src="https://img.shields.io/github/downloads/Kosthi/ipatool-rs/total?label=Downloads" alt="GitHub Downloads"></a>
<a href="https://github.com/Kosthi/ipatool-rs/actions/workflows/ci.yml"><img src="https://github.com/Kosthi/ipatool-rs/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
<a href="https://star-history.com/#Kosthi/ipatool-rs&Date"><img src="https://img.shields.io/github/stars/Kosthi/ipatool-rs?style=flat&label=Stars" alt="GitHub Stars"></a>
</p>
<p align="center">
<a href="#quickstart">Quickstart</a> ·
<a href="#installation">Installation</a> ·
<a href="#usage">Usage</a> ·
<a href="#migrating-from-majdipatool">Migrating from ipatool</a> ·
<a href="#how-it-works">How It Works</a> ·
<a href="#faq">FAQ</a> ·
<a href="https://github.com/Kosthi/ipatool-rs/discussions">Discussions</a> ·
<a href="README_zh.md">中文文档</a>
</p>
<p align="center">
<a href="media/demo.gif"><img src="media/demo.gif" alt="ipatool-rs live TUI and CLI demo" width="860"></a>
</p>
---
## Quickstart
Install `ipatool` and launch the interactive terminal UI — or grab an IPA in three commands:
```bash
# 1. Install (macOS / Linux via Homebrew — see below for Windows, Cargo, and curl installers)
brew install Kosthi/tap/ipatool-rs
# 2a. Launch the interactive TUI (login, search, purchase, and download in one screen)
ipatool
# 2b. Or use the CLI directly
ipatool auth login --email your@apple.id
ipatool download -b com.tencent.xin --purchase
```
Need to **downgrade an iOS app to an older version**?
```bash
ipatool version list -b com.tencent.xin
ipatool download -b com.tencent.xin --version-id 865432100
```
## Why `ipatool-rs`?
While upstream Go [ipatool](https://github.com/majd/ipatool) has also been updated for Apple's newer Store authentication, `ipatool-rs` takes a **fundamentally lighter, Rust-native engineering approach** focused on **low memory usage, fast execution, tiny binary size, and an interactive terminal UI**:
- **Lightweight C-ABI Signing vs. Full ObjC Runtime Emulation**: To satisfy Apple's `auth/v1/native` SAP and Store ADI (`X-Apple-AMD`) checks, upstream `ipatool` unpacks ~78 MB of macOS IPSW shared-cache images (`AppleMediaServices`, `adid`, `fairplayd`, `FairPlayIOKit`, etc.) and emulates an Objective-C/Swift runtime bridge on top of Go's GC heap. `ipatool-rs` instead drives self-contained C entry points (`CommerceKit`/`CoreFP` + ~4 MB Android `libCoreADI.so` with zero daemon, kernel, or ObjC runtime dependencies) inside Unicorn — cutting cached asset size nearly in half and keeping peak RAM usage minimal.
- **Constant-Memory Streaming & Zero-Recompression Patching**: Downloads stream directly to disk in small chunks (`O(1)` memory whether an IPA is 50 MB or 4 GB) with HTTP `Range` resume. When injecting `iTunesMetadata.plist` and SINF DRM data, `ipatool-rs` copies existing ZIP entries as raw compressed streams (`raw_copy_file`) without decompressing and re-deflating the payload.
- **~9× Smaller Distribution & Zero GC Overhead**: Prebuilt release archives are **~3 MB** (vs. **~25–27 MB** for upstream Go builds), compiled to native code with `rustls` (no OpenSSL dependency) and zero garbage-collector pauses.
- **Interactive TUI + Concurrent Download Queue**: Beyond scriptable CLI subcommands, running `ipatool` launches a full keyboard-driven terminal UI (`ratatui`) to search, claim free licenses, and manage multiple background downloads in one session.
### Common Use Cases
- **Downgrade iOS apps**: List historical `version-id` builds from Apple's servers and download older `.ipa` releases without needing discontinued iTunes 12.6.5.
- **Archive apps before delisting**: Keep local, patch-ready `.ipa` backups (with `iTunesMetadata.plist` and SINF injected) for devices authorized under your Apple ID.
- **Interactive terminal workflow**: Browse App Store results, inspect app details, claim free licenses, and monitor concurrent downloads in a keyboard-driven TUI.
- **Automation & CI pipelines**: Combine `--format json` and `--non-interactive` for low-overhead scripted metadata lookups and IPA retrieval.
### Comparison
| Aspect | [ipatool](https://github.com/majd/ipatool) (Go, v2.8+) | `ipatool-rs` (Rust) |
|--------|--------------------------------------------------------|---------------------|
| **Interactive TUI** | ❌ CLI only | ✅ Built-in keyboard-driven TUI + CLI |
| **Background download queue** | ❌ Single CLI invocation | ✅ Concurrent queue in TUI Downloads tab |
| **Release package size** | ~25–27 MB compressed | ✅ **~2.7–4.3 MB** compressed (~9× smaller) |
| **Memory model** | Go GC + ObjC runtime bridge heap | ✅ Zero-GC Rust + direct C-ABI shims (`O(1)` streaming RAM) |
| **Signing engine & cached assets** | ~78 MB macOS IPSW / dyld cache (`AppleMediaServices`, `fairplayd`, etc.) | ✅ ~42 MB standalone `CommerceKit` + self-contained `libCoreADI.so` |
| **IPA patching I/O** | Rewrites archive entries | ✅ Zero-recompression `raw_copy_file` stream copy |
| **Apple ID auth, 2FA & `X-Apple-AMD`** | ✅ Supported | ✅ Supported (with auto re-auth on expired token) |
| **Historical versions & Range resume** | ✅ Supported | ✅ Supported (`version list`, `--version-id`, Range resume) |
| **Credential storage** | Native OS keychain | ✅ Native OS keychain (macOS / Linux / Windows) |
| **Reusable core library** | Go internal/pkg modules | ✅ Standalone async `ipatool-core` crate (`tokio` + `rustls`) |
| **Scope** | Multi-platform packages (incl. macOS `.pkg`) + MCP | Focused, lightweight iOS `.ipa` TUI & CLI |
## Features
- **Interactive TUI mode**: Run `ipatool` with no arguments for Search, Library, Downloads, and Account tabs.
- **Signed sign-in & device proof**: Performs Apple's SAP handshake and Store ADI (`X-Apple-AMD`) device provisioning required by `auth/v1/native` since November 2026 — without redistributing Apple binaries.
- **Multi-storefront search**: Query App Store catalogs across any country code (`--country US`, `JP`, `CN`, etc.).
- **Zero-recompression IPA patching**: Injects purchase metadata (`iTunesMetadata.plist`) and SINF authorization data by copying compressed ZIP streams directly without re-deflating the app payload.
- **Resilient downloads & sessions**: Streams large IPA files with HTTP Range resume in CLI mode and automatic token refresh when stored credentials expire.
- **Script-friendly CLI**: Structured `--format json` output and `--non-interactive` mode for headless environments.
## Installation
### Homebrew (macOS / Linux)
```bash
brew install Kosthi/tap/ipatool-rs
```
### One-Line Installer (macOS / Linux / Windows)
```bash
# macOS / Linux
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/Kosthi/ipatool-rs/releases/latest/download/ipatool-rs-installer.sh | sh
```
```powershell
# Windows PowerShell
powershell -ExecutionPolicy Bypass -c "irm https://github.com/Kosthi/ipatool-rs/releases/latest/download/ipatool-rs-installer.ps1 | iex"
```
### Cargo / mise
```bash
# Install from source via Cargo
cargo install ipatool-rs
# Install prebuilt binary via cargo-binstall
cargo binstall ipatool-rs
# Or install prebuilt binary via mise (ubi backend)
mise use -g "ubi:Kosthi/ipatool-rs[exe=ipatool]"
```
### Prebuilt Release Binaries
Download archives directly from [GitHub Releases](https://github.com/Kosthi/ipatool-rs/releases):
| Platform | Asset | Install |
|----------|-------|---------|
| Windows x64 | `ipatool-rs-x86_64-pc-windows-msvc.zip` | Extract and place `ipatool.exe` on your `PATH`. |
| macOS Apple Silicon | `ipatool-rs-aarch64-apple-darwin.tar.xz` | Extract and place `ipatool` on your `PATH`. |
| macOS Intel | `ipatool-rs-x86_64-apple-darwin.tar.xz` | Extract and place `ipatool` on your `PATH`. |
| Linux x64 | `ipatool-rs-x86_64-unknown-linux-gnu.tar.xz` | Extract and place `ipatool` on your `PATH`. |
| Linux ARM64 | `ipatool-rs-aarch64-unknown-linux-gnu.tar.xz` | Extract and place `ipatool` on your `PATH`. |
Each release includes per-asset `.sha256` checksums and a unified `sha256.sum`.
### Build From Source
```bash
git clone https://github.com/Kosthi/ipatool-rs.git
cd ipatool-rs
cargo build --release
# Binary at target/release/ipatool
```
## Usage
### Terminal UI (TUI)
Launch the interactive TUI by running `ipatool` without subcommands:
```bash
ipatool
```
Built with [ratatui](https://ratatui.rs/) and [crossterm](https://github.com/crossterm-rs/crossterm), the TUI lets you sign in, search the App Store, acquire free licenses, and manage concurrent downloads from the keyboard.
#### Keyboard Controls
| Scope | Key | Action |
|-------|-----|--------|
| **Global** | `q` / `Ctrl+C` | Quit |
| | `Tab` / `Shift+Tab` | Switch tabs |
| | `1`–`4` | Jump directly to a tab |
| | `j` / `k` or `Up` / `Down` | Navigate the current list |
| | `Esc` | Cancel input or close popup |
| **Search tab** | `/` or `s` | Focus the search bar |
| | `Enter` | Run search |
| | `d` | Download selected app |
| | `p` | Purchase (obtain free license for) selected app |
| **Downloads tab** | `x` | Cancel selected download |
| | `c` | Clear finished downloads |
| **Account tab** | `l` | Log in |
| | `r` | Revoke stored credentials |
### CLI Usage
> [!NOTE]
> **First sign-in downloads ~50 MB once.** Apple requires sign-in and store requests to carry an action signature and a Store ADI device proof generated by Apple's own code (see [How It Works](#how-it-works)). Those components are fetched once via HTTP range requests, verified against pinned SHA-256 digests, and cached under `~/.ipatool/cache/` for all subsequent runs.
#### 1. Authenticate with Apple ID
```bash
# Interactive login (prompts securely for password and 2FA code if needed)
ipatool auth login --email your@apple.id
# Pass password / 2FA code directly
ipatool auth login --email your@apple.id --password 'password' --auth-code 123456
# Inspect active session & storefront
ipatool auth info
# Log out and remove stored credentials
ipatool auth revoke
```
#### 2. Search the App Store
```bash
ipatool search "WeChat" --limit 10
ipatool search "Telegram" --limit 5 --country US
```
#### 3. Obtain a Free License & Download IPAs
By default, IPAs are saved in the current directory as `{bundle_id}_{version_id}_{version}.ipa`. Pass `--purchase` to automatically claim a free license if your account does not own the app yet.
```bash
# Download latest IPA and auto-purchase free license if needed
ipatool download -b com.tencent.xin --purchase
# Custom output path
ipatool download -b com.tencent.xin --purchase -o ~/Downloads/wechat.ipa
# Download by numeric App ID
ipatool download -i 414478124 --purchase
# Obtain a free license without downloading
ipatool purchase -b com.tencent.xin
```
#### 4. List & Download Older App Versions (Downgrade)
```bash
# List all available external version IDs for an app
ipatool version list -b com.tencent.xin
# Inspect version metadata (display version string, release info)
ipatool version meta -b com.tencent.xin --version-id 865432100
# Download that exact historical version
ipatool download -b com.tencent.xin --version-id 865432100
```
#### Global Flags
```text
--format <text|json> Output format (default: text)
--verbose Enable debug logging
--non-interactive Disable interactive prompts (for scripts/CI)
```
## Migrating from `majd/ipatool`
`ipatool-rs` keeps familiar CLI semantics so existing scripts require minimal changes:
| Task | `majd/ipatool` (Go) | `ipatool-rs` |
|------|---------------------|--------------|
| Sign in | `ipatool auth login -e ...` | `ipatool auth login --email ...` |
| Account info | `ipatool auth info` | `ipatool auth info` |
| Sign out | `ipatool auth revoke` | `ipatool auth revoke` |
| Search apps | `ipatool search "term"` | `ipatool search "term" [--country US]` |
| Purchase free license | `ipatool purchase -b <bundle_id>` | `ipatool purchase -b <bundle_id>` |
| Download latest IPA | `ipatool download -b <bundle_id> --purchase` | `ipatool download -b <bundle_id> --purchase` |
| List older versions | `ipatool list-versions -b <bundle_id>` | `ipatool version list -b <bundle_id>` |
| Version metadata | `ipatool get-version-metadata ...` | `ipatool version meta -b <bundle_id> --version-id <id>` |
| Interactive TUI | *Not available* | `ipatool` |
## How It Works
1. **Auth & Device Proof** — Posts credentials to Apple's `auth/v1/native` endpoint with both an `X-Apple-ActionSignature` (SAP) and a Store-scoped `X-Apple-AMD` / `X-Apple-AMD-M` device proof, completing `otp/1.5/finish` provisioning automatically on first use. Handles 2FA, pod redirects, retry logic, OS keychain storage, and cookies.
Producing both proofs requires running Apple's own signing routines. On first use, `ipatool-rs`:
- HTTP range-reads a public OS X 10.9 update package (~33 MB of 1.27 GB) to extract `CommerceKit`, `CommerceCore`, and `CoreFP`;
- HTTP range-reads Apple's official Android Apple Music APK (~2 MB of 142 MB) to extract x86-64 `libCoreADI.so` and `libstoreservicescore.so`;
- Downloads a prebuilt [Unicorn](https://www.unicorn-engine.org/) CPU emulator and executes those x86-64 Mach-O and ELF binaries in-process with their external imports serviced directly from Rust.
Every artifact is verified against pinned SHA-256 digests before execution and cached under `~/.ipatool/cache/` (with persistent ADI provisioning state under `~/.ipatool/adi/`). **No Apple code is redistributed with this repository or its binaries.**
2. **Search / Lookup** — Queries the public iTunes Search API for app metadata and storefront-specific results.
3. **Purchase** — Sends a buy request to `buy.itunes.apple.com` with Store AMD headers and `STDQ` pricing, falling back to `GAME` for Apple Arcade-style responses.
4. **Download** — Requests the signed CDN URL and SINF DRM blobs from Apple's `volumeStoreDownloadProduct` endpoint with Store AMD headers, then streams the archive with HTTP Range resume support.
5. **Patch** — Rebuilds the ZIP archive on the fly, injecting `iTunesMetadata.plist` and `SC_Info/*.sinf` so the resulting `.ipa` installs cleanly on any device authorized for your Apple ID.
6. **TUI** — Wraps `ipatool-core` in an async `ratatui` + `crossterm` interface with non-blocking background workers for search, authentication, licensing, and queued downloads.
## Project Structure
```text
ipatool-rs/
|-- Cargo.toml # Workspace root
|-- media/ # README logo and TUI demo assets
`-- crates/
|-- ipatool-core/ # Reusable library crate
| `-- src/
| |-- adi/ # Store ADI (X-Apple-AMD) runtime & ELF loader
| |-- api/ # Apple Store API endpoints
| |-- client/ # HTTP client, plist parser, cookie jar
| |-- model/ # Account, App, Platform, StoreFront types
| |-- ipa/ # IPA patching & HTTP range ZIP reader
| |-- sap/ # SAP signing runtime, Mach-O loader & Unicorn engine
| |-- error.rs # Structured error hierarchy
| |-- credential.rs # Native OS keychain storage
| `-- guid.rs # Device GUID generation
`-- ipatool-cli/ # Binary crate (`ipatool`)
`-- src/
|-- main.rs # CLI entry point & clap definitions
|-- output.rs # Text / JSON formatters
|-- tui/ # Interactive ratatui terminal UI
`-- commands/ # Subcommand handlers
```
## FAQ
<details>
<summary><strong>Is my Apple ID password stored on disk?</strong></summary>
<br>
No. After a successful login, <code>ipatool-rs</code> stores a session <code>password_token</code> issued by Apple plus non-sensitive account metadata inside your OS keychain (macOS Keychain, Linux <code>libsecret</code>, or Windows Credential Manager) — never in a plain-text file. If you log in interactively, your password is never persisted; the keychain entry only stores a password when you explicitly pass <code>--password</code> on the CLI for unattended script re-authentication.
</details>
<details>
<summary><strong>Does this bypass DRM or violate Apple's Terms of Service?</strong></summary>
<br>
No. <code>ipatool-rs</code> downloads apps you have legitimately purchased or claimed a free license for, identical to downloading from the App Store. Downloaded IPAs retain FairPlay DRM tied to your Apple ID and will only install on devices authorized under that account. Review Apple's Terms of Service for your jurisdiction and use case.
</details>
<details>
<summary><strong>How does <code>ipatool-rs</code> keep memory and disk usage lower than other Store clients?</strong></summary>
<br>
Instead of extracting ~78 MB of macOS IPSW shared-cache frameworks (<code>AppleMediaServices</code>, <code>fairplayd</code>, <code>adid</code>) and emulating an Objective-C runtime, <code>ipatool-rs</code> drives compact, self-contained C libraries (<code>CommerceKit</code>/<code>CoreFP</code> + ~4 MB Android <code>libCoreADI.so</code>) directly in Unicorn. Downloads stream straight to disk in constant memory, and IPA patching uses raw ZIP stream copying (<code>raw_copy_file</code>) without decompressing or re-encoding multi-gigabyte app payloads.
</details>
<details>
<summary><strong>Why does the first login download ~50 MB?</strong></summary>
<br>
Generating valid SAP and Store ADI proofs requires executing Apple's own signing libraries. On first login, <code>ipatool-rs</code> range-reads ~35 MB of Apple packages plus a ~15 MB prebuilt Unicorn emulator, verifies every file against pinned SHA-256 hashes, and caches them in <code>~/.ipatool/cache/</code>. Subsequent runs start instantly.
</details>
<details>
<summary><strong>Login fails with "failed to establish a SAP signing session". How do I fix it?</strong></summary>
<br>
Re-run the command with <code>--verbose</code> to inspect the root cause. If integrity verification failed (usually caused by an interrupted network download), remove <code>~/.ipatool/cache/</code> and run <code>ipatool auth login</code> again. If the issue persists, please open an issue with the <code>--verbose</code> output (redacting your email).
</details>
<details>
<summary><strong>I get a 2FA prompt every time I run a command.</strong></summary>
<br>
Your stored session token has likely expired. Run <code>ipatool auth login</code> once to refresh credentials in your OS keychain. For automated scripts, pass <code>--non-interactive</code> after establishing a valid session.
</details>
<details>
<summary><strong>Which App Store countries / storefronts are supported?</strong></summary>
<br>
All storefronts supported by the iTunes Search API. Pass <code>--country <ISO-3166-1-alpha-2></code> (for example <code>--country US</code>, <code>--country JP</code>, <code>--country CN</code>) when searching. Downloads automatically use the storefront associated with your logged-in Apple ID.
</details>
## Star History
<a href="https://www.star-history.com/?type=date&repos=Kosthi%2Fipatool-rs">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=Kosthi/ipatool-rs&type=date&theme=dark&legend=top-left" />
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=Kosthi/ipatool-rs&type=date&legend=top-left" />
<img alt="Star History Chart" src="https://api.star-history.com/chart?repos=Kosthi/ipatool-rs&type=date&legend=top-left" />
</picture>
</a>
## License
Released under the [MIT License](LICENSE).