pub struct NameMappings { /* private fields */ }Expand description
The §6.2 mappings object: classes maps a descriptor to the class’s
full new descriptor, fields and methods map a member signature to the
member’s new simple name. Keys use the DEX’s own names throughout, so a
member of a renamed class is still keyed by the old class descriptor. Keys are checked on insertion and
kept sorted, so iteration, serialisation and NameMappings::hash do
not depend on insertion order. The default (empty) value is the identity.
Implementations§
Source§impl NameMappings
impl NameMappings
Sourcepub fn new() -> NameMappings
pub fn new() -> NameMappings
No renames: every name stays as it is.
Sourcepub fn insert_class(
&mut self,
descriptor: &str,
new_descriptor: &str,
) -> Result<Option<String>, MappingError>
pub fn insert_class( &mut self, descriptor: &str, new_descriptor: &str, ) -> Result<Option<String>, MappingError>
Rename the class descriptor to the descriptor new_descriptor
(Lz/c; → Lcom/example/Cart;); returns the name it replaced.
§Errors
MappingError::Class for a bad descriptor,
MappingError::NewClass for a bad new_descriptor.
Sourcepub fn insert_field(
&mut self,
signature: &str,
new_name: &str,
) -> Result<Option<String>, MappingError>
pub fn insert_field( &mut self, signature: &str, new_name: &str, ) -> Result<Option<String>, MappingError>
Rename the field signature (Lowner;->name:Type); returns the name
it replaced.
§Errors
MappingError::Field for a bad signature,
MappingError::NewName for a bad new_name.
Sourcepub fn insert_method(
&mut self,
signature: &str,
new_name: &str,
) -> Result<Option<String>, MappingError>
pub fn insert_method( &mut self, signature: &str, new_name: &str, ) -> Result<Option<String>, MappingError>
Rename the method signature (Lowner;->name(args)Ret); returns the
name it replaced. Constructors and static initialisers keep their
names, so <init> / <clinit> are refused.
§Errors
MappingError::Method for a bad signature or a constructor,
MappingError::NewName for a bad new_name.
Sourcepub fn classes(&self) -> &BTreeMap<String, String>
pub fn classes(&self) -> &BTreeMap<String, String>
Descriptor → new descriptor, sorted by the DEX’s descriptor.
Sourcepub fn fields(&self) -> &BTreeMap<String, String>
pub fn fields(&self) -> &BTreeMap<String, String>
Field signature → new name, sorted by signature.
Sourcepub fn methods(&self) -> &BTreeMap<String, String>
pub fn methods(&self) -> &BTreeMap<String, String>
Method signature → new name, sorted by signature.
Sourcepub fn restricted_to(&self, keep: impl Fn(&str) -> bool) -> NameMappings
pub fn restricted_to(&self, keep: impl Fn(&str) -> bool) -> NameMappings
The entries a request needs: the classes keep accepts and the
members they own. For a slice, keep should accept every class the
slice refers to, not only its targets, since references to renamed
classes and members are renamed in the output too.
Sourcepub fn hash(&self) -> MappingsHash
pub fn hash(&self) -> MappingsHash
The stable hash of the entries: sections in a fixed order, each entry length-prefixed so no two different mappings feed the same bytes.
Source§impl NameMappings
impl NameMappings
Sourcepub fn from_proguard(text: &str) -> Result<ProguardMapping, ProguardError>
pub fn from_proguard(text: &str) -> Result<ProguardMapping, ProguardError>
Parse an R8 / ProGuard mapping file. Only the outermost frame of an R8 inline stack names the method; members that R8 moved in from another class, identity entries and removed classes are skipped silently. Duplicates and unusable names become warnings; only lines that are not mapping syntax at all fail the parse.
§Errors
ProguardError::Syntax for the first line that is not mapping syntax.
Sourcepub fn from_proguard_reader(
reader: impl Read,
) -> Result<ProguardMapping, ProguardError>
pub fn from_proguard_reader( reader: impl Read, ) -> Result<ProguardMapping, ProguardError>
NameMappings::from_proguard on everything reader yields (UTF-8).
§Errors
ProguardError::Io when reading fails or the text is not UTF-8,
plus the errors of NameMappings::from_proguard.
Sourcepub fn from_proguard_file(
path: impl AsRef<Path>,
) -> Result<ProguardMapping, ProguardError>
pub fn from_proguard_file( path: impl AsRef<Path>, ) -> Result<ProguardMapping, ProguardError>
NameMappings::from_proguard on the file at path.
§Errors
ProguardError::File when the file cannot be read or is not UTF-8,
plus the errors of NameMappings::from_proguard.
Trait Implementations§
Source§impl Clone for NameMappings
impl Clone for NameMappings
Source§impl Debug for NameMappings
impl Debug for NameMappings
Source§impl Default for NameMappings
impl Default for NameMappings
impl Eq for NameMappings
Source§impl NameResolver for NameMappings
impl NameResolver for NameMappings
Source§fn class(&self, descriptor: &str) -> Option<&str>
fn class(&self, descriptor: &str) -> Option<&str>
descriptor: Lz/c; →
Lcom/example/Cart;. The package may differ from the DEX’s; for a
nested class the value is the whole binary name (…/Cart$Line;).