Skip to content

Commit

Permalink
Custom app name and bundle support
Browse files Browse the repository at this point in the history
  • Loading branch information
powenn committed Jul 28, 2022
1 parent 6a2bd7a commit 06a7e42
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 73 deletions.
2 changes: 1 addition & 1 deletion DEBIAN/control
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Author: Powen <powen0966091716@gmail.com>
Maintainer: Powen <powen0966091716@gmail.com>
Version: @@VERSION@@
Section: Applications
Depends: dpkg, ldid , bash
Depends: dpkg, ldid , bash , plutil | com.bingner.plutil
Pre-Depends: firmware (>= 14.0)
Architecture: iphoneos-arm
depiction: https://github.com/powenn/permasigneriOS
8 changes: 6 additions & 2 deletions permasigneriOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
B57382CE2874755500133E34 /* AuxiliaryExecute in Frameworks */ = {isa = PBXBuildFile; productRef = B57382CD2874755500133E34 /* AuxiliaryExecute */; };
B57382D328751D0E00133E34 /* DirectoryPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57382D228751D0E00133E34 /* DirectoryPath.swift */; };
B57382D52875586D00133E34 /* CheckApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57382D42875586D00133E34 /* CheckApp.swift */; };
B575D397289229A000377919 /* Plist.sh in Resources */ = {isa = PBXBuildFile; fileRef = B575D3962892299F00377919 /* Plist.sh */; };
B5A1F7772875C46F002176A4 /* PackToDeb.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A1F7762875C46F002176A4 /* PackToDeb.swift */; };
B5A1F77E2876A9BC002176A4 /* OpenInFilza.swift in Sources */ = {isa = PBXBuildFile; fileRef = B5A1F77D2876A9BC002176A4 /* OpenInFilza.swift */; };
B5A1F7822877AD53002176A4 /* entitlements.plist in Resources */ = {isa = PBXBuildFile; fileRef = B5A1F7812877AD53002176A4 /* entitlements.plist */; };
Expand All @@ -50,6 +51,7 @@
B57382C8287447EB00133E34 /* AppInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppInfoView.swift; sourceTree = "<group>"; };
B57382D228751D0E00133E34 /* DirectoryPath.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectoryPath.swift; sourceTree = "<group>"; };
B57382D42875586D00133E34 /* CheckApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CheckApp.swift; sourceTree = "<group>"; };
B575D3962892299F00377919 /* Plist.sh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = Plist.sh; sourceTree = "<group>"; };
B5A1F7762875C46F002176A4 /* PackToDeb.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PackToDeb.swift; sourceTree = "<group>"; };
B5A1F77D2876A9BC002176A4 /* OpenInFilza.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OpenInFilza.swift; sourceTree = "<group>"; };
B5A1F7812877AD53002176A4 /* entitlements.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = entitlements.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -116,6 +118,7 @@
B57382A82874191700133E34 /* Resources */ = {
isa = PBXGroup;
children = (
B575D3962892299F00377919 /* Plist.sh */,
B5A1F7812877AD53002176A4 /* entitlements.plist */,
B57382AA2874191700133E34 /* postinst */,
B57382AB2874191700133E34 /* postrm */,
Expand Down Expand Up @@ -210,6 +213,7 @@
B57382A62874178600133E34 /* Launch Screen.storyboard in Resources */,
B573829E2874162700133E34 /* Preview Assets.xcassets in Resources */,
B573829B2874162700133E34 /* Assets.xcassets in Resources */,
B575D397289229A000377919 /* Plist.sh in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -357,7 +361,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 11;
DEVELOPMENT_ASSET_PATHS = "\"permasigneriOS/Preview Content\"";
DEVELOPMENT_TEAM = L4LN9U3ZS7;
ENABLE_PREVIEWS = YES;
Expand Down Expand Up @@ -390,7 +394,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 10;
CURRENT_PROJECT_VERSION = 11;
DEVELOPMENT_ASSET_PATHS = "\"permasigneriOS/Preview Content\"";
DEVELOPMENT_TEAM = L4LN9U3ZS7;
ENABLE_PREVIEWS = YES;
Expand Down
Binary file not shown.
7 changes: 5 additions & 2 deletions permasigneriOS/CheckApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class CheckApp: ObservableObject {
private init() { }

static let shared = CheckApp()

var appNameInPayload:String = ""
var payloadPath:URL = URL(fileURLWithPath: "")

Expand All @@ -27,7 +26,9 @@ class CheckApp: ObservableObject {
var config: [String: Any]?
var InfoPlistPath = URL(string: "")
var app_name:String = ""
@Published var app_bundle:String = ""
@Published var custom_app_name:String = ""
var app_bundle:String = ""
@Published var custom_app_bundle:String = ""
var app_version:String = ""
var app_min_ios:String = ""
var app_author:String = ""
Expand Down Expand Up @@ -64,6 +65,8 @@ class CheckApp: ObservableObject {
app_version = config?["CFBundleShortVersionString"] as! String
app_min_ios = config?["MinimumOSVersion"] as! String? ?? "14.0"
app_author = app_bundle.components(separatedBy: ".")[1]
custom_app_bundle = app_bundle
custom_app_name = app_name
validInfoPlist = true
} else {
validInfoPlist = false
Expand Down
80 changes: 54 additions & 26 deletions permasigneriOS/PackToDeb.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ class Progress: ObservableObject {
static let shared = Progress()

var OutputDebFilePath = ""
// @Published var Percent = 1.0
// @Published var Percent = 1.0
@Published var ProgressingDescribe = ""
@Published var CustomDebDescription = ""

var AppNameDir = ""

func resetDebFolder() {
try? FileManager.default.removeItem(at: tmpDirectory.appendingPathComponent("deb"))
}
Expand Down Expand Up @@ -46,8 +48,8 @@ class Progress: ObservableObject {
try? FileManager.default.copyItem(at: controlFileURL, to: DebDebianDirectory.appendingPathComponent("control"))
do {
var newControlFileText = try String(contentsOf: controlFileURL, encoding: .utf8)
newControlFileText = newControlFileText.replacingOccurrences(of: "{APP_NAME}", with: CheckApp.shared.app_name)
newControlFileText = newControlFileText.replacingOccurrences(of: "{APP_BUNDLE}", with: CheckApp.shared.app_bundle)
newControlFileText = newControlFileText.replacingOccurrences(of: "{APP_NAME}", with: CheckApp.shared.custom_app_name)
newControlFileText = newControlFileText.replacingOccurrences(of: "{APP_BUNDLE}", with: CheckApp.shared.custom_app_bundle)
newControlFileText = newControlFileText.replacingOccurrences(of: "{APP_VERSION}", with: CheckApp.shared.app_version)
newControlFileText = newControlFileText.replacingOccurrences(of: "{APP_MIN_IOS}", with: CheckApp.shared.app_min_ios)
newControlFileText = newControlFileText.replacingOccurrences(of: "{APP_AUTHOR}", with: CheckApp.shared.app_author)
Expand All @@ -65,7 +67,7 @@ class Progress: ObservableObject {
try? FileManager.default.copyItem(at: postinstFileURL, to: DebDebianDirectory.appendingPathComponent("postinst"))
do {
var newPostinstFileText = try String(contentsOf: postinstFileURL, encoding: .utf8)
newPostinstFileText = newPostinstFileText.replacingOccurrences(of: "{APP_NAME}", with: CheckApp.shared.app_name)
newPostinstFileText = newPostinstFileText.replacingOccurrences(of: "{APP_NAME}", with: CheckApp.shared.custom_app_name)
try newPostinstFileText.write(to: DebDebianDirectory.appendingPathComponent("postinst"), atomically: true, encoding: .utf8)
}
catch {
Expand All @@ -77,7 +79,7 @@ class Progress: ObservableObject {
try? FileManager.default.copyItem(at: postrmFileURL, to: DebDebianDirectory.appendingPathComponent("postrm"))
do {
var newPostrmFileText = try String(contentsOf: postrmFileURL, encoding: .utf8)
newPostrmFileText = newPostrmFileText.replacingOccurrences(of: "{APP_NAME}", with: CheckApp.shared.app_name)
newPostrmFileText = newPostrmFileText.replacingOccurrences(of: "{APP_NAME}", with: CheckApp.shared.custom_app_name)
try newPostrmFileText.write(to: DebDebianDirectory.appendingPathComponent("postrm"), atomically: true, encoding: .utf8)
}
catch {
Expand All @@ -90,45 +92,71 @@ class Progress: ObservableObject {
try? FileManager.default.copyItem(at: entitlementsFileURL, to: tmpDirectory.appendingPathComponent("entitlements.plist"))

let plistDict = NSMutableDictionary(contentsOfFile: tmpDirectory.appendingPathComponent("entitlements.plist").path)
plistDict!.setObject(CheckApp.shared.app_bundle, forKey: "application-identifier" as NSCopying)
plistDict!.setObject(CheckApp.shared.custom_app_bundle, forKey: "application-identifier" as NSCopying)
plistDict!.write(toFile: tmpDirectory.appendingPathComponent("entitlements.plist").path, atomically: false)

plistDict!.setObject(["group.\(CheckApp.shared.app_bundle)"], forKey: "com.apple.security.application-groups" as NSCopying)
plistDict!.setObject(["group.\(CheckApp.shared.custom_app_bundle)"], forKey: "com.apple.security.application-groups" as NSCopying)
plistDict!.write(toFile: tmpDirectory.appendingPathComponent("entitlements.plist").path, atomically: false)

plistDict!.setObject([CheckApp.shared.app_bundle], forKey: "keychain-access-groups" as NSCopying)
plistDict!.setObject([CheckApp.shared.custom_app_bundle], forKey: "keychain-access-groups" as NSCopying)
plistDict!.write(toFile: tmpDirectory.appendingPathComponent("entitlements.plist").path, atomically: false)
}
// Info.plist
// get Info in plist file
if CheckApp.shared.app_bundle != CheckApp.shared.custom_app_bundle {
AppNameDir = CheckApp.shared.appNameInPayload.replacingOccurrences(of: CheckApp.shared.app_name, with: CheckApp.shared.custom_app_name)
let InfoPlistPathInTmpPayload = CheckApp.shared.payloadPath.appendingPathComponent("\(CheckApp.shared.appNameInPayload)/Info.plist")
if let PlistScriptFileURL = Bundle.main.url(forResource: "Plist", withExtension: "sh") {
try? FileManager.default.copyItem(at: PlistScriptFileURL, to: tmpDirectory.appendingPathComponent("Plist.sh"))
do {
var newPlistScriptText = try String(contentsOf: PlistScriptFileURL, encoding: .utf8)
newPlistScriptText = newPlistScriptText.replacingOccurrences(of: "{MY_PLIST_PATH}", with: InfoPlistPathInTmpPayload.path)
newPlistScriptText = newPlistScriptText.replacingOccurrences(of: "{OLD_VALUE}", with: CheckApp.shared.app_bundle)
newPlistScriptText = newPlistScriptText.replacingOccurrences(of: "{NEW_VALUE}", with: CheckApp.shared.custom_app_bundle)
try newPlistScriptText.write(to: tmpDirectory.appendingPathComponent("Plist.sh"), atomically: true, encoding: .utf8)
}
catch {
print(error.localizedDescription)
}
}
let plistDict = NSMutableDictionary(contentsOfFile: InfoPlistPathInTmpPayload.path)
plistDict!.setObject(CheckApp.shared.custom_app_name, forKey: "CFBundleDisplayName" as NSCopying)
plistDict!.write(toFile: CheckApp.shared.payloadPath.appendingPathComponent("\(CheckApp.shared.appNameInPayload)/Info.plist").path, atomically: false)

AuxiliaryExecute.local.bash(command: "bash /var/mobile/Documents/permasigneriOS/tmp/Plist.sh")
} else {
AppNameDir = CheckApp.shared.appNameInPayload
}
}

func copyAppContent() {
try? FileManager.default.copyItem(at: CheckApp.shared.payloadPath.appendingPathComponent(CheckApp.shared.appNameInPayload), to: DebApplicationsDirectory.appendingPathComponent(CheckApp.shared.appNameInPayload))
try? FileManager.default.copyItem(at: CheckApp.shared.payloadPath.appendingPathComponent(CheckApp.shared.appNameInPayload), to: DebApplicationsDirectory.appendingPathComponent(AppNameDir))
}

func ChangeDebPermisson() {
// Scripts parts
AuxiliaryExecute.local.bash(command: "chmod 0755 /var/mobile/Documents/permasigneriOS/tmp/deb/DEBIAN/postrm")
AuxiliaryExecute.local.bash(command: "chmod 0755 /var/mobile/Documents/permasigneriOS/tmp/deb/DEBIAN/postinst")
// app_executable
AuxiliaryExecute.local.bash(command: "chmod 0755 /var/mobile/Documents/permasigneriOS/tmp/deb/Applications/\(CheckApp.shared.appNameInPayload)/\(CheckApp.shared.app_executable!)")
AuxiliaryExecute.local.bash(command: "chmod 0755 /var/mobile/Documents/permasigneriOS/tmp/deb/Applications/\(AppNameDir)/\(CheckApp.shared.app_executable!)")

// -------------------------- //
AuxiliaryExecute.local.bash(command: "chmod -R 04755 /var/mobile/Documents/permasigneriOS/tmp/deb/Applications/\(CheckApp.shared.appNameInPayload)")
AuxiliaryExecute.local.bash(command: "chmod -R 04755 /var/mobile/Documents/permasigneriOS/tmp/deb/Applications/\(AppNameDir)")
// -------------------------- //
}

func SignAppWithLdid() {
AuxiliaryExecute.local.bash(command: "ldid -S/var/mobile/Documents/permasigneriOS/tmp/entitlements.plist -M -K/Applications/permasigneriOS.app/dev_certificate.p12 /var/mobile/Documents/permasigneriOS/tmp/deb/Applications/\(CheckApp.shared.appNameInPayload)/\(CheckApp.shared.app_executable!)")
AuxiliaryExecute.local.bash(command: "chmod 0755 /var/mobile/Documents/permasigneriOS/tmp/deb/Applications/\(CheckApp.shared.appNameInPayload)/\(CheckApp.shared.app_executable!)")
AuxiliaryExecute.local.bash(command: "ldid -S/var/mobile/Documents/permasigneriOS/tmp/entitlements.plist -M -K/Applications/permasigneriOS.app/dev_certificate.p12 /var/mobile/Documents/permasigneriOS/tmp/deb/Applications/\(AppNameDir)/\(CheckApp.shared.app_executable!)")
AuxiliaryExecute.local.bash(command: "chmod 0755 /var/mobile/Documents/permasigneriOS/tmp/deb/Applications/\(AppNameDir)/\(CheckApp.shared.app_executable!)")

// ldid sign example.app
AuxiliaryExecute.local.bash(command: "ldid -S/var/mobile/Documents/permasigneriOS/tmp/entitlements.plist -M -K/Applications/permasigneriOS.app/dev_certificate.p12 /var/mobile/Documents/permasigneriOS/tmp/deb/Applications/\(CheckApp.shared.appNameInPayload)")
AuxiliaryExecute.local.bash(command: "ldid -S/var/mobile/Documents/permasigneriOS/tmp/entitlements.plist -M -K/Applications/permasigneriOS.app/dev_certificate.p12 /var/mobile/Documents/permasigneriOS/tmp/deb/Applications/\(AppNameDir)")

}

func CheckFrameWorkDirExist() {
// If exist .framework or .dylib then sign them
let FrameWorkFolderPath = DebApplicationsDirectory.appendingPathComponent("\(CheckApp.shared.appNameInPayload)/Frameworks").path
let FrameWorkFolderPath = DebApplicationsDirectory.appendingPathComponent("\(AppNameDir)/Frameworks").path
var frameworkBinaryName:String = ""
if FileManager.default.fileExists(atPath: FrameWorkFolderPath) {

Expand All @@ -145,8 +173,8 @@ class Progress: ObservableObject {

}
if content.hasSuffix(".dylib"){
AuxiliaryExecute.local.bash(command: "ldid -K/Applications/permasigneriOS.app/dev_certificate.p12 /var/mobile/Documents/permasigneriOS/tmp/deb/Applications/\(CheckApp.shared.appNameInPayload)/Frameworks/\(content)")
AuxiliaryExecute.local.bash(command: "chmod 0755 /var/mobile/Documents/permasigneriOS/tmp/deb/Applications/\(CheckApp.shared.appNameInPayload)/Frameworks/\(content)")
AuxiliaryExecute.local.bash(command: "ldid -K/Applications/permasigneriOS.app/dev_certificate.p12 /var/mobile/Documents/permasigneriOS/tmp/deb/Applications/\(AppNameDir)/Frameworks/\(content)")
AuxiliaryExecute.local.bash(command: "chmod 0755 /var/mobile/Documents/permasigneriOS/tmp/deb/Applications/\(AppNameDir)/Frameworks/\(content)")
}
}
}
Expand All @@ -166,39 +194,39 @@ class Progress: ObservableObject {
}

func permanentSignButtonFunc() {
// Percent = 0.0
// Percent = 0.0
ProgressingDescribe = "[1/8] Clearing folder"
resetDebFolder()

// Percent += 0.125
// Percent += 0.125
ProgressingDescribe = "[2/8] Preparing folder"
prepareDebFolder()

// Percent += 0.125
// Percent += 0.125
ProgressingDescribe = "[3/8] Copying Resources"
copyResourcesAndReplace()

// Percent += 0.125
// Percent += 0.125
ProgressingDescribe = "[4/8] Copying app contents"
copyAppContent()

// Percent += 0.125
// Percent += 0.125
ProgressingDescribe = "[5/8] Setting permissions"
ChangeDebPermisson()

// Percent += 0.125
// Percent += 0.125
ProgressingDescribe = "[6/8] Signing with ldid"
SignAppWithLdid()

// Percent += 0.125
// Percent += 0.125
ProgressingDescribe = "[7/8] Checking frameworks"
CheckFrameWorkDirExist()

// Percent += 0.125
// Percent += 0.125
ProgressingDescribe = "[8/8] Packing to deb"
PackToDeb()

ProgressingDescribe = ""
// Percent = 1.0
// Percent = 1.0
}
}
65 changes: 65 additions & 0 deletions permasigneriOS/Resources/Plist.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/bin/bash
######################################## BASH LIB #######################################
bash.string.replace() {
local text="$1" find="$2" replace="$3";

echo "${text}" | while IFS= read -r line; do
printf '%s\n' "${line//"$find"/$replace}";
done
}
######################################## BASH LIB #######################################

######################################## APPLE LIB ######################################
apple.plist.read() {
local filepath="${1}"

defaults read "${filepath}"
}
apple.plist.convert.to.xml() {
local filepath="${1}" tmp="${2}"

# If second argument is passed, then we save the conversion to a new file rather than write over the original
if [[ "${tmp}" == "true" ]]; then
tmp="/tmp${filepath}"
fi

if [[ "${tmp}" != "" ]]; then
bash.cp "${filepath}" "${tmp}"

filepath="${tmp}"
fi

plutil -convert xml1 "${filepath}"

# We also output the content which can be supressed if desired by caller
cat "${filepath}"
}
apple.plist.convert.to.binary() {
local filepath="${1}"

plutil -convert binary1 "${filepath}"
}
apple.plist.write() {
local filepath="$1" text="$2"

echo "${text}" > "${filepath}"

apple.plist.convert.to.binary "${filepath}" # Not sure if this step is neccessary, if xml representation is enough. Not verified or tested without.
}
apple.plist.read.search.replace.write() {
local file="${1}" search="${2}" replacement="${3}"

local updated=$(bash.string.replace "$(apple.plist.read "${file}")" "${search}" "${replacement}")

apple.plist.write "${file}" "${updated}"
}
######################################## APPLE LIB ######################################


######################################## EXAMPLE ##################################
#my.test.1() {
# apple.plist.read.search.replace.write "/tmp/com.apple.finder.plist" "/Users/" "/Home/"
#}
######################################## EXAMPLE ##################################

apple.plist.read.search.replace.write {MY_PLIST_PATH} {OLD_VALUE} {NEW_VALUE}
Binary file not shown.
4 changes: 2 additions & 2 deletions permasigneriOS/Resources/postinst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/sh
uicache -p /Applications/{APP_NAME}.app
#!/bin/bash
uicache -p /Applications/{APP_NAME}.app
Loading

0 comments on commit 06a7e42

Please sign in to comment.