mirror of
https://github.com/majd/ipatool
synced 2026-11-28 18:27:52 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3040955de1 | ||
|
|
f0c7e02db9 | ||
|
|
cd54b3bbcb | ||
|
|
82f70f23c7 | ||
|
|
96115462d0 | ||
|
|
1b65463007 | ||
|
|
dba1d3b195 | ||
|
|
eee3416b67 | ||
|
|
2f3b0330e0 | ||
|
|
b257a5c8b1 | ||
|
|
df45f1cc44 | ||
|
|
a92c829fb7 | ||
|
|
7569f89208 | ||
|
|
8003c042f4 | ||
|
|
74165461cb | ||
|
|
fdccf874b9 | ||
|
|
29731ec0b1 | ||
|
|
97edbccc58 | ||
|
|
1463c85279 | ||
|
|
7d8531b3e0 | ||
|
|
7507290769 | ||
|
|
644d6a7104 | ||
|
|
dfd2709d2a | ||
|
|
e3adde06b3 | ||
|
|
fc49c7af91 | ||
|
|
234ee2fe52 | ||
|
|
b030cd454f | ||
|
|
f3a54098ea | ||
|
|
69c07d0062 | ||
|
|
f0922b303e | ||
|
|
5a4d2f5e8d | ||
|
|
972f0b2cd0 | ||
|
|
03993b2b93 | ||
|
|
5009048d44 | ||
|
|
59fb28cee0 | ||
|
|
5f1fb02a12 | ||
|
|
32c6012918 | ||
|
|
f55e9ac53b | ||
|
|
a83dcb2849 | ||
|
|
6ff82c66aa | ||
|
|
c4610ca808 | ||
|
|
1563a82a20 | ||
|
|
48ed1df5c7 | ||
|
|
1448ca3ebc | ||
|
|
a3e483830f | ||
|
|
8cfd902bbf | ||
|
|
8165331378 | ||
|
|
bed12a55a9 | ||
|
|
73a416c917 |
No files matched your search
@@ -0,0 +1,86 @@
|
||||
name: Distribute
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
get_version:
|
||||
name: Get version
|
||||
runs-on: ubuntu-20.04
|
||||
steps:
|
||||
- name: Set output
|
||||
id: set_output
|
||||
run: echo ::set-output name=version::${GITHUB_REF#refs/tags/v}
|
||||
outputs:
|
||||
version: ${{ steps.set_output.outputs.version }}
|
||||
test:
|
||||
name: Run tests
|
||||
runs-on: macos-12
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Inject version
|
||||
run: ./Scripts/version
|
||||
- name: Build
|
||||
run: swift build
|
||||
- name: Run tests
|
||||
run: swift test
|
||||
build:
|
||||
name: Build
|
||||
runs-on: macos-12
|
||||
needs: [get_version, test]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Inject version
|
||||
run: ./Scripts/version
|
||||
- name: Build
|
||||
run: make build
|
||||
- name: Upload binary
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: ipatool-v${{ needs.get_version.outputs.version }}
|
||||
path: .build/ipatool
|
||||
if-no-files-found: error
|
||||
distribute:
|
||||
name: Distribute
|
||||
runs-on: ubuntu-20.04
|
||||
needs: [get_version, build]
|
||||
steps:
|
||||
- name: Download binary
|
||||
uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: ipatool-v${{ needs.get_version.outputs.version }}
|
||||
path: ipatool-v${{ needs.get_version.outputs.version }}
|
||||
- name: Archive binary
|
||||
run: |
|
||||
mv ipatool-v${{ needs.get_version.outputs.version }}/ipatool ipatool
|
||||
zip ipatool-v${{ needs.get_version.outputs.version }}.zip ipatool
|
||||
- name: Upload binary to release
|
||||
uses: svenstaro/upload-release-action@v2
|
||||
with:
|
||||
repo_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
file: ipatool-v${{ needs.get_version.outputs.version }}.zip
|
||||
asset_name: ipatool-v${{ needs.get_version.outputs.version }}.zip
|
||||
tag: ${{ github.ref }}
|
||||
overwrite: false
|
||||
- name: Checkout homebrew repo
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
repository: ${{ secrets.HOMEBREW_REPO }}
|
||||
path: repo
|
||||
ref: main
|
||||
token: ${{ secrets.GH_TOKEN }}
|
||||
- name: Update homebrew repo
|
||||
run: |
|
||||
SHA256=$(sha256sum ipatool-v${{ needs.get_version.outputs.version }}.zip | awk '{print $1}')
|
||||
cd repo
|
||||
sed -i "3s/.*/ sha256 \"$SHA256\"/" Casks/ipatool.rb
|
||||
sed -i "2s/.*/ version \"${{ needs.get_version.outputs.version }}\"/" Casks/ipatool.rb
|
||||
git config --local user.name ${{ secrets.GH_NAME }}
|
||||
git config --local user.email ${{ secrets.GH_EMAIL }}
|
||||
git add Casks/ipatool.rb
|
||||
git commit -m "Update ipatool to v${{ needs.get_version.outputs.version }}"
|
||||
git push "https://${{ secrets.GH_TOKEN }}@github.com/${{ secrets.HOMEBREW_REPO }}.git" --set-upstream "main"
|
||||
@@ -0,0 +1,49 @@
|
||||
name: Integration Tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
runs-on: macos-12
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Inject version
|
||||
run: ./Scripts/version
|
||||
- name: Build
|
||||
run: make build
|
||||
- name: Upload binary
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: ipatool
|
||||
path: .build/ipatool
|
||||
if-no-files-found: error
|
||||
test:
|
||||
name: Test
|
||||
runs-on: ${{ matrix.macos }}
|
||||
needs: [build]
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
macos: [macos-10.15, macos-11, macos-12]
|
||||
command: [auth, download, purchase, search]
|
||||
steps:
|
||||
- name: Download binary
|
||||
uses: actions/download-artifact@v2
|
||||
with:
|
||||
name: ipatool
|
||||
path: ipatool-current
|
||||
- name: Update permissions
|
||||
run: chmod +x ./ipatool-current/ipatool
|
||||
- name: Install Swift toolchain
|
||||
run: |
|
||||
wget https://download.swift.org/swift-5.5.3-release/xcode/swift-5.5.3-RELEASE/swift-5.5.3-RELEASE-osx.pkg
|
||||
sudo installer -pkg swift-5.5.3-RELEASE-osx.pkg -target /
|
||||
- name: Run tests
|
||||
run: |
|
||||
export DYLD_LIBRARY_PATH=/Library/Developer/Toolchains/swift-5.5.3-RELEASE.xctoolchain/usr/lib/swift/macosx
|
||||
./ipatool-current/ipatool ${{ matrix.command }} --help
|
||||
@@ -0,0 +1,20 @@
|
||||
name: Unit Tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
test-networking:
|
||||
name: Test Networking
|
||||
runs-on: macos-12
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
- name: Inject version
|
||||
run: ./Scripts/version
|
||||
- name: Build
|
||||
run: swift build
|
||||
- name: Run tests
|
||||
run: swift test --filter NetworkingTests
|
||||
+5
-61
@@ -1,4 +1,3 @@
|
||||
### macOS ###
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
@@ -7,7 +6,6 @@
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
@@ -27,11 +25,6 @@ Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### Swift ###
|
||||
# Xcode
|
||||
#
|
||||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
||||
|
||||
## User settings
|
||||
xcuserdata/
|
||||
|
||||
@@ -59,67 +52,18 @@ DerivedData/
|
||||
*.ipa
|
||||
*.dSYM.zip
|
||||
*.dSYM
|
||||
.build*
|
||||
|
||||
## Playgrounds
|
||||
timeline.xctimeline
|
||||
playground.xcworkspace
|
||||
|
||||
# Swift Package Manager
|
||||
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
|
||||
# Packages/
|
||||
# Package.pins
|
||||
# Package.resolved
|
||||
# *.xcodeproj
|
||||
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
|
||||
# hence it is not needed unless you have added a package configuration file to your project
|
||||
# .swiftpm
|
||||
|
||||
/Packages
|
||||
/*.xcodeproj
|
||||
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
|
||||
.build/
|
||||
|
||||
# CocoaPods
|
||||
# We recommend against adding the Pods directory to your .gitignore. However
|
||||
# you should judge for yourself, the pros and cons are mentioned at:
|
||||
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
||||
# Pods/
|
||||
# Add this line if you want to avoid checking in source code from the Xcode workspace
|
||||
# *.xcworkspace
|
||||
|
||||
# Carthage
|
||||
# Add this line if you want to avoid checking in source code from Carthage dependencies.
|
||||
# Carthage/Checkouts
|
||||
|
||||
Carthage/Build/
|
||||
|
||||
# Add this lines if you are using Accio dependency management (Deprecated since Xcode 12)
|
||||
# Dependencies/
|
||||
# .accio/
|
||||
|
||||
# fastlane
|
||||
# It is recommended to not store the screenshots in the git repo.
|
||||
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
|
||||
# For more information about the recommended setup visit:
|
||||
# https://docs.fastlane.tools/best-practices/source-control/#source-control
|
||||
|
||||
fastlane/report.xml
|
||||
fastlane/Preview.html
|
||||
fastlane/screenshots/**/*.png
|
||||
fastlane/test_output
|
||||
|
||||
# Code Injection
|
||||
# After new code Injection tools there's a generated folder /iOSInjectionProject
|
||||
# https://github.com/johnno1962/injectionforxcode
|
||||
|
||||
iOSInjectionProject/
|
||||
|
||||
### Xcode ###
|
||||
# Xcode
|
||||
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
|
||||
|
||||
|
||||
|
||||
|
||||
## Gcc Patch
|
||||
/*.gcno
|
||||
Sources/CLI/Package.swift
|
||||
|
||||
### Xcode Patch ###
|
||||
*.xcodeproj/*
|
||||
|
||||
@@ -0,0 +1,156 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1320"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Networking"
|
||||
BuildableName = "Networking"
|
||||
BlueprintName = "Networking"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "StoreAPI"
|
||||
BuildableName = "StoreAPI"
|
||||
BlueprintName = "StoreAPI"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "ipatool"
|
||||
BuildableName = "ipatool"
|
||||
BlueprintName = "ipatool"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "NO"
|
||||
buildForArchiving = "NO"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "NetworkingTests"
|
||||
BuildableName = "NetworkingTests"
|
||||
BlueprintName = "NetworkingTests"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "CLI"
|
||||
BuildableName = "CLI"
|
||||
BlueprintName = "CLI"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "Persistence"
|
||||
BuildableName = "Persistence"
|
||||
BlueprintName = "Persistence"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "NetworkingTests"
|
||||
BuildableName = "NetworkingTests"
|
||||
BlueprintName = "NetworkingTests"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "ipatool"
|
||||
BuildableName = "ipatool"
|
||||
BlueprintName = "ipatool"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "ipatool"
|
||||
BuildableName = "ipatool"
|
||||
BlueprintName = "ipatool"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
+21
-22
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1250"
|
||||
LastUpgradeVersion = "1320"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
@@ -14,10 +14,10 @@
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "A9CA48BD2658F93F00BC09D5"
|
||||
BuildableName = "IPATool"
|
||||
BlueprintName = "IPATool"
|
||||
ReferencedContainer = "container:ipatool.xcodeproj">
|
||||
BlueprintIdentifier = "Networking"
|
||||
BuildableName = "Networking"
|
||||
BlueprintName = "Networking"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
@@ -28,6 +28,16 @@
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "NetworkingTests"
|
||||
BuildableName = "NetworkingTests"
|
||||
BlueprintName = "NetworkingTests"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
@@ -40,16 +50,6 @@
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "A9CA48BD2658F93F00BC09D5"
|
||||
BuildableName = "IPATool"
|
||||
BlueprintName = "IPATool"
|
||||
ReferencedContainer = "container:ipatool.xcodeproj">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
@@ -57,16 +57,15 @@
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "A9CA48BD2658F93F00BC09D5"
|
||||
BuildableName = "IPATool"
|
||||
BlueprintName = "IPATool"
|
||||
ReferencedContainer = "container:ipatool.xcodeproj">
|
||||
BlueprintIdentifier = "Networking"
|
||||
BuildableName = "Networking"
|
||||
BlueprintName = "Networking"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</MacroExpansion>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1320"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "StoreAPI"
|
||||
BuildableName = "StoreAPI"
|
||||
BlueprintName = "StoreAPI"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<MacroExpansion>
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "StoreAPI"
|
||||
BuildableName = "StoreAPI"
|
||||
BlueprintName = "StoreAPI"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</MacroExpansion>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
@@ -0,0 +1,102 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1320"
|
||||
version = "1.3">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
buildImplicitDependencies = "YES">
|
||||
<BuildActionEntries>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "YES"
|
||||
buildForArchiving = "YES"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "ipatool"
|
||||
BuildableName = "ipatool"
|
||||
BlueprintName = "ipatool"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
<BuildActionEntry
|
||||
buildForTesting = "YES"
|
||||
buildForRunning = "YES"
|
||||
buildForProfiling = "NO"
|
||||
buildForArchiving = "NO"
|
||||
buildForAnalyzing = "YES">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "NetworkingTests"
|
||||
BuildableName = "NetworkingTests"
|
||||
BlueprintName = "NetworkingTests"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildActionEntry>
|
||||
</BuildActionEntries>
|
||||
</BuildAction>
|
||||
<TestAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES">
|
||||
<Testables>
|
||||
<TestableReference
|
||||
skipped = "NO">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "NetworkingTests"
|
||||
BuildableName = "NetworkingTests"
|
||||
BlueprintName = "NetworkingTests"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</TestableReference>
|
||||
</Testables>
|
||||
</TestAction>
|
||||
<LaunchAction
|
||||
buildConfiguration = "Debug"
|
||||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
|
||||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
|
||||
launchStyle = "0"
|
||||
useCustomWorkingDirectory = "NO"
|
||||
ignoresPersistentStateOnLaunch = "NO"
|
||||
debugDocumentVersioning = "YES"
|
||||
debugServiceExtension = "internal"
|
||||
allowLocationSimulation = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "ipatool"
|
||||
BuildableName = "ipatool"
|
||||
BlueprintName = "ipatool"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
buildConfiguration = "Release"
|
||||
shouldUseLaunchSchemeArgsEnv = "YES"
|
||||
savedToolIdentifier = ""
|
||||
useCustomWorkingDirectory = "NO"
|
||||
debugDocumentVersioning = "YES">
|
||||
<BuildableProductRunnable
|
||||
runnableDebuggingMode = "0">
|
||||
<BuildableReference
|
||||
BuildableIdentifier = "primary"
|
||||
BlueprintIdentifier = "ipatool"
|
||||
BuildableName = "ipatool"
|
||||
BlueprintName = "ipatool"
|
||||
ReferencedContainer = "container:">
|
||||
</BuildableReference>
|
||||
</BuildableProductRunnable>
|
||||
</ProfileAction>
|
||||
<AnalyzeAction
|
||||
buildConfiguration = "Debug">
|
||||
</AnalyzeAction>
|
||||
<ArchiveAction
|
||||
buildConfiguration = "Release"
|
||||
revealArchiveInOrganizer = "YES">
|
||||
</ArchiveAction>
|
||||
</Scheme>
|
||||
@@ -0,0 +1,19 @@
|
||||
prefix ?= /usr/local
|
||||
bindir = $(prefix)/bin
|
||||
|
||||
build:
|
||||
swift build --product ipatool --configuration release --triple arm64-apple-macosx
|
||||
swift build --product ipatool --configuration release --triple x86_64-apple-macosx
|
||||
lipo -create -output .build/ipatool .build/arm64-apple-macosx/release/ipatool .build/x86_64-apple-macosx/release/ipatool
|
||||
|
||||
install: build
|
||||
install -d "$(bindir)"
|
||||
install ".build/ipatool" "$(bindir)"
|
||||
|
||||
uninstall:
|
||||
rm -rf "$(bindir)/ipatool"
|
||||
|
||||
clean:
|
||||
rm -rf .build
|
||||
|
||||
.PHONY: build install uninstall clean
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"object": {
|
||||
"pins": [
|
||||
{
|
||||
"package": "KeychainAccess",
|
||||
"repositoryURL": "https://github.com/kishikawakatsumi/KeychainAccess",
|
||||
"state": {
|
||||
"branch": "v4.2.2",
|
||||
"revision": "84e546727d66f1adc5439debad16270d0fdd04e7",
|
||||
"version": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "swift-argument-parser",
|
||||
"repositoryURL": "https://github.com/apple/swift-argument-parser",
|
||||
"state": {
|
||||
"branch": "1.0.2",
|
||||
"revision": "e1465042f195f374b94f915ba8ca49de24300a0d",
|
||||
"version": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"package": "ZIPFoundation",
|
||||
"repositoryURL": "https://github.com/weichsel/ZIPFoundation",
|
||||
"state": {
|
||||
"branch": "0.9.14",
|
||||
"revision": "7254c74b49cec2cb81520523ba993c671f71b066",
|
||||
"version": null
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"version": 1
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// swift-tools-version:5.5
|
||||
|
||||
import PackageDescription
|
||||
|
||||
let package = Package(
|
||||
name: "IPATool",
|
||||
platforms: [.macOS(.v10_15)],
|
||||
products: [
|
||||
.executable(name: "ipatool", targets: ["CLI"]),
|
||||
.library(name: "StoreAPI", targets: ["StoreAPI"]),
|
||||
.library(name: "Networking", targets: ["Networking"]),
|
||||
.library(name: "Persistence", targets: ["Persistence"])
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/apple/swift-argument-parser", revision: "1.0.2"),
|
||||
.package(url: "https://github.com/weichsel/ZIPFoundation", revision: "0.9.14"),
|
||||
.package(url: "https://github.com/kishikawakatsumi/KeychainAccess", revision: "v4.2.2")
|
||||
],
|
||||
targets: [
|
||||
.executableTarget(
|
||||
name: "CLI",
|
||||
dependencies: [
|
||||
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
||||
.byName(name: "Networking"),
|
||||
.byName(name: "StoreAPI"),
|
||||
.byName(name: "Persistence")
|
||||
]
|
||||
),
|
||||
.target(
|
||||
name: "StoreAPI",
|
||||
dependencies: [
|
||||
.product(name: "ArgumentParser", package: "swift-argument-parser"),
|
||||
.product(name: "ZIPFoundation", package: "ZIPFoundation"),
|
||||
.byName(name: "Networking"),
|
||||
]
|
||||
),
|
||||
.target(name: "Networking", dependencies: []),
|
||||
.testTarget(name: "NetworkingTests", dependencies: ["Networking"]),
|
||||
.target(name: "Persistence", dependencies: [
|
||||
.byName(name: "KeychainAccess")
|
||||
]),
|
||||
]
|
||||
)
|
||||
@@ -0,0 +1,131 @@
|
||||
# IPATool
|
||||
|
||||
[](https://GitHub.com/majd/ipatool/releases/)
|
||||
[](https://github.com/majd/ipatool/blob/main/LICENSE)
|
||||
[](https://github.com/majd/ipatool/actions/workflows/unit-tests.yml)
|
||||
[](https://github.com/majd/ipatool/actions/workflows/integration-tests.yml)
|
||||

|
||||

|
||||
|
||||
`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.
|
||||
|
||||

|
||||
|
||||
- [Requirements](#requirements)
|
||||
- [Installation](#installation)
|
||||
- [Manual](#manual)
|
||||
- [Homebrew](#homebrew)
|
||||
- [Usage](#usage)
|
||||
- [FAQ](https://github.com/majd/ipatool/wiki/FAQ)
|
||||
- [License](#license)
|
||||
|
||||
## Requirements
|
||||
|
||||
- macOS 10.15 or later.
|
||||
- Apple ID set up to use the App Store.
|
||||
|
||||
## Installation
|
||||
|
||||
### Manual
|
||||
|
||||
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 authenticate with the App Store, use the `auth` command.
|
||||
|
||||
```
|
||||
OVERVIEW: Authenticate with the App Store.
|
||||
|
||||
USAGE: ipatool auth <subcommand>
|
||||
|
||||
OPTIONS:
|
||||
--version Show the version.
|
||||
-h, --help Show help information.
|
||||
|
||||
SUBCOMMANDS:
|
||||
login Login to the App Store.
|
||||
revoke Revoke your App Store credentials.
|
||||
|
||||
See 'ipatool help auth <subcommand>' for detailed help.
|
||||
```
|
||||
|
||||
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 <term> [--limit <limit>] [--country <country>] [--device-family <device-family>] [--log-level <log-level>]
|
||||
|
||||
ARGUMENTS:
|
||||
<term> The term to search for.
|
||||
|
||||
OPTIONS:
|
||||
-l, --limit <limit> The maximum amount of search results to retrieve.
|
||||
(default: 5)
|
||||
-c, --country <country> The two-letter (ISO 3166-1 alpha-2) country code for
|
||||
the iTunes Store. (default: US)
|
||||
-d, --device-family <device-family>
|
||||
The device family to limit the search query to.
|
||||
(default: iPhone)
|
||||
--log-level <log-level> The log level. (default: info)
|
||||
--version Show the version.
|
||||
-h, --help Show help information.
|
||||
```
|
||||
|
||||
To obtain a license for an app, use the `purchase` command.
|
||||
|
||||
```
|
||||
OVERVIEW: Obtain a license for the app from the App Store.
|
||||
|
||||
USAGE: ipatool purchase --bundle-identifier <bundle-identifier> [--country <country>] [--device-family <device-family>] [--log-level <log-level>]
|
||||
|
||||
OPTIONS:
|
||||
-b, --bundle-identifier <bundle-identifier>
|
||||
The bundle identifier of the target iOS app.
|
||||
-c, --country <country> The two-letter (ISO 3166-1 alpha-2) country code for
|
||||
the iTunes Store. (default: US)
|
||||
-d, --device-family <device-family>
|
||||
The device family to limit the search query to.
|
||||
(default: iPhone)
|
||||
--log-level <log-level> The log level. (default: info)
|
||||
--version Show the version.
|
||||
-h, --help Show help information.
|
||||
```
|
||||
|
||||
To download a copy of the ipa file, use the `download` command.
|
||||
|
||||
```
|
||||
OVERVIEW: Download (encrypted) iOS app packages from the App Store.
|
||||
|
||||
USAGE: ipatool download --bundle-identifier <bundle-identifier> [--country <country>] [--device-family <device-family>] [--output <output>] [--log-level <log-level>] [--purchase]
|
||||
|
||||
OPTIONS:
|
||||
-b, --bundle-identifier <bundle-identifier>
|
||||
The bundle identifier of the target iOS app.
|
||||
-c, --country <country> The two-letter (ISO 3166-1 alpha-2) country code for
|
||||
the iTunes Store. (default: US)
|
||||
-d, --device-family <device-family>
|
||||
The device family to limit the search query to.
|
||||
(default: iPhone)
|
||||
-o, --output <output> The destination path of the downloaded app package.
|
||||
--log-level <log-level> The log level. (default: info)
|
||||
--purchase Obtain a license for the app if needed.
|
||||
--version Show the version.
|
||||
-h, --help Show help information.
|
||||
```
|
||||
|
||||
**Note:** You can specify the Apple ID email address and username as arguments when using the tool or by setting them as environment variables (`IPATOOL_EMAIL` and `IPATOOL_PASSWORD`). If you do not specify this information using either of those methods, the tool will prompt for user input in an interactive session. Similarly, you can supply the 2FA code interactively or using the environment variable `IPATOOL_2FA_CODE`.
|
||||
|
||||
## License
|
||||
|
||||
IPATool is released under the [MIT license](https://github.com/majd/ipatool/blob/main/LICENSE).
|
||||
Executable
+13
@@ -0,0 +1,13 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
VERSION=$(git describe --abbrev=0 --tags | cut -c 2-)
|
||||
|
||||
cat <<EOF >"$PWD/Sources/CLI/Package.swift"
|
||||
// Automatically generated
|
||||
|
||||
enum Package {
|
||||
static let version = "${VERSION}"
|
||||
}
|
||||
EOF
|
||||
|
||||
echo "Version ${VERSION}"
|
||||
@@ -1,166 +0,0 @@
|
||||
//
|
||||
// Download.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
|
||||
struct Download: ParsableCommand {
|
||||
static var configuration: CommandConfiguration {
|
||||
return .init(abstract: "Download (encrypted) iOS app packages from the App Store.")
|
||||
}
|
||||
|
||||
@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, .long], help: "The password for the Apple ID.")
|
||||
private var password: String?
|
||||
|
||||
@Option
|
||||
private var logLevel: LogLevel = .info
|
||||
}
|
||||
|
||||
extension Download {
|
||||
func run() throws {
|
||||
let logger = ConsoleLogger(level: logLevel)
|
||||
|
||||
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)
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
|
||||
switch error {
|
||||
case iTunesClient.Error.appNotFound:
|
||||
logger.log("Could not find app.", level: .error)
|
||||
default:
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
}
|
||||
|
||||
_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
|
||||
} 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
|
||||
} else {
|
||||
logger.log("An Apple ID password is required.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
|
||||
let account: StoreResponse.Account
|
||||
|
||||
do {
|
||||
logger.log("Authenticating with the App Store...", level: .info)
|
||||
account = 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)
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
|
||||
switch error {
|
||||
case StoreClient.Error.invalidResponse:
|
||||
logger.log("Received invalid response.", level: .error)
|
||||
case StoreResponse.Error.invalidAccount:
|
||||
logger.log("This Apple ID has not been set up to use the App Store.", level: .error)
|
||||
case StoreResponse.Error.invalidCredentials:
|
||||
logger.log("Invalid credentials.", level: .error)
|
||||
case StoreResponse.Error.lockedAccount:
|
||||
logger.log("This Apple ID has been disabled for security reasons.", level: .error)
|
||||
default:
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
}
|
||||
|
||||
_exit(1)
|
||||
}
|
||||
default:
|
||||
logger.log("\(error)", level: .debug)
|
||||
|
||||
switch error {
|
||||
case StoreClient.Error.invalidResponse:
|
||||
logger.log("Received invalid response.", level: .error)
|
||||
case StoreResponse.Error.invalidAccount:
|
||||
logger.log("This Apple ID has not been set up to use the App Store.", level: .error)
|
||||
case StoreResponse.Error.invalidCredentials:
|
||||
logger.log("Invalid credentials.", level: .error)
|
||||
case StoreResponse.Error.lockedAccount:
|
||||
logger.log("This Apple ID has been disabled for security reasons.", level: .error)
|
||||
default:
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
}
|
||||
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
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)
|
||||
logger.log("Received a response of the signed copy: \(item.md5).", level: .debug)
|
||||
|
||||
logger.log("Creating signature client...", level: .debug)
|
||||
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)
|
||||
}
|
||||
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)
|
||||
|
||||
logger.log("Done.", level: .info)
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
//
|
||||
// Search.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
|
||||
struct Search: ParsableCommand {
|
||||
static var configuration: CommandConfiguration {
|
||||
return .init(abstract: "Search for iOS apps available on the App Store.")
|
||||
}
|
||||
|
||||
@Option
|
||||
private var logLevel: LogLevel = .info
|
||||
|
||||
@Option
|
||||
private var limit: Int = 5
|
||||
|
||||
@Argument(help: "The term to search for.")
|
||||
var term: String
|
||||
}
|
||||
|
||||
extension Search {
|
||||
func run() throws {
|
||||
let logger = ConsoleLogger(level: logLevel)
|
||||
|
||||
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)
|
||||
|
||||
do {
|
||||
logger.log("Searching for '\(term)'...", level: .info)
|
||||
let results = try itunesClient.search(term: term, limit: limit)
|
||||
|
||||
guard !results.isEmpty else {
|
||||
logger.log("No results found.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
|
||||
logger.log("Found \(results.count) results:\n\(results.enumerated().map({ "\($0 + 1). \($1.name): \($1.bundleIdentifier) (\($1.version))." }).joined(separator: "\n"))", level: .info)
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
//
|
||||
// IPATool.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import ArgumentParser
|
||||
|
||||
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",
|
||||
subcommands: [Download.self, Search.self])
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
//
|
||||
// HTTPClient.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol HTTPClientInterface {
|
||||
func send(_ request: HTTPRequest, completion: @escaping (Result<HTTPResponse, Error>) -> Void)
|
||||
}
|
||||
|
||||
extension HTTPClientInterface {
|
||||
func send(_ request: HTTPRequest) throws -> HTTPResponse {
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
var result: Result<HTTPResponse, Error>?
|
||||
|
||||
send(request) {
|
||||
result = $0
|
||||
semaphore.signal()
|
||||
}
|
||||
|
||||
_ = semaphore.wait(timeout: .distantFuture)
|
||||
|
||||
switch result {
|
||||
case .none:
|
||||
throw HTTPClient.Error.timeout
|
||||
case let .failure(error):
|
||||
throw error
|
||||
case let .success(response):
|
||||
return response
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class HTTPClient: HTTPClientInterface {
|
||||
private let urlSession: URLSessionInterface
|
||||
|
||||
init(urlSession: URLSessionInterface) {
|
||||
self.urlSession = urlSession
|
||||
}
|
||||
|
||||
func send(_ request: HTTPRequest, completion: @escaping (Result<HTTPResponse, Swift.Error>) -> Void) {
|
||||
do {
|
||||
let urlRequest = try makeURLRequest(from: request)
|
||||
|
||||
urlSession.dataTask(with: urlRequest) { (data, response, error) in
|
||||
if let error = error {
|
||||
return completion(.failure(error))
|
||||
}
|
||||
|
||||
guard let response = response as? HTTPURLResponse else {
|
||||
return completion(.failure(Error.invalidResponse(response)))
|
||||
}
|
||||
|
||||
completion(.success(.init(statusCode: response.statusCode, data: data)))
|
||||
}.resume()
|
||||
} catch {
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
|
||||
private func makeURLRequest(from request: HTTPRequest) throws -> URLRequest {
|
||||
var urlRequest = URLRequest(url: request.endpoint.url)
|
||||
urlRequest.httpMethod = request.method.rawValue
|
||||
|
||||
switch request.payload {
|
||||
case .none:
|
||||
urlRequest.httpBody = nil
|
||||
case let .urlEncoding(propertyList):
|
||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||
|
||||
var urlComponents = URLComponents(string: request.endpoint.url.absoluteString)
|
||||
urlComponents?.queryItems = !propertyList.isEmpty ? propertyList.map { URLQueryItem(name: $0.0, value: $0.1.description) } : nil
|
||||
|
||||
switch request.method {
|
||||
case .get:
|
||||
urlRequest.url = urlComponents?.url
|
||||
case .post:
|
||||
urlRequest.httpBody = urlComponents?.percentEncodedQuery?.data(using: .utf8, allowLossyConversion: false)
|
||||
}
|
||||
case let .xml(value):
|
||||
urlRequest.setValue("application/xml", forHTTPHeaderField: "Content-Type")
|
||||
urlRequest.httpBody = try PropertyListSerialization.data(fromPropertyList: value, format: .xml, options: 0)
|
||||
}
|
||||
|
||||
request.headers.forEach { urlRequest.setValue($0.value, forHTTPHeaderField: $0.key) }
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
extension HTTPClient {
|
||||
enum Error: Swift.Error {
|
||||
case invalidResponse(URLResponse?)
|
||||
case timeout
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
//
|
||||
// HTTPDownloadClient.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol HTTPDownloadClientInterface {
|
||||
func download(from source: URL, to target: URL, progress: @escaping (Float) -> Void, completion: @escaping (Result<Void, Error>) -> Void)
|
||||
}
|
||||
|
||||
extension HTTPDownloadClientInterface {
|
||||
func download(from source: URL, to target: URL, progress: @escaping (Float) -> Void) throws {
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
var result: Result<Void, Error>?
|
||||
|
||||
download(from: source, to: target, progress: progress) {
|
||||
result = $0
|
||||
semaphore.signal()
|
||||
}
|
||||
|
||||
_ = semaphore.wait(timeout: .distantFuture)
|
||||
|
||||
switch result {
|
||||
case .none:
|
||||
throw HTTPClient.Error.timeout
|
||||
case let .failure(error):
|
||||
throw error
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class HTTPDownloadClient: NSObject, HTTPDownloadClientInterface {
|
||||
private var urlSession: URLSession!
|
||||
private var progressHandler: ((Float) -> Void)?
|
||||
private var completionHandler: ((Result<Void, Swift.Error>) -> Void)?
|
||||
private var targetURL: URL?
|
||||
|
||||
override init() {
|
||||
super.init()
|
||||
self.urlSession = URLSession(configuration: .default, delegate: self, delegateQueue: nil)
|
||||
}
|
||||
|
||||
func download(from source: URL, to target: URL, progress: @escaping (Float) -> Void, completion: @escaping (Result<Void, Swift.Error>) -> Void) {
|
||||
assert(progressHandler == nil)
|
||||
assert(completionHandler == nil)
|
||||
assert(targetURL == nil)
|
||||
|
||||
progressHandler = progress
|
||||
completionHandler = completion
|
||||
targetURL = target
|
||||
urlSession.downloadTask(with: source).resume()
|
||||
}
|
||||
}
|
||||
|
||||
extension HTTPDownloadClient: URLSessionDownloadDelegate {
|
||||
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didWriteData bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) {
|
||||
progressHandler?(Float(totalBytesWritten) / Float(totalBytesExpectedToWrite))
|
||||
}
|
||||
|
||||
func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
|
||||
defer {
|
||||
progressHandler = nil
|
||||
completionHandler = nil
|
||||
targetURL = nil
|
||||
}
|
||||
|
||||
guard let target = targetURL else {
|
||||
return completionHandler?(.failure(Error.invalidTarget)) ?? ()
|
||||
}
|
||||
|
||||
do {
|
||||
try FileManager.default.moveItem(at: location, to: target)
|
||||
completionHandler?(.success(()))
|
||||
} catch {
|
||||
completionHandler?(.failure(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension HTTPDownloadClient {
|
||||
enum Error: Swift.Error {
|
||||
case invalidTarget
|
||||
}
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
//
|
||||
// URLSession.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol URLSessionInterface {
|
||||
func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask
|
||||
}
|
||||
|
||||
extension URLSession: URLSessionInterface {}
|
||||
@@ -1,156 +0,0 @@
|
||||
//
|
||||
// StoreClient.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol StoreClientInterface {
|
||||
func authenticate(email: String, password: String, code: String?, completion: @escaping (Result<StoreResponse.Account, Error>) -> Void)
|
||||
func item(identifier: String, directoryServicesIdentifier: String, completion: @escaping (Result<StoreResponse.Item, Error>) -> Void)
|
||||
}
|
||||
|
||||
extension StoreClientInterface {
|
||||
func authenticate(email: String,
|
||||
password: String,
|
||||
code: String? = nil,
|
||||
completion: @escaping (Result<StoreResponse.Account, Swift.Error>) -> Void) {
|
||||
authenticate(email: email, password: password, code: code, completion: completion)
|
||||
}
|
||||
|
||||
func authenticate(email: String, password: String, code: String? = nil) throws -> StoreResponse.Account {
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
var result: Result<StoreResponse.Account, Error>?
|
||||
|
||||
authenticate(email: email, password: password, code: code) {
|
||||
result = $0
|
||||
semaphore.signal()
|
||||
}
|
||||
|
||||
_ = semaphore.wait(timeout: .distantFuture)
|
||||
|
||||
switch result {
|
||||
case .none:
|
||||
throw StoreClient.Error.timeout
|
||||
case let .failure(error):
|
||||
throw error
|
||||
case let .success(result):
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
func item(identifier: String, directoryServicesIdentifier: String) throws -> StoreResponse.Item {
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
var result: Result<StoreResponse.Item, Error>?
|
||||
|
||||
item(identifier: identifier, directoryServicesIdentifier: directoryServicesIdentifier) {
|
||||
result = $0
|
||||
semaphore.signal()
|
||||
}
|
||||
|
||||
_ = semaphore.wait(timeout: .distantFuture)
|
||||
|
||||
switch result {
|
||||
case .none:
|
||||
throw StoreClient.Error.timeout
|
||||
case let .failure(error):
|
||||
throw error
|
||||
case let .success(result):
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class StoreClient: StoreClientInterface {
|
||||
private let httpClient: HTTPClient
|
||||
|
||||
init(httpClient: HTTPClient) {
|
||||
self.httpClient = httpClient
|
||||
}
|
||||
|
||||
func authenticate(email: String, password: String, code: String?, completion: @escaping (Result<StoreResponse.Account, Swift.Error>) -> Void) {
|
||||
authenticate(email: email,
|
||||
password: password,
|
||||
code: code,
|
||||
isFirstAttempt: true,
|
||||
completion: completion)
|
||||
}
|
||||
|
||||
private func authenticate(email: String,
|
||||
password: String,
|
||||
code: String?,
|
||||
isFirstAttempt: Bool,
|
||||
completion: @escaping (Result<StoreResponse.Account, Swift.Error>) -> Void) {
|
||||
let request = StoreRequest.authenticate(email: email, password: password, code: code)
|
||||
|
||||
httpClient.send(request) { [weak self] result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
do {
|
||||
let decoded = try response.decode(StoreResponse.self, as: .xml)
|
||||
|
||||
switch decoded {
|
||||
case let .account(account):
|
||||
completion(.success(account))
|
||||
case .item:
|
||||
completion(.failure(Error.invalidResponse))
|
||||
case let .failure(error):
|
||||
switch error {
|
||||
case StoreResponse.Error.invalidCredentials:
|
||||
if isFirstAttempt {
|
||||
return self?.authenticate(email: email,
|
||||
password: password,
|
||||
code: code,
|
||||
isFirstAttempt: false,
|
||||
completion: completion) ?? ()
|
||||
}
|
||||
|
||||
completion(.failure(error))
|
||||
default:
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
completion(.failure(error))
|
||||
}
|
||||
case let .failure(error):
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func item(identifier: String, directoryServicesIdentifier: String, completion: @escaping (Result<StoreResponse.Item, Swift.Error>) -> Void) {
|
||||
let request = StoreRequest.download(appIdentifier: identifier, directoryServicesIdentifier: directoryServicesIdentifier)
|
||||
|
||||
httpClient.send(request) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
do {
|
||||
let decoded = try response.decode(StoreResponse.self, as: .xml)
|
||||
|
||||
switch decoded {
|
||||
case let .item(item):
|
||||
completion(.success(item))
|
||||
case .account:
|
||||
completion(.failure(Error.invalidResponse))
|
||||
case let .failure(error):
|
||||
completion(.failure(error))
|
||||
}
|
||||
} catch {
|
||||
completion(.failure(error))
|
||||
}
|
||||
case let .failure(error):
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension StoreClient {
|
||||
enum Error: Swift.Error {
|
||||
case timeout
|
||||
case invalidResponse
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
//
|
||||
// StoreResponse.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum StoreResponse {
|
||||
case failure(error: Swift.Error)
|
||||
case account(Account)
|
||||
case item(Item)
|
||||
}
|
||||
|
||||
extension StoreResponse {
|
||||
struct Account {
|
||||
let firstName: String
|
||||
let lastName: String
|
||||
let directoryServicesIdentifier: String
|
||||
}
|
||||
|
||||
struct Item {
|
||||
let url: URL
|
||||
let md5: String
|
||||
let signatures: [Signature]
|
||||
let metadata: [String: Any]
|
||||
}
|
||||
|
||||
enum Error: Int, Swift.Error {
|
||||
case unknownError = 0
|
||||
case genericError = 5002
|
||||
case codeRequired = 1
|
||||
case invalidLicense = 9610
|
||||
case invalidCredentials = -5000
|
||||
case invalidAccount = 5001
|
||||
case invalidItem = -10000
|
||||
case lockedAccount = -10001
|
||||
}
|
||||
}
|
||||
|
||||
extension StoreResponse: Decodable {
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
let error = try container.decodeIfPresent(String.self, forKey: .error)
|
||||
let message = try container.decodeIfPresent(String.self, forKey: .message)
|
||||
|
||||
if container.contains(.account) {
|
||||
let directoryServicesIdentifier = try container.decode(String.self, forKey: .directoryServicesIdentifier)
|
||||
let accountContainer = try container.nestedContainer(keyedBy: AccountInfoCodingKeys.self, forKey: .account)
|
||||
let addressContainer = try accountContainer.nestedContainer(keyedBy: AddressCodingKeys.self, forKey: .address)
|
||||
let firstName = try addressContainer.decode(String.self, forKey: .firstName)
|
||||
let lastName = try addressContainer.decode(String.self, forKey: .lastName)
|
||||
|
||||
self = .account(.init(firstName: firstName, lastName: lastName, directoryServicesIdentifier: directoryServicesIdentifier))
|
||||
} else if let items = try container.decodeIfPresent([Item].self, forKey: .items), let item = items.first {
|
||||
self = .item(item)
|
||||
} else if let error = error, !error.isEmpty {
|
||||
self = .failure(error: Error(rawValue: Int(error) ?? 0) ?? .unknownError)
|
||||
} else {
|
||||
switch message {
|
||||
case "Your account information was entered incorrectly.":
|
||||
self = .failure(error: Error.invalidCredentials)
|
||||
case "An Apple ID verification code is required to sign in. Type your password followed by the verification code shown on your other devices.":
|
||||
self = .failure(error: Error.codeRequired)
|
||||
case "This Apple ID has been locked for security reasons. Visit iForgot to reset your account (https://iforgot.apple.com).":
|
||||
self = .failure(error: Error.lockedAccount)
|
||||
default:
|
||||
self = .failure(error: Error.unknownError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case directoryServicesIdentifier = "dsPersonId"
|
||||
case message = "customerMessage"
|
||||
case items = "songList"
|
||||
case error = "failureType"
|
||||
case account = "accountInfo"
|
||||
}
|
||||
|
||||
private enum AccountInfoCodingKeys: String, CodingKey {
|
||||
case address
|
||||
}
|
||||
|
||||
private enum AddressCodingKeys: String, CodingKey {
|
||||
case firstName
|
||||
case lastName
|
||||
}
|
||||
}
|
||||
|
||||
extension StoreResponse.Item: Decodable {
|
||||
init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
let md5 = try container.decode(String.self, forKey: .md5)
|
||||
|
||||
guard let key = CodingUserInfoKey(rawValue: "data"),
|
||||
let data = decoder.userInfo[key] as? Data,
|
||||
let json = try PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [String: Any],
|
||||
let items = json["songList"] as? [[String: Any]],
|
||||
let item = items.first(where: { $0["md5"] as? String == md5 }),
|
||||
let metadata = item["metadata"] as? [String: Any]
|
||||
else { throw StoreResponse.Error.invalidItem }
|
||||
|
||||
let absoluteUrl = try container.decode(String.self, forKey: .url)
|
||||
|
||||
self.md5 = md5
|
||||
self.metadata = metadata
|
||||
self.signatures = try container.decode([Signature].self, forKey: .signatures)
|
||||
|
||||
if let url = URL(string: absoluteUrl) {
|
||||
self.url = url
|
||||
} else {
|
||||
let context = DecodingError.Context(codingPath: [CodingKeys.url], debugDescription: "URL contains illegal characters: \(absoluteUrl).")
|
||||
throw DecodingError.keyNotFound(CodingKeys.url, context)
|
||||
}
|
||||
}
|
||||
|
||||
struct Signature: Decodable {
|
||||
let id: Int
|
||||
let sinf: Data
|
||||
}
|
||||
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case url = "URL"
|
||||
case metadata
|
||||
case md5
|
||||
case signatures = "sinfs"
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
//
|
||||
// iTunesClient.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol iTunesClientInterface {
|
||||
func lookup(bundleIdentifier: String, completion: @escaping (Result<iTunesResponse.Result, Error>) -> Void)
|
||||
func search(term: String, limit: Int, completion: @escaping (Result<[iTunesResponse.Result], Error>) -> Void)
|
||||
}
|
||||
|
||||
extension iTunesClientInterface {
|
||||
func lookup(bundleIdentifier: String) throws -> iTunesResponse.Result {
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
var result: Result<iTunesResponse.Result, Error>?
|
||||
|
||||
lookup(bundleIdentifier: bundleIdentifier) {
|
||||
result = $0
|
||||
semaphore.signal()
|
||||
}
|
||||
|
||||
_ = semaphore.wait(timeout: .distantFuture)
|
||||
|
||||
switch result {
|
||||
case .none:
|
||||
throw iTunesClient.Error.timeout
|
||||
case let .failure(error):
|
||||
throw error
|
||||
case let .success(result):
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
func search(term: String, limit: Int) throws -> [iTunesResponse.Result] {
|
||||
let semaphore = DispatchSemaphore(value: 0)
|
||||
var result: Result<[iTunesResponse.Result], Error>?
|
||||
|
||||
search(term: term, limit: limit) {
|
||||
result = $0
|
||||
semaphore.signal()
|
||||
}
|
||||
|
||||
_ = semaphore.wait(timeout: .distantFuture)
|
||||
|
||||
switch result {
|
||||
case .none:
|
||||
throw iTunesClient.Error.timeout
|
||||
case let .failure(error):
|
||||
throw error
|
||||
case let .success(result):
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final class iTunesClient: iTunesClientInterface {
|
||||
private let httpClient: HTTPClient
|
||||
|
||||
init(httpClient: HTTPClient) {
|
||||
self.httpClient = httpClient
|
||||
}
|
||||
|
||||
func lookup(bundleIdentifier: String, completion: @escaping (Result<iTunesResponse.Result, Swift.Error>) -> Void) {
|
||||
let request = iTunesRequest.lookup(bundleIdentifier: bundleIdentifier)
|
||||
|
||||
httpClient.send(request) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
do {
|
||||
let decoded = try response.decode(iTunesResponse.self, as: .json)
|
||||
guard let result = decoded.results.first else { return completion(.failure(Error.appNotFound)) }
|
||||
completion(.success(result))
|
||||
} catch {
|
||||
completion(.failure(error))
|
||||
}
|
||||
case let .failure(error):
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func search(term: String, limit: Int, completion: @escaping (Result<[iTunesResponse.Result], Swift.Error>) -> Void) {
|
||||
let request = iTunesRequest.search(term: term, limit: limit)
|
||||
|
||||
httpClient.send(request) { result in
|
||||
switch result {
|
||||
case let .success(response):
|
||||
do {
|
||||
let decoded = try response.decode(iTunesResponse.self, as: .json)
|
||||
completion(.success(decoded.results))
|
||||
} catch {
|
||||
completion(.failure(error))
|
||||
}
|
||||
case let .failure(error):
|
||||
completion(.failure(error))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension iTunesClient {
|
||||
enum Error: Swift.Error {
|
||||
case timeout
|
||||
case appNotFound
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
//
|
||||
// iTunesRequest.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum iTunesRequest {
|
||||
case search(term: String, limit: Int)
|
||||
case lookup(bundleIdentifier: String)
|
||||
}
|
||||
|
||||
extension iTunesRequest: HTTPRequest {
|
||||
var method: HTTPMethod {
|
||||
return .get
|
||||
}
|
||||
|
||||
var endpoint: HTTPEndpoint {
|
||||
switch self {
|
||||
case .lookup:
|
||||
return iTunesEndpoint.lookup
|
||||
case .search:
|
||||
return iTunesEndpoint.search
|
||||
}
|
||||
}
|
||||
|
||||
var payload: HTTPPayload? {
|
||||
switch self {
|
||||
case let .lookup(bundleIdentifier):
|
||||
return .urlEncoding(["media": "software", "bundleId": bundleIdentifier, "limit": "1"])
|
||||
case let .search(term, limit):
|
||||
return .urlEncoding(["media": "software", "term": term, "limit": "\(limit)"])
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
//
|
||||
// main.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
IPATool.main()
|
||||
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// AsyncSupport.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 04.01.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import ArgumentParser
|
||||
|
||||
protocol AsyncParsableCommand: ParsableCommand {
|
||||
mutating func run() async throws
|
||||
}
|
||||
|
||||
extension AsyncParsableCommand {
|
||||
mutating func run() throws {
|
||||
throw CleanExit.helpRequest(self)
|
||||
}
|
||||
}
|
||||
|
||||
protocol AsyncMain {
|
||||
associatedtype Command: ParsableCommand
|
||||
}
|
||||
|
||||
extension AsyncMain {
|
||||
static func main() async {
|
||||
do {
|
||||
var command = try Command.parseAsRoot()
|
||||
if var command = command as? AsyncParsableCommand {
|
||||
try await command.run()
|
||||
} else {
|
||||
try command.run()
|
||||
}
|
||||
} catch {
|
||||
Command.exit(withError: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
//
|
||||
// Auth.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 21.03.22.
|
||||
//
|
||||
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
import Networking
|
||||
import StoreAPI
|
||||
import Persistence
|
||||
|
||||
struct Auth: AsyncParsableCommand {
|
||||
static var configuration: CommandConfiguration {
|
||||
return .init(
|
||||
commandName: "auth",
|
||||
abstract: "Authenticate with the App Store.",
|
||||
subcommands: [Login.self, Revoke.self],
|
||||
defaultSubcommand: nil
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
extension Auth {
|
||||
struct Login: AsyncParsableCommand {
|
||||
static var configuration: CommandConfiguration {
|
||||
return .init(abstract: "Login to the App Store.")
|
||||
}
|
||||
|
||||
@Option(name: [.short, .customLong("email")], help: "The email address for the Apple ID.")
|
||||
private var emailArgument: String?
|
||||
|
||||
@Option(name: [.short, .customLong("password")], help: "The password for the Apple ID.")
|
||||
private var passwordArgument: String?
|
||||
|
||||
@Option(name: [.customLong("auth-code")], help: "The 2FA code for the Apple ID.")
|
||||
private var authCodeArgument: String?
|
||||
|
||||
@Option(name: [.long], help: "The log level.")
|
||||
private var logLevel: LogLevel = .info
|
||||
|
||||
lazy var logger = ConsoleLogger(level: logLevel)
|
||||
}
|
||||
|
||||
struct Revoke: AsyncParsableCommand {
|
||||
static var configuration: CommandConfiguration {
|
||||
return .init(abstract: "Revoke your App Store credentials.")
|
||||
}
|
||||
|
||||
@Option(name: [.long], help: "The log level.")
|
||||
private var logLevel: LogLevel = .info
|
||||
|
||||
lazy var logger = ConsoleLogger(level: logLevel)
|
||||
}
|
||||
}
|
||||
|
||||
extension Auth.Login {
|
||||
private 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)
|
||||
}
|
||||
}
|
||||
|
||||
private 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)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func authCode() -> String {
|
||||
if let authCode = authCodeArgument {
|
||||
return authCode
|
||||
} else if let authCode = ProcessInfo.processInfo.environment["IPATOOL_2FA_CODE"] {
|
||||
return authCode
|
||||
} else if let authCode = String(validatingUTF8: UnsafePointer<CChar>(getpass(logger.compile("Enter 2FA code: ", level: .warning)))) {
|
||||
return authCode
|
||||
} else {
|
||||
logger.log("A 2FA auth-code is required.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func authenticate(email: String, password: String) async -> Account {
|
||||
logger.log("Creating HTTP client...", level: .debug)
|
||||
let httpClient = HTTPClient(session: URLSession.shared)
|
||||
|
||||
logger.log("Creating App Store client...", level: .debug)
|
||||
let storeClient = StoreClient(httpClient: httpClient)
|
||||
|
||||
do {
|
||||
logger.log("Authenticating with the App Store...", level: .info)
|
||||
let account = try await storeClient.authenticate(email: email, password: password, code: nil)
|
||||
return Account(
|
||||
name: "\(account.firstName) \(account.lastName)",
|
||||
email: email,
|
||||
passwordToken: account.passwordToken,
|
||||
directoryServicesIdentifier: account.directoryServicesIdentifier
|
||||
)
|
||||
} catch {
|
||||
switch error {
|
||||
case StoreResponse.Error.codeRequired:
|
||||
do {
|
||||
let account = try await storeClient.authenticate(email: email, password: password, code: authCode())
|
||||
return Account(
|
||||
name: "\(account.firstName) \(account.lastName)",
|
||||
email: email,
|
||||
passwordToken: account.passwordToken,
|
||||
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.invalidAccount:
|
||||
logger.log("This Apple ID has not been set up to use the App Store.", level: .error)
|
||||
case StoreResponse.Error.invalidCredentials:
|
||||
logger.log("Invalid credentials.", level: .error)
|
||||
case StoreResponse.Error.lockedAccount:
|
||||
logger.log("This Apple ID has been disabled for security reasons.", level: .error)
|
||||
default:
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
}
|
||||
|
||||
_exit(1)
|
||||
}
|
||||
default:
|
||||
logger.log("\(error)", level: .debug)
|
||||
|
||||
switch error {
|
||||
case StoreClient.Error.invalidResponse:
|
||||
logger.log("Received invalid response.", level: .error)
|
||||
case StoreResponse.Error.invalidAccount:
|
||||
logger.log("This Apple ID has not been set up to use the App Store.", level: .error)
|
||||
case StoreResponse.Error.invalidCredentials:
|
||||
logger.log("Invalid credentials.", level: .error)
|
||||
case StoreResponse.Error.lockedAccount:
|
||||
logger.log("This Apple ID has been disabled for security reasons.", level: .error)
|
||||
default:
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
}
|
||||
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mutating func run() async throws {
|
||||
// Get Apple ID email
|
||||
let email: String = email()
|
||||
|
||||
// Get Apple ID password
|
||||
let password: String = password()
|
||||
|
||||
// Authenticate with the App Store
|
||||
let account: Account = await authenticate(email: email, password: password)
|
||||
|
||||
// Store data in keychain
|
||||
do {
|
||||
let keychainStore = KeychainStore(service: "ipatool.service")
|
||||
try keychainStore.setValue(account, forKey: "account")
|
||||
|
||||
logger.log("Authenticated as '\(account.name)'.", level: .info)
|
||||
} catch {
|
||||
logger.log("Failed to save account data in keychain.", level: .error)
|
||||
logger.log("\(error)", level: .debug)
|
||||
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Auth.Revoke {
|
||||
mutating func run() async throws {
|
||||
let keychainStore = KeychainStore(service: "ipatool.service")
|
||||
|
||||
guard let account: Account = try keychainStore.value(forKey: "account") else {
|
||||
logger.log("No credentials available to revoke.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
|
||||
try keychainStore.remove("account")
|
||||
logger.log("Revoked credentials for '\(account.name)'.", level: .info)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,249 @@
|
||||
//
|
||||
// Download.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
import Networking
|
||||
import StoreAPI
|
||||
import Persistence
|
||||
|
||||
struct Download: AsyncParsableCommand {
|
||||
static var configuration: CommandConfiguration {
|
||||
return .init(abstract: "Download (encrypted) iOS app packages from the App Store.")
|
||||
}
|
||||
|
||||
@Option(name: [.short, .long], help: "The bundle identifier of the target iOS app.")
|
||||
private var bundleIdentifier: String
|
||||
|
||||
@Option(
|
||||
name: [.customShort("c"), .customLong("country")],
|
||||
help: "The two-letter (ISO 3166-1 alpha-2) country code for the iTunes Store."
|
||||
)
|
||||
private var countryCode: String = "US"
|
||||
|
||||
@Option(name: [.short, .long], help: "The device family to limit the search query to.")
|
||||
private var deviceFamily: DeviceFamily = .phone
|
||||
|
||||
@Option(name: [.short, .long], help: "The destination path of the downloaded app package.")
|
||||
private var output: String?
|
||||
|
||||
@Option(name: [.long], help: "The log level.")
|
||||
private var logLevel: LogLevel = .info
|
||||
|
||||
@Flag(name: .long, help: "Obtain a license for the app if needed.")
|
||||
private var purchase: Bool = false
|
||||
|
||||
lazy var logger = ConsoleLogger(level: logLevel)
|
||||
}
|
||||
|
||||
extension Download {
|
||||
private mutating func app(with bundleIdentifier: String, countryCode: String) async -> iTunesResponse.Result {
|
||||
logger.log("Creating HTTP client...", level: .debug)
|
||||
let httpClient = HTTPClient(session: URLSession.shared)
|
||||
|
||||
logger.log("Creating iTunes client...", level: .debug)
|
||||
let itunesClient = iTunesClient(httpClient: httpClient)
|
||||
|
||||
do {
|
||||
logger.log("Querying the iTunes Store for '\(bundleIdentifier)' in country '\(countryCode)'...", level: .info)
|
||||
return try await itunesClient.lookup(
|
||||
bundleIdentifier: bundleIdentifier,
|
||||
countryCode: countryCode,
|
||||
deviceFamily: deviceFamily
|
||||
)
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
|
||||
switch error {
|
||||
case iTunesClient.Error.appNotFound:
|
||||
logger.log("Could not find app.", level: .error)
|
||||
default:
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
}
|
||||
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private mutating func purchase(app: iTunesResponse.Result, account: Account) async {
|
||||
guard app.price == 0 else {
|
||||
logger.log("It is only possible to obtain a license for free apps. Purchase the app manually and run the \"download\" command again.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
|
||||
logger.log("Creating HTTP client...", level: .debug)
|
||||
let httpClient = HTTPClient(session: URLSession.shared)
|
||||
|
||||
logger.log("Creating App Store client...", level: .debug)
|
||||
let storeClient = StoreClient(httpClient: httpClient)
|
||||
|
||||
do {
|
||||
logger.log("Obtaining a license for '\(app.identifier)' from the App Store...", level: .info)
|
||||
try await storeClient.purchase(
|
||||
identifier: "\(app.identifier)",
|
||||
directoryServicesIdentifier: account.directoryServicesIdentifier,
|
||||
passwordToken: account.passwordToken,
|
||||
countryCode: countryCode
|
||||
)
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
|
||||
switch error {
|
||||
case StoreClient.Error.purchaseFailed:
|
||||
logger.log("Purchase failed.", level: .error)
|
||||
case StoreClient.Error.duplicateLicense:
|
||||
logger.log("A license already exists for this item.", level: .error)
|
||||
case StoreResponse.Error.priceMismatch:
|
||||
logger.log("Pirce mismatch. It is only possible to obtain a license for free apps.", level: .error)
|
||||
case StoreResponse.Error.invalidCountry:
|
||||
logger.log("The country provided does not match with the account you are using. Supply a valid country using the \"--country\" flag.", level: .error)
|
||||
case StoreResponse.Error.passwordTokenExpired:
|
||||
logger.log("Token expired. Login again using the \"auth\" command.", level: .error)
|
||||
default:
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
}
|
||||
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func item(
|
||||
from app: iTunesResponse.Result,
|
||||
account: Account,
|
||||
purchaseAttempted: Bool = false
|
||||
) async -> StoreResponse.Item {
|
||||
logger.log("Creating HTTP client...", level: .debug)
|
||||
let httpClient = HTTPClient(session: 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 await 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:
|
||||
if !purchaseAttempted, purchase {
|
||||
logger.log("License is missing.", level: .info)
|
||||
|
||||
await purchase(app: app, account: account)
|
||||
logger.log("Obtained a license for '\(app.identifier)'.", level: .debug)
|
||||
|
||||
return await item(from: app, account: account, purchaseAttempted: true)
|
||||
} else {
|
||||
logger.log("Your Apple ID does not have a license for this app. Use the \"purchase\" command or the \"--purchase\" to obtain a license.", level: .error)
|
||||
}
|
||||
case StoreResponse.Error.invalidCountry:
|
||||
logger.log("The country provided does not match with the account you are using. Supply a valid country using the \"--country\" flag.", level: .error)
|
||||
case StoreResponse.Error.passwordTokenExpired:
|
||||
logger.log("Token expired. Login again using the \"auth\" command.", level: .error)
|
||||
default:
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
}
|
||||
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func download(item: StoreResponse.Item, to targetURL: URL) async {
|
||||
logger.log("Creating download client...", level: .debug)
|
||||
let downloadClient = HTTPDownloadClient()
|
||||
|
||||
do {
|
||||
logger.log("Downloading app package...", level: .info)
|
||||
try await 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)
|
||||
}
|
||||
}
|
||||
|
||||
private 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)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func makeOutputPath(app: iTunesResponse.Result) -> String {
|
||||
let fileName: String = "/\(bundleIdentifier)_\(app.identifier)_v\(app.version)_\(Int.random(in: 100...999)).ipa"
|
||||
|
||||
guard let output = output else {
|
||||
return FileManager.default.currentDirectoryPath.appending(fileName)
|
||||
}
|
||||
|
||||
var isDirectory: ObjCBool = false
|
||||
FileManager.default.fileExists(atPath: output, isDirectory: &isDirectory)
|
||||
|
||||
return isDirectory.boolValue ? output.appending(fileName) : output
|
||||
}
|
||||
|
||||
mutating func validate() throws {
|
||||
guard let output = output else { return }
|
||||
|
||||
var isDirectory: ObjCBool = false
|
||||
guard !FileManager.default.fileExists(atPath: output, isDirectory: &isDirectory) || isDirectory.boolValue else {
|
||||
logger.log("A file already exists at \(output).", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
mutating func run() async throws {
|
||||
// Authenticate with the App Store
|
||||
let keychainStore = KeychainStore(service: "ipatool.service")
|
||||
|
||||
guard let account: Account = try keychainStore.value(forKey: "account") else {
|
||||
logger.log("Authentication required. Run \"ipatool auth --help\" for help.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
logger.log("Authenticated as '\(account.name)'.", level: .info)
|
||||
|
||||
// Query for app
|
||||
let app: iTunesResponse.Result = await app(with: bundleIdentifier, countryCode: countryCode)
|
||||
logger.log("Found app: \(app.name) (\(app.version)).", level: .debug)
|
||||
|
||||
// Query for store item
|
||||
let item: StoreResponse.Item = await item(from: app, account: account)
|
||||
logger.log("Received a response of the signed copy: \(item.md5).", level: .debug)
|
||||
|
||||
// Generate file name
|
||||
let path = makeOutputPath(app: app)
|
||||
logger.log("Output path: \(path).", level: .debug)
|
||||
|
||||
// Download app package
|
||||
await download(item: item, to: URL(fileURLWithPath: path))
|
||||
logger.log("Saved app package to \(URL(fileURLWithPath: path).lastPathComponent).", level: .info)
|
||||
|
||||
// Apply patches
|
||||
applyPatches(item: item, email: account.email, path: path)
|
||||
logger.log("Done.", level: .info)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// IPATool.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import ArgumentParser
|
||||
|
||||
struct IPATool: ParsableCommand {
|
||||
static var configuration: CommandConfiguration {
|
||||
return CommandConfiguration(
|
||||
commandName: "ipatool",
|
||||
abstract: "A cli tool for interacting with Apple's ipa files.",
|
||||
version: Package.version,
|
||||
subcommands: [Auth.self, Download.self, Purchase.self, Search.self]
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@main enum Main: AsyncMain {
|
||||
typealias Command = IPATool
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
//
|
||||
// Purchase.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.03.22.
|
||||
//
|
||||
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
import Networking
|
||||
import StoreAPI
|
||||
import Persistence
|
||||
|
||||
struct Purchase: AsyncParsableCommand {
|
||||
static var configuration: CommandConfiguration {
|
||||
return .init(abstract: "Obtain a license for the app from the App Store.")
|
||||
}
|
||||
|
||||
@Option(name: [.short, .long], help: "The bundle identifier of the target iOS app.")
|
||||
private var bundleIdentifier: String
|
||||
|
||||
@Option(
|
||||
name: [.customShort("c"), .customLong("country")],
|
||||
help: "The two-letter (ISO 3166-1 alpha-2) country code for the iTunes Store."
|
||||
)
|
||||
private var countryCode: String = "US"
|
||||
|
||||
@Option(name: [.short, .long], help: "The device family to limit the search query to.")
|
||||
private var deviceFamily: DeviceFamily = .phone
|
||||
|
||||
@Option(name: [.long], help: "The log level.")
|
||||
private var logLevel: LogLevel = .info
|
||||
|
||||
lazy var logger = ConsoleLogger(level: logLevel)
|
||||
}
|
||||
|
||||
extension Purchase {
|
||||
private mutating func app(with bundleIdentifier: String) async -> iTunesResponse.Result {
|
||||
logger.log("Creating HTTP client...", level: .debug)
|
||||
let httpClient = HTTPClient(session: URLSession.shared)
|
||||
|
||||
logger.log("Creating iTunes client...", level: .debug)
|
||||
let itunesClient = iTunesClient(httpClient: httpClient)
|
||||
|
||||
do {
|
||||
logger.log("Querying the iTunes Store for '\(bundleIdentifier)' in country '\(countryCode)'...", level: .info)
|
||||
let app = try await itunesClient.lookup(
|
||||
bundleIdentifier: bundleIdentifier,
|
||||
countryCode: countryCode,
|
||||
deviceFamily: deviceFamily
|
||||
)
|
||||
|
||||
guard app.price == 0 else {
|
||||
logger.log("Only free apps are supported.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
|
||||
return app
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
|
||||
switch error {
|
||||
case iTunesClient.Error.appNotFound:
|
||||
logger.log("Could not find app.", level: .error)
|
||||
default:
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
}
|
||||
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
private mutating func purchase(app: iTunesResponse.Result, account: Account) async {
|
||||
logger.log("Creating HTTP client...", level: .debug)
|
||||
let httpClient = HTTPClient(session: URLSession.shared)
|
||||
|
||||
logger.log("Creating App Store client...", level: .debug)
|
||||
let storeClient = StoreClient(httpClient: httpClient)
|
||||
|
||||
do {
|
||||
logger.log("Obtaining a license for '\(app.identifier)' from the App Store...", level: .info)
|
||||
try await storeClient.purchase(
|
||||
identifier: "\(app.identifier)",
|
||||
directoryServicesIdentifier: account.directoryServicesIdentifier,
|
||||
passwordToken: account.passwordToken,
|
||||
countryCode: countryCode
|
||||
)
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
|
||||
switch error {
|
||||
case StoreClient.Error.purchaseFailed:
|
||||
logger.log("Purchase failed.", level: .error)
|
||||
case StoreClient.Error.duplicateLicense:
|
||||
logger.log("A license already exists for this item.", level: .error)
|
||||
case StoreResponse.Error.priceMismatch:
|
||||
logger.log("Pirce mismatch. It is only possible to obtain a license for free apps.", level: .error)
|
||||
case StoreResponse.Error.invalidCountry:
|
||||
logger.log("The country provided does not match with the account you are using. Supply a valid country using the \"--country\" flag.", level: .error)
|
||||
case StoreResponse.Error.passwordTokenExpired:
|
||||
logger.log("Token expired. Login again using the \"auth\" command.", level: .error)
|
||||
default:
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
}
|
||||
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
mutating func run() async throws {
|
||||
// Authenticate with the App Store
|
||||
let keychainStore = KeychainStore(service: "ipatool.service")
|
||||
|
||||
guard let account: Account = try keychainStore.value(forKey: "account") else {
|
||||
logger.log("Authentication required. Run \"ipatool auth --help\" for help.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
logger.log("Authenticated as '\(account.name)'.", level: .info)
|
||||
|
||||
// Query for app
|
||||
let app: iTunesResponse.Result = await app(with: bundleIdentifier)
|
||||
logger.log("Found app: \(app.name) (\(app.version)).", level: .debug)
|
||||
|
||||
// Obtain a license
|
||||
await purchase(app: app, account: account)
|
||||
logger.log("Obtained a license for '\(app.identifier)'.", level: .debug)
|
||||
logger.log("Done.", level: .info)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
//
|
||||
// Search.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
import Networking
|
||||
import StoreAPI
|
||||
|
||||
struct Search: AsyncParsableCommand {
|
||||
static var configuration: CommandConfiguration {
|
||||
return .init(abstract: "Search for iOS apps available on the App Store.")
|
||||
}
|
||||
|
||||
@Argument(help: "The term to search for.")
|
||||
private var term: String
|
||||
|
||||
@Option(name: [.short, .long], help: "The maximum amount of search results to retrieve.")
|
||||
private var limit: Int = 5
|
||||
|
||||
@Option(
|
||||
name: [.customShort("c"), .customLong("country")],
|
||||
help: "The two-letter (ISO 3166-1 alpha-2) country code for the iTunes Store."
|
||||
)
|
||||
private var countryCode: String = "US"
|
||||
|
||||
@Option(name: [.short, .long], help: "The device family to limit the search query to.")
|
||||
private var deviceFamily: DeviceFamily = .phone
|
||||
|
||||
@Option(name: [.long], help: "The log level.")
|
||||
private var logLevel: LogLevel = .info
|
||||
|
||||
lazy var logger = ConsoleLogger(level: logLevel)
|
||||
}
|
||||
|
||||
extension Search {
|
||||
mutating func results(with term: String) async -> [iTunesResponse.Result] {
|
||||
logger.log("Creating HTTP client...", level: .debug)
|
||||
let httpClient = HTTPClient(session: URLSession.shared)
|
||||
|
||||
logger.log("Creating iTunes client...", level: .debug)
|
||||
let itunesClient = iTunesClient(httpClient: httpClient)
|
||||
|
||||
logger.log("Searching for '\(term)' using the '\(countryCode)' store front...", level: .info)
|
||||
|
||||
do {
|
||||
let results = try await itunesClient.search(
|
||||
term: term,
|
||||
limit: limit,
|
||||
countryCode: countryCode,
|
||||
deviceFamily: deviceFamily
|
||||
)
|
||||
|
||||
guard !results.isEmpty else {
|
||||
logger.log("No results found.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
|
||||
return results
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
_exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
mutating func run() async throws {
|
||||
// Search the iTunes store
|
||||
let results = await 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)
|
||||
}
|
||||
}
|
||||
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// Account.swift
|
||||
// IPATool
|
||||
//
|
||||
// Created by Majd Alfhaily on 21.03.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct Account: Codable {
|
||||
let name: String
|
||||
let email: String
|
||||
let passwordToken: String
|
||||
let directoryServicesIdentifier: String
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// HTTPClient.swift
|
||||
// Networking
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol HTTPClientInterface {
|
||||
func send(_ request: HTTPRequest) async throws -> HTTPResponse
|
||||
}
|
||||
|
||||
public final class HTTPClient: HTTPClientInterface {
|
||||
private let session: URLSessionInterface
|
||||
|
||||
public init(session: URLSessionInterface) {
|
||||
self.session = session
|
||||
}
|
||||
|
||||
public func send(_ request: HTTPRequest) async throws -> HTTPResponse {
|
||||
let request = try makeURLRequest(from: request)
|
||||
let (data, response) = try await session.data(for: request)
|
||||
|
||||
guard let response = response as? HTTPURLResponse else {
|
||||
throw Error.invalidResponse(response)
|
||||
}
|
||||
|
||||
return HTTPResponse(statusCode: response.statusCode, data: data)
|
||||
}
|
||||
|
||||
private func makeURLRequest(from request: HTTPRequest) throws -> URLRequest {
|
||||
var urlRequest = URLRequest(url: request.endpoint.url)
|
||||
urlRequest.httpMethod = request.method.rawValue
|
||||
|
||||
switch request.payload {
|
||||
case .none:
|
||||
urlRequest.httpBody = nil
|
||||
case let .urlEncoding(propertyList):
|
||||
urlRequest.setValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
|
||||
|
||||
var urlComponents = URLComponents(string: request.endpoint.url.absoluteString)
|
||||
urlComponents?.queryItems = !propertyList.isEmpty ? propertyList.map {
|
||||
URLQueryItem(name: $0.0, value: $0.1.description)
|
||||
} : nil
|
||||
|
||||
switch request.method {
|
||||
case .get:
|
||||
urlRequest.url = urlComponents?.url
|
||||
case .post:
|
||||
urlRequest.httpBody = urlComponents?.percentEncodedQuery?.data(
|
||||
using: .utf8,
|
||||
allowLossyConversion: false
|
||||
)
|
||||
}
|
||||
case let .xml(value):
|
||||
urlRequest.setValue("application/xml", forHTTPHeaderField: "Content-Type")
|
||||
urlRequest.httpBody = try PropertyListSerialization.data(fromPropertyList: value, format: .xml, options: 0)
|
||||
}
|
||||
|
||||
request.headers.forEach { urlRequest.setValue($0.value, forHTTPHeaderField: $0.key) }
|
||||
|
||||
return urlRequest
|
||||
}
|
||||
}
|
||||
|
||||
extension HTTPClient {
|
||||
enum Error: Swift.Error {
|
||||
case invalidResponse(URLResponse?)
|
||||
case timeout
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// HTTPDownloadClient.swift
|
||||
// Networking
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol HTTPDownloadClientInterface {
|
||||
func download(from source: URL, to target: URL, progress: @escaping (Float) -> Void) async throws
|
||||
}
|
||||
|
||||
public final class HTTPDownloadClient: NSObject, HTTPDownloadClientInterface {
|
||||
private var session: URLSession!
|
||||
private var progressHandler: ((Float) -> Void)?
|
||||
private var continuation: CheckedContinuation<Void, Swift.Error>?
|
||||
private var targetURL: URL?
|
||||
|
||||
public override init() {
|
||||
super.init()
|
||||
self.session = URLSession(configuration: .default, delegate: self, delegateQueue: nil)
|
||||
}
|
||||
|
||||
public func download(from source: URL, to target: URL, progress: @escaping (Float) -> Void) async throws {
|
||||
assert(progressHandler == nil)
|
||||
assert(continuation == nil)
|
||||
assert(targetURL == nil)
|
||||
|
||||
progressHandler = progress
|
||||
targetURL = target
|
||||
|
||||
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Swift.Error>) in
|
||||
self.continuation = continuation
|
||||
let task = session.downloadTask(with: source)
|
||||
task.resume()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension HTTPDownloadClient: URLSessionDownloadDelegate {
|
||||
public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Swift.Error?) {
|
||||
guard let error = error else {
|
||||
return
|
||||
}
|
||||
|
||||
defer {
|
||||
progressHandler = nil
|
||||
continuation = nil
|
||||
targetURL = nil
|
||||
}
|
||||
|
||||
continuation?.resume(throwing: error)
|
||||
}
|
||||
|
||||
public func urlSession(
|
||||
_ session: URLSession,
|
||||
downloadTask: URLSessionDownloadTask,
|
||||
didWriteData bytesWritten: Int64,
|
||||
totalBytesWritten: Int64,
|
||||
totalBytesExpectedToWrite: Int64
|
||||
) {
|
||||
progressHandler?(Float(totalBytesWritten) / Float(totalBytesExpectedToWrite))
|
||||
}
|
||||
|
||||
public func urlSession(
|
||||
_ session: URLSession,
|
||||
downloadTask: URLSessionDownloadTask,
|
||||
didFinishDownloadingTo location: URL
|
||||
) {
|
||||
defer {
|
||||
progressHandler = nil
|
||||
continuation = nil
|
||||
targetURL = nil
|
||||
}
|
||||
|
||||
guard let target = targetURL else {
|
||||
return continuation?.resume(throwing: Error.invalidTarget) ?? ()
|
||||
}
|
||||
|
||||
do {
|
||||
try FileManager.default.moveItem(at: location, to: target)
|
||||
continuation?.resume()
|
||||
} catch {
|
||||
continuation?.resume(throwing: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension HTTPDownloadClient {
|
||||
enum Error: Swift.Error {
|
||||
case invalidTarget
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
//
|
||||
// HTTPEndpoint.swift
|
||||
// IPATool
|
||||
// Networking
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol HTTPEndpoint {
|
||||
public protocol HTTPEndpoint {
|
||||
var url: URL { get }
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
//
|
||||
// HTTPMethod.swift
|
||||
// IPATool
|
||||
// Networking
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum HTTPMethod: String {
|
||||
public enum HTTPMethod: String {
|
||||
case get = "GET"
|
||||
case post = "POST"
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
//
|
||||
// HTTPPayload.swift
|
||||
// IPATool
|
||||
// Networking
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
enum HTTPPayload {
|
||||
public enum HTTPPayload {
|
||||
case xml([String: String])
|
||||
case urlEncoding([String: String])
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
//
|
||||
// HTTPRequest.swift
|
||||
// IPATool
|
||||
// Networking
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol HTTPRequest {
|
||||
public protocol HTTPRequest {
|
||||
var method: HTTPMethod { get }
|
||||
var endpoint: HTTPEndpoint { get }
|
||||
var headers: [String: String] { get }
|
||||
@@ -15,6 +15,6 @@ protocol HTTPRequest {
|
||||
}
|
||||
|
||||
extension HTTPRequest {
|
||||
var headers: [String: String] { [:] }
|
||||
var payload: HTTPPayload? { nil }
|
||||
public var headers: [String: String] { [:] }
|
||||
public var payload: HTTPPayload? { nil }
|
||||
}
|
||||
@@ -1,19 +1,19 @@
|
||||
//
|
||||
// HTTPResponse.swift
|
||||
// IPATool
|
||||
// Networking
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct HTTPResponse {
|
||||
let statusCode: Int
|
||||
let data: Data?
|
||||
public struct HTTPResponse {
|
||||
public let statusCode: Int
|
||||
public let data: Data?
|
||||
}
|
||||
|
||||
extension HTTPResponse {
|
||||
func decode<T: Decodable>(_ type: T.Type, as decoder: Decoder) throws -> T {
|
||||
public func decode<T: Decodable>(_ type: T.Type, as decoder: Decoder) throws -> T {
|
||||
guard let data = data else {
|
||||
throw Error.noData
|
||||
}
|
||||
@@ -32,12 +32,12 @@ extension HTTPResponse {
|
||||
}
|
||||
|
||||
extension HTTPResponse {
|
||||
enum Decoder {
|
||||
public enum Decoder {
|
||||
case json
|
||||
case xml
|
||||
}
|
||||
|
||||
enum Error: Swift.Error {
|
||||
public enum Error: Swift.Error {
|
||||
case noData
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// URLSession.swift
|
||||
// Networking
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol URLSessionInterface {
|
||||
func data(for request: URLRequest) async throws -> (Data, URLResponse)
|
||||
}
|
||||
|
||||
extension URLSession: URLSessionInterface {
|
||||
public func data(for request: URLRequest) async throws -> (Data, URLResponse) {
|
||||
try await withCheckedThrowingContinuation { continuation in
|
||||
let task = dataTask(with: request) { data, response, error in
|
||||
guard let data = data, let response = response else {
|
||||
let error = error ?? URLError(.badServerResponse)
|
||||
return continuation.resume(throwing: error)
|
||||
}
|
||||
|
||||
continuation.resume(returning: (data, response))
|
||||
}
|
||||
|
||||
task.resume()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// KeychainStore.swift
|
||||
// Persistence
|
||||
//
|
||||
// Created by Majd Alfhaily on 21.03.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import KeychainAccess
|
||||
|
||||
public protocol KeychainStoreInterface {
|
||||
func value<T: Codable>(forKey itemKey: String) throws -> T?
|
||||
func setValue<T: Codable>(_ item: T, forKey itemKey: String) throws
|
||||
func remove(_ key: String) throws
|
||||
}
|
||||
|
||||
public class KeychainStore: KeychainStoreInterface {
|
||||
private let keychain: Keychain
|
||||
|
||||
public init(service: String) {
|
||||
self.keychain = Keychain(service: service)
|
||||
}
|
||||
|
||||
public func value<T: Codable>(forKey itemKey: String) throws -> T? {
|
||||
guard let data = try keychain.getData(itemKey) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return try JSONDecoder().decode(T.self, from: data)
|
||||
}
|
||||
|
||||
public func setValue<T: Codable>(_ item: T, forKey itemKey: String) throws {
|
||||
let data = try JSONEncoder().encode(item)
|
||||
try keychain.set(data, key: itemKey)
|
||||
}
|
||||
|
||||
public func remove(_ key: String) throws {
|
||||
try keychain.remove(key)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
//
|
||||
// DeviceFamily.swift
|
||||
// StoreAPI
|
||||
//
|
||||
// Created by Majd Alfhaily on 17.01.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import ArgumentParser
|
||||
|
||||
public enum DeviceFamily: String, ExpressibleByArgument {
|
||||
case phone = "iPhone"
|
||||
case pad = "iPad"
|
||||
|
||||
public var defaultValueDescription: String {
|
||||
return rawValue
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// Storefront.swift
|
||||
// StoreAPI
|
||||
//
|
||||
// Created by Benjamin Altpeter on 20.03.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
// https://web.archive.org/web/20191206001952/https://affiliate.itunes.apple.com/resources/documentation/linking-to-the-itunes-music-store
|
||||
public enum Storefront: String, CaseIterable {
|
||||
case AE = "143481"
|
||||
case AG = "143540"
|
||||
case AI = "143538"
|
||||
case AM = "143524"
|
||||
case AO = "143564"
|
||||
case AR = "143505"
|
||||
case AT = "143445"
|
||||
case AU = "143460"
|
||||
case AZ = "143568"
|
||||
case BB = "143541"
|
||||
case BD = "143490"
|
||||
case BE = "143446"
|
||||
case BG = "143526"
|
||||
case BH = "143559"
|
||||
case BM = "143542"
|
||||
case BN = "143560"
|
||||
case BO = "143556"
|
||||
case BR = "143503"
|
||||
case BS = "143539"
|
||||
case BW = "143525"
|
||||
case BY = "143565"
|
||||
case BZ = "143555"
|
||||
case CA = "143455"
|
||||
case CH = "143459"
|
||||
case CI = "143527"
|
||||
case CL = "143483"
|
||||
case CN = "143465"
|
||||
case CO = "143501"
|
||||
case CR = "143495"
|
||||
case CY = "143557"
|
||||
case CZ = "143489"
|
||||
case DE = "143443"
|
||||
case DK = "143458"
|
||||
case DM = "143545"
|
||||
case DO = "143508"
|
||||
case DZ = "143563"
|
||||
case EC = "143509"
|
||||
case EE = "143518"
|
||||
case EG = "143516"
|
||||
case ES = "143454"
|
||||
case FI = "143447"
|
||||
case FR = "143442"
|
||||
case GB = "143444"
|
||||
case GD = "143546"
|
||||
case GH = "143573"
|
||||
case GR = "143448"
|
||||
case GT = "143504"
|
||||
case GY = "143553"
|
||||
case HK = "143463"
|
||||
case HN = "143510"
|
||||
case HR = "143494"
|
||||
case HU = "143482"
|
||||
case ID = "143476"
|
||||
case IE = "143449"
|
||||
case IL = "143491"
|
||||
case IN = "143467"
|
||||
case IS = "143558"
|
||||
case IT = "143450"
|
||||
case JM = "143511"
|
||||
case JO = "143528"
|
||||
case JP = "143462"
|
||||
case KE = "143529"
|
||||
case KN = "143548"
|
||||
case KR = "143466"
|
||||
case KW = "143493"
|
||||
case KY = "143544"
|
||||
case KZ = "143517"
|
||||
case LB = "143497"
|
||||
case LC = "143549"
|
||||
case LI = "143522"
|
||||
case LK = "143486"
|
||||
case LT = "143520"
|
||||
case LU = "143451"
|
||||
case LV = "143519"
|
||||
case MD = "143523"
|
||||
case MG = "143531"
|
||||
case MK = "143530"
|
||||
case ML = "143532"
|
||||
case MO = "143515"
|
||||
case MS = "143547"
|
||||
case MT = "143521"
|
||||
case MU = "143533"
|
||||
case MV = "143488"
|
||||
case MX = "143468"
|
||||
case MY = "143473"
|
||||
case NE = "143534"
|
||||
case NG = "143561"
|
||||
case NI = "143512"
|
||||
case NL = "143452"
|
||||
case NO = "143457"
|
||||
case NP = "143484"
|
||||
case NZ = "143461"
|
||||
case OM = "143562"
|
||||
case PA = "143485"
|
||||
case PE = "143507"
|
||||
case PH = "143474"
|
||||
case PK = "143477"
|
||||
case PL = "143478"
|
||||
case PT = "143453"
|
||||
case PY = "143513"
|
||||
case QA = "143498"
|
||||
case RO = "143487"
|
||||
case RS = "143500"
|
||||
case RU = "143469"
|
||||
case SA = "143479"
|
||||
case SE = "143456"
|
||||
case SG = "143464"
|
||||
case SI = "143499"
|
||||
case SK = "143496"
|
||||
case SN = "143535"
|
||||
case SR = "143554"
|
||||
case SV = "143506"
|
||||
case TC = "143552"
|
||||
case TH = "143475"
|
||||
case TN = "143536"
|
||||
case TR = "143480"
|
||||
case TT = "143551"
|
||||
case TW = "143470"
|
||||
case TZ = "143572"
|
||||
case UA = "143492"
|
||||
case UG = "143537"
|
||||
case US = "143441"
|
||||
case UY = "143514"
|
||||
case UZ = "143566"
|
||||
case VC = "143550"
|
||||
case VE = "143502"
|
||||
case VG = "143543"
|
||||
case VN = "143471"
|
||||
case YE = "143571"
|
||||
case ZA = "143472"
|
||||
|
||||
init?(countryCode: String) {
|
||||
guard let value = Storefront.allCases.first(where: { "\($0)" == countryCode }) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
self = value
|
||||
}
|
||||
}
|
||||
+6
-6
@@ -1,6 +1,6 @@
|
||||
//
|
||||
// SignatureClient.swift
|
||||
// IPATool
|
||||
// StoreAPI
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
@@ -8,21 +8,21 @@
|
||||
import Foundation
|
||||
import ZIPFoundation
|
||||
|
||||
protocol SignatureClientInterface {
|
||||
public protocol SignatureClientInterface {
|
||||
func appendMetadata(item: StoreResponse.Item, email: String) throws
|
||||
func appendSignature(item: StoreResponse.Item) throws
|
||||
}
|
||||
|
||||
final class SignatureClient: SignatureClientInterface {
|
||||
public final class SignatureClient: SignatureClientInterface {
|
||||
private let fileManager: FileManager
|
||||
private let filePath: String
|
||||
|
||||
init(fileManager: FileManager, filePath: String) {
|
||||
public init(fileManager: FileManager, filePath: String) {
|
||||
self.fileManager = fileManager
|
||||
self.filePath = filePath
|
||||
}
|
||||
|
||||
func appendMetadata(item: StoreResponse.Item, email: String) throws {
|
||||
public func appendMetadata(item: StoreResponse.Item, email: String) throws {
|
||||
guard let archive = Archive(url: URL(fileURLWithPath: filePath), accessMode: .update) else {
|
||||
throw Error.invalidArchive
|
||||
}
|
||||
@@ -39,7 +39,7 @@ final class SignatureClient: SignatureClientInterface {
|
||||
try fileManager.removeItem(at: metadataUrl)
|
||||
}
|
||||
|
||||
func appendSignature(item: StoreResponse.Item) throws {
|
||||
public func appendSignature(item: StoreResponse.Item) throws {
|
||||
guard let archive = Archive(url: URL(fileURLWithPath: filePath), accessMode: .update) else {
|
||||
throw Error.invalidArchive
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
//
|
||||
// StoreClient.swift
|
||||
// StoreAPI
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Networking
|
||||
|
||||
public protocol StoreClientInterface {
|
||||
func authenticate(email: String, password: String, code: String?) async throws -> StoreResponse.Account
|
||||
func item(identifier: String, directoryServicesIdentifier: String) async throws -> StoreResponse.Item
|
||||
func purchase(
|
||||
identifier: String,
|
||||
directoryServicesIdentifier: String,
|
||||
passwordToken: String,
|
||||
countryCode: String
|
||||
) async throws
|
||||
}
|
||||
|
||||
public final class StoreClient: StoreClientInterface {
|
||||
private let httpClient: HTTPClient
|
||||
|
||||
public init(httpClient: HTTPClient) {
|
||||
self.httpClient = httpClient
|
||||
}
|
||||
|
||||
public func authenticate(email: String, password: String, code: String?) async throws -> StoreResponse.Account {
|
||||
try await authenticate(email: email, password: password, code: code, isFirstAttempt: true)
|
||||
}
|
||||
|
||||
public func item(identifier: String, directoryServicesIdentifier: String) async throws -> StoreResponse.Item {
|
||||
let request = StoreRequest.download(
|
||||
appIdentifier: identifier,
|
||||
directoryServicesIdentifier: directoryServicesIdentifier
|
||||
)
|
||||
let response = try await httpClient.send(request)
|
||||
let storeResponse = try response.decode(StoreResponse.self, as: .xml)
|
||||
|
||||
switch storeResponse {
|
||||
case let .item(item):
|
||||
return item
|
||||
case let .failure(error):
|
||||
throw error
|
||||
default:
|
||||
throw Error.invalidResponse
|
||||
}
|
||||
}
|
||||
|
||||
public func purchase(
|
||||
identifier: String,
|
||||
directoryServicesIdentifier: String,
|
||||
passwordToken: String,
|
||||
countryCode: String
|
||||
) async throws {
|
||||
let request = StoreRequest.purchase(
|
||||
appIdentifier: identifier,
|
||||
directoryServicesIdentifier: directoryServicesIdentifier,
|
||||
passwordToken: passwordToken,
|
||||
countryCode: countryCode
|
||||
)
|
||||
|
||||
let response = try await httpClient.send(request)
|
||||
|
||||
// Returns status code 500 if the Apple ID already contains a license
|
||||
switch response.statusCode {
|
||||
case 500:
|
||||
throw Error.duplicateLicense
|
||||
default:
|
||||
let response = try response.decode(StoreResponse.self, as: .xml)
|
||||
|
||||
switch response {
|
||||
case let .purchase(receipt):
|
||||
guard receipt.statusCode == 0, receipt.status == .success else {
|
||||
throw Error.purchaseFailed
|
||||
}
|
||||
case let .failure(error):
|
||||
throw error
|
||||
default:
|
||||
throw Error.invalidResponse
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func authenticate(email: String,
|
||||
password: String,
|
||||
code: String?,
|
||||
isFirstAttempt: Bool) async throws -> StoreResponse.Account {
|
||||
let request = StoreRequest.authenticate(email: email, password: password, code: code)
|
||||
let response = try await httpClient.send(request)
|
||||
let decoded = try response.decode(StoreResponse.self, as: .xml)
|
||||
|
||||
switch decoded {
|
||||
case let .account(account):
|
||||
return account
|
||||
case let .failure(error):
|
||||
switch error {
|
||||
case StoreResponse.Error.invalidCredentials:
|
||||
if isFirstAttempt {
|
||||
return try await authenticate(email: email, password: password, code: code, isFirstAttempt: false)
|
||||
}
|
||||
|
||||
throw error
|
||||
default:
|
||||
throw error
|
||||
}
|
||||
default:
|
||||
throw Error.invalidResponse
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension StoreClient {
|
||||
public enum Error: Swift.Error {
|
||||
case timeout
|
||||
case invalidResponse
|
||||
case purchaseFailed
|
||||
case duplicateLicense
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,17 @@
|
||||
//
|
||||
// StoreEndpoint.swift
|
||||
// IPATool
|
||||
// StoreAPI
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Networking
|
||||
|
||||
enum StoreEndpoint {
|
||||
case authenticate(prefix: String, guid: String)
|
||||
case download(guid: String)
|
||||
case purchase
|
||||
}
|
||||
|
||||
extension StoreEndpoint: HTTPEndpoint {
|
||||
@@ -26,6 +28,8 @@ extension StoreEndpoint: HTTPEndpoint {
|
||||
return "\(prefix)-buy.itunes.apple.com"
|
||||
case .download:
|
||||
return "p25-buy.itunes.apple.com"
|
||||
case .purchase:
|
||||
return "buy.itunes.apple.com"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +39,8 @@ extension StoreEndpoint: HTTPEndpoint {
|
||||
return "/WebObjects/MZFinance.woa/wa/authenticate?guid=\(guid)"
|
||||
case let .download(guid):
|
||||
return "/WebObjects/MZFinance.woa/wa/volumeStoreDownloadProduct?guid=\(guid)"
|
||||
case .purchase:
|
||||
return "/WebObjects/MZBuy.woa/wa/buyProduct"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,22 @@
|
||||
//
|
||||
// StoreRequest.swift
|
||||
// IPATool
|
||||
// StoreAPI
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Networking
|
||||
|
||||
enum StoreRequest {
|
||||
case authenticate(email: String, password: String, code: String? = nil)
|
||||
case download(appIdentifier: String, directoryServicesIdentifier: String)
|
||||
case purchase(
|
||||
appIdentifier: String,
|
||||
directoryServicesIdentifier: String,
|
||||
passwordToken: String,
|
||||
countryCode: String
|
||||
)
|
||||
}
|
||||
|
||||
extension StoreRequest: HTTPRequest {
|
||||
@@ -19,6 +26,8 @@ extension StoreRequest: HTTPRequest {
|
||||
return StoreEndpoint.authenticate(prefix: (code == nil) ? "p25" : "p71", guid: guid)
|
||||
case .download:
|
||||
return StoreEndpoint.download(guid: guid)
|
||||
case .purchase:
|
||||
return StoreEndpoint.purchase
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +37,7 @@ extension StoreRequest: HTTPRequest {
|
||||
|
||||
var headers: [String: String] {
|
||||
var headers: [String: String] = [
|
||||
"User-Agent": "Configurator/2.0 (Macintosh; OS X 10.12.6; 16G29) AppleWebKit/2603.3.8",
|
||||
"User-Agent": "Configurator/2.15 (Macintosh; OS X 11.0.0; 16G29) AppleWebKit/2603.3.8",
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
]
|
||||
|
||||
@@ -38,6 +47,12 @@ extension StoreRequest: HTTPRequest {
|
||||
case let .download(_, directoryServicesIdentifier):
|
||||
headers["X-Dsid"] = directoryServicesIdentifier
|
||||
headers["iCloud-DSID"] = directoryServicesIdentifier
|
||||
case let .purchase(_, directoryServicesIdentifier, passwordToken, countryCode):
|
||||
headers["X-Dsid"] = directoryServicesIdentifier
|
||||
headers["iCloud-DSID"] = directoryServicesIdentifier
|
||||
headers["Content-Type"] = "application/x-apple-plist"
|
||||
headers["X-Apple-Store-Front"] = Storefront(countryCode: countryCode)?.rawValue
|
||||
headers["X-Token"] = passwordToken
|
||||
}
|
||||
|
||||
return headers
|
||||
@@ -61,12 +76,28 @@ extension StoreRequest: HTTPRequest {
|
||||
"guid": guid,
|
||||
"salableAdamId": "\(appIdentifier)"
|
||||
])
|
||||
case let .purchase(appIdentifier, _, _, _):
|
||||
return .xml([
|
||||
"appExtVrsId": "0",
|
||||
"hasAskedToFulfillPreorder": "true",
|
||||
"buyWithoutAuthorization": "true",
|
||||
"hasDoneAgeCheck": "true",
|
||||
"guid": guid,
|
||||
"needDiv": "0",
|
||||
"origPage": "Software-" + appIdentifier,
|
||||
"origPageLocation": "Buy",
|
||||
"price": "0",
|
||||
"pricingParameters": "STDQ",
|
||||
"productType": "C",
|
||||
"salableAdamId": appIdentifier
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension StoreRequest {
|
||||
// This identifier is calculated by reading the MAC address of the device and stripping the nonalphabetic characters from the string.
|
||||
// This identifier is calculated by reading the MAC address of the device
|
||||
// and stripping the nonalphabetic characters from the string.
|
||||
// https://stackoverflow.com/a/31838376
|
||||
private var guid: String {
|
||||
let MAC_ADDRESS_LENGTH = 6
|
||||
@@ -86,14 +117,18 @@ extension StoreRequest {
|
||||
let bsdData = Data(bsd.utf8)
|
||||
var managementInfoBase = [CTL_NET, AF_ROUTE, 0, AF_LINK, NET_RT_IFLIST, bsdIndex]
|
||||
|
||||
guard sysctl(&managementInfoBase, 6, nil, &length, nil, 0) >= 0 else { fatalError("Could not read MAC address") }
|
||||
guard sysctl(&managementInfoBase, 6, nil, &length, nil, 0) >= 0 else {
|
||||
fatalError("Could not read MAC address")
|
||||
}
|
||||
|
||||
buffer = [CChar](unsafeUninitializedCapacity: length, initializingWith: {buffer, initializedCount in
|
||||
for x in 0..<length { buffer[x] = 0 }
|
||||
initializedCount = length
|
||||
})
|
||||
|
||||
guard sysctl(&managementInfoBase, 6, &buffer, &length, nil, 0) >= 0 else { fatalError("Could not read MAC address") }
|
||||
guard sysctl(&managementInfoBase, 6, &buffer, &length, nil, 0) >= 0 else {
|
||||
fatalError("Could not read MAC address")
|
||||
}
|
||||
|
||||
let infoData = Data(bytes: buffer, count: length)
|
||||
let indexAfterMsghdr = MemoryLayout<if_msghdr>.stride + 1
|
||||
@@ -0,0 +1,179 @@
|
||||
//
|
||||
// StoreResponse.swift
|
||||
// StoreAPI
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public enum StoreResponse {
|
||||
case failure(error: Swift.Error)
|
||||
case account(Account)
|
||||
case item(Item)
|
||||
case purchase(Receipt)
|
||||
|
||||
public enum Error: Int, Swift.Error {
|
||||
case unknownError = 0
|
||||
case genericError = 5002
|
||||
case codeRequired = 1
|
||||
case invalidLicense = 9610
|
||||
case invalidCredentials = -5000
|
||||
case invalidAccount = 5001
|
||||
case invalidItem = -10000
|
||||
case lockedAccount = -10001
|
||||
case invalidCountry = -128
|
||||
case passwordTokenExpired = 2034
|
||||
case priceMismatch = 2019
|
||||
}
|
||||
}
|
||||
|
||||
extension StoreResponse: Decodable {
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
|
||||
let error = try container.decodeIfPresent(String.self, forKey: .error)
|
||||
let message = try container.decodeIfPresent(String.self, forKey: .message)
|
||||
|
||||
if container.contains(.account) {
|
||||
let directoryServicesIdentifier = try container.decode(String.self, forKey: .directoryServicesIdentifier)
|
||||
let passwordToken = try container.decode(String.self, forKey: .passwordToken)
|
||||
let accountContainer = try container.nestedContainer(keyedBy: AccountInfoCodingKeys.self, forKey: .account)
|
||||
let addressContainer = try accountContainer.nestedContainer(keyedBy: AddressCodingKeys.self, forKey: .address)
|
||||
let firstName = try addressContainer.decode(String.self, forKey: .firstName)
|
||||
let lastName = try addressContainer.decode(String.self, forKey: .lastName)
|
||||
|
||||
self = .account(
|
||||
Account(
|
||||
firstName: firstName,
|
||||
lastName: lastName,
|
||||
directoryServicesIdentifier: directoryServicesIdentifier,
|
||||
passwordToken: passwordToken
|
||||
)
|
||||
)
|
||||
} else if let items = try container.decodeIfPresent([Item].self, forKey: .items), let item = items.first {
|
||||
self = .item(item)
|
||||
} else if container.contains(.statusCode) {
|
||||
let statusCode = try container.decode(Int.self, forKey: .statusCode)
|
||||
let statusType = try container.decode(String.self, forKey: .statusType)
|
||||
|
||||
self = .purchase(Receipt(statusCode: statusCode, status: Receipt.Status(rawValue: statusType)))
|
||||
} else if let error = error, !error.isEmpty {
|
||||
self = .failure(error: Error(rawValue: Int(error) ?? 0) ?? .unknownError)
|
||||
} else {
|
||||
switch message {
|
||||
case "Your account information was entered incorrectly.":
|
||||
self = .failure(error: Error.invalidCredentials)
|
||||
case "An Apple ID verification code is required to sign in. Type your password followed by the verification code shown on your other devices.":
|
||||
self = .failure(error: Error.codeRequired)
|
||||
case "MZFinance.BadLogin.Configurator_message":
|
||||
self = .failure(error: Error.codeRequired)
|
||||
case "This Apple ID has been locked for security reasons. Visit iForgot to reset your account (https://iforgot.apple.com).":
|
||||
self = .failure(error: Error.lockedAccount)
|
||||
default:
|
||||
self = .failure(error: Error.unknownError)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case directoryServicesIdentifier = "dsPersonId"
|
||||
case passwordToken = "passwordToken"
|
||||
case message = "customerMessage"
|
||||
case items = "songList"
|
||||
case error = "failureType"
|
||||
case account = "accountInfo"
|
||||
case statusCode = "status"
|
||||
case statusType = "jingleDocType"
|
||||
}
|
||||
|
||||
private enum AccountInfoCodingKeys: String, CodingKey {
|
||||
case address
|
||||
}
|
||||
|
||||
private enum AddressCodingKeys: String, CodingKey {
|
||||
case firstName
|
||||
case lastName
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Account
|
||||
|
||||
extension StoreResponse {
|
||||
public struct Account {
|
||||
public let firstName: String
|
||||
public let lastName: String
|
||||
public let directoryServicesIdentifier: String
|
||||
public let passwordToken: String
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Item
|
||||
|
||||
extension StoreResponse {
|
||||
public struct Item: Decodable {
|
||||
public let url: URL
|
||||
public let md5: String
|
||||
public let signatures: [Signature]
|
||||
public let metadata: [String: Any]
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||
let md5 = try container.decode(String.self, forKey: .md5)
|
||||
|
||||
guard let key = CodingUserInfoKey(rawValue: "data"),
|
||||
let data = decoder.userInfo[key] as? Data,
|
||||
let json = try PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any],
|
||||
let items = json["songList"] as? [[String: Any]],
|
||||
let item = items.first(where: { $0["md5"] as? String == md5 }),
|
||||
let metadata = item["metadata"] as? [String: Any]
|
||||
else { throw StoreResponse.Error.invalidItem }
|
||||
|
||||
let absoluteUrl = try container.decode(String.self, forKey: .url)
|
||||
|
||||
self.md5 = md5
|
||||
self.metadata = metadata
|
||||
self.signatures = try container.decode([Signature].self, forKey: .signatures)
|
||||
|
||||
if let url = URL(string: absoluteUrl) {
|
||||
self.url = url
|
||||
} else {
|
||||
let context = DecodingError.Context(
|
||||
codingPath: [CodingKeys.url],
|
||||
debugDescription: "URL contains illegal characters: \(absoluteUrl)."
|
||||
)
|
||||
throw DecodingError.keyNotFound(CodingKeys.url, context)
|
||||
}
|
||||
}
|
||||
|
||||
public struct Signature: Decodable {
|
||||
public let id: Int
|
||||
public let sinf: Data
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case url = "URL"
|
||||
case metadata
|
||||
case md5
|
||||
case signatures = "sinfs"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Receipt
|
||||
|
||||
extension StoreResponse {
|
||||
public struct Receipt {
|
||||
public let statusCode: Int
|
||||
public let status: Status
|
||||
|
||||
public enum Status {
|
||||
case success
|
||||
case failure
|
||||
|
||||
init(rawValue: String) {
|
||||
self = rawValue == "purchaseSuccess" ? .success : .failure
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
//
|
||||
// iTunesClient.swift
|
||||
// StoreAPI
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Networking
|
||||
|
||||
public protocol iTunesClientInterface {
|
||||
func lookup(
|
||||
bundleIdentifier: String,
|
||||
countryCode: String,
|
||||
deviceFamily: DeviceFamily
|
||||
) async throws -> iTunesResponse.Result
|
||||
|
||||
func search(
|
||||
term: String,
|
||||
limit: Int,
|
||||
countryCode: String,
|
||||
deviceFamily: DeviceFamily
|
||||
) async throws -> [iTunesResponse.Result]
|
||||
}
|
||||
|
||||
public final class iTunesClient: iTunesClientInterface {
|
||||
private let httpClient: HTTPClient
|
||||
|
||||
public init(httpClient: HTTPClient) {
|
||||
self.httpClient = httpClient
|
||||
}
|
||||
|
||||
public func lookup(
|
||||
bundleIdentifier: String,
|
||||
countryCode: String,
|
||||
deviceFamily: DeviceFamily
|
||||
) async throws -> iTunesResponse.Result {
|
||||
let request = iTunesRequest.lookup(
|
||||
bundleIdentifier: bundleIdentifier,
|
||||
countryCode: countryCode,
|
||||
deviceFamily: deviceFamily
|
||||
)
|
||||
let response = try await httpClient.send(request)
|
||||
let decoded = try response.decode(iTunesResponse.self, as: .json)
|
||||
guard let result = decoded.results.first else { throw Error.appNotFound }
|
||||
return result
|
||||
}
|
||||
|
||||
public func search(
|
||||
term: String,
|
||||
limit: Int,
|
||||
countryCode: String,
|
||||
deviceFamily: DeviceFamily
|
||||
) async throws -> [iTunesResponse.Result] {
|
||||
let request = iTunesRequest.search(
|
||||
term: term,
|
||||
limit: limit,
|
||||
countryCode: countryCode,
|
||||
deviceFamily: deviceFamily
|
||||
)
|
||||
let response = try await httpClient.send(request)
|
||||
let decoded = try response.decode(iTunesResponse.self, as: .json)
|
||||
return decoded.results
|
||||
}
|
||||
}
|
||||
|
||||
extension iTunesClient {
|
||||
public enum Error: Swift.Error {
|
||||
case timeout
|
||||
case appNotFound
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,12 @@
|
||||
//
|
||||
// iTunesEndpoint.swift
|
||||
// IPATool
|
||||
// StoreAPI
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Networking
|
||||
|
||||
enum iTunesEndpoint {
|
||||
case search
|
||||
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// iTunesRequest.swift
|
||||
// StoreAPI
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import ArgumentParser
|
||||
import Networking
|
||||
|
||||
enum iTunesRequest {
|
||||
case search(term: String, limit: Int, countryCode: String, deviceFamily: DeviceFamily = .phone)
|
||||
case lookup(bundleIdentifier: String, countryCode: String, deviceFamily: DeviceFamily = .phone)
|
||||
}
|
||||
|
||||
extension iTunesRequest: HTTPRequest {
|
||||
var method: HTTPMethod {
|
||||
return .get
|
||||
}
|
||||
|
||||
var endpoint: HTTPEndpoint {
|
||||
switch self {
|
||||
case .lookup:
|
||||
return iTunesEndpoint.lookup
|
||||
case .search:
|
||||
return iTunesEndpoint.search
|
||||
}
|
||||
}
|
||||
|
||||
var payload: HTTPPayload? {
|
||||
switch self {
|
||||
case let .lookup(bundleIdentifier, countryCode, deviceFamily):
|
||||
return .urlEncoding([
|
||||
"media": "software",
|
||||
"bundleId": bundleIdentifier,
|
||||
"limit": "1",
|
||||
"country": countryCode,
|
||||
"entity": deviceFamily.entity
|
||||
])
|
||||
case let .search(term, limit, countryCode, deviceFamily):
|
||||
return .urlEncoding([
|
||||
"media": "software",
|
||||
"term": term,
|
||||
"limit": "\(limit)",
|
||||
"country": countryCode,
|
||||
"entity": deviceFamily.entity
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private extension DeviceFamily {
|
||||
var entity: String {
|
||||
switch self {
|
||||
case .phone:
|
||||
return "software"
|
||||
case .pad:
|
||||
return "iPadSoftware"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,24 @@
|
||||
//
|
||||
// iTunesResponse.swift
|
||||
// IPATool
|
||||
// StoreAPI
|
||||
//
|
||||
// Created by Majd Alfhaily on 22.05.21.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct iTunesResponse {
|
||||
public struct iTunesResponse {
|
||||
let results: [Result]
|
||||
let count: Int
|
||||
}
|
||||
|
||||
extension iTunesResponse {
|
||||
struct Result {
|
||||
let bundleIdentifier: String
|
||||
let version: String
|
||||
let identifier: Int
|
||||
let name: String
|
||||
public struct Result {
|
||||
public let bundleIdentifier: String
|
||||
public let version: String
|
||||
public let identifier: Int
|
||||
public let name: String
|
||||
public let price: Float
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,5 +35,6 @@ extension iTunesResponse.Result: Codable {
|
||||
case name = "trackName"
|
||||
case bundleIdentifier = "bundleId"
|
||||
case version
|
||||
case price
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
//
|
||||
// HTTPClientTests.swift
|
||||
// NetworkingTests
|
||||
//
|
||||
// Created by Majd Alfhaily on 17.01.22.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import Networking
|
||||
|
||||
final class HTTPClientTests: XCTestCase {
|
||||
private var sut: HTTPClient!
|
||||
private var session: URLSessionMock!
|
||||
|
||||
override func setUp() {
|
||||
session = URLSessionMock()
|
||||
sut = HTTPClient(session: session)
|
||||
}
|
||||
|
||||
func test_GET_success_returnsValidResposne() async throws {
|
||||
session.onData = { request in
|
||||
let url = try XCTUnwrap(request.url?.absoluteString)
|
||||
XCTAssertTrue(url.hasPrefix("https://api.example.com"))
|
||||
XCTAssertEqual(request.httpMethod, "GET")
|
||||
|
||||
let data = try XCTUnwrap("foo".data(using: .utf8))
|
||||
let response = HTTPURLResponse(
|
||||
url: URL(string: "https://example.com")!,
|
||||
mimeType: nil,
|
||||
expectedContentLength: 0,
|
||||
textEncodingName: nil
|
||||
)
|
||||
return (data, response)
|
||||
}
|
||||
|
||||
let response = try await sut.send(TestRequest.get(nil))
|
||||
let data = try XCTUnwrap(response.data)
|
||||
XCTAssertEqual(String(data: data, encoding: .utf8), "foo")
|
||||
}
|
||||
|
||||
func test_GET_failure_returnsInvalidResposne() async throws {
|
||||
session.onData = { request in
|
||||
let url = try XCTUnwrap(request.url?.absoluteString)
|
||||
XCTAssertTrue(url.hasPrefix("https://api.example.com"))
|
||||
XCTAssertEqual(request.httpMethod, "GET")
|
||||
|
||||
let data = try XCTUnwrap("foo".data(using: .utf8))
|
||||
|
||||
let response = URLResponse(
|
||||
url: URL(string: "https://example.com")!,
|
||||
mimeType: nil,
|
||||
expectedContentLength: 0,
|
||||
textEncodingName: nil
|
||||
)
|
||||
return (data, response)
|
||||
}
|
||||
|
||||
do {
|
||||
_ = try await sut.send(TestRequest.get(nil))
|
||||
XCTFail()
|
||||
} catch {
|
||||
XCTAssertNotNil(error)
|
||||
}
|
||||
}
|
||||
|
||||
func test_POST_xmlEncoding_returnsValidResponse() async throws {
|
||||
session.onData = { request in
|
||||
let url = try XCTUnwrap(request.url?.absoluteString)
|
||||
XCTAssertTrue(url.hasPrefix("https://api.example.com"))
|
||||
XCTAssertEqual(request.httpMethod, "POST")
|
||||
|
||||
let data = try XCTUnwrap(request.httpBody)
|
||||
let decoded = try PropertyListSerialization.propertyList(
|
||||
from: data,
|
||||
options: [],
|
||||
format: nil
|
||||
) as! [String: String]
|
||||
|
||||
XCTAssertEqual(decoded["foo"], "bar")
|
||||
|
||||
let response = HTTPURLResponse(
|
||||
url: URL(string: "https://example.com")!,
|
||||
mimeType: nil,
|
||||
expectedContentLength: 0,
|
||||
textEncodingName: nil
|
||||
)
|
||||
return (data, response)
|
||||
}
|
||||
|
||||
_ = try await sut.send(TestRequest.post(.xml(["foo": "bar"])))
|
||||
}
|
||||
|
||||
func test_GET_urlEncoding_returnsValidResponse() async throws {
|
||||
session.onData = { request in
|
||||
let url = try XCTUnwrap(request.url?.absoluteString)
|
||||
XCTAssertTrue(url.hasPrefix("https://api.example.com"))
|
||||
XCTAssertTrue(url.hasSuffix("?foo=bar"))
|
||||
XCTAssertEqual(request.httpMethod, "GET")
|
||||
|
||||
let response = HTTPURLResponse(
|
||||
url: URL(string: "https://example.com")!,
|
||||
mimeType: nil,
|
||||
expectedContentLength: 0,
|
||||
textEncodingName: nil
|
||||
)
|
||||
return (Data(), response)
|
||||
}
|
||||
|
||||
_ = try await sut.send(TestRequest.get(.urlEncoding(["foo": "bar"])))
|
||||
}
|
||||
|
||||
func test_POST_urlEncoding_returnsValidResponse() async throws {
|
||||
session.onData = { request in
|
||||
let url = try XCTUnwrap(request.url?.absoluteString)
|
||||
let data = try XCTUnwrap(request.httpBody)
|
||||
let decoded = String(data: data, encoding: .utf8)
|
||||
let headerValue = try XCTUnwrap(request.allHTTPHeaderFields?["X-Test"])
|
||||
|
||||
XCTAssertTrue(url.hasPrefix("https://api.example.com"))
|
||||
XCTAssertEqual(decoded, "foo=bar")
|
||||
XCTAssertEqual(request.httpMethod, "POST")
|
||||
XCTAssertEqual(headerValue, "true")
|
||||
|
||||
let response = HTTPURLResponse(
|
||||
url: URL(string: "https://example.com")!,
|
||||
mimeType: nil,
|
||||
expectedContentLength: 0,
|
||||
textEncodingName: nil
|
||||
)
|
||||
return (Data(), response)
|
||||
}
|
||||
|
||||
_ = try await sut.send(TestRequest.post(.urlEncoding(["foo": "bar"])))
|
||||
}
|
||||
}
|
||||
|
||||
private enum TestRequest: HTTPRequest {
|
||||
case get(HTTPPayload?)
|
||||
case post(HTTPPayload)
|
||||
|
||||
var method: HTTPMethod {
|
||||
switch self {
|
||||
case .get:
|
||||
return .get
|
||||
case .post:
|
||||
return .post
|
||||
}
|
||||
}
|
||||
|
||||
var endpoint: HTTPEndpoint {
|
||||
switch self {
|
||||
case .get, .post:
|
||||
return TestEndpoint.generic
|
||||
}
|
||||
}
|
||||
|
||||
var payload: HTTPPayload? {
|
||||
switch self {
|
||||
case let .get(payload):
|
||||
return payload
|
||||
case let .post(payload):
|
||||
return payload
|
||||
}
|
||||
}
|
||||
|
||||
var headers: [String: String] {
|
||||
switch self {
|
||||
case .get, .post:
|
||||
return ["X-Test": "true"]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private enum TestEndpoint: HTTPEndpoint {
|
||||
case generic
|
||||
|
||||
var url: URL {
|
||||
switch self {
|
||||
case .generic:
|
||||
return URL(string: "https://api.example.com/\(UUID().uuidString)")!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
//
|
||||
// HTTPDownloadClient.swift
|
||||
// NetworkingTests
|
||||
//
|
||||
// Created by Majd Alfhaily on 17.01.22.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import Networking
|
||||
|
||||
final class HTTPDownloadClientTests: XCTestCase {
|
||||
private var sut: HTTPDownloadClient!
|
||||
|
||||
override func setUp() {
|
||||
sut = HTTPDownloadClient()
|
||||
}
|
||||
|
||||
func test_download_success_returnsValidResponse() async throws {
|
||||
let source = try XCTUnwrap(URL(string: "https://proof.ovh.net/files/1Mb.dat"))
|
||||
let target = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(UUID().uuidString)
|
||||
var lastValue: Float = 0
|
||||
|
||||
try await sut.download(from: source, to: target) { value in
|
||||
XCTAssertGreaterThanOrEqual(value, lastValue)
|
||||
lastValue = value
|
||||
}
|
||||
|
||||
XCTAssertTrue(FileManager.default.fileExists(atPath: target.path))
|
||||
}
|
||||
|
||||
func test_download_failure_throwsError() async throws {
|
||||
let source = try XCTUnwrap(URL(string: "https://\(UUID().uuidString).test"))
|
||||
let target = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(UUID().uuidString)
|
||||
|
||||
do {
|
||||
try await sut.download(from: source, to: target) { _ in }
|
||||
} catch {
|
||||
XCTAssertNotNil(error)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// HTTPResponseTests.swift
|
||||
// NetworkingTests
|
||||
//
|
||||
// Created by Majd Alfhaily on 17.01.22.
|
||||
//
|
||||
|
||||
import XCTest
|
||||
@testable import Networking
|
||||
|
||||
final class HTTPResponseTests: XCTestCase {
|
||||
func test_decode_jsonData_returnsObject() async throws {
|
||||
let data = try JSONEncoder().encode(["foo": "bar"])
|
||||
let response = HTTPResponse(statusCode: 200, data: data)
|
||||
|
||||
let object = try response.decode([String: String].self, as: .json)
|
||||
XCTAssertEqual(object["foo"], "bar")
|
||||
}
|
||||
|
||||
func test_decode_xmlData_returnsObject() async throws {
|
||||
let data = try PropertyListEncoder().encode(["foo": "bar"])
|
||||
let response = HTTPResponse(statusCode: 200, data: data)
|
||||
|
||||
let object = try response.decode([String: String].self, as: .xml)
|
||||
XCTAssertEqual(object["foo"], "bar")
|
||||
}
|
||||
|
||||
func test_decode_noData_returnsObject() async throws {
|
||||
let response = HTTPResponse(statusCode: 200, data: nil)
|
||||
XCTAssertThrowsError(try response.decode([String: String].self, as: .xml))
|
||||
}
|
||||
|
||||
func test_decode_invalidData_returnsObject() async throws {
|
||||
let data = try PropertyListEncoder().encode(["foo": "bar"])
|
||||
let response = HTTPResponse(statusCode: 200, data: data)
|
||||
|
||||
XCTAssertThrowsError(try response.decode([String: String].self, as: .json))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// URLSessionMock.swift
|
||||
// NetworkingTests
|
||||
//
|
||||
// Created by Majd Alfhaily on 17.01.22.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
import Networking
|
||||
|
||||
final class URLSessionMock: URLSessionInterface {
|
||||
var onData: ((_ request: URLRequest) async throws -> (Data, URLResponse))?
|
||||
|
||||
func data(for request: URLRequest) async throws -> (Data, URLResponse) {
|
||||
guard let onData = onData else {
|
||||
fatalError("Override implementation using `onData`.")
|
||||
}
|
||||
|
||||
return try await onData(request)
|
||||
}
|
||||
}
|
||||
@@ -1,472 +0,0 @@
|
||||
// !$*UTF8*$!
|
||||
{
|
||||
archiveVersion = 1;
|
||||
classes = {
|
||||
};
|
||||
objectVersion = 52;
|
||||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
A9CA48C22658F93F00BC09D5 /* main.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48C12658F93F00BC09D5 /* main.swift */; };
|
||||
A9CA48CA2658FB6900BC09D5 /* ArgumentParser in Frameworks */ = {isa = PBXBuildFile; productRef = A9CA48C92658FB6900BC09D5 /* ArgumentParser */; };
|
||||
A9CA48CD2658FBF700BC09D5 /* Download.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48CC2658FBF700BC09D5 /* Download.swift */; };
|
||||
A9CA48CF2658FC7400BC09D5 /* IPATool.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48CE2658FC7400BC09D5 /* IPATool.swift */; };
|
||||
A9CA48D2265913B300BC09D5 /* HTTPRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48D1265913B300BC09D5 /* HTTPRequest.swift */; };
|
||||
A9CA48D626591AC200BC09D5 /* HTTPClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48D526591AC200BC09D5 /* HTTPClient.swift */; };
|
||||
A9CA48D826591B0400BC09D5 /* URLSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48D726591B0400BC09D5 /* URLSession.swift */; };
|
||||
A9CA48DA26591CE200BC09D5 /* HTTPMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48D926591CE200BC09D5 /* HTTPMethod.swift */; };
|
||||
A9CA48DC26591CF100BC09D5 /* HTTPPayload.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48DB26591CF100BC09D5 /* HTTPPayload.swift */; };
|
||||
A9CA48DE26591D6A00BC09D5 /* HTTPEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48DD26591D6A00BC09D5 /* HTTPEndpoint.swift */; };
|
||||
A9CA48E026591E4000BC09D5 /* HTTPResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48DF26591E4000BC09D5 /* HTTPResponse.swift */; };
|
||||
A9CA48E3265926D200BC09D5 /* iTunesClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48E2265926D200BC09D5 /* iTunesClient.swift */; };
|
||||
A9CA48E5265926DB00BC09D5 /* iTunesRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48E4265926DB00BC09D5 /* iTunesRequest.swift */; };
|
||||
A9CA48E72659273700BC09D5 /* iTunesEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48E62659273700BC09D5 /* iTunesEndpoint.swift */; };
|
||||
A9CA48E92659281F00BC09D5 /* iTunesResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48E82659281F00BC09D5 /* iTunesResponse.swift */; };
|
||||
A9CA48EC26592DD100BC09D5 /* StoreClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48EB26592DD100BC09D5 /* StoreClient.swift */; };
|
||||
A9CA48EE26592DD800BC09D5 /* StoreEndpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48ED26592DD800BC09D5 /* StoreEndpoint.swift */; };
|
||||
A9CA48F026592DE100BC09D5 /* StoreRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48EF26592DE100BC09D5 /* StoreRequest.swift */; };
|
||||
A9CA48F22659317E00BC09D5 /* StoreResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48F12659317E00BC09D5 /* StoreResponse.swift */; };
|
||||
A9CA48F52659423C00BC09D5 /* ZIPFoundation in Frameworks */ = {isa = PBXBuildFile; productRef = A9CA48F42659423C00BC09D5 /* ZIPFoundation */; };
|
||||
A9CA48F8265942D500BC09D5 /* SignatureClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48F7265942D500BC09D5 /* SignatureClient.swift */; };
|
||||
A9CA48FA2659478600BC09D5 /* HTTPDownloadClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48F92659478600BC09D5 /* HTTPDownloadClient.swift */; };
|
||||
A9CA48FD26594B5F00BC09D5 /* Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48FC26594B5F00BC09D5 /* Logging.swift */; };
|
||||
A9CA48FF26594B7A00BC09D5 /* LogLevel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA48FE26594B7A00BC09D5 /* LogLevel.swift */; };
|
||||
A9CA490126594BB000BC09D5 /* ConsoleLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA490026594BB000BC09D5 /* ConsoleLogger.swift */; };
|
||||
A9CA49032659627A00BC09D5 /* Search.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9CA49022659627A00BC09D5 /* Search.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXCopyFilesBuildPhase section */
|
||||
A9CA48BC2658F93F00BC09D5 /* CopyFiles */ = {
|
||||
isa = PBXCopyFilesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
dstPath = /usr/share/man/man1/;
|
||||
dstSubfolderSpec = 0;
|
||||
files = (
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 1;
|
||||
};
|
||||
/* End PBXCopyFilesBuildPhase section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
A9CA48BE2658F93F00BC09D5 /* ipatool */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = ipatool; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
A9CA48C12658F93F00BC09D5 /* main.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = main.swift; sourceTree = "<group>"; };
|
||||
A9CA48CC2658FBF700BC09D5 /* Download.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Download.swift; sourceTree = "<group>"; };
|
||||
A9CA48CE2658FC7400BC09D5 /* IPATool.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IPATool.swift; sourceTree = "<group>"; };
|
||||
A9CA48D1265913B300BC09D5 /* HTTPRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPRequest.swift; sourceTree = "<group>"; };
|
||||
A9CA48D526591AC200BC09D5 /* HTTPClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPClient.swift; sourceTree = "<group>"; };
|
||||
A9CA48D726591B0400BC09D5 /* URLSession.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLSession.swift; sourceTree = "<group>"; };
|
||||
A9CA48D926591CE200BC09D5 /* HTTPMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPMethod.swift; sourceTree = "<group>"; };
|
||||
A9CA48DB26591CF100BC09D5 /* HTTPPayload.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPPayload.swift; sourceTree = "<group>"; };
|
||||
A9CA48DD26591D6A00BC09D5 /* HTTPEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPEndpoint.swift; sourceTree = "<group>"; };
|
||||
A9CA48DF26591E4000BC09D5 /* HTTPResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPResponse.swift; sourceTree = "<group>"; };
|
||||
A9CA48E2265926D200BC09D5 /* iTunesClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iTunesClient.swift; sourceTree = "<group>"; };
|
||||
A9CA48E4265926DB00BC09D5 /* iTunesRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iTunesRequest.swift; sourceTree = "<group>"; };
|
||||
A9CA48E62659273700BC09D5 /* iTunesEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iTunesEndpoint.swift; sourceTree = "<group>"; };
|
||||
A9CA48E82659281F00BC09D5 /* iTunesResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iTunesResponse.swift; sourceTree = "<group>"; };
|
||||
A9CA48EB26592DD100BC09D5 /* StoreClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreClient.swift; sourceTree = "<group>"; };
|
||||
A9CA48ED26592DD800BC09D5 /* StoreEndpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreEndpoint.swift; sourceTree = "<group>"; };
|
||||
A9CA48EF26592DE100BC09D5 /* StoreRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreRequest.swift; sourceTree = "<group>"; };
|
||||
A9CA48F12659317E00BC09D5 /* StoreResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreResponse.swift; sourceTree = "<group>"; };
|
||||
A9CA48F7265942D500BC09D5 /* SignatureClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignatureClient.swift; sourceTree = "<group>"; };
|
||||
A9CA48F92659478600BC09D5 /* HTTPDownloadClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HTTPDownloadClient.swift; sourceTree = "<group>"; };
|
||||
A9CA48FC26594B5F00BC09D5 /* Logging.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = "<group>"; };
|
||||
A9CA48FE26594B7A00BC09D5 /* LogLevel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogLevel.swift; sourceTree = "<group>"; };
|
||||
A9CA490026594BB000BC09D5 /* ConsoleLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConsoleLogger.swift; sourceTree = "<group>"; };
|
||||
A9CA49022659627A00BC09D5 /* Search.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Search.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
A9CA48BB2658F93F00BC09D5 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
A9CA48CA2658FB6900BC09D5 /* ArgumentParser in Frameworks */,
|
||||
A9CA48F52659423C00BC09D5 /* ZIPFoundation in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
A9CA48B52658F93F00BC09D5 = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A9CA48C02658F93F00BC09D5 /* Source */,
|
||||
A9CA48BF2658F93F00BC09D5 /* Products */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A9CA48BF2658F93F00BC09D5 /* Products */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A9CA48BE2658F93F00BC09D5 /* ipatool */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A9CA48C02658F93F00BC09D5 /* Source */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A9CA48CB2658FBEB00BC09D5 /* Commands */,
|
||||
A9CA48E1265926BF00BC09D5 /* iTunes */,
|
||||
A9CA48FB26594B5600BC09D5 /* Logger */,
|
||||
A9CA48D02659138600BC09D5 /* Networking */,
|
||||
A9CA48F6265942A600BC09D5 /* Signature */,
|
||||
A9CA48EA265929E000BC09D5 /* Store */,
|
||||
A9CA48CE2658FC7400BC09D5 /* IPATool.swift */,
|
||||
A9CA48C12658F93F00BC09D5 /* main.swift */,
|
||||
);
|
||||
path = Source;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A9CA48CB2658FBEB00BC09D5 /* Commands */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A9CA48CC2658FBF700BC09D5 /* Download.swift */,
|
||||
A9CA49022659627A00BC09D5 /* Search.swift */,
|
||||
);
|
||||
path = Commands;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A9CA48D02659138600BC09D5 /* Networking */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A9CA48D526591AC200BC09D5 /* HTTPClient.swift */,
|
||||
A9CA48F92659478600BC09D5 /* HTTPDownloadClient.swift */,
|
||||
A9CA48DD26591D6A00BC09D5 /* HTTPEndpoint.swift */,
|
||||
A9CA48D926591CE200BC09D5 /* HTTPMethod.swift */,
|
||||
A9CA48DB26591CF100BC09D5 /* HTTPPayload.swift */,
|
||||
A9CA48D1265913B300BC09D5 /* HTTPRequest.swift */,
|
||||
A9CA48DF26591E4000BC09D5 /* HTTPResponse.swift */,
|
||||
A9CA48D726591B0400BC09D5 /* URLSession.swift */,
|
||||
);
|
||||
path = Networking;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A9CA48E1265926BF00BC09D5 /* iTunes */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A9CA48E2265926D200BC09D5 /* iTunesClient.swift */,
|
||||
A9CA48E62659273700BC09D5 /* iTunesEndpoint.swift */,
|
||||
A9CA48E4265926DB00BC09D5 /* iTunesRequest.swift */,
|
||||
A9CA48E82659281F00BC09D5 /* iTunesResponse.swift */,
|
||||
);
|
||||
path = iTunes;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A9CA48EA265929E000BC09D5 /* Store */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A9CA48EB26592DD100BC09D5 /* StoreClient.swift */,
|
||||
A9CA48ED26592DD800BC09D5 /* StoreEndpoint.swift */,
|
||||
A9CA48EF26592DE100BC09D5 /* StoreRequest.swift */,
|
||||
A9CA48F12659317E00BC09D5 /* StoreResponse.swift */,
|
||||
);
|
||||
path = Store;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A9CA48F6265942A600BC09D5 /* Signature */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A9CA48F7265942D500BC09D5 /* SignatureClient.swift */,
|
||||
);
|
||||
path = Signature;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
A9CA48FB26594B5600BC09D5 /* Logger */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
A9CA48FC26594B5F00BC09D5 /* Logging.swift */,
|
||||
A9CA48FE26594B7A00BC09D5 /* LogLevel.swift */,
|
||||
A9CA490026594BB000BC09D5 /* ConsoleLogger.swift */,
|
||||
);
|
||||
path = Logger;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
A9CA48BD2658F93F00BC09D5 /* IPATool */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = A9CA48C52658F93F00BC09D5 /* Build configuration list for PBXNativeTarget "IPATool" */;
|
||||
buildPhases = (
|
||||
A9CA48BA2658F93F00BC09D5 /* Sources */,
|
||||
A9CA48BB2658F93F00BC09D5 /* Frameworks */,
|
||||
A9CA48BC2658F93F00BC09D5 /* CopyFiles */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = IPATool;
|
||||
packageProductDependencies = (
|
||||
A9CA48C92658FB6900BC09D5 /* ArgumentParser */,
|
||||
A9CA48F42659423C00BC09D5 /* ZIPFoundation */,
|
||||
);
|
||||
productName = ipatool;
|
||||
productReference = A9CA48BE2658F93F00BC09D5 /* ipatool */;
|
||||
productType = "com.apple.product-type.tool";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
A9CA48B62658F93F00BC09D5 /* Project object */ = {
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
LastSwiftUpdateCheck = 1250;
|
||||
LastUpgradeCheck = 1250;
|
||||
TargetAttributes = {
|
||||
A9CA48BD2658F93F00BC09D5 = {
|
||||
CreatedOnToolsVersion = 12.5;
|
||||
};
|
||||
};
|
||||
};
|
||||
buildConfigurationList = A9CA48B92658F93F00BC09D5 /* Build configuration list for PBXProject "ipatool" */;
|
||||
compatibilityVersion = "Xcode 9.3";
|
||||
developmentRegion = en;
|
||||
hasScannedForEncodings = 0;
|
||||
knownRegions = (
|
||||
en,
|
||||
Base,
|
||||
);
|
||||
mainGroup = A9CA48B52658F93F00BC09D5;
|
||||
packageReferences = (
|
||||
A9CA48C82658FB6900BC09D5 /* XCRemoteSwiftPackageReference "swift-argument-parser" */,
|
||||
A9CA48F32659423C00BC09D5 /* XCRemoteSwiftPackageReference "ZIPFoundation" */,
|
||||
);
|
||||
productRefGroup = A9CA48BF2658F93F00BC09D5 /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
A9CA48BD2658F93F00BC09D5 /* IPATool */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
A9CA48BA2658F93F00BC09D5 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
A9CA48CF2658FC7400BC09D5 /* IPATool.swift in Sources */,
|
||||
A9CA48DE26591D6A00BC09D5 /* HTTPEndpoint.swift in Sources */,
|
||||
A9CA48E026591E4000BC09D5 /* HTTPResponse.swift in Sources */,
|
||||
A9CA48D626591AC200BC09D5 /* HTTPClient.swift in Sources */,
|
||||
A9CA48DA26591CE200BC09D5 /* HTTPMethod.swift in Sources */,
|
||||
A9CA48E3265926D200BC09D5 /* iTunesClient.swift in Sources */,
|
||||
A9CA48F026592DE100BC09D5 /* StoreRequest.swift in Sources */,
|
||||
A9CA48D826591B0400BC09D5 /* URLSession.swift in Sources */,
|
||||
A9CA48E5265926DB00BC09D5 /* iTunesRequest.swift in Sources */,
|
||||
A9CA48D2265913B300BC09D5 /* HTTPRequest.swift in Sources */,
|
||||
A9CA48FD26594B5F00BC09D5 /* Logging.swift in Sources */,
|
||||
A9CA48C22658F93F00BC09D5 /* main.swift in Sources */,
|
||||
A9CA48EC26592DD100BC09D5 /* StoreClient.swift in Sources */,
|
||||
A9CA490126594BB000BC09D5 /* ConsoleLogger.swift in Sources */,
|
||||
A9CA48F8265942D500BC09D5 /* SignatureClient.swift in Sources */,
|
||||
A9CA48E92659281F00BC09D5 /* iTunesResponse.swift in Sources */,
|
||||
A9CA48FF26594B7A00BC09D5 /* LogLevel.swift in Sources */,
|
||||
A9CA48EE26592DD800BC09D5 /* StoreEndpoint.swift in Sources */,
|
||||
A9CA48DC26591CF100BC09D5 /* HTTPPayload.swift in Sources */,
|
||||
A9CA48E72659273700BC09D5 /* iTunesEndpoint.swift in Sources */,
|
||||
A9CA48F22659317E00BC09D5 /* StoreResponse.swift in Sources */,
|
||||
A9CA49032659627A00BC09D5 /* Search.swift in Sources */,
|
||||
A9CA48FA2659478600BC09D5 /* HTTPDownloadClient.swift in Sources */,
|
||||
A9CA48CD2658FBF700BC09D5 /* Download.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
A9CA48C32658F93F00BC09D5 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_DYNAMIC_NO_PIC = NO;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_OPTIMIZATION_LEVEL = 0;
|
||||
GCC_PREPROCESSOR_DEFINITIONS = (
|
||||
"DEBUG=1",
|
||||
"$(inherited)",
|
||||
);
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 11.3;
|
||||
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
|
||||
MTL_FAST_MATH = YES;
|
||||
ONLY_ACTIVE_ARCH = YES;
|
||||
SDKROOT = macosx;
|
||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
A9CA48C42658F93F00BC09D5 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ALWAYS_SEARCH_USER_PATHS = NO;
|
||||
CLANG_ANALYZER_NONNULL = YES;
|
||||
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
|
||||
CLANG_CXX_LIBRARY = "libc++";
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CLANG_ENABLE_OBJC_ARC = YES;
|
||||
CLANG_ENABLE_OBJC_WEAK = YES;
|
||||
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
|
||||
CLANG_WARN_BOOL_CONVERSION = YES;
|
||||
CLANG_WARN_COMMA = YES;
|
||||
CLANG_WARN_CONSTANT_CONVERSION = YES;
|
||||
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
|
||||
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
|
||||
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
|
||||
CLANG_WARN_EMPTY_BODY = YES;
|
||||
CLANG_WARN_ENUM_CONVERSION = YES;
|
||||
CLANG_WARN_INFINITE_RECURSION = YES;
|
||||
CLANG_WARN_INT_CONVERSION = YES;
|
||||
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
|
||||
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
|
||||
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
|
||||
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
|
||||
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
|
||||
CLANG_WARN_STRICT_PROTOTYPES = YES;
|
||||
CLANG_WARN_SUSPICIOUS_MOVE = YES;
|
||||
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
|
||||
CLANG_WARN_UNREACHABLE_CODE = YES;
|
||||
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
|
||||
COPY_PHASE_STRIP = NO;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
GCC_C_LANGUAGE_STANDARD = gnu11;
|
||||
GCC_NO_COMMON_BLOCKS = YES;
|
||||
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
|
||||
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
||||
GCC_WARN_UNDECLARED_SELECTOR = YES;
|
||||
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
|
||||
GCC_WARN_UNUSED_FUNCTION = YES;
|
||||
GCC_WARN_UNUSED_VARIABLE = YES;
|
||||
MACOSX_DEPLOYMENT_TARGET = 11.3;
|
||||
MTL_ENABLE_DEBUG_INFO = NO;
|
||||
MTL_FAST_MATH = YES;
|
||||
SDKROOT = macosx;
|
||||
SWIFT_COMPILATION_MODE = wholemodule;
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-O";
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
A9CA48C62658F93F00BC09D5 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
PRODUCT_NAME = ipatool;
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
A9CA48C72658F93F00BC09D5 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
MACOSX_DEPLOYMENT_TARGET = 10.11;
|
||||
PRODUCT_NAME = ipatool;
|
||||
SWIFT_VERSION = 5.0;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
A9CA48B92658F93F00BC09D5 /* Build configuration list for PBXProject "ipatool" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
A9CA48C32658F93F00BC09D5 /* Debug */,
|
||||
A9CA48C42658F93F00BC09D5 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
A9CA48C52658F93F00BC09D5 /* Build configuration list for PBXNativeTarget "IPATool" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
A9CA48C62658F93F00BC09D5 /* Debug */,
|
||||
A9CA48C72658F93F00BC09D5 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
|
||||
/* Begin XCRemoteSwiftPackageReference section */
|
||||
A9CA48C82658FB6900BC09D5 /* XCRemoteSwiftPackageReference "swift-argument-parser" */ = {
|
||||
isa = XCRemoteSwiftPackageReference;
|
||||
repositoryURL = "https://github.com/apple/swift-argument-parser";
|
||||
requirement = {
|
||||
kind = exactVersion;
|
||||
version = 0.4.3;
|
||||
};
|
||||
};
|
||||
A9CA48F32659423C00BC09D5 /* XCRemoteSwiftPackageReference "ZIPFoundation" */ = {
|
||||
isa = XCRemoteSwiftPackageReference;
|
||||
repositoryURL = "https://github.com/weichsel/ZIPFoundation.git";
|
||||
requirement = {
|
||||
kind = exactVersion;
|
||||
version = 0.9.12;
|
||||
};
|
||||
};
|
||||
/* End XCRemoteSwiftPackageReference section */
|
||||
|
||||
/* Begin XCSwiftPackageProductDependency section */
|
||||
A9CA48C92658FB6900BC09D5 /* ArgumentParser */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = A9CA48C82658FB6900BC09D5 /* XCRemoteSwiftPackageReference "swift-argument-parser" */;
|
||||
productName = ArgumentParser;
|
||||
};
|
||||
A9CA48F42659423C00BC09D5 /* ZIPFoundation */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = A9CA48F32659423C00BC09D5 /* XCRemoteSwiftPackageReference "ZIPFoundation" */;
|
||||
productName = ZIPFoundation;
|
||||
};
|
||||
/* End XCSwiftPackageProductDependency section */
|
||||
};
|
||||
rootObject = A9CA48B62658F93F00BC09D5 /* Project object */;
|
||||
}
|
||||
Reference in new issue
Block a user