I was making an app to call system commands after pressing a button.
The environment is Mac OS Sierra 10.12.5, Xcode 8.3.3, Objective-C.
Here's my code:
- (IBAction)ButtonPressed:(UIButton *)sender {
NSString *title = [sender titleForState: UIControlStateNormal];
NSString *plainText = [NSString stringWithFormat:#"%# button pressed", title];
_statusLabel.text = plainText;
NSPipe *pipe;
pipe = [NSPipe pipe];
NSFileHandle *file;
file = [pipe fileHandleForReading];
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath : #"/bin/ls"];
NSArray *arguments;
arguments = [NSArray arrayWithObjects: #"-l", #"-a", #"-t", nil];
[task setArguments : arguments];
[task setStandardOutput : pipe];
[task launch];
NSData *data;
data = [file readDataToEndOfFile];
NSString *string;
string = [[NSString alloc] initWithData: data
encoding: NSUTF8StringEncoding];
NSLog (#"woop! got\n%#", string);
}
I run this on my jailbroken iPhone 6 (iOS version 10.2). The program always crashes when I press the button.
The crash log is:
2017-07-13 14:08:20.346060 Hello World[2770:532052] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Couldn't posix_spawn: error 1'
*** First throw call stack:
(0x18ae451b8 0x18987c55c 0x18ae45100 0x18b96de6c 0x1000d646c 0x190d2fd30 0x190d2fcb0 0x190d1a128 0x190d2f59c 0x190d2f0c4 0x190d2a328 0x190cfada0 0x1914e475c 0x1914de130 0x18adf2b5c 0x18adf24a4 0x18adf00a4 0x18ad1e2b8 0x18c7d2198 0x190d657fc 0x190d60534 0x1000d69c8 0x189d015b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I don't know 'NSInternalInconsistencyException', reason: 'Couldn't posix_spawn: error 1'.
Also, the final command I want to test is
kill -USR1 `ps ax|grep omm|grep ys|xargs|cut -d ' '-f 1`
However, the commands above just cannot work, I can't move on.
Any ideas?
Related
I'm programming an application in Swift and Objective-C and when I run the test app on the iPhone everything works, but when i was trying to start a call the application crashed showing this:
*** First throw call stack:
(0x181be11b8 0x18061855c 0x181be1100 0x182610eb8 0x100265a2c 0x187acbd30 0x187acbcb0 0x187ab6128 0x187acb59c 0x187acb0c4 0x187ac6328 0x187a96da0 0x18828075c 0x18827a130 0x181b8eb5c 0x181b8e4a4 0x181b8c0a4 0x181aba2b8 0x18356e198 0x187b017fc 0x187afc534 0x1002bc898 0x180a9d5b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) terminating
This is the button code:
- (IBAction)startCallButton:(id)sender {
TCallViewController *callViewController = [[TCallViewController alloc] init];
[self.navigationController pushViewController:callViewController animated:YES];
NSString *handle = [[NSString alloc] initWithString:_handle];
BOOL Video = _video;
if ((handle = callViewController.handle) ){
Video = callViewController.video;
[callManager startCallWithHandle:(handle) video:Video];
}
}
how can I solve this problem?
Updated full image of console Image shows the console containing errorXcode throws this exception when send button is pressed on message view controller toolbar.
DataManager* dm = [DataManager sharedInstance];
NSDictionary* msgdata = #{KChatIdentifier: _chatId,
kMessageToIdentifier : _toIdentifier,
kMessageFromIdentifier : _fromIdentifier,
kMessageText : text,
kMessageType : [NSNumber numberWithInt:MESSAGE_TYPE_TEXT],
kMessageSenderName: dm.currentUser.username,
kMessageSenderImageURL: dm.currentUser.imageURL,
kMessageReceiverName: #"", kMessageReceiverImageURL:#""};
NSLog(#"%#", msgdata);
[[SocketManager sharedInstance] sendText:msgdata];
JSQMessage* newMessage = [JSQMessage messageWithSenderId:self.senderId displayName:self.senderDisplayName text:text];
[_arrMessages addObject:newMessage];
[self checkForDateHeader:date index:_arrMessages.count-1];
[self finishSendingMessage];
}
I could successfully run the following command on simulator
tcpdump -i en0 -A -vvv host www.facebook.com
I used the following code
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath: #"/usr/sbin/tcpdump"];
[task setArguments: [[NSArray alloc] initWithObjects:#"-c",#"10", #"-i",#"en1",#"-A",#"-vvv",#"host",#"www.facebook.com", nil]];
NSPipe *pipe= [NSPipe pipe];
[task setStandardOutput: pipe];
file = [pipe fileHandleForReading];
[task launch];
when i run this code on iPhone it gives following error
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'launch path not accessible'
* First throw call stack:
(0x2f4a5f4b 0x398e66af 0x2f4a5e8d 0x2fe93081 0x12933 0x31c1d37b 0x31c1d139 0x31c23e05 0x31c214db 0x31c8c08d 0x31c88e59 0x31c83353 0x31c1e41f 0x31c1d721 0x31c82b3d 0x3410170d 0x341012f7 0x2f4709df 0x2f47097b 0x2f46f14f 0x2f3d9c27 0x2f3d9a0b 0x31c81dd9 0x31c7d049 0x12f2d 0x39deeab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
i have tried removing "/usr/sbin/" from code when running on iphone still it gives same error.Where am i going wrong?
2012-10-08 14:48:14.579 sageby[2716:907] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SBJsonParser errorTrace]: unrecognized selector sent to instance 0x1fda4660'
* First throw call stack:
(0x352412a3 0x34a1397f 0x35244e07 0x35243531 0x3519af68 0x12932f 0x1293a7 0x12cda3 0x12c9b1 0x12c753 0x12aac7 0x12e567 0x12eac3 0x3a26bef5 0x3a1ab9f1 0x3a1ab90d 0x384ba5df 0x384b9ccb 0x384e2133 0x3518774d 0x384e2593 0x3844615d 0x35216683 0x35215ee9 0x35214cb7 0x35187ebd 0x35187d49 0x35ef02eb 0x37dcd301 0xaaaf1 0x39e0cb20)
libc++abi.dylib: terminate called throwing an exception
(lldb)
//MBProgressHUD
MBProgressHUD *hud=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.labelText=#"Accessing account..";
hud.labelFont=[UIFont fontWithName:#"Arial Rounded MT Bold" size:14];
//URL GETTING
NSString *phpfile=[[NSString alloc]initWithFormat:#"http://dev.xxxx.com/pxxx/Module_MyPxxx/json_xxxx_xxx_info.php"];
NSString *param_str=[[NSString alloc]initWithFormat:#"email=%#", mydelegate.overall_email];
NSString *receivedDataAsString=[mydelegate phpConnection:param_str :phpfile];
SBJsonParser *parser=[[SBJsonParser alloc]init];
NSError *error=nil;
self.dic_user_info=[[parser objectWithString:receivedDataAsString error:&error]objectAtIndex:0];
if(error)
{
NSLog(#"JSON Parser error! Reason: %#", error.localizedDescription);
}
//URL GETTING
phpfile=[[NSString alloc]initWithFormat:#"http://dev.xxx.com/pxxx/Module_MyPxxx/json_get_xxx_xxx_pxxx.php"];
param_str=[[NSString alloc]initWithFormat:#"email=%#", mydelegate.overall_email];
receivedDataAsString=[mydelegate phpConnection:param_str :phpfile];
parser=[[SBJsonParser alloc]init];
error=nil;
self.array_polls=[parser objectWithString:receivedDataAsString error:&error];
if(error)
{
NSLog(#"JSON Parser error! Reason: %#", error.localizedDescription);
}
[self.tableView reloadData];
[MBProgressHUD hideHUDForView:self.view animated:YES];
hi i'm the developer of the application.
The problem is that running on Xcode 4.5 is correct but just running on iphone device it wont work..
Request:
- (void) getMyImageWithContestOfFace{
currentApiCall = getMyImageFb;
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"SELECT pic FROM user WHERE uid=me()",#"query",
nil];
AppDelegate *delegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
[[delegate facebook] requestWithMethodName:#"fql.query"
andParams:params
andHttpMethod:#"POST"
andDelegate:self];
}
Parsing:
...
case getMyImageFb:{
flag = TRUE;
imageWithFace = [[UIImage alloc] init];
imageWithFace = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[result objectForKey:#"pic"]]]];
}
break;
...
When i call it i catch very strange exeption:
*2011-11-10 00:30:30.661 FaceGraph[1699:f803] I have some information
2011-11-10 00:30:30.664 FaceGraph[1699:f803] -[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x6d3d470
2011-11-10 00:30:30.666 FaceGraph[1699:f803] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0x6d3d470'
First throw call stack:
(0x15d9052 0x176ad0a 0x15daced 0x153ff00 0x153fce2 0x254db 0xb6d6 0xbcf7 0xc9ba59 0xc99e94 0xc9aeb7 0xc99e4f 0xc99fd5 0xbdef6a 0x3b8bbbd 0x3c585ea 0x3b82298 0x3c5816b 0x3b82137 0x15ad97f 0x1510b73 0x1510454 0x150fdb4 0x150fccb 0x14c2879 0x14c293e 0x2a6a9b 0x2332 0x22a5)
terminate called throwing an exceptionsharedlibrary apply-load-rules all
Current language: auto; currently objective-c
No idea why. The most strange that i did it before ABSOLUTELY the same, and it worked fine.
I can't find the difference between my old projects and current. Maybe somebody have the same problem?? If you need more code - ask for it.
thanks
Well, the exception seems to be quite clear: result is probably an array and not a dictionary.
PS: The line imageWithFace = [[UIImage alloc] init]; is totally superfluous given the line that follows it. You should remove it.
I forgot to add:
if ([result isKindOfClass:[NSArray class]]){
result = [result objectAtIndex:0];
}
in result-parsing function.