mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 14:01:00 +00:00
refactor(node-sea): share ELF note table scanning (#15644)
This commit is contained in:
1 parent
44fbcfc787
commit
374f392e15
1 file changed
+26
-44
@@ -515,6 +515,30 @@ const locateElfNotes = async (
|
||||
little,
|
||||
frames: Math.floor(carrier.fileSize / ELF_NOTE_HEADER_BYTES),
|
||||
};
|
||||
const scanNote = async (
|
||||
offset: bigint,
|
||||
length: bigint,
|
||||
alignment: bigint,
|
||||
): Promise<void> => {
|
||||
const note = {
|
||||
offset:
|
||||
offset <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(offset) : undefined,
|
||||
length:
|
||||
length <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(length) : undefined,
|
||||
align:
|
||||
alignment <= BigInt(Number.MAX_SAFE_INTEGER)
|
||||
? Number(alignment)
|
||||
: undefined,
|
||||
};
|
||||
const scanned = await scanElfNoteTable(
|
||||
carrier,
|
||||
note,
|
||||
scan,
|
||||
found.length > 0,
|
||||
);
|
||||
if (scanned === undefined) opaque ??= NODE_SEA_ELF_TABLE_TRUNCATED;
|
||||
else for (const range of scanned) found.push(range);
|
||||
};
|
||||
const programs = await readElfTables(carrier, {
|
||||
offset: phoff,
|
||||
count: phnum,
|
||||
@@ -533,28 +557,7 @@ const locateElfNotes = async (
|
||||
if (!parsedProgram.ok) continue;
|
||||
const program = parsedProgram.value;
|
||||
if (program.type !== PT_NOTE) continue;
|
||||
const note = {
|
||||
offset:
|
||||
program.offset <= BigInt(Number.MAX_SAFE_INTEGER)
|
||||
? Number(program.offset)
|
||||
: undefined,
|
||||
length:
|
||||
program.fileSize <= BigInt(Number.MAX_SAFE_INTEGER)
|
||||
? Number(program.fileSize)
|
||||
: undefined,
|
||||
align:
|
||||
program.alignment <= BigInt(Number.MAX_SAFE_INTEGER)
|
||||
? Number(program.alignment)
|
||||
: undefined,
|
||||
};
|
||||
const scanned = await scanElfNoteTable(
|
||||
carrier,
|
||||
note,
|
||||
scan,
|
||||
found.length > 0,
|
||||
);
|
||||
if (scanned === undefined) opaque ??= NODE_SEA_ELF_TABLE_TRUNCATED;
|
||||
else for (const range of scanned) found.push(range);
|
||||
await scanNote(program.offset, program.fileSize, program.alignment);
|
||||
}
|
||||
// The runtime locates the blob through PT_NOTE segments. Injectors can
|
||||
// leave stale or misaligned SHT_NOTE entries, so section notes are only a
|
||||
@@ -589,28 +592,7 @@ const locateElfNotes = async (
|
||||
"Compressed ELF note sections cannot establish raw Node SEA blob offsets";
|
||||
continue;
|
||||
}
|
||||
const note = {
|
||||
offset:
|
||||
section.offset <= BigInt(Number.MAX_SAFE_INTEGER)
|
||||
? Number(section.offset)
|
||||
: undefined,
|
||||
length:
|
||||
section.size <= BigInt(Number.MAX_SAFE_INTEGER)
|
||||
? Number(section.size)
|
||||
: undefined,
|
||||
align:
|
||||
section.alignment <= BigInt(Number.MAX_SAFE_INTEGER)
|
||||
? Number(section.alignment)
|
||||
: undefined,
|
||||
};
|
||||
const scanned = await scanElfNoteTable(
|
||||
carrier,
|
||||
note,
|
||||
scan,
|
||||
found.length > 0,
|
||||
);
|
||||
if (scanned === undefined) opaque ??= NODE_SEA_ELF_TABLE_TRUNCATED;
|
||||
else for (const range of scanned) found.push(range);
|
||||
await scanNote(section.offset, section.size, section.alignment);
|
||||
}
|
||||
if (found.length > 0 && opaque !== undefined) throw formatFailure(opaque);
|
||||
return found;
|
||||
|
||||
Reference in new issue
Block a user