python - 如何解析C头文件?

标签 python c

有谁知道在 Python 中使用 C 头文件的好方法吗?例如,我有一个包含全局变量的 C 程序:

typedef struct ImageInfo
{
    uint8_t revisionMajor;
    uint8_t revisionMinor;
    uint16_t checksum;    

} ImageInfo;

ImageInfo gImageInfo;   /* Placed at a specific address by the linker */

我希望能够获取由 C 编译器/链接器生成的二进制文件,并使用 Python 脚本解析此结构(并可能对其进行修改)。

最佳答案

这是昨天在 SO 上提到的;我还没有机会更彻底地检查它,但我的意思是。 pycparser,“用 Python 编写的 C 解析器和 AST 生成器”。

https://github.com/eliben/pycparser

关于python - 如何解析C头文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1951421/

相关文章:

python - Python 中的 read() 返回类型

python - 如何删除 Django 中默认用户数据库中的现有字段?

c - NUL 和 NULL 有什么区别?

ios - 我如何向量化这个 for 循环?

c++ - 错误] ISO C++ 禁止指针和整数之间的比较 [-fpermissive]

c - c 中的 printf()它不应该将输入值视为地址吗

Python 3 异常 : TypeError: function missing 1 required positional argument: 'words'

python - CPLEX 给出了两个不同的结果?

Python:从 matplotlib.pyplot.contour() 中查找等高线

c - 类型定义,#define