mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 19:53:50 +00:00
31 lines
1.3 KiB
TypeScript
31 lines
1.3 KiB
TypeScript
import { readManagedMetadataLayout } from "../../src/domain/managed/managedMetadataLayout.js";
|
|
import { buildManagedPeFixture } from "../../src/dotnet/ManagedPe.fixture.js";
|
|
import { readManagedPeLayout } from "../../src/domain/managed/managedPeReader.js";
|
|
import { readTypeDefinitionRowFacts } from "../../src/domain/managed/managedTypeDefinitionRows.js";
|
|
|
|
/** Select TypeDef list coordinates while retaining the fixture's readable member rows. */
|
|
export const managedMemberListStartsFixture = (
|
|
fields: readonly number[],
|
|
methods: readonly number[],
|
|
): Buffer => {
|
|
if (fields.length === 0 || fields.length !== methods.length)
|
|
throw new Error("Each fixture TypeDef needs both list coordinates");
|
|
const bytes = buildManagedPeFixture({
|
|
additionalEmptyTypes: fields.length - 1,
|
|
});
|
|
const pe = readManagedPeLayout(bytes);
|
|
if (pe.cli === null) throw new Error("Fixture omitted CLI metadata");
|
|
const { rva, size } = pe.cli.metadata;
|
|
const layout = readManagedMetadataLayout(
|
|
bytes,
|
|
pe.rvaToOffset(rva, size, "cli.metadata"),
|
|
size,
|
|
);
|
|
for (const [index, field] of fields.entries()) {
|
|
const row = readTypeDefinitionRowFacts(bytes, layout, index + 1);
|
|
bytes.writeUInt16LE(field, row.fieldListOffset);
|
|
bytes.writeUInt16LE(methods[index]!, row.methodListOffset);
|
|
}
|
|
return bytes;
|
|
};
|