From 0a112802cdd06e43db53f6b1f556eea6d1ff0564 Mon Sep 17 00:00:00 2001 From: Jean-Marie Mineau Date: Wed, 4 Oct 2023 14:30:07 +0200 Subject: [PATCH] skeleton for method --- TODO.md | 2 +- androscalpel/src/lib.rs | 4 +++ androscalpel/src/method.rs | 60 ++++++++++++++++++++++++++++++++++++++ test.sh | 2 +- 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 androscalpel/src/method.rs diff --git a/TODO.md b/TODO.md index 2968a7f..23b5c03 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,5 @@ -- enum - method +- anotation - code - edditable format - sanity checks diff --git a/androscalpel/src/lib.rs b/androscalpel/src/lib.rs index 40f8f74..24e961a 100644 --- a/androscalpel/src/lib.rs +++ b/androscalpel/src/lib.rs @@ -6,6 +6,7 @@ pub mod apk; pub mod class; pub mod dex_id; pub mod field; +pub mod method; pub mod method_handle; pub mod scalar; pub mod value; @@ -14,6 +15,7 @@ pub use apk::*; pub use class::*; pub use dex_id::*; pub use field::*; +pub use method::*; pub use method_handle::*; pub use scalar::*; pub use value::*; @@ -186,6 +188,8 @@ fn androscalpel(_py: Python, m: &PyModule) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; + m.add_class::()?; + m.add_class::()?; m.add_class::()?; m.add_class::()?; Ok(()) diff --git a/androscalpel/src/method.rs b/androscalpel/src/method.rs new file mode 100644 index 0000000..f5a9476 --- /dev/null +++ b/androscalpel/src/method.rs @@ -0,0 +1,60 @@ +//! Representation of a method. + +use pyo3::prelude::*; + +use crate::IdMethod; + +/// Represent a method. +#[pyclass] +#[derive(Debug, Clone)] +pub struct Method { + /// The structure used to reference this method. + #[pyo3(get, set)] + pub descriptor: IdMethod, + /* TODO: ACCESS FLAG + /// The field visibility + #[pyo3(get, set)] + pub visibility: FieldVisibility, + /// If the field is defined for the class globally + #[pyo3(get, set)] + pub is_static: bool, + /// If the field is immutable after construction + #[pyo3(get, set)] + pub is_final: bool, + /// For thread safety + #[pyo3(get, set)] + pub is_volatile: bool, + /// If the field should **not** be saved by default serialization + #[pyo3(get, set)] + pub is_transient: bool, + /// If the field is not defined in the source code + #[pyo3(get, set)] + pub is_synthetic: bool, + /// If the field is an enumerated value + #[pyo3(get, set)] + pub is_enum: bool, + */ + /// The code of the method + pub code: (), +} + +#[pymethods] +impl Method { + #[new] + pub fn new(descriptor: IdMethod) -> Self { + Self { + descriptor, + code: (), + } + } + + pub fn __str__(&self) -> String { + self.__repr__() + } + + pub fn __repr__(&self) -> String { + let name: String = (&self.descriptor.name).into(); + let ty: String = self.descriptor.proto.__str__(); + format!("Method({name}, {ty})") + } +} diff --git a/test.sh b/test.sh index f6e7a28..2063d57 100755 --- a/test.sh +++ b/test.sh @@ -4,4 +4,4 @@ source venv_maturin/bin/activate cd androscalpel maturin develop cd .. -python test.py +python -i test.py