3

我的应用程序在 App Store 中可用,因此无法使用私有 api。

想知道调用sysctl获取后台进程列表是否是私有api调用?下面是获取运行进程列表的代码片段。

提前致谢。

- (NSArray *)runningProcesses 
{
    int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0};
    size_t miblen = 4;

    size_t size;
    int st = sysctl(mib, miblen, NULL, &size, NULL, 0);

    struct kinfo_proc *process = NULL;
    struct kinfo_proc *newprocess = NULL;

    do {
        size += size / 10;
        newprocess = realloc(process, size);

        if (!newprocess) {
            if (process) {
                free(process);
            }

            return nil;
        }

        process = newprocess;
        st = sysctl(mib, miblen, process, &size, NULL, 0);
    } while (st == -1 && errno == ENOMEM);

    if (st == 0) {
        if (size % sizeof(struct kinfo_proc) == 0) {
            int nprocess = size / sizeof(struct kinfo_proc);

            if (nprocess) {
                NSMutableArray * array = [[NSMutableArray alloc] init];

                for (int i = nprocess - 1; i >= 0; i--) {
                    NSString *processID = [[NSString alloc] initWithFormat:@"%d", process[i].kp_proc.p_pid];
                    NSString *processName = [[NSString alloc] initWithFormat:@"%s", process[i].kp_proc.p_comm];

                    NSDictionary *dict = [[NSDictionary alloc] initWithObjects:[NSArray arrayWithObjects:processID, processName, nil] 
                                                                       forKeys:[NSArray arrayWithObjects:@"ProcessID", @"ProcessName", nil]];
                    [processID release];
                    [processName release];
                    [array addObject:dict];
                    [dict release];
                }

                free(process);
                return array;
            }
        }
    }

    return nil;
}
4

2 回答 2

4

您可以使用一个非常有用的工具,称为 Appscanner

https://github.com/ChimpStudios/App-Scanner

App Scanner 是适用于 iOS 开发人员的预检提交检查列表。它搜索私有 API 使用的代码。

它应该捕获大多数私有 API 使用。

您可以通过以下三种方式之一使用 App Scanner:将已编译的模拟器 .app 文件夹放入 GUI 以扫描应用程序,在搜索文本字段中键入方法签名,或将命令行版本作为脚本的一部分集成到构建阶段以Xcode 编译后自动检查代码。

基本上,作者有一个私有 API 的转储,并且可以检查您是否使用了任何 API。

由于 sysctl 是一个 UNIX 调用,我不认为它是私有的。

于 2014-08-20T06:26:15.780 回答
2

No, this call isn't private. Apple allows its use (well, at least for now).

I have an app in the AppStore that does this.

于 2014-08-20T06:41:05.647 回答