0

So granted, I am very new to tweak development, but I'm running into an issue. I'm working on a tweak for personal use that hooks into multiple processes, but I'm having difficulty sharing a variable between those process-specific hooks. For instance, my SpringBoard method hooks are able to set the value of a static variable and then access the value set. But the app-specific method hooks are unable to retrieve the value set within the context of a SpringBoard method. The variable is coming back uninitialized.

Since the tweak library is common, how can I initialize a "global" library-level variable within the context of one process' hook and access that value within the context of another process.

My first attempts look something like this:

static BOOL isEnabled;

%hook FirstProcessFirstClass

- (void) methodInFirstProcessFirstClass {
    isEnabled = YES;
    %orig;
}

%end

%hook FirstProcessSecondClass

- (void) methodInFirstProcessSecondClass {
    // This will be 1 if it occurs after methodInFirstProcessFirstClass
    NSLog("isEnabled equals %d", isEnabled);
    %orig;
}

%end

%hook SecondProcessClass

- (void) methodInSecondProcessClass {
    // This is always going to be uninitialized (i.e., 0)
    NSLog("isEnabled equals %d", isEnabled);
    %orig;
}

%end

You get the picture, I'd like to share a "global variable" between hooked processes. Thanks for humoring me. :/

Osbourne Ruddock
  • 465
  • 4
  • 20

1 Answers1

2

Sharing a variable across processes is a bit more complex than just having a global variable. You'll need to use some form of IPC (Inter Process Communication) to synchronize the variable across processes. Since you hook SpringBoard and other apps, you can set up SpringBoard as the "server" so that it sends the new state of the variable on other processes.

You can also make use of the %group directive to make the hooks be applied depending on which process your tweak is actually hooked, so that the hooks for SpringBoard are only active in the SpringBoard process and not on the apps. This will not change much, but there will not be unnecessary hooks in place.

uroboro
  • 291
  • 2
  • 6
  • Thanks for this. I think I am showing how little I actually understand the work that Logos does in hooking methods. My assumption was that I could share variables common to the library with any hooked method, but I see that life is not so easy. "IPC" was the search term I needed to employ on GitHub. If I can produce a working implementation, I'll post my findings as an answer but accept this one. In the meantime, we'll see what else comes over the wire. Thanks again! – Osbourne Ruddock Jan 20 '15 at 17:55
  • 1
    Thanks again for your help. I started with the tutorial here: http://iphonedevwiki.net/index.php/CPDistributedMessagingCenter and implemented RocketBootstrap, which does allow me to achieve IPC, but it is painfully slow... – Osbourne Ruddock Jan 21 '15 at 07:53