From 85793bacfc11b2842b65221ff941db8888a87b80 Mon Sep 17 00:00:00 2001 From: Arpad Borsos Date: Mon, 8 Jul 2024 10:59:06 +0200 Subject: [PATCH] Remove Proguard bindings These were originally created to eventually replace the symbolic proguard mappings with these. But we instead moved all that to Rust instead. --- Cargo.lock | 20 ------- bindings/Cargo.toml | 1 - bindings/src/lib.rs | 3 - bindings/src/proguard.rs | 99 -------------------------------- python/sentry_ophio/proguard.py | 4 -- python/sentry_ophio/proguard.pyi | 21 ------- tests/conftest.py | 9 --- tests/fixtures/proguard.txt | 35 ----------- tests/test_proguard.py | 36 ------------ 9 files changed, 228 deletions(-) delete mode 100644 bindings/src/proguard.rs delete mode 100644 python/sentry_ophio/proguard.py delete mode 100644 python/sentry_ophio/proguard.pyi delete mode 100644 tests/conftest.py delete mode 100644 tests/fixtures/proguard.txt delete mode 100644 tests/test_proguard.py diff --git a/Cargo.lock b/Cargo.lock index 390a478..6d8c765 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -537,7 +537,6 @@ name = "ophio-bindings" version = "0.2.7" dependencies = [ "anyhow", - "proguard", "pyo3", "rust-ophio", "smol_str", @@ -634,16 +633,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "proguard" -version = "5.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b88dddb086b00f5539a95d2c7a2373358fd8bfadb7b1297cc29e0196403a1b98" -dependencies = [ - "lazy_static", - "uuid", -] - [[package]] name = "pyo3" version = "0.21.2" @@ -895,12 +884,6 @@ dependencies = [ "serde", ] -[[package]] -name = "sha1_smol" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae1a47186c03a32177042e55dbc5fd5aee900b8e0069a8d70fba96a9375cd012" - [[package]] name = "siphasher" version = "0.3.11" @@ -1082,9 +1065,6 @@ name = "uuid" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a183cf7feeba97b4dd1c0d46788634f6221d87fa961b305bed08c851829efcc0" -dependencies = [ - "sha1_smol", -] [[package]] name = "version_check" diff --git a/bindings/Cargo.toml b/bindings/Cargo.toml index 1910f2b..eb4a3b1 100644 --- a/bindings/Cargo.toml +++ b/bindings/Cargo.toml @@ -10,7 +10,6 @@ crate-type = ["cdylib"] [dependencies] anyhow = "1.0.79" -proguard = { version = "5.4.0", features = ["uuid"] } pyo3 = { version = "0.21.0", features = [ "anyhow", "extension-module", diff --git a/bindings/src/lib.rs b/bindings/src/lib.rs index 7ba9f7d..c6bbcdf 100644 --- a/bindings/src/lib.rs +++ b/bindings/src/lib.rs @@ -1,7 +1,6 @@ use pyo3::prelude::*; mod enhancers; -mod proguard; #[pymodule] fn _bindings(_py: Python, m: Bound) -> PyResult<()> { @@ -9,8 +8,6 @@ fn _bindings(_py: Python, m: Bound) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; - m.add_class::()?; - m.add_class::()?; Ok(()) } diff --git a/bindings/src/proguard.rs b/bindings/src/proguard.rs deleted file mode 100644 index 1aec739..0000000 --- a/bindings/src/proguard.rs +++ /dev/null @@ -1,99 +0,0 @@ -use pyo3::prelude::*; -use pyo3::types::{IntoPyDict, PyBytes}; -use symbolic::common::{AsSelf, ByteView, SelfCell}; - -#[pyclass(frozen, get_all)] -pub struct JavaStackFrame { - pub class_name: String, - pub method: String, - pub file: Option, - pub line: usize, -} - -struct Inner<'a> { - mapping: proguard::ProguardMapping<'a>, - mapper: proguard::ProguardMapper<'a>, -} - -impl<'slf, 'a: 'slf> AsSelf<'slf> for Inner<'a> { - type Ref = Inner<'slf>; - - fn as_self(&'slf self) -> &Self::Ref { - self - } -} - -#[pyclass(frozen)] -pub struct ProguardMapper { - inner: SelfCell, Inner<'static>>, -} - -#[pymethods] -impl ProguardMapper { - #[staticmethod] - pub fn open(path: &str) -> PyResult { - let byteview = ByteView::open(path)?; - - let inner = SelfCell::new(byteview, |data| { - let mapping = proguard::ProguardMapping::new(unsafe { &*data }); - let mapper = proguard::ProguardMapper::new(mapping.clone()); - Inner { mapping, mapper } - }); - - Ok(ProguardMapper { inner }) - } - - /// Returns the UUID of the file. - #[getter] - pub fn uuid<'p>(&self, py: Python<'p>) -> PyResult> { - let uuid = self.inner.get().mapping.uuid(); - - let bytes = PyBytes::new_bound(py, uuid.as_bytes()); - let kwargs = [("bytes", bytes)].into_py_dict_bound(py); - py.import_bound("uuid")? - .getattr("UUID")? - .call((), Some(&kwargs)) - } - - /// True if the file contains line information. - #[getter] - pub fn has_line_info(&self) -> bool { - self.inner.get().mapping.has_line_info() - } - - /// Remaps the given class name. - pub fn remap_class(&self, klass: &str) -> Option<&str> { - self.inner.get().mapper.remap_class(klass) - } - - /// Remaps the given class and method name if that can be done unambiguously. - pub fn remap_method(&self, klass: &str, method: &str) -> Option<(&str, &str)> { - self.inner.get().mapper.remap_method(klass, method) - } - - pub fn remap_frame( - &self, - klass: &str, - method: &str, - line: usize, - parameters: Option<&str>, - ) -> Vec { - let frame = if let Some(parameters) = parameters { - proguard::StackFrame::with_parameters(klass, method, parameters) - } else { - proguard::StackFrame::new(klass, method, line) - }; - - self.inner - .get() - .mapper - .remap_frame(&frame) - .map(|frame| JavaStackFrame { - class_name: frame.class().into(), - method: frame.method().into(), - file: frame.file().map(Into::into), - line: frame.line(), - }) - .collect() - } -} diff --git a/python/sentry_ophio/proguard.py b/python/sentry_ophio/proguard.py deleted file mode 100644 index 3ba3bed..0000000 --- a/python/sentry_ophio/proguard.py +++ /dev/null @@ -1,4 +0,0 @@ -from ._bindings import JavaStackFrame, ProguardMapper - -JavaStackFrame.__module__ = __name__ -ProguardMapper.__module__ = __name__ diff --git a/python/sentry_ophio/proguard.pyi b/python/sentry_ophio/proguard.pyi deleted file mode 100644 index d1e64cc..0000000 --- a/python/sentry_ophio/proguard.pyi +++ /dev/null @@ -1,21 +0,0 @@ -from dataclasses import dataclass -from uuid import UUID - -@dataclass(frozen=True) -class JavaStackFrame: - class_name: str - method: str - file: str | None - line: int - -class ProguardMapper: - @staticmethod - def open(path: str) -> ProguardMapper: ... - @property - def uuid(self) -> UUID: ... - @property - def has_line_info(self) -> bool: ... - def remap_method(self, klass: str, method: str) -> tuple[str, str] | None: ... - def remap_frame( - self, klass: str, method: str, line: int, parameters: str | None = None - ) -> list[JavaStackFrame]: ... diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index e5c285a..0000000 --- a/tests/conftest.py +++ /dev/null @@ -1,9 +0,0 @@ -import os - -import pytest - - -@pytest.fixture(scope="module") -def fixture_path(): - here = os.path.abspath(os.path.dirname(__file__)) - return os.path.join(here, "fixtures") diff --git a/tests/fixtures/proguard.txt b/tests/fixtures/proguard.txt deleted file mode 100644 index 4168d1c..0000000 --- a/tests/fixtures/proguard.txt +++ /dev/null @@ -1,35 +0,0 @@ -android.support.constraint.ConstraintLayout$LayoutParams -> android.support.constraint.ConstraintLayout$a: - int guideBegin -> a -android.support.constraint.solver.ArrayRow -> android.support.constraint.a.b: - android.support.constraint.solver.SolverVariable variable -> a - float constantValue -> b - boolean used -> c - android.support.constraint.solver.ArrayLinkedVariables variables -> d - boolean isSimpleDefinition -> e - 22:32:void (android.support.constraint.solver.Cache) -> - 35:36:void updateClientEquations() -> a - 43:43:boolean hasKeyVariable() -> b - 51:51:java.lang.String toString() -> toString - 55:101:java.lang.String toReadableString() -> c - 105:109:void reset() -> d - 112:112:boolean hasVariable(android.support.constraint.solver.SolverVariable) -> a - 116:120:android.support.constraint.solver.ArrayRow createRowDefinition(android.support.constraint.solver.SolverVariable,int) -> a - 124:131:android.support.constraint.solver.ArrayRow createRowEquals(android.support.constraint.solver.SolverVariable,int) -> b - 135:151:android.support.constraint.solver.ArrayRow createRowEquals(android.support.constraint.solver.SolverVariable,android.support.constraint.solver.SolverVariable,int) -> a - 155:156:android.support.constraint.solver.ArrayRow addSingleError(android.support.constraint.solver.SolverVariable,int) -> c - 162:180:android.support.constraint.solver.ArrayRow createRowGreaterThan(android.support.constraint.solver.SolverVariable,android.support.constraint.solver.SolverVariable,android.support.constraint.solver.SolverVariable,int) -> a - 185:203:android.support.constraint.solver.ArrayRow createRowLowerThan(android.support.constraint.solver.SolverVariable,android.support.constraint.solver.SolverVariable,android.support.constraint.solver.SolverVariable,int) -> b - 211:233:android.support.constraint.solver.ArrayRow createRowEqualDimension(float,float,float,android.support.constraint.solver.SolverVariable,int,android.support.constraint.solver.SolverVariable,int,android.support.constraint.solver.SolverVariable,int,android.support.constraint.solver.SolverVariable,int) -> a - 238:280:android.support.constraint.solver.ArrayRow createRowCentering(android.support.constraint.solver.SolverVariable,android.support.constraint.solver.SolverVariable,int,float,android.support.constraint.solver.SolverVariable,android.support.constraint.solver.SolverVariable,int) -> a - 284:286:android.support.constraint.solver.ArrayRow addError(android.support.constraint.solver.SolverVariable,android.support.constraint.solver.SolverVariable) -> a - 291:294:android.support.constraint.solver.ArrayRow createRowDimensionPercent(android.support.constraint.solver.SolverVariable,android.support.constraint.solver.SolverVariable,android.support.constraint.solver.SolverVariable,float) -> a - 311:315:android.support.constraint.solver.ArrayRow createRowDimensionRatio(android.support.constraint.solver.SolverVariable,android.support.constraint.solver.SolverVariable,android.support.constraint.solver.SolverVariable,android.support.constraint.solver.SolverVariable,float) -> a - 331:332:boolean updateRowWithEquation(android.support.constraint.solver.ArrayRow) -> a - 337:342:void ensurePositiveConstant() -> e - 345:352:void pickRowVariable() -> f - 355:368:void pivot(android.support.constraint.solver.SolverVariable) -> b -io.sentry.sample.MainActivity -> io.sentry.sample.MainActivity: - 1:1:void ():15:15 -> - 1:1:void bar():54:54 -> a - 1:1:void foo():44 -> a - 1:1:void onClickHandler(android.view.View):40 -> a diff --git a/tests/test_proguard.py b/tests/test_proguard.py deleted file mode 100644 index ba83179..0000000 --- a/tests/test_proguard.py +++ /dev/null @@ -1,36 +0,0 @@ -import os -import uuid - -from sentry_ophio.proguard import ProguardMapper - - -def test_mapper(fixture_path): - mapper = ProguardMapper.open(os.path.join(fixture_path, "proguard.txt")) - assert mapper.has_line_info - # FIXME: - assert mapper.uuid == uuid.UUID("da86dcce-c05f-5cc1-a1a0-8fbf5d74beb2") - - assert ( - mapper.remap_class("android.support.constraint.ConstraintLayout$a") - == "android.support.constraint.ConstraintLayout$LayoutParams" - ) - - assert mapper.remap_method("android.support.constraint.a.b", "f") == ( - "android.support.constraint.solver.ArrayRow", - "pickRowVariable", - ) - - remapped = mapper.remap_frame("android.support.constraint.a.b", "a", 116) - assert len(remapped) == 1 - assert remapped[0].class_name == "android.support.constraint.solver.ArrayRow" - assert remapped[0].method == "createRowDefinition" - assert remapped[0].line == 116 - - remapped = mapper.remap_frame("io.sentry.sample.MainActivity", "a", 1) - assert len(remapped) == 3 - assert remapped[0].method == "bar" - assert remapped[0].line == 54 - assert remapped[1].method == "foo" - assert remapped[1].line == 44 - assert remapped[2].method == "onClickHandler" - assert remapped[2].line == 40