Compare commits

...
9 Commits
Author SHA1 Message Date
Majd Alfhaily f55e9ac53b Align version (1.0.3) 2021-05-25 23:51:20 +02:00
Majd Alfhaily a83dcb2849 Bump minimum supported macOS target to 10.15 2021-05-25 23:51:20 +02:00
Majd Alfhaily 6ff82c66aa Clean up commands 2021-05-25 23:47:52 +02:00
Majd Alfhaily c4610ca808 Add install instructions 2021-05-24 21:35:59 +02:00
Majd Alfhaily 1563a82a20 Align version (1.0.2) 2021-05-24 21:35:59 +02:00
Majd Alfhaily 48ed1df5c7 Handle invalid license errors 2021-05-24 21:35:59 +02:00
Majd Alfhaily 1448ca3ebc Add Makefile 2021-05-24 21:35:59 +02:00
Majd Alfhaily a3e483830f Align version (1.0.1) 2021-05-24 21:35:59 +02:00
Majd Alfhaily 8cfd902bbf Update readme 2021-05-24 21:35:59 +02:00
8 changed files with 184 additions and 75 deletions

No files matched your search

+1
View File
@@ -59,6 +59,7 @@ DerivedData/
*.ipa
*.dSYM.zip
*.dSYM
.build*
## Playgrounds
timeline.xctimeline
+17
View File
@@ -0,0 +1,17 @@
prefix ?= /usr/local
bindir = $(prefix)/bin
build:
xcodebuild -scheme ipatool -configuration release -archivePath .build archive
install: build
install -d "$(bindir)"
install ".build.xcarchive/Products/$(bindir)/ipatool" "$(bindir)"
uninstall:
rm -rf "$(bindir)/ipatool"
clean:
rm -rf .build.xcarchive
.PHONY: build install uninstall clean
+23 -7
View File
@@ -1,6 +1,7 @@
# IPATool
![Swift](https://img.shields.io/badge/Swift-5.x-green.svg)
![macOS](https://img.shields.io/badge/macOS-10.11%2B-green.svg)
[![Release](https://img.shields.io/github/release/majd/ipatool.svg)](https://GitHub.com/majd/ipatool/releases/)
![Swift](https://img.shields.io/badge/Swift-5.4-green.svg)
![macOS](https://img.shields.io/badge/macOS-10.15%2B-green.svg)
[![License](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/majd/ipatool/blob/main/LICENSE)
`ipatool` is a command line tool that allows you to search for iOS apps on the [App Store](https://apps.apple.com) and download a copy of the app package, known as an _ipa_ file.
@@ -8,9 +9,24 @@
![Demo](./demo.gif)
## Requirements
* macOS 10.11 or later.
* macOS 10.15 or later.
* Apple ID set up to use the App Store.
## Installation
### Manual Install
You can grab the latest version of `ipatool` from [GitHub releases](https://github.com/majd/ipatool/releases).
### Homebrew
You can install `ipatool` using [Homebrew](https://brew.sh).
```
$ brew tap majd/repo
$ brew install ipatool
```
## Usage
To search for apps on the App Store, use the `search` command.
@@ -18,14 +34,14 @@ To search for apps on the App Store, use the `search` command.
```
OVERVIEW: Search for iOS apps available on the App Store.
USAGE: ipatool search [--log-level <log-level>] [--limit <limit>] <term>
USAGE: ipatool search [--limit <limit>] <term> [--log-level <log-level>]
ARGUMENTS:
<term> The term to search for.
OPTIONS:
--log-level <log-level> (default: info)
--limit <limit> (default: 5)
--log-level <log-level> (default: info)
--version Show the version.
-h, --help Show help information.
```
@@ -58,11 +74,11 @@ The tool does not store your credentials anywhere and it only communicates with
**Will my Apple ID get flagged for using this tool?**
Maybe, but probably not. While this tool communicates with iTunes and the App Store directly, mimicking the behavior of iTunes running on macOS, I cannot guarrantee its safety. I recommend using a throwaway Apple ID. **Use this tool your own risk**.
Maybe, but probably not. While this tool communicates with iTunes and the App Store directly, mimicking the behavior of iTunes running on macOS, I cannot guarantee its safety. I recommend using a throwaway Apple ID. **Use this tool at your own risk**.
**Can I use this tool to download paid apps without paying for them?**
**No**. This is is not a piracy tool; you can only download apps that you have previously install on your iOS device. This limitation applies to free apps as well. Essentially, your account must already have a license for the app you are trying to download.
**No**. This is is not a piracy tool; you can only download apps that you have previously installed on your iOS device. This limitation applies to free apps as well. Essentially, your account must already have a license for the app you are trying to download.
**Can I use this tool to sideload unuspported iOS apps on Apple Silicon Macs?**
+121 -54
View File
@@ -16,37 +16,29 @@ struct Download: ParsableCommand {
@Option(name: [.short, .long], help: "The bundle identifier of the target iOS app.")
private var bundleIdentifier: String
@Option(name: [.short, .long], help: "The email address for the Apple ID.")
private var email: String?
@Option(name: [.short, .customLong("email")], help: "The email address for the Apple ID.")
private var emailArgument: String?
@Option(name: [.short, .long], help: "The password for the Apple ID.")
private var password: String?
@Option(name: [.short, .customLong("password")], help: "The password for the Apple ID.")
private var passwordArgument: String?
@Option
private var logLevel: LogLevel = .info
lazy var logger = ConsoleLogger(level: logLevel)
}
extension Download {
func run() throws {
let logger = ConsoleLogger(level: logLevel)
mutating func app(with bundleIdentifier: String) -> iTunesResponse.Result {
logger.log("Creating HTTP client...", level: .debug)
let httpClient = HTTPClient(urlSession: URLSession.shared)
logger.log("Creating iTunes client...", level: .debug)
let itunesClient = iTunesClient(httpClient: httpClient)
logger.log("Creating App Store client...", level: .debug)
let storeClient = StoreClient(httpClient: httpClient)
logger.log("Creating download client...", level: .debug)
let downloadClient = HTTPDownloadClient()
logger.log("Querying the iTunes store for '\(bundleIdentifier)'...", level: .info)
let app: iTunesResponse.Result
do {
app = try itunesClient.lookup(bundleIdentifier: bundleIdentifier)
logger.log("Querying the iTunes Store for '\(bundleIdentifier)'...", level: .info)
return try itunesClient.lookup(bundleIdentifier: bundleIdentifier)
} catch {
logger.log("\(error)", level: .debug)
@@ -59,45 +51,51 @@ extension Download {
_exit(1)
}
logger.log("Found app: \(app.name) (\(app.version)).", level: .debug)
let email: String
let password: String
if let cliEmail = self.email {
email = cliEmail
} else if let envEmail = ProcessInfo.processInfo.environment["IPATOOL_EMAIL"] {
email = envEmail
} else if let inputEmail = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter Apple ID email: ", level: .warning)))) {
email = inputEmail
}
mutating func email() -> String {
if let email = emailArgument {
return email
} else if let email = ProcessInfo.processInfo.environment["IPATOOL_EMAIL"] {
return email
} else if let email = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter Apple ID email: ", level: .warning)))) {
return email
} else {
logger.log("An Apple ID email address is required.", level: .error)
_exit(1)
}
if let cliPassword = self.password {
password = cliPassword
} else if let envPassword = ProcessInfo.processInfo.environment["IPATOOL_PASSWORD"] {
password = envPassword
} else if let inputPassword = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter Apple ID password: ", level: .warning)))) {
password = inputPassword
}
mutating func password() -> String {
if let password = passwordArgument {
return password
} else if let password = ProcessInfo.processInfo.environment["IPATOOL_PASSWORD"] {
return password
} else if let password = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter Apple ID password: ", level: .warning)))) {
return password
} else {
logger.log("An Apple ID password is required.", level: .error)
_exit(1)
}
}
mutating func authenticate(email: String, password: String) -> StoreResponse.Account {
logger.log("Creating HTTP client...", level: .debug)
let httpClient = HTTPClient(urlSession: URLSession.shared)
let account: StoreResponse.Account
logger.log("Creating App Store client...", level: .debug)
let storeClient = StoreClient(httpClient: httpClient)
do {
logger.log("Authenticating with the App Store...", level: .info)
account = try storeClient.authenticate(email: email, password: password)
return try storeClient.authenticate(email: email, password: password)
} catch {
switch error {
case StoreResponse.Error.codeRequired:
let code = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter 2FA code: ", level: .warning))))
do {
account = try storeClient.authenticate(email: email, password: password, code: code)
return try storeClient.authenticate(email: email, password: password, code: code)
} catch {
logger.log("\(error)", level: .debug)
@@ -135,32 +133,101 @@ extension Download {
_exit(1)
}
}
}
mutating func item(from app: iTunesResponse.Result, account: StoreResponse.Account) -> StoreResponse.Item {
logger.log("Creating HTTP client...", level: .debug)
let httpClient = HTTPClient(urlSession: URLSession.shared)
logger.log("Creating App Store client...", level: .debug)
let storeClient = StoreClient(httpClient: httpClient)
do {
logger.log("Requesting a signed copy of '\(app.identifier)' from the App Store...", level: .info)
return try storeClient.item(identifier: "\(app.identifier)", directoryServicesIdentifier: account.directoryServicesIdentifier)
} catch {
logger.log("\(error)", level: .debug)
switch error {
case StoreClient.Error.invalidResponse:
logger.log("Received invalid response.", level: .error)
case StoreResponse.Error.invalidItem:
logger.log("Received invalid store item.", level: .error)
case StoreResponse.Error.invalidLicense:
logger.log("Your Apple ID does not have a license for this app. Download the app on an iOS device to obtain a license.", level: .error)
default:
logger.log("An unknown error has occurred.", level: .error)
}
_exit(1)
}
}
mutating func download(item: StoreResponse.Item, to targetURL: URL) {
logger.log("Creating download client...", level: .debug)
let downloadClient = HTTPDownloadClient()
do {
logger.log("Downloading app package...", level: .info)
try downloadClient.download(from: item.url, to: targetURL) { [logger] progress in
logger.log("Downloading app package... [\(Int((progress * 100).rounded()))%]",
prefix: "\u{1B}[1A\u{1B}[K",
level: .info)
}
} catch {
logger.log("\(error)", level: .debug)
logger.log("An error has occurred while downloading the app package.", level: .error)
_exit(1)
}
}
mutating func applyPatches(item: StoreResponse.Item, email: String, path: String) {
logger.log("Creating signature client...", level: .debug)
let signatureClient = SignatureClient(fileManager: .default, filePath: path)
do {
logger.log("Applying patches...", level: .info)
try signatureClient.appendMetadata(item: item, email: email)
try signatureClient.appendSignature(item: item)
} catch {
logger.log("\(error)", level: .debug)
logger.log("Failed to apply patches. The ipa file will be left incomplete.", level: .error)
_exit(1)
}
}
mutating func run() throws {
// Query for app
let app: iTunesResponse.Result = app(with: bundleIdentifier)
logger.log("Found app: \(app.name) (\(app.version)).", level: .debug)
// Get Apple ID email
let email: String = email()
// Get Apple ID password
let password: String = password()
// Authenticate with the App Store
let account: StoreResponse.Account = authenticate(email: email, password: password)
logger.log("Authenticated as '\(account.firstName) \(account.lastName)'.", level: .info)
logger.log("Requesting a signed copy of '\(app.identifier)' from the App Store...", level: .info)
let item = try storeClient.item(identifier: "\(app.identifier)", directoryServicesIdentifier: account.directoryServicesIdentifier)
// Query for store item
let item: StoreResponse.Item = item(from: app, account: account)
logger.log("Received a response of the signed copy: \(item.md5).", level: .debug)
logger.log("Creating signature client...", level: .debug)
// Generate file name
let path = FileManager.default.currentDirectoryPath
.appending("/\(bundleIdentifier)_\(app.identifier)_v\(app.version)_\(Int.random(in: 100...999))")
.appending(".ipa")
logger.log("Output path: \(path).", level: .debug)
let signatureClient = SignatureClient(fileManager: .default, filePath: path)
logger.log("Downloading app package...", level: .info)
try downloadClient.download(from: item.url, to: URL(fileURLWithPath: path)) { progress in
logger.log("Downloading app package... [\(Int((progress * 100).rounded()))%]",
prefix: "\u{1B}[1A\u{1B}[K",
level: .info)
}
// Download app package
download(item: item, to: URL(fileURLWithPath: path))
logger.log("Saved app package to \(URL(fileURLWithPath: path).lastPathComponent).", level: .info)
logger.log("Applying patches...", level: .info)
try signatureClient.appendMetadata(item: item, email: email)
try signatureClient.appendSignature(item: item)
// Apply patches
applyPatches(item: item, email: email, path: path)
logger.log("Done.", level: .info)
}
}
+1 -1
View File
@@ -11,7 +11,7 @@ struct IPATool: ParsableCommand {
static var configuration: CommandConfiguration {
return .init(commandName: "ipatool",
abstract: "A cli tool for interacting with Apple's ipa files.",
version: "1.0.0",
version: "1.0.3",
subcommands: [Download.self, Search.self])
}
}
+17 -9
View File
@@ -21,12 +21,12 @@ struct Search: ParsableCommand {
@Option
private var logLevel: LogLevel = .info
lazy var logger = ConsoleLogger(level: logLevel)
}
extension Search {
func run() throws {
let logger = ConsoleLogger(level: logLevel)
mutating func results(with term: String) -> [iTunesResponse.Result] {
logger.log("Creating HTTP client...", level: .debug)
let httpClient = HTTPClient(urlSession: URLSession.shared)
@@ -41,17 +41,25 @@ extension Search {
logger.log("No results found.", level: .error)
_exit(1)
}
let output = results
.enumerated()
.map({ "\($0 + 1). \($1.name): \($1.bundleIdentifier) (\($1.version))." })
.joined(separator: "\n")
logger.log("Found \(results.count) \(results.count == 1 ? "result" : "results"):\n\(output)", level: .info)
return results
} catch {
logger.log("\(error)", level: .debug)
logger.log("An unknown error has occurred.", level: .error)
_exit(1)
}
}
mutating func run() throws {
// Search the iTunes store
let results = results(with: term)
// Compile output
let output = results
.enumerated()
.map({ "\($0 + 1). \($1.name): \($1.bundleIdentifier) (\($1.version))." })
.joined(separator: "\n")
logger.log("Found \(results.count) \(results.count == 1 ? "result" : "results"):\n\(output)", level: .info)
}
}
+2 -2
View File
@@ -397,7 +397,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.15;
PRODUCT_NAME = ipatool;
SWIFT_VERSION = 5.0;
};
@@ -407,7 +407,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
MACOSX_DEPLOYMENT_TARGET = 10.11;
MACOSX_DEPLOYMENT_TARGET = 10.15;
PRODUCT_NAME = ipatool;
SWIFT_VERSION = 5.0;
};
@@ -56,7 +56,7 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "download com.apple.TestFlight"
argument = "download -b com.apple.TestFlight"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
@@ -64,7 +64,7 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "search TestFlight --limit 1"
argument = "search TestFlight --limit 5"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>