GBA001/Delta/Extensions/Bundle+SwizzleBundleID.swift
Riley Testut e91b6bcd6b Uses constant bundleID for Fabric regardless of actual bundleID
AltStore resigns apps with unique bundle identifiers per-user, so we temporarily swizzle Bundle.infoDictionary to return a constant bundle identifier for Fabric so they can all be grouped together.
2019-08-07 16:51:00 -07:00

39 lines
1.1 KiB
Swift

//
// Bundle+SwizzleBundleID.swift
// Delta
//
// Created by Riley Testut on 8/7/19.
// Copyright © 2019 Riley Testut. All rights reserved.
//
import Foundation
import ObjectiveC.runtime
extension Bundle
{
@objc private var swizzled_infoDictionary: [String : Any]? {
var infoDictionary = self.swizzled_infoDictionary
infoDictionary?[kCFBundleIdentifierKey as String] = "com.rileytestut.Delta.AltStore"
return infoDictionary
}
public static func swizzleBundleID(handler: () -> Void)
{
let bundleClass: AnyClass = Bundle.self
guard
let originalMethod = class_getInstanceMethod(bundleClass, #selector(getter: Bundle.infoDictionary)),
let swizzledMethod = class_getInstanceMethod(bundleClass, #selector(getter: Bundle.swizzled_infoDictionary))
else {
print("Failed to swizzle Bundle.infoDictionary.")
return
}
method_exchangeImplementations(originalMethod, swizzledMethod)
handler()
method_exchangeImplementations(swizzledMethod, originalMethod)
}
}