avm1_types/
lib.rs

1pub use self::push_value::PushValue;
2#[cfg(feature = "serde")]
3use serde::{Deserialize, Serialize};
4
5#[macro_use]
6mod bitflags;
7
8pub mod action;
9pub mod cfg;
10pub mod error;
11#[cfg(feature = "serde")]
12mod helpers;
13mod push_value;
14pub mod raw;
15mod swf_float;
16
17#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
18#[cfg_attr(
19  feature = "serde",
20  derive(Serialize, Deserialize),
21  serde(tag = "type", content = "target", rename_all = "PascalCase")
22)]
23pub enum CatchTarget {
24  Register(u8),
25  Variable(String),
26}
27
28#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
29#[cfg_attr(feature = "serde", derive(Serialize, Deserialize), serde(rename_all = "PascalCase"))]
30pub enum GetUrl2Method {
31  None,
32  Get,
33  Post,
34}
35
36#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
37#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
38pub struct Parameter {
39  pub register: u8,
40  pub name: String,
41}
42
43serde_bitflags! {
44  pub struct FunctionFlags: u16 {
45    #[serde(name = "preload_this")]
46    const PRELOAD_THIS = 1 << 0;
47    #[serde(name = "suppress_this")]
48    const SUPPRESS_THIS = 1 << 1;
49    #[serde(name = "preload_arguments")]
50    const PRELOAD_ARGUMENTS = 1 << 2;
51    #[serde(name = "suppress_arguments")]
52    const SUPPRESS_ARGUMENTS = 1 << 3;
53    #[serde(name = "preload_super")]
54    const PRELOAD_SUPER = 1 << 4;
55    #[serde(name = "suppress_super")]
56    const SUPPRESS_SUPER = 1 << 5;
57    #[serde(name = "preload_root")]
58    const PRELOAD_ROOT = 1 << 6;
59    #[serde(name = "preload_parent")]
60    const PRELOAD_PARENT = 1 << 7;
61    #[serde(name = "preload_global")]
62    const PRELOAD_GLOBAL = 1 << 8;
63  }
64}
65
66#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
67#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
68pub struct ActionHeader {
69  pub code: u8,
70  pub length: u16,
71}
72
73#[cfg(all(test, feature = "serde"))]
74mod tests {
75  use crate::cfg::Cfg;
76  use std::path::Path;
77  use test_generator::test_resources;
78
79  #[test_resources("../tests/avm1/[!.]*/*/")]
80  fn test_cfg(path: &str) {
81    let path: &Path = Path::new(path);
82    let name = path
83      .components()
84      .last()
85      .unwrap()
86      .as_os_str()
87      .to_str()
88      .expect("Failed to retrieve sample name");
89
90    if name == "corrupted-push" || name == "try-jump-to-catch-throw-finally"
91    // || name == "float32-trace"
92    // || name == "float64-trace"
93    {
94      return;
95    }
96
97    let cfg_path = path.join("cfg.json");
98
99    let value_json = ::std::fs::read_to_string(cfg_path).expect("Failed to read CFG file");
100
101    let value: Cfg = serde_json_v8::from_str(&value_json).expect("Failed to read CFG");
102
103    let output_json = serde_json_v8::to_string_pretty(&value).expect("Failed to write CFG");
104    let output_json = format!("{}\n", output_json);
105
106    assert_eq!(output_json, value_json)
107  }
108}
109
110#[cfg(all(test, feature = "serde"))]
111mod e2e_raw_tests {
112  use crate::raw::Action;
113  use test_generator::test_resources;
114
115  #[test_resources("../tests/raw/*.json")]
116  fn test_parse_action(path: &str) {
117    let file = ::std::fs::File::open(path).unwrap();
118    let reader = ::std::io::BufReader::new(file);
119    // Check that we can parse the test case without issues
120    serde_json_v8::from_reader::<_, Action>(reader).unwrap();
121  }
122}