mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 14:59:05 +00:00
refactor(elf): reuse classified note types for descriptor decoding (#17304)
This commit is contained in:
1 parent
5601f32cce
commit
334e65a8cb
1 file changed
+23
-30
@@ -23,6 +23,7 @@ import {
|
||||
} from "../../domain/native/elfNoteLayout.js";
|
||||
import type {
|
||||
ElfNotes,
|
||||
ElfNoteTypeName,
|
||||
InspectElfNotesInput,
|
||||
} from "../../domain/native/elfNotes.js";
|
||||
import {
|
||||
@@ -248,14 +249,14 @@ const parseNoteStreamFromTable = (
|
||||
|
||||
const decodeGnu = (
|
||||
owner: string,
|
||||
type: number,
|
||||
typeName: ElfNoteTypeName,
|
||||
descriptor: Buffer,
|
||||
descriptorOffset: number,
|
||||
little: boolean,
|
||||
text: TextBudget,
|
||||
): ElfNotes["entries"][number]["gnu"] => {
|
||||
if (owner !== "GNU") return null;
|
||||
if (type === 3 && descriptor.length > 0) {
|
||||
if (typeName === "gnu_build_id" && descriptor.length > 0) {
|
||||
chargeText(text, descriptor.length * 2);
|
||||
return {
|
||||
build_id_hex: descriptor.toString("hex"),
|
||||
@@ -263,7 +264,7 @@ const decodeGnu = (
|
||||
gold_version: null,
|
||||
};
|
||||
}
|
||||
if (type === 1 && descriptor.length === 16) {
|
||||
if (typeName === "gnu_abi_tag" && descriptor.length === 16) {
|
||||
const reader = new BinaryReader(descriptor, little, "elf-notes");
|
||||
const os = reader.u32(0);
|
||||
return {
|
||||
@@ -278,7 +279,7 @@ const decodeGnu = (
|
||||
gold_version: null,
|
||||
};
|
||||
}
|
||||
if (type === 4) {
|
||||
if (typeName === "gnu_gold_version") {
|
||||
const range = `${String(descriptorOffset)}:${String(descriptor.length)}`;
|
||||
let end = text.scans.get(range);
|
||||
if (end === undefined) {
|
||||
@@ -626,8 +627,7 @@ const decodeCoreAuxv = (
|
||||
};
|
||||
|
||||
const decodeCore = (
|
||||
owner: string,
|
||||
type: number,
|
||||
typeName: ElfNoteTypeName,
|
||||
descriptor: Buffer,
|
||||
descriptorOffset: number,
|
||||
little: boolean,
|
||||
@@ -635,14 +635,13 @@ const decodeCore = (
|
||||
machine: number,
|
||||
text: TextBudget,
|
||||
): ElfNotes["entries"][number]["core"] => {
|
||||
if (owner !== "CORE") return null;
|
||||
if (type === 3)
|
||||
if (typeName === "core_prpsinfo")
|
||||
return decodeCorePrpsinfo(descriptor, little, bits === 64, machine, text);
|
||||
if (type === 0x46494c45)
|
||||
if (typeName === "core_file")
|
||||
return decodeCoreFile(descriptor, descriptorOffset, little, bits, text);
|
||||
if (type === 0x53494749)
|
||||
if (typeName === "core_siginfo")
|
||||
return decodeCoreSiginfo(descriptor, little, machine);
|
||||
if (type === 6)
|
||||
if (typeName === "core_auxv")
|
||||
return decodeCoreAuxv(descriptor, descriptorOffset, little, bits, text);
|
||||
return null;
|
||||
};
|
||||
@@ -725,14 +724,13 @@ const scanAndroidIdentSlot = (descriptor: Buffer, start: number): number => {
|
||||
};
|
||||
|
||||
const decodeAndroid = (
|
||||
owner: string,
|
||||
type: number,
|
||||
typeName: ElfNoteTypeName,
|
||||
descriptor: Buffer,
|
||||
descriptorOffset: number,
|
||||
little: boolean,
|
||||
text: TextBudget,
|
||||
): ElfNotes["entries"][number]["android"] => {
|
||||
if (owner !== "Android" || type !== 1) return null;
|
||||
if (typeName !== "android_ident") return null;
|
||||
const reader = new BinaryReader(descriptor, little, "elf-notes");
|
||||
if (descriptor.length === 4) {
|
||||
return {
|
||||
@@ -1271,7 +1269,6 @@ const toEntry = (
|
||||
const little = header.byteOrder === "little";
|
||||
const linuxCore = isLinuxCoreProfile(header);
|
||||
const typeName = elfNoteTypeName(note.owner, note.type, linuxCore);
|
||||
const coreOwner = note.owner === "CORE" && linuxCore;
|
||||
const range = `${String(note.descriptor_offset)}:${String(note.descsz)}`;
|
||||
let digest = text.hashes.get(range);
|
||||
if (digest === undefined) {
|
||||
@@ -1300,27 +1297,23 @@ const toEntry = (
|
||||
},
|
||||
gnu: decodeGnu(
|
||||
note.owner,
|
||||
note.type,
|
||||
typeName,
|
||||
note.descriptor,
|
||||
note.descriptor_offset,
|
||||
little,
|
||||
text,
|
||||
),
|
||||
core: coreOwner
|
||||
? decodeCore(
|
||||
note.owner,
|
||||
note.type,
|
||||
note.descriptor,
|
||||
note.descriptor_offset,
|
||||
little,
|
||||
header.elfClass,
|
||||
header.machine,
|
||||
text,
|
||||
)
|
||||
: null,
|
||||
core: decodeCore(
|
||||
typeName,
|
||||
note.descriptor,
|
||||
note.descriptor_offset,
|
||||
little,
|
||||
header.elfClass,
|
||||
header.machine,
|
||||
text,
|
||||
),
|
||||
android: decodeAndroid(
|
||||
note.owner,
|
||||
note.type,
|
||||
typeName,
|
||||
note.descriptor,
|
||||
note.descriptor_offset,
|
||||
little,
|
||||
|
||||
Reference in new issue
Block a user