list file names
This commit is contained in:
parent
ea18640a78
commit
857a67b657
2 changed files with 170 additions and 1 deletions
|
|
@ -3,6 +3,13 @@ use std::io::{Read, Seek, SeekFrom, Write};
|
|||
|
||||
use androscalpel_serializer::{ReadSeek, Result, Serializable};
|
||||
|
||||
mod cp437;
|
||||
|
||||
enum Encoding {
|
||||
CP437,
|
||||
UTF8,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serializable, Default)]
|
||||
//struct Signature(pub [u8; 4]);
|
||||
struct Signature(pub u32);
|
||||
|
|
@ -121,6 +128,23 @@ impl Serializable for FileHeader {
|
|||
impl FileHeader {
|
||||
const SIGNATURE: Signature = Signature(0x02014b50);
|
||||
const MIN_SIZE: usize = 4 + 6 * 2 + 4 * 3 + 5 * 2 + 4 * 2;
|
||||
|
||||
const MASK_UTF8_FILENAME: u16 = 1 << 11;
|
||||
|
||||
fn get_name_encoding(&self) -> Encoding {
|
||||
if self.general_purpose_flag & Self::MASK_UTF8_FILENAME != 0 {
|
||||
Encoding::UTF8
|
||||
} else {
|
||||
Encoding::CP437
|
||||
}
|
||||
}
|
||||
|
||||
fn get_name(&self) -> String {
|
||||
match self.get_name_encoding() {
|
||||
Encoding::UTF8 => std::str::from_utf8(&self.file_name).unwrap().into(),
|
||||
Encoding::CP437 => cp437::cp437_to_string(&self.file_name),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
|
|
@ -423,10 +447,15 @@ impl<T: Read + Seek> ZipFile<T> {
|
|||
comment_size -= 1;
|
||||
Some(file_size - comment_size as u64 - EndCentralDirectory::MIN_SIZE as u64)
|
||||
}
|
||||
|
||||
fn get_file_names(&self) -> Vec<String> {
|
||||
self.files.iter().map(|f| f.get_name()).collect()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
//let file = File::open("app-release.apk").expect("failed to open file");
|
||||
let file = File::open("tst_64.zip").expect("failed to open file");
|
||||
let zip_fime = ZipFile::new(file);
|
||||
let zip_file = ZipFile::new(file);
|
||||
println!("{}", zip_file.get_file_names().join("\n"));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue