Skip to content

Commit 182b898

Browse files
author
hackcatml
committed
use ZIPFoundation for create IPA
1 parent 6c94ba3 commit 182b898

18 files changed

Lines changed: 41 additions & 5236 deletions

File tree

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ XCDD_TOP = $(HOME)/Library/Developer/Xcode/DerivedData/
1616
XCDD_MID = $(shell basename $(XCDD_TOP)/$(PWD)*)
1717
XCDD_BOT = /SourcePackages/checkouts
1818

19-
MOD_NAME = Zip
20-
MOD_LOC = $(XCDD_TOP)$(XCDD_MID)$(XCDD_BOT)/$(MOD_NAME)/Zip
19+
MOD_NAME = ZIPFoundation
20+
MOD_LOC = $(XCDD_TOP)$(XCDD_MID)$(XCDD_BOT)/$(MOD_NAME)/Sources
2121

2222
# Set rootless package scheme
2323
THEOS_PACKAGE_SCHEME =
@@ -27,7 +27,7 @@ endif
2727

2828
# Define included files, imported frameworks, etc.
2929
TOOL_NAME = mldecrypt
30-
$(TOOL_NAME)_FILES = $(shell find Sources/$(TOOL_NAME) -name '*.swift') $(wildcard $(shell find $(MOD_LOC) -name '*.swift')) $(shell find $(THEOS)/include/Minizip -name '*.c') $(shell find $(THEOS)/include/cdaswift -name '*.mm')
30+
$(TOOL_NAME)_FILES = $(shell find Sources/$(TOOL_NAME) -name '*.swift') $(wildcard $(shell find $(MOD_LOC) -name '*.swift')) $(shell find $(THEOS)/include/cdaswift -name '*.mm')
3131
$(TOOL_NAME)_FILES += $(wildcard Sources/include/opainject/*.m)
3232
$(TOOL_NAME)_CFLAGS = -w
3333
$(TOOL_NAME)_SWIFTFLAGS = -ISources/include

Package.resolved

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ let package: Package = .init(
6262
),
6363
],
6464
dependencies: [
65-
.package(url: "https://github.com/marmelroy/Zip.git", branch: "master"),
65+
.package(url: "https://github.com/weichsel/ZIPFoundation.git", .upToNextMajor(from: "0.9.0"))
6666
],
6767
targets: [
6868
.target(
6969
name: "mldecrypt",
7070
dependencies: [
71-
.product(name: "Zip", package: "Zip"),
71+
.product(name:"ZIPFoundation", package: "ZIPFoundation")
7272
],
7373
swiftSettings: [.unsafeFlags(swiftFlags)]
7474
),

Sources/mldecrypt/Tool.swift

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import Foundation
22
import os
3-
import Zip
43
import cdaswift
54
import opainject
5+
import ZIPFoundation
66

77
let MACH_PORT_NULL: mach_port_name_t = 0
88
let MACH_PORT_DEAD: mach_port_name_t = ~mach_port_name_t(0)
99

10+
let documentsPath: String = "/var/mobile/Documents/"
11+
1012
// Check if it's arm64e device
1113
func isArm64eDevice() -> Bool {
1214
var systemInfo = utsname()
@@ -76,7 +78,7 @@ func createIpa(bundleId: String) -> Int {
7678
// Replace a original binary file with a dumped one
7779
let appResourceDir = (AppUtils.sharedInstance().searchAppResourceDir(bundleId)! as NSString).lastPathComponent
7880
let fileToReplace = workPath.appendingPathComponent("Payload").path + "/\(appResourceDir)/\(bundleExecutable)"
79-
let replacementFile = "/var/mobile/Documents/\(bundleExecutable).decrypted"
81+
let replacementFile = "\(documentsPath)\(bundleExecutable).decrypted"
8082
try fileMgr.removeItem(atPath: fileToReplace)
8183
try fileMgr.copyItem(atPath: replacementFile, toPath: fileToReplace)
8284

@@ -102,19 +104,31 @@ func createIpa(bundleId: String) -> Int {
102104

103105
// Zip
104106
do {
107+
// Clean ipa first if it's already there
108+
if let filesInDocumentsDir = try? fileMgr.contentsOfDirectory(atPath: "\(documentsPath)") {
109+
for file in filesInDocumentsDir {
110+
let filefullpath = "\(documentsPath)".appending((file as NSString).lastPathComponent)
111+
if file == "\(bundleExecutable).ipa" {
112+
try? fileMgr.removeItem(atPath: filefullpath)
113+
}
114+
}
115+
}
116+
105117
let buffer: StringBuffer = StringBuffer()
106118
var progressBar: ProgressBar = ProgressBar(output: buffer)
107119

108120
let filePath = URL(fileURLWithPath: workPath.appendingPathComponent("Payload").path, isDirectory: true)
109-
let zipFilePath = URL(fileURLWithPath: "/var/mobile/Documents/\(bundleExecutable).ipa", isDirectory: false)
110-
try Zip.zipFiles(paths: [filePath], zipFilePath: zipFilePath, password: nil, progress: { (progress) in
111-
progressBar.render(count: Int(progress * 100), total:100)
112-
progress == 1 ?
121+
let zipFilePath = URL(fileURLWithPath: "\(documentsPath)\(bundleExecutable).ipa", isDirectory: false)
122+
123+
let zipProgress = Progress()
124+
let observation = zipProgress.observe(\.fractionCompleted) { progress, _ in
125+
progressBar.render(count: Int(progress.fractionCompleted * 100), total:100)
126+
progress.fractionCompleted == 1 ?
113127
{ print("Zipping...\(buffer.string)"); fflush(stdout) }() :
114128
{ print("Zipping...\(buffer.string)", terminator: "\r"); fflush(stdout) }()
115-
})
116-
// Remove the real work path
117-
try fileMgr.removeItem(atPath: workPath.path)
129+
}
130+
try fileMgr.zipItem(at: filePath, to: zipFilePath, progress: zipProgress)
131+
observation.invalidate()
118132
return 0
119133
}
120134
catch {
@@ -156,7 +170,7 @@ func setDecryptTarget(set: Bool, bundleId: String) -> Void {
156170
}
157171

158172
func backup(arguments: [String], bundleId: String) -> Void {
159-
let documentsURL = URL(string: "/var/mobile/Documents")!
173+
let documentsURL = URL(string: documentsPath)!
160174
let filelist = try! FileManager.default.contentsOfDirectory(atPath: documentsURL.path)
161175
let bundleExecutable = AppUtils.sharedInstance().searchAppExecutable(bundleId)!
162176
for file in filelist {

control

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: com.hackcatml.mldecrypt
22
Name: mldecrypt
3-
Version: 0.0.9
3+
Version: 0.1.0
44
Architecture: iphoneos-arm
55
Description: An awesome tool of some sort!!
66
Maintainer: hackcatml

module/Minizip/include/Minizip.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

module/Minizip/include/crypt.h

Lines changed: 0 additions & 131 deletions
This file was deleted.

0 commit comments

Comments
 (0)