【问题标题】:Making a daemon for a jailbroken iOS为越狱的 iOS 制作守护进程
【发布时间】:2011-02-24 18:47:51
【问题描述】:


我一直在寻找一种在 iPhone 上启动守护进程的方法,我通过学习 ants application 的源代码用 Xcode 创建了一个小测试应用程序,它告诉我应该使用 launchctl 但不幸的是它不起作用.

我已经在/Applications/ 的 iPod Touch 上使用 SSH 安装了我的应用程序,然后我通过帐户 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

当我使用 root 启动它(使用 su 执行它)时,我让守护程序运行,但它什么也没做。

我的守护进程应该在启动后每十秒显示一个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

【问题讨论】:

    标签: iphone ios daemon jailbreak launchd


    【解决方案1】:

    你工作太辛苦了。您需要做的就是创建一个 .plist 文件,其中包含应用程序标识符和路径,并将其添加到 /System/Library/LaunchDaemon 文件夹。然后确保您的应用位于 /Applications 文件夹中。重新启动,每次开机都会正常工作。

    谷歌“Chris Alvares daemon”并查看他的教程...

    【讨论】:

    • 我遵循了 Chris Alvares 守护进程教程。但是,我未能成功运行守护程序。它给出了一个错误。
    【解决方案2】:

    我认为 launchD 不能触发 GUI 级应用。 “Aqua”级别的任何内容都必须是“StartupItem”或“Login Item”。你仍然可以以 root 身份启动它们,这取决于它们从哪里开始,以及它们归谁所有,但是 launchd 不会触及那些东西......处理它....

    如果您使用越狱的 iphone...如果您想从“移动终端”打开 GUI 应用程序,您应该在 Cydia 中查找该应用程序“这样做”。它不像启动可执行文件那么容易。有一些时髦的跳板交互。该实用程序负责处理。它被称为......“AppsThruTerm”(bigboss repo)一旦安装......你使用命令att blahblahblah

    启动你的“应用程序”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多