Mac OS X 如何执行应用程序

本文介绍了在Mac OS X系统中,由于与传统的UNIX变种不同,如何执行应用程序。文章讨论了OSX的运行时环境,特别是Dyld运行时环境,以及Mach-O文件格式在应用程序加载、链接和执行过程中的作用。通过otool工具,详细解析了Mach-O文件的头部、载入命令区段和原始段数据,展示了如何分析和理解二进制文件的内容。
摘要由CSDN通过智能技术生成

作为长期的UNIX用户,我通常有一些排除系统故障的工具。最近,我正在开发软件并新增了对苹果公司的OSX系统的支持。但是和其他传统UNIX变种不同,OSX不支持许多与加载、链接和执行程序相关的工具。

例如,当共享库重定位出错时,我所做的首要事情就是对可执行文件运行ldd。ldd工具列出了可执行文件所依赖的共享库(包括所在路径)。但是在OSX上,试图运行ldd将报错。

evil:~ mohit$ ldd /bin/ls
-bash: ldd: command not found

没找到?但在所有的类UNIX系统上基本上都有的啊!我想知道objdump是否可用。

evil:~ mohit$ objdump -x /bin/ls
-bash: objdump: command not found

命令未找到!怎么回事?

问题在于与Linux、Solaris、HP-UX和其他许多UNIX变种不同,OSX不使用ELF文件格式。另外,OSX不属于GNU项目的一部分。该项目包含像ldd和objdump这样的工具。

为了在OSX获得可执行文件所依赖的共享库列表,需要使用otool工具。

evil:~ mohit$ otool /bin/ls
otool: one of -fahlLtdoOrTMRIHScis must be specified
Usage: otool [-fahlLDtdorSTMRIHvVcXm] <object file> ...
        -f print the fat headers
        -a print the archive header
        -h print the mach header
        -l print the load commands
        -L print shared libraries used
        -D print shared library id name
        -t print the text section (disassemble with -v)
        -p <routine name> start dissassemble from routine name
        -s <segname> <sectname> print contents of section
        -d print the data section
        -o print the Objective-C segment
        -r print the relocation entries
        -S print the table of contents of a library
        -T print the table of contents of a dynamic shared library
        -M print the module table of a dynamic shared library
        -R print the reference table of a dynamic shared library
        -I print the indirect symbol table
        -H print the two-level hints table
        -v print verbosely (symbolicly) when possible
        -V print disassembled operands symbolicly
        -c print argument strings of a core file
        -X print no leading addresses or headers
        -m don't use archive(member) syntax
evil:~ mohit$ otool -L /bin/ls
/bin/ls:
        /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, c
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值