2

I have a jailbreak application that needs to run as root, so at the beginning of the main function, I call setuid(0); The problem arises when I want to terminate the application through the task switcher. I remove it from the multitask bar, but it continues to run in he background. Does anybody know how to fix this? I know "iFile" had this problem for a while.

lufinkey
  • 342
  • 4
  • 15

2 Answers2

1

The problem you have is actually pretty simple.
SpringBoard and therefore the Multitasking Bar runs as the user mobile while your app runs as root. The mobile user can't kill a process that runs as root.
My first idea to resolve this is to hook (MobileSubstrate) into the multitasking bar and since MS tweaks can run as root, detect when the user kills your app and kill it yourself as the root user because SpringBoard simply can't do it.
Or if this doesn't solve it, ask the guy who made iFile, he is really helpful, I'm sure he will give you some guidance with this problem.

Rickye
  • 1,023
  • 1
  • 9
  • 16
  • yeah I sent him an email, but I got his autoresponse telling me that he gets a lot of emails and may not get back to me for a month. Is there any sort of event that gets called when the application is "asked" to terminate? I know applicationWillTerminate exists, but that only works when the application is actually exiting. I'm wondering if there's any sort of event where the application receives a signal telling it to exit? – lufinkey May 23 '14 at 13:15
  • 1
    Tweak can't "run", it's a dynamic library. Tweak will have all the privileges, sandbox restrictions and everything from the process it's being loaded into. So if a process runs as mobile then your tweak will also run as mobile because they exist as one process. Obvious solution would be to hook into SpringBoard and send notification when application killed in multitasking bar. When received in application just call `exit(0)`. But I think `applicationWillTerminate` should be called regardles of process privileges. That's just an event, SpringBoard should be able send it even to `root` process. – creker May 23 '14 at 14:11
  • it's not not getting called because of process privileges, it's not being called because the application isn't terminating – lufinkey May 23 '14 at 17:50
0

I would recommend investigating exactly how you've achieved root privilege escalation, and is it built as a normal UIApplication, and installed in /Applications/?

I don't think this should be preventing you from killing the app. Take a look at the Cydia app itself, which also runs as root.

I can kill Cydia with no problems via the task switcher (verified afterwards with the ps command).

If you log into a jailbroken phone, take a look at:

/Applications/Cydia.app/Cydia
/Applications/Cydia.app/MobileCydia

I believe the technique is well described here. Otherwise, you may need to post more information about how you've coded your app.

Community
  • 1
  • 1
Nate
  • 31,017
  • 13
  • 83
  • 207
  • It is running from /Applications/ with the permissions set to 7555. I've used the same technique that cydia uses. I have a script that runs my actual executable and sets it as root, and then in the "main" of the app, I use setuid(0) – lufinkey May 24 '14 at 19:28
  • I'll try to run one of my own apps tonight, and see if I can reproduce the problem. Can you reproduce what I described with Cydia? In other words, on your phone, do you see that killing Cydia from the task switcher does work? – Nate May 25 '14 at 01:57
  • @Finke, yeah, I just tested this on a jailbreak app of mine that runs as root. On iOS 7.0.4, using the task switcher to kill it works just fine, as it does with Cydia. Not sure what about your app is different, but this should work. Is this a `voip` app, or using some other feature that might prompt iOS to **restart** the app when killed? – Nate May 29 '14 at 10:48
  • I'm running iOS 6. It's a fairly normal app, though – lufinkey May 30 '14 at 19:05