readPeVersionResource function

Future<PeVersionResource?> readPeVersionResource(
  1. String filePath
)

Reads the version resource out of a PE image, in pure Dart.

Unlike the version.dll reader this needs no FFI and no Windows host — a PE file can be inspected from any platform — and it finds the resource by type alone, so images whose RT_VERSION entry is stored under a name string (VS_VERSION_INFO, emitted by some windres builds) are readable. The Win32 version APIs look up the numeric id 1 and report those files as carrying no version info at all.

Only the headers and the resource section are read, so pointing this at a large binary does not pull the whole file into memory. The consequence is a narrower reach than parsePeVersionResource: an image that points its version payload at a section other than the one holding the resource directory reads as null here, while the in-memory parser can still follow it. No PE toolchain is known to emit that layout — the loader maps the resource directory and its data as one region — so this trades an unused capability for not reading the file.

An image can carry more than one version resource — several languages under one entry, or several entries. This returns the one Win32 would pick (see selectPeVersionResource); use readPeVersionResources for all of them.

Returns null when filePath is absent, is not a PE image, or has no version resource. Never throws for malformed input.

Implementation

Future<PeVersionResource?> readPeVersionResource(String filePath) async =>
    selectPeVersionResource(await readPeVersionResources(filePath));