Trying to use cydia libraries: NSTask on Jailbroken iphone crashes with Segmentation fault: 11

旧时模样 提交于 2019-12-07 10:29:16

问题


I want to run dpkg ( or any other binary library files from cydia in the /bin or /usr/bin directories) from a GUI app with an icon, like mobileterminal, ifile, myfile, cydia, alertscript, and so many others can. How do they accesses the libraries? This code works, and the stdout of the process is printed in nslog but then it immediately crashes with Segmentation fault: 11. this is in my viewdidload function. This DOES NOT OCCUR IN THE SIMULATOR, only my iPhone 4. weird. have tried running as both mobile and root. the app is under /Applications folder. Here's my code.

EDIT: I'm using the snow leopard version of xcode, and just updated to lion but I'm thinking that's probably not the issue? My iPhone is ios5.0.1. will post when I test it.

NSString * workingdir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSTask * nstaskvar=[NSTask new];//note the NSTask.h file included! 
    NSPipe * outputPipe = [NSPipe pipe];

    [nstaskvar setLaunchPath:@"/bin/ls"];

    [nstaskvar setArguments:[NSArray arrayWithObjects:@"/usr",nil]];
    [nstaskvar setCurrentDirectoryPath:workingdir];

    [nstaskvar setStandardOutput:outputPipe];
    [nstaskvar setStandardInput:[NSPipe pipe]];

    [nstaskvar launch];

    NSString * outputstring = [[[NSString alloc] initWithData:[[outputPipe fileHandleForReading] readDataToEndOfFile] encoding:NSUTF8StringEncoding] autorelease];//readDataToEndOfFile reads until file is closed, which happens when process exits :) (i couldnt get waitUntilExit to work)
NSLog(@"%@", outputstring);



    [nstaskvar release];
    [outputPipe release];

回答1:


Solved it! After I upgraded to xcode 4.3.2, the lion version, the simulator crashed with exc_bad_access so i enabled zombies and found it was the last two lines [nstaskvar release]; [outputPipe release]; that caused the problem.

I disabled them both and it went away, and now works great on my iphone :D.



来源:https://stackoverflow.com/questions/9983430/trying-to-use-cydia-libraries-nstask-on-jailbroken-iphone-crashes-with-segmenta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!