From 8c4d0aecdc65582eecee72ae22e105c1d3728825 Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Fri, 16 Oct 2026 00:06:37 +0900 Subject: [PATCH] fix: parse alternate VS_FIXEDFILEINFO structure --- dzgui/api/pefile.py | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/dzgui/api/pefile.py b/dzgui/api/pefile.py index 7c86987..15e028f 100644 --- a/dzgui/api/pefile.py +++ b/dzgui/api/pefile.py @@ -255,16 +255,28 @@ class PeFileError(Exception): pass + def parse_version_number(data: BinaryIO) -> FileVersion: # https://learn.microsoft.com/en-us/windows/win32/api/verrsrc/ns-verrsrc-vs_fixedfileinfo - minor = struct.unpack("> 16 & 0xFFFF - major = struct.unpack("> 0 & 0xFFFF - build = struct.unpack("> 0 & 0xFFFF - # NOTE: 0-pad revision number - revision = str(struct.unpack("> 16 & 0xFFFF) - offset = 3 - len(revision) - padded = "0" * offset + revision - return FileVersion(major, minor, build, padded) + """ + Note: structure differs from standard VS_FIXEDFILEINFO + Major: lower 16 bits of first DWORD + Minor: upper 16 bits of first DWORD + Build: lower 16 bits of third DWORD + Revision: upper 16 bits of second DWORD, zero-padded + Lower 16 bits of revision DWORD appear unused. + """ + major_minor = struct.unpack("> 16) & 0xFFFF + build = build_dword & 0xFFFF + revision = (revision_pair >> 16) & 0xFFFF + revision = f"{revision:03d}" + + return FileVersion(major, minor, build, revision) def seek_to_hex(address: str, data: BinaryIO) -> None: