/** * The game version of a stock folder (a version without a record in patches/versions/ is only * pointed out, never refused; version-record.ts). * * The version is the file version of win64/aces.exe: the VS_FIXEDFILEINFO block in its version * resource, which Windows shows as "File version" (2.61.0.37 for the target build). */ import { PeImage } from '@wto/exepatch'; /** VS_FIXEDFILEINFO.dwSignature, little-endian. */ const FIXED_FILE_INFO_SIGNATURE = 0xfeef04bd; const RESOURCE_SECTION = '.rsrc'; /** "major.minor.build.revision" from the executable's version resource, or null when it has none. */ export function executableVersion(executable: Uint8Array): string | null { const image = new PeImage(executable); if (!image.sections.some((section) => section.name === RESOURCE_SECTION)) return null; const resources = image.sectionBytes(RESOURCE_SECTION); const view = new DataView(resources.buffer, resources.byteOffset, resources.byteLength); // The fixed file info is 4-byte aligned inside the VS_VERSIONINFO resource; its signature // does not occur elsewhere in practice, and the struct version after it must be 1.0. for (let offset = 0; offset + 16 <= resources.byteLength; offset += 4) { if (view.getUint32(offset, true) !== FIXED_FILE_INFO_SIGNATURE) continue; if (view.getUint32(offset + 4, true) !== 0x00010000) continue; const high = view.getUint32(offset + 8, true); const low = view.getUint32(offset + 12, true); return [high >>> 16, high & 0xffff, low >>> 16, low & 0xffff].join('.'); } return null; }