Skip to main content

CabResolver

Trait CabResolver 

Source
pub trait CabResolver:
    Send
    + Sync
    + Debug {
    // Required method
    fn resolve(&self, name: &[u8]) -> Option<Source>;

    // Provided method
    fn find_file(&self, name: &[u8]) -> Result<Option<Source>, Error> { ... }
}
Expand description

Finds a file the registry does not hold, where UnityPy looks in env.path: find_file’s fallback after get_cab (environment.py:310-354), and each load_file(name, True) of a resource read’s fallback (files/SerializedFile.py:330-349).

Required Methods§

Source

fn resolve(&self, name: &[u8]) -> Option<Source>

The source for name, or None when there is none. name is one of three kinds, each as UnityPy passes it on (review round 9: these docs named only the first and the third):

  • find_file’s name (Environment::find_file): for a dereference, the external’s path cleaned as PPtr.deref cleans it (crate::pystr::clean_external_path: a leading archive:/, then assets/, dropped, the last / component kept, lower-cased); for a caller’s own call, the name the caller gave, as it is. UnityPy opens env.path joined with it when that exists; else it takes, from the files a walk of env.path lists, the first whose walked path is the name, else the first whose walked path ends with it, a plain suffix with no separator boundary (beside sub/ab.assets, a root xab.assets answers ab.assets), else the first whose walked path, its basename lower-cased, ends with the name’s simplified name, which it opens by that lower-cased path, so on a case-sensitive file system only a basename all lower case on disk is found that way; a miss raises FileNotFoundError. Its test of the simplified name alone never matches (it compares a bare name with the walk’s full paths). environment.py:326-354; PARITY.md section 3’s Environment.find_file row has the whole account (the walk built once, links, prefixes).
  • In a resource read’s fallback (Environment::resource), first each of the reading file’s externals’ stored path, as it is, not cleaned (archive:/CAB-x/CAB-x, Assets/Level/Thing.asset: files/SerializedFile.py:339-340),
  • then each of its four resource candidates (resource_candidates: the resource path’s basename and the three names made from its stem, helpers/ResourceReader.py:11-18, SerializedFile.py:342-349).

UnityPy’s load_file opens a name of either of the last two kinds as a path when one exists there; else, a relative one, joined to env.path; else the case-insensitive match find_sensitive_path finds under env.path; else nothing (environment.py:110-137).

Provided Methods§

Source

fn find_file(&self, name: &[u8]) -> Result<Option<Source>, Error>

What find_file gets for name (the first kind above), where the registry has no CAB of it: Self::resolve’s source by default, a miss None. UnityPy’s walk answers a miss two ways (environment.py:330-354): None where load_file cannot open the path it matched (a broken link, or a basename it lower-cased, which on a case-sensitive file system names no file), and FileNotFoundError where it matched nothing. A resolver that tells them apart (the bindings’) returns the second as Err(Error::NotFound(NotFound::Cab(name))) (crate::error::NotFound::Cab): Environment::find_file returns it as it is, and a dereference, which raises FileNotFoundError either way (classes/PPtr.py:80-85), fails with DerefError::NotFound, which a container preload skips as UnityPy’s skips every FileNotFoundError. Any other error fails the call that asked. An error returned here is the caller’s code’s, a pool refusal in it counted as it enters the core and retried once, as a fetcher’s is (Fetch::fetch): Environment::find_file, a dereference and the container pass’s preload each evict the other dependencies and ask once more (review round 12: only a dereference did).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§