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
18 changes: 3 additions & 15 deletions src/cache/mod.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
use std::collections::{hash_map::DefaultHasher, HashSet};
use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
use std::sync::{Arc, LazyLock, RwLock};

pub static SAFE_STRING_CACHE: LazyLock<Arc<RwLock<HashSet<String>>>> =
LazyLock::new(|| Arc::new(RwLock::new(HashSet::new())));

pub fn is_cached_safe_string(s: &str) -> bool {
if let Ok(cache) = SAFE_STRING_CACHE.read() {
cache.contains(s)
} else {
pub fn is_cached_safe_string(_s: &str) -> bool {
false
}
}

pub fn cache_safe_string(s: &str) {
if let Ok(mut cache) = SAFE_STRING_CACHE.write() {
cache.insert(s.to_string());
}
}
pub fn cache_safe_string(_s: &str) {}

pub fn calculate_detection_hash(data: &[u8]) -> u64 {
let mut hasher = DefaultHasher::new();
Expand Down
5 changes: 0 additions & 5 deletions src/scanner/api_analyzer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,6 @@ impl ApiAnalyzer {
return format!("Method/Field: {}", method.name);
}
}
for field in &details.fields {
if field.name.len() > 5 && !field.name.contains('/') {
return field.name.clone();
}
}
"".to_string()
}

Expand Down
90 changes: 37 additions & 53 deletions src/scanner/jar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,41 +34,45 @@ impl CollapseScanner {

let file_data = std::fs::read(jar_path)?;

let indices_to_scan: Vec<usize> = {
let mut archive = ZipArchive::new(Cursor::new(&file_data[..]))?;
let mut indices = Vec::new();
let mut skipped = 0;

for i in 0..archive.len() {
let entry = match archive.by_index(i) {
Ok(f) => f,
Err(_) => {
skipped += 1;
continue;
}
};
let name = match entry.enclosed_name() {
Some(p) => get_archive_entry_name(&p.to_string_lossy()),
None => get_archive_entry_name(&String::from_utf8_lossy(entry.name_raw())),
};
if !entry.is_dir() && self.should_scan(&name) {
indices.push(i);
let mut archive = ZipArchive::new(Cursor::new(&file_data[..]))?;
let mut entries_to_scan = Vec::new();
let mut skipped = 0;

for i in 0..archive.len() {
let mut entry = match archive.by_index(i) {
Ok(f) => f,
Err(_) => {
skipped += 1;
continue;
}
};
let name = match entry.enclosed_name() {
Some(p) => get_archive_entry_name(&p.to_string_lossy()),
None => get_archive_entry_name(&String::from_utf8_lossy(entry.name_raw())),
};
if !entry.is_dir() && self.should_scan(&name) {
let file_size = entry.size() as usize;
let mut buffer = Vec::with_capacity(file_size);
if entry.read_to_end(&mut buffer).is_ok() {
let compressed_size = entry.compressed_size();
entries_to_scan.push((name, buffer, compressed_size));
} else {
skipped += 1;
}
} else {
skipped += 1;
}
}

if self.options.verbose {
println!(
"[+] JAR indexed: {} entries ({} skipped)",
archive.len(),
skipped
);
}
indices
};
if self.options.verbose {
println!(
"[+] JAR indexed: {} entries ({} skipped)",
archive.len(),
skipped
);
}

let total_files = indices_to_scan.len();
let total_files = entries_to_scan.len();
let processed_count = Arc::new(AtomicUsize::new(0));

if let Some(ref prog_arc) = self.options.progress {
Expand All @@ -80,29 +84,9 @@ impl CollapseScanner {
}
}

let results: Vec<ScanResult> = indices_to_scan
.par_iter()
.flat_map(|&i| {
let mut archive = match ZipArchive::new(Cursor::new(&file_data[..])) {
Ok(a) => a,
Err(_) => return Vec::new(),
};
let mut entry = match archive.by_index(i) {
Ok(f) => f,
Err(_) => return Vec::new(),
};
let entry_name = match entry.enclosed_name() {
Some(p) => get_archive_entry_name(&p.to_string_lossy()),
None => get_archive_entry_name(&String::from_utf8_lossy(entry.name_raw())),
};
let file_size = entry.size() as usize;
let mut buffer = Vec::with_capacity(file_size);
if entry.read_to_end(&mut buffer).is_err() {
processed_count.fetch_add(1, Ordering::Relaxed);
return Vec::new();
}
let compressed_size = entry.compressed_size();

let results: Vec<ScanResult> = entries_to_scan
.into_par_iter()
.flat_map(|(entry_name, buffer, compressed_size)| {
let progress_name = entry_name.clone();
if let Some(ref prog_arc) = self.options.progress {
if let Ok(mut gp) = prog_arc.lock() {
Expand Down Expand Up @@ -280,7 +264,7 @@ impl CollapseScanner {
&relative_name,
&nested_buffer,
Some(compressed_size),
archive_depth,
archive_depth + 1,
)?);
}

Expand Down
Loading