diff --git a/crates/cli/src/main.rs b/crates/cli/src/main.rs index c7f8482..42d3cd4 100644 --- a/crates/cli/src/main.rs +++ b/crates/cli/src/main.rs @@ -70,6 +70,12 @@ struct Opt { /// Frame rate of the output SWF. #[arg(long, default_value_t = 24.0, help_heading = "Generated SWF Options")] frame_rate: f32, + + /// Whether the SWF uses the network sandbox. + /// If set, the SWF is allowed to make network requests but cannot access local files. + /// If not set, the SWF can access local files but cannot make network requests. + #[arg(long, help_heading = "Generated SWF Options")] + use_network_sandbox: bool, } fn main() -> Result<()> { @@ -97,7 +103,11 @@ fn main() -> Result<()> { .output .or_else(|| opt.script.first().map(|s| s.with_extension("swf"))) .unwrap_or_else(|| PathBuf::from("output.swf")); - let swf = pcode.to_swf(&SwfOptions::default().with_frame_rate(opt.frame_rate))?; + let swf = pcode.to_swf( + &SwfOptions::default() + .with_frame_rate(opt.frame_rate) + .with_network_sandbox(opt.use_network_sandbox), + )?; fs::write(&output_path, swf)?; Ok(()) } diff --git a/crates/rascal/src/program.rs b/crates/rascal/src/program.rs index 2bafcee..a3fb8be 100644 --- a/crates/rascal/src/program.rs +++ b/crates/rascal/src/program.rs @@ -16,6 +16,7 @@ pub struct SwfOptions { pub(crate) stage_y_min: f64, pub(crate) stage_x_max: f64, pub(crate) stage_y_max: f64, + pub(crate) use_network_sandbox: bool, } impl Default for SwfOptions { @@ -26,6 +27,7 @@ impl Default for SwfOptions { stage_y_min: 0.0, stage_x_max: 100.0, stage_y_max: 100.0, + use_network_sandbox: false, } } } @@ -49,6 +51,11 @@ impl SwfOptions { self.stage_y_max = stage_y_max; self } + + pub fn with_network_sandbox(mut self, use_network_sandbox: bool) -> Self { + self.use_network_sandbox = use_network_sandbox; + self + } } #[derive(Debug, Clone, Serialize)] diff --git a/crates/rascal/src/swf.rs b/crates/rascal/src/swf.rs index e97f220..c668936 100644 --- a/crates/rascal/src/swf.rs +++ b/crates/rascal/src/swf.rs @@ -6,7 +6,7 @@ use std::collections::HashMap; use std::io::Result; use std::io::Write; use swf::write::SwfWriteExt; -use swf::{CharacterId, ExportedAsset, Fixed8, Sprite, SwfStr, Tag, Twips}; +use swf::{CharacterId, ExportedAsset, FileAttributes, Fixed8, Sprite, SwfStr, Tag, Twips}; impl<'a> ActionEncoder<'a> {} @@ -38,7 +38,16 @@ pub(crate) fn pcode_to_swf( modules.push((format!("__Packages.{}", name), result.output)); } - let mut tags = vec![Tag::SetBackgroundColor(swf::Color::WHITE)]; + let mut file_attributes = FileAttributes::empty(); + file_attributes.set( + FileAttributes::USE_NETWORK_SANDBOX, + swf_options.use_network_sandbox, + ); + + let mut tags = vec![ + Tag::FileAttributes(file_attributes), + Tag::SetBackgroundColor(swf::Color::WHITE), + ]; for initializer in &initializers { tags.push(Tag::DoAction(initializer)) }