add examples

This commit is contained in:
Jean-Marie Mineau 2025-10-06 18:13:36 +02:00
parent 22571a39fc
commit 28f47eaba4
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
4 changed files with 65 additions and 1 deletions

View file

@ -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"

View file

@ -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<Instruction> {
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::<HashMap<_, Option<Cursor<&[u8]>>>>,
)*/
}

View file

@ -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();
}

View file

@ -1,4 +1,4 @@
use anyhow::Result;
pub use anyhow::Result;
#[cfg(feature = "python")]
use pyo3::prelude::*;