Files
reverse-engineering-anything/src/domain/firmware/devicetree.fixture.ts
T
morluto 264dcd5fee refactor(artifacts): break the artifacts-firmware and artifacts-gpu import cycles (#11331)
* refactor(domain): move BinaryContainer into src/domain

BinaryContainer imports only domain modules and is shared by artifacts, firmware, gpu, go, il2cpp, python, rust and native. Living under src/native made artifacts and firmware import native for its failure types and BinaryReader. Pure move: git mv plus import specifier updates.

* refactor(firmware): move the devicetree parser into src/domain/firmware

The FIT artifact reader in src/artifacts parses embedded devicetree blobs with the parser that lived under src/firmware, while firmware's providers import src/artifacts: the two units imported each other. The parser and its fixture are pure and now sit beside domain/firmware/devicetree.ts. Pure move: git mv plus import specifier and baseline key updates.

* refactor(artifacts): break the artifacts-gpu import cycle (#11335)

* refactor(artifacts): move the LZ4 block decoder into src/artifacts

Pure move: git mv plus import specifier updates. The next commit removes its GPU-specific budget.

* refactor(artifacts): take the LZ4 output budget from the caller

decodeLz4Block bounded every decode by the GPU object budget and threw through rejectGpu, so UnityFS decoding in src/artifacts imported src/gpu while gpu imports artifacts. Callers now pass their budget: GPU payloads keep GPU_OBJECT_BYTES; UnityFS passes its 64 MiB block bound, which its size checks already enforce before decoding. Malformed blocks still throw BinaryFormatFailure with the same messages.

* test(architecture): drop the artifacts-firmware and artifacts-gpu cycles from the layer baseline

* refactor(artifacts): move the PE resource reader into src/artifacts/pe (#11347)

refactor(artifacts): move the PE resource layout and parser into src/artifacts/pe

The Node SEA and Deno standalone readers in src/artifacts locate PE resources with the layout and parser that lived under src/native/pe, while those modules already read through src/artifacts (ArtifactReaderFailure, assertArtifactReadActive). Pure move: git mv plus import specifier, baseline key and spec path updates.
2026-11-16 03:44:53 +08:00

115 lines
3.2 KiB
TypeScript

/** Small synthetic DTB writer shared by parser and public workflow tests. */
export interface FixtureNode {
name: string;
properties?: Record<string, Buffer>;
/** Written after `properties`, in order, so a name may repeat. */
repeatedProperties?: readonly (readonly [string, Buffer])[];
children?: FixtureNode[];
}
export const cells = (...values: number[]): Buffer => {
const b = Buffer.alloc(values.length * 4);
values.forEach((v, i) => b.writeUInt32BE(v, i * 4));
return b;
};
export const dtString = (value: string): Buffer => Buffer.from(`${value}\0`);
export const devicetreeFixture = (
root: FixtureNode = {
name: "",
properties: {
compatible: dtString("test,board"),
model: dtString("Test board"),
"#address-cells": cells(1),
"#size-cells": cells(1),
},
children: [
{
name: "chosen",
properties: {
bootargs: dtString("console=ttyS0"),
"stdout-path": dtString("serial0"),
},
},
{ name: "aliases", properties: { serial0: dtString("/serial@1000") } },
{
name: "serial@1000",
properties: {
reg: cells(0x1000, 0x100),
phandle: cells(1),
"interrupt-parent": cells(99),
},
},
{ name: "consumer", properties: { "remote-endpoint": cells(1) } },
],
},
version = 17,
): Buffer => {
const names = new Map<string, number>(),
strings: Buffer[] = [],
structure: Buffer[] = [];
let stringBytes = 0;
const padded = (b: Buffer) =>
Buffer.concat([b, Buffer.alloc((4 - (b.length % 4)) % 4)]);
const walk = (node: FixtureNode) => {
structure.push(cells(1), padded(dtString(node.name)));
for (const [name, value] of [
...Object.entries(node.properties ?? {}),
...(node.repeatedProperties ?? []),
]) {
let offset = names.get(name);
if (offset === undefined) {
offset = stringBytes;
names.set(name, offset);
const b = dtString(name);
strings.push(b);
stringBytes += b.length;
}
structure.push(cells(3, value.length, offset), padded(value));
}
node.children?.forEach(walk);
structure.push(cells(2));
};
walk(root);
structure.push(cells(9));
const body = Buffer.concat(structure),
namesBlock = Buffer.concat(strings);
const header = cells(
0xd00dfeed,
72 + body.length + namesBlock.length,
72,
72 + body.length,
40,
version,
16,
0,
namesBlock.length,
body.length,
);
const reservations = Buffer.alloc(32);
reservations.writeBigUInt64BE(0x80000000n, 0);
reservations.writeBigUInt64BE(0x1000n, 8);
return Buffer.concat([header, reservations, body, namesBlock]);
};
/** Minimal valid FDT whose empty strings range starts at the reservation map. */
export const emptyStringsAtReservationBoundaryFixture = (
version: 16 | 17,
): Buffer => {
const bytes = Buffer.alloc(72);
const write = (offset: number, value: number) =>
bytes.writeUInt32BE(value, offset);
write(0, 0xd00dfeed);
write(4, bytes.length);
write(8, 40);
write(12, 56);
write(16, 56);
write(20, version);
write(24, 16);
write(32, 0);
if (version === 17) write(36, 16);
write(40, 1);
write(44, 0);
write(48, 2);
write(52, 9);
return bytes;
};