From 37f084e3e0df3a105a62331e7ce3fbf940c3e977 Mon Sep 17 00:00:00 2001 From: David Wendt Date: Fri, 10 Sep 2021 23:18:34 -0400 Subject: [PATCH] scanner: Include other SWF header information in the scanner output. --- scanner/src/execute.rs | 23 +++++++++++------ scanner/src/file_results.rs | 49 +++++++++++++++++++++++++++++++++++++ scanner/src/scan.rs | 8 ++++++ 3 files changed, 72 insertions(+), 8 deletions(-) diff --git a/scanner/src/execute.rs b/scanner/src/execute.rs index 921e8eebe..d93ceb1a8 100644 --- a/scanner/src/execute.rs +++ b/scanner/src/execute.rs @@ -14,7 +14,6 @@ use ruffle_core::swf::{decompress_swf, parse_swf}; use ruffle_core::tag_utils::SwfMovie; use ruffle_core::Player; use sha2::{Digest, Sha256}; -use swf::{FileAttributes, Tag}; use std::path::Path; @@ -128,14 +127,22 @@ pub fn execute_report_main(execute_report_opt: ExecuteReportOpt) -> Result<(), s match catch_unwind(|| parse_swf(&swf_buf)) { Ok(swf) => match swf { Ok(swf) => { - let mut vm_type = Some(AvmType::Avm1); - if let Some(Tag::FileAttributes(fa)) = swf.tags.first() { - if fa.contains(FileAttributes::IS_ACTION_SCRIPT_3) { - vm_type = Some(AvmType::Avm2); - } - } + let stage_size = swf.header.stage_size(); + let stage_width = (stage_size.x_max - stage_size.x_min).to_pixels(); + let stage_height = (stage_size.y_max - stage_size.y_min).to_pixels(); - file_result.vm_type = vm_type; + file_result.compression = Some(swf.header.compression().into()); + file_result.version = Some(swf.header.version()); + file_result.stage_size = Some(format!("{}x{}", stage_width, stage_height)); + file_result.frame_rate = Some(swf.header.frame_rate().into()); + file_result.num_frames = Some(swf.header.num_frames()); + file_result.use_direct_blit = Some(swf.header.use_direct_blit()); + file_result.use_gpu = Some(swf.header.use_gpu()); + file_result.use_network_sandbox = Some(swf.header.use_network_sandbox()); + file_result.vm_type = Some(match swf.header.is_action_script_3() { + true => AvmType::Avm2, + false => AvmType::Avm1, + }); } Err(e) => { file_result.error = Some(format!("Parse error: {}", e.to_string())); diff --git a/scanner/src/file_results.rs b/scanner/src/file_results.rs index c1c7a0669..b517a78f9 100644 --- a/scanner/src/file_results.rs +++ b/scanner/src/file_results.rs @@ -14,6 +14,23 @@ pub enum AvmType { Avm2, } +#[derive(Serialize, Deserialize, Debug)] +pub enum Compression { + None, + Zlib, + Lzma, +} + +impl From for Compression { + fn from(sc: swf::Compression) -> Self { + match sc { + swf::Compression::None => Compression::None, + swf::Compression::Zlib => Compression::Zlib, + swf::Compression::Lzma => Compression::Lzma, + } + } +} + /// A particular step in the scanner process. #[derive(Serialize, Deserialize, Debug)] pub enum Step { @@ -58,6 +75,30 @@ pub struct FileResults { /// Any errors encountered while testing. pub error: Option, + /// The compression type this SWF uses. + pub compression: Option, + + /// The file format version of this SWF. + pub version: Option, + + /// The stage size of this SWF. + pub stage_size: Option, + + /// The frame rate of this SWF. + pub frame_rate: Option, + + /// The number of frames this SWF claims to contain. + pub num_frames: Option, + + /// Whether or not the SWF requests hardware-accelerated presentation. + pub use_direct_blit: Option, + + /// Whether or not the SWF requests hardware-accelerated compositing. + pub use_gpu: Option, + + /// Whether or not the SWF requests network access when ran locally. + pub use_network_sandbox: Option, + /// The AVM type of the movie. pub vm_type: Option, } @@ -76,6 +117,14 @@ impl FileResults { progress: Step::Start, testing_time: 0, error: None, + compression: None, + version: None, + stage_size: None, + frame_rate: None, + num_frames: None, + use_direct_blit: None, + use_gpu: None, + use_network_sandbox: None, vm_type: None, } } diff --git a/scanner/src/scan.rs b/scanner/src/scan.rs index 0b9c2e562..3b7c74342 100644 --- a/scanner/src/scan.rs +++ b/scanner/src/scan.rs @@ -107,6 +107,14 @@ pub fn scan_main(opt: ScanOpt) -> Result<(), std::io::Error> { "Progress", "Test Duration", "Error", + "Compression", + "SWF Version", + "Stage Size", + "Frame Rate", + "Number of Frames", + "Direct Blit", + "GPU", + "Network Sandbox", "AVM Version", ])?;