如何“附加”到应用程序,监视它以调用命令行实用程序并记录这些调用的文件名和命令行参数?
解决方案也可以是记录Mac OS X上所有应用程序执行的应用程序(过滤掉最常见的系统调用).
示例GUI前端:http://xact.sourceforge.net/(因为它是开源的,可以只调试它,但是xACT只是一个例子.让我们假设我们只有一个现成的* .app来监控).
更新:dtrace可以监视exec调用并打印所调用命令的名称.这是解决方案的一半,另一半是获得命令行参数.这还没有解决(直到有人确认他们已经有dtrace这样做).
解决方法 DTrace可以完成这项工作.根据我在其他地方关于这个问题的评论中与Joey Hagedorn的讨论,可以改进10.6附带的脚本以使用合理数量的参数(50).因为脚本有很多重复,所以我将在这里包含一个输出DTrace脚本的脚本,该脚本运行良好.这一个最多可以提出50个论点;您可能希望通过更改for循环来扩展参数的数量.#!/bin/bashcat <<header#!/usr/sbin/dtrace -s/* * newproc.d - snoop new processes as they are executed. DTrace Oneliner. * * This is a DTrace Oneliner from the DTracetoolkit. * * 15-May-2005 Brendan Gregg Created this. *//* * Updated to capture arguments in OS X. Unfortunately this isn't straight forward... */#pragma D option quIEtthis unsigned long long argv_ptr; /* WIDe enough for 64 bit user procs */proc:::exec-success{ print_pID[pID] = 1; /* This pID emerged from an exec,make a note of that. */}/* * The "this" variables are local to (all) of the following syscall::mmap:return probes,* and only those probes. They must be initialized before use in each new firing. */syscall::mmap:return{ this->argc = 0; /* disable argument collection until we notice an exec-success */}syscall::mmap:return/ print_pID[pID] /{ print_pID[pID] = 0; this->is64Bit = curpsinfo->pr_dmodel == PR_MODEL_ILP32 ? 0 : 1; this->wordsize = this->is64Bit ? 8 : 4; this->argc = curpsinfo->pr_argc; this->argc = (this->argc < 0) ? 0 : this->argc; /* Safety */ this->argv_ptr = curpsinfo->pr_argv; printf("%d %s ",pID,this->is64Bit ? "64b" : "32b");}headerfor ((i=0;i<50;++i)); docat <<REPEATsyscall::mmap:return/ this->argc /{ this->here_argv = copyin(this->argv_ptr,this->wordsize); this->arg = this->is64Bit ? *(unsigned long long*)(this->here_argv) : *(unsigned long*)(this->here_argv); printf("%s ",copyinstr(this->arg)); this->argv_ptr += this->wordsize; this->argc--;}REPEATdonecat <<FOOTERsyscall::mmap:return/ this->argv_ptr /{ printf("%s\n",this->argc > 0 ? "(...)" : ""); this->argc = 0; this->argv_ptr = 0;}FOOTER总结
以上是内存溢出为你收集整理的监控Cocoa应用程序以在Mac OS X上执行外部实用程序(例如,ffmpeg)?全部内容,希望文章能够帮你解决监控Cocoa应用程序以在Mac OS X上执行外部实用程序(例如,ffmpeg)?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)