diff --git a/androscalpel/Cargo.toml b/androscalpel/Cargo.toml index 8561fa4..94f5839 100644 --- a/androscalpel/Cargo.toml +++ b/androscalpel/Cargo.toml @@ -33,3 +33,8 @@ python = ["pyo3", "pyo3-log"] # Currently not supported external-zip-reader = ["zip"] platform-list = ["androscalpel_platform_api_list"] code-analysis = [] + +[[example]] +name = "list-method" +[[example]] +name = "count_ins_and_genapk" diff --git a/androscalpel/examples/count_ins_and_genapk.rs b/androscalpel/examples/count_ins_and_genapk.rs new file mode 100644 index 0000000..67c6595 --- /dev/null +++ b/androscalpel/examples/count_ins_and_genapk.rs @@ -0,0 +1,39 @@ +use androscalpel::{Apk, Instruction, Result, VisitableMut, VisitorMut}; +use std::env; + +#[derive(Default)] +struct InsCounter { + pub n: u64, +} +impl VisitorMut for InsCounter { + fn visit_instruction(&mut self, ins: Instruction) -> Result { + if !ins.is_pseudo_ins() { + self.n += 1; + } + ins.default_visit_mut(self) + } +} + +fn main() { + let args: Vec<_> = env::args().collect(); + assert!(args.len() > 1, "Need one argument"); + + let mut cnt = InsCounter::default(); + let apk = cnt + .visit_apk(Apk::load_apk_path((&args[1]).into(), false, false).unwrap()) + .unwrap(); + println!("Nb INS: {}", cnt.n); + + let mut files = apk.gen_raw_dex().unwrap(); + + /*apk_frauder::replace_dex( + (&args[1]).into(), + (&args[1] + ".pathed").into(), + &mut dex_files, + cli.keystore, + cli.zipalign, + cli.apksigner, + cli.keypassword.as_deref(), + None::>>>, + )*/ +} diff --git a/androscalpel/examples/list-method.rs b/androscalpel/examples/list-method.rs new file mode 100644 index 0000000..2c75408 --- /dev/null +++ b/androscalpel/examples/list-method.rs @@ -0,0 +1,20 @@ +use androscalpel::{Apk, Method, Result, SmaliName, Visitable, Visitor}; +use std::env; + +#[derive(Default)] +struct MethodPrinter {} +impl Visitor for MethodPrinter { + fn visit_method(&mut self, method: &Method) -> Result<()> { + println!("Method: {}", method.descriptor.try_to_smali()?); + method.default_visit(self)?; + Ok(()) + } +} + +fn main() { + let args: Vec<_> = env::args().collect(); + assert!(args.len() > 1, "Need one argument"); + + let apk = Apk::load_apk_path((&args[1]).into(), false, false).unwrap(); + MethodPrinter::default().visit_apk(&apk).unwrap(); +} diff --git a/androscalpel/src/lib.rs b/androscalpel/src/lib.rs index 4d2016f..f23e96d 100644 --- a/androscalpel/src/lib.rs +++ b/androscalpel/src/lib.rs @@ -1,4 +1,4 @@ -use anyhow::Result; +pub use anyhow::Result; #[cfg(feature = "python")] use pyo3::prelude::*;