From 074cc4bc8e1fa676f454d0c194af941419e9c78f Mon Sep 17 00:00:00 2001 From: David Wendt Date: Mon, 23 Aug 2021 19:24:52 -0400 Subject: [PATCH] scanner: Report the AVM version of every scanned file --- Cargo.lock | 1 + scanner/Cargo.toml | 1 + scanner/src/main.rs | 29 +++++++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3db1c1fc4..dade992c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3181,6 +3181,7 @@ dependencies = [ "path-slash", "ruffle_core", "serde", + "swf", "walkdir", ] diff --git a/scanner/Cargo.toml b/scanner/Cargo.toml index b20c15d12..81aeab65c 100644 --- a/scanner/Cargo.toml +++ b/scanner/Cargo.toml @@ -15,3 +15,4 @@ serde = { version = "1.0", features = ["derive"] } csv = "1.1" indicatif = "0.16" path-slash = "0.1.4" +swf = { path = "../swf" } diff --git a/scanner/src/main.rs b/scanner/src/main.rs index 11e785d87..cabcb639f 100644 --- a/scanner/src/main.rs +++ b/scanner/src/main.rs @@ -2,6 +2,7 @@ use clap::Clap; use indicatif::{ProgressBar, ProgressStyle}; use path_slash::PathExt; use ruffle_core::swf::{decompress_swf, parse_swf}; +use swf::{FileAttributes, Tag}; use serde::Serialize; use std::path::{Path, PathBuf}; @@ -9,10 +10,17 @@ use std::path::{Path, PathBuf}; use std::panic::catch_unwind; use walkdir::{DirEntry, WalkDir}; +#[derive(Serialize, Debug)] +enum AvmType { + Avm1, + Avm2, +} + #[derive(Serialize, Debug)] struct FileResults { name: String, error: Option, + vm_type: Option, } #[derive(Clap, Debug)] @@ -60,6 +68,7 @@ fn scan_file(file: DirEntry, name: String) -> FileResults { FileResults { name, error: Some(format!("File error: {}", e.to_string())), + vm_type: None, } } } @@ -68,20 +77,36 @@ fn scan_file(file: DirEntry, name: String) -> FileResults { let swf_buf = decompress_swf(&data[..]).unwrap(); match catch_unwind(|| parse_swf(&swf_buf)) { Ok(swf) => match swf { - Ok(_swf) => FileResults { name, error: None }, + 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); + } + } + + FileResults { + name, + error: None, + vm_type, + } + } Err(e) => FileResults { name, error: Some(format!("Parse error: {}", e.to_string())), + vm_type: None, }, }, Err(e) => match e.downcast::() { Ok(e) => FileResults { name, error: Some(format!("PANIC: {}", e.to_string())), + vm_type: None, }, Err(_) => FileResults { name, error: Some("PANIC".to_string()), + vm_type: None, }, }, } @@ -106,7 +131,7 @@ fn main() -> Result<(), std::io::Error> { .progress_chars("##-"), ); - writer.write_record(&["Filename", "Error"])?; + writer.write_record(&["Filename", "Error", "AVM Version"])?; for file in to_scan { let name = file