diff options
Diffstat (limited to 'venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests')
10 files changed, 228 insertions, 0 deletions
| diff --git a/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__init__.py b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__init__.py new file mode 100644 index 0000000..dfe67ba --- /dev/null +++ b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__init__.py @@ -0,0 +1,2 @@ +# Empty file :) +# pylint: disable=C0111 diff --git a/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__pycache__/__init__.cpython-311.pyc b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__pycache__/__init__.cpython-311.pycBinary files differ new file mode 100644 index 0000000..612fa57 --- /dev/null +++ b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__pycache__/__init__.cpython-311.pyc diff --git a/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__pycache__/testjavascriptobfuscator.cpython-311.pyc b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__pycache__/testjavascriptobfuscator.cpython-311.pycBinary files differ new file mode 100644 index 0000000..6c1abb8 --- /dev/null +++ b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__pycache__/testjavascriptobfuscator.cpython-311.pyc diff --git a/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__pycache__/testmyobfuscate.cpython-311.pyc b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__pycache__/testmyobfuscate.cpython-311.pycBinary files differ new file mode 100644 index 0000000..c62db76 --- /dev/null +++ b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__pycache__/testmyobfuscate.cpython-311.pyc diff --git a/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__pycache__/testpacker.cpython-311.pyc b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__pycache__/testpacker.cpython-311.pycBinary files differ new file mode 100644 index 0000000..86d19bf --- /dev/null +++ b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__pycache__/testpacker.cpython-311.pyc diff --git a/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__pycache__/testurlencode.cpython-311.pyc b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__pycache__/testurlencode.cpython-311.pycBinary files differ new file mode 100644 index 0000000..93bd7db --- /dev/null +++ b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/__pycache__/testurlencode.cpython-311.pyc diff --git a/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/testjavascriptobfuscator.py b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/testjavascriptobfuscator.py new file mode 100644 index 0000000..d40db2d --- /dev/null +++ b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/testjavascriptobfuscator.py @@ -0,0 +1,59 @@ +# +#     written by Stefano Sanfilippo <a.little.coder@gmail.com> +# + +"""Tests for JavaScriptObfuscator unpacker.""" + +import unittest +from jsbeautifier.unpackers.javascriptobfuscator import unpack, detect, smartsplit + +# pylint: disable=R0904 + + +class TestJavascriptObfuscator(unittest.TestCase): +    """JavascriptObfuscator.com test case.""" + +    def test_smartsplit(self): +        """Test smartsplit() function.""" +        split = smartsplit + +        def equals(data, result): +            return self.assertEqual(split(data), result) + +        equals("", []) +        equals('"a", "b"', ['"a"', '"b"']) +        equals('"aaa","bbbb"', ['"aaa"', '"bbbb"']) +        equals('"a", "b\\""', ['"a"', '"b\\""']) + +    def test_detect(self): +        """Test detect() function.""" + +        def positive(source): +            return self.assertTrue(detect(source)) + +        def negative(source): +            return self.assertFalse(detect(source)) + +        negative("") +        negative("abcd") +        negative("var _0xaaaa") +        positive('var _0xaaaa = ["a", "b"]') +        positive('var _0xaaaa=["a", "b"]') +        positive('var _0x1234=["a","b"]') + +    def test_unpack(self): +        """Test unpack() function.""" + +        def decodeto(ob, original): +            return self.assertEqual(unpack(ob), original) + +        decodeto("var _0x8df3=[];var a=10;", "var a=10;") +        decodeto( +            'var _0xb2a7=["\x74\x27\x65\x73\x74"];var i;for(i=0;i<10;++i)' +            "{alert(_0xb2a7[0]);} ;", +            "var i;for(i=0;i<10;++i){alert" '("t\'est");} ;', +        ) + + +if __name__ == "__main__": +    unittest.main() diff --git a/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/testmyobfuscate.py b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/testmyobfuscate.py new file mode 100644 index 0000000..d69df82 --- /dev/null +++ b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/testmyobfuscate.py @@ -0,0 +1,48 @@ +# +#     written by Stefano Sanfilippo <a.little.coder@gmail.com> +# + +"""Tests for MyObfuscate unpacker.""" + +import unittest +import os +from jsbeautifier.unpackers.myobfuscate import detect, unpack +from jsbeautifier.unpackers.tests import __path__ as path + +INPUT = os.path.join(path[0], "test-myobfuscate-input.js") +OUTPUT = os.path.join(path[0], "test-myobfuscate-output.js") + +# pylint: disable=R0904 + + +class TestMyObfuscate(unittest.TestCase): +    # pylint: disable=C0103 +    """MyObfuscate obfuscator testcase.""" + +    @classmethod +    def setUpClass(cls): +        """Load source files (encoded and decoded version) for tests.""" +        with open(INPUT, "r") as data: +            cls.input = data.read() +        with open(OUTPUT, "r") as data: +            cls.output = data.read() + +    def test_detect(self): +        """Test detect() function.""" + +        def detected(source): +            return self.assertTrue(detect(source)) + +        detected(self.input) + +    def test_unpack(self): +        """Test unpack() function.""" + +        def check(inp, out): +            return self.assertEqual(unpack(inp), out) + +        check(self.input, self.output) + + +if __name__ == "__main__": +    unittest.main() diff --git a/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/testpacker.py b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/testpacker.py new file mode 100644 index 0000000..1de9934 --- /dev/null +++ b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/testpacker.py @@ -0,0 +1,73 @@ +# -*- coding: utf-8 -*- +# +#     written by Stefano Sanfilippo <a.little.coder@gmail.com> +# + +"""Tests for P.A.C.K.E.R. unpacker.""" + +import unittest +from jsbeautifier.unpackers.packer import detect, unpack + +# pylint: disable=R0904 + + +class TestPacker(unittest.TestCase): +    """P.A.C.K.E.R. testcase.""" + +    def test_detect(self): +        """Test detect() function.""" + +        def positive(source): +            return self.assertTrue(detect(source)) + +        def negative(source): +            return self.assertFalse(detect(source)) + +        negative("") +        negative("var a = b") +        positive("eval(function(p,a,c,k,e,r") +        positive("eval ( function(p, a, c, k, e, r") + +    def test_unpack(self): +        """Test unpack() function.""" + +        def check(inp, out): +            return detect(inp) and self.assertEqual(unpack(inp), out) + +        check( +            "eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)" +            "){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=" +            "function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p.replace(" +            "new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('0 2=1'," +            "62,3,'var||a'.split('|'),0,{}))", +            "var a=1", +        ) + +        check( +            "function test (){alert ('This is a test!')}; " +            "eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String))" +            "{while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function" +            "(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp(" +            "'\\b'+e(c)+'\\b','g'),k[c]);return p}('0 2=\\'{Íâ–+›ï;ã†Ù¥#\\'',3,3," +            "'var||a'.split('|'),0,{}))", +            "function test (){alert ('This is a test!')}; var a='{Íâ–+›ï;ã†Ù¥#'", +        ) + +        check( +            "eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('2 0=\"4 3!\";2 1=0.5(/b/6);a.9(\"8\").7=1;',12,12,'str|n|var|W3Schools|Visit|search|i|innerHTML|demo|getElementById|document|w3Schools'.split('|'),0,{}))", +            'var str="Visit W3Schools!";var n=str.search(/w3Schools/i);document.getElementById("demo").innerHTML=n;', +        ) + +        check( +            "a=b;\r\nwhile(1){\ng=h;{return'\\w+'};break;eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('$(5).4(3(){$('.1').0(2);$('.6').0(d);$('.7').0(b);$('.a').0(8);$('.9').0(c)});',14,14,'html|r5e57|8080|function|ready|document|r1655|rc15b|8888|r39b0|r6ae9|3128|65309|80'.split('|'),0,{}))c=abx;", +            "a=b;\r\nwhile(1){\ng=h;{return'\\w+'};break;$(document).ready(function(){$('.r5e57').html(8080);$('.r1655').html(80);$('.rc15b').html(3128);$('.r6ae9').html(8888);$('.r39b0').html(65309)});c=abx;", +        ) + +        check( +            "eval(function(p,a,c,k,e,r){e=function(c){return c.toString(36)};if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'[0-9ab]'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('$(5).a(6(){ $('.8').0(1); $('.b').0(4); $('.9').0(2); $('.7').0(3)})',[],12,'html|52136|555|65103|8088|document|function|r542c|r8ce6|rb0de|ready|rfab0'.split('|'),0,{}))", +            "$(document).ready(function(){ $('.r8ce6').html(52136); $('.rfab0').html(8088); $('.rb0de').html(555); $('.r542c').html(65103)})", +        ) + + +if __name__ == "__main__": +    unittest.main() diff --git a/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/testurlencode.py b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/testurlencode.py new file mode 100644 index 0000000..10e236d --- /dev/null +++ b/venv/lib/python3.11/site-packages/jsbeautifier/unpackers/tests/testurlencode.py @@ -0,0 +1,46 @@ +# +#     written by Stefano Sanfilippo <a.little.coder@gmail.com> +# + +"""Tests for urlencoded unpacker.""" + +import unittest + +from jsbeautifier.unpackers.urlencode import detect, unpack + +# pylint: disable=R0904 + + +class TestUrlencode(unittest.TestCase): +    """urlencode test case.""" + +    def test_detect(self): +        """Test detect() function.""" + +        def encoded(source): +            return self.assertTrue(detect(source)) + +        def unencoded(source): +            return self.assertFalse(detect(source)) + +        unencoded("") +        unencoded("var a = b") +        encoded("var%20a+=+b") +        encoded("var%20a=b") +        encoded("var%20%21%22") + +    def test_unpack(self): +        """Test unpack function.""" + +        def equals(source, result): +            return self.assertEqual(unpack(source), result) + +        equals("", "") +        equals("abcd", "abcd") +        equals("var a = b", "var a = b") +        equals("var%20a=b", "var a=b") +        equals("var%20a+=+b", "var a = b") + + +if __name__ == "__main__": +    unittest.main() | 
