Quantcast
Channel: Essence Sharing | 干货分享 - iOSRE
Viewing all articles
Browse latest Browse all 301

如何在rootless环境下的launchdaemon执行bash脚本

$
0
0

@Lakr233 wrote:

之前被坑到了 忘记了bash目录不在根目录下 。。。 发个帖提醒一下

extern char **environ;
void run_cmd(char *incmd) {
pid_t pid;

NSString *run = [[NSString alloc] initWithUTF8String:incmd];
run = [[NSString alloc] initWithFormat:@"'%@'", run];
char *cmd = (char *)[run UTF8String];
// aviod echo went wrong on rootless jb

char *argv[] = {"bash", "-c", cmd, NULL, NULL};
int status;

NSString *cmdStr = [[NSString alloc] initWithUTF8String: cmd];
NSLog(@"[Execute] bash -c %@", cmdStr);

if (isRootless) {
    NSString *rtcmd = [[NSString alloc] initWithFormat: @"PATH=/var/containers/Bundle/tweaksupport/usr/local/bin:/var/containers/Bundle/tweaksupport/usr/bin:/var/containers/Bundle/tweaksupport/bin:/var/containers/Bundle/iosbinpack64/usr/sbin/"];
    rtcmd = [rtcmd stringByAppendingString:@" "];
    rtcmd = [rtcmd stringByAppendingString: [[NSString alloc] initWithUTF8String:incmd]];
    char *rootlessARGS[] = {"bash", "-c", (char *)[rtcmd UTF8String], NULL, NULL};
    status = posix_spawn(&pid, "/var/containers/Bundle/tweaksupport/bin/bash", NULL, NULL, rootlessARGS, environ);
} else {
    status = posix_spawn(&pid, "/bin/bash", NULL, NULL, argv, environ);
}

if (status == 0) {
    if (waitpid(pid, &status, 0) == -1) {
        perror("waitpid");
    }
}

}

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 301

Trending Articles