Skip to content

Commit

Permalink
feat(proguard): add support for android deobfuscation with parameters…
Browse files Browse the repository at this point in the history
… mapping (#1418)

* add support for android deobfuscation with parameters mapping

to be used when we don't have line numbers
  • Loading branch information
viglia authored Mar 27, 2024
1 parent cd9e728 commit 0f6e0c9
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- proguard: Added a mandatory `index` field to `JvmFrame` (#1411) by @loewenheim
- proguard: Support for source contex (#1414) by @loewenheim
- proguard: Field `lineno` on `JvmFrame` is now optional (#1417) by @loewenheim
- proguard: support method deobfuscation based on parameters mapping (#1418) by @viglia

### Dependencies

Expand Down
9 changes: 9 additions & 0 deletions crates/symbolicator-proguard/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ pub struct JvmFrame {
/// When returning frames in a `CompletedJvmSymbolicationResponse`, all frames that were
/// expanded from the frame with index `i` will also have index `i`.
pub index: usize,

/// Comma separated list of method's parameters.
///
/// This has to be set when we want to deobfuscate based on the function parameters
/// instead of using line numbers.
///
/// example of parameters list: `okio.Buffer,long`
#[serde(skip_serializing_if = "Option::is_none")]
pub parameters: Option<String>,
}

/// An exception in a JVM event.
Expand Down
2 changes: 1 addition & 1 deletion crates/symbolicator-proguard/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl ProguardMapper {
pub fn new(byteview: ByteView<'static>) -> Self {
let inner = SelfCell::new(byteview, |data| {
let mapping = proguard::ProguardMapping::new(unsafe { &*data });
let mapper = proguard::ProguardMapper::new(mapping);
let mapper = proguard::ProguardMapper::new_with_param_mapping(mapping, true);
ProguardInner { mapper }
});

Expand Down
22 changes: 18 additions & 4 deletions crates/symbolicator-proguard/src/symbolication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,24 @@ impl ProguardService {
frame: &JvmFrame,
release_package: Option<&str>,
) -> Vec<JvmFrame> {
// First, try to remap the whole frame. This only works if it has a line number.
if let Some(lineno) = frame.lineno {
let proguard_frame =
proguard::StackFrame::new(&frame.module, &frame.function, lineno as usize);
let stack_frame = frame
.lineno
.map(|lineno| {
proguard::StackFrame::new(&frame.module, &frame.function, lineno as usize)
})
.or_else(|| {
frame.parameters.as_ref().map(|params| {
proguard::StackFrame::with_parameters(
&frame.module,
&frame.function,
params.as_str(),
)
})
});

// First, try to remap the whole frame.
// This only works if it has a line number or params.
if let Some(proguard_frame) = stack_frame {
let mut mapped_frames = Vec::new();

for mapper in mappers {
Expand Down

0 comments on commit 0f6e0c9

Please sign in to comment.