C语言 适用于 Mac OS X 的类似 readelf 的工具?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3286675/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 05:56:42  来源:igfitidea点击:

readelf-like tool for Mac OS X?

cmacosfunctionsymbols

提问by karlphillip

Is there a tool for reading Mac OS X binaries that would print information about relocation tables and symbol offsets similar to this readelfoutput?

是否有用于读取 Mac OS X 二进制文件的工具,该工具会打印与此readelf输出类似的重定位表和符号偏移量的信息?

readelf -r app

Relocation section '.rel.dyn' at offset 0x5ec contains 2 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
08049d58  00001706 R_386_GLOB_DAT    00000000   __gmon_start__
08049d60  00000305 R_386_COPY        08049d60   _ZSt4cout

Relocation section '.rel.plt' at offset 0x5fc contains 13 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
08049d24  00000107 R_386_JUMP_SLOT   0804868c   print
08049d28  00000207 R_386_JUMP_SLOT   0804869c   _ZNSt8ios_base4InitC1E
08049d2c  00000507 R_386_JUMP_SLOT   080486ac   _ZStlsISt11char_traits
08049d30  00000607 R_386_JUMP_SLOT   080486bc   _ZNSolsEPFRSoS_E
08049d34  00000707 R_386_JUMP_SLOT   08048664   _init
08049d38  00000807 R_386_JUMP_SLOT   080486dc   sleep
08049d3c  00000907 R_386_JUMP_SLOT   080486ec   _ZNKSsixEj
08049d40  00000b07 R_386_JUMP_SLOT   080486fc   _ZNKSs4sizeEv
08049d44  00000c07 R_386_JUMP_SLOT   0804870c   __libc_start_main
08049d48  00000d07 R_386_JUMP_SLOT   08048ae4   _fini
08049d4c  00001307 R_386_JUMP_SLOT   0804872c   _ZSt4endlIcSt11char_tr
08049d50  00001507 R_386_JUMP_SLOT   0804873c   __gxx_personality_v0
08049d54  00001607 R_386_JUMP_SLOT   0804874c   _ZNSt8ios_base4InitD1E

In this example, printis a function loaded from a shared library (I wrote) at runtime. readelfis able to display information about its location inside the appbinary.

在这个例子中,print是一个在运行时从共享库(我写的)加载的函数。 readelf能够显示有关其在app二进制文件中的位置的信息。

回答by cbehanna

Using Macports:

使用Macports

  1. Install macports.
  2. Using macports port install binutils
  3. gobjdump -p /path/to/app
  1. 安装 macports
  2. 使用 macport port install binutils
  3. gobjdump -p /path/to/app

Using Homebrew:

使用自制软件

  1. Install Homebrew
  2. Do brew update && brew install binutils
  3. /usr/local/path/to/gobjdump -p /path/to/app# or follow instructions to add it to your PATH
  1. 安装 Homebrew
  2. brew update && brew install binutils
  3. /usr/local/path/to/gobjdump -p /path/to/app# 或按照说明将其添加到您的 PATH

There are, of course, many other command-line options. Note that the binutils port cautions that installing it may cause other ports to fail to build. Having it around to port install/look at something/port uninstall can still be handy.

当然,还有许多其他命令行选项。注意 binutils 端口提示安装它可能会导致其他端口无法构建。使用它进行端口安装/查看某些内容/端口卸载仍然很方便。

It's rather amazing that there isn't already some native tool to do this.

令人惊讶的是,还没有一些本地工具可以做到这一点。

回答by ergosys

otool -l test.o

otool -l test.o

回答by Peter Hosey

You might try dwarfdump.

你可以试试dwarfdump

???????????

????????????

回答by Jichao

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install binutils
greadelf filepath
  1. install homebrew.
  2. use homebrew to install binutils
  3. the readelf in binutils is called greadelf.
  1. 安装自制软件。
  2. 使用 homebrew 安装 binutils
  3. binutils 中的 readelf 被称为greadelf.

回答by carlfilips

Have you tried ObjConv? http://agner.org/optimize/#objconv

你试过 ObjConv 吗?http://agner.org/optimize/#objconv

This utility can be used for converting object files between COFF/PE, OMF, ELF and Mach-O (used by Mac OS) formats for all 32-bit and 64-bit x86 platforms. Can modify symbol names in object files. Can build, modify and convert function libraries across platforms. Can dump object files and executable files. Also includes a very good disassembler supporting the SSE4, AVX, FMA and XOP instruction sets.

此实用程序可用于在所有 32 位和 64 位 x86 平台的 COFF/PE、OMF、ELF 和 Mach-O(由 Mac OS 使用)格式之间转换目标文件。可以修改目标文件中的符号名称。可以跨平台构建、修改和转换函数库。可以转储目标文件和可执行文件。还包括一个非常好的反汇编器,支持 SSE4、AVX、FMA 和 XOP 指令集。

Ps.: The source code is included (GPL).

Ps.:包含源代码(GPL)。