Skip to content

Commit

Permalink
ref: refactor rust bindings to support optional parameters for StackF…
Browse files Browse the repository at this point in the history
…rame (#820)

* Refactor rust bindings to support optional parameters for StackFrame
  • Loading branch information
viglia authored Nov 13, 2023
1 parent 9144d60 commit 8e51b6e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 29 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

**Internal**

**Features**

- Add support for `parameters` param in the `remap_frame` to allow deobfuscation when line is not available ([#820](https://github.com/getsentry/symbolic/pull/820))

**Fixes**

## 12.5.0

**Internal**
Expand Down
46 changes: 23 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions py/symbolic/proguard.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@

class JavaStackFrame:
def __init__(
self, class_name: str, method: str, line: int, file: str | None = None
self,
class_name: str,
method: str,
line: int,
file: str | None = None,
parameters: str | None = None,
) -> None:
self.class_name = class_name
self.method = method
self.file = file or None
self.line = line
self.parameters = parameters


class ProguardMapper(RustObject):
Expand Down Expand Up @@ -74,13 +80,16 @@ def remap_method(self, klass: str, method: str) -> Tuple[str, str] | None:

return output if len(output[0]) > 0 and len(output[1]) > 0 else None

def remap_frame(self, klass: str, method: str, line: int) -> list[JavaStackFrame]:
def remap_frame(
self, klass: str, method: str, line: int, parameters: str = ""
) -> list[JavaStackFrame]:
"""Remaps the stackframe, given its class, method and line."""
result = self._methodcall(
lib.symbolic_proguardmapper_remap_frame,
encode_str(klass),
encode_str(method),
line,
encode_str(parameters),
)

frames = []
Expand Down
2 changes: 1 addition & 1 deletion symbolic-cabi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ publish = false
crate-type = ["cdylib"]

[dependencies]
proguard = { version = "5.1.0", features = ["uuid"] }
proguard = { version = "5.3.0", features = ["uuid"] }
sourcemap = "7.0.0"
symbolic = { version = "12.5.0", path = "../symbolic", features = ["cfi", "debuginfo", "sourcemapcache", "symcache"] }
tempfile = "3.4.0"
6 changes: 4 additions & 2 deletions symbolic-cabi/include/symbolic.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef SYMBOLIC_H_INCLUDED
#define SYMBOLIC_H_INCLUDED

/* Generated with cbindgen:0.24.5 */
/* Generated with cbindgen:0.26.0 */

/* Warning, this file is autogenerated. Do not modify this manually. */

Expand Down Expand Up @@ -167,6 +167,7 @@ typedef struct SymbolicJavaStackFrame {
struct SymbolicStr method;
struct SymbolicStr file;
uintptr_t line;
struct SymbolicStr parameters;
} SymbolicJavaStackFrame;

/**
Expand Down Expand Up @@ -512,7 +513,8 @@ void symbolic_proguardmapper_free(struct SymbolicProguardMapper *mapper);
struct SymbolicProguardRemapResult symbolic_proguardmapper_remap_frame(const struct SymbolicProguardMapper *mapper,
const struct SymbolicStr *class_,
const struct SymbolicStr *method,
uintptr_t line);
uintptr_t line,
const struct SymbolicStr *parameters);

/**
* Remaps a class name.
Expand Down
10 changes: 9 additions & 1 deletion symbolic-cabi/src/proguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub struct SymbolicJavaStackFrame {
pub method: SymbolicStr,
pub file: SymbolicStr,
pub line: usize,
pub parameters: SymbolicStr,
}

/// The result of remapping a Stack Frame.
Expand Down Expand Up @@ -80,16 +81,22 @@ ffi_fn! {
class: *const SymbolicStr,
method: *const SymbolicStr,
line: usize,
parameters: *const SymbolicStr,
) -> Result<SymbolicProguardRemapResult> {
let mapper = &SymbolicProguardMapper::as_rust(mapper).inner.get().mapper;
let frame = StackFrame::new((*class).as_str(), (*method).as_str(), line);
let frame = if (*parameters).len > 0 {
StackFrame::with_parameters((*class).as_str(), (*method).as_str(), (*parameters).as_str())
} else {
StackFrame::new((*class).as_str(), (*method).as_str(), line)
};

let mut frames: Vec<_> = mapper.remap_frame(&frame).map(|frame| {
SymbolicJavaStackFrame {
class_name: frame.class().to_owned().into(),
method: frame.method().to_owned().into(),
file: frame.file().unwrap_or("").to_owned().into(),
line: frame.line(),
parameters: frame.parameters().unwrap_or("").to_owned().into(),
}
}).collect();

Expand Down Expand Up @@ -137,6 +144,7 @@ ffi_fn! {
method: remapped_method.to_owned().into(),
file: "".to_owned().into(),
line: 0,
parameters: "".to_owned().into(),
}];

frames.shrink_to_fit();
Expand Down

0 comments on commit 8e51b6e

Please sign in to comment.