Skip to content

Commit

Permalink
feat: add some logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mufanc committed Dec 31, 2023
1 parent ecaa999 commit 746d4be
Show file tree
Hide file tree
Showing 4 changed files with 220 additions and 6 deletions.
217 changes: 211 additions & 6 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ strip = true # Strip symbols from binary*
[dependencies]
anyhow = "1.0.72"
clap = { version = "4.0.14", features = ["derive"] }
env_logger = "0.10"
log = "0.4"
nix = { version = "0.26.2", features = [ "uio" ] }
once_cell = "1.18.0"
regex = "1.6.0"
Expand Down
5 changes: 5 additions & 0 deletions src/dex.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{fs, mem, ptr};
use std::path::PathBuf;
use log::debug;
use once_cell::sync::Lazy;
use regex::bytes::Regex;
use crate::memory::{RemoteMemory, MemoryMap};
Expand Down Expand Up @@ -67,19 +68,23 @@ impl<'a> MemoryDex<'a> {

pub fn is_valid(&self) -> bool {
if !PATTERN_DEX_MAGIC.is_match(&self.header.magic) {
debug!("invalid header magic: {:?}", &self.header.magic);
return false
}

if self.map.size() < self.header.file_size as usize {
debug!("file size doesn't match");
return false
}

// https://source.android.com/docs/core/runtime/dex-format?hl=zh-cn#endian-constant
if self.header.endian_tag != 0x12345678 && self.header.endian_tag != 0x78563412 {
debug!("invalid endian tag");
return false;
}

if self.header.type_ids_size > 65535 || self.header.proto_ids_size > 65535 {
debug!("too many method ids or proto ids");
return false;
}

Expand Down
2 changes: 2 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ mod memory;
mod dex;

fn main() {
env_logger::init();

if let Err(err) = dump::dump_dex_files(&argparse::parse()) {
println!("[!] Error: {:?}", err)
}
Expand Down

0 comments on commit 746d4be

Please sign in to comment.