@@ -7,7 +7,7 @@ import ZIPFoundation
77let MACH_PORT_NULL : mach_port_name_t = 0
88let 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
1313func 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)
0 commit comments