mirror of
https://github.com/morluto/rea.git
synced 2026-12-05 19:51:20 -05:00
e78ac1a55b
* feat(artifacts): read UnityFS AssetBundle containers inspect-artifact and extract-artifact now recognize the UnityFS signature and treat format versions 6 through 9 as containers. Header facts (format version, player/engine strings, declared size, dataflags, blocks-info bounds and the declared 16-byte data hash) are retained alongside a directory of CAB-* and .resS members. Member bytes stream on demand: only the blocks covering the requested member are read and decompressed with bounded expansion and cancellation. Bundles declaring asset-bundle encryption keep header facts and report unknown directory coverage. LZMA blocks-info reports unknown coverage; LZMA member reads fail as unavailable while the directory stays readable. Malformed counts, out-of-stream members and declared sizes beyond the file fail as format errors. UnityFS classifies by bytes in root detection, inventory graph construction and desktop inspection, which emits a unityfs-header fact. Validation: tsc --noEmit, oxlint (no new findings on touched files), 17 reader tests covering LZ4HC/uncompressed tables, blocks-info at end, format 6 without padding alignment, multi-block members, malformed input, unsupported compression, cancellation and abandoned streams; full artifacts/domain/conformance suites pass. Verified against one real YooAsset bundle (Unity 2021.3.32f1, format 8, LZ4HC): the streamed SerializedFile contained its managed assembly byte-identical to a UnityPy extraction. Other producer variants unverified. * fix(unityfs): own bounded member reads and preserve partial evidence * refactor(unityfs): clarify producer revision flag decisions * fix(artifacts): preserve coverage authority and bound UnityFS block work --------- Co-authored-by: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com>
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import type { FileHandle } from "node:fs/promises";
|
|
import { ArtifactReaderFailure } from "./ArtifactReader.js";
|
|
import { assertArtifactReadActive } from "./ArtifactFileOperation.js";
|
|
|
|
/** Positional exact reads preserve short-read, cancellation and I/O semantics. */
|
|
export const readArtifactFileBytes = async (
|
|
handle: Pick<FileHandle, "read">,
|
|
position: number,
|
|
length: number,
|
|
end: number,
|
|
signal?: AbortSignal,
|
|
): Promise<Buffer> => {
|
|
if (
|
|
!Number.isSafeInteger(end) ||
|
|
end < 0 ||
|
|
!Number.isSafeInteger(position) ||
|
|
!Number.isSafeInteger(length) ||
|
|
length < 0 ||
|
|
position < 0 ||
|
|
length > end - position
|
|
)
|
|
throw new ArtifactReaderFailure(
|
|
"format",
|
|
"Artifact read exceeds its source range",
|
|
);
|
|
const buffer = Buffer.alloc(length);
|
|
let consumed = 0;
|
|
while (consumed < length) {
|
|
assertArtifactReadActive(signal);
|
|
const { bytesRead } = await handle.read(
|
|
buffer,
|
|
consumed,
|
|
length - consumed,
|
|
position + consumed,
|
|
);
|
|
assertArtifactReadActive(signal);
|
|
if (bytesRead === 0)
|
|
throw new ArtifactReaderFailure("format", "Artifact source is truncated");
|
|
consumed += bytesRead;
|
|
}
|
|
return buffer;
|
|
};
|