Domanda

I am looking for a global function for apps in iOS 7.

More specifically, I want to injected code into the app(s) upon launch, which will only effect the app, and not the SpringBoard.

I have tried a couple of things but they only affect the SpringBoard:

%hook SBApplicationIcon
    - (id)application {
        return %orig;
    }
    - (id)initWithApplication:(id)arg1 {
        return %orig;
    }
%end

%hook SBApplicationController
    - (id)init {
         return %orig;
    }
%end

%hook SBUIController
    - (void)launchIcon:(id)arg1 fromLocation:(int)arg2 {
        %orig;
    }
    - (id)contentView {
        return %orig;
    }
%end

%hook SBApplication
    - (void)didLaunch:(id)arg1 {
        %orig;
    }
%end

These are just a couple of examples of functions I've tried.

I suspect the filter needs to be changed as well, but that depends on where the function is located ofc (com.apple.springboard is set atm).

I was received a tip to set the filter to *, but that doesn't do me much good if I don't know what function to %hook.

Please explain your answer if possible.

È stato utile?

Soluzione 2

There is a workaround using NSDistributedNotificationCenter which will do what you want.

First of all, you need to set your filter to com.apple.UIKit so your dynamic library get's hooked into all processes.

Then create a Class (.h and .m file) and lets name it GlobalFunction:

GlobalFunction.h file

@interface GlobalFunction: NSObject
@end

GlobalFunction.m file

#import "GlobalFunction.h"

@implementation GlobalFunction
- (id)init {
    self = [super init];

    if (self) {
        [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(globalNotificationReceived:) name:@"info.ilendemli.globalNotification" object:nil];
    }

    return self;
}

- (void)globalNotificationReceived:(NSNotification *)notification {
    NSLog(@"Notification Received");
}
@end

and in your Tweak.xm do the following:

#import "GlobalFunction.h"

%hook SpringBoard
- (void)applicationDidFinishLaunching:(id)application {
    %orig;
    [GlobalFunction new];
}
%end

so the Class gets initialized when SpringBoard loads up. Then use:

[[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"info.ilendemli.globalNotification" object:nil];

to post a notification so the method gets called.

I haven't tested this but it should work, and it's similar to something i made before, which works great.

Edit #1:

To execute the method on app-launch add the following in your Tweak.xm file:

static NSArray *blackList = @[ @"MailAppController", @"SpringBoard", @"FBWildeApplication" ];

%hook UIApplication

- (void)_run {
    NSString *classString = NSStringFromClass([self class]);

    if (![blackList containsObject:classString]) {
        [[NSDistributedNotificationCenter defaultCenter] postNotificationName:@"info.ilendemli.globalNotification" object:nil];
    }

    %orig;
}

%end

Edit #2:

Edited the post to remove %ctor, because that probably wouldn't work. Added alternative approach by hooking SpringBoard and initializing the Class there.

Altri suggerimenti

Your code is only running in SpringBoard because you've chosen to hook methods in SpringBoard classes (e.g. SBUIController, SBApplicationController, etc.), and your filter is set to only hook SpringBoard itself.

Try checking out the MobileSubstrate docs here

I'm not 100% sure I understand what you're trying to do, but it sounds like you simply want any method that will run in all normal "apps"?

If so, you might change your filter to hook everything that uses UIKit:

Filter = {
  Bundles = (com.apple.UIKit);
};

You could then try using MSHookFunction() to hook a C-function, as shown in this example.

In your code, try hooking UIApplicationMain(), which I believe all normal apps would use.

Update:

Another potential technique would be to hook any of the usual launch callback methods from the UIApplicationDelegate protocol. In order to using hooking, though, you need to discover which classes implement this protocol. See this answer for an example of doing this (with another protocol).

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top