add array support to dex values
This commit is contained in:
parent
feff847310
commit
d69036d3b5
5 changed files with 69 additions and 9 deletions
4
TODO.md
4
TODO.md
|
|
@ -1,4 +1,8 @@
|
|||
- enum
|
||||
- method
|
||||
- code
|
||||
- edditable format
|
||||
- sanity checks
|
||||
- tests
|
||||
- DexValues will become a problem ? (eg need to clone the vector for the array)
|
||||
- https://source.android.com/docs/core/runtime/dex-format#system-annotation
|
||||
|
|
|
|||
|
|
@ -269,7 +269,12 @@ impl Apk {
|
|||
dex,
|
||||
)?)),
|
||||
EncodedValue::Enum(val) => Ok(DexValue::Enum(IdEnum(*val))),
|
||||
EncodedValue::Array(_val) => todo!(), //Ok(DexValue::Array(DexArray(*val))),
|
||||
EncodedValue::Array(arr) => Ok(DexValue::Array(DexArray(
|
||||
arr.values
|
||||
.iter()
|
||||
.map(|val| Self::encoded_value_to_dex_value(val, dex))
|
||||
.collect::<Result<_>>()?,
|
||||
))),
|
||||
EncodedValue::Annotation(_val) => todo!(), //Ok(DexValue::Annotation(DexAnnotation(*val))),
|
||||
EncodedValue::Null => Ok(DexValue::Null(DexNull)),
|
||||
EncodedValue::Boolean(val) => Ok(DexValue::Boolean(DexBoolean(*val))),
|
||||
|
|
|
|||
|
|
@ -276,3 +276,20 @@ impl IntoPy<PyObject> for MethodHandle {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MethodHandle {
|
||||
// Not exposed to python, but meh, let's keep it coherent
|
||||
pub fn __str__(&self) -> String {
|
||||
match self {
|
||||
Self::StaticPut(val) => val.__str__(),
|
||||
Self::StaticGet(val) => val.__str__(),
|
||||
Self::InstancePut(val) => val.__str__(),
|
||||
Self::InstanceGet(val) => val.__str__(),
|
||||
Self::InvokeStatic(val) => val.__str__(),
|
||||
Self::InvokeInstance(val) => val.__str__(),
|
||||
Self::InvokeConstructor(val) => val.__str__(),
|
||||
Self::InvokeDirect(val) => val.__str__(),
|
||||
Self::InvokeInterface(val) => val.__str__(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
//! The class identifying dex structure.
|
||||
|
||||
use crate::DexValue;
|
||||
use pyo3::prelude::*;
|
||||
|
||||
// TODO: move DexString here
|
||||
|
|
@ -233,24 +234,31 @@ impl DexBoolean {
|
|||
}
|
||||
|
||||
#[pyclass]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct DexArray;
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DexArray(pub Vec<DexValue>);
|
||||
#[pymethods]
|
||||
impl DexArray {
|
||||
#[new]
|
||||
pub fn _new() -> Self {
|
||||
Self
|
||||
pub fn _new(arr: Vec<DexValue>) -> Self {
|
||||
Self(arr)
|
||||
}
|
||||
|
||||
pub fn get_value(&self) {
|
||||
todo!()
|
||||
pub fn get_value(&self) -> Vec<DexValue> {
|
||||
self.0.clone() // TODO: this will becom a problem...
|
||||
}
|
||||
|
||||
pub fn __str__(&self) -> String {
|
||||
self.__repr__()
|
||||
format!(
|
||||
"[{}]",
|
||||
self.0
|
||||
.iter()
|
||||
.map(|val| val.__str__())
|
||||
.collect::<Vec<String>>()
|
||||
.join(", ")
|
||||
)
|
||||
}
|
||||
|
||||
pub fn __repr__(&self) -> String {
|
||||
"DexArray".into()
|
||||
"DexArray()".into()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,6 +74,32 @@ impl<'source> FromPyObject<'source> for DexValue {
|
|||
}
|
||||
}
|
||||
|
||||
impl DexValue {
|
||||
// Not exposed to python, but meh, let's keep it coherent
|
||||
pub fn __str__(&self) -> String {
|
||||
match self {
|
||||
DexValue::Byte(val) => val.__str__(),
|
||||
DexValue::Short(val) => val.__str__(),
|
||||
DexValue::Char(val) => val.__str__(),
|
||||
DexValue::Int(val) => val.__str__(),
|
||||
DexValue::Long(val) => val.__str__(),
|
||||
DexValue::Float(val) => val.__str__(),
|
||||
DexValue::Double(val) => val.__str__(),
|
||||
DexValue::MethodType(val) => val.__str__(),
|
||||
DexValue::MethodHandle(val) => val.__str__(),
|
||||
DexValue::String(val) => val.__str__(),
|
||||
DexValue::Type(val) => val.__str__(),
|
||||
DexValue::Field(val) => val.__str__(),
|
||||
DexValue::Method(val) => val.__str__(),
|
||||
DexValue::Enum(val) => val.__str__(),
|
||||
DexValue::Array(val) => val.__str__(),
|
||||
DexValue::Annotation(val) => val.__str__(),
|
||||
DexValue::Null(val) => val.__str__(),
|
||||
DexValue::Boolean(val) => val.__str__(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl IntoPy<PyObject> for DexValue {
|
||||
fn into_py(self, py: Python<'_>) -> PyObject {
|
||||
match self {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue