clean-checkpoint-1

This commit is contained in:
Magesh K
2024-12-07 17:45:09 +05:30
parent e27c5f0b87
commit 63a3203e50
95 changed files with 1040 additions and 3761 deletions

View File

@@ -8,12 +8,6 @@
#import "NSError+ALTServerError.h"
#if TARGET_OS_OSX
#import "AltServer-Swift.h"
#else
#import "AltStoreCore/AltStoreCore-Swift.h"
#endif
#if ALTJIT
#import "AltJIT-Swift.h"
@import AltSign;
@@ -26,10 +20,9 @@
#endif
NSErrorDomain const AltServerErrorDomain = @"AltServer.ServerError";
NSErrorDomain const AltServerInstallationErrorDomain = @"AltServer.InstallationError";
NSErrorDomain const AltServerInstallationErrorDomain = @"Apple.InstallationError";
NSErrorDomain const AltServerConnectionErrorDomain = @"AltServer.ConnectionError";
NSErrorUserInfoKey const ALTUnderlyingErrorDomainErrorKey = @"underlyingErrorDomain";
NSErrorUserInfoKey const ALTUnderlyingErrorCodeErrorKey = @"underlyingErrorCode";
NSErrorUserInfoKey const ALTProvisioningProfileBundleIDErrorKey = @"bundleIdentifier";
@@ -219,7 +212,7 @@ NSErrorUserInfoKey const ALTNSCodingPathKey = @"NSCodingPath";
if (underlyingError != nil) {
return underlyingError.localizedFailureReason ?: underlyingError.localizedDescription;
}
return NSLocalizedString(@"An error occured while installing the app.", @"");
return NSLocalizedString(@"An error occurred while installing the app.", @"");
}
case ALTServerErrorMaximumFreeAppLimitReached:
@@ -289,7 +282,9 @@ NSErrorUserInfoKey const ALTNSCodingPathKey = @"NSCodingPath";
if (underlyingError.localizedRecoverySuggestion != nil){
return underlyingError.localizedRecoverySuggestion;
}
// If there is no underlying error found, fall through to AltServerErrorDeviceNotFound
// If there is no underlying error, fall through to ALTServerErrorDeviceNotFound.
// return nil;
}
case ALTServerErrorDeviceNotFound:
return NSLocalizedString(@"Make sure you have trusted this device with your computer and Wi-Fi sync is enabled.", @"");

View File

@@ -75,8 +75,8 @@ public extension ALTLocalizedError
var userInfo: [String: Any?] = [
NSLocalizedFailureErrorKey: self.errorFailure,
ALTLocalizedTitleErrorKey: self.errorTitle,
// ALTSourceFileErrorKey: self.sourceFile, // TODO: Figure out where these come from
// ALTSourceLineErrorKey: self.sourceLine,
ALTSourceFileErrorKey: self.sourceFile,
ALTSourceLineErrorKey: self.sourceLine,
]
userInfo.merge(self.userInfoValues) { (_, new) in new }

View File

@@ -30,6 +30,7 @@
_wrappedError = [error copy];
}
}
return self;
}

View File

@@ -1,66 +0,0 @@
//
// JITError.swift
// AltJIT
//
// Created by Riley Testut on 9/3/23.
// Copyright © 2023 Riley Testut. All rights reserved.
//
import Foundation
extension JITError
{
enum Code: Int, ALTErrorCode
{
typealias Error = JITError
case processNotRunning
case dependencyNotFound
}
static func processNotRunning(_ process: AppProcess, file: StaticString = #file, line: Int = #line) -> JITError {
JITError(code: .processNotRunning, process: process, sourceFile: file, sourceLine: UInt(line))
}
static func dependencyNotFound(_ dependency: String?, file: StaticString = #file, line: Int = #line) -> JITError {
let errorFailure = NSLocalizedString("AltServer requires additional dependencies to enable JIT on iOS 17.", comment: "")
return JITError(code: .dependencyNotFound, errorFailure: errorFailure, dependency: dependency, faq: "https://faq.altstore.io/how-to-use-altstore/altjit", sourceFile: file, sourceLine: UInt(line))
}
}
struct JITError: ALTLocalizedError
{
let code: Code
var errorTitle: String?
var errorFailure: String?
@UserInfoValue var process: AppProcess?
@UserInfoValue var dependency: String?
@UserInfoValue var faq: String? // Show user FAQ URL in AltStore error log.
var sourceFile: StaticString?
var sourceLine: UInt?
var errorFailureReason: String {
switch self.code
{
case .processNotRunning:
let targetName = self.process?.description ?? NSLocalizedString("The target app", comment: "")
return String(format: NSLocalizedString("%@ is not running.", comment: ""), targetName)
case .dependencyNotFound:
let dependencyName = self.dependency.map { "'\($0)'" } ?? NSLocalizedString("A required dependency", comment: "")
return String(format: NSLocalizedString("%@ is not installed.", comment: ""), dependencyName)
}
}
var recoverySuggestion: String? {
switch self.code
{
case .processNotRunning: return NSLocalizedString("Make sure the app is running in the foreground on your device then try again.", comment: "")
case .dependencyNotFound: return NSLocalizedString("Please follow the instructions on the AltStore FAQ to install all required dependencies, then try again.", comment: "")
}
}
}

View File

@@ -25,6 +25,7 @@ public extension ALTServerError
// because it'll still be accessible via error.underlyingError.underlyingError.
var userInfo = error.userInfo
userInfo[NSUnderlyingErrorKey] = error
self = ALTServerError(.underlyingError, userInfo: userInfo)
}
}

View File

@@ -17,6 +17,7 @@ public extension Bundle
public static let certificateID = "ALTCertificateID"
public static let appGroups = "ALTAppGroups"
public static let altBundleID = "ALTBundleIdentifier"
public static let orgbundleIdentifier = "com.SideStore"
public static let appbundleIdentifier = orgbundleIdentifier + ".SideStore"
public static let devicePairingString = "ALTPairingFile"

View File

@@ -34,7 +34,8 @@ public extension NSError
@objc(alt_localizedTitle)
var localizedTitle: String? {
return self.userInfo[ALTLocalizedTitleErrorKey] as? String
let localizedTitle = self.userInfo[ALTLocalizedTitleErrorKey] as? String
return localizedTitle
}
@objc(alt_errorWithLocalizedFailure:)
@@ -48,14 +49,17 @@ public extension NSError
default:
var userInfo = self.userInfo
userInfo[NSLocalizedFailureReasonErrorKey] = failure
userInfo[NSLocalizedFailureErrorKey] = failure
return ALTWrappedError(error: self, userInfo: userInfo)
let error = ALTWrappedError(error: self, userInfo: userInfo)
return error
}
}
@objc(alt_errorWithLocalizedTitle:)
func withLocalizedTitle(_ title: String) -> NSError {
switch self
func withLocalizedTitle(_ title: String) -> NSError
{
switch self
{
case var error as any ALTLocalizedError:
error.errorTitle = title
@@ -64,8 +68,9 @@ public extension NSError
default:
var userInfo = self.userInfo
userInfo[ALTLocalizedTitleErrorKey] = title
return ALTWrappedError(error: self, userInfo: userInfo)
let error = ALTWrappedError(error: self, userInfo: userInfo)
return error
}
}
@@ -77,6 +82,7 @@ public extension NSError
userInfo[NSLocalizedFailureReasonErrorKey] = self.localizedFailureReason
userInfo[NSLocalizedRecoverySuggestionErrorKey] = self.localizedRecoverySuggestion
userInfo[NSDebugDescriptionErrorKey] = self.localizedDebugDescription
// Remove userInfo values that don't conform to NSSecureEncoding.
userInfo = userInfo.filter { (key, value) in
guard let secureCodable = value as? NSSecureCoding else { return false }
@@ -111,13 +117,16 @@ public extension NSError
let error = NSError(domain: self.domain, code: self.code, userInfo: userInfo)
return error
}
func formattedDetailedDescription(with font: ALTFont) -> NSAttributedString {
#if canImport(UIKit)
func formattedDetailedDescription(with font: ALTFont) -> NSAttributedString
{
#if canImport(UIKit)
let boldFontDescriptor = font.fontDescriptor.withSymbolicTraits(.traitBold) ?? font.fontDescriptor
#else
let boldFont = ALTFont(descriptor: boldFontDescriptor, size: font.pointSize)
#else
let boldFontDescriptor = font.fontDescriptor.withSymbolicTraits(.bold)
#endif
let boldFont = ALTFont(descriptor: boldFontDescriptor, size: font.pointSize) ?? font
#endif
var preferredKeyOrder = [
NSDebugDescriptionErrorKey,
@@ -126,12 +135,13 @@ public extension NSError
NSLocalizedFailureReasonErrorKey,
NSLocalizedRecoverySuggestionErrorKey,
ALTLocalizedTitleErrorKey,
// ALTSourceFileErrorKey,
// ALTSourceLineErrorKey,
ALTSourceFileErrorKey,
ALTSourceLineErrorKey,
NSUnderlyingErrorKey
]
if #available(iOS 14.5, macOS 11.3, *) {
if #available(iOS 14.5, macOS 11.3, *)
{
preferredKeyOrder.append(NSMultipleUnderlyingErrorsKey)
}
@@ -142,14 +152,16 @@ public extension NSError
userInfo[NSLocalizedFailureReasonErrorKey] = self.localizedFailureReason
userInfo[NSLocalizedRecoverySuggestionErrorKey] = self.localizedRecoverySuggestion
let sortedUserInfo = userInfo.sorted { a, b in
let sortedUserInfo = userInfo.sorted { (a, b) in
let indexA = preferredKeyOrder.firstIndex(of: a.key)
let indexB = preferredKeyOrder.firstIndex(of: b.key)
switch (indexA, indexB) {
switch (indexA, indexB)
{
case (let indexA?, let indexB?): return indexA < indexB
case (_?, nil): return true // indexA exists, indexB is nil, indexA should come first
case (nil, _?): return false // indexB exists, indexB is nil, indexB should come first
case (nil, nil): return a.key < b.key // both nil, so sort alphabetically
case (_?, nil): return true // indexA exists, indexB is nil, so A should come first.
case (nil, _?): return false // indexA is nil, indexB exists, so B should come first.
case (nil, nil): return a.key < b.key // both indexes are nil, so sort alphabetically.
}
}
@@ -166,8 +178,8 @@ public extension NSError
case NSLocalizedFailureReasonErrorKey: keyName = NSLocalizedString("Failure Reason", comment: "")
case NSLocalizedRecoverySuggestionErrorKey: keyName = NSLocalizedString("Recovery Suggestion", comment: "")
case ALTLocalizedTitleErrorKey: keyName = NSLocalizedString("Title", comment: "")
// case ALTSourceFileErrorKey: keyName = NSLocalizedString("Source File", comment: "")
// case ALTSourceLineErrorKey: keyName = NSLocalizedString("Source Line", comment: "")
case ALTSourceFileErrorKey: keyName = NSLocalizedString("Source File", comment: "")
case ALTSourceLineErrorKey: keyName = NSLocalizedString("Source Line", comment: "")
case NSUnderlyingErrorKey: keyName = NSLocalizedString("Underlying Error", comment: "")
default:
if #available(iOS 14.5, macOS 11.3, *), key == NSMultipleUnderlyingErrorsKey
@@ -214,27 +226,32 @@ public extension NSError
typealias UserInfoProvider = (Error, String) -> Any?
@objc
class func alt_setUserInfoValueProvider(forDomain domain: String, provider: UserInfoProvider?) {
NSError.setUserInfoValueProvider(forDomain: domain) { error, key in
class func alt_setUserInfoValueProvider(forDomain domain: String, provider: UserInfoProvider?)
{
NSError.setUserInfoValueProvider(forDomain: domain) { (error, key) in
let nsError = error as NSError
switch key{
switch key
{
case NSLocalizedDescriptionKey:
if nsError.localizedFailure != nil {
// Error has localizedFailure, so return nil to construct localizedDescription from it + localizedFailureReason
if nsError.localizedFailure != nil
{
// Error has localizedFailure, so return nil to construct localizedDescription from it + localizedFailureReason.
return nil
} else if let localizedDescription = provider?(error, NSLocalizedDescriptionKey) as? String {
// Only call provider() if there is no localizedFailure
}
else if let localizedDescription = provider?(error, NSLocalizedDescriptionKey) as? String
{
// Only call provider() if there is no localizedFailure.
return localizedDescription
}
/* Otherwise return failureReason for localizedDescription to avoid system prepending "Operation Failed" message
Do NOT return provider(NSLocalizedFailureReason) which might be unexpectedly nil if unrecognized error code. */
// Otherwise, return failureReason for localizedDescription to avoid system prepending "Operation Failed" message.
// Do NOT return provider(NSLocalizedFailureReason), which might be unexpectedly nil if unrecognized error code.
return nsError.localizedFailureReason
default:
return provider?(error, key)
let value = provider?(error, key)
return value
}
}
}
@@ -243,21 +260,27 @@ public extension NSError
public extension Error
{
var underlyingError: Error? {
return (self as NSError).userInfo[NSUnderlyingErrorKey] as? Error
let underlyingError = (self as NSError).userInfo[NSUnderlyingErrorKey] as? Error
return underlyingError
}
var localizedErrorCode: String {
return String(format: NSLocalizedString("%@ %@", comment: ""), (self as NSError).domain, self.displayCode as NSNumber)
let nsError = self as NSError
let localizedErrorCode = String(format: NSLocalizedString("%@ %@", comment: ""), nsError.domain, self.displayCode as NSNumber)
return localizedErrorCode
}
var displayCode: Int {
guard let serverError = self as? ALTServerError else {
// Not ALTServerError, so display regular code.
return (self as NSError).code
}
/* We want AltServerError codes to start at 2000, but we can't change them without breaking AltServer compatibility.
Instead we just add 2000 when displaying code to the user to make it appear as if the codes start at 2000 anyway.
*/
return 2000 + serverError.code.rawValue
// We want ALTServerError codes to start at 2000,
// but we can't change them without breaking AltServer compatibility.
// Instead, we just add 2000 when displaying code to user
// to make it appear as if codes start at 2000 normally.
let code = 2000 + serverError.code.rawValue
return code
}
}

View File

@@ -2,17 +2,21 @@
// OperatingSystemVersion+Comparable.swift
// AltStoreCore
//
// Created by nythepegasus on 5/9/24.
// Created by Riley Testut on 11/15/22.
// Copyright © 2022 Riley Testut. All rights reserved.
//
import Foundation
extension OperatingSystemVersion: Comparable {
public static func ==(lhs: OperatingSystemVersion, rhs: OperatingSystemVersion) -> Bool {
extension OperatingSystemVersion: Comparable
{
public static func ==(lhs: OperatingSystemVersion, rhs: OperatingSystemVersion) -> Bool
{
return lhs.majorVersion == rhs.majorVersion && lhs.minorVersion == rhs.minorVersion && lhs.patchVersion == rhs.patchVersion
}
public static func <(lhs: OperatingSystemVersion, rhs: OperatingSystemVersion) -> Bool {
public static func <(lhs: OperatingSystemVersion, rhs: OperatingSystemVersion) -> Bool
{
return lhs.stringValue.compare(rhs.stringValue, options: .numeric) == .orderedAscending
}
}

View File

@@ -30,6 +30,7 @@ extension CodableError
case codableError(CodableError)
indirect case array([UserInfoValue])
indirect case dictionary([String: UserInfoValue])
var value: Any? {
switch self
{
@@ -42,6 +43,7 @@ extension CodableError
case .dictionary(let dictionary): return dictionary.compactMapValues { $0.value } // .compactMapValues instead of .mapValues to ensure nil values are removed.
}
}
var codableValue: Codable? {
switch self
{
@@ -52,10 +54,12 @@ extension CodableError
let sanitizedError = nsError.sanitizedForSerialization()
let data = try? NSKeyedArchiver.archivedData(withRootObject: sanitizedError, requiringSecureCoding: true)
return data
case .array(let array): return array
case .dictionary(let dictionary): return dictionary
}
}
init(_ rawValue: Any?)
{
switch rawValue
@@ -69,6 +73,7 @@ extension CodableError
default: self = .unknown(rawValue)
}
}
init(from decoder: Decoder) throws
{
let container = try decoder.singleValueContainer()
@@ -104,11 +109,11 @@ extension CodableError
self = .unknown(nil)
}
}
func encode(to encoder: Encoder) throws
{
var container = encoder.singleValueContainer()
if let value = self.codableValue
{
try container.encode(value)
@@ -127,11 +132,11 @@ struct CodableError: Codable
return self.rawError ?? NSError(domain: self.errorDomain, code: self.errorCode, userInfo: self.userInfo ?? [:])
}
private var rawError: Error?
private var errorDomain: String
private var errorCode: Int
private var userInfo: [String: Any]?
private enum CodingKeys: String, CodingKey
{
case errorDomain
@@ -143,58 +148,63 @@ struct CodableError: Codable
init(error: Error)
{
self.rawError = error
let nsError = error as NSError
self.errorDomain = nsError.domain
self.errorCode = nsError.code
if !nsError.userInfo.isEmpty
{
self.userInfo = nsError.userInfo
}
}
init(from decoder: Decoder) throws
{
let container = try decoder.container(keyedBy: CodingKeys.self)
// Assume ALTServerError.errorDomain if no explicit domain provided.
self.errorDomain = try container.decodeIfPresent(String.self, forKey: .errorDomain) ?? ALTServerError.errorDomain
self.errorCode = try container.decode(Int.self, forKey: .errorCode)
if let rawUserInfo = try container.decodeIfPresent([String: UserInfoValue].self, forKey: .errorUserInfo)
{
// Attempt decoding from .errorUserInfo first, because it will gracefully handle unknown user info values.
// Copy ALTLocalized... values to NSLocalized... if provider is nil or if error is unrecognized.
// This ensures we preserve error messages if receiving an unknown error.
var userInfo = rawUserInfo.compactMapValues { $0.value }
// Recognized == the provider returns value for NSLocalizedFailureReasonErrorKey, or error is ALTServerError.underlyingError.
let provider = NSError.userInfoValueProvider(forDomain: self.errorDomain)
let isRecognizedError = (
provider?(self.error, NSLocalizedFailureReasonErrorKey) != nil ||
(self.error._domain == ALTServerError.errorDomain && self.error._code == ALTServerError.underlyingError.rawValue)
)
if !isRecognizedError
{
// Error not recognized, so copy over NSLocalizedDescriptionKey and NSLocalizedFailureReasonErrorKey.
userInfo[NSLocalizedDescriptionKey] = userInfo[ErrorUserInfoKey.altLocalizedDescription]
userInfo[NSLocalizedFailureReasonErrorKey] = userInfo[ErrorUserInfoKey.altLocalizedFailureReason]
}
// Copy over NSLocalizedRecoverySuggestionErrorKey and NSDebugDescriptionErrorKey if provider returns nil.
if provider?(self.error, NSLocalizedRecoverySuggestionErrorKey) == nil
{
userInfo[NSLocalizedRecoverySuggestionErrorKey] = userInfo[ErrorUserInfoKey.altLocalizedRecoverySuggestion]
}
if provider?(self.error, NSDebugDescriptionErrorKey) == nil
{
userInfo[NSDebugDescriptionErrorKey] = userInfo[ErrorUserInfoKey.altDebugDescription]
}
userInfo[ErrorUserInfoKey.altLocalizedDescription] = nil
userInfo[ErrorUserInfoKey.altLocalizedFailureReason] = nil
userInfo[ErrorUserInfoKey.altLocalizedRecoverySuggestion] = nil
userInfo[ErrorUserInfoKey.altDebugDescription] = nil
self.userInfo = userInfo
}
else if let rawUserInfo = try container.decodeIfPresent([String: UserInfoValue].self, forKey: .legacyUserInfo)
@@ -204,11 +214,13 @@ struct CodableError: Codable
self.userInfo = userInfo
}
}
func encode(to encoder: Encoder) throws
{
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.errorDomain, forKey: .errorDomain)
try container.encode(self.errorCode, forKey: .errorCode)
let rawLegacyUserInfo = self.userInfo?.compactMapValues { (value) -> UserInfoValue? in
// .legacyUserInfo only supports String and NSError values.
switch value
@@ -219,19 +231,19 @@ struct CodableError: Codable
}
}
try container.encodeIfPresent(rawLegacyUserInfo, forKey: .legacyUserInfo)
let nsError = self.error as NSError
var userInfo = self.userInfo ?? [:]
userInfo[ErrorUserInfoKey.altLocalizedDescription] = nsError.localizedDescription
userInfo[ErrorUserInfoKey.altLocalizedFailureReason] = nsError.localizedFailureReason
userInfo[ErrorUserInfoKey.altLocalizedRecoverySuggestion] = nsError.localizedRecoverySuggestion
userInfo[ErrorUserInfoKey.altDebugDescription] = nsError.localizedDebugDescription
// No need to use alternate key. This is a no-op if userInfo already contains localizedFailure,
// but it caches the UserInfoProvider value if one exists.
userInfo[NSLocalizedFailureErrorKey] = nsError.localizedFailure
let rawUserInfo = userInfo.compactMapValues { UserInfoValue($0) }
try container.encodeIfPresent(rawUserInfo, forKey: .errorUserInfo)
}

View File

@@ -201,6 +201,7 @@ public struct ErrorResponse: ServerMessageProtocol
public var identifier = "ErrorResponse"
public var error: ALTServerError {
// Must be ALTServerError
return self.serverError.map { ALTServerError($0.error) } ?? ALTServerError(self.errorCode)
}
private var serverError: CodableError?

View File

@@ -1,18 +0,0 @@
//
// AltXPCProtocol.h
// AltXPC
//
// Created by Riley Testut on 12/2/20.
// Copyright © 2020 Riley Testut. All rights reserved.
//
#import <Foundation/Foundation.h>
@class ALTAnisetteData;
@protocol AltXPCProtocol
- (void)ping:(void (^_Nonnull)(void))completionHandler;
- (void)requestAnisetteDataWithCompletionHandler:(void (^_Nonnull)(ALTAnisetteData *_Nullable anisetteData, NSError *_Nullable error))completionHandler;
@end