Call method from another app (Jailbreak iOS)
Asked Answered
H

1

8

On a jailbroken iOS device, is it possible for one app to call a method from another app (an instance method, not a static one)? Another way of phrasing this: how can I get the instance of an app (assuming the app is running) so that I can call one of its methods?

Background: I am trying to call a function in the Music player app from a hooked method in the iPodUI Private Framework (see this post for more details).

This question has been asked for Android, but I didn't find anything for jailbreak iOS. If that's because I'm asking the wrong question and there's a different approach to take, I'm open to that.

Hexahydrate answered 6/10, 2013 at 20:47 Comment(5)
Shoot, after typing all this I found this question which seems to hold a possible answer: #18224650Hexahydrate
Unless I'm misunderstanding your question, I don't think the other answer (about CPDistributedMessagingCenter) will help you. That would be useful if you know the other app (e.g. Music player) is already coded to listen for a particular notification / message. If you just want to call an arbitrary method in another app, that isn't designed to be called by other processes, then I think you need MobileSubstrate hooking.Dulcia
Thanks Nate. But shouldn't I be able to hook into the Music player app and add my own listener? Or am I making this more complicated than it should be?Hexahydrate
If you mean combining the technique that uses CPDistributedMessagingCenter and hooking, so that the music player has a new server/listener ... sure, you could do that. I guess the question is whether you need to pass parameters to this method. If you don't, then CPDistributedMessagingCenter is not necessary, and you can use any of several notification mechanisms.Dulcia
I don't need to pass parameters to the method (well actually the final method in the Music player will need parameters, but only the Music player will know what these are--most likely I'll use a wrapper function), so I'd be interested in learning about the possibilities.Hexahydrate
S
2

An easy and alternative way to achieve this is with cycript and system() call, however please BEWARE of the dangers of using system() before using it as it is potentially insecure (which is, to my opinion, not that much important on a jailbroken iOS where everything is pretty much unsafe)

let's say you have a method like [[SomeClass sharedInstance] methodToBeCalledExternally] that you want to call from some other process

you can save that call to a text file in /tmp/something.cy

then you inject that code externally by running:

cycript -p Music /tmp/something.cy

but if you need to do it programatically, and of course if the environment isn't sandboxed (I assume it isn't), then you can do:

system("cycript -p Music /tmp/something.cy")

this way you can execute arbitrary ObjC code in any process (in this case, the Music app), from your code.

finally, don't forget to remove the file /tmp/something.cy as you will no longer need it

Spinose answered 1/5, 2014 at 21:16 Comment(1)
Thanks, sounds like a good solution, will have to try this out sometime.Hexahydrate

© 2022 - 2024 — McMap. All rights reserved.