mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 19:51:20 -05:00
6f267022ed
* feat(errors)!: add the TargetFailure model, its projection table and conformance registry Introduce one domain-owned TargetFailure value whose kind alone derives the public code, category, retryability, recovery and details, for CLI and MCP alike. Selected-file malformed and truncated refusals are the first area on it: AnalysisMalformedTargetError is replaced by AnalysisTargetFailureError, and ParseFailure's byte-structure variants are TargetFailure variants rather than a parallel type. The shared stableArtifactParserFailureCli loop is replaced by a declarative registry (tests/support/targetFailure/readers/*.ts) and one generated suite that runs every registered case through the CLI and MCP. BREAKING CHANGE: selected-file malformed and truncated refusals add details.failure_kind, and a truncated target's remediation now says to re-acquire the complete file instead of choosing another target. Codes are unchanged. Affected operations: every operation that refuses a selected file's malformed or truncated bytes, including the ELF, PE, Mach-O, DWARF, Go, Rust, BEAM, pyc, devicetree, Apple IPS, kernel module, binary hardening, managed PE/CLI and IL2CPP readers. * test(managed): name the target failure error in the merged status test * docs(reference): name the error CSV instead of linking a non-page file * fix(tests): expect the path reason for non-regular dyld inputs #14225 refuses a non-regular dyld input as ArtifactReaderFailure("path"); dylibFileLifetime still expected "format" and fails on main's shard 9. * fix(tests): expect io, invariant and path where #14225 reclassified stableArtifact expected "format" for an impossible descriptor byte count (now io) and an invalid chunk size (now InternalInvariantError); directoryArtifactReaderOpen expected "format" for a non-file entry (now path, the same change as #14238). All three fail on main. * fix(errors)!: raise container reader byte faults as malformed or truncated targets Delete the ambiguous `format` reason from ArtifactReaderFailure and ArtifactOperationError. Each container reader now raises its owner's fact once, through malformedArtifact / truncatedArtifact, with format, offset, field and measured extents. Short reads inside a measured extent are read-coverage integrity failures, path-kind refusals are `path`, foreign or recovery-requiring inputs are `unsupported`, host tool output is `io`, and REA defects are InternalInvariantError. The trace, NTFS journal, release exposure, web capture, native macOS and web artifact adapters project the reader's parsed facts as AnalysisTargetFailureError instead of invalid_request. Inventory malformed, truncated, unsupported and cancelled reasons take their code from the TargetFailure projection table, so a truncated container is unsupported_target with failure_kind "truncated" on both paths. BREAKING CHANGE: inventory_artifact, inspect_artifact, extract_artifact, analyze_javascript_application, inspect_desktop_application, inspect_keyed_archive, inspect_asset_catalog, inspect_nuget_nupkg, trace_dylib_resolution, trace_web_module_imports and trace_web_source_location report damaged container bytes as unsupported_target (details.reason "malformed" or "truncated", with failure_kind and format) instead of artifact_operation_failed with reason "format", and a truncated container as unsupported_target instead of truncated. inspect_playwright_trace, inspect_ntfs_journal, audit_release_exposure, the web capture inspection operations and the caller-selected import and source maps report damaged selected bytes as unsupported_target instead of invalid_request. The `format` reason no longer appears in details.reason. * test(artifacts): expect target failure codes in compiled CLI and MCP suites * fix(errors): give the integrity kind a schema-valid code and list the reference page artifact_integrity_mismatch's projection schema requires declared and calculated digests, which a TargetFailure of kind integrity does not carry, so the kind now projects artifact_operation_failed with category integrity_mismatch. The model test validates every kind's projection against analysisErrorProjectionSchema. The reference page joins the documentation sidebar. * fix(artifacts): report a short carrier read as a changed file and keep unsupported desktop probes local A Bun or Node SEA short read inside a range already checked against the measured size meant the file changed, not that it was truncated. The carrier range reader and Bun's readExact now raise read-coverage integrity for it, and keep 'outside the file' as the truncated case. DesktopFileInspection records an unsupported managed-metadata probe as a row issue again, so later file checks still run. * test(errors): register PE DOS-signature and truncated IPS refusals and drop their per-command copies The non-MZ PE imports and load-config cases (PE32/PE32+, ZZ and high-bit signatures) and the truncated Apple IPS body move into the conformance registry, which runs them through the CLI and MCP and now also checks that a refusal leaves the selected file unchanged. The per-command tests keep only their valid-image controls. * feat(errors)!: make failure_kind the identifier and derive code and retry from it Apply the owner review on #14239 to the TargetFailure model: - remove details.format_failure; failure_kind is the only identifier; - give integrity, conflict and io their own codes (target_integrity_mismatch, input_conflict, host_io_failed) and derive inventory malformed, truncated and unsupported codes from the same table; - add a retry hint (none, backoff, after_change) derived from the kind, with io refined by its transient errno fact; retryable stays the unchanged-retry flag and is true exactly for backoff; - rename the limit-cut result code and category truncated to partial; - drop cancelled and resource from the target kinds and spell identifiers in American English (unrecognized); - return a target failure a tool handler throws as a projected isError result instead of letting the SDK flatten it to text. BREAKING CHANGE: details.format_failure is removed (read details.failure_kind). The truncated result code and category are now partial. Target integrity failures report target_integrity_mismatch, host read failures host_io_failed and disagreeing inputs input_conflict. Inventory operations (inventory_artifact, inspect_artifact, extract_artifact and the other inventory callers) report truncated container bytes as unsupported_target. Every target failure carries a top-level retry hint. * fix(artifacts): keep changed-file short reads, invalid offsets and EOF declarations apart PyInstaller reads inside the measured size, and .NET bundle manifest refills, now raise read-coverage integrity on a zero-byte read instead of truncated. A .NET bundle field and a Godot PCK directory entry that extend past the file are truncated (with offset and extents) instead of malformed. An absent or invalid ASAR packed offset is malformed; only a valid range past the archive is truncated. The .NET manifest string offset is reported in file coordinates. * fix(artifacts): verify the carrier before blaming a short read on the bytes The NTFS $MFT decoder, positional members (FIT, uImage, Bun, Deno) and .NET bundle members now re-verify the source before reporting a short stream as malformed, so a file that changed during the read reports the change. The truncation site builds the model's measured extent. * docs(android): name unsupported_target for truncated boot image structures * fix(errors)!: report a target that changed during the read as failure_kind changed Inventory integrity failures whose check means the target moved under the read (container, member and unpacked-entry identity, read coverage, traversal coverage) now take the model's changed projection: code artifact_changed, retry backoff and details.failure_kind changed. A selected target that no longer matches the one the session admitted gets its own admitted-identity check and keeps its reopen recovery. BREAKING CHANGE: inventory_artifact, inspect_artifact, extract_artifact and the other inventory operations report a target that changed during the read as artifact_changed (retryable, failure_kind changed) instead of artifact_operation_failed. Admission-identity refusals report integrity_check admitted-identity instead of container-identity. * test(artifacts): expect admitted-identity for selections replaced before admission A selected source replaced before admission fails the admitted-identity check rather than container-identity since the changed/admitted split. * test(go): name the fixture and result when an MZ carrier is not refused through MCP * test(web): expect the partial code for a refused source-map admission The limit-cut code is partial; this Windows-lane test arrived from main with the old truncated spelling. * test(errors): check the MCP target failure as the text clients receive The stdio transport removes the private structured carrier from every isError result, so the conformance suite asserted a field that never reaches clients and failed every case. The projected diagnostic is checked from the JSON text instead. * test(artifacts): expect artifact_changed when selected bytes change after inventory Bundle resources replaced after open and unselected JavaScript sources rewritten after inventory now fail a change check, so they report artifact_changed with retry backoff rather than artifact_operation_failed. * fix(errors): report a session digest mismatch as admitted-identity The digest the session admitted does not change when the same request is repeated, so targetDigestChangedFailure was inviting a backoff retry that fails the same way. It now names admitted-identity, which stays artifact_operation_failed and not retryable, and tells the caller to reopen. Co-authored-by: morluto <morluto@users.noreply.github.com> * fix(artifacts): classify unused PyInstaller compressed input as layout zlib stops at the first complete stream, so a declared span that arrives intact but is not fully consumed is trailing junk or a second stream, not a file that changed. A source that ends before that span stays read-coverage. The cached-carrier test replaces the file with a different size so a shared timestamp cannot hide the rewrite. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(applications): expect unsupported_target for a damaged trace stream A trace member whose CRC fails is a malformed zip target. The partial Evidence assertion now checks that code, failure_kind and format. Co-authored-by: morluto <morluto@users.noreply.github.com> * test(dylib): expect admitted-identity when the opened target is replaced The session keeps the digest it admitted, so replacing the executable and repeating trace_dylib_resolution is not a retryable container change. Co-authored-by: morluto <morluto@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <morluto@users.noreply.github.com>
486 lines
16 KiB
TypeScript
486 lines
16 KiB
TypeScript
import { ArtifactPreparation } from "./ArtifactPreparation.js";
|
|
import { Readable, Transform } from "node:stream";
|
|
import { setImmediate } from "node:timers/promises";
|
|
|
|
import type {
|
|
AndroidOtaPartitionMetadata,
|
|
AndroidOtaPayloadMetadata,
|
|
} from "../domain/formatMetadata/androidAndSystemMetadata.js";
|
|
import { readArtifactFileBytes } from "./ArtifactFileRange.js";
|
|
import {
|
|
assertArtifactReadActive,
|
|
yieldArtifactRead,
|
|
ArtifactEntryContentUnavailable,
|
|
ArtifactReaderFailure,
|
|
copyArtifactEntry,
|
|
malformedArtifact,
|
|
truncatedArtifact,
|
|
assertProducedEntry,
|
|
type ArtifactEntry,
|
|
type ArtifactReader,
|
|
type ArtifactTraversalOptions,
|
|
ArtifactResourceScope,
|
|
ArtifactFileSource,
|
|
} from "../resources/index.js";
|
|
import { ownArtifactStream } from "./OwnedArtifactStream.js";
|
|
import type { StableRegularFileDescriptor } from "../filesystem/RegularFile.js";
|
|
import { ZstandardFrameAllowanceError } from "../domain/compression/zstandardFrameAllowance.js";
|
|
import { ConfigurationError } from "../domain/configurationErrors.js";
|
|
import {
|
|
ANDROID_OTA_HEADER_V2_BYTES,
|
|
androidOtaDistinctOperationDataBytes,
|
|
androidOtaExtractRefusalError,
|
|
androidOtaExtractRefusalLimitation,
|
|
parseAndroidOtaHeader,
|
|
parseAndroidOtaPayload,
|
|
reconstructAndroidOtaPartitionCooperative,
|
|
withAndroidOtaPayloadSignature,
|
|
type AndroidOtaPartition,
|
|
type AndroidOtaPayload,
|
|
type AndroidOtaPayloadParseError,
|
|
type AndroidOtaPayloadReconstructError,
|
|
} from "../domain/firmware/androidOtaPayload.js";
|
|
|
|
const LABEL = "Android OTA payload";
|
|
|
|
type AndroidOtaEntry = ArtifactEntry & {
|
|
readonly partition: AndroidOtaPartition;
|
|
readonly formatMetadata: AndroidOtaPartitionMetadata;
|
|
};
|
|
|
|
/** Inventory a CrAU v2 payload without applying delta operations or verifying signatures. */
|
|
export class AndroidOtaPayloadArtifactReader implements ArtifactReader {
|
|
readonly format = "android-ota-payload" as const;
|
|
readonly #scope = new ArtifactResourceScope();
|
|
readonly #entries = new Map<string, AndroidOtaEntry>();
|
|
readonly #streams = new Set<Readable>();
|
|
readonly #source: ArtifactFileSource;
|
|
readonly #preparation = new ArtifactPreparation();
|
|
#payload: AndroidOtaPayload | undefined;
|
|
#coverageStatus: "complete" | "unknown" = "complete";
|
|
#limitations: string[] = [];
|
|
#closing = false;
|
|
|
|
constructor(path: string, admitted?: StableRegularFileDescriptor) {
|
|
this.#source = new ArtifactFileSource(path, LABEL, admitted);
|
|
}
|
|
|
|
formatMetadata(): AndroidOtaPayloadMetadata | undefined {
|
|
return this.#payload === undefined ? undefined : toMetadata(this.#payload);
|
|
}
|
|
|
|
async prepareContainer(
|
|
expectedSha256: string,
|
|
signal?: AbortSignal,
|
|
): Promise<void> {
|
|
await this.#scope.run(async () => {
|
|
this.#assertOpen(signal);
|
|
await this.#source.bindSha256(expectedSha256, signal);
|
|
});
|
|
}
|
|
|
|
async *entries(
|
|
signal?: AbortSignal,
|
|
options?: ArtifactTraversalOptions,
|
|
): AsyncIterable<ArtifactEntry> {
|
|
await this.#scope.run(async () => {
|
|
this.#assertOpen(signal);
|
|
await this.#preparation.run(
|
|
signal,
|
|
() => this.#prepare(signal),
|
|
() => this.#assertOpen(signal),
|
|
);
|
|
await this.#source.read(signal);
|
|
});
|
|
this.#assertOpen(signal);
|
|
options?.onCoverage?.({
|
|
status: this.#coverageStatus,
|
|
limitations: [...this.#limitations],
|
|
});
|
|
let index = 0;
|
|
for (const entry of this.#entries.values()) {
|
|
if (index % 256 === 0) await setImmediate();
|
|
index += 1;
|
|
this.#assertOpen(signal);
|
|
yield copyArtifactEntry(entry);
|
|
}
|
|
this.#assertOpen(signal);
|
|
}
|
|
|
|
async open(entry: ArtifactEntry, signal?: AbortSignal): Promise<Readable> {
|
|
return this.#scope.run(async () => {
|
|
this.#assertOpen(signal);
|
|
const stored = this.#entries.get(entry.adapterKey);
|
|
assertProducedEntry(
|
|
entry,
|
|
stored,
|
|
"Android OTA partition does not match its owning inventory",
|
|
);
|
|
const { handle, initial } = await this.#source.read(signal);
|
|
this.#assertOpen(signal);
|
|
const refused = androidOtaExtractRefusalError(stored.partition);
|
|
if (refused !== null && stored.partition.extractRefusal !== null)
|
|
throw refusedContent(stored.partition.extractRefusal, refused);
|
|
const payload = this.#payload;
|
|
if (payload === undefined)
|
|
throw new ArtifactReaderFailure(
|
|
"unavailable",
|
|
"Android OTA payload reader has no prepared inventory",
|
|
);
|
|
const operationData = androidOtaDistinctOperationDataBytes(
|
|
stored.partition.operations,
|
|
);
|
|
if (!operationData.ok) throw reconstructFailure(operationData.error);
|
|
const blob = new Map<string, Uint8Array>();
|
|
for (const operation of stored.partition.operations) {
|
|
if (operation.dataLength === 0) continue;
|
|
const key = `${String(operation.dataOffset)}:${String(operation.dataLength)}`;
|
|
if (blob.has(key)) continue;
|
|
blob.set(
|
|
key,
|
|
await readArtifactFileBytes(
|
|
"android-ota-payload",
|
|
handle,
|
|
payload.header.blobOffset + operation.dataOffset,
|
|
operation.dataLength,
|
|
initial.size,
|
|
signal,
|
|
),
|
|
);
|
|
this.#assertOpen(signal);
|
|
}
|
|
await this.#source.read(signal);
|
|
this.#assertOpen(signal);
|
|
const reconstructed = await reconstructAndroidOtaPartitionCooperative(
|
|
stored.partition,
|
|
payload.blockSize,
|
|
(offset, length) =>
|
|
blob.get(`${String(offset)}:${String(length)}`) ?? new Uint8Array(),
|
|
() => yieldArtifactRead(signal),
|
|
// A SHA-256 claim on the entry is checked by the shared scanner under
|
|
// the caller's integrity policy, so record-and-continue can keep the
|
|
// observed bytes. Without that claim the reader checks it here.
|
|
{ verifyDeclaredHash: stored.declaredIntegrity === null },
|
|
);
|
|
if (!reconstructed.ok) throw reconstructFailure(reconstructed.error);
|
|
const cancellationFailure = (reason: unknown): ArtifactReaderFailure =>
|
|
new ArtifactReaderFailure("cancelled", `${LABEL} read cancelled`, {
|
|
cause: reason,
|
|
});
|
|
const image = reconstructed.value;
|
|
const source =
|
|
image.length === 0 ? Readable.from([]) : Readable.from([image]);
|
|
const output = this.#memberStream(stored, image.length, signal);
|
|
ownArtifactStream(source, output, {
|
|
scope: this.#scope,
|
|
streams: this.#streams,
|
|
signal,
|
|
cancellationFailure,
|
|
label: LABEL,
|
|
});
|
|
return output;
|
|
});
|
|
}
|
|
|
|
async close(): Promise<void> {
|
|
this.#closing = true;
|
|
for (const stream of this.#streams)
|
|
stream.destroy(
|
|
new ArtifactReaderFailure("unavailable", `${LABEL} reader closed`),
|
|
);
|
|
await this.#scope.close();
|
|
await this.#source.close();
|
|
this.#entries.clear();
|
|
this.#payload = undefined;
|
|
this.#coverageStatus = "complete";
|
|
this.#limitations = [];
|
|
}
|
|
|
|
provenance(): readonly [] {
|
|
return [];
|
|
}
|
|
|
|
#assertOpen(signal?: AbortSignal): void {
|
|
assertArtifactReadActive(signal);
|
|
if (this.#closing)
|
|
throw new ArtifactReaderFailure("unavailable", `${LABEL} reader closed`);
|
|
}
|
|
|
|
async #prepare(signal?: AbortSignal): Promise<void> {
|
|
const { handle, initial } = await this.#source.read(signal);
|
|
const headerBytes = await readArtifactFileBytes(
|
|
"android-ota-payload",
|
|
handle,
|
|
0,
|
|
Math.min(initial.size, ANDROID_OTA_HEADER_V2_BYTES),
|
|
initial.size,
|
|
signal,
|
|
);
|
|
const header = parseAndroidOtaHeader(headerBytes, initial.size);
|
|
if (!header.ok) throw parseFailure(header.error);
|
|
const { manifestOffset, metadataPrefixEnd } = header.value;
|
|
const metadata = await readArtifactFileBytes(
|
|
"android-ota-payload",
|
|
handle,
|
|
manifestOffset,
|
|
metadataPrefixEnd - manifestOffset,
|
|
initial.size,
|
|
signal,
|
|
);
|
|
const payload = parseAndroidOtaPayload(
|
|
header.value,
|
|
metadata,
|
|
initial.size,
|
|
);
|
|
if (!payload.ok) throw parseFailure(payload.error);
|
|
const signatureRange = payload.value.payloadSignatureRange;
|
|
const payloadSignature =
|
|
signatureRange === null
|
|
? undefined
|
|
: await readArtifactFileBytes(
|
|
"android-ota-payload",
|
|
handle,
|
|
signatureRange.offset,
|
|
signatureRange.bytes,
|
|
initial.size,
|
|
signal,
|
|
);
|
|
await this.#source.read(signal);
|
|
this.#assertOpen(signal);
|
|
const parsed =
|
|
payloadSignature === undefined
|
|
? payload
|
|
: withAndroidOtaPayloadSignature(payload.value, payloadSignature);
|
|
if (parsed.ok) {
|
|
this.#payload = parsed.value;
|
|
this.#coverageStatus = "complete";
|
|
this.#limitations = [...parsed.value.limitations];
|
|
} else {
|
|
if (parsed.error.kind === "limit") throw parseFailure(parsed.error);
|
|
this.#payload = payload.value;
|
|
this.#coverageStatus = "unknown";
|
|
this.#limitations = [
|
|
...payload.value.limitations,
|
|
`Optional trailing payload signature could not be parsed: ${parsed.error.message}`,
|
|
];
|
|
}
|
|
this.#entries.clear();
|
|
for (const partition of this.#payload.partitions) {
|
|
const entry = entryFor(partition);
|
|
this.#entries.set(entry.adapterKey, entry);
|
|
}
|
|
}
|
|
|
|
#memberStream(
|
|
entry: AndroidOtaEntry,
|
|
expectedSize: number,
|
|
signal?: AbortSignal,
|
|
): Transform {
|
|
let bytes = 0;
|
|
const check = async (): Promise<void> => {
|
|
if (bytes !== expectedSize)
|
|
throw formatFailure(`member ended early: ${entry.path}`);
|
|
await this.#source.read(signal);
|
|
};
|
|
return new Transform({
|
|
transform(chunk: Buffer, _encoding, callback) {
|
|
bytes += chunk.length;
|
|
callback(null, chunk);
|
|
},
|
|
flush(callback) {
|
|
void check().then(
|
|
() => callback(),
|
|
(cause: unknown) =>
|
|
callback(
|
|
cause instanceof Error
|
|
? cause
|
|
: new Error("Android OTA payload read failed", { cause }),
|
|
),
|
|
);
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
const FORMAT = "android-ota-payload";
|
|
|
|
const formatFailure = (
|
|
detail: string,
|
|
options?: ErrorOptions,
|
|
): ArtifactReaderFailure =>
|
|
malformedArtifact(FORMAT, `${LABEL} is malformed: ${detail}`, options);
|
|
|
|
const parseFailure = (
|
|
failure: AndroidOtaPayloadParseError,
|
|
): ArtifactReaderFailure => {
|
|
switch (failure.kind) {
|
|
case "limit":
|
|
return new ArtifactReaderFailure("limit", failure.message, {
|
|
boundary: "capacity",
|
|
cause: failure,
|
|
});
|
|
case "unsupported":
|
|
return new ArtifactReaderFailure("unavailable", failure.message, {
|
|
cause: failure,
|
|
});
|
|
case "truncated":
|
|
return truncatedArtifact(FORMAT, failure.message, { cause: failure });
|
|
case "malformed":
|
|
return formatFailure(failure.message, { cause: failure });
|
|
}
|
|
};
|
|
|
|
/**
|
|
* The inventory already recorded why it will not rebuild this partition, so
|
|
* every refusal stays per-member content that is unavailable. Inventory keeps
|
|
* the partition table and the reason instead of failing the whole scan.
|
|
*/
|
|
const refusedContent = (
|
|
refusal: NonNullable<AndroidOtaPartition["extractRefusal"]>,
|
|
failure: AndroidOtaPayloadReconstructError,
|
|
): ArtifactEntryContentUnavailable => {
|
|
const limitation = androidOtaExtractRefusalLimitation(refusal);
|
|
return new ArtifactEntryContentUnavailable(failure.message, limitation, {
|
|
traversal: { status: "unknown", limitations: [limitation] },
|
|
cause: failure,
|
|
});
|
|
};
|
|
|
|
const reconstructFailure = (
|
|
failure: AndroidOtaPayloadReconstructError,
|
|
): ArtifactReaderFailure => {
|
|
if (
|
|
failure._tag === "AndroidOtaPayloadUnsupportedOperation" ||
|
|
failure._tag === "AndroidOtaPayloadBlobTruncated"
|
|
) {
|
|
const limitation = androidOtaExtractRefusalLimitation(
|
|
failure._tag === "AndroidOtaPayloadBlobTruncated"
|
|
? "blob_truncated"
|
|
: "unsupported_operations",
|
|
);
|
|
return new ArtifactEntryContentUnavailable(failure.message, limitation, {
|
|
traversal: { status: "unknown", limitations: [limitation] },
|
|
cause: failure,
|
|
});
|
|
}
|
|
if (failure._tag === "AndroidOtaPayloadIntegrityFailure")
|
|
return new ArtifactReaderFailure("integrity", failure.message, {
|
|
cause: failure,
|
|
integrityCheck: "declared-digest",
|
|
});
|
|
if (failure instanceof ConfigurationError) throw failure;
|
|
if (failure._tag === "ZstandardFrameWorkRefusal")
|
|
throw new ZstandardFrameAllowanceError(
|
|
{ maxFrames: failure.value, source: failure.source },
|
|
failure.offset,
|
|
);
|
|
return parseFailure(failure);
|
|
};
|
|
|
|
const partitionInfo = (info: AndroidOtaPartition["newPartitionInfo"]) => ({
|
|
size: info.size,
|
|
hash_hex: info.hashHex,
|
|
});
|
|
|
|
const entryFor = (partition: AndroidOtaPartition): AndroidOtaEntry => {
|
|
const hash = partition.newPartitionInfo.hashHex;
|
|
const sha256 =
|
|
hash !== null && /^[0-9a-f]{64}$/u.test(hash)
|
|
? ({ algorithm: "sha256", digest: hash } as const)
|
|
: null;
|
|
return {
|
|
path: partition.path,
|
|
kind: "file",
|
|
declaredSize: partition.newPartitionInfo.size,
|
|
compressedSize: partition.totalDataLength,
|
|
executable: false,
|
|
encrypted: false,
|
|
byteOffset: null,
|
|
declaredIntegrity: partition.extractable ? sha256 : null,
|
|
unpacked: false,
|
|
limitations:
|
|
partition.extractRefusal === null
|
|
? []
|
|
: [androidOtaExtractRefusalLimitation(partition.extractRefusal)],
|
|
adapterKey: `android-ota-payload:partition:${String(partition.index)}`,
|
|
formatMetadata: {
|
|
kind: "android-ota-partition",
|
|
index: partition.index,
|
|
name: partition.name,
|
|
extractable: partition.extractable,
|
|
new_partition_info: partitionInfo(partition.newPartitionInfo),
|
|
old_partition_info:
|
|
partition.oldPartitionInfo === null
|
|
? null
|
|
: partitionInfo(partition.oldPartitionInfo),
|
|
version: partition.version,
|
|
run_postinstall: partition.runPostinstall,
|
|
postinstall_path: partition.postinstallPath,
|
|
filesystem_type: partition.filesystemType,
|
|
operation_counts: [...partition.operationCounts],
|
|
total_data_length: partition.totalDataLength,
|
|
merge_operation_count: partition.mergeOperationCount,
|
|
estimate_cow_size: partition.estimateCowSize,
|
|
},
|
|
sourcePath: partition.path,
|
|
partition,
|
|
};
|
|
};
|
|
|
|
const toMetadata = (payload: AndroidOtaPayload): AndroidOtaPayloadMetadata => ({
|
|
kind: "android-ota-payload",
|
|
magic: payload.header.magic,
|
|
major_version: payload.header.majorVersion,
|
|
manifest_size: payload.header.manifestSize,
|
|
metadata_signature_size: payload.header.metadataSignatureSize,
|
|
manifest_offset: payload.header.manifestOffset,
|
|
blob_offset: payload.header.blobOffset,
|
|
block_size: payload.blockSize,
|
|
minor_version: payload.minorVersion,
|
|
payload_kind: payload.payloadKind,
|
|
max_timestamp: payload.maxTimestamp,
|
|
partial_update: payload.partialUpdate,
|
|
security_patch_level: payload.securityPatchLevel,
|
|
signatures_offset: payload.signaturesOffset,
|
|
signatures_size: payload.signaturesSize,
|
|
metadata_signature_blob_size: payload.metadataSignatureBlobSize,
|
|
metadata_signature_count: payload.metadataSignatureCount,
|
|
payload_signature_blob_size: payload.payloadSignatureBlobSize,
|
|
payload_signature_count: payload.payloadSignatureCount,
|
|
signatures_verified: false,
|
|
snapshot_enabled: payload.snapshotEnabled,
|
|
vabc_enabled: payload.vabcEnabled,
|
|
vabc_compression_param: payload.vabcCompressionParam,
|
|
blob_truncated: payload.blobTruncated,
|
|
partitions: payload.partitions.map((partition) => ({
|
|
index: partition.index,
|
|
name: partition.name,
|
|
path: partition.path,
|
|
new_partition_info: partitionInfo(partition.newPartitionInfo),
|
|
old_partition_info:
|
|
partition.oldPartitionInfo === null
|
|
? null
|
|
: partitionInfo(partition.oldPartitionInfo),
|
|
version: partition.version,
|
|
run_postinstall: partition.runPostinstall,
|
|
postinstall_path: partition.postinstallPath,
|
|
filesystem_type: partition.filesystemType,
|
|
operation_counts: [...partition.operationCounts],
|
|
total_data_length: partition.totalDataLength,
|
|
merge_operation_count: partition.mergeOperationCount,
|
|
estimate_cow_size: partition.estimateCowSize,
|
|
extractable: partition.extractable,
|
|
})),
|
|
dynamic_partition_groups: payload.dynamicPartitionGroups.map((group) => ({
|
|
name: group.name,
|
|
size: group.size,
|
|
partition_names: [...group.partitionNames],
|
|
})),
|
|
apex_info: payload.apexInfo.map((apex) => ({
|
|
package_name: apex.packageName,
|
|
version: apex.version,
|
|
is_compressed: apex.isCompressed,
|
|
decompressed_size: apex.decompressedSize,
|
|
})),
|
|
});
|