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.

Community
  • 1
  • 1
newenglander
  • 2,019
  • 24
  • 55
  • 1
    Shoot, after typing all this I found this question which seems to hold a possible answer: http://stackoverflow.com/questions/18224150/communication-between-tweak-and-app – newenglander Oct 06 '13 at 20:47
  • 1
    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. – Nate Oct 07 '13 at 05:30
  • 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? – newenglander Oct 07 '13 at 08:03
  • 1
    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. – Nate Oct 07 '13 at 08:35
  • 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. – newenglander Oct 07 '13 at 09:01

1 Answers1

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

Eric Castro
  • 135
  • 1
  • 6