Skip to main content

NameMappings

Struct NameMappings 

Source
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

Source

pub fn new() -> NameMappings

No renames: every name stays as it is.

Source

pub fn is_empty(&self) -> bool

Whether there are no renames at all.

Source

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.

Source

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.

Source

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.

Source

pub fn classes(&self) -> &BTreeMap<String, String>

Descriptor → new descriptor, sorted by the DEX’s descriptor.

Source

pub fn fields(&self) -> &BTreeMap<String, String>

Field signature → new name, sorted by signature.

Source

pub fn methods(&self) -> &BTreeMap<String, String>

Method signature → new name, sorted by signature.

Source

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.

Source

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

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NameMappings

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for NameMappings

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for NameMappings

Source§

impl NameResolver for NameMappings

Source§

fn class(&self, descriptor: &str) -> Option<&str>

The full new descriptor of the class 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;).
Source§

fn field(&self, signature: &str) -> Option<&str>

The new name of the field Lowner;->name:Type.
Source§

fn method(&self, signature: &str) -> Option<&str>

The new name of the method Lowner;->name(args)Ret.
Source§

impl PartialEq for NameMappings

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for NameMappings

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.