In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)06/01 Report--
When developing jailbreak applications and plug-ins, system is often called to execute system commands. As early as Xcode 7, the system function was used to prompt warnings:
'system' is deprecated: first deprecated in iOS 8.0-Use posix_spawn APIs installd
Just a warning, it can still be compiled and used normally, but the upgrade to Xcode 9 Magi system function is removed from SDK and can no longer be used. Hint:
'system' is unavailable: not available on iOS
There are generally three alternatives. The first is to use posix_spawn. The code is as follows:
Pid_t pid;char * argv [] = {"/ bin/ls", / / path "- al", / / parameter1 "/", / / parameter2 NULL}; posix_spawn (& pid, argv [0], NULL, NULL, argv, NULL); printf ("pid=%d,child pid=%d\ n", getpid (), pid); int stat;waitpid (pid,&stat,0); printf ("stat is% d\ n", stat)
The second is to use NSTask, the code is as follows:
NSTask * task = [[NSTask alloc] init]; task.launchPath = @ "/ bin/ls"; task.arguments = [NSArray arrayWithObjects: @ "- al", @ "/", nil]; [task launch]; [task waitUntilExit]
The NSTask.h header file information is as follows:
# import @ class NSString, NSArray, NSDictionary; @ interface NSTask: NSObject / / Create an NSTask which can be run at a later time// An NSTask can only be run once. Subsequent attempts to// run an NSTask will raise.// Upon task death a notification will be sent// {Name = NSTaskDidTerminateNotification; object = task;} / /-(instancetype) init; / / set parameters// these methods can only be done before a launch// if not set, use current// if not set, use current// set standard I channels; may be either an NSFileHandle or an NSPipe- O channels; may be either an NSFileHandle or an NSPipe- (void) setStandardInput: (id) input;- (void) setStandardOutput: (id) output;- (void) setStandardError: (id) error / get parameters@property (NS_NONATOMIC_IOSONLY, copy) NSString * launchPath;@property (NS_NONATOMIC_IOSONLY, copy) NSArray * arguments;@property (NS_NONATOMIC_IOSONLY, copy) NSDictionary * environment;@property (NS_NONATOMIC_IOSONLY, copy) NSString * currentDirectoryPath; / / get standardI / O channels; could be either an NSFileHandle or an NSPipe- (id) standardInput;- (id) standardOutput;- (id) standardError; / / actions- (void) launch;-(void) interrupt; / / Not always possible. Sends SIGINT.- (void) terminate; / / Not always possible. Sends SIGTERM. @ property (NS_NONATOMIC_IOSONLY, readonly) BOOL suspend;@property (NS_NONATOMIC_IOSONLY, readonly) BOOL resume; / / status@property (NS_NONATOMIC_IOSONLY, readonly) int processIdentifier; @ property (NS_NONATOMIC_IOSONLY, getter=isRunning, readonly) BOOL running; @ property (NS_NONATOMIC_IOSONLY, readonly) int terminationStatus; @ end @ interface NSTask (NSTaskConveniences) + (NSTask *) launchedTaskWithLaunchPath: (NSString *) path arguments: (NSArray *) arguments;// convenience; create and launch-(void) waitUntilExit / / poll the runLoop in defaultMode until task completes @ end FOUNDATION_EXPORT NSString * const NSTaskDidTerminateNotification
If you have to call the system function, use the third method to find the address of the system function and call it directly. For more information, please see: call the function dynamically. The specific code is as follows:
Typedef int (* my_system) (const char * str); int call_system (const char * str) {/ / dynamic library path char * dylib_path = "/ usr/lib/libSystem.dylib"; / / Open dynamic library void * handle = dlopen (dylib_path, RTLD_GLOBAL | RTLD_NOW); if (handle = = NULL) {/ / error fprintf (stderr, "% s\ n", dlerror ()) } else {/ / get the system address my_system system = dlsym (handle, "system"); / / call if (system) {int ret = system (str); return ret;} dlclose (handle); / / close the handle} return-1;}
In this way, the call_system function is equivalent to the function of system, just replace it.
Original address: https://www.exchen.net/ios-hacker-system-%E5%87%BD%E6%95%B0%E8%A2%AB%E5%BA%9F%E9%99%A4%E7%9A%84%E6%9B%BF%E4%BB%A3%E6%96%B9%E6%B3%95.html
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.