Files
orca/config/scripts/native-build/windows/windows-pe-imports.mjs
Neil 9bd6272fdf refactor(tooling): organize build, CI, and test owners (#38130)
* refactor(tooling): organize test runtime and maintenance owners

* test(tooling): preserve relocated runtime fixture dependency edges

* refactor(tooling): preserve xterm routing owner checks

* ci(tooling): include routing owner in sparse checkout

* test(tooling): preserve copied workflow dependency closures

* fix(tooling): normalize hashed JSON assets in release parity

* fix(tooling): distinguish asset aliases from literal references

* fix(tooling): frame normalized asset reference payloads

* fix(tooling): normalize decoded JSON asset references

* refactor(tooling): organize build, CI and release owners

* fix(tooling): align moved generator and workflow path contracts

* fix(tooling): update generated plugin bundle owner banners

* test(tooling): create relocated mobile verifier fixture directories

* test(tooling): copy headless detector dependency closure

* test(tooling): align native batch policy fixtures with owner path

* fix(tooling): link moved reliability command to historical evidence

* fix(tooling): preserve nested sandbox owners and canonical guide source

* fix(tooling): target release version owners in checkout fixture
2026-11-04 21:08:19 -08:00

54 lines
2.0 KiB
JavaScript

// Read DLL names directly to avoid parser dependency/supply-chain input for one release check.
const IMPORT_DIRECTORY_INDEX = 1
export function readPeImportedDllNames(buffer) {
const peOffset = buffer.readUInt32LE(0x3c)
if (buffer.toString('latin1', peOffset, peOffset + 4) !== 'PE\0\0') {
throw new Error('Not a PE image')
}
const sectionCount = buffer.readUInt16LE(peOffset + 6)
const optionalHeaderSize = buffer.readUInt16LE(peOffset + 20)
const optionalHeader = peOffset + 24
const isPe32Plus = buffer.readUInt16LE(optionalHeader) === 0x20b
const dataDirectories = optionalHeader + (isPe32Plus ? 112 : 96)
const importRva = buffer.readUInt32LE(dataDirectories + IMPORT_DIRECTORY_INDEX * 8)
if (importRva === 0) {
return []
}
const sections = []
for (let index = 0; index < sectionCount; index += 1) {
const header = optionalHeader + optionalHeaderSize + index * 40
sections.push({
virtualAddress: buffer.readUInt32LE(header + 12),
size: Math.max(buffer.readUInt32LE(header + 8), buffer.readUInt32LE(header + 16)),
rawOffset: buffer.readUInt32LE(header + 20)
})
}
const fileOffset = (rva) => {
const section = sections.find(
(candidate) =>
rva >= candidate.virtualAddress && rva < candidate.virtualAddress + candidate.size
)
if (!section) {
throw new Error(`RVA 0x${rva.toString(16)} is outside every section`)
}
return rva - section.virtualAddress + section.rawOffset
}
const names = []
for (let descriptor = fileOffset(importRva); ; descriptor += 20) {
const nameRva = buffer.readUInt32LE(descriptor + 12)
if (nameRva === 0) {
return names
}
const start = fileOffset(nameRva)
names.push(buffer.toString('latin1', start, buffer.indexOf(0, start)))
}
}
// The Visual C++ runtime DLLs ship with the Redistributable, not with Windows.
const DYNAMIC_VC_RUNTIME_RE = /^(?:vcruntime|msvcp|msvcr)\d+(?:_\d+)?\.dll$/i
export function findDynamicVcRuntimeImports(dllNames) {
return dllNames.filter((name) => DYNAMIC_VC_RUNTIME_RE.test(name))
}