如何从ELF文件中获取静态初始化的全局变量的值?
例如,我有以下C ++源文件
// define global variables here
int Label = 1234;
char Hash[] = "0x11231abc";
将其编译为 *.O文件,以后可以链接到可执行的二进制文件。是否可以使用一些现有工具(例如Readelf,objdump)从ELF文件中获取值?
For example I have following c++ source file
// define global variables here
int Label = 1234;
char Hash[] = "0x11231abc";
compile this to *.o file, and may be later linked to an executable binary. Is it possible to get the value from ELF file by using some existing tools, like readelf, objdump?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是否完全可能 都取决于这些变量的使用方式,无论是本地还是全局,它们是否具有地址,使用了哪些编译器以及哪些优化有效。
如果变量是全局的,并且未优化代码,请确保
readelf
和objdump
命令的某些组合可能可以为您找到答案。通常,GDB将是这里使用的更好工具。
Whether this is possible at all depends on how exactly these variables are used, whether they are local or global, whether they have their address taken, which compiler is used and what optimizations are in effect.
If the variables are global and the code is not optimized, sure some combination of
readelf
andobjdump
commands could possibly get you the answer.In general, GDB would be a better tool to use here.