diff --git a/src/avm1/opcode.rs b/src/avm1/opcode.rs index b88a28600..f76beb43a 100644 --- a/src/avm1/opcode.rs +++ b/src/avm1/opcode.rs @@ -1,7 +1,7 @@ #![allow(clippy::useless_attribute)] #[allow(dead_code)] -#[derive(Debug,PartialEq,Clone,Copy,FromPrimitive)] +#[derive(Debug, PartialEq, Clone, Copy, FromPrimitive)] pub enum OpCode { End = 0x00, diff --git a/src/avm1/read.rs b/src/avm1/read.rs index 69df55570..5e80e723e 100644 --- a/src/avm1/read.rs +++ b/src/avm1/read.rs @@ -1,7 +1,7 @@ #![allow(clippy::unreadable_literal)] -use crate::avm1::types::*; use crate::avm1::opcode::OpCode; +use crate::avm1::types::*; use crate::read::SwfRead; use std::io::{Error, ErrorKind, Read, Result}; @@ -18,10 +18,7 @@ impl SwfRead for Reader { impl Reader { pub fn new(inner: R, version: u8) -> Reader { - Reader { - inner, - version, - } + Reader { inner, version } } pub fn read_action_list(&mut self) -> Result> { @@ -34,7 +31,7 @@ impl Reader { pub fn read_action(&mut self) -> Result> { use num_traits::FromPrimitive; - + let (opcode, length) = self.read_opcode_and_length()?; let mut action_reader = Reader::new(self.inner.by_ref().take(length as u64), self.version); @@ -123,13 +120,17 @@ impl Reader { } OpCode::GotoLabel => Action::GotoLabel(action_reader.read_c_string()?), OpCode::Greater => Action::Greater, - OpCode::If => Action::If { offset: action_reader.read_i16()? }, + OpCode::If => Action::If { + offset: action_reader.read_i16()?, + }, OpCode::ImplementsOp => Action::ImplementsOp, OpCode::Increment => Action::Increment, OpCode::InitArray => Action::InitArray, OpCode::InitObject => Action::InitObject, OpCode::InstanceOf => Action::InstanceOf, - OpCode::Jump => Action::Jump { offset: action_reader.read_i16()? }, + OpCode::Jump => Action::Jump { + offset: action_reader.read_i16()?, + }, OpCode::Less => Action::Less, OpCode::Less2 => Action::Less2, OpCode::MBAsciiToChar => Action::MBAsciiToChar, @@ -195,7 +196,9 @@ impl Reader { (&mut action_reader.inner as &mut Read).take(code_length.into()), self.version, ); - Action::With { actions: with_reader.read_action_list()? } + Action::With { + actions: with_reader.read_action_list()?, + } } OpCode::WaitForFrame2 => Action::WaitForFrame2 { num_actions_to_skip: action_reader.read_u8()?, @@ -221,10 +224,7 @@ impl Reader { fn read_unknown_action(&mut self, opcode: u8, length: usize) -> Result { let mut data = vec![0u8; length]; self.inner.read_exact(&mut data)?; - Ok(Action::Unknown { - opcode, - data, - }) + Ok(Action::Unknown { opcode, data }) } fn read_push_value(&mut self) -> Result { @@ -363,8 +363,7 @@ pub mod tests { // Failed, result doesn't match. panic!( "Incorrectly parsed action.\nRead:\n{:?}\n\nExpected:\n{:?}", - parsed_action, - expected_action + parsed_action, expected_action ); } } diff --git a/src/avm1/types.rs b/src/avm1/types.rs index 97d8abf7d..806232978 100644 --- a/src/avm1/types.rs +++ b/src/avm1/types.rs @@ -38,7 +38,10 @@ pub enum Action { GetMember, GetProperty, GetTime, - GetUrl { url: String, target: String }, + GetUrl { + url: String, + target: String, + }, GetUrl2 { send_vars_method: SendVarsMethod, is_target_sprite: bool, @@ -52,13 +55,17 @@ pub enum Action { }, GotoLabel(String), Greater, - If { offset: i16 }, + If { + offset: i16, + }, ImplementsOp, Increment, InitArray, InitObject, InstanceOf, - Jump { offset: i16 }, + Jump { + offset: i16, + }, Less, Less2, MBAsciiToChar, @@ -107,10 +114,20 @@ pub enum Action { Trace, Try(TryBlock), TypeOf, - WaitForFrame { frame: u16, num_actions_to_skip: u8 }, - WaitForFrame2 { num_actions_to_skip: u8 }, - With { actions: Vec }, - Unknown { opcode: u8, data: Vec }, + WaitForFrame { + frame: u16, + num_actions_to_skip: u8, + }, + WaitForFrame2 { + num_actions_to_skip: u8, + }, + With { + actions: Vec, + }, + Unknown { + opcode: u8, + data: Vec, + }, } #[derive(Clone, Debug, PartialEq)] diff --git a/src/avm1/write.rs b/src/avm1/write.rs index 753e59cd3..67d6df5e7 100644 --- a/src/avm1/write.rs +++ b/src/avm1/write.rs @@ -1,7 +1,7 @@ #![allow(clippy::cyclomatic_complexity, clippy::unreadable_literal)] -use crate::avm1::types::*; use crate::avm1::opcode::OpCode; +use crate::avm1::types::*; use crate::write::SwfWrite; use std::io::{Result, Write}; @@ -18,10 +18,7 @@ impl SwfWrite for Writer { impl Writer { pub fn new(inner: W, version: u8) -> Writer { - Writer { - inner, - version, - } + Writer { inner, version } } pub fn write_action_list(&mut self, actions: &[Action]) -> Result<()> { @@ -69,8 +66,12 @@ impl Writer { let mut fn_writer = Writer::new(&mut action_buf, self.version); fn_writer.write_action_list(actions)?; } - let len = name.len() + 1 + 2 + params.iter().map(|p| p.len() + 1).sum::() + - 2 + action_buf.len(); + let len = name.len() + + 1 + + 2 + + params.iter().map(|p| p.len() + 1).sum::() + + 2 + + action_buf.len(); self.write_action_header(OpCode::DefineFunction, len)?; self.write_c_string(name)?; self.write_u16(params.len() as u16)?; @@ -86,12 +87,16 @@ impl Writer { let mut fn_writer = Writer::new(&mut action_buf, self.version); fn_writer.write_action_list(&function.actions)?; } - let len = function.name.len() + 1 + 3 + - function + let len = function.name.len() + + 1 + + 3 + + function .params .iter() .map(|p| p.name.len() + 2) - .sum::() + 4 + action_buf.len(); + .sum::() + + 4 + + action_buf.len(); let num_registers = function .params .iter() @@ -101,26 +106,25 @@ impl Writer { self.write_c_string(&function.name)?; self.write_u16(function.params.len() as u16)?; self.write_u8(num_registers)?; - let flags = - if function.preload_global { - 0b1_00000000 + let flags = if function.preload_global { + 0b1_00000000 + } else { + 0 + } | if function.preload_parent { + 0b10000000 + } else { + 0 + } | if function.preload_root { 0b1000000 } else { 0 } + | if function.suppress_super { 0b100000 } else { 0 } + | if function.preload_super { 0b10000 } else { 0 } + | if function.suppress_arguments { + 0b1000 } else { 0 - } | - if function.preload_parent { - 0b10000000 - } else { - 0 - } | if function.preload_root { 0b1000000 } else { 0 } | - if function.suppress_super { 0b100000 } else { 0 } | - if function.preload_super { 0b10000 } else { 0 } | - if function.suppress_arguments { - 0b1000 - } else { - 0 - } | if function.preload_arguments { 0b100 } else { 0 } | - if function.suppress_this { 0b10 } else { 0 } | - if function.preload_this { 0b1 } else { 0 }; + } + | if function.preload_arguments { 0b100 } else { 0 } + | if function.suppress_this { 0b10 } else { 0 } + | if function.preload_this { 0b1 } else { 0 }; self.write_u16(flags)?; for param in &function.params { self.write_u8(if let Some(n) = param.register_index { @@ -162,12 +166,12 @@ impl Writer { } => { self.write_action_header(OpCode::GetUrl2, 1)?; let flags = (match send_vars_method { - SendVarsMethod::None => 0, - SendVarsMethod::Get => 1, - SendVarsMethod::Post => 2, - } << 6) | - if is_target_sprite { 0b10 } else { 0 } | - if is_load_vars { 0b1 } else { 0 }; + SendVarsMethod::None => 0, + SendVarsMethod::Get => 1, + SendVarsMethod::Post => 2, + } << 6) + | if is_target_sprite { 0b10 } else { 0 } + | if is_load_vars { 0b1 } else { 0 }; self.write_u8(flags)?; } Action::GetVariable => self.write_action_header(OpCode::GetVariable, 0)?, @@ -228,8 +232,7 @@ impl Writer { .map(|v| match *v { Value::Str(ref string) => string.len() + 2, Value::Null | Value::Undefined => 1, - Value::Register(_) | - Value::Bool(_) => 2, + Value::Register(_) | Value::Bool(_) => 2, Value::Double(_) => 9, Value::Float(_) | Value::Int(_) => 5, Value::ConstantPool(v) => { @@ -299,8 +302,9 @@ impl Writer { } finally_length = fn_writer.inner.len() - (try_length + catch_length); } - let len = 7 + action_buf.len() + - if let Some((CatchVar::Var(ref name), _)) = try_block.catch { + let len = 7 + + action_buf.len() + + if let Some((CatchVar::Var(ref name), _)) = try_block.catch { name.len() + 1 } else { 1 @@ -311,8 +315,8 @@ impl Writer { 0b100 } else { 0 - } | if try_block.finally.is_some() { 0b10 } else { 0 } | - if try_block.catch.is_some() { 0b1 } else { 0 }, + } | if try_block.finally.is_some() { 0b10 } else { 0 } + | if try_block.catch.is_some() { 0b1 } else { 0 }, )?; self.write_u16(try_length as u16)?; self.write_u16(catch_length as u16)?; @@ -333,7 +337,9 @@ impl Writer { self.write_u16(frame)?; self.write_u8(num_actions_to_skip)?; } - Action::WaitForFrame2 { num_actions_to_skip } => { + Action::WaitForFrame2 { + num_actions_to_skip, + } => { self.write_action_header(OpCode::WaitForFrame2, 1)?; self.write_u8(num_actions_to_skip)?; } @@ -432,9 +438,7 @@ mod tests { if written_bytes != expected_bytes { panic!( "Error writing action.\nTag:\n{:?}\n\nWrote:\n{:?}\n\nExpected:\n{:?}", - action, - written_bytes, - expected_bytes + action, written_bytes, expected_bytes ); } } diff --git a/src/avm2/mod.rs b/src/avm2/mod.rs index ef5b63972..37b7a5c22 100644 --- a/src/avm2/mod.rs +++ b/src/avm2/mod.rs @@ -1,5 +1,5 @@ -pub mod types; pub mod read; +pub mod types; pub mod write; mod opcode; diff --git a/src/avm2/opcode.rs b/src/avm2/opcode.rs index 8a98798e9..77c110aaf 100644 --- a/src/avm2/opcode.rs +++ b/src/avm2/opcode.rs @@ -1,7 +1,7 @@ #![allow(clippy::useless_attribute)] #[allow(dead_code)] -#[derive(Debug,PartialEq,Clone,Copy,FromPrimitive)] +#[derive(Debug, PartialEq, Clone, Copy, FromPrimitive)] pub enum OpCode { Add = 0xA0, AddI = 0xC5, diff --git a/src/avm2/read.rs b/src/avm2/read.rs index 78f0c94c0..c4e2f0e7a 100644 --- a/src/avm2/read.rs +++ b/src/avm2/read.rs @@ -90,10 +90,9 @@ impl Reader { } fn read_i24(&mut self) -> Result { - Ok( - i32::from(self.read_u8()?) | (i32::from(self.read_u8()?) << 8) | - (i32::from(self.read_u8()?) << 16), - ) + Ok(i32::from(self.read_u8()?) + | (i32::from(self.read_u8()?) << 8) + | (i32::from(self.read_u8()?) << 16)) } fn read_i32(&mut self) -> Result { let mut n: i32 = 0; @@ -114,7 +113,10 @@ impl Reader { fn read_string(&mut self) -> Result { let len = self.read_u30()? as usize; let mut s = String::with_capacity(len); - self.inner.by_ref().take(len as u64).read_to_string(&mut s)?; + self.inner + .by_ref() + .take(len as u64) + .read_to_string(&mut s)?; Ok(s) } @@ -352,10 +354,7 @@ impl Reader { value: self.read_index()?, }) } - Ok(Metadata { - name, - items, - }) + Ok(Metadata { name, items }) } fn read_instance(&mut self) -> Result { @@ -877,8 +876,7 @@ pub mod tests { // Failed, result doesn't match. panic!( "Incorrectly parsed ABC.\nRead:\n{:?}\n\nExpected:\n{:?}", - parsed, - abc_file + parsed, abc_file ); } } diff --git a/src/avm2/types.rs b/src/avm2/types.rs index 757d59957..efa43b9fa 100644 --- a/src/avm2/types.rs +++ b/src/avm2/types.rs @@ -60,8 +60,12 @@ pub enum Multiname { namespace: Index, name: Index, }, - RTQName { name: Index }, - RTQNameA { name: Index }, + RTQName { + name: Index, + }, + RTQNameA { + name: Index, + }, RTQNameL, RTQNameLA, Multiname { @@ -72,8 +76,12 @@ pub enum Multiname { namespace_set: Index, name: Index, }, - MultinameL { namespace_set: Index }, - MultinameLA { namespace_set: Index }, + MultinameL { + namespace_set: Index, + }, + MultinameLA { + namespace_set: Index, + }, } #[derive(Clone, Debug, PartialEq)] @@ -178,10 +186,22 @@ pub enum TraitKind { type_name: Index, value: Option, }, - Method { disp_id: u32, method: Index }, - Getter { disp_id: u32, method: Index }, - Setter { disp_id: u32, method: Index }, - Class { slot_id: u32, class: Index }, + Method { + disp_id: u32, + method: Index, + }, + Getter { + disp_id: u32, + method: Index, + }, + Setter { + disp_id: u32, + method: Index, + }, + Class { + slot_id: u32, + class: Index, + }, Function { slot_id: u32, function: Index, @@ -209,14 +229,21 @@ pub struct Script { pub enum Op { Add, AddI, - AsType { type_name: Index }, + AsType { + type_name: Index, + }, AsTypeLate, BitAnd, BitNot, BitOr, BitXor, - Call { num_args: u32 }, - CallMethod { index: Index, num_args: u32 }, + Call { + num_args: u32, + }, + CallMethod { + index: Index, + num_args: u32, + }, CallProperty { index: Index, num_args: u32, @@ -229,7 +256,10 @@ pub enum Op { index: Index, num_args: u32, }, - CallStatic { index: Index, num_args: u32 }, + CallStatic { + index: Index, + num_args: u32, + }, CallSuper { index: Index, num_args: u32, @@ -239,15 +269,21 @@ pub enum Op { num_args: u32, }, CheckFilter, - Coerce { index: Index }, + Coerce { + index: Index, + }, CoerceA, CoerceS, - Construct { num_args: u32 }, + Construct { + num_args: u32, + }, ConstructProp { index: Index, num_args: u32, }, - ConstructSuper { num_args: u32 }, + ConstructSuper { + num_args: u32, + }, ConvertB, ConvertD, ConvertI, @@ -259,31 +295,63 @@ pub enum Op { register_name: Index, register: u8, }, - DebugFile { file_name: Index }, - DebugLine { line_num: u32 }, - DecLocal { index: u32 }, - DecLocalI { index: u32 }, + DebugFile { + file_name: Index, + }, + DebugLine { + line_num: u32, + }, + DecLocal { + index: u32, + }, + DecLocalI { + index: u32, + }, Decrement, DecrementI, - DeleteProperty { index: Index }, + DeleteProperty { + index: Index, + }, Divide, Dup, - Dxns { index: Index }, + Dxns { + index: Index, + }, DxnsLate, Equals, EscXAttr, EscXElem, - FindProperty { index: Index }, - FindPropStrict { index: Index }, - GetDescendants { index: Index }, + FindProperty { + index: Index, + }, + FindPropStrict { + index: Index, + }, + GetDescendants { + index: Index, + }, GetGlobalScope, - GetGlobalSlot { index: u32 }, - GetLex { index: Index }, - GetLocal { index: u32 }, - GetProperty { index: Index }, - GetScopeObject { index: u8 }, - GetSlot { index: u32 }, - GetSuper { index: Index }, + GetGlobalSlot { + index: u32, + }, + GetLex { + index: Index, + }, + GetLocal { + index: u32, + }, + GetProperty { + index: Index, + }, + GetScopeObject { + index: u8, + }, + GetSlot { + index: u32, + }, + GetSuper { + index: Index, + }, GreaterEquals, GreaterThan, HasNext, @@ -291,31 +359,71 @@ pub enum Op { object_register: u32, index_register: u32, }, - IfEq { offset: i32 }, - IfFalse { offset: i32 }, - IfGe { offset: i32 }, - IfGt { offset: i32 }, - IfLe { offset: i32 }, - IfLt { offset: i32 }, - IfNge { offset: i32 }, - IfNgt { offset: i32 }, - IfNle { offset: i32 }, - IfNlt { offset: i32 }, - IfNe { offset: i32 }, - IfStrictEq { offset: i32 }, - IfStrictNe { offset: i32 }, - IfTrue { offset: i32 }, + IfEq { + offset: i32, + }, + IfFalse { + offset: i32, + }, + IfGe { + offset: i32, + }, + IfGt { + offset: i32, + }, + IfLe { + offset: i32, + }, + IfLt { + offset: i32, + }, + IfNge { + offset: i32, + }, + IfNgt { + offset: i32, + }, + IfNle { + offset: i32, + }, + IfNlt { + offset: i32, + }, + IfNe { + offset: i32, + }, + IfStrictEq { + offset: i32, + }, + IfStrictNe { + offset: i32, + }, + IfTrue { + offset: i32, + }, In, - IncLocal { index: u32 }, - IncLocalI { index: u32 }, + IncLocal { + index: u32, + }, + IncLocalI { + index: u32, + }, Increment, IncrementI, - InitProperty { index: Index }, + InitProperty { + index: Index, + }, InstanceOf, - IsType { index: Index }, + IsType { + index: Index, + }, IsTypeLate, - Jump { offset: i32 }, - Kill { index: u32 }, + Jump { + offset: i32, + }, + Kill { + index: u32, + }, Label, LessEquals, LessThan, @@ -330,39 +438,73 @@ pub enum Op { Negate, NegateI, NewActivation, - NewArray { num_args: u32 }, - NewCatch { index: Index }, - NewClass { index: Index }, - NewFunction { index: Index }, - NewObject { num_args: u32 }, + NewArray { + num_args: u32, + }, + NewCatch { + index: Index, + }, + NewClass { + index: Index, + }, + NewFunction { + index: Index, + }, + NewObject { + num_args: u32, + }, NextName, NextValue, Nop, Not, Pop, PopScope, - PushByte { value: u8 }, - PushDouble { value: Index }, + PushByte { + value: u8, + }, + PushDouble { + value: Index, + }, PushFalse, - PushInt { value: Index }, - PushNamespace { value: Index }, + PushInt { + value: Index, + }, + PushNamespace { + value: Index, + }, PushNaN, PushNull, PushScope, - PushShort { value: u32 }, // TODO: Is this really a u30? - PushString { value: Index }, + PushShort { + value: u32, + }, // TODO: Is this really a u30? + PushString { + value: Index, + }, PushTrue, - PushUint { value: Index }, + PushUint { + value: Index, + }, PushUndefined, PushWith, ReturnValue, ReturnVoid, RShift, - SetLocal { index: u32 }, - SetGlobalSlot { index: u32 }, - SetProperty { index: Index }, - SetSlot { index: u32 }, - SetSuper { index: Index }, + SetLocal { + index: u32, + }, + SetGlobalSlot { + index: u32, + }, + SetProperty { + index: Index, + }, + SetSlot { + index: u32, + }, + SetSuper { + index: Index, + }, StrictEquals, Subtract, SubtractI, diff --git a/src/avm2/write.rs b/src/avm2/write.rs index 1d4d9496b..338e4585a 100644 --- a/src/avm2/write.rs +++ b/src/avm2/write.rs @@ -293,13 +293,12 @@ impl Writer { } self.write_index(&method.name)?; self.write_u8( - if has_param_names { 0x80 } else { 0 } | if method.needs_dxns { 0x40 } else { 0 } | - if num_optional_params > 0 { 0x08 } else { 0 } | if method.needs_rest { - 0x04 - } else { - 0 - } | if method.needs_activation { 0x02 } else { 0 } | - if method.needs_arguments_object { + if has_param_names { 0x80 } else { 0 } + | if method.needs_dxns { 0x40 } else { 0 } + | if num_optional_params > 0 { 0x08 } else { 0 } + | if method.needs_rest { 0x04 } else { 0 } + | if method.needs_activation { 0x02 } else { 0 } + | if method.needs_arguments_object { 0x01 } else { 0 @@ -396,11 +395,9 @@ impl Writer { 0x08 } else { 0 - } | if instance.is_interface { 0x04 } else { 0 } | if instance.is_final { - 0x02 - } else { - 0 - } | if instance.is_sealed { 0x01 } else { 0 }, + } | if instance.is_interface { 0x04 } else { 0 } + | if instance.is_final { 0x02 } else { 0 } + | if instance.is_sealed { 0x01 } else { 0 }, )?; if let Some(ref namespace) = instance.protected_namespace { @@ -442,11 +439,12 @@ impl Writer { fn write_trait(&mut self, t: &Trait) -> Result<()> { self.write_index(&t.name)?; - let flags = if !t.metadata.is_empty() { 0b0100_0000 } else { 0 } | if t.is_override { - 0b0010_0000 + let flags = if !t.metadata.is_empty() { + 0b0100_0000 } else { 0 - } | if t.is_final { 0b0001_0000 } else { 0 }; + } | if t.is_override { 0b0010_0000 } else { 0 } + | if t.is_final { 0b0001_0000 } else { 0 }; match t.kind { TraitKind::Slot { @@ -990,8 +988,7 @@ pub mod tests { // Failed, result doesn't match. panic!( "Incorrectly written ABC.\nWritten:\n{:?}\n\nExpected:\n{:?}", - out, - bytes + out, bytes ); } } diff --git a/src/read.rs b/src/read.rs index 58d06fa4f..99fd6607b 100644 --- a/src/read.rs +++ b/src/read.rs @@ -1,9 +1,9 @@ #![allow(clippy::float_cmp, clippy::inconsistent_digit_grouping, clippy::unreadable_literal)] +use crate::types::*; use byteorder::{LittleEndian, ReadBytesExt}; use std::collections::HashSet; use std::io::{Error, ErrorKind, Read, Result}; -use crate::types::*; /// Reads SWF data from a stream. pub fn read_swf(input: R) -> Result { @@ -53,18 +53,21 @@ fn make_zlib_reader<'a, R: Read + 'a>(input: R) -> Result> { Ok(Box::new(decoder)) } -#[cfg(not(any(feature = "flate2",feature = "libflate")))] +#[cfg(not(any(feature = "flate2", feature = "libflate")))] fn make_zlib_reader<'a, R: Read + 'a>(_input: R) -> Result> { - Err(Error::new(ErrorKind::InvalidData, "Support for Zlib compressed SWFs is not enabled.")) + Err(Error::new( + ErrorKind::InvalidData, + "Support for Zlib compressed SWFs is not enabled.", + )) } #[cfg(feature = "lzma-support")] fn make_lzma_reader<'a, R: Read + 'a>(mut input: R) -> Result> { // Flash uses a mangled LZMA header, so we have to massage it into the normal // format. + use byteorder::WriteBytesExt; use std::io::{Cursor, Write}; use xz2::stream::{Action, Stream}; - use byteorder::WriteBytesExt; input.read_u32::()?; // Compressed length let mut lzma_properties = [0u8; 5]; input.read_exact(&mut lzma_properties)?; @@ -78,7 +81,10 @@ fn make_lzma_reader<'a, R: Read + 'a>(mut input: R) -> Result> { #[cfg(not(feature = "lzma-support"))] fn make_lzma_reader<'a, R: Read + 'a>(_input: R) -> Result> { - Err(Error::new(ErrorKind::InvalidData, "Support for LZMA compressed SWFs is not enabled.")) + Err(Error::new( + ErrorKind::InvalidData, + "Support for LZMA compressed SWFs is not enabled.", + )) } pub trait SwfRead { @@ -143,9 +149,8 @@ pub trait SwfRead { } // TODO: There is probably a better way to do this. // TODO: Verify ANSI for SWF 5 and earlier. - String::from_utf8(bytes).map_err(|_| { - Error::new(ErrorKind::InvalidData, "Invalid string data") - }) + String::from_utf8(bytes) + .map_err(|_| Error::new(ErrorKind::InvalidData, "Invalid string data")) } } @@ -297,12 +302,7 @@ impl Reader { let r = self.read_u8()?; let g = self.read_u8()?; let b = self.read_u8()?; - Ok(Color { - r, - g, - b, - a: 255, - }) + Ok(Color { r, g, b, a: 255 }) } fn read_rgba(&mut self) -> Result { @@ -310,12 +310,7 @@ impl Reader { let g = self.read_u8()?; let b = self.read_u8()?; let a = self.read_u8()?; - Ok(Color { - r, - g, - b, - a, - }) + Ok(Color { r, g, b, a }) } fn read_color_transform_no_alpha(&mut self) -> Result { @@ -452,19 +447,13 @@ impl Reader { let id = tag_reader.read_u16()?; let mut jpeg_data = Vec::with_capacity(length - 2); tag_reader.input.read_to_end(&mut jpeg_data)?; - Tag::DefineBits { - id, - jpeg_data, - } + Tag::DefineBits { id, jpeg_data } } Some(TagCode::DefineBitsJpeg2) => { let id = tag_reader.read_u16()?; let mut jpeg_data = Vec::with_capacity(length - 2); tag_reader.input.read_to_end(&mut jpeg_data)?; - Tag::DefineBitsJpeg2 { - id, - jpeg_data, - } + Tag::DefineBitsJpeg2 { id, jpeg_data } } Some(TagCode::DefineBitsJpeg3) => tag_reader.read_define_bits_jpeg_3(3)?, Some(TagCode::DefineBitsJpeg4) => tag_reader.read_define_bits_jpeg_3(4)?, @@ -549,9 +538,7 @@ impl Reader { } else { vec![] }; - Tag::EnableTelemetry { - password_hash, - } + Tag::EnableTelemetry { password_hash } } Some(TagCode::ImportAssets) => { let url = tag_reader.read_c_string()?; @@ -563,10 +550,7 @@ impl Reader { name: tag_reader.read_c_string()?, }); } - Tag::ImportAssets { - url, - imports, - } + Tag::ImportAssets { url, imports } } Some(TagCode::ImportAssets2) => { let url = tag_reader.read_c_string()?; @@ -580,10 +564,7 @@ impl Reader { name: tag_reader.read_c_string()?, }); } - Tag::ImportAssets { - url, - imports, - } + Tag::ImportAssets { url, imports } } Some(TagCode::JpegTables) => { @@ -651,10 +632,7 @@ impl Reader { let id = tag_reader.read_u16()?; let mut action_data = Vec::with_capacity(length); tag_reader.input.read_to_end(&mut action_data)?; - Tag::DoInitAction { - id, - action_data, - } + Tag::DoInitAction { id, action_data } } Some(TagCode::EnableDebugger) => Tag::EnableDebugger(tag_reader.read_c_string()?), @@ -724,8 +702,9 @@ impl Reader { Some(TagCode::FrameLabel) => { let label = tag_reader.read_c_string()?; Tag::FrameLabel { - is_anchor: tag_reader.version >= 6 && length > label.len() + 1 && - tag_reader.read_u8()? != 0, + is_anchor: tag_reader.version >= 6 + && length > label.len() + 1 + && tag_reader.read_u8()? != 0, label, } } @@ -760,10 +739,7 @@ impl Reader { let size = length as usize; let mut data = vec![0; size]; tag_reader.input.read_exact(&mut data[..])?; - Tag::Unknown { - tag_code, - data, - } + Tag::Unknown { tag_code, data } } }; @@ -799,15 +775,13 @@ impl Reader { id, is_track_as_menu: false, records, - actions: vec![ - ButtonAction { - conditions: vec![ButtonActionCondition::OverDownToOverUp] - .into_iter() - .collect(), - key_code: None, - action_data: action_data, - }, - ], + actions: vec![ButtonAction { + conditions: vec![ButtonActionCondition::OverDownToOverUp] + .into_iter() + .collect(), + key_code: None, + action_data: action_data, + }], }))) } @@ -1015,10 +989,7 @@ impl Reader { } } - Ok(Tag::DefineFont(Box::new(FontV1 { - id, - glyphs, - }))) + Ok(Tag::DefineFont(Box::new(FontV1 { id, glyphs }))) } fn read_define_font_2(&mut self, version: u8) -> Result { @@ -2605,12 +2576,12 @@ impl Reader { #[cfg(test)] pub mod tests { + use super::*; + use crate::tag_codes::TagCode; + use crate::test_data; use std::fs::File; use std::io::{Cursor, Read}; use std::vec::Vec; - use super::*; - use crate::test_data; - use crate::tag_codes::TagCode; fn reader(data: &[u8]) -> Reader<&[u8]> { let default_version = 13; @@ -2731,22 +2702,8 @@ pub mod tests { .map(|_| reader.read_bit().unwrap()) .collect::>(), [ - false, - true, - false, - true, - false, - true, - false, - true, - false, - false, - true, - false, - false, - true, - false, - true + false, true, false, true, false, true, false, true, false, false, true, false, + false, true, false, true ] ); } @@ -2795,13 +2752,7 @@ pub mod tests { #[test] fn read_fixed8() { let buf = [ - 0b00000000, - 0b00000000, - 0b00000000, - 0b00000001, - 0b10000000, - 0b00000110, - 0b01000000, + 0b00000000, 0b00000000, 0b00000000, 0b00000001, 0b10000000, 0b00000110, 0b01000000, 0b11101011, ]; let mut reader = Reader::new(&buf[..], 1); @@ -3059,8 +3010,7 @@ pub mod tests { // Failed, result doesn't match. panic!( "Incorrectly parsed tag.\nRead:\n{:?}\n\nExpected:\n{:?}", - parsed_tag, - expected_tag + parsed_tag, expected_tag ); } } diff --git a/src/tag_codes.rs b/src/tag_codes.rs index d839e66af..ac8b1a1e2 100644 --- a/src/tag_codes.rs +++ b/src/tag_codes.rs @@ -1,7 +1,7 @@ #![allow(clippy::useless_attribute)] #[allow(dead_code)] -#[derive(Debug,PartialEq,Clone,Copy,FromPrimitive)] +#[derive(Debug, PartialEq, Clone, Copy, FromPrimitive)] pub enum TagCode { End = 0, ShowFrame = 1, diff --git a/src/test_data.rs b/src/test_data.rs index a1fcd76d2..fc9e40051 100644 --- a/src/test_data.rs +++ b/src/test_data.rs @@ -1,15 +1,15 @@ #![allow(clippy::inconsistent_digit_grouping, clippy::unreadable_literal)] use crate::avm1::types::*; -use crate::avm2::types::*; use crate::avm2::read::tests::read_abc_from_file; -use std::fs::File; -use std::vec::Vec; +use crate::avm2::types::*; use crate::read::read_swf; use crate::read::tests::{read_tag_bytes_from_file, read_tag_bytes_from_file_with_index}; use crate::tag_codes::TagCode; use crate::types::*; use crate::write::write_swf; +use std::fs::File; +use std::vec::Vec; #[allow(dead_code)] pub fn echo_swf(filename: &str) { @@ -50,72 +50,10 @@ pub fn tag_tests() -> Vec { Tag::DefineBits { id: 1, jpeg_data: vec![ - 255, - 216, - 255, - 224, - 0, - 16, - 74, - 70, - 73, - 70, - 0, - 1, - 1, - 0, - 0, - 1, - 0, - 1, - 0, - 0, - 255, - 192, - 0, - 17, - 8, - 0, - 5, - 0, - 6, - 3, - 1, - 34, - 0, - 2, - 17, - 1, - 3, - 17, - 1, - 255, - 218, - 0, - 12, - 3, - 1, - 0, - 2, - 17, - 3, - 17, - 0, - 63, - 0, - 252, - 215, - 162, - 138, - 43, - 248, - 28, - 255, - 0, - 180, - 3, - 255, - 217, + 255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 255, + 192, 0, 17, 8, 0, 5, 0, 6, 3, 1, 34, 0, 2, 17, 1, 3, 17, 1, 255, 218, 0, 12, 3, + 1, 0, 2, 17, 3, 17, 0, 63, 0, 252, 215, 162, 138, 43, 248, 28, 255, 0, 180, 3, + 255, 217, ], }, read_tag_bytes_from_file( @@ -128,646 +66,38 @@ pub fn tag_tests() -> Vec { Tag::DefineBitsJpeg2 { id: 1, jpeg_data: vec![ - 255, - 216, - 255, - 219, - 0, - 67, - 0, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 255, - 219, - 0, - 67, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 255, - 196, - 0, - 31, - 0, - 0, - 1, - 5, - 1, - 1, - 1, - 1, - 1, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 255, - 196, - 0, - 181, - 16, - 0, - 2, - 1, - 3, - 3, - 2, - 4, - 3, - 5, - 5, - 4, - 4, - 0, - 0, - 1, - 125, - 1, - 2, - 3, - 0, - 4, - 17, - 5, - 18, - 33, - 49, - 65, - 6, - 19, - 81, - 97, - 7, - 34, - 113, - 20, - 50, - 129, - 145, - 161, - 8, - 35, - 66, - 177, - 193, - 21, - 82, - 209, - 240, - 36, - 51, - 98, - 114, - 130, - 9, - 10, - 22, - 23, - 24, - 25, - 26, - 37, - 38, - 39, - 40, - 41, - 42, - 52, - 53, - 54, - 55, - 56, - 57, - 58, - 67, - 68, - 69, - 70, - 71, - 72, - 73, - 74, - 83, - 84, - 85, - 86, - 87, - 88, - 89, - 90, - 99, - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 115, - 116, - 117, - 118, - 119, - 120, - 121, - 122, - 131, - 132, - 133, - 134, - 135, - 136, - 137, - 138, - 146, - 147, - 148, - 149, - 150, - 151, - 152, - 153, - 154, - 162, - 163, - 164, - 165, - 166, - 167, - 168, - 169, - 170, - 178, - 179, - 180, - 181, - 182, - 183, - 184, - 185, - 186, - 194, - 195, - 196, - 197, - 198, - 199, - 200, - 201, - 202, - 210, - 211, - 212, - 213, - 214, - 215, - 216, - 217, - 218, - 225, - 226, - 227, - 228, - 229, - 230, - 231, - 232, - 233, - 234, - 241, - 242, - 243, - 244, - 245, - 246, - 247, - 248, - 249, - 250, - 255, - 196, - 0, - 31, - 1, - 0, - 3, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 255, - 196, - 0, - 181, - 17, - 0, - 2, - 1, - 2, - 4, - 4, - 3, - 4, - 7, - 5, - 4, - 4, - 0, - 1, - 2, - 119, - 0, - 1, - 2, - 3, - 17, - 4, - 5, - 33, - 49, - 6, - 18, - 65, - 81, - 7, - 97, - 113, - 19, - 34, - 50, - 129, - 8, - 20, - 66, - 145, - 161, - 177, - 193, - 9, - 35, - 51, - 82, - 240, - 21, - 98, - 114, - 209, - 10, - 22, - 36, - 52, - 225, - 37, - 241, - 23, - 24, - 25, - 26, - 38, - 39, - 40, - 41, - 42, - 53, - 54, - 55, - 56, - 57, - 58, - 67, - 68, - 69, - 70, - 71, - 72, - 73, - 74, - 83, - 84, - 85, - 86, - 87, - 88, - 89, - 90, - 99, - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 115, - 116, - 117, - 118, - 119, - 120, - 121, - 122, - 130, - 131, - 132, - 133, - 134, - 135, - 136, - 137, - 138, - 146, - 147, - 148, - 149, - 150, - 151, - 152, - 153, - 154, - 162, - 163, - 164, - 165, - 166, - 167, - 168, - 169, - 170, - 178, - 179, - 180, - 181, - 182, - 183, - 184, - 185, - 186, - 194, - 195, - 196, - 197, - 198, - 199, - 200, - 201, - 202, - 210, - 211, - 212, - 213, - 214, - 215, - 216, - 217, - 218, - 226, - 227, - 228, - 229, - 230, - 231, - 232, - 233, - 234, - 242, - 243, - 244, - 245, - 246, - 247, - 248, - 249, - 250, - 255, - 217, - 255, - 216, - 255, - 224, - 0, - 16, - 74, - 70, - 73, - 70, - 0, - 1, - 1, - 0, - 0, - 1, - 0, - 1, - 0, - 0, - 255, - 192, - 0, - 17, - 8, - 0, - 5, - 0, - 5, - 3, - 1, - 34, - 0, - 2, - 17, - 1, - 3, - 17, - 1, - 255, - 218, - 0, - 12, - 3, - 1, - 0, - 2, - 17, - 3, - 17, - 0, - 63, - 0, - 252, - 215, - 162, - 138, - 43, - 248, - 28, - 255, - 0, - 180, - 3, - 255, - 217, + 255, 216, 255, 219, 0, 67, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 255, 219, 0, + 67, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 255, 196, 0, 31, 0, 0, 1, 5, 1, 1, 1, + 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, + 0, 181, 16, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 125, 1, 2, 3, 0, 4, + 17, 5, 18, 33, 49, 65, 6, 19, 81, 97, 7, 34, 113, 20, 50, 129, 145, 161, 8, 35, + 66, 177, 193, 21, 82, 209, 240, 36, 51, 98, 114, 130, 9, 10, 22, 23, 24, 25, + 26, 37, 38, 39, 40, 41, 42, 52, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, + 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, + 115, 116, 117, 118, 119, 120, 121, 122, 131, 132, 133, 134, 135, 136, 137, 138, + 146, 147, 148, 149, 150, 151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, + 169, 170, 178, 179, 180, 181, 182, 183, 184, 185, 186, 194, 195, 196, 197, 198, + 199, 200, 201, 202, 210, 211, 212, 213, 214, 215, 216, 217, 218, 225, 226, 227, + 228, 229, 230, 231, 232, 233, 234, 241, 242, 243, 244, 245, 246, 247, 248, 249, + 250, 255, 196, 0, 31, 1, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, + 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, 0, 181, 17, 0, 2, 1, 2, 4, 4, 3, 4, + 7, 5, 4, 4, 0, 1, 2, 119, 0, 1, 2, 3, 17, 4, 5, 33, 49, 6, 18, 65, 81, 7, 97, + 113, 19, 34, 50, 129, 8, 20, 66, 145, 161, 177, 193, 9, 35, 51, 82, 240, 21, + 98, 114, 209, 10, 22, 36, 52, 225, 37, 241, 23, 24, 25, 26, 38, 39, 40, 41, 42, + 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, + 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, + 121, 122, 130, 131, 132, 133, 134, 135, 136, 137, 138, 146, 147, 148, 149, 150, + 151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, 169, 170, 178, 179, 180, + 181, 182, 183, 184, 185, 186, 194, 195, 196, 197, 198, 199, 200, 201, 202, 210, + 211, 212, 213, 214, 215, 216, 217, 218, 226, 227, 228, 229, 230, 231, 232, 233, + 234, 242, 243, 244, 245, 246, 247, 248, 249, 250, 255, 217, 255, 216, 255, 224, + 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 255, 192, 0, 17, 8, 0, 5, + 0, 5, 3, 1, 34, 0, 2, 17, 1, 3, 17, 1, 255, 218, 0, 12, 3, 1, 0, 2, 17, 3, 17, + 0, 63, 0, 252, 215, 162, 138, 43, 248, 28, 255, 0, 180, 3, 255, 217, ], }, read_tag_bytes_from_file( @@ -782,294 +112,18 @@ pub fn tag_tests() -> Vec { version: 3, deblocking: 0.0, data: vec![ - 255, - 216, - 255, - 224, - 0, - 16, - 74, - 70, - 73, - 70, - 0, - 1, - 1, - 0, - 0, - 1, - 0, - 1, - 0, - 0, - 255, - 219, - 0, - 67, - 0, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 255, - 219, - 0, - 67, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 255, - 192, - 0, - 17, - 8, - 0, - 8, - 0, - 8, - 3, - 1, - 34, - 0, - 2, - 17, - 1, - 3, - 17, - 1, - 255, - 196, - 0, - 21, - 0, - 1, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 10, - 255, - 196, - 0, - 20, - 16, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 255, - 196, - 0, - 21, - 1, - 1, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 7, - 9, - 255, - 196, - 0, - 20, - 17, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 255, - 218, - 0, - 12, - 3, - 1, - 0, - 2, - 17, - 3, - 17, - 0, - 63, - 0, - 134, - 240, - 23, - 224, - 94, - 255, - 217, + 255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 255, + 219, 0, 67, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 255, 219, 0, 67, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 255, 192, 0, 17, 8, 0, 8, 0, 8, 3, 1, 34, 0, 2, 17, + 1, 3, 17, 1, 255, 196, 0, 21, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 10, 255, 196, 0, 20, 16, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 255, 196, 0, 21, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, + 255, 196, 0, 20, 17, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, + 218, 0, 12, 3, 1, 0, 2, 17, 3, 17, 0, 63, 0, 134, 240, 23, 224, 94, 255, 217, ], alpha_data: vec![120, 218, 107, 104, 160, 12, 0, 0, 16, 124, 32, 1], }), @@ -1079,31 +133,31 @@ pub fn tag_tests() -> Vec { ), ), /* TODO(Herschel): How do I get Flash to generate a DefineBitsJPEG4 tag? - ( - 10, - Tag::DefineBitsJpeg3(DefineBitsJpeg3 { - id: 1, - version: 4, - deblocking: 0.0, - data: vec![ - 255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0,0, 255, 219, - 0, 67, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 255, 219, 0, 67, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 255, 192, 0, 17, 8, 0, 8, 0, 8, 3, 1, 34, 0, 2, 17, 1, 3, 17, 1, 255, 196, 0, 21, - 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 255, 196, 0, 20, 16, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 196, 0, 21, 1, 1, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 255, 196, 0, 20, 17, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 218, 0, 12, 3, 1, 0, 2, 17, 3, 17, 0, 63, 0, 134, - 240, 23, 224, 94, 255, 217 - ], - alpha_data: vec![120, 218, 107, 104, 160, 12, 0, 0, 16, 124, 32, 1], - }), - read_tag_bytes_from_file("tests/swfs/DefineBitsJpeg4-CC.swf", TagCode::DefineBitsJpeg4) - ), - */ + ( + 10, + Tag::DefineBitsJpeg3(DefineBitsJpeg3 { + id: 1, + version: 4, + deblocking: 0.0, + data: vec![ + 255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 1, 0, 0, 1, 0, 1, 0,0, 255, 219, + 0, 67, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 255, 219, 0, 67, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 255, 192, 0, 17, 8, 0, 8, 0, 8, 3, 1, 34, 0, 2, 17, 1, 3, 17, 1, 255, 196, 0, 21, + 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 255, 196, 0, 20, 16, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 196, 0, 21, 1, 1, 1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 255, 196, 0, 20, 17, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 218, 0, 12, 3, 1, 0, 2, 17, 3, 17, 0, 63, 0, 134, + 240, 23, 224, 94, 255, 217 + ], + alpha_data: vec![120, 218, 107, 104, 160, 12, 0, 0, 16, 124, 32, 1], + }), + read_tag_bytes_from_file("tests/swfs/DefineBitsJpeg4-CC.swf", TagCode::DefineBitsJpeg4) + ), + */ ( 3, Tag::DefineBitsLossless(DefineBitsLossless { @@ -1114,21 +168,7 @@ pub fn tag_tests() -> Vec { height: 8, num_colors: 0, data: vec![ - 120, - 218, - 251, - 207, - 192, - 240, - 255, - 255, - 8, - 198, - 0, - 4, - 128, - 127, - 129, + 120, 218, 251, 207, 192, 240, 255, 255, 8, 198, 0, 4, 128, 127, 129, ], }), read_tag_bytes_from_file( @@ -1146,21 +186,7 @@ pub fn tag_tests() -> Vec { height: 8, num_colors: 0, data: vec![ - 120, - 218, - 107, - 96, - 96, - 168, - 107, - 24, - 193, - 24, - 0, - 227, - 81, - 63, - 129, + 120, 218, 107, 96, 96, 168, 107, 24, 193, 24, 0, 227, 81, 63, 129, ], }), read_tag_bytes_from_file( @@ -1197,15 +223,13 @@ pub fn tag_tests() -> Vec { blend_mode: BlendMode::Normal, }, ], - actions: vec![ - ButtonAction { - conditions: vec![ButtonActionCondition::OverDownToOverUp] - .into_iter() - .collect(), - key_code: None, - action_data: vec![0], - }, - ], + actions: vec![ButtonAction { + conditions: vec![ButtonActionCondition::OverDownToOverUp] + .into_iter() + .collect(), + key_code: None, + action_data: vec![0], + }], })), read_tag_bytes_from_file("tests/swfs/definebutton.swf", TagCode::DefineButton), ), @@ -1232,13 +256,11 @@ pub fn tag_tests() -> Vec { b_add: 0, a_add: 0, }, - filters: vec![ - Filter::BlurFilter(Box::new(BlurFilter { - blur_x: 5f64, - blur_y: 5f64, - num_passes: 1, - })), - ], + filters: vec![Filter::BlurFilter(Box::new(BlurFilter { + blur_x: 5f64, + blur_y: 5f64, + num_passes: 1, + }))], blend_mode: BlendMode::Difference, }, ButtonRecord { @@ -1472,130 +494,130 @@ pub fn tag_tests() -> Vec { read_tag_bytes_from_file("tests/swfs/DefineEditText-MX.swf", TagCode::DefineFont2), ), /* TODO(Herschel): Flash writes out zero rectangles with 1-bit, - * Causing this test to fail. - ( - 6, - Tag::DefineFont2(Box::new(Font2 { - version: 2, - id: 1, - name: "Verdana\u{0}".to_string(), - is_small_text: false, - is_ansi: false, - is_shift_jis: false, - is_italic: false, - is_bold: false, - language: Language::Latin, - layout: Some(Font2Layout { - ascent: 1030, - descent: 215, - leading: 221, - kerning: vec![], - }), - glyphs: vec![ - Glyph2 { - code: 33, - advance: Some(403), - bounds: Some(Rectangle { - x_min: 0.0, - x_max: 0.0, - y_min: 0.0, - y_max: 0.0, - }), - shape_records: vec![ - ShapeRecord::StyleChange(StyleChangeData { - move_to: Some((12.9, -37.2)), - fill_style_0: Some(1), - fill_style_1: None, - line_style: None, - new_styles: None + * Causing this test to fail. + ( + 6, + Tag::DefineFont2(Box::new(Font2 { + version: 2, + id: 1, + name: "Verdana\u{0}".to_string(), + is_small_text: false, + is_ansi: false, + is_shift_jis: false, + is_italic: false, + is_bold: false, + language: Language::Latin, + layout: Some(Font2Layout { + ascent: 1030, + descent: 215, + leading: 221, + kerning: vec![], + }), + glyphs: vec![ + Glyph2 { + code: 33, + advance: Some(403), + bounds: Some(Rectangle { + x_min: 0.0, + x_max: 0.0, + y_min: 0.0, + y_max: 0.0, }), - ShapeRecord::StraightEdge { delta_x: -0.65, delta_y: 26.95 }, - ShapeRecord::StraightEdge { delta_x: -4.25, delta_y: 0.0 }, - ShapeRecord::StraightEdge { delta_x: -0.7, delta_y: -26.95 }, - ShapeRecord::StraightEdge { delta_x: 5.6, delta_y: 0.0 }, - ShapeRecord::StyleChange(StyleChangeData { - move_to: Some((12.65, 0.0)), - fill_style_0: None, - fill_style_1: None, - line_style: None, - new_styles: None - }), - ShapeRecord::StraightEdge { delta_x: -5.1, delta_y: 0.0 }, - ShapeRecord::StraightEdge { delta_x: 0.0, delta_y: -5.25 }, - ShapeRecord::StraightEdge { delta_x: 5.1, delta_y: 0.0 }, - ShapeRecord::StraightEdge { delta_x: 0.0, delta_y: 5.25 } - ], - } - ], - })), - read_tag_bytes_from_file("tests/swfs/DefineFont2-CS55.swf", TagCode::DefineFont2) - ), - - ( - 8, - Tag::DefineFont2(Box::new(Font { - version: 3, - id: 1, - name: "Dummy\u{0}".to_string(), // TODO(Herschel): Extra null byte? - is_small_text: false, - is_ansi: false, - is_shift_jis: false, - is_italic: false, - is_bold: false, - language: Language::Latin, - layout: Some(FontLayout { - ascent: 17160, - descent: 4180, - leading: 860, - kerning: vec![ - KerningRecord { left_code: 65, right_code: 65, adjustment: -5000 }, - KerningRecord { left_code: 66, right_code: 65, adjustment: -25536 }, - KerningRecord { left_code: 65, right_code: 66, adjustment: -15000 }, - KerningRecord { left_code: 66, right_code: 66, adjustment: -5000 }, + shape_records: vec![ + ShapeRecord::StyleChange(StyleChangeData { + move_to: Some((12.9, -37.2)), + fill_style_0: Some(1), + fill_style_1: None, + line_style: None, + new_styles: None + }), + ShapeRecord::StraightEdge { delta_x: -0.65, delta_y: 26.95 }, + ShapeRecord::StraightEdge { delta_x: -4.25, delta_y: 0.0 }, + ShapeRecord::StraightEdge { delta_x: -0.7, delta_y: -26.95 }, + ShapeRecord::StraightEdge { delta_x: 5.6, delta_y: 0.0 }, + ShapeRecord::StyleChange(StyleChangeData { + move_to: Some((12.65, 0.0)), + fill_style_0: None, + fill_style_1: None, + line_style: None, + new_styles: None + }), + ShapeRecord::StraightEdge { delta_x: -5.1, delta_y: 0.0 }, + ShapeRecord::StraightEdge { delta_x: 0.0, delta_y: -5.25 }, + ShapeRecord::StraightEdge { delta_x: 5.1, delta_y: 0.0 }, + ShapeRecord::StraightEdge { delta_x: 0.0, delta_y: 5.25 } + ], + } ], - }), - glyphs: vec![ - Glyph { - shape_records: vec![ - ShapeRecord::StyleChange(StyleChangeData { - move_to: Some((205.5, -527.5)), - fill_style_0: Some(1), - fill_style_1: None, - line_style: None, - new_styles: None } - ), - ShapeRecord::StraightEdge { delta_x: 371.0, delta_y: 0.0 }, - ShapeRecord::StraightEdge { delta_x: 0.0, delta_y: 65.0 }, - ShapeRecord::StraightEdge { delta_x: -371.0, delta_y: 0.0 }, - ShapeRecord::StraightEdge { delta_x: 0.0, delta_y: -65.0 } + })), + read_tag_bytes_from_file("tests/swfs/DefineFont2-CS55.swf", TagCode::DefineFont2) + ), + + ( + 8, + Tag::DefineFont2(Box::new(Font { + version: 3, + id: 1, + name: "Dummy\u{0}".to_string(), // TODO(Herschel): Extra null byte? + is_small_text: false, + is_ansi: false, + is_shift_jis: false, + is_italic: false, + is_bold: false, + language: Language::Latin, + layout: Some(FontLayout { + ascent: 17160, + descent: 4180, + leading: 860, + kerning: vec![ + KerningRecord { left_code: 65, right_code: 65, adjustment: -5000 }, + KerningRecord { left_code: 66, right_code: 65, adjustment: -25536 }, + KerningRecord { left_code: 65, right_code: 66, adjustment: -15000 }, + KerningRecord { left_code: 66, right_code: 66, adjustment: -5000 }, ], - code: 65, - advance: Some(15400), - bounds: Some(Rectangle { x_min: 0.0, x_max: 0.0, y_min: 0.0, y_max: 0.0 }) - }, - Glyph { - shape_records: vec![ - ShapeRecord::StyleChange(StyleChangeData { - move_to: Some((249.0, -694.0)), - fill_style_0: Some(1), - fill_style_1: None, - line_style: None, - new_styles: None - }), - ShapeRecord::StraightEdge { delta_x: 135.5, delta_y: 0.0 }, - ShapeRecord::StraightEdge { delta_x: 0.0, delta_y: 660.5 }, - ShapeRecord::StraightEdge { delta_x: -135.5, delta_y: 0.0 }, - ShapeRecord::StraightEdge { delta_x: 0.0, delta_y: -660.5 } - ], - code: 66, - advance: Some(12200), - bounds: Some(Rectangle { x_min: 0.0, x_max: 0.0, y_min: 0.0, y_max: 0.0 }) - } - ], - })), - read_tag_bytes_from_file("tests/swfs/DefineFont3-CS55.swf", TagCode::DefineFont3) - ), - */ + }), + glyphs: vec![ + Glyph { + shape_records: vec![ + ShapeRecord::StyleChange(StyleChangeData { + move_to: Some((205.5, -527.5)), + fill_style_0: Some(1), + fill_style_1: None, + line_style: None, + new_styles: None } + ), + ShapeRecord::StraightEdge { delta_x: 371.0, delta_y: 0.0 }, + ShapeRecord::StraightEdge { delta_x: 0.0, delta_y: 65.0 }, + ShapeRecord::StraightEdge { delta_x: -371.0, delta_y: 0.0 }, + ShapeRecord::StraightEdge { delta_x: 0.0, delta_y: -65.0 } + ], + code: 65, + advance: Some(15400), + bounds: Some(Rectangle { x_min: 0.0, x_max: 0.0, y_min: 0.0, y_max: 0.0 }) + }, + Glyph { + shape_records: vec![ + ShapeRecord::StyleChange(StyleChangeData { + move_to: Some((249.0, -694.0)), + fill_style_0: Some(1), + fill_style_1: None, + line_style: None, + new_styles: None + }), + ShapeRecord::StraightEdge { delta_x: 135.5, delta_y: 0.0 }, + ShapeRecord::StraightEdge { delta_x: 0.0, delta_y: 660.5 }, + ShapeRecord::StraightEdge { delta_x: -135.5, delta_y: 0.0 }, + ShapeRecord::StraightEdge { delta_x: 0.0, delta_y: -660.5 } + ], + code: 66, + advance: Some(12200), + bounds: Some(Rectangle { x_min: 0.0, x_max: 0.0, y_min: 0.0, y_max: 0.0 }) + } + ], + })), + read_tag_bytes_from_file("tests/swfs/DefineFont3-CS55.swf", TagCode::DefineFont3) + ), + */ ( 8, Tag::DefineFontAlignZones { @@ -1693,51 +715,47 @@ pub fn tag_tests() -> Vec { y_min: 15.0, y_max: 65.0, }, - fill_styles: vec![ - FillStyle::LinearGradient(Gradient { - matrix: Matrix { - translate_x: 40.0, - translate_y: 40.0, - scale_x: 0.024429321, - scale_y: 0.024429321, - rotate_skew_0: 0.024429321, - rotate_skew_1: -0.024429321, - }, - spread: GradientSpread::Pad, - interpolation: GradientInterpolation::RGB, - records: vec![ - GradientRecord { - ratio: 0, - color: Color { - r: 255, - g: 255, - b: 255, - a: 255, - }, + fill_styles: vec![FillStyle::LinearGradient(Gradient { + matrix: Matrix { + translate_x: 40.0, + translate_y: 40.0, + scale_x: 0.024429321, + scale_y: 0.024429321, + rotate_skew_0: 0.024429321, + rotate_skew_1: -0.024429321, + }, + spread: GradientSpread::Pad, + interpolation: GradientInterpolation::RGB, + records: vec![ + GradientRecord { + ratio: 0, + color: Color { + r: 255, + g: 255, + b: 255, + a: 255, }, - GradientRecord { - ratio: 255, - color: Color { - r: 0, - g: 0, - b: 0, - a: 255, - }, - }, - ], - }), - ], - line_styles: vec![ - LineStyle::new_v1( - 200, - Color { - r: 0, - g: 255, - b: 0, - a: 255, }, - ), - ], + GradientRecord { + ratio: 255, + color: Color { + r: 0, + g: 0, + b: 0, + a: 255, + }, + }, + ], + })], + line_styles: vec![LineStyle::new_v1( + 200, + Color { + r: 0, + g: 255, + b: 0, + a: 255, + }, + )], shape: vec![ ShapeRecord::StyleChange(StyleChangeData { move_to: Some((20.0, 20.0)), @@ -1800,51 +818,47 @@ pub fn tag_tests() -> Vec { y_min: 8.35, y_max: 61.0, }, - fill_styles: vec![ - FillStyle::LinearGradient(Gradient { - matrix: Matrix { - translate_x: 48.4, - translate_y: 34.65, - scale_x: 0.0058898926, - scale_y: 0.030914307, - rotate_skew_0: 0.0, - rotate_skew_1: 0.0, - }, - spread: GradientSpread::Pad, - interpolation: GradientInterpolation::RGB, - records: vec![ - GradientRecord { - ratio: 56, - color: Color { - r: 255, - g: 0, - b: 0, - a: 255, - }, + fill_styles: vec![FillStyle::LinearGradient(Gradient { + matrix: Matrix { + translate_x: 48.4, + translate_y: 34.65, + scale_x: 0.0058898926, + scale_y: 0.030914307, + rotate_skew_0: 0.0, + rotate_skew_1: 0.0, + }, + spread: GradientSpread::Pad, + interpolation: GradientInterpolation::RGB, + records: vec![ + GradientRecord { + ratio: 56, + color: Color { + r: 255, + g: 0, + b: 0, + a: 255, }, - GradientRecord { - ratio: 157, - color: Color { - r: 0, - g: 0, - b: 255, - a: 255, - }, - }, - ], - }), - ], - line_styles: vec![ - LineStyle::new_v1( - 40, - Color { - r: 255, - g: 255, - b: 0, - a: 255, }, - ), - ], + GradientRecord { + ratio: 157, + color: Color { + r: 0, + g: 0, + b: 255, + a: 255, + }, + }, + ], + })], + line_styles: vec![LineStyle::new_v1( + 40, + Color { + r: 255, + g: 255, + b: 0, + a: 255, + }, + )], shape: vec![ ShapeRecord::StyleChange(StyleChangeData { move_to: Some((20.0, 60.0)), @@ -1921,71 +935,67 @@ pub fn tag_tests() -> Vec { y_min: 20.0, y_max: 220.0, }, - fill_styles: vec![ - FillStyle::FocalGradient { - gradient: Gradient { - matrix: Matrix { - translate_x: 116.05, - translate_y: 135.05, - scale_x: 0.11468506, - scale_y: 0.18927002, - rotate_skew_0: 0.0, - rotate_skew_1: 0.0, + fill_styles: vec![FillStyle::FocalGradient { + gradient: Gradient { + matrix: Matrix { + translate_x: 116.05, + translate_y: 135.05, + scale_x: 0.11468506, + scale_y: 0.18927002, + rotate_skew_0: 0.0, + rotate_skew_1: 0.0, + }, + spread: GradientSpread::Pad, + interpolation: GradientInterpolation::RGB, + records: vec![ + GradientRecord { + ratio: 0, + color: Color { + r: 255, + g: 0, + b: 0, + a: 255, + }, }, - spread: GradientSpread::Pad, - interpolation: GradientInterpolation::RGB, - records: vec![ - GradientRecord { - ratio: 0, - color: Color { - r: 255, - g: 0, - b: 0, - a: 255, - }, + GradientRecord { + ratio: 70, + color: Color { + r: 255, + g: 0, + b: 255, + a: 255, }, - GradientRecord { - ratio: 70, - color: Color { - r: 255, - g: 0, - b: 255, - a: 255, - }, + }, + GradientRecord { + ratio: 255, + color: Color { + r: 0, + g: 0, + b: 0, + a: 255, }, - GradientRecord { - ratio: 255, - color: Color { - r: 0, - g: 0, - b: 0, - a: 255, - }, - }, - ], - }, - focal_point: 0.97265625, + }, + ], }, - ], - line_styles: vec![ - LineStyle { - width: 200, - color: Color { - r: 0, - g: 255, - b: 0, - a: 255, - }, - start_cap: LineCapStyle::Round, - end_cap: LineCapStyle::Round, - join_style: LineJoinStyle::Round, - fill_style: None, - allow_scale_x: true, - allow_scale_y: true, - is_pixel_hinted: false, - allow_close: true, + focal_point: 0.97265625, + }], + line_styles: vec![LineStyle { + width: 200, + color: Color { + r: 0, + g: 255, + b: 0, + a: 255, }, - ], + start_cap: LineCapStyle::Round, + end_cap: LineCapStyle::Round, + join_style: LineJoinStyle::Round, + fill_style: None, + allow_scale_x: true, + allow_scale_y: true, + is_pixel_hinted: false, + allow_close: true, + }], shape: vec![ ShapeRecord::StyleChange(StyleChangeData { move_to: Some((20.0, 20.0)), @@ -2048,71 +1058,67 @@ pub fn tag_tests() -> Vec { y_min: 16.35, y_max: 147.35, }, - fill_styles: vec![ - FillStyle::FocalGradient { - gradient: Gradient { - matrix: Matrix { - translate_x: 164.0, - translate_y: 150.05, - scale_x: 0.036087036, - scale_y: 0.041992188, - rotate_skew_0: 0.1347351, - rotate_skew_1: -0.15675354, + fill_styles: vec![FillStyle::FocalGradient { + gradient: Gradient { + matrix: Matrix { + translate_x: 164.0, + translate_y: 150.05, + scale_x: 0.036087036, + scale_y: 0.041992188, + rotate_skew_0: 0.1347351, + rotate_skew_1: -0.15675354, + }, + spread: GradientSpread::Pad, + interpolation: GradientInterpolation::RGB, + records: vec![ + GradientRecord { + ratio: 0, + color: Color { + r: 0, + g: 255, + b: 255, + a: 255, + }, }, - spread: GradientSpread::Pad, - interpolation: GradientInterpolation::RGB, - records: vec![ - GradientRecord { - ratio: 0, - color: Color { - r: 0, - g: 255, - b: 255, - a: 255, - }, + GradientRecord { + ratio: 183, + color: Color { + r: 0, + g: 255, + b: 0, + a: 255, }, - GradientRecord { - ratio: 183, - color: Color { - r: 0, - g: 255, - b: 0, - a: 255, - }, + }, + GradientRecord { + ratio: 226, + color: Color { + r: 255, + g: 0, + b: 255, + a: 255, }, - GradientRecord { - ratio: 226, - color: Color { - r: 255, - g: 0, - b: 255, - a: 255, - }, - }, - ], - }, - focal_point: -0.9921875, + }, + ], }, - ], - line_styles: vec![ - LineStyle { - width: 40, - color: Color { - r: 255, - g: 255, - b: 0, - a: 255, - }, - start_cap: LineCapStyle::Round, - end_cap: LineCapStyle::Round, - join_style: LineJoinStyle::Round, - fill_style: None, - allow_scale_x: true, - allow_scale_y: true, - is_pixel_hinted: false, - allow_close: true, + focal_point: -0.9921875, + }], + line_styles: vec![LineStyle { + width: 40, + color: Color { + r: 255, + g: 255, + b: 0, + a: 255, }, - ], + start_cap: LineCapStyle::Round, + end_cap: LineCapStyle::Round, + join_style: LineJoinStyle::Round, + fill_style: None, + allow_scale_x: true, + allow_scale_y: true, + is_pixel_hinted: false, + allow_close: true, + }], shape: vec![ ShapeRecord::StyleChange(StyleChangeData { move_to: Some((26.0, 147.35)), @@ -2247,14 +1253,12 @@ pub fn tag_tests() -> Vec { has_non_scaling_strokes: true, has_scaling_strokes: false, styles: ShapeStyles { - fill_styles: vec![ - FillStyle::Color(Color { - r: 255, - g: 0, - b: 0, - a: 255, - }), - ], + fill_styles: vec![FillStyle::Color(Color { + r: 255, + g: 0, + b: 0, + a: 255, + })], line_styles: vec![], }, shape: vec![ @@ -2306,40 +1310,38 @@ pub fn tag_tests() -> Vec { has_non_scaling_strokes: true, has_scaling_strokes: false, styles: ShapeStyles { - fill_styles: vec![ - FillStyle::RadialGradient(Gradient { - matrix: Matrix { - translate_x: 24.95f32, - translate_y: 24.95f32, - scale_x: 0.030731201f32, - scale_y: 0.030731201f32, - rotate_skew_0: 0f32, - rotate_skew_1: 0f32, + fill_styles: vec![FillStyle::RadialGradient(Gradient { + matrix: Matrix { + translate_x: 24.95f32, + translate_y: 24.95f32, + scale_x: 0.030731201f32, + scale_y: 0.030731201f32, + rotate_skew_0: 0f32, + rotate_skew_1: 0f32, + }, + spread: GradientSpread::Pad, + interpolation: GradientInterpolation::RGB, + records: vec![ + GradientRecord { + ratio: 0, + color: Color { + r: 255, + g: 0, + b: 0, + a: 255, + }, }, - spread: GradientSpread::Pad, - interpolation: GradientInterpolation::RGB, - records: vec![ - GradientRecord { - ratio: 0, - color: Color { - r: 255, - g: 0, - b: 0, - a: 255, - }, + GradientRecord { + ratio: 255, + color: Color { + r: 0, + g: 0, + b: 0, + a: 0, }, - GradientRecord { - ratio: 255, - color: Color { - r: 0, - g: 0, - b: 0, - a: 0, - }, - }, - ], - }), - ], + }, + ], + })], line_styles: vec![], }, shape: vec![ @@ -2653,26 +1655,8 @@ pub fn tag_tests() -> Vec { }, num_samples: 10, data: vec![ - 255, - 127, - 0, - 128, - 255, - 127, - 0, - 128, - 255, - 127, - 0, - 128, - 255, - 127, - 0, - 128, - 255, - 127, - 0, - 128, + 255, 127, 0, 128, 255, 127, 0, 128, 255, 127, 0, 128, 255, 127, 0, 128, 255, + 127, 0, 128, ], })), read_tag_bytes_from_file("tests/swfs/definesound.swf", TagCode::DefineSound), @@ -2703,34 +1687,32 @@ pub fn tag_tests() -> Vec { y_max: 18.45, }, matrix: Matrix::new(), - records: vec![ - TextRecord { - font_id: Some(1), - color: Some(Color { - r: 0, - g: 0, - b: 0, - a: 255, - }), - x_offset: None, - y_offset: Some(16.1), - height: Some(320), - glyphs: vec![ - GlyphEntry { - index: 0, - advance: 145, - }, - GlyphEntry { - index: 1, - advance: 203, - }, - GlyphEntry { - index: 0, - advance: 145, - }, - ], - }, - ], + records: vec![TextRecord { + font_id: Some(1), + color: Some(Color { + r: 0, + g: 0, + b: 0, + a: 255, + }), + x_offset: None, + y_offset: Some(16.1), + height: Some(320), + glyphs: vec![ + GlyphEntry { + index: 0, + advance: 145, + }, + GlyphEntry { + index: 1, + advance: 203, + }, + GlyphEntry { + index: 0, + advance: 145, + }, + ], + }], })), read_tag_bytes_from_file("tests/swfs/DefineFont-MX.swf", TagCode::DefineText), ), @@ -2752,9 +1734,9 @@ pub fn tag_tests() -> Vec { ), ( 5, - Tag::DoAction( - vec![150, 10, 0, 0, 84, 101, 115, 116, 105, 110, 103, 33, 0, 38, 0] - ), + Tag::DoAction(vec![ + 150, 10, 0, 0, 84, 101, 115, 116, 105, 110, 103, 33, 0, 38, 0, + ]), read_tag_bytes_from_file("tests/swfs/doaction.swf", TagCode::DoAction), ), ( @@ -2781,38 +1763,8 @@ pub fn tag_tests() -> Vec { 10, Tag::EnableTelemetry { password_hash: vec![ - 207, - 128, - 205, - 138, - 237, - 72, - 45, - 93, - 21, - 39, - 215, - 220, - 114, - 252, - 239, - 248, - 78, - 99, - 38, - 89, - 40, - 72, - 68, - 125, - 45, - 192, - 176, - 232, - 125, - 252, - 154, - 144, + 207, 128, 205, 138, 237, 72, 45, 93, 21, 39, 215, 220, 114, 252, 239, 248, 78, + 99, 38, 89, 40, 72, 68, 125, 45, 192, 176, 232, 125, 252, 154, 144, ], }, read_tag_bytes_from_file( @@ -2822,12 +1774,10 @@ pub fn tag_tests() -> Vec { ), ( 6, - Tag::ExportAssets(vec![ - ExportedAsset { - id: 2, - name: "Test๐Ÿ’ฏ".to_string(), - }, - ]), + Tag::ExportAssets(vec![ExportedAsset { + id: 2, + name: "Test๐Ÿ’ฏ".to_string(), + }]), read_tag_bytes_from_file("tests/swfs/exportassets.swf", TagCode::ExportAssets), ), ( @@ -2869,12 +1819,10 @@ pub fn tag_tests() -> Vec { 7, Tag::ImportAssets { url: "exportassets.swf".to_string(), - imports: vec![ - ExportedAsset { - id: 1, - name: "Test๐Ÿ’ฏ".to_string(), - }, - ], + imports: vec![ExportedAsset { + id: 1, + name: "Test๐Ÿ’ฏ".to_string(), + }], }, read_tag_bytes_from_file("tests/swfs/importassets.swf", TagCode::ImportAssets), ), @@ -2882,592 +1830,44 @@ pub fn tag_tests() -> Vec { 8, Tag::ImportAssets { url: "exportassets.swf".to_string(), - imports: vec![ - ExportedAsset { - id: 1, - name: "Test๐Ÿ’ฏ".to_string(), - }, - ], + imports: vec![ExportedAsset { + id: 1, + name: "Test๐Ÿ’ฏ".to_string(), + }], }, read_tag_bytes_from_file("tests/swfs/importassets2.swf", TagCode::ImportAssets2), ), ( 1, Tag::JpegTables(vec![ - 255, - 216, - 255, - 219, - 0, - 67, - 0, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 255, - 219, - 0, - 67, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 255, - 196, - 0, - 31, - 0, - 0, - 1, - 5, - 1, - 1, - 1, - 1, - 1, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 255, - 196, - 0, - 181, - 16, - 0, - 2, - 1, - 3, - 3, - 2, - 4, - 3, - 5, - 5, - 4, - 4, - 0, - 0, - 1, - 125, - 1, - 2, - 3, - 0, - 4, - 17, - 5, - 18, - 33, - 49, - 65, - 6, - 19, - 81, - 97, - 7, - 34, - 113, - 20, - 50, - 129, - 145, - 161, - 8, - 35, - 66, - 177, - 193, - 21, - 82, - 209, - 240, - 36, - 51, - 98, - 114, - 130, - 9, - 10, - 22, - 23, - 24, - 25, - 26, - 37, - 38, - 39, - 40, - 41, - 42, - 52, - 53, - 54, - 55, - 56, - 57, - 58, - 67, - 68, - 69, - 70, - 71, - 72, - 73, - 74, - 83, - 84, - 85, - 86, - 87, - 88, - 89, - 90, - 99, - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 115, - 116, - 117, - 118, - 119, - 120, - 121, - 122, - 131, - 132, - 133, - 134, - 135, - 136, - 137, - 138, - 146, - 147, - 148, - 149, - 150, - 151, - 152, - 153, - 154, - 162, - 163, - 164, - 165, - 166, - 167, - 168, - 169, - 170, - 178, - 179, - 180, - 181, - 182, - 183, - 184, - 185, - 186, - 194, - 195, - 196, - 197, - 198, - 199, - 200, - 201, - 202, - 210, - 211, - 212, - 213, - 214, - 215, - 216, - 217, - 218, - 225, - 226, - 227, - 228, - 229, - 230, - 231, - 232, - 233, - 234, - 241, - 242, - 243, - 244, - 245, - 246, - 247, - 248, - 249, - 250, - 255, - 196, - 0, - 31, - 1, - 0, - 3, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 255, - 196, - 0, - 181, - 17, - 0, - 2, - 1, - 2, - 4, - 4, - 3, - 4, - 7, - 5, - 4, - 4, - 0, - 1, - 2, - 119, - 0, - 1, - 2, - 3, - 17, - 4, - 5, - 33, - 49, - 6, - 18, - 65, - 81, - 7, - 97, - 113, - 19, - 34, - 50, - 129, - 8, - 20, - 66, - 145, - 161, - 177, - 193, - 9, - 35, - 51, - 82, - 240, - 21, - 98, - 114, - 209, - 10, - 22, - 36, - 52, - 225, - 37, - 241, - 23, - 24, - 25, - 26, - 38, - 39, - 40, - 41, - 42, - 53, - 54, - 55, - 56, - 57, - 58, - 67, - 68, - 69, - 70, - 71, - 72, - 73, - 74, - 83, - 84, - 85, - 86, - 87, - 88, - 89, - 90, - 99, - 100, - 101, - 102, - 103, - 104, - 105, - 106, - 115, - 116, - 117, - 118, - 119, - 120, - 121, - 122, - 130, - 131, - 132, - 133, - 134, - 135, - 136, - 137, - 138, - 146, - 147, - 148, - 149, - 150, - 151, - 152, - 153, - 154, - 162, - 163, - 164, - 165, - 166, - 167, - 168, - 169, - 170, - 178, - 179, - 180, - 181, - 182, - 183, - 184, - 185, - 186, - 194, - 195, - 196, - 197, - 198, - 199, - 200, - 201, - 202, - 210, - 211, - 212, - 213, - 214, - 215, - 216, - 217, - 218, - 226, - 227, - 228, - 229, - 230, - 231, - 232, - 233, - 234, - 242, - 243, - 244, - 245, - 246, - 247, - 248, - 249, - 250, - 255, - 217, + 255, 216, 255, 219, 0, 67, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 255, 219, 0, 67, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 255, 196, 0, 31, 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, 0, 181, 16, 0, 2, 1, 3, 3, 2, 4, 3, + 5, 5, 4, 4, 0, 0, 1, 125, 1, 2, 3, 0, 4, 17, 5, 18, 33, 49, 65, 6, 19, 81, 97, 7, + 34, 113, 20, 50, 129, 145, 161, 8, 35, 66, 177, 193, 21, 82, 209, 240, 36, 51, 98, + 114, 130, 9, 10, 22, 23, 24, 25, 26, 37, 38, 39, 40, 41, 42, 52, 53, 54, 55, 56, + 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, 88, 89, 90, 99, 100, + 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, 121, 122, 131, 132, + 133, 134, 135, 136, 137, 138, 146, 147, 148, 149, 150, 151, 152, 153, 154, 162, + 163, 164, 165, 166, 167, 168, 169, 170, 178, 179, 180, 181, 182, 183, 184, 185, + 186, 194, 195, 196, 197, 198, 199, 200, 201, 202, 210, 211, 212, 213, 214, 215, + 216, 217, 218, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 241, 242, 243, + 244, 245, 246, 247, 248, 249, 250, 255, 196, 0, 31, 1, 0, 3, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 255, 196, 0, 181, 17, 0, + 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 119, 0, 1, 2, 3, 17, 4, 5, 33, 49, 6, 18, + 65, 81, 7, 97, 113, 19, 34, 50, 129, 8, 20, 66, 145, 161, 177, 193, 9, 35, 51, 82, + 240, 21, 98, 114, 209, 10, 22, 36, 52, 225, 37, 241, 23, 24, 25, 26, 38, 39, 40, + 41, 42, 53, 54, 55, 56, 57, 58, 67, 68, 69, 70, 71, 72, 73, 74, 83, 84, 85, 86, 87, + 88, 89, 90, 99, 100, 101, 102, 103, 104, 105, 106, 115, 116, 117, 118, 119, 120, + 121, 122, 130, 131, 132, 133, 134, 135, 136, 137, 138, 146, 147, 148, 149, 150, + 151, 152, 153, 154, 162, 163, 164, 165, 166, 167, 168, 169, 170, 178, 179, 180, + 181, 182, 183, 184, 185, 186, 194, 195, 196, 197, 198, 199, 200, 201, 202, 210, + 211, 212, 213, 214, 215, 216, 217, 218, 226, 227, 228, 229, 230, 231, 232, 233, + 234, 242, 243, 244, 245, 246, 247, 248, 249, 250, 255, 217, ]), read_tag_bytes_from_file( "tests/swfs/DefineBits-JpegTables-MX.swf", @@ -3711,24 +2111,7 @@ pub fn tag_tests() -> Vec { is_bitmap_cached: false, is_visible: true, amf_data: Some(vec![ - 10, - 11, - 1, - 9, - 116, - 101, - 115, - 116, - 6, - 17, - 84, - 101, - 115, - 116, - 105, - 110, - 103, - 33, + 10, 11, 1, 9, 116, 101, 115, 116, 6, 17, 84, 101, 115, 116, 105, 110, 103, 33, 1, ]), })), @@ -3823,13 +2206,11 @@ pub fn tag_tests() -> Vec { in_sample: None, out_sample: None, num_loops: 1, - envelope: Some(vec![ - SoundEnvelopePoint { - sample: 0, - left_volume: 0.0, - right_volume: 1.0, - }, - ]), + envelope: Some(vec![SoundEnvelopePoint { + sample: 0, + left_volume: 0.0, + right_volume: 1.0, + }]), }), }, read_tag_bytes_from_file("tests/swfs/startsound2.swf", TagCode::StartSound2), @@ -4115,132 +2496,126 @@ pub fn avm1_tests() -> Vec { } pub fn avm2_tests() -> Vec { - vec![ - ( - 10, - AbcFile { - major_version: 46, - minor_version: 16, - constant_pool: ConstantPool { - ints: vec![], - uints: vec![], - doubles: vec![], - strings: vec![ - "".to_string(), - "void".to_string(), - "Avm2Test".to_string(), - "trace".to_string(), - "Test".to_string(), - ], - namespaces: vec![Namespace::Package(Index::new(1))], - namespace_sets: vec![], - multinames: vec![ - Multiname::QName { - namespace: Index::new(1), - name: Index::new(2), - }, - Multiname::QName { - namespace: Index::new(1), - name: Index::new(3), - }, - Multiname::QName { - namespace: Index::new(1), - name: Index::new(4), - }, - ], - }, - methods: vec![ - Method { - name: Index::new(0), - params: vec![], - return_type: Index::new(1), - needs_arguments_object: false, - needs_activation: false, - needs_rest: false, - needs_dxns: false, - }, - Method { - name: Index::new(0), - params: vec![], - return_type: Index::new(0), - needs_arguments_object: false, - needs_activation: false, - needs_rest: false, - needs_dxns: false, - }, + vec![( + 10, + AbcFile { + major_version: 46, + minor_version: 16, + constant_pool: ConstantPool { + ints: vec![], + uints: vec![], + doubles: vec![], + strings: vec![ + "".to_string(), + "void".to_string(), + "Avm2Test".to_string(), + "trace".to_string(), + "Test".to_string(), ], - metadata: vec![], - instances: vec![], - classes: vec![], - scripts: vec![ - Script { - init_method: Index::new(1), - traits: vec![ - Trait { - name: Index::new(2), - kind: TraitKind::Method { - disp_id: 1, - method: Index::new(0), - }, - metadata: vec![], - is_final: false, - is_override: false, - }, - ], + namespaces: vec![Namespace::Package(Index::new(1))], + namespace_sets: vec![], + multinames: vec![ + Multiname::QName { + namespace: Index::new(1), + name: Index::new(2), }, - ], - method_bodies: vec![ - MethodBody { - method: Index::new(0), - max_stack: 2, - num_locals: 1, - init_scope_depth: 1, - max_scope_depth: 2, - code: vec![ - Op::GetLocal { index: 0 }, - Op::PushScope, - Op::FindPropStrict { - index: Index::new(3), - }, - Op::PushString { - value: Index::new(5), - }, - Op::CallPropVoid { - index: Index::new(3), - num_args: 1, - }, - Op::ReturnVoid, - ], - exceptions: vec![], - traits: vec![], + Multiname::QName { + namespace: Index::new(1), + name: Index::new(3), }, - MethodBody { - method: Index::new(1), - max_stack: 1, - num_locals: 2, - init_scope_depth: 1, - max_scope_depth: 2, - code: vec![ - Op::GetLocal { index: 0 }, - Op::PushScope, - Op::FindPropStrict { - index: Index::new(2), - }, - Op::CallProperty { - index: Index::new(2), - num_args: 0, - }, - Op::CoerceA, - Op::SetLocal { index: 1 }, - Op::GetLocal { index: 1 }, - Op::ReturnValue, - ], - exceptions: vec![], - traits: vec![], + Multiname::QName { + namespace: Index::new(1), + name: Index::new(4), }, ], }, - read_abc_from_file("tests/swfs/AVM2-Dummy.swf"), - ), - ] + methods: vec![ + Method { + name: Index::new(0), + params: vec![], + return_type: Index::new(1), + needs_arguments_object: false, + needs_activation: false, + needs_rest: false, + needs_dxns: false, + }, + Method { + name: Index::new(0), + params: vec![], + return_type: Index::new(0), + needs_arguments_object: false, + needs_activation: false, + needs_rest: false, + needs_dxns: false, + }, + ], + metadata: vec![], + instances: vec![], + classes: vec![], + scripts: vec![Script { + init_method: Index::new(1), + traits: vec![Trait { + name: Index::new(2), + kind: TraitKind::Method { + disp_id: 1, + method: Index::new(0), + }, + metadata: vec![], + is_final: false, + is_override: false, + }], + }], + method_bodies: vec![ + MethodBody { + method: Index::new(0), + max_stack: 2, + num_locals: 1, + init_scope_depth: 1, + max_scope_depth: 2, + code: vec![ + Op::GetLocal { index: 0 }, + Op::PushScope, + Op::FindPropStrict { + index: Index::new(3), + }, + Op::PushString { + value: Index::new(5), + }, + Op::CallPropVoid { + index: Index::new(3), + num_args: 1, + }, + Op::ReturnVoid, + ], + exceptions: vec![], + traits: vec![], + }, + MethodBody { + method: Index::new(1), + max_stack: 1, + num_locals: 2, + init_scope_depth: 1, + max_scope_depth: 2, + code: vec![ + Op::GetLocal { index: 0 }, + Op::PushScope, + Op::FindPropStrict { + index: Index::new(2), + }, + Op::CallProperty { + index: Index::new(2), + num_args: 0, + }, + Op::CoerceA, + Op::SetLocal { index: 1 }, + Op::GetLocal { index: 1 }, + Op::ReturnValue, + ], + exceptions: vec![], + traits: vec![], + }, + ], + }, + read_abc_from_file("tests/swfs/AVM2-Dummy.swf"), + )] } diff --git a/src/types.rs b/src/types.rs index 1af285803..7774531d1 100644 --- a/src/types.rs +++ b/src/types.rs @@ -153,7 +153,6 @@ pub enum PlaceObjectAction { Replace(CharacterId), } - #[derive(Debug, PartialEq, Clone)] pub enum Filter { DropShadowFilter(Box), @@ -318,9 +317,18 @@ pub enum Tag { Protect(Option), CsmTextSettings(CsmTextSettings), - DefineBinaryData { id: CharacterId, data: Vec }, - DefineBits { id: CharacterId, jpeg_data: Vec }, - DefineBitsJpeg2 { id: CharacterId, jpeg_data: Vec }, + DefineBinaryData { + id: CharacterId, + data: Vec, + }, + DefineBits { + id: CharacterId, + jpeg_data: Vec, + }, + DefineBitsJpeg2 { + id: CharacterId, + jpeg_data: Vec, + }, DefineBitsJpeg3(DefineBitsJpeg3), DefineBitsLossless(DefineBitsLossless), DefineButton(Box