@@ -185,6 +185,21 @@ func setDecryptTarget(set: Bool, bundleId: String) -> Void {
185185}
186186
187187func backup( arguments: [ String ] , bundleId: String ) -> Void {
188+ if isRootless ( ) {
189+ let decryptedFile = AppUtils . sharedInstance ( ) . searchAppExecutable ( bundleId) + " .decrypted "
190+ let appDocumentsPath = AppUtils . sharedInstance ( ) . searchAppDataDir ( bundleId) + " /Documents/ "
191+ let decryptedFilePath = appDocumentsPath + decryptedFile
192+ let srcURL = URL ( fileURLWithPath: decryptedFilePath)
193+ let dstURL = URL ( fileURLWithPath: documentsPath + decryptedFile)
194+ do {
195+ try FileManager . default. copyItem ( at: srcURL, to: dstURL)
196+ try FileManager . default. removeItem ( at: srcURL)
197+ }
198+ catch {
199+ print ( " Error: \( error. localizedDescription) " )
200+ }
201+ }
202+
188203 let documentsURL = URL ( string: documentsPath) !
189204 let filelist = try ! FileManager . default. contentsOfDirectory ( atPath: documentsURL. path)
190205 let bundleExecutable = AppUtils . sharedInstance ( ) . searchAppExecutable ( bundleId) !
@@ -221,36 +236,46 @@ func opainject(arguments: [String]) -> Void {
221236 exit ( 1 )
222237 }
223238
224- let bundleId = arguments [ index]
225-
226- let processList = Getpid ( )
227- guard let processes = processList. processes else {
228- print ( " Failed to retrieve process list. " )
229- exit ( 1 )
230- }
231239 var targetPid : Int32 = 0
232- for process in processes {
233- let pid = process. kp_proc. p_pid
234- let name = withUnsafePointer ( to: process. kp_proc. p_comm) {
235- String ( cString: UnsafeRawPointer ( $0) . assumingMemoryBound ( to: CChar . self) )
240+ let bundleId = arguments [ index]
241+ if isArm64eDevice ( ) , CommandLine . argc >= 5 {
242+ let index = arguments. firstIndex ( where: {
243+ $0. allSatisfy ( { $0. isNumber } )
244+ } )
245+ targetPid = Int32 ( arguments [ index!] ) !
246+ } else {
247+ let processList = Getpid ( )
248+ guard let processes = processList. processes else {
249+ print ( " Failed to retrieve process list. " )
250+ exit ( 1 )
236251 }
237- if name. contains ( AppUtils . sharedInstance ( ) . searchAppExecutable ( bundleId) !) {
238- targetPid = Int32 ( pid)
239- break
252+ for process in processes {
253+ let pid = process. kp_proc. p_pid
254+ let name = withUnsafePointer ( to: process. kp_proc. p_comm) {
255+ String ( cString: UnsafeRawPointer ( $0) . assumingMemoryBound ( to: CChar . self) )
256+ }
257+ if name. contains ( AppUtils . sharedInstance ( ) . searchAppExecutable ( bundleId) !) {
258+ targetPid = Int32 ( pid)
259+ break
260+ }
261+ }
262+ guard targetPid != 0 else {
263+ print ( " Cannot find pid for \( bundleId) " )
264+ exit ( 1 )
240265 }
241- }
242- guard targetPid != 0 else {
243- print ( " Cannot find pid for \( bundleId) " )
244- exit ( 1 )
245266 }
246267
247268 if isArm64eDevice ( ) {
248269 var pacArg : UnsafeMutablePointer < Int8 > ? = nil
249- if CommandLine . argc >= 4 {
250- pacArg = CommandLine . unsafeArgv [ 3 ]
270+ if CommandLine . argc >= 5 {
271+ pacArg = CommandLine . unsafeArgv [ Int ( CommandLine . argc ) - 1 ]
251272 }
252273 if pacArg == nil || String ( cString: pacArg!) != " pac " {
253- spawnPacChild ( CommandLine . argc, CommandLine . unsafeArgv)
274+ let pidString = String ( targetPid)
275+ let pidPtr = strdup ( pidString)
276+
277+ CommandLine . unsafeArgv [ Int ( CommandLine . argc) ] = pidPtr
278+ spawnPacChild ( CommandLine . argc + 1 , CommandLine . unsafeArgv)
254279 exit ( 0 )
255280 }
256281 }
@@ -295,6 +320,9 @@ func opainject(arguments: [String]) -> Void {
295320 if arguments. contains ( " -b " ) {
296321 sleep ( 4 )
297322 backup ( arguments: arguments, bundleId: bundleId)
323+ } else {
324+ sleep ( 1 )
325+ backup ( arguments: arguments, bundleId: bundleId)
298326 }
299327
300328 exit ( 0 )
@@ -346,6 +374,17 @@ public struct mldecrypt {
346374 print ( helpString)
347375 exit ( 0 )
348376 } else if arguments. contains ( " -r " ) {
377+ var index = arguments. firstIndex ( of: " -r " )
378+ if index != 1 {
379+ print ( " \n Usage: mldecrypt -r <bundleId> || mldecrypt -r -b <bundleId> " )
380+ exit ( 1 )
381+ } else if arguments. contains ( " -b " ) {
382+ index = arguments. firstIndex ( of: " -b " )
383+ if index != 2 {
384+ print ( " \n Usage: mldecrypt -r <bundleId> || mldecrypt -r -b <bundleId> " )
385+ exit ( 1 )
386+ }
387+ }
349388 opainject ( arguments: arguments)
350389 } else if arguments. count == 2 || ( arguments. count == 3 && arguments [ 1 ] . contains ( " -b " ) ) {
351390 let bundleId = arguments. count == 2 ? arguments [ 1 ] : arguments [ 2 ]
0 commit comments