rename duplicate classes

This commit is contained in:
Jean-Marie Mineau 2025-03-26 17:08:31 +01:00
parent 5c91adfe93
commit b7c7282f1b
Signed by: histausse
GPG key ID: B66AEEDA9B645AD2
3 changed files with 29 additions and 11 deletions

8
patcher/Cargo.lock generated
View file

@ -35,7 +35,7 @@ dependencies = [
[[package]]
name = "androscalpel"
version = "0.1.0"
source = "git+ssh://git@git.mineau.eu/histausse/androscalpel.git?rev=5379c29#5379c29eb881bb2fbed9703206f01f4a9ec73ca3"
source = "git+ssh://git@git.mineau.eu/histausse/androscalpel.git?rev=c0152e7#c0152e76089b7a51ce28e19c1828cdbdd435271a"
dependencies = [
"adler",
"androscalpel_serializer",
@ -51,7 +51,7 @@ dependencies = [
[[package]]
name = "androscalpel_serializer"
version = "0.1.0"
source = "git+ssh://git@git.mineau.eu/histausse/androscalpel.git?rev=5379c29#5379c29eb881bb2fbed9703206f01f4a9ec73ca3"
source = "git+ssh://git@git.mineau.eu/histausse/androscalpel.git?rev=c0152e7#c0152e76089b7a51ce28e19c1828cdbdd435271a"
dependencies = [
"androscalpel_serializer_derive",
"log",
@ -60,7 +60,7 @@ dependencies = [
[[package]]
name = "androscalpel_serializer_derive"
version = "0.1.0"
source = "git+ssh://git@git.mineau.eu/histausse/androscalpel.git?rev=5379c29#5379c29eb881bb2fbed9703206f01f4a9ec73ca3"
source = "git+ssh://git@git.mineau.eu/histausse/androscalpel.git?rev=c0152e7#c0152e76089b7a51ce28e19c1828cdbdd435271a"
dependencies = [
"proc-macro2",
"quote",
@ -129,7 +129,7 @@ dependencies = [
[[package]]
name = "apk_frauder"
version = "0.1.0"
source = "git+ssh://git@git.mineau.eu/histausse/androscalpel.git?rev=5379c29#5379c29eb881bb2fbed9703206f01f4a9ec73ca3"
source = "git+ssh://git@git.mineau.eu/histausse/androscalpel.git?rev=c0152e7#c0152e76089b7a51ce28e19c1828cdbdd435271a"
dependencies = [
"androscalpel_serializer",
"flate2",

View file

@ -6,8 +6,8 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
androscalpel = { git = "ssh://git@git.mineau.eu/histausse/androscalpel.git", rev = "5379c29", features = ["code-analysis"] }
apk_frauder = { git = "ssh://git@git.mineau.eu/histausse/androscalpel.git", rev = "5379c29"}
androscalpel = { git = "ssh://git@git.mineau.eu/histausse/androscalpel.git", rev = "c0152e7", features = ["code-analysis"] }
apk_frauder = { git = "ssh://git@git.mineau.eu/histausse/androscalpel.git", rev = "c0152e7"}
anyhow = { version = "1.0.95", features = ["backtrace"] }
clap = { version = "4.5.27", features = ["derive"] }
env_logger = "0.11.6"

View file

@ -1,7 +1,7 @@
use std::collections::HashMap;
use std::fs::File;
use androscalpel::{Apk, DexString, IdType, VisitableMut, VisitorMut};
use androscalpel::{Apk, DexString, IdType, VisitorMut};
use anyhow::{Context, Result};
use clap::ValueEnum;
@ -70,17 +70,30 @@ fn insert_code_model_class_loaders(apk: &mut Apk, data: &RuntimeData) -> Result<
};
let collisions = class_defined.intersection(&classes);
for cls in collisions {
class_loader.rename_classdef(cls);
class_loader.rename_classdef(cls)?;
}
class_defined.extend(classes);
class_loaders.insert(dyn_data.classloader.clone(), class_loader);
}
// TODO: rename colliding classes according to class laoder
// TODO: get the ClassLoader::parent values...
// TODO: model the delegation behavior and rename ref to class accordingly
// TODO: update Runtime Data to reflect the name change
todo!()
let apk = if let ApkOrRef::Ref(apk) = class_loaders.remove("MAIN").unwrap().apk {
apk
} else {
panic!("Main APK is not stored as ref?")
};
for (_, ClassLoader { apk: other, .. }) in class_loaders.into_iter() {
if let ApkOrRef::Owned(other) = other {
apk.merge(other);
} else {
panic!("Secondary APK is not stored as owned?")
}
}
//todo!()
Ok(())
}
/// Structure modelizing a class loader.
@ -129,13 +142,18 @@ impl ClassLoader<'_> {
new_name.try_to_smali().unwrap(),
);
let class = self.apk().remove_class(cls, None).with_context(|| {
let class = self.apk().remove_class(cls, None)?.with_context(|| {
format!(
"Try to rename classdef of {} in class loader {}, but classdef not found",
cls.__str__(),
&id
)
})?;
let class = RenameTypeVisitor {
new_names: [(cls.clone(), new_name.clone())].into(),
}
.visit_class(class)?;
self.apk().add_class("classes.dex", class)?;
self.renamed_classes.insert(cls.clone(), new_name);
Ok(())