From b0c4d0759c381787b78aaec7e639e4b2540e30ea Mon Sep 17 00:00:00 2001 From: missing Date: Thu, 21 Jul 2022 00:14:23 -0700 Subject: [PATCH] initial commit --- Cargo.lock | 7 +++ Cargo.toml | 8 ++++ src/foobar | 1 + src/main.rs | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 152 insertions(+) create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 src/foobar create mode 100644 src/main.rs diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..387a97d --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "jsfuck" +version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..4ffe370 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "jsfuck" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/src/foobar b/src/foobar new file mode 100644 index 0000000..46712b4 --- /dev/null +++ b/src/foobar @@ -0,0 +1 @@ +(+!![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![])[(!![] + [])[+[]] + ([][([][[]] + [])[+!![] + !![] + !![] + !![]] + (![] + [])[+!![] + !![]] + (![] + [])[+!![]] + (!![] + [])[+[]]] + [])[+!![] + !![] + !![] + !![] + !![] + !![]] + (([] + [])[([][([][[]] + [])[+!![] + !![] + !![] + !![]] + (![] + [])[+!![] + !![]] + (![] + [])[+!![]] + (!![] + [])[+[]]] + [])[+!![] + !![] + !![]] + ([][([][[]] + [])[+!![] + !![] + !![] + !![]] + (![] + [])[+!![] + !![]] + (![] + [])[+!![]] + (!![] + [])[+[]]] + [])[+!![] + !![] + !![] + !![] + !![] + !![]] + ([][[]] + [])[+!![]] + (![] + [])[+!![] + !![] + !![]] + (!![] + [])[+[]] + (!![] + [])[+!![]] + ([][[]] + [])[+[]] + ([][([][[]] + [])[+!![] + !![] + !![] + !![]] + (![] + [])[+!![] + !![]] + (![] + [])[+!![]] + (!![] + [])[+[]]] + [])[+!![] + !![] + !![]] + (!![] + [])[+[]] + ([][([][[]] + [])[+!![] + !![] + !![] + !![]] + (![] + [])[+!![] + !![]] + (![] + [])[+!![]] + (!![] + [])[+[]]] + [])[+!![] + !![] + !![] + !![] + !![] + !![]] + (!![] + [])[+!![]]] + [])] \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..ad9b20c --- /dev/null +++ b/src/main.rs @@ -0,0 +1,136 @@ +#![warn(clippy::pedantic)] + +use std::io::{stdin, Read}; + +fn main() { + let mut input = String::new(); + stdin().read_to_string(&mut input).unwrap(); + + println!( + "{}({})()", + function_constructor(), + string_with_fromcodepoint(input.trim()) + ); +} + +fn string_with_fromcodepoint(s: &str) -> String { + let mut out = String::new(); + out.push_str(&function_constructor()); + out.push('('); + out.push_str(&string("return String.fromCodePoint(")); + for c in s.chars() { + out.push('+'); + out.push_str(&string(&(c as u32).to_string())); + out.push('+'); + out.push_str(&char(',')); + } + out.push('+'); + out.push_str(&char(')')); + out.push_str(")()"); + out +} + +fn regexp_constructor() -> String { + format!("{}({})()", function_constructor(), string("return RegExp")) +} + +fn function_constructor() -> String { + format!("[][{}][{}]", string("flat"), string("constructor")) +} + +fn string(s: &str) -> String { + s.chars().map(char).collect::>().join("+") +} + +fn char(c: char) -> String { + if c == ',' { + format!("([[]][{}]([[]])+[])", string("concat")) + } else if c.is_ascii() && c.is_numeric() { + format!("(({})+[])", number(c as usize - b'0' as usize)) + } else if let Some(index) = "undefined".find(c) { + format!("([][[]]+[])[{}]", number(index)) + } else if let Some(index) = "true".find(c) { + format!("(!![]+[])[{}]", number(index)) + } else if let Some(index) = "false".find(c) { + format!("(![]+[])[{}]", number(index)) + } else if let Some(index) = "function flat() {".find(c) { + format!("([][{}]+[])[{}]", string("flat"), number(index)) + } else if let Some(index) = "[object Array Iterator]".find(c) { + format!("([][{}]()+[])[{}]", string("entries"), number(index)) + } else if let Some(index) = "Number".find(c) { + format!( + "((+[])[{}]+[])[{}]", + string("constructor"), + number(index + 9) + ) + } else if let Some(index) = "String".find(c) { + format!( + "(([]+[])[{}]+[])[{}]", + string("constructor"), + number(index + 9) + ) + } else if let Some(index) = "Function".find(c) { + format!("({}+[])[{}]", function_constructor(), number(index + 9)) + } else if c == '}' { + format!( + "([][{}]+[])[{}](-({}))", + string("flat"), + string("at"), + number(1) + ) + } else if c == '.' { + format!("(+({})+[])[{}]", string("11e100"), number(1)) + } else if c.is_ascii_lowercase() { + format!( + "({})[{}+(([]+[])[{}][{}])]({})", + number(c as usize - b'a' as usize + 10), + string("to"), + string("constructor"), + string("name"), + number(36) + ) + } else if let Some(index) = "RangeError:".find(c) { + format!( + "({}({})()+[])[{}]", + function_constructor(), + string("try{String().normalize(false)}catch(f){return f}"), + number(index) + ) + } else if let Some(index) = "/(?:)/".find(c) { + format!("({}()+[])[{}]", regexp_constructor(), number(index)) + } else if c == '\\' { + format!( + "({}({})+[])[{}]", + regexp_constructor(), + string("/"), + number(1) + ) + } else if c == '\'' { + format!( + "({}({})()+[])[{}]", + function_constructor(), + string("try{Function([[]].concat([[]]).toString())}catch(f){return f}"), + number(30) + ) + } else { + let mut buf = [0; 2]; + let buf = c.encode_utf16(&mut buf); + let s = buf + .iter() + .map(|v| format!("\\u{:04x}", v)) + .collect::(); + format!( + "{}({})()", + function_constructor(), + string(&format!("return '{}'", s)) + ) + } +} + +fn number(n: usize) -> String { + if n == 0 { + "+[]".to_owned() + } else { + "+!![]".repeat(n) + } +}