Skip to content

Commit d9d6b5d

Browse files
author
hackcatml
committed
change the dump dir for rootless, update fakesigning with ldid
1 parent 77e767a commit d9d6b5d

2 files changed

Lines changed: 53 additions & 7 deletions

File tree

Sources/mldecrypt/Tool.swift

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import ZIPFoundation
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/"
10+
var documentsPath: String = "/var/mobile/Documents/"
1111

1212
// Check if it's arm64e device
1313
func isArm64eDevice() -> Bool {
@@ -47,8 +47,7 @@ func randomStringInLength(_ len: Int) -> String {
4747
return ret
4848
}
4949

50-
func createIpa(bundleId: String) -> Int {
51-
// Clean before
50+
func cleanTempDir() -> Void {
5251
let fileMgr = FileManager.default
5352
if let filesInTemp = try? fileMgr.contentsOfDirectory(atPath: NSTemporaryDirectory()) {
5453
for file in filesInTemp {
@@ -59,6 +58,12 @@ func createIpa(bundleId: String) -> Int {
5958
}
6059
}
6160
}
61+
}
62+
63+
func createIpa(bundleId: String) -> Int {
64+
let fileMgr = FileManager.default
65+
// Clean before
66+
cleanTempDir()
6267

6368
// source path
6469
let src: String! = AppUtils.sharedInstance().searchAppBundleDir(bundleId)
@@ -87,7 +92,11 @@ func createIpa(bundleId: String) -> Int {
8792
if isRootless() {
8893
command = "/var/jb" + command
8994
}
90-
let _ = task(launchPath: command, arguments: "-S", "\(fileToReplace)")
95+
let out = task(launchPath: command, arguments: "-e", "\(fileToReplace)")
96+
let entitlementsPath = "\(workPath)/ent.xml"
97+
let data = out.data(using: .utf8)
98+
fileMgr.createFile(atPath: entitlementsPath, contents: data)
99+
let _ = task(launchPath: command, arguments: "-S\(entitlementsPath)", "\(fileToReplace)")
91100

92101
// Remove files in the Payload dir except for .app dir
93102
let directoryContents = try fileMgr.contentsOfDirectory(at: workPath.appendingPathComponent("Payload"), includingPropertiesForKeys: nil)
@@ -99,6 +108,8 @@ func createIpa(bundleId: String) -> Int {
99108
}
100109
catch {
101110
print("Something went wrong while copying: \(error.localizedDescription)")
111+
// Clean temp dir
112+
cleanTempDir()
102113
return 1
103114
}
104115

@@ -129,10 +140,14 @@ func createIpa(bundleId: String) -> Int {
129140
}
130141
try fileMgr.zipItem(at: filePath, to: zipFilePath, progress: zipProgress)
131142
observation.invalidate()
143+
// Clean after
144+
cleanTempDir()
132145
return 0
133146
}
134147
catch {
135148
print("Something went wrong while zipping: \(error.localizedDescription)")
149+
// Clean after
150+
cleanTempDir()
136151
return 1
137152
}
138153
}
@@ -177,7 +192,7 @@ func backup(arguments: [String], bundleId: String) -> Void {
177192
if file == bundleExecutable + ".decrypted" {
178193
if arguments.count == 3 && arguments[1].contains("-b") || arguments.contains("-b") {
179194
if createIpa(bundleId: bundleId) != 0 {
180-
print("Something went wrong while create ipa. retry")
195+
print("Something went wrong while creating ipa. retry")
181196
exit(1)
182197
}
183198
}
@@ -191,7 +206,7 @@ func backup(arguments: [String], bundleId: String) -> Void {
191206
}
192207
}
193208
// Kill the failed app process
194-
print("Something went wrong. retry\n")
209+
print("Something went wrong while decrypting binary. retry\n")
195210
var command = "/usr/bin/killall"
196211
if isRootless() {
197212
command = "/var/jb" + command
@@ -305,6 +320,24 @@ public struct mldecrypt {
305320
exit(1)
306321
}
307322

323+
if isRootless() {
324+
// create rooltess documents path if it's not exists
325+
documentsPath = "/var/jb" + documentsPath
326+
let fileManager = FileManager.default
327+
if !fileManager.fileExists(atPath: documentsPath) {
328+
do {
329+
try fileManager.createDirectory(atPath: documentsPath, withIntermediateDirectories: true, attributes: nil)
330+
var command = "/usr/bin/chown"
331+
if isRootless() {
332+
command = "/var/jb" + command
333+
}
334+
let _ = task(launchPath: command, arguments: "mobile:", "\(documentsPath)")
335+
} catch {
336+
print("\(error.localizedDescription)")
337+
}
338+
}
339+
}
340+
308341
if arguments[1].contains("list") || arguments[1].contains("-l") {
309342
let searchTerm = "list"
310343
AppUtils.sharedInstance().searchApp(searchTerm)

Sources/mldecryptor/Tweak.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,24 @@ var image_count: UInt32 = 0
77
var image_index: UInt32 = 0
88
var target_imgName: UnsafeMutablePointer<Int8>?
99

10+
// Check if it's rootless
11+
func isRootless() -> Bool {
12+
let rootlessPath = "/var/jb/usr/bin/su"
13+
if access(rootlessPath, F_OK) == 0 {
14+
return true
15+
}
16+
return false
17+
}
18+
1019
// https://github.com/lich4/personal_script/blob/master/Frida_script/ios_dump.js
1120
func dumpstart(_ targetImgName: UnsafeMutablePointer<Int8>?) {
1221
os_log("[hackcatml] binary dump started")
1322

14-
let dumpPath = "/var/mobile/Documents/" + URL(fileURLWithPath: Bundle.main.executablePath ?? "").lastPathComponent + ".decrypted"
23+
var documentsPath = "/var/mobile/Documents/"
24+
if isRootless() {
25+
documentsPath = "/var/jb" + documentsPath
26+
}
27+
let dumpPath: String = documentsPath + URL(fileURLWithPath: Bundle.main.executablePath ?? "").lastPathComponent + ".decrypted"
1528
if FileManager.default.fileExists(atPath: dumpPath) {
1629
unlink(dumpPath)
1730
}

0 commit comments

Comments
 (0)