在 Linux 中使用 Python 读取 EXE、MSI 和 ZIP 文件元数据

发布于 2024-09-24 03:56:55 字数 535 浏览 1 评论 0原文

我正在编写一个 Python 脚本来将大量 Windows 安装程序索引到数据库中。

我想知道如何使用在 Linux 上运行的 Python 从 EXE、MSI 和 ZIP 文件中读取元数据信息(公司、产品名称、版本等)。

软件

我在 Ubuntu 10.04 64 位上使用 Python 2.6.5 和 Django 1.2.1。

目前发现:

可以提取 EXE 元数据的 Windows 命令行实用程序(如 SysUtils 中的 filever),或其他仅在 Windows 中工作的单独 CL 实用程序。我尝试通过 Wine 运行它们,但它们有问题,并且不值得花精力去查找这些 CL 实用程序所依赖的库和框架并尝试将它们安装在 Wine/Crossover 中。

Python 的 Win32 模块可以做一些事情,但不能在 Linux 中运行(对吗?)

第二个问题:

显然,更改文件的元数据会更改文件的 MD5 哈希和。除了定位和读取文件之外,是否有一种独立于元数据的散列文件的通用方法(例如:跳过前 1024 个字节?)

I am writing a Python script to index a large set of Windows installers into a DB.

I would like top know how to read the metadata information (Company, Product Name, Version, etc) from EXE, MSI and ZIP files using Python running on Linux.

Software

I am using Python 2.6.5 on Ubuntu 10.04 64-bit with Django 1.2.1.

Found so far:

Windows command line utilities that can extract EXE metadata (like filever from SysUtils), or other individual CL utils that only work in Windows. I've tried running these through Wine but they have problems and it hasn't been worth the work to go and find the libs and frameworks that those CL utils depend on and try installing them in Wine/Crossover.

Win32 modules for Python that can do some things but won't run in Linux (right?)

Secondary question:

Obviously changing the file's metadata would change the MD5 hashsum of the file. Is there a general method of hashing a file independent of the metadata besides locating it and reading it in (ex: like skipping the first 1024 byes?)

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

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

发布评论

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

评论(4

雨落星ぅ辰 2024-10-01 03:56:55

看看这个库: http://bitbucket.org/haypo/hachoir/wiki/Home 以及使用该库的示例程序: http://pypi .python.org/pypi/hachoir-metadata/1.3.3。第二个链接是一个示例程序,它使用 Hachoir 二进制文件操作库(第一个链接)来解析元数据。

该库可以处理以下格式:

  • 档案:bzip2、gzip、zip、tar
  • 音频:MPEG 音频(“MP3”)、WAV、Sun/NeXT 音频、Ogg/Vorbis (OGG)、MIDI、AIFF 、AIFC、真实音频 (RA)
  • 图像:BMP、CUR、EMF、ICO、GIF、JPEG、PCX、PNG、TGA、TIFF、WMF、XCF
  • 其他:Torrent
  • 程序:EXE
  • 视频:ASF 格式(WMV 视频)、AVI、 Matroska (MKV)、Quicktime (MOV)、Ogg/Theora、Real media (RM)

此外,Hachoir 可以执行一些文件操作操作,我认为这些操作包括一些原始的元数据操作。

Take a look at this library: http://bitbucket.org/haypo/hachoir/wiki/Home and this example program that uses the library: http://pypi.python.org/pypi/hachoir-metadata/1.3.3. The second link is an example program which uses the Hachoir binary file manipulation library (first link) to parse the metadata.

The library can handle these formats:

  • Archives: bzip2, gzip, zip, tar
  • Audio: MPEG audio ("MP3"), WAV, Sun/NeXT audio, Ogg/Vorbis (OGG), MIDI, AIFF, AIFC, Real audio (RA)
  • Image: BMP, CUR, EMF, ICO, GIF, JPEG, PCX, PNG, TGA, TIFF, WMF, XCF
  • Misc: Torrent
  • Program: EXE
  • Video: ASF format (WMV video), AVI, Matroska (MKV), Quicktime (MOV), Ogg/Theora, Real media (RM)

Additionally, Hachoir can do some file manipulation operations which I would assume includes some primitive metadata manipulation.

萌︼了一个春 2024-10-01 03:56:55

hachoir-元数据获取“产品版本”,但编译器更改“文件版本”。
那么返回的版本就不是我们需要的了。

我发现了一个很好用的小解决方案:

http://pev.sourceforge.net/

我已经测试过成功了。它简单、快速、稳定。

The hachoir-metadata get the "Product Version" but the compilers changes the "File Version".
Then the version returned is not the we need.

I found a small a well working soluction:

http://pev.sourceforge.net/

I've tested with success. It's simple, fast and stable.

枕梦 2024-10-01 03:56:55

要回答您的问题之一,您可以使用 zipfile 模块,特别是 ZipInfo 对象来获取 zip 文件的元数据。

至于仅对文件的数据进行哈希处理,只有知道哪些部分是数据、哪些部分是元数据,才可以这样做。没有通用的方法,因为许多文件格式以不同的方式存储其元数据。

To answer one of your questions, you can use the zipfile module, specifically the ZipInfo object to get the metadata for zip files.

As for hashing only the data of the file, you can only to that if you know which parts are data and which are metadata. There can be no general method as many file formats store their metadata differently.

暮色兮凉城 2024-10-01 03:56:55

回答你的第二个问题:不,没有办法对 PE 文件或 ZIP 文件进行哈希处理,忽略元数据,而不查找和读取元数据。这是因为您感兴趣的元数据存储在文件中的可变位置。

对于 PE 文件(EXE、DLL 等),它存储在资源块中,通常位于文件末尾,文件开头的一系列指针和表给出了位置。

对于 ZIP 文件,它分散在整个存档中 - 每个包含的文件前面都有自己的元数据,最后有一个表给出每个元数据块的位置。但听起来您可能实际上想要读取 ZIP 存档中的文件并在其中查找 EXE(如果您需要程序元数据); ZIP 存档本身不存储公司名称或版本号。

To answer your second question: no, there is no way to hash a PE file or ZIP file, ignoring the metadata, without locating and reading the metadata. This is because the metadata you're interested in is stored at variable locations in the file.

In the case of PE files (EXE, DLL, etc), it's stored in a resource block, typically towards the end of the file, and a series of pointers and tables at the start of the file gives the location.

In the case of ZIP files, it's scattered throughout the archive -- each included file is preceded by its own metadata, and then there's a table at the end giving the locations of each metadata block. But it sounds like you might actually be wanting to read the files within the ZIP archive and look for EXEs in there if you're after program metadata; the ZIP archive itself does not store company names or version numbers.

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