Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

1.7 KB
Raw Blame
import { expect, it } from "vitest";
import {
  parseNativeAotPe,
  NATIVE_AOT_MAX_REPORT_BYTES,
} from "./nativeAotPe.js";
import {
  nativeAotPeHeaderIndirectionFixture,
  nativeAotPeOptionalHeaderFixture,
  nativeAotPeDigest,
} from "../../../tests/fixtures/nativeaotPe.js";

it.each([
  { rva: 0x3f8, admitted: true },
  { rva: 0x3fc, admitted: false },
  { rva: 0x400, admitted: false },
])(
  "admits a header-backed TypeManager pointer only when all eight bytes are mapped ($rva)",
  ({ rva, admitted }) => {
    const bytes = nativeAotPeHeaderIndirectionFixture(rva);
    const result = parseNativeAotPe(
      bytes,
      nativeAotPeDigest(bytes),
      NATIVE_AOT_MAX_REPORT_BYTES,
    );
    expect(result.summary.header_address !== null).toBe(admitted);
    if (!admitted)
      expect(result.summary).toMatchObject({
        status: "not_applicable",
        method_tables: 0,
        reason:
          "No supported ReadyToRun directory signature was found in initialized non-executable PE sections.",
      });
  },
);

it.each([
  { optionalBytes: 56, admitted: false },
  { optionalBytes: 64, admitted: true },
])(
  "reads mapping fields only from the declared optional header ($optionalBytes bytes)",
  ({ optionalBytes, admitted }) => {
    const bytes = nativeAotPeOptionalHeaderFixture(optionalBytes);
    const result = parseNativeAotPe(
      bytes,
      nativeAotPeDigest(bytes),
      NATIVE_AOT_MAX_REPORT_BYTES,
    );
    expect(result.summary.header_address !== null).toBe(admitted);
    if (!admitted)
      expect(result.summary).toMatchObject({
        status: "not_applicable",
        method_tables: 0,
        reason: "PE optional header is too short for image mapping fields",
      });
  },
);