Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 54 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/shield-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ clap = { version = "4.5", features = ["derive", "cargo", "env"] }
anyhow = "1.0"
env_logger = "0.11"
log = "0.4"
zip = { version = "2.4", default-features = false, features = ["deflate"] }
zip = { version = "9", default-features = false, features = ["deflate"] }
colored = "3.1"
shield-core = { path = "../../crates/shield-core" }
shield-ios = { path = "../../crates/shield-ios" }
Expand Down
14 changes: 9 additions & 5 deletions apps/shield-cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,8 @@ fn extract_aab_modules(
let mut seen = std::collections::BTreeSet::new();
for index in 0..archive.len() {
let mut entry = archive.by_index(index)?;
let Some((module, relative)) = entry.name().split_once('/') else {
let name = entry.name()?.into_owned();
let Some((module, relative)) = name.split_once('/') else {
continue;
};
if !requested.contains(module) || relative.is_empty() {
Expand All @@ -1088,21 +1089,21 @@ fn extract_aab_modules(
.components()
.any(|component| !matches!(component, std::path::Component::Normal(_)))
{
anyhow::bail!("AAB 模块条目路径非法:{}", entry.name());
anyhow::bail!("AAB 模块条目路径非法:{name}");
}
if entry
.unix_mode()
.is_some_and(|mode| mode & 0o170000 == 0o120000)
{
anyhow::bail!("AAB 模块不允许符号链接:{}", entry.name());
anyhow::bail!("AAB 模块不允许符号链接:{name}");
}
let destination = root.join(module).join(relative_path);
if entry.is_dir() {
std::fs::create_dir_all(&destination)?;
continue;
}
if !seen.insert((module.to_string(), relative.to_string())) {
anyhow::bail!("AAB 模块包含重复条目:{}", entry.name());
anyhow::bail!("AAB 模块包含重复条目:{name}");
}
if let Some(parent) = destination.parent() {
std::fs::create_dir_all(parent)?;
Expand Down Expand Up @@ -1875,7 +1876,10 @@ mod tests {
super::zip_bundle_module(&module, &module_zip).unwrap();
let file = std::fs::File::open(module_zip).unwrap();
let archive = zip::ZipArchive::new(file).unwrap();
let names: Vec<_> = archive.file_names().map(str::to_string).collect();
let names: Vec<_> = archive
.file_names()
.map(|name| name.unwrap().into_owned())
.collect();
assert!(names.contains(&"manifest/AndroidManifest.xml".to_string()));
assert!(names.contains(&"dex/classes.dex".to_string()));
assert!(names.contains(&"resources.pb".to_string()));
Expand Down
2 changes: 1 addition & 1 deletion apps/shield-gui/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ semver = "1"
shield-core = { path = "../../../crates/shield-core" }
shield-cli = { path = "../../shield-cli" }
shield-ios = { path = "../../../crates/shield-ios" }
zip = { version = "2", default-features = false, features = ["deflate"] }
zip = { version = "9", default-features = false, features = ["deflate"] }
which = "8"
dunce = "1"
url = "2"
Expand Down
2 changes: 1 addition & 1 deletion crates/shield-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ anyhow = "1.0"
thiserror = "2.0"
log = "0.4"
walkdir = "2.5"
zip = { version = "2.4", default-features = false, features = ["deflate"] }
zip = { version = "9", default-features = false, features = ["deflate"] }
zstd = { workspace = true }
which = "8.0"
colored = "3.1"
Expand Down
19 changes: 13 additions & 6 deletions crates/shield-core/src/apk_inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@ pub fn check_apk(path: &Path, apksigner_path: Option<&Path>) -> Result<ApkCheckO
Err(_) => continue,
};

if entry.name() == "classes.dex" && !already_protected {
let name = match entry.name() {
Ok(name) => name.into_owned(),
Err(_) => continue,
};
if name == "classes.dex" && !already_protected {
let entry_size = entry.size();
already_protected = contains_valid_mshd_block(&mut entry, entry_size)
.context("读取 classes.dex 失败")?;
}
// Xop 使用 assets/protector 目录保存壳载荷。即使没有 MSHD trailer,
// 也必须拒绝把它再次交给 Shellsmith,避免形成两套 Application/Loader。
if is_known_protection_marker(entry.name()) {
if is_known_protection_marker(&name) {
already_protected = true;
}
if let Some(abi) = entry
.name()
if let Some(abi) = name
.strip_prefix("lib/")
.and_then(|name| name.split_once('/').map(|(abi, _)| abi))
{
Expand Down Expand Up @@ -274,7 +277,10 @@ fn check_apk_signed(apk_path: &Path, apksigner_path: Option<&Path>) -> Result<bo
let Ok(entry) = archive.by_index(i) else {
continue;
};
let name = entry.name();
let name = match entry.name() {
Ok(name) => name.into_owned(),
Err(_) => continue,
};
if name.starts_with("META-INF/")
&& (name.ends_with(".RSA") || name.ends_with(".DSA") || name.ends_with(".EC"))
{
Expand Down Expand Up @@ -459,7 +465,8 @@ Source Stamp Signer certificate SHA-256 digest: 22222222222222222222222222222222
let dir = tempfile::tempdir().unwrap();
let apk = dir.path().join("empty.apk");
std::fs::write(&apk, []).unwrap();
let message = classify_apk_zip_error(&apk, &zip::result::ZipError::InvalidArchive("eof"));
let message =
classify_apk_zip_error(&apk, &zip::result::ZipError::InvalidArchive("eof".into()));
assert!(message.starts_with("文件为空,不是有效 APK"));
}

Expand Down
2 changes: 1 addition & 1 deletion crates/shield-core/src/bundle_inspect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn inspect_aab(path: &Path) -> Result<AabInspection> {
let entry = archive
.by_index(index)
.with_context(|| format!("读取 AAB 条目 {index} 失败"))?;
let name = entry.name();
let name = entry.name()?.into_owned();
if name == "BundleConfig.pb" {
has_bundle_config = true;
}
Expand Down
7 changes: 6 additions & 1 deletion crates/shield-core/src/native_vmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ fn validate_entry(entry: &str) -> Result<(&str, &str, &str)> {

fn zip_library(archive: &mut zip::ZipArchive<File>, name: &str) -> Result<Vec<u8>> {
ensure!(
archive.file_names().filter(|n| *n == name).count() == 1,
archive
.file_names()
.filter_map(|n| n.ok())
.filter(|n| n.as_ref() == name)
.count()
== 1,
"Native 归档条目缺失或重复:{name}"
);
let entry = archive.by_name(name)?;
Expand Down
Loading
Loading