【发布时间】:2012-06-12 03:54:29
【问题描述】:
如何转储可执行文件中的所有全局变量和地址偏移量?
这是在 os x 上,使用 gcc 编译的 xcode 开发的应用程序。
谢谢
【问题讨论】:
如何转储可执行文件中的所有全局变量和地址偏移量?
这是在 os x 上,使用 gcc 编译的 xcode 开发的应用程序。
谢谢
【问题讨论】:
使用otool 或cctools。
您应该可以使用objdump 和/或readelf 来执行此操作。
我手头没有 *nix 系统,但objdump -s -j .data 应该可以让你离你很近。
【讨论】:
从 macOS 上的可执行文件中获取全局变量列表及其偏移量的简单方法(原始问题)是使用 nm 工具。没有任何额外的键,它给出了变量和它们的偏移量。
例子:
$ nm <some binary>
...
U __ZTVN10__cxxabiv117__class_type_infoE
U __ZTVN10__cxxabiv120__si_class_type_infoE
000000010006e248 s __ZTVN7testing17TestEventListenerE
000000010006e1c0 s __ZTVN7testing22EmptyTestEventListenerE
000000010006dfa8 s __ZTVN7testing31TestPartResultReporterInterfaceE
000000010006d860 S __ZTVN7testing32ScopedFakeTestPartResultReporterE
000000010006d8d8 S __ZTVN7testing4TestE
...
查看man nm了解U、s、S等代码的解释。
如果您还想查找字符串常量,还有另一个工具strings:
$ strings <some binary> -o -t x
将为您提供字符串文字及其偏移量的列表。
更多详情请见man strings。
【讨论】: