Skip to content

Commit

Permalink
also return the remapped class
Browse files Browse the repository at this point in the history
  • Loading branch information
Swatinem committed Oct 17, 2023
1 parent 7bb58c6 commit 351eeb6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ impl<'s> ProguardMapper<'s> {
/// The `class` argument has to be the fully-qualified obfuscated name of the
/// class, with its complete module prefix.
///
/// The `method` will be resolved if that can be done unambiguously,
/// otherwise `None` is being returned.
pub fn remap_method(&'s self, class: &str, method: &str) -> Option<&'s str> {
/// If the `method` can be resolved unambiguously, it will be returned
/// alongside the remapped `class`, otherwise `None` is being returned.
pub fn remap_method(&'s self, class: &str, method: &str) -> Option<(&'s str, &'s str)> {
let class = self.classes.get(class)?;
let mut members = class.members.get(method)?.iter();
let first = members.next()?;
Expand All @@ -207,7 +207,7 @@ impl<'s> ProguardMapper<'s> {
// We could potentially skip inlined functions here, but lets rather be conservative.
let all_matching = members.all(|member| member.original == first.original);

all_matching.then_some(first.original)
all_matching.then_some((class.original, first.original))
}

/// Remaps a single Stackframe.
Expand Down
11 changes: 7 additions & 4 deletions tests/retrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ fn test_remap_kotlin() {
#[test]
fn test_remap_just_method() {
let mapper = ProguardMapper::from(
r#"com.exmaple.app.MainActivity -> com.exmaple.app.MainActivity:
r#"com.exmaple.app.MainActivity -> a.b.c.d:
com.example1.domain.MyBean myBean -> p
1:1:void <init>():11:11 -> <init>
1:1:void buttonClicked(android.view.View):29:29 -> buttonClicked
Expand All @@ -120,9 +120,12 @@ fn test_remap_just_method() {
2:5:void onCreate(android.os.Bundle):22:25 -> onCreate"#,
);

let unambiguous = mapper.remap_method("com.exmaple.app.MainActivity", "onCreate");
assert_eq!(unambiguous, Some("onCreate"));
let unambiguous = mapper.remap_method("a.b.c.d", "onCreate");
assert_eq!(
unambiguous,
Some(("com.exmaple.app.MainActivity", "onCreate"))
);

let ambiguous = mapper.remap_method("com.exmaple.app.MainActivity", "buttonClicked");
let ambiguous = mapper.remap_method("a.b.c.d", "buttonClicked");
assert_eq!(ambiguous, None);
}

0 comments on commit 351eeb6

Please sign in to comment.