mirror of
https://github.com/morluto/rea.git
synced 2026-11-29 18:06:46 +00:00
refactor(evidence): share PE inspection provenance (#14428)
This commit is contained in:
1 parent
7676a386a1
commit
08cfbf88cb
7 files changed
+85
-146
No files matched your search
@@ -2,13 +2,13 @@ import { insideArtifact } from "./artifactRange.js";
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import type { PeCertificatesPort } from "../../ports/binaryDiagnostics/PeCertificatesPort.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import {
|
||||
inspectPeCertificatesInputSchema,
|
||||
peCertificatesSchema,
|
||||
type PeCertificates,
|
||||
} from "../../domain/native/peCertificates.js";
|
||||
import { peSubjectArchitecture } from "../../domain/peMachine.js";
|
||||
import { observedPeEvidence } from "./observedPeEvidence.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import { executeArtifactInspection } from "../ArtifactInspectionExecution.js";
|
||||
|
||||
@@ -38,42 +38,23 @@ export class PeCertificatesService {
|
||||
validateReport: (report, parameters) =>
|
||||
report.artifact.path === parameters.path &&
|
||||
validReport(report, parameters.max_entries),
|
||||
buildEvidence: (value, identity, parameters) => {
|
||||
const architecture = peSubjectArchitecture(
|
||||
value.machine,
|
||||
value.format,
|
||||
);
|
||||
const locations = [
|
||||
{ kind: "artifact-path" as const, path: value.artifact.path },
|
||||
...(value.table === null
|
||||
buildEvidence: (value, identity, parameters) =>
|
||||
observedPeEvidence(
|
||||
value,
|
||||
identity,
|
||||
OPERATION,
|
||||
parameters,
|
||||
value.table === null
|
||||
? []
|
||||
: [
|
||||
{
|
||||
kind: "file-offset-range" as const,
|
||||
kind: "file-offset-range",
|
||||
start: value.table.location.offset,
|
||||
end:
|
||||
value.table.location.offset + value.table.location.bytes,
|
||||
},
|
||||
]),
|
||||
];
|
||||
return createEvidence(
|
||||
{
|
||||
path: value.artifact.path,
|
||||
format: "pe",
|
||||
sha256: value.artifact.sha256,
|
||||
...(architecture === undefined ? {} : { architecture }),
|
||||
},
|
||||
identity,
|
||||
{
|
||||
operation: OPERATION,
|
||||
parameters,
|
||||
result: value,
|
||||
confidence: "observed",
|
||||
limitations: value.limitations,
|
||||
locations,
|
||||
},
|
||||
);
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
rawInput,
|
||||
options,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { insideArtifact } from "./artifactRange.js";
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import type { PeImportsPort } from "../../ports/binaryDiagnostics/PeImportsPort.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import {
|
||||
inspectPeImportsInputSchema,
|
||||
peImportsSchema,
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
type PeImports,
|
||||
} from "../../domain/native/peImports.js";
|
||||
import { peVa } from "../../domain/native/peAddressSpace.js";
|
||||
import { peSubjectArchitecture } from "../../domain/peMachine.js";
|
||||
import { observedPeEvidence } from "./observedPeEvidence.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import { executeArtifactInspection } from "../ArtifactInspectionExecution.js";
|
||||
|
||||
@@ -39,33 +39,11 @@ export class PeImportsService {
|
||||
toParameters: (input) => input,
|
||||
validateReport: (report, input) =>
|
||||
report.artifact.path === input.path && validReport(report, input),
|
||||
buildEvidence: (value, identity, parameters) => {
|
||||
const architecture = peSubjectArchitecture(
|
||||
value.machine,
|
||||
value.format,
|
||||
);
|
||||
return createEvidence(
|
||||
{
|
||||
path: value.artifact.path,
|
||||
format: "pe",
|
||||
sha256: value.artifact.sha256,
|
||||
...(architecture === undefined ? {} : { architecture }),
|
||||
},
|
||||
identity,
|
||||
{
|
||||
operation: OPERATION,
|
||||
parameters,
|
||||
result: value,
|
||||
confidence: "observed",
|
||||
limitations: value.limitations,
|
||||
locations: [
|
||||
{ kind: "artifact-path" as const, path: value.artifact.path },
|
||||
...fileRange(value.import_directory),
|
||||
...fileRange(value.delay_import_directory),
|
||||
],
|
||||
},
|
||||
);
|
||||
},
|
||||
buildEvidence: (value, identity, parameters) =>
|
||||
observedPeEvidence(value, identity, OPERATION, parameters, [
|
||||
...fileRange(value.import_directory),
|
||||
...fileRange(value.delay_import_directory),
|
||||
]),
|
||||
},
|
||||
rawInput,
|
||||
options,
|
||||
|
||||
@@ -2,13 +2,13 @@ import { insideArtifact } from "./artifactRange.js";
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import type { PeLoadConfigPort } from "../../ports/binaryDiagnostics/PeLoadConfigPort.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import {
|
||||
inspectPeLoadConfigInputSchema,
|
||||
peLoadConfigSchema,
|
||||
type PeLoadConfig,
|
||||
} from "../../domain/native/peLoadConfig.js";
|
||||
import { peSubjectArchitecture } from "../../domain/peMachine.js";
|
||||
import { observedPeEvidence } from "./observedPeEvidence.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import { executeArtifactInspection } from "../ArtifactInspectionExecution.js";
|
||||
|
||||
@@ -38,13 +38,8 @@ export class PeLoadConfigService {
|
||||
validateReport: (report, parameters) =>
|
||||
report.artifact.path === parameters.path &&
|
||||
validReport(report, parameters),
|
||||
buildEvidence: (value, identity, parameters) => {
|
||||
const architecture = peSubjectArchitecture(
|
||||
value.machine,
|
||||
value.format,
|
||||
);
|
||||
const locations = [
|
||||
{ kind: "artifact-path" as const, path: value.artifact.path },
|
||||
buildEvidence: (value, identity, parameters) =>
|
||||
observedPeEvidence(value, identity, OPERATION, parameters, [
|
||||
...fileRange(value.tls?.directory ?? null),
|
||||
...fileRange(value.load_config?.directory ?? null),
|
||||
...structureRange(value.load_config),
|
||||
@@ -56,25 +51,7 @@ export class PeLoadConfigService {
|
||||
end: offset + bytes,
|
||||
}),
|
||||
),
|
||||
];
|
||||
return createEvidence(
|
||||
{
|
||||
path: value.artifact.path,
|
||||
format: "pe",
|
||||
sha256: value.artifact.sha256,
|
||||
...(architecture === undefined ? {} : { architecture }),
|
||||
},
|
||||
identity,
|
||||
{
|
||||
operation: OPERATION,
|
||||
parameters,
|
||||
result: value,
|
||||
confidence: "observed",
|
||||
limitations: value.limitations,
|
||||
locations,
|
||||
},
|
||||
);
|
||||
},
|
||||
]),
|
||||
},
|
||||
rawInput,
|
||||
options,
|
||||
|
||||
@@ -2,14 +2,14 @@ import { insideArtifact } from "./artifactRange.js";
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import type { PeResourcesPort } from "../../ports/binaryDiagnostics/PeResourcesPort.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import {
|
||||
inspectPeResourcesInputSchema,
|
||||
peResourcesSchema,
|
||||
type PeResources,
|
||||
type PeResourceIdentity,
|
||||
} from "../../domain/native/peResources.js";
|
||||
import { peSubjectArchitecture } from "../../domain/peMachine.js";
|
||||
import { observedPeEvidence } from "./observedPeEvidence.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import { executeArtifactInspection } from "../ArtifactInspectionExecution.js";
|
||||
|
||||
@@ -39,29 +39,8 @@ export class PeResourcesService {
|
||||
validateReport: (report, parameters) =>
|
||||
report.artifact.path === parameters.path &&
|
||||
validReport(report, parameters.max_entries),
|
||||
buildEvidence: (value, identity, parameters) => {
|
||||
const architecture = peSubjectArchitecture(
|
||||
value.machine,
|
||||
value.format,
|
||||
);
|
||||
return createEvidence(
|
||||
{
|
||||
path: value.artifact.path,
|
||||
format: "pe",
|
||||
sha256: value.artifact.sha256,
|
||||
...(architecture === undefined ? {} : { architecture }),
|
||||
},
|
||||
identity,
|
||||
{
|
||||
operation: OPERATION,
|
||||
parameters,
|
||||
result: value,
|
||||
confidence: "observed",
|
||||
limitations: value.limitations,
|
||||
locations: [{ kind: "artifact-path", path: value.artifact.path }],
|
||||
},
|
||||
);
|
||||
},
|
||||
buildEvidence: (value, identity, parameters) =>
|
||||
observedPeEvidence(value, identity, OPERATION, parameters),
|
||||
},
|
||||
rawInput,
|
||||
options,
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import type { ExecutionOptions } from "../../ports/AnalysisProvider.js";
|
||||
import type { PeUnwindRangesPort } from "../../ports/binaryDiagnostics/PeUnwindRangesPort.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import { createEvidence, type Evidence } from "../../domain/evidence.js";
|
||||
import type { Evidence } from "../../domain/evidence.js";
|
||||
import {
|
||||
inspectPeUnwindRangesInputSchema,
|
||||
peUnwindRangesSchema,
|
||||
type InspectPeUnwindRangesInput,
|
||||
type PeUnwindRanges,
|
||||
} from "../../domain/native/peUnwindRanges.js";
|
||||
import { peSubjectArchitecture } from "../../domain/peMachine.js";
|
||||
import { observedPeEvidence } from "./observedPeEvidence.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import { executeArtifactInspection } from "../ArtifactInspectionExecution.js";
|
||||
|
||||
@@ -40,39 +40,21 @@ export class PeUnwindRangesService {
|
||||
report.artifact.path === parameters.path &&
|
||||
validReport(report, parameters),
|
||||
buildEvidence: (value, identity, parameters) => {
|
||||
const architecture = peSubjectArchitecture(
|
||||
value.machine,
|
||||
value.format,
|
||||
);
|
||||
const directory = value.exception_directory;
|
||||
const locations = [
|
||||
{ kind: "artifact-path" as const, path: value.artifact.path },
|
||||
...(directory.file_offset === null || directory.size === null
|
||||
return observedPeEvidence(
|
||||
value,
|
||||
identity,
|
||||
OPERATION,
|
||||
parameters,
|
||||
directory.file_offset === null || directory.size === null
|
||||
? []
|
||||
: [
|
||||
{
|
||||
kind: "file-offset-range" as const,
|
||||
kind: "file-offset-range",
|
||||
start: directory.file_offset,
|
||||
end: directory.file_offset + directory.size,
|
||||
},
|
||||
]),
|
||||
];
|
||||
return createEvidence(
|
||||
{
|
||||
path: value.artifact.path,
|
||||
format: "pe",
|
||||
sha256: value.artifact.sha256,
|
||||
...(architecture === undefined ? {} : { architecture }),
|
||||
},
|
||||
identity,
|
||||
{
|
||||
operation: OPERATION,
|
||||
parameters,
|
||||
result: value,
|
||||
confidence: "observed",
|
||||
limitations: value.limitations,
|
||||
locations,
|
||||
},
|
||||
],
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import type {
|
||||
Evidence,
|
||||
EvidenceLocation,
|
||||
EvidenceProvider,
|
||||
} from "../../domain/evidence.js";
|
||||
import { peSubjectArchitecture } from "../../domain/peMachine.js";
|
||||
import {
|
||||
observedFileEvidence,
|
||||
type FileInspectionReport,
|
||||
} from "../observedFileEvidence.js";
|
||||
|
||||
/** Bind a PE observation to the architecture supported by its machine and optional header. */
|
||||
export const observedPeEvidence = (
|
||||
report: FileInspectionReport & {
|
||||
readonly machine: number;
|
||||
readonly format: "pe32" | "pe32-plus";
|
||||
},
|
||||
provider: EvidenceProvider,
|
||||
operation: string,
|
||||
parameters: unknown,
|
||||
locations: readonly EvidenceLocation[] = [],
|
||||
): Evidence => {
|
||||
const architecture = peSubjectArchitecture(report.machine, report.format);
|
||||
return observedFileEvidence(
|
||||
report,
|
||||
provider,
|
||||
operation,
|
||||
parameters,
|
||||
locations,
|
||||
{
|
||||
format: "pe",
|
||||
...(architecture === undefined ? {} : { architecture }),
|
||||
},
|
||||
);
|
||||
};
|
||||
@@ -3,23 +3,30 @@ import {
|
||||
type Evidence,
|
||||
type EvidenceLocation,
|
||||
type EvidenceProvider,
|
||||
type EvidenceSubjectTarget,
|
||||
} from "../domain/evidence.js";
|
||||
|
||||
/** Report fields shared by file inspection Evidence producers. */
|
||||
export interface FileInspectionReport {
|
||||
readonly artifact: { readonly path: string; readonly sha256: string };
|
||||
readonly limitations: readonly string[];
|
||||
}
|
||||
|
||||
/** Bind a file inspection to its reported bytes and ordered source locations. */
|
||||
export const observedFileEvidence = (
|
||||
report: {
|
||||
readonly artifact: { readonly path: string; readonly sha256: string };
|
||||
readonly limitations: readonly string[];
|
||||
},
|
||||
report: FileInspectionReport,
|
||||
provider: EvidenceProvider,
|
||||
operation: string,
|
||||
parameters: unknown,
|
||||
additionalLocations: readonly EvidenceLocation[] = [],
|
||||
subject: Pick<EvidenceSubjectTarget, "format" | "architecture"> = {
|
||||
format: "file",
|
||||
},
|
||||
): Evidence =>
|
||||
createEvidence(
|
||||
{
|
||||
...subject,
|
||||
path: report.artifact.path,
|
||||
format: "file",
|
||||
sha256: report.artifact.sha256,
|
||||
},
|
||||
provider,
|
||||
|
||||
Reference in new issue
Block a user