gpt4 book ai didi

iphone - 在越狱的 iPhone 上执行二进制文件

转载 作者:行者123 更新时间:2023-12-03 21:16:42 25 4
gpt4 key购买 nike

由于 iPhone 对其应用程序进行沙箱处理,我无法访问 /bin/ 文件夹。因此,我使用 SSH 连接从 iPhone 获取 /bin/date 二进制文件,并将其包含在我的项目中。当我使用 NSLog 时,我的文件的路径是正确的:/var/mobile/Applications/95078888-DDA8-4C1E-93DC-1F9E0A26E70A/Documents/date。下面列出了我遇到的问题。有谁知道我该如何修复这个错误?

*注意:如果我在模拟器中运行它并使用此代码执行任何与 mac OSX 兼容的二进制文件,它就可以工作,但是当我尝试使用 iPhone 二进制文件在设备上运行它时,就会出现问题。

错误:

2012-08-09 14:23:13.757 TestBinary[7891:707] Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'couldn't fork: errno 1'

First throw call stack: (0x359b388f 0x335d7259 0x359b3789 0x359b37ab 0x34deb915 0xda5af 0x3590d3fd 0x330cee07 0x330cedc3 0x330ceda1 0x330ceb11 0x330cf449 0x330cd92b 0x330cd319 0x330b3695 0x330b2f3b 0x336a522b 0x35987523 0x359874c5 0x35986313 0x359094a5 0x3590936d 0x336a4439 0x330e1cd5 0xd9ecd 0xd9e98)

terminate called throwing an exception

Program received signal: “SIGABRT”. Data Formatters temporarily unavailable, will re-try after a 'continue'. (Can't find dlopen function, so it is not possible to load shared libraries.)

mi_cmd_stack_list_frames: Not enough frames in stack.

mi_cmd_stack_list_frames: Not enough frames in stack.

调用日期文件的代码:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *path = [NSString stringWithFormat:@"%@/date", documentsDirectory];

NSLog(@"%@", path);

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath: path];

NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];

NSFileHandle *file;
file = [pipe fileHandleForReading];

[task launch];

NSData *data;
data = [file readDataToEndOfFile];

NSString *string;
string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];

label.numberOfLines=0;
label.text = string;

[string release];
[task release];

我的 NSTask 文件:

#import <Foundation/NSObject.h>

@class NSString, NSArray, NSDictionary;

@interface NSTask : NSObject

- (id)init;

- (void)setLaunchPath:(NSString *)path;
- (void)setArguments:(NSArray *)arguments;
- (void)setEnvironment:(NSDictionary *)dict;
- (void)setCurrentDirectoryPath:(NSString *)path;
- (void)setStandardInput:(id)input;
- (void)setStandardOutput:(id)output;
- (void)setStandardError:(id)error;

- (NSString *)launchPath;
- (NSArray *)arguments;
- (NSDictionary *)environment;
- (NSString *)currentDirectoryPath;

- (id)standardInput;
- (id)standardOutput;
- (id)standardError;

- (void)launch;

- (void)interrupt;
- (void)terminate;

- (BOOL)suspend;
- (BOOL)resume;

- (int)processIdentifier;
- (BOOL)isRunning;

- (int)terminationStatus;

@end

@interface NSTask (NSTaskConveniences)

+ (NSTask *)launchedTaskWithLaunchPath:(NSString *)path arguments:(NSArray *)arguments;

- (void)waitUntilExit;

@end

FOUNDATION_EXPORT NSString * const NSTaskDidTerminateNotification;
#endif

编辑1:

我使用以下目录解压:https://github.com/samsoffes/ssziparchive

这是我要解压缩并执行的代码:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

NSString *path2 = [[NSBundle mainBundle] pathForResource:@"date" ofType:@"zip"];
[SSZipArchive unzipFileAtPath: path2 toDestination:documentsDirectory];

NSString *path = [NSString stringWithFormat:@"%@/date", documentsDirectory];

NSFileManager* fileManager = [NSFileManager defaultManager];
NSMutableDictionary *attributes = [NSMutableDictionary dictionaryWithDictionary:[fileManager attributesOfItemAtPath:path error:nil]];

[attributes setValue:[NSNumber numberWithShort: 0777]
forKey:NSFilePosixPermissions];
NSError* err;
[fileManager setAttributes: attributes ofItemAtPath: path error: &err];

NSTask *task = [[NSTask alloc] init];
[task setLaunchPath: path];

NSPipe *pipe;
pipe = [NSPipe pipe];
[task setStandardOutput: pipe];

NSFileHandle *file;
file = [pipe fileHandleForReading];

[task launch];

NSData *data;
data = [file readDataToEndOfFile];

NSString *string;
string = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];

label.numberOfLines=0;
label.text = string;

[string release];
[task release];

最佳答案

我不确定为什么会发生这种情况,但是当 Xcode 构建时,它会以某种方式损坏date二进制文件。如果您查看原始 date 文件(在您的项目文件夹下),然后在 Xcode build 目录下找到相同的文件(例如):

/Users/myusername/Library/Developer/Xcode/DerivedData/HelloJB-gsokzlpnejddadbccgrfkxnumkyl/Build/Products/Release-iphoneos/HelloJB.app

您可以对这两个文件运行 diff 命令,它会告诉您这些二进制文件不同。这足以导致这个问题。

出于某种原因,Xcode 正在查看该类型的资源,并对其执行某些操作。例如,我知道它会尝试在应用程序的 png 资源上使用某种 pngcrush 实用程序。也许这很相似。

无论如何,我发现解决此问题的一种方法是在 Mac 上压缩 date 文件。然后,将 date.zip 作为捆绑资源包含在您的项目中。清理并构建。 Xcode 不会损坏 zip 文件。

现在,当您的应用启动时,需要从其捆绑资源中解压 date.zip 文件,并将解压版本存储在文档中,或者 < strong>缓存,或者任何你想要的地方。您可能还需要记住设置执行权限。

See this for programmatically unzipping files

更新:

之后,您可能需要将文件设置为具有可执行权限。像这样的事情:

NSFileManager* fileManager = [NSFileManager defaultManager];
NSMutableDictionary* attributes = [[NSMutableDictionary alloc] init];
NSNumber* permission = [NSNumber numberWithLong: 0755];
[attributes setObject:permission forKey: NSFilePosixPermissions];
NSError* err;
[fileManager setAttributes: attributes ofItemAtPath: filePath error: &err];

关于iphone - 在越狱的 iPhone 上执行二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11889742/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com