Skip to main content

Module serialized

Module serialized 

Source
Expand description

SerializedFile metadata (files/SerializedFile.py:206-360, files/ObjectReader.py:67-130), ported from UnityPy, bytes-native.

Rules ported exactly (plan section 3.7):

  • the header (SerializedFile.py:255-269): the endian byte at offset 16 from format 9, else at file_size - metadata_size (absolute); the format-22 fields replace the legacy u32s;
  • gates (SerializedFile.py:271-288): the version string from format 7, the target platform from 8, enable_type_tree from 13 (else true), big_id_enabled at 7-13;
  • type records (SerializedFile.py:112-149): is_stripped_type from 16, script_type_index from 17 (else -1), script_id and old_type_hash from 13 under UnityPy’s condition, trees only when enable_type_tree, blobs at format 10 and 12 and up; at 21 ref types read three names and plain types a dependency list;
  • objects (ObjectReader.py:73-130): path id as i64 under bigID, i32 below 14, else aligned i64; byte_start u32 (or i64 from 22) plus data_offset; below 16 the type is the first whose class_id equals the object’s type_id, from 16 types[type_id] with Python indexing (a negative id counts from the end; out of range fails the file); at 11-16 the object’s script index is written back into its type, the last object winning; the objects dict keeps a repeated path id at its first position with its last entry;
  • read_string_to_null’s 32,767-byte window for every metadata string;
  • the reader UnityPy reads the file with (crate::stream::ReaderKind): the memory reader for bytes and every entry of a container, the stream reader for a file loaded from a path, whose rules the metadata’s reads and every object read follow (SerializedFile::reader_kind);
  • every table is built with range(count) (SerializedFile.py:282-308): a negative count is zero records, and a table grows record by record, so no count sizes an allocation;
  • with FileContext::eager_asset_bundle, the first AssetBundle in dict order is read at load with check_read, and a failure fails the file (SerializedFile.py:316-324). UnityPy reads it in object mode (parse_as_object); the core reads it in dict mode, and package D’s fixtures pin that the two agree (plan section 3.7).

Memory. Every table (types, their dependency lists and trees, objects, the dict order, scripts, externals, ref types) is built in a crate::limits::MeteredVec on the input’s meter, and the file keeps the charges: two directory rows over the same bytes parse twice and pay twice. Strings are zero-copy slices of the file.

Work. The container read (SerializedFile::container) builds the whole AssetBundle value and keeps only its rows and preload table, so two directory rows over the same bytes would repeat a read whose memory is returned: what the meter granted the read on its own thread, beyond what its Container keeps, counts as the open’s work (crate::error::LimitKind::DecodeWork), and so does all it was granted when it fails with an error its cell keeps. At load, a failure fails the parse, whose grants its bundle counts instead (files::bundle, “Memory and work”), so they count once (round 5).

Owner: package C. The accessors and SerializedType’s constructors and SerializedType::tree are implemented by the scaffold, so package B can build ref types for its tests before C lands.

Structs§

External
One external file reference.
ObjectInfo
One row of the object table.
ScriptRef
One script type reference (LocalSerializedObjectIdentifier).
SerializedFile
A parsed SerializedFile: metadata and object table. Values are read on demand through ObjectRef.
SerializedHeader
The header, as read.
SerializedSaveSnapshot
Caller-owned metadata and object payload snapshot. All retained storage must be charged by the caller before constructing it. Object rows are emitted in supplied order, including repeated path ids; dictionary keys are irrelevant.
SerializedType
A type record (SerializedType), plain or ref type. Not Clone: it lives in its file’s table, which paid for it.