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§
Sourcefn resolve(&self, name: &[u8]) -> Option<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 asPPtr.derefcleans it (crate::pystr::clean_external_path: a leadingarchive:/, thenassets/, dropped, the last/component kept, lower-cased); for a caller’s own call, the name the caller gave, as it is. UnityPy opensenv.pathjoined with it when that exists; else it takes, from the files a walk ofenv.pathlists, the first whose walked path is the name, else the first whose walked path ends with it, a plain suffix with no separator boundary (besidesub/ab.assets, a rootxab.assetsanswersab.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 raisesFileNotFoundError. 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.mdsection 3’sEnvironment.find_filerow 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§
Sourcefn find_file(&self, name: &[u8]) -> Result<Option<Source>, Error>
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".