summaryrefslogtreecommitdiff
path: root/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/evalbased.py
diff options
context:
space:
mode:
authorcyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
committercyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
commit6d7ba58f880be618ade07f8ea080fe8c4bf8a896 (patch)
treeb1c931051ffcebd2bd9d61d98d6233ffa289bbce /venv/lib/python3.11/site-packages/jsbeautifier/unpackers/evalbased.py
parent4f884c9abc32990b4061a1bb6997b4b37e58ea0b (diff)
venv
Diffstat (limited to 'venv/lib/python3.11/site-packages/jsbeautifier/unpackers/evalbased.py')
-rw-r--r--venv/lib/python3.11/site-packages/jsbeautifier/unpackers/evalbased.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/evalbased.py b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/evalbased.py
new file mode 100644
index 0000000..74f1f0f
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/evalbased.py
@@ -0,0 +1,44 @@
+#
+# Unpacker for eval() based packers, a part of javascript beautifier
+# by Einar Lielmanis <einar@beautifier.io>
+#
+# written by Stefano Sanfilippo <a.little.coder@gmail.com>
+#
+# usage:
+#
+# if detect(some_string):
+# unpacked = unpack(some_string)
+#
+
+"""Unpacker for eval() based packers: runs JS code and returns result.
+Works only if a JS interpreter (e.g. Mozilla's Rhino) is installed and
+properly set up on host."""
+
+from subprocess import PIPE, Popen
+
+PRIORITY = 3
+
+
+def detect(source):
+ """Detects if source is likely to be eval() packed."""
+ return source.strip().lower().startswith("eval(function(")
+
+
+def unpack(source):
+ """Runs source and return resulting code."""
+ return jseval("print %s;" % source[4:]) if detect(source) else source
+
+
+# In case of failure, we'll just return the original, without crashing on user.
+
+
+def jseval(script):
+ """Run code in the JS interpreter and return output."""
+ try:
+ interpreter = Popen(["js"], stdin=PIPE, stdout=PIPE)
+ except OSError:
+ return script
+ result, errors = interpreter.communicate(script)
+ if interpreter.poll() or errors:
+ return script
+ return result