I am programming an advanced Executable (binary) Analyser Application that can do many operations on Mach-O binaries. One of these functions is a simple launch operation with can simply execute the executable and log its output. I recently found out the when terminal launches executable files, it detects when the executable runs its own NSTask inside its code.
eg.
Terminal is executing my application and is also showing (in the red circle) that my application is currently running an NSTask of the "file" command:
What I want to figure out is how I can make my app do this to other executable files. I want my app to launch an Executable and when the executable runs a shell script (NSTask), My app will detect it and log it.
eg. An Executable has the following code:
int main(int argc, const char * argv[]) {
NSTask *task = [NSTask new];
task.launchPath = @"/usr/bin/file";
task.arguments = @[@"--mime", @"--brief", @"/path/to/file"];
task.standardOutput = [NSPipe new];
[task launch];
return 0;
}
When I execute this in Terminal, once the line
[task launch];
is executed, Terminal will display the sub process name in the titlebar:
I Want my app to execute an Executable just like terminal and when an executable runs its own NSTask, I want my app to detect that and log it.
So when my app runs this executable. I want my app to detect when the "file" task is executed in the executable.
I Hope this isn't to difficult to Understand. I also have a feeling I will have to dig deeper than NSTask to include this process.
Thanks.