2

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.

4

2 回答 2

4

您的代码仅在SpringBoard中运行,因为您已选择挂钩SpringBoard 类中的方法(例如SBUIControllerSBApplicationController等),并且您的过滤器设置为仅挂钩 SpringBoard 本身。

尝试在此处查看 MobileSubstrate 文档

我不是 100% 确定我理解你想要做什么,但听起来你只是想要任何可以在所有普通“应用程序”中运行的方法?

如果是这样,您可能会更改过滤器以挂钩使用 UIKit 的所有内容:

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

然后,您可以尝试使用MSHookFunction()挂钩 C 函数,如本示例所示

在您的代码中,尝试挂钩UIApplicationMain(),我相信所有普通应用程序都会使用它。

更新:

UIApplicationDelegate 另一种潜在的技术是从协议中挂钩任何常用的启动回调方法。但是,为了使用挂钩,您需要发现哪些实现了该协议。 有关执行此操作的示例(使用另一个协议),请参见此答案

于 2013-12-28T08:20:09.187 回答
1

有一个使用NSDistributedNotificationCenter的解决方法,它可以满足您的需求。

首先,您需要将过滤器设置为com.apple.UIKit,以便您的动态库与所有进程挂钩。

然后创建一个类(.h 和 .m 文件)并将其命名为GlobalFunction

GlobalFunction.h 文件

@interface GlobalFunction: NSObject
@end

GlobalFunction.m 文件

#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

并在您的Tweak.xm中执行以下操作:

#import "GlobalFunction.h"

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

所以当SpringBoard加载时,类会被初始化。然后使用:

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

发布通知,以便调用该方法。

我没有对此进行测试,但它应该可以工作,并且它类似于我之前制作的东西,效果很好。

编辑#1:

要在 app-launch 上执行该方法,请在Tweak.xm文件中添加以下内容:

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

编辑#2:

编辑帖子以删除 %ctor,因为这可能行不通。通过挂钩 SpringBoard 并在那里初始化类添加了替代方法。

于 2014-08-11T07:07:39.630 回答