add file modification
This commit is contained in:
parent
fb2ba61d21
commit
df9d258780
4 changed files with 44 additions and 2 deletions
|
|
@ -1,4 +1,5 @@
|
|||
use androscalpel_serializer::Serializable;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
|
|
@ -156,6 +157,7 @@ pub fn replace_dex(
|
|||
// 2048 -validity 10000 -alias ALIAS`
|
||||
zipalign: Option<impl AsRef<Path>>,
|
||||
apksigner: Option<impl AsRef<Path>>,
|
||||
additionnal_files: Option<HashMap<String, Option<impl Read + Seek>>>,
|
||||
) {
|
||||
let zipalign = if let Some(path) = &zipalign {
|
||||
path.as_ref().as_os_str()
|
||||
|
|
@ -185,6 +187,10 @@ pub fn replace_dex(
|
|||
|
||||
apk.unlink_signature_files();
|
||||
apk.unlink_bytecode_files();
|
||||
if let Some(additionnal_files) = &additionnal_files {
|
||||
apk.files
|
||||
.retain(|file| additionnal_files.get(&file.get_name()).is_none());
|
||||
}
|
||||
for f in apk.files.clone() {
|
||||
apk_out.insert_file_from_zip(f, &mut apk);
|
||||
}
|
||||
|
|
@ -200,6 +206,18 @@ pub fn replace_dex(
|
|||
Some(file_info_ref.local_header.clone()),
|
||||
);
|
||||
}
|
||||
if let Some(mut additionnal_files) = additionnal_files {
|
||||
for (name, data) in &mut additionnal_files {
|
||||
file_info_ref.set_name(name);
|
||||
if let Some(data) = data.as_mut() {
|
||||
apk_out.insert_file(
|
||||
data,
|
||||
file_info_ref.header.clone(),
|
||||
Some(file_info_ref.local_header.clone()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
apk_out.write_central_directory();
|
||||
// TODO: we can probably do that ourself an spare ourself the trouble of finding zipalign
|
||||
Command::new(zipalign)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Cursor;
|
||||
|
||||
fn main() {
|
||||
apk_frauder::replace_dex(
|
||||
|
|
@ -15,5 +17,6 @@ fn main() {
|
|||
"{}/Android/Sdk/build-tools/34.0.0/apksigner",
|
||||
env::var("HOME").expect("$HOME not set")
|
||||
)),
|
||||
None::<HashMap<String, Option<Cursor<&[u8]>>>>,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -297,6 +297,8 @@ impl<T: Read + Seek> ZipFileReader<T> {
|
|||
}
|
||||
|
||||
pub fn get_classes_file_info(&self) -> Vec<&FileInfo> {
|
||||
// TODO: check for holes: if classesN.dex does not exist,
|
||||
// classesM.dex for M>N are ignored.
|
||||
self.files
|
||||
.iter()
|
||||
.filter(|&file| match_dexfile_name(&file.get_name()))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue