Skip to content

armgit / rea

Public Imported from GitHub
0

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

refactor(managed): own successful PE inspection identity

morluto6b44e35bec09
diff --git a/src/dotnet/ManagedMemberInspector.ts b/src/dotnet/ManagedMemberInspector.ts
index 36f6137ba..48c36ff9f 100644
--- a/src/dotnet/ManagedMemberInspector.ts
+++ b/src/dotnet/ManagedMemberInspector.ts
@@ -14,9 +14,9 @@ import {
} from "./ManagedPeReader.js";
import {
readManagedResourceDirectory,
- managedTableRowCounts,
readManagedMetadataInventory,
} from "./ManagedMetadataInventory.js";
+import { managedPeInspectionEnvelope } from "./ManagedPeInspectionEnvelope.js";
import { readManagedMetadataLayout } from "./ManagedMetadataLayout.js";
import {
appendManagedParseIssues,
@@ -286,23 +286,13 @@ export const inspectManagedMembersBytes = (
return managedMemberInspectionSchema.parse(
admitManagedProjection(
{
- artifact: {
- path: target.path,
- sha256: target.sha256,
- byte_length: bytes.length,
- format: "pe",
- },
- module: inventory.module,
- metadata: {
- status: issues.length === 0 ? "complete" : "partial",
- version: layout.version,
- table_row_counts: managedTableRowCounts(layout),
- },
- identity_scope: {
- token_identity: "build-local",
- requires_artifact_sha256: target.sha256,
- requires_mvid: inventory.module?.mvid ?? null,
- },
+ ...managedPeInspectionEnvelope(
+ target,
+ bytes.length,
+ layout,
+ inventory.module,
+ issues,
+ ),
types,
signature_resolution: "type-names-v1",
nesting_read: parsedTypes.nesting.complete,
diff --git a/src/dotnet/ManagedNativeBoundaryHelpers.ts b/src/dotnet/ManagedNativeBoundaryHelpers.ts
index d0d3dd768..12bc15c49 100644
--- a/src/dotnet/ManagedNativeBoundaryHelpers.ts
+++ b/src/dotnet/ManagedNativeBoundaryHelpers.ts
@@ -16,7 +16,7 @@ import {
metadataToken,
readMetadataString,
} from "./ManagedMetadataHeaps.js";
-import { managedTableRowCounts } from "./ManagedMetadataInventory.js";
+import { managedPeInspectionEnvelope } from "./ManagedPeInspectionEnvelope.js";
import type { ManagedMetadataInventory } from "./ManagedMetadataInventory.js";
import {
managedCli32BitRequirement,
@@ -439,23 +439,13 @@ export const buildNativeBoundaryInspection = ({
managedNativeBoundaryInspectionSchema.parse(
admitManagedProjection(
{
- artifact: {
- path: target.path,
- sha256: target.sha256,
- byte_length: bytes.length,
- format: "pe",
- },
- module: inventory.module,
- metadata: {
- status: issues.length === 0 ? "complete" : "partial",
- version: layout.version,
- table_row_counts: managedTableRowCounts(layout),
- },
- identity_scope: {
- token_identity: "build-local",
- requires_artifact_sha256: target.sha256,
- requires_mvid: inventory.module?.mvid ?? null,
- },
+ ...managedPeInspectionEnvelope(
+ target,
+ bytes.length,
+ layout,
+ inventory.module,
+ issues,
+ ),
cli_native: cliNative(pe.cli),
module_refs: moduleRefs,
pinvoke_imports: imports,
diff --git a/src/dotnet/ManagedNativeBoundaryInspector.test.ts b/src/dotnet/ManagedNativeBoundaryInspector.test.ts
index 8be4d882c..4c94548c4 100644
--- a/src/dotnet/ManagedNativeBoundaryInspector.test.ts
+++ b/src/dotnet/ManagedNativeBoundaryInspector.test.ts
@@ -333,6 +333,17 @@ describe("independent managed metadata facets", () => {
]),
});
}
+ expect({
+ artifact: native.artifact,
+ module: native.module,
+ metadata: native.metadata,
+ identity_scope: native.identity_scope,
+ }).toEqual({
+ artifact: members.artifact,
+ module: members.module,
+ metadata: members.metadata,
+ identity_scope: members.identity_scope,
+ });
expect(members.methods[0]?.name).toBe("Main");
expect(native.pinvoke_imports[0]?.import_name).toBe("MessageBoxW");
expect(native.cli_native?.ready_to_run_signature).toBe(true);
diff --git a/src/dotnet/ManagedPeInspectionEnvelope.ts b/src/dotnet/ManagedPeInspectionEnvelope.ts
new file mode 100644
index 000000000..5b8e96e93
--- /dev/null
+++ b/src/dotnet/ManagedPeInspectionEnvelope.ts
@@ -0,0 +1,34 @@
+import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
+import type { ManagedParseIssue } from "../domain/managed/managedArtifact.js";
+import type { ManagedMetadataLayout } from "./ManagedMetadataLayout.js";
+import {
+ managedTableRowCounts,
+ type ManagedMetadataInventory,
+} from "./ManagedMetadataInventory.js";
+
+/** Shared artifact and token identity facts for successful managed PE projections. */
+export const managedPeInspectionEnvelope = (
+ target: BinaryTarget,
+ byteLength: number,
+ layout: ManagedMetadataLayout,
+ module: ManagedMetadataInventory["module"],
+ issues: readonly ManagedParseIssue[],
+) => ({
+ artifact: {
+ path: target.path,
+ sha256: target.sha256,
+ byte_length: byteLength,
+ format: "pe" as const,
+ },
+ module,
+ metadata: {
+ status: issues.length === 0 ? ("complete" as const) : ("partial" as const),
+ version: layout.version,
+ table_row_counts: managedTableRowCounts(layout),
+ },
+ identity_scope: {
+ token_identity: "build-local" as const,
+ requires_artifact_sha256: target.sha256,
+ requires_mvid: module?.mvid ?? null,
+ },
+});