From acd5c8445e0c638c8b1aa8356b9d345367b5b7e6 Mon Sep 17 00:00:00 2001 From: Jean-Marie Mineau Date: Mon, 7 Apr 2025 13:08:46 +0200 Subject: [PATCH] add option to pass key pwd from arg --- androscalpel_serializer/src/core/string.rs | 6 +++--- apk_frauder/src/lib.rs | 15 +++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/androscalpel_serializer/src/core/string.rs b/androscalpel_serializer/src/core/string.rs index 8d85a9b..1be3234 100644 --- a/androscalpel_serializer/src/core/string.rs +++ b/androscalpel_serializer/src/core/string.rs @@ -143,7 +143,7 @@ impl StringDataItem { let two = self.data[i] as u32; i += 1; if one & 0x20 == 0 { - utf16_string.push((one & 0x1f) << 6 | (two & 0x3f)); + utf16_string.push(((one & 0x1f) << 6) | (two & 0x3f)); continue; } @@ -155,7 +155,7 @@ impl StringDataItem { let three = self.data[i] as u32; i += 1; if one & 0x10 == 0 { - utf16_string.push((one & 0x0f) << 12 | (two & 0x3f) << 6 | (three & 0x3f)); + utf16_string.push(((one & 0x0f) << 12) | ((two & 0x3f) << 6) | (three & 0x3f)); continue; } @@ -167,7 +167,7 @@ impl StringDataItem { let four = self.data[i] as u32; i += 1; let code_point = - (one & 0x0f) << 18 | (two & 0x3f) << 12 | (three & 0x3f) << 6 | (four & 0x3f); + ((one & 0x0f) << 18) | ((two & 0x3f) << 12) | ((three & 0x3f) << 6) | (four & 0x3f); let mut pair = ((code_point >> 10) + 0xd7c0) & 0xffff; pair |= ((code_point & 0x03ff) + 0xdc00) << 16; utf16_string.push(pair); diff --git a/apk_frauder/src/lib.rs b/apk_frauder/src/lib.rs index e97aae8..5769b2f 100644 --- a/apk_frauder/src/lib.rs +++ b/apk_frauder/src/lib.rs @@ -150,6 +150,7 @@ impl FileInfo { /// /// The `zipalign` and `apksigner` args allow to use a specific version of the /// tools instead of the one in the PATH (if it even exist) +#[allow(clippy::too_many_arguments)] pub fn replace_dex( apk: impl AsRef, dst: impl AsRef, @@ -159,6 +160,7 @@ pub fn replace_dex( // 2048 -validity 10000 -alias ALIAS` zipalign: Option>, apksigner: Option>, + keypassword: Option<&str>, additionnal_files: Option>>, ) { let zipalign = if let Some(path) = &zipalign { @@ -233,14 +235,19 @@ pub fn replace_dex( .status() .unwrap(); - Command::new(apksigner) + let mut cmd = Command::new(apksigner); + let cmd = cmd .arg("sign") .arg("--ks") .arg(keystore.as_ref().as_os_str()) .arg("--out") .arg(dst.as_ref().as_os_str()) - .arg(aligned_path.as_os_str()) - .status() - .unwrap(); + .arg(aligned_path.as_os_str()); + let cmd = if let Some(pwd) = keypassword { + cmd.arg("--ks-pass").arg(format!("pass:${pwd}")) + } else { + cmd + }; + cmd.status().unwrap(); fs::remove_dir_all(tmp_dir).expect("Failled to remove tmp dir"); }