convert instruction to an editable format WIP
This commit is contained in:
parent
2d164362a7
commit
29c43a68b2
5 changed files with 2631 additions and 45 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -4,11 +4,11 @@ use std::collections::HashSet;
|
|||
|
||||
use pyo3::prelude::*;
|
||||
|
||||
use crate::{DexString, IdField, IdMethod, IdMethodType, IdType, MethodHandle};
|
||||
use crate::{DexString, IdField, IdMethod, IdMethodType, IdType, Instruction, MethodHandle};
|
||||
|
||||
// TODO: make this easy to edit/manipulate, maybe move to Method
|
||||
|
||||
type TmpHandlerType = (Vec<(IdType, u32)>, Option<u32>);
|
||||
// type TmpHandlerType = (Vec<(IdType, u32)>, Option<u32>);
|
||||
|
||||
/// The code run by a method.
|
||||
#[pyclass]
|
||||
|
|
@ -33,12 +33,12 @@ pub struct Code {
|
|||
// TODO: implement OPcode
|
||||
/// The instructions.
|
||||
#[pyo3(get, set)]
|
||||
pub insns: Vec<u16>,
|
||||
pub insns: Vec<Instruction>,
|
||||
// TODO: currently unusable, juste a mapping ty TryItem
|
||||
// TODO: maybe implement as custom OPcode to make me easy to modify?
|
||||
/// Try blocks
|
||||
#[pyo3(get, set)]
|
||||
pub tries: Vec<(u32, u16, TmpHandlerType)>,
|
||||
// /// Try blocks
|
||||
// #[pyo3(get, set)]
|
||||
// pub tries: Vec<(u32, u16, TmpHandlerType)>,
|
||||
// TODO: currently unusable, juste a mapping ty TryItem
|
||||
// TODO: maybe implement as custom OPcode to make me easy to modify?
|
||||
}
|
||||
|
|
@ -62,6 +62,8 @@ impl Code {
|
|||
|
||||
/// Return all strings referenced in the codes.
|
||||
pub fn get_all_strings(&self) -> HashSet<DexString> {
|
||||
todo!()
|
||||
/*
|
||||
let mut strings = HashSet::new();
|
||||
for (_, _, (list, _)) in &self.tries {
|
||||
for (ty, _) in list {
|
||||
|
|
@ -69,10 +71,13 @@ impl Code {
|
|||
}
|
||||
}
|
||||
strings
|
||||
*/
|
||||
}
|
||||
|
||||
/// Return all types referenced in the codes.
|
||||
pub fn get_all_types(&self) -> HashSet<IdType> {
|
||||
todo!()
|
||||
/*
|
||||
let mut types = HashSet::new();
|
||||
for (_, _, (list, _)) in &self.tries {
|
||||
for (ty, _) in list {
|
||||
|
|
@ -80,6 +85,7 @@ impl Code {
|
|||
}
|
||||
}
|
||||
types
|
||||
*/
|
||||
}
|
||||
|
||||
/// Return all prototypes referenced in the codes.
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -24,7 +24,7 @@ pub use dex_id::*;
|
|||
pub use dex_string::*;
|
||||
pub use dex_writer::*;
|
||||
pub use field::*;
|
||||
//pub use instructions::*;
|
||||
pub use instructions::{CallSite, Instruction};
|
||||
pub use method::*;
|
||||
pub use method_handle::*;
|
||||
pub use scalar::*;
|
||||
|
|
|
|||
|
|
@ -194,6 +194,16 @@ impl<'a> DexFileReader<'a> {
|
|||
)))
|
||||
}
|
||||
|
||||
/// Return a [`CallSiteIdItem`] reference from its idx.
|
||||
pub fn get_call_site_id(&self, idx: usize) -> Result<&CallSiteIdItem> {
|
||||
self.call_site_ids
|
||||
.get(idx)
|
||||
.ok_or(Error::InconsistantStruct(format!(
|
||||
"call site {idx} is out of bound (|call_site_ids|={})",
|
||||
self.call_site_ids.len()
|
||||
)))
|
||||
}
|
||||
|
||||
fn sanity_check(&self) -> Result<()> {
|
||||
if self.header.magic.version != [0x30, 0x33, 0x39] {
|
||||
warn!(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue