mirror of
https://github.com/morluto/rea.git
synced 2026-11-11 17:28:08 +00:00
refactor: consolidate binary artifact interpretation and fixture ownership
Share exact ELF program-header facts across nine consumers while preserving their admission and precision policies. Centralize conformance path and digest binding, retain verifier-specific checks, and route fixture-owner changes to CI qualification.
This commit is contained in:
1 parent
23bc51d5c4
commit
9341b116ef
20 files changed
+484
-144
No files matched your search
@@ -0,0 +1,30 @@
|
||||
import { err, ok } from "./result.js";
|
||||
|
||||
/** Fixed ELF32/ELF64 program declarations; consumers own type, precision and mapping admission. */
|
||||
export const readElfProgramHeader = (
|
||||
bytes: Uint8Array,
|
||||
bits: 32 | 64,
|
||||
littleEndian: boolean,
|
||||
) => {
|
||||
const wide = bits === 64;
|
||||
if (bytes.byteLength < (wide ? 56 : 32))
|
||||
return err({
|
||||
kind: "malformed" as const,
|
||||
message: "ELF program 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));
|
||||
return ok({
|
||||
type: view.getUint32(0, littleEndian),
|
||||
flags: view.getUint32(wide ? 4 : 24, littleEndian),
|
||||
offset: word(wide ? 8 : 4),
|
||||
virtualAddress: word(wide ? 16 : 8),
|
||||
physicalAddress: word(wide ? 24 : 12),
|
||||
fileSize: word(wide ? 32 : 16),
|
||||
memorySize: word(wide ? 40 : 20),
|
||||
alignment: word(wide ? 48 : 28),
|
||||
});
|
||||
};
|
||||
Reference in new issue
Block a user