mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
refactor(elf): read module version CRCs through BinaryReader (#12530)
This commit is contained in:
3 files changed
+19
-7
No files matched your search
@@ -30,7 +30,6 @@
|
||||
"src/native/AppleSwiftDispatchFacets.ts": 1,
|
||||
"src/native/elf/ElfNoteParser.ts": 27,
|
||||
"src/native/elf/ElfUnwindTables.ts": 6,
|
||||
"src/native/elf/KernelModuleParser.ts": 4,
|
||||
"src/native/hardening/ElfHardening.ts": 2,
|
||||
"src/native/initializers/ElfInitializerSymbols.ts": 4,
|
||||
"src/native/initializers/MachoInitializers.ts": 22,
|
||||
|
||||
@@ -478,3 +478,20 @@ it("charges many sections sharing one huge __ksymtab name to the entry budget",
|
||||
expect(report.coverage.examined_entries).toBe(6 + 2 + 1 + 8192);
|
||||
expect(JSON.stringify(report).length).toBeLessThan(2 * 1024 * 1024);
|
||||
});
|
||||
|
||||
it.each([true, false])(
|
||||
"keeps the upper CRC word of each ELF64 version record (little=%s)",
|
||||
(little) => {
|
||||
const versions = Buffer.concat([
|
||||
modversionEntry(0xfedcba9876543210n, "first", 64, little),
|
||||
modversionEntry(0x0100000000000002n, "second", 64, little),
|
||||
]);
|
||||
const report = parse(kernelModuleFixture({ bits: 64, little, versions }));
|
||||
expect(
|
||||
report.versions?.entries.map(({ crc_hex, name }) => [crc_hex, name]),
|
||||
).toEqual([
|
||||
["fedcba9876543210", "first"],
|
||||
["0100000000000002", "second"],
|
||||
]);
|
||||
},
|
||||
);
|
||||
@@ -337,18 +337,14 @@ const parseVersions = (
|
||||
};
|
||||
const nameBytes = bits === 64 ? 56 : 60;
|
||||
const crcBytes = bits === 64 ? 8 : 4;
|
||||
const reader = new BinaryReader(stored, little, "elf");
|
||||
const count = stored.length / entryBytes;
|
||||
exceeds(examined.count + count, maxEntries);
|
||||
const entries: NonNullable<Report["versions"]>["entries"] = [];
|
||||
for (let index = 0; index < count; index += 1) {
|
||||
const start = index * entryBytes;
|
||||
const record = stored.subarray(start, start + entryBytes);
|
||||
const crc =
|
||||
bits === 64
|
||||
? little
|
||||
? record.readBigUInt64LE(0)
|
||||
: record.readBigUInt64BE(0)
|
||||
: BigInt(little ? record.readUInt32LE(0) : record.readUInt32BE(0));
|
||||
const crc = reader.word(start, bits);
|
||||
const nameField = record.subarray(crcBytes, crcBytes + nameBytes);
|
||||
const end = nameField.indexOf(0);
|
||||
entries.push({
|
||||
|
||||
Reference in new issue
Block a user