fix(apple): preserve archive signatures and metadata byte identity
This commit is contained in:
@@ -11,6 +11,23 @@ import { parseMachoLayout } from "./AppleMachoSelection.js";
|
||||
import { decodeAppleDispatchMetadata } from "./AppleDispatchMetadata.js";
|
||||
|
||||
describe("native Mach-O slice selection", () => {
|
||||
it("preserves high-bit section-name bytes instead of ASCII-folding metadata names", () => {
|
||||
const segment = Buffer.alloc(152);
|
||||
segment.writeUInt32LE(0x19, 0);
|
||||
segment.writeUInt32LE(segment.length, 4);
|
||||
segment.writeUInt32LE(1, 64);
|
||||
// `0xdf` becomes `_` under Buffer's ASCII decoder, falsely producing
|
||||
// the known `__objc_classlist` name from a malformed high-bit byte.
|
||||
Buffer.from("__objc_classlist", "ascii").copy(segment, 72);
|
||||
segment[72] = 0xdf;
|
||||
const layout = parseMachoLayout(
|
||||
Buffer.from(machoImage({ commands: [segment] })),
|
||||
"arm64",
|
||||
);
|
||||
|
||||
expect(layout.sections[0]?.name).toBe("ß_objc_classlist");
|
||||
});
|
||||
|
||||
it("accepts a FAT slice whose table identity and embedded header agree", () => {
|
||||
const fat = fatImage([{ cpu: CPU.arm64, bytes: machoImage({}) }]);
|
||||
expect(parseMachoLayout(Buffer.from(fat), "arm64").segments).toEqual([]);
|
||||
|
||||
@@ -260,7 +260,8 @@ const collectSegment = (
|
||||
state.sections.push({
|
||||
name: bytes
|
||||
.subarray(position, position + 16)
|
||||
.toString("ascii")
|
||||
// ASCII decoding masks high bits and can fabricate known metadata names.
|
||||
.toString("latin1")
|
||||
.replace(/\0.*$/u, ""),
|
||||
address: bytes.readBigUInt64LE(position + 32),
|
||||
size: Number(sectionSize),
|
||||
|
||||
Reference in New Issue
Block a user