mirror of
https://github.com/morluto/rea.git
synced 2026-12-04 10:04:50 +00:00
refactor(elf): decouple structural admission from lane policies and type MIPS limitations (#14356)
Decouple fatal ELF structural/framing checks from optional trailing
section-table range observations via an explicit sectionRanges policy
("strict" | "observe") on validateElfDeclaredRanges, keeping native
section-directory and non-MIPS32 validation strict while making
readMipsElfMetadata reachable for carved MIPS32 ELFs.
Replace untyped string[] limitations on MipsElfMetadata and
MipsElfInspection with the MipsElfLimitation discriminated union
("truncated_section_table" | "unexamined_declarations") so
GhidraMipsProfile switches on typed kinds rather than prose prefixes,
admitting carved recordless legacy MIPS32 ET_EXEC images while keeping
declared-ABI, non-ET_EXEC, PSP, and non-section-truncation limitations
fail-closed.
Closes #14343
This commit is contained in:
1 parent
b6e06169cd
commit
782c274200
9 files changed
+526
-204
No files matched your search
@@ -86,32 +86,56 @@ export type HeaderArchitecture = Exclude<
|
||||
(typeof HEADER_ARCHITECTURE_EXCLUSIONS)[number]
|
||||
>;
|
||||
|
||||
/**
|
||||
* Prefix of the limitation recorded when an optional ELF32 MIPS section header
|
||||
* table extends past the captured file, leaving unread headers unknown.
|
||||
*/
|
||||
export const MIPS_SECTION_TABLE_TRUNCATION_PREFIX =
|
||||
"MIPS section header table at file offset ";
|
||||
/** Typed declaration-inspection limitation; consumers switch on `kind`, never prose. */
|
||||
export type MipsElfLimitation =
|
||||
| {
|
||||
readonly kind: "truncated_section_table";
|
||||
readonly offset: number;
|
||||
readonly examined: number;
|
||||
readonly declared: number;
|
||||
readonly message: string;
|
||||
}
|
||||
| {
|
||||
readonly kind: "unexamined_declarations";
|
||||
readonly message: string;
|
||||
};
|
||||
|
||||
/** Extract human-readable messages from typed MIPS ELF inspection limitations. */
|
||||
export const mipsLimitationMessages = (
|
||||
limitations?: readonly MipsElfLimitation[],
|
||||
): readonly string[] =>
|
||||
(limitations ?? []).map((limitation) => limitation.message);
|
||||
|
||||
const MIPS_ET_EXEC = 2;
|
||||
const MIPS_ARCH_1 = 0x00000000;
|
||||
const MIPS_ARCH_32 = 0x50000000;
|
||||
const MIPS_ARCH_32R2 = 0x70000000;
|
||||
|
||||
/**
|
||||
* True when an ELF32 MIPS header has the recordless legacy ET_EXEC shape
|
||||
* (unspecified ABI, MIPS-I/MIPS32/MIPS32r2, no ASE/machine/FP64/NAN2008/n32/32bitmode flags).
|
||||
* Whether an ELF header has the recordless legacy ELF32 MIPS ET_EXEC shape:
|
||||
* MIPS-I / MIPS32 / MIPS32r2 with unspecified ABI and no ASE, machine,
|
||||
* FP64, NAN2008, n32, or 32bitmode flags. Does not by itself establish lane
|
||||
* admission (ABI flags, GNU attributes, and limitations are checked by the
|
||||
* provider profile).
|
||||
*/
|
||||
export const isRecordlessLegacyMips32Header = (
|
||||
mips: Pick<MipsElfMetadata, "elfClass" | "type" | "flags">,
|
||||
export const isRecordlessLegacyMipsExecHeader = (
|
||||
metadata: ElfFamilyMetadata,
|
||||
): boolean => {
|
||||
const arch = mips.flags & 0xf0000000;
|
||||
const { flags } = metadata;
|
||||
const arch = flags & 0xf0000000;
|
||||
return (
|
||||
mips.elfClass === 32 &&
|
||||
mips.type === 2 &&
|
||||
(arch === 0x00000000 || arch === 0x50000000 || arch === 0x70000000) &&
|
||||
(mips.flags & 0x0f000000) === 0 &&
|
||||
(mips.flags & 0x00ff0000) === 0 &&
|
||||
(mips.flags & 0x0000f000) === 0 &&
|
||||
(mips.flags & 0x20) === 0 &&
|
||||
(mips.flags & 0x40) === 0 &&
|
||||
(mips.flags & 0x100) === 0 &&
|
||||
(mips.flags & 0x600) === 0
|
||||
metadata.elfClass === 32 &&
|
||||
metadata.type === MIPS_ET_EXEC &&
|
||||
(arch === MIPS_ARCH_1 ||
|
||||
arch === MIPS_ARCH_32 ||
|
||||
arch === MIPS_ARCH_32R2) &&
|
||||
(flags & 0x0f000000) === 0 &&
|
||||
(flags & 0x00ff0000) === 0 &&
|
||||
(flags & 0x0000f000) === 0 &&
|
||||
(flags & 0x20) === 0 &&
|
||||
(flags & 0x40) === 0 &&
|
||||
(flags & 0x100) === 0 &&
|
||||
(flags & 0x600) === 0
|
||||
);
|
||||
};
|
||||
|
||||
@@ -122,7 +146,7 @@ export interface MipsElfMetadata extends ElfFamilyMetadata {
|
||||
/** Undefined until inspected; null means no GNU attribute section was observed. */
|
||||
readonly gnuAttributes?: MipsGnuAttributes | null;
|
||||
/** Unavailable declaration sources; missing records there remain unknown. */
|
||||
readonly limitations?: readonly string[];
|
||||
readonly limitations?: readonly MipsElfLimitation[];
|
||||
/** Complete dynamic REL declarations, or the reason they could not be inspected. */
|
||||
readonly sharedLoad?:
|
||||
| {
|
||||
|
||||
Reference in new issue
Block a user