use std::io::{Read, Seek};
use crate::common::detection::FileFormat;
pub fn detect_ole2_format(bytes: &[u8]) -> Option<FileFormat> {
if !crate::ole::is_ole_file(bytes) {
return None;
}
let cursor = std::io::Cursor::new(bytes);
detect_ole2_format_from_reader(&mut cursor.clone())
}
pub fn detect_ole2_format_from_reader<R: Read + Seek>(
reader: &mut R
) -> Option<FileFormat> {
let ole_file = match crate::ole::OleFile::open(reader) {
Ok(ole) => ole,
Err(_) => return None,
};
if ole_file.exists(&["WordDocument"]) {
return Some(FileFormat::Doc);
}
if ole_file.exists(&["PowerPoint Document"]) {
return Some(FileFormat::Ppt);
}
if ole_file.exists(&["Workbook"]) || ole_file.exists(&["Book"]) {
return Some(FileFormat::Xls);
}
Some(FileFormat::Doc)
}