mirror of
https://github.com/majd/ipatool
synced 2026-11-30 11:08:06 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff43c07a32 | ||
|
|
07a0f3310d | ||
|
|
9cfd72d142 |
No files matched your search
@@ -51,7 +51,7 @@ jobs:
|
||||
- name: Inject version
|
||||
run: ./Scripts/version
|
||||
- name: Build
|
||||
run: make build
|
||||
run: make build-macos
|
||||
- name: Upload binary
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
@@ -77,34 +77,8 @@ jobs:
|
||||
run: ./Scripts/version
|
||||
- name: Install dependencies
|
||||
run: brew install xcodegen ldid
|
||||
- name: Generate Xcode project
|
||||
run: xcodegen -s ios-project.yml
|
||||
- name: Build archive
|
||||
run: |
|
||||
xcodebuild archive -scheme CLI \
|
||||
-sdk iphoneos \
|
||||
-configuration Release \
|
||||
-derivedDataPath .build \
|
||||
-archivePath .build/ipatool.xcarchive \
|
||||
CODE_SIGN_IDENTITY='' \
|
||||
CODE_SIGNING_REQUIRED=NO \
|
||||
CODE_SIGN_ENTITLEMENTS='' \
|
||||
CODE_SIGNING_ALLOWED=NO
|
||||
cp .build/ipatool.xcarchive/Products/Applications/CLI.app/CLI .build/ipatool
|
||||
- name: Fakesign executable
|
||||
run: |
|
||||
cat <<EOF >"$PWD/.build/entitlements.xml"
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>platform-application</key>
|
||||
<true />
|
||||
<key>com.apple.private.security.container-required</key>
|
||||
<false />
|
||||
</dict>
|
||||
</plist>
|
||||
EOF
|
||||
ldid -S.build/entitlements.xml ./.build/ipatool
|
||||
- name: Build
|
||||
run: make build-ios
|
||||
- name: Upload binary
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
|
||||
@@ -20,39 +20,14 @@ jobs:
|
||||
restore-keys: |
|
||||
${{ runner.os }}-spm-${{ hashFiles('Package.resolved') }}
|
||||
${{ runner.os }}-spm-
|
||||
- name: Inject version
|
||||
run: ./Scripts/version
|
||||
- name: Install dependencies
|
||||
run: brew install xcodegen ldid
|
||||
- name: Generate Xcode project
|
||||
run: xcodegen -s ios-project.yml
|
||||
- name: Build archive
|
||||
- name: Inject version
|
||||
run: ./Scripts/version
|
||||
- name: Build
|
||||
run: |
|
||||
xcodebuild archive -scheme CLI \
|
||||
-sdk iphoneos \
|
||||
-configuration Release \
|
||||
-derivedDataPath .build \
|
||||
-archivePath .build/ipatool.xcarchive \
|
||||
CODE_SIGN_IDENTITY='' \
|
||||
CODE_SIGNING_REQUIRED=NO \
|
||||
CODE_SIGN_ENTITLEMENTS='' \
|
||||
CODE_SIGNING_ALLOWED=NO
|
||||
cp .build/ipatool.xcarchive/Products/Applications/CLI.app/CLI .build/ipatool
|
||||
make build-ios
|
||||
file .build/ipatool
|
||||
- name: Fakesign executable
|
||||
run: |
|
||||
cat <<EOF >"$PWD/.build/entitlements.xml"
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>platform-application</key>
|
||||
<true />
|
||||
<key>com.apple.private.security.container-required</key>
|
||||
<false />
|
||||
</dict>
|
||||
</plist>
|
||||
EOF
|
||||
ldid -S.build/entitlements.xml ./.build/ipatool
|
||||
build_macos:
|
||||
name: Dry build (macOS)
|
||||
runs-on: macos-12
|
||||
@@ -71,5 +46,5 @@ jobs:
|
||||
run: ./Scripts/version
|
||||
- name: Build
|
||||
run: |
|
||||
make build
|
||||
make build-macos
|
||||
file .build/ipatool
|
||||
@@ -26,7 +26,7 @@ jobs:
|
||||
- name: Inject version
|
||||
run: ./Scripts/version
|
||||
- name: Build
|
||||
run: make build
|
||||
run: make build-macos
|
||||
- name: Upload binary
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
|
||||
@@ -1,22 +1,57 @@
|
||||
prefix ?= /usr/local
|
||||
bindir = $(prefix)/bin
|
||||
|
||||
define ios_entitlements
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>keychain-access-groups</key>
|
||||
<array>
|
||||
<string>ipatool</string>
|
||||
</array>
|
||||
<key>application-identifier</key>
|
||||
<string>ipatool</string>
|
||||
<key>platform-application</key>
|
||||
<true />
|
||||
<key>com.apple.private.security.container-required</key>
|
||||
<false />
|
||||
</dict>
|
||||
</plist>
|
||||
endef
|
||||
|
||||
lint:
|
||||
swiftlint lint --config .swiftlint.yml --path Sources/ Tests/m Plugins/
|
||||
|
||||
build: lint
|
||||
build-macos: lint
|
||||
swift build -c release --arch arm64
|
||||
swift build -c release --arch x86_64
|
||||
lipo -create -output .build/ipatool .build/arm64-apple-macosx/release/ipatool .build/x86_64-apple-macosx/release/ipatool
|
||||
|
||||
install: build
|
||||
build-ios: lint
|
||||
xcodegen -s ios-project.yml
|
||||
xcodebuild archive -scheme CLI \
|
||||
-sdk iphoneos \
|
||||
-configuration Release \
|
||||
-derivedDataPath .build \
|
||||
-archivePath .build/ipatool.xcarchive \
|
||||
CODE_SIGN_IDENTITY='' \
|
||||
CODE_SIGNING_REQUIRED=NO \
|
||||
CODE_SIGN_ENTITLEMENTS='' \
|
||||
CODE_SIGNING_ALLOWED=NO
|
||||
cp .build/ipatool.xcarchive/Products/Applications/CLI.app/CLI .build/ipatool
|
||||
echo "$$ios_entitlements" > "${PWD}/.build/entitlements.xml"
|
||||
ldid -S.build/entitlements.xml ./.build/ipatool
|
||||
|
||||
install-macos: build
|
||||
install -d "$(bindir)"
|
||||
install ".build/ipatool" "$(bindir)"
|
||||
|
||||
uninstall:
|
||||
uninstall-macos:
|
||||
rm -rf "$(bindir)/ipatool"
|
||||
|
||||
clean:
|
||||
rm -rf .build
|
||||
|
||||
.PHONY: build install uninstall clean
|
||||
.PHONY: build-macos install-macos uninstall-macos clean
|
||||
|
||||
export ios_entitlements
|
||||
@@ -110,7 +110,7 @@ extension Download {
|
||||
"The country provided does not match with the account you are using.",
|
||||
"Supply a valid country using the \"--country\" flag."
|
||||
].joined(separator: " "), level: .error)
|
||||
case StoreResponse.Error.passwordTokenExpired:
|
||||
case StoreResponse.Error.passwordTokenExpired, StoreResponse.Error.passwordChanged:
|
||||
logger.log("Token expired. Login again using the \"auth\" command.", level: .error)
|
||||
default:
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
@@ -164,7 +164,7 @@ extension Download {
|
||||
"The country provided does not match with the account you are using.",
|
||||
"Supply a valid country using the \"--country\" flag."
|
||||
].joined(separator: " "), level: .error)
|
||||
case StoreResponse.Error.passwordTokenExpired:
|
||||
case StoreResponse.Error.passwordTokenExpired, StoreResponse.Error.passwordChanged:
|
||||
logger.log("Token expired. Login again using the \"auth\" command.", level: .error)
|
||||
default:
|
||||
logger.log([
|
||||
@@ -203,6 +203,30 @@ extension Download {
|
||||
logger.log("Applying patches...", level: .info)
|
||||
try signatureClient.appendMetadata(item: item, email: email)
|
||||
try signatureClient.appendSignature(item: item)
|
||||
} catch {
|
||||
switch error {
|
||||
case SignatureClient.Error.fileNotFound:
|
||||
logger.log(
|
||||
"App uses old code signature version, falling back to alternative patching mechanism.",
|
||||
level: .debug
|
||||
)
|
||||
logger.log("The produced app package may not be compatible with modern iOS releases.", level: .info)
|
||||
applyOldPatches(item: item, email: email, path: path)
|
||||
default:
|
||||
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 applyOldPatches(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 fallback patches...", level: .info)
|
||||
try signatureClient.appendOldSignature(item: item)
|
||||
} catch {
|
||||
logger.log("\(error)", level: .debug)
|
||||
logger.log("Failed to apply patches. The ipa file will be left incomplete.", level: .error)
|
||||
|
||||
@@ -103,7 +103,7 @@ extension Purchase {
|
||||
"The country provided does not match with the account you are using.",
|
||||
"Supply a valid country using the \"--country\" flag."
|
||||
].joined(separator: " "), level: .error)
|
||||
case StoreResponse.Error.passwordTokenExpired:
|
||||
case StoreResponse.Error.passwordTokenExpired, StoreResponse.Error.passwordChanged:
|
||||
logger.log("Token expired. Login again using the \"auth\" command.", level: .error)
|
||||
default:
|
||||
logger.log("An unknown error has occurred.", level: .error)
|
||||
|
||||
@@ -51,6 +51,18 @@ public final class SignatureClient: SignatureClientInterface {
|
||||
throw Error.invalidArchive
|
||||
}
|
||||
|
||||
try appendSignatureFromManfiest(forItem: item, inArchive: archive)
|
||||
}
|
||||
|
||||
public func appendOldSignature(item: StoreResponse.Item) throws {
|
||||
guard let archive = Archive(url: URL(fileURLWithPath: filePath), accessMode: .update) else {
|
||||
throw Error.invalidArchive
|
||||
}
|
||||
|
||||
try appendOldSignature(forItem: item, inArchive: archive)
|
||||
}
|
||||
|
||||
private func appendSignatureFromManfiest(forItem item: StoreResponse.Item, inArchive archive: Archive) throws {
|
||||
let manifest = try readPlist(
|
||||
archive: archive,
|
||||
matchingSuffix: ".app/SC_Info/Manifest.plist",
|
||||
@@ -87,6 +99,52 @@ public final class SignatureClient: SignatureClientInterface {
|
||||
try fileManager.removeItem(at: signatureBaseUrl)
|
||||
}
|
||||
|
||||
private func appendOldSignature(forItem item: StoreResponse.Item, inArchive archive: Archive) throws {
|
||||
guard let infoEntry = archive.first(where: { $0.path.hasSuffix(".app/Info.plist") }) else {
|
||||
throw Error.invalidAppBundle
|
||||
}
|
||||
|
||||
let temporaryInfoURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(UUID().uuidString)
|
||||
_ = try archive.extract(infoEntry, to: temporaryInfoURL, skipCRC32: true)
|
||||
let infoData = try Data(contentsOf: temporaryInfoURL)
|
||||
|
||||
guard let infoPlist = try PropertyListSerialization.propertyList(
|
||||
from: infoData,
|
||||
format: nil
|
||||
) as? [String: Any] else {
|
||||
throw Error.invalidAppBundle
|
||||
}
|
||||
|
||||
guard let executableName = infoPlist["CFBundleExecutable"] as? String else {
|
||||
throw Error.invalidAppBundle
|
||||
}
|
||||
|
||||
let appBundleName = URL(fileURLWithPath: infoEntry.path)
|
||||
.deletingLastPathComponent()
|
||||
.deletingPathExtension()
|
||||
.lastPathComponent
|
||||
|
||||
guard let signatureItem = item.signatures.first(where: { $0.id == 0 }) else {
|
||||
throw Error.invalidSignature
|
||||
}
|
||||
|
||||
let signatureBaseUrl = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(UUID().uuidString)
|
||||
let signatureUrl = signatureBaseUrl
|
||||
.appendingPathComponent("Payload")
|
||||
.appendingPathComponent(appBundleName)
|
||||
.appendingPathExtension("app")
|
||||
.appendingPathComponent("SC_Info")
|
||||
.appendingPathComponent(executableName)
|
||||
.appendingPathExtension("sinf")
|
||||
|
||||
let signatureRelativePath = signatureUrl.path.replacingOccurrences(of: "\(signatureBaseUrl.path)/", with: "")
|
||||
|
||||
try fileManager.createDirectory(at: signatureUrl.deletingLastPathComponent(), withIntermediateDirectories: true)
|
||||
try signatureItem.sinf.write(to: signatureUrl)
|
||||
try archive.addEntry(with: signatureRelativePath, relativeTo: signatureBaseUrl)
|
||||
try fileManager.removeItem(at: signatureBaseUrl)
|
||||
}
|
||||
|
||||
private func readPlist<T: Decodable>(archive: Archive, matchingSuffix: String, type: T.Type) throws -> T {
|
||||
guard let entry = archive.first(where: { $0.path.hasSuffix(matchingSuffix) }) else {
|
||||
throw Error.fileNotFound(matchingSuffix)
|
||||
@@ -115,7 +173,7 @@ extension SignatureClient {
|
||||
}
|
||||
}
|
||||
|
||||
enum Error: Swift.Error {
|
||||
public enum Error: Swift.Error {
|
||||
case invalidArchive
|
||||
case invalidAppBundle
|
||||
case invalidSignature
|
||||
|
||||
@@ -15,6 +15,7 @@ public enum StoreResponse {
|
||||
|
||||
public enum Error: Int, Swift.Error {
|
||||
case unknownError = 0
|
||||
case passwordChanged = 2002
|
||||
case genericError = 5002
|
||||
case codeRequired = 1
|
||||
case invalidLicense = 9610
|
||||
|
||||
Reference in new issue
Block a user