如何从ELF文件中获取静态初始化的全局变量的值?

发布于 2025-02-11 08:53:37 字数 241 浏览 0 评论 0原文

例如,我有以下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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

作妖 2025-02-18 08:53:37

是否可以使用一些现有工具(例如Readelf,objdump?

)从ELF文件中获取值?

这是否完全可能 都取决于这些变量的使用方式,无论是本地还是全局,它们是否具有地址,使用了哪些编译器以及哪些优化有效。

如果变量是全局的,并且未优化代码,请确保readelfobjdump命令的某些组合可能可以为您找到答案。

通常,GDB将是这里使用的更好工具。

Is it possible to get the value from ELF file by using some existing tools, like readelf, objdump?

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 and objdump commands could possibly get you the answer.

In general, GDB would be a better tool to use here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文