initial commit

This commit is contained in:
missing 2022-07-21 00:14:23 -07:00
parent 01c5546b18
commit b0c4d0759c
4 changed files with 152 additions and 0 deletions

7
Cargo.lock generated Normal file
View file

@ -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"

8
Cargo.toml Normal file
View file

@ -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]

1
src/foobar Normal file
View file

@ -0,0 +1 @@
(+!![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![] + !![])[(!![] + [])[+[]] + ([][([][[]] + [])[+!![] + !![] + !![] + !![]] + (![] + [])[+!![] + !![]] + (![] + [])[+!![]] + (!![] + [])[+[]]] + [])[+!![] + !![] + !![] + !![] + !![] + !![]] + (([] + [])[([][([][[]] + [])[+!![] + !![] + !![] + !![]] + (![] + [])[+!![] + !![]] + (![] + [])[+!![]] + (!![] + [])[+[]]] + [])[+!![] + !![] + !![]] + ([][([][[]] + [])[+!![] + !![] + !![] + !![]] + (![] + [])[+!![] + !![]] + (![] + [])[+!![]] + (!![] + [])[+[]]] + [])[+!![] + !![] + !![] + !![] + !![] + !![]] + ([][[]] + [])[+!![]] + (![] + [])[+!![] + !![] + !![]] + (!![] + [])[+[]] + (!![] + [])[+!![]] + ([][[]] + [])[+[]] + ([][([][[]] + [])[+!![] + !![] + !![] + !![]] + (![] + [])[+!![] + !![]] + (![] + [])[+!![]] + (!![] + [])[+[]]] + [])[+!![] + !![] + !![]] + (!![] + [])[+[]] + ([][([][[]] + [])[+!![] + !![] + !![] + !![]] + (![] + [])[+!![] + !![]] + (![] + [])[+!![]] + (!![] + [])[+[]]] + [])[+!![] + !![] + !![] + !![] + !![] + !![]] + (!![] + [])[+!![]]] + [])]

136
src/main.rs Normal file
View file

@ -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::<Vec<_>>().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::<String>();
format!(
"{}({})()",
function_constructor(),
string(&format!("return '{}'", s))
)
}
}
fn number(n: usize) -> String {
if n == 0 {
"+[]".to_owned()
} else {
"+!![]".repeat(n)
}
}