为越狱的iOS创建一个守护进程

3


我一直在寻找在iPhone上启动守护进程的方法,并通过学习蚂蚁应用程序的源代码创建了一个小型测试应用程序,这教会了我应该使用launchctl。但不幸的是,它没有起作用。

我已经通过SSH在我的iPod Touch上安装了我的应用程序在/Applications/中,然后通过mobile账户通过SSH启动它,我的日志显示如下:

Script started on Thu Feb 24 19:33:28 2011
bash-3.2$ ssh mobile@192.168.1.8
mobile@192.168.1.8's password: 
iPod-van-Henri:~ mobile$ cd /Applications
iPod-van-Henri:/Applications mobile$ cd DaemonUtility.app/
iPod-van-Henri:/Applications/DaemonUtility.app mobile$ ./DaemonUtility 
2011-02-24 19:35:08.022 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:09.021 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:10.021 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:11.021 DaemonUtility[1369:107] Read 0 bytes
Bug: launchctl.c:2367 (24307):13: (dbfd = open(g_job_overrides_db_path, O_RDONLY | O_EXLOCK | O_CREAT, S_IRUSR | S_IWUSR)) != -1
launchctl: CFURLWriteDataAndPropertiesToResource(/private/var/stash/Applications.pwn/DaemonUtility.app/com.developerief2.daemontest.plist) failed: -10
launch_msg(): Socket is not connected
2011-02-24 19:35:12.039 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:13.021 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:14.021 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:15.021 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:16.021 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:17.021 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:18.021 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:19.021 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:20.021 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:21.021 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:22.021 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:23.021 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:24.021 DaemonUtility[1369:107] Read 0 bytes
2011-02-24 19:35:25.021 DaemonUtility[1369:107] Read 0 bytes
^C
iPod-van-Henri:/Applications/DaemonUtility.app mobile$ exit
logout
Connection to 192.168.1.8 closed.

bash-3.2$ exit
exit

Script done on Thu Feb 24 19:34:49 2011

当我使用suroot身份启动它时,守护进程会运行,但没有任何作用。
自从它的启动以来,我的守护进程应该每十秒显示一个UIViewAlert
**main.m (Daemon)**
//
//  main.m
//  DaemonTest
//
//  Created by ief2 on 23/02/11.
//

#import <UIKit/UIKit.h>

@interface DAAppDelegate : NSObject <UIApplicationDelegate> {
    NSDate *_startupDate;
    NSTimer *_messageTimer;
}
@property (nonatomic, retain) NSDate *startupDate;
@end

@interface DAAppDelegate (PrivateMethods)
- (void)showMessage:(NSTimer *)timer;
@end

@implementation DAAppDelegate
@synthesize startupDate=_startupDate;

- (void)dealloc {
    [_startupDate dealloc];
    [_messageTimer dealloc];

    [super dealloc];
}

- (void)applicationDidFinishLaunching:(UIApplication *)theApplication {
    UIAlertView *myView;
    myView = [[UIAlertView alloc] initWithTitle:@"Daemon Launched" 
                                        message:@"The daemon was launched"
                                       delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
    [myView show];
    [myView release];

    self.startupDate = [NSDate date];

    NSTimer *myTimer = [NSTimer scheduledTimerWithTimeInterval:10 
                                                        target:self
                                                      selector:@selector(showMessage:) 
                                                      userInfo:nil
                                                       repeats:YES];
    _messageTimer = [myTimer retain];
}

- (void)applicationWillTerminate:(UIApplication *)theApplication {
    [_messageTimer invalidate];

    UIAlertView *myView;
    myView = [[UIAlertView alloc] initWithTitle:@"Daemon Terminated" 
                                        message:@"The daemon was terminated"
                                       delegate:nil
                              cancelButtonTitle:@"OK"
                              otherButtonTitles:nil];
    [myView show];
    [myView release];
}

- (void)showMessage:(NSTimer *)timer {
    NSTimeInterval mySec;
    mySec = [self.startupDate timeIntervalSinceNow];
    NSString *format = [NSString stringWithFormat:
                        @"The daemon has been running for %llu seconds",
                        (unsigned long long)mySec];
    UIAlertView *myView;
    myView = [[UIAlertView alloc] initWithTitle:@"Daemon Message" 
                                        message:format 
                                       delegate:nil 
                              cancelButtonTitle:@"OK" 
                              otherButtonTitles:nil];
    [myView show];
    [myView release];
}
@end


int main(int argc, const char **argv) {
    NSAutoreleasePool *mainPool = [[NSAutoreleasePool alloc] init];

    UIApplicationMain(argc, (char **)argv, nil, @"DAAppDelegate");

    [mainPool drain];
    return 0;
}

完整的应用程序源代码可以在我的电脑上找到:
http://81.82.20.197/DaemonTest.zip

提前感谢,
ief2

2个回答

7
你工作太辛苦了。你只需要创建一个.plist文件,其中包含应用程序标识符和路径,并将其添加到/System/Library/LaunchDaemon文件夹中。然后确保你的应用程序在/Applications文件夹中。重新启动手机,每次启动时它都会起作用。
谷歌搜索“Chris Alvares daemon”并查看他的教程...

我已经按照Chris Alvares的守护进程教程进行了操作。然而,我在成功运行守护进程方面遇到了困难。它会报错。 - Sunil Phani Manne

-1

我认为launchD不能触发GUI级别的应用程序。任何属于“Aqua”级别的应用程序都必须是“StartupItem”或“Login Item”。您仍然可以根据启动位置和所有者以root身份启动它们,但是launchd不会涉及那些东西……如果您希望由launchd处理,我认为甚至无法拥有菜单栏图标....

另外,如果您在谈论越狱的iPhone...如果您想从“mobileterminal”打开GUI应用程序,您应该在Cydia中寻找“完成此操作”的应用程序。这并不像只需启动可执行文件一样简单......还存在一些奇怪的springboard交互..而那个实用工具负责处理。它被称为......“AppsThruTerm”(bigboss存储库)。安装后...您可以使用命令att blahblahblah启动您的“应用程序”。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接