Skip to content

Commit 9d5761d

Browse files
committed
Support network_sandbox (FileAttributes swf tag) through API and CLI
1 parent 03226e7 commit 9d5761d

4 files changed

Lines changed: 29 additions & 3 deletions

File tree

‎crates/cli/src/main.rs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ struct Opt {
7070
/// Frame rate of the output SWF.
7171
#[arg(long, default_value_t = 24.0, help_heading = "Generated SWF Options")]
7272
frame_rate: f32,
73+
74+
/// Whether the SWF uses the network sandbox.
75+
/// If set, the SWF is allowed to make network requests but cannot access local files.
76+
/// If not set, the SWF can access local files but cannot make network requests.
77+
#[arg(long, help_heading = "Generated SWF Options")]
78+
use_network_sandbox: bool,
7379
}
7480

7581
fn main() -> Result<()> {
@@ -97,7 +103,11 @@ fn main() -> Result<()> {
97103
.output
98104
.or_else(|| opt.script.first().map(|s| s.with_extension("swf")))
99105
.unwrap_or_else(|| PathBuf::from("output.swf"));
100-
let swf = pcode.to_swf(&SwfOptions::default().with_frame_rate(opt.frame_rate))?;
106+
let swf = pcode.to_swf(
107+
&SwfOptions::default()
108+
.with_frame_rate(opt.frame_rate)
109+
.with_network_sandbox(opt.use_network_sandbox),
110+
)?;
101111
fs::write(&output_path, swf)?;
102112
Ok(())
103113
}

‎crates/rascal/src/program.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub struct SwfOptions {
1616
pub(crate) stage_y_min: f64,
1717
pub(crate) stage_x_max: f64,
1818
pub(crate) stage_y_max: f64,
19+
pub(crate) use_network_sandbox: bool,
1920
}
2021

2122
impl Default for SwfOptions {
@@ -26,6 +27,7 @@ impl Default for SwfOptions {
2627
stage_y_min: 0.0,
2728
stage_x_max: 100.0,
2829
stage_y_max: 100.0,
30+
use_network_sandbox: false,
2931
}
3032
}
3133
}
@@ -49,6 +51,11 @@ impl SwfOptions {
4951
self.stage_y_max = stage_y_max;
5052
self
5153
}
54+
55+
pub fn with_network_sandbox(mut self, use_network_sandbox: bool) -> Self {
56+
self.use_network_sandbox = use_network_sandbox;
57+
self
58+
}
5259
}
5360

5461
#[derive(Debug, Clone, Serialize)]

‎crates/rascal/src/swf.rs‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::collections::HashMap;
66
use std::io::Result;
77
use std::io::Write;
88
use swf::write::SwfWriteExt;
9-
use swf::{CharacterId, ExportedAsset, Fixed8, Sprite, SwfStr, Tag, Twips};
9+
use swf::{CharacterId, ExportedAsset, FileAttributes, Fixed8, Sprite, SwfStr, Tag, Twips};
1010

1111
impl<'a> ActionEncoder<'a> {}
1212

@@ -38,7 +38,16 @@ pub(crate) fn pcode_to_swf(
3838
modules.push((format!("__Packages.{}", name), result.output));
3939
}
4040

41-
let mut tags = vec![Tag::SetBackgroundColor(swf::Color::WHITE)];
41+
let mut file_attributes = FileAttributes::empty();
42+
file_attributes.set(
43+
FileAttributes::USE_NETWORK_SANDBOX,
44+
swf_options.use_network_sandbox,
45+
);
46+
47+
let mut tags = vec![
48+
Tag::FileAttributes(file_attributes),
49+
Tag::SetBackgroundColor(swf::Color::WHITE),
50+
];
4251
for initializer in &initializers {
4352
tags.push(Tag::DoAction(initializer))
4453
}

‎output.swf‎

52 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)