分析 MIPS 二进制文件:是否有用于解析二进制数据的 Python 库?

发布于 2024-07-04 00:18:47 字数 413 浏览 7 评论 0原文

我正在开发一个实用程序,需要将十六进制地址解析为二进制文件中的符号函数名称和源代码行号。 该实用程序将在 x86 上的 Linux 上运行,尽管它分析的二进制文件将用于基于 MIPS 的嵌入式系统。 MIPS 二进制文件采用 ELF 格式,使用 DWARF 作为符号调试信息。

我目前正计划分叉 objdump,传入十六进制地址列表并解析输出以获取函数名称和源代码行号。 我已经编译了一个支持 MIPS 二进制文件的 objdump,并且它正在工作。

我更喜欢有一个包,允许我从 Python 代码中本地查找内容,而无需分叉另一个进程。 我在 python.org 上找不到任何提及 libdwarf、libelf 或 libbfd 的内容,在 dwarfstd.org 上也找不到任何提及 python 的内容。

某处有合适的模块吗?

I'm working on a utility which needs to resolve hex addresses to a symbolic function name and source code line number within a binary. The utility will run on Linux on x86, though the binaries it analyzes will be for a MIPS-based embedded system. The MIPS binaries are in ELF format, using DWARF for the symbolic debugging information.

I'm currently planning to fork objdump, passing in a list of hex addresses and parsing the output to get function names and source line numbers. I have compiled an objdump with support for MIPS binaries, and it is working.

I'd prefer to have a package allowing me to look things up natively from the Python code without forking another process. I can find no mention of libdwarf, libelf, or libbfd on python.org, nor any mention of python on dwarfstd.org.

Is there a suitable module available somewhere?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(6

幸福不弃 2024-07-11 00:18:47

我一直在使用 Construct 开发 DWARF 解析器。 目前相当粗糙,解析速度很慢。 但我想我至少应该让你知道。 只需做一些工作,它可能会满足您的需求。

我在 Mercurial 中获得了代码,托管在 bitbucket 上:

Construct 是一个非常有趣的库。 DWARF 是一种复杂的格式(正如我所发现的),并且我认为将 Construct 推向了极限。

I've been developing a DWARF parser using Construct. Currently fairly rough, and parsing is slow. But I thought I should at least let you know. It may suit your needs, with a bit of work.

I've got the code in Mercurial, hosted at bitbucket:

Construct is a very interesting library. DWARF is a complex format (as I'm discovering) and pushes Construct to its limits I think.

乱了心跳 2024-07-11 00:18:47

hachior 是另一个用于解析二进制数据的库

hachior is another library for parsing binary data

缱绻入梦 2024-07-11 00:18:47

您应该尝试构造。 将二进制数据解析为Python对象非常有用。

甚至还有一个 ELF32 文件格式的示例。

You should give Construct a try. It is very useful to parse binary data into python objects.

There is even an example for the ELF32 file format.

玉环 2024-07-11 00:18:47

请检查 pyelftools - 一个新的纯 Python 库,旨在执行此操作。

Please check pyelftools - a new pure Python library meant to do this.

放手` 2024-07-11 00:18:47

我不知道,但如果其他方法都失败了,你可以使用 ctypes 直接使用 libdwarf、libelf 或 libbfd。

I don't know of any, but if all else fails you could use ctypes to directly use libdwarf, libelf or libbfd.

咆哮 2024-07-11 00:18:47

您可能对 pydevtools 中的 DWARF 库感兴趣:

>>> from bintools.dwarf import DWARF
>>> dwarf = DWARF('test/test')
>>> dwarf.get_loc_by_addr(0x8048475)
('/home/emilmont/Workspace/dbg/test/main.c', 36, 0)

You might be interested in the DWARF library from pydevtools:

>>> from bintools.dwarf import DWARF
>>> dwarf = DWARF('test/test')
>>> dwarf.get_loc_by_addr(0x8048475)
('/home/emilmont/Workspace/dbg/test/main.c', 36, 0)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文