(iOS,TheOS)%挂钩到全局应用程序功能

时间:2013-12-25 18:39:46

标签: objective-c ios7 hook jailbreak theos

我正在为iOS 7中的应用寻找全球function

更具体地说,我希望在启动时将代码注入应用程序,这只会影响app,而不影响SpringBoard

我尝试过几件事,但它们只影响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

这些只是我尝试functions的几个例子。

我怀疑过滤器也需要更改,但这取决于函数所在的位置(com.apple.springboard设置为atm)。

我收到了一条提示,要求将过滤器设置为*,但如果我不知道function%hook的内容,那对我来说并不是很好。

请尽可能解释你的答案。

2 个答案:

答案 0 :(得分:4)

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

Try checking out the MobileSubstrate docs here

我不是百分百肯定我明白你要做什么,但听起来你只是想要在所有普通“应用程序”中运行的任何方法?

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

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

然后,您可以尝试使用MSHookFunction()挂钩C函数as shown in this example

在您的代码中,尝试挂钩UIApplicationMain(),我相信所有正常的应用都会使用。

更新

另一种可能的技术是从UIApplicationDelegate 协议挂钩任何常用的启动回调方法。但是,为了使用挂钩,您需要发现哪些实现此协议。 See this answer for an example of doing this (with another protocol)

答案 1 :(得分:1)

使用 NSDistributedNotificationCenter 的解决方法可以满足您的需求。

首先,您需要将过滤器设置为 com.apple.UIKit ,以便动态库可以连接到所有进程。

然后创建一个Class(.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并在那里初始化Class来添加替代方法。

相关问题