Files
reverse-engineering-anything/src/domain/elfSectionHeader.ts
T
morlutoandCursor Agent e504e09aeb fix(elf): keep compressed storage out of decoded metadata facts (#9892)
* fix(elf): keep compressed storage out of decoded metadata facts

* fix(elf): admit compressed string tables the profile does not read

SHF_COMPRESSED string tables are rejected only when they name sections
or symbols. An unreferenced string table is not decoded, so it no longer
makes an otherwise analyzable ELF unsupported.

* fix(elf): keep requirement names when verdef declares no entries

A compressed GNU version-definition section with sh_info 0 has no
definitions to decode. Skipping it leaves requirement names in place
instead of clearing them as an unread compressed table.

* fix(elf): skip empty version requirements before storage reads

* fix(elf): skip empty compressed version-requirement tables

A GNU verneed section with sh_info 0 has no requirement records. Reading
its compressed bytes was a version failure and partial coverage; the
declared count now skips that read.

* fix(mips): distinguish compressed metadata storage (#9959)

* fix(elf): note a missing symbol table only when a relocation needs it

A sectionless image with direct DT_INIT and DT_FINI no longer becomes incomplete solely because DT_SYMTAB does not match a decoded table. The same note remains when a dynamic relocation asks for a symbol.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-11-11 17:21:19 +08:00

35 lines
1.1 KiB
TypeScript

import { err, ok } from "./result.js";
/** Fixed ELF32/ELF64 section declarations; consumers own names, numbering and mapping admission. */
export const readElfSectionHeader = (
bytes: Uint8Array,
bits: 32 | 64,
littleEndian: boolean,
) => {
const wide = bits === 64;
if (bytes.byteLength < (wide ? 64 : 40))
return err({
kind: "malformed" as const,
message: "ELF section header is truncated",
});
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
const word = (at: number): bigint =>
wide
? view.getBigUint64(at, littleEndian)
: BigInt(view.getUint32(at, littleEndian));
const flags = word(8);
return ok({
nameOffset: view.getUint32(0, littleEndian),
type: view.getUint32(4, littleEndian),
flags,
compressed: (flags & 0x800n) !== 0n,
address: word(wide ? 16 : 12),
offset: word(wide ? 24 : 16),
size: word(wide ? 32 : 20),
link: view.getUint32(wide ? 40 : 24, littleEndian),
info: view.getUint32(wide ? 44 : 28, littleEndian),
alignment: word(wide ? 48 : 32),
entrySize: word(wide ? 56 : 36),
});
};