Skip to main content

SerializedFile

Struct SerializedFile 

Source
pub struct SerializedFile { /* private fields */ }
Expand description

A parsed SerializedFile: metadata and object table. Values are read on demand through ObjectRef.

Implementations§

Source§

impl SerializedFile

Source

pub fn get_writeable_cab( &self, name: Option<&RawStr>, ) -> Result<Option<WriteableCab>, SaveError>

Create a resource in the parent bundle/WebFile and append its external. Top-level SerializedFiles have no writable CAB, as in UnityPy.

Source

pub fn get_writeable_cab_with_guid( &self, name: Option<&RawStr>, guid: [u8; 16], ) -> Result<Option<WriteableCab>, SaveError>

The same operation with the last sixteen ASCII bytes of a UUID URN supplied by the caller (the Python binding can pass uuid.uuid1()). This also makes the otherwise nondeterministic GUID replayable.

Source

pub fn writeable_externals(&self) -> Result<MeteredVec<External>, SaveError>

Pending metadata additions. Loaded metadata remains the immutable externals() view, as original object bytes do after set_raw_data.

Source§

impl SerializedFile

Source

pub fn is_changed(&self) -> bool

Whether explicitly marked or an object replacement has been installed.

Source

pub fn mark_changed(&self)

Mark this file and all live parent containers changed.

Source§

impl SerializedFile

Source

pub fn parse( name: RawStr, data: Bytes, parent: Option<Parent>, meter: &Arc<Meter>, ctx: &Arc<FileContext>, ) -> Result<Arc<Self>, Error>

SerializedFile.__init__ over bytes (the memory reader’s rules). Everything it keeps is charged to meter, the input’s.

Source

pub fn parse_with_reader( name: RawStr, data: Bytes, parent: Option<Parent>, meter: &Arc<Meter>, ctx: &Arc<FileContext>, reader: ReaderKind, ) -> Result<Arc<Self>, Error>

Self::parse by the rules of the reader UnityPy would read data with (ReaderKind::Stream for a top-level file loaded from a path), which its objects’ reads follow too.

Source§

impl SerializedFile

Source

pub fn save(&self, options: SaveOptions) -> Result<Bytes, SaveError>

Save metadata and objects, sorting by signed path id and padding every data block to eight bytes. The result owns its meter charge. Saving never clears is_changed or rewrites the loaded reader’s metadata.

Old trees, required pre-v13 trees, and pre-v9’s data offset are corrected under both layouts (Tier C writing). Otherwise UnityPy matches UnityPy 1.25.2’s uncompressed save through format 22 and HEAD 417d595 for formats 23-26. HEAD’s absent per-type node assertion and formats above 26 refuse before building or charging output.

Semantic refuses with a Range collision an output that detection would not reload as a SerializedFile (a bundle signature or gzip magic in the header’s sizes, the brotli marker at 0x20 in metadata or object bytes below format 22); the UnityPy layout writes it unchecked.

Source

pub fn save_with_snapshot( &self, options: SaveOptions, snapshot: &SerializedSaveSnapshot<'_>, ) -> Result<Bytes, SaveError>

Serialize a metered snapshot without modifying the loaded file or edits.

Source§

impl SerializedFile

Source

pub fn occurrence_key(&self) -> (usize, &[usize])

The identity of this file occurrence while it is held. A dependency keeps the same input address and directory path across cache reopens.

Source

pub fn meter(&self) -> &Arc<Meter> ⓘ

The meter of the input it belongs to: what reading its objects charges (crate::walk::ReadCtx::meter).

Source

pub fn name(&self) -> &RawStr

The name it was loaded under.

Source

pub fn data(&self) -> &Bytes

The whole file’s bytes.

Source

pub fn pinned(&self) -> u64

The length of the buffer its bytes are a slice of, which a slice of them keeps alive: its container’s decoded run, or the container’s own bytes’ buffer (Parent::pinned); its own length for a top-level file. A value read from it, and each typetree it parsed, copy their slices out when they would keep much more than themselves alive (crate::pin).

Source

pub fn copies(&self) -> Copies

What its object reads and its parse copied out of the buffer its bytes are a slice of so far (crate::pin; plan section 8, R3).

Source

pub fn constructor_position(&self) -> i128

Final metadata cursor of the constructor’s input reader.

Source

pub fn reader_kind(&self) -> ReaderKind

The reader used for metadata and object reads: stream for paths, otherwise memory (ObjectRef::read_typetree, ObjectRef::raw_data).

Source

pub fn reader_position(&self) -> i128

The shared reader’s position after loading metadata and the eager container.

Source

pub fn header(&self) -> &SerializedHeader

The header.

Source

pub fn unity_version(&self) -> Option<&RawStr>

The version string as read (format 7 and up).

Source

pub fn version(&self) -> Option<&ResolvedVersion>

Chain 2’s result (format 7 and up).

Source

pub fn target_platform(&self) -> Option<i32>

The raw target platform (format 8 and up).

Source

pub fn enable_type_tree(&self) -> bool

Whether type records carry trees.

Source

pub fn big_id_enabled(&self) -> i32

big_id_enabled (formats 7-13, else 0).

Source

pub fn types(&self) -> &[SerializedType]

Type records, in file order, script indexes written back.

Source

pub fn ref_types(&self) -> Option<&[SerializedType]>

Ref types (format 20 and up).

Source

pub fn ref_types_view(&self) -> RefTypes<'_>

The reader’s view of the ref types.

Source

pub fn script_types(&self) -> &[ScriptRef]

Script type references.

Source

pub fn externals(&self) -> &[External]

External file references.

Source

pub fn user_information(&self) -> Option<&RawStr>

userInformation (format 5 and up).

Source

pub fn object_infos(&self) -> &[ObjectInfo]

The object table in file order, repeated path ids kept.

Source

pub fn object_order(&self) -> &[u32]

UnityPy’s objects dict order: indexes into Self::object_infos of each path id’s last entry, at its first position.

Source

pub fn objects(self: &Arc<Self>) -> impl Iterator<Item = ObjectRef> + '_

The objects, in dict order.

Source

pub fn objects_by_path(self: &Arc<Self>) -> impl Iterator<Item = ObjectRef> + '_

The objects in ascending signed path id (UnityPy’s sorted(objects.values(), key=lambda o: o.path_id)): the table Self::object searches, kept and charged with the file, so a caller orders them without a copy or a sort.

Source

pub fn object(self: &Arc<Self>, path_id: i64) -> Option<ObjectRef>

The object objects[path_id] holds.

Source

pub fn container(self: &Arc<Self>) -> Result<&Container, Error>

The container rows of the first AssetBundle in dict order, read once (crate::container::read_container) and published (get_or_publish_result: the read runs outside the cell, and a refused charge is returned, not kept). What the read was granted and its container does not keep is the open’s work (module docs, “Work”).

Source

pub fn parent(&self) -> Option<&Parent>

The container this file is an entry of.

Source

pub fn context(&self) -> &Arc<FileContext> ⓘ

The context it was loaded with.

Trait Implementations§

Source§

impl Debug for SerializedFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.