import assert from 'node:assert/strict'; import test from 'node:test'; import { readPortableExecutableVersionInfo } from './pe-version-info.mjs'; // 真实安装包(dev-win 0.1.154 / release-win 0.1.150)已在本轮用线上对象验证过解析结果; // 这里只守住「非 PE 输入必须失败关闭」这条,避免解析器坏掉时静默返回空身份。 test('rejects buffers that are not PE files', () => { assert.throws( () => readPortableExecutableVersionInfo(Buffer.alloc(128)), /不是 PE 文件/u, ); assert.throws( () => readPortableExecutableVersionInfo('not a buffer'), /需要传入 PE 文件的 Buffer/u, ); }); test('rejects a PE without a version resource', () => { const buffer = Buffer.alloc(512); buffer.writeUInt16LE(0x5a4d, 0); buffer.writeUInt32LE(0x80, 0x3c); buffer.writeUInt32LE(0x00004550, 0x80); buffer.writeUInt16LE(1, 0x84 + 2); buffer.writeUInt16LE(0xe0, 0x84 + 16); buffer.writeUInt16LE(0x10b, 0x98); assert.throws( () => readPortableExecutableVersionInfo(buffer), /没有资源目录|RT_VERSION|属于任何节/u, ); });