Advertisement
magnetos

luaobfuscator

Mar 9th, 2023
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // #==================================#
  2. // #      toolbox-collapsible         #
  3. // #==================================#
  4.  
  5. var coll = document.getElementsByClassName("toolbox-collapsible");
  6. var i;
  7.  
  8. for (i = 0; i < coll.length; i++) {
  9.     coll[i].addEventListener("click", function () {
  10.         this.classList.toggle("toolbox-hit");
  11.         var content = this.nextElementSibling;
  12.         if (content.style.display === "block") {
  13.             content.style.display = "none";
  14.         } else {
  15.             content.style.display = "block";
  16.         }
  17.         /*if (content.style.height === "auto") {
  18.             content.style.height = "0";
  19.         } else {
  20.             content.style.height = "auto";
  21.         }*/
  22.     });
  23. }
  24.  
  25. let toolboxDiv = document.getElementById("notepad-toolbox1");
  26. let toolboxDownloadBtn = document.getElementById("toolbox-download-btn");
  27. let codeWindow = document.getElementById("lua-codewindow")
  28. let downloadBtn = document.getElementById("toolbox-download-btn");
  29.  
  30. function toggleHome(state) {
  31.     // toggle home/landing page elemts on/off
  32.     if (toolboxDiv == null) {
  33.         return;
  34.     }
  35.  
  36.     if (state) {
  37.         toolboxDiv.style.filter = "Saturate(0.1)";
  38.         toolboxDownloadBtn.style.display = "none";
  39.         //codeWindow.contentEditable = false;
  40.         codeWindow.style.filter = "blur(0)";
  41.     }
  42.     else {
  43.  
  44.         toolboxDiv.style.filter = "none";
  45.         toolboxDownloadBtn.style.display = "block";
  46.         //codeWindow.contentEditable = true;
  47.         codeWindow.style.filter = "blur(0)";
  48.     }
  49. }
  50.  
  51. // load on playground ONLY?
  52. window.onload = function () {
  53.     // #==================================#
  54.     // #            UI Button             #
  55.     // #==================================#
  56.  
  57.     let isObfuscating = false
  58.     function startObfuscation() {
  59.         if (isObfuscating)
  60.             return false
  61.  
  62.         codeWindow.style.filter = "blur(3px)";
  63.         isObfuscating = true;
  64.         return true
  65.     }
  66.  
  67.     function stopObfuscation() {
  68.         if (!isObfuscating)
  69.             return false
  70.  
  71.         codeWindow.style.filter = "blur(0px)";
  72.         isObfuscating = false;
  73.         return true
  74.     }
  75.  
  76.     let gtagz = "adsbygoogle";
  77.     let luafile = document.getElementById("lua-file")
  78.     if (luafile != null) {
  79.         // NOTE: only load on index?
  80.         // TODO: improve
  81.         downloadBtn.addEventListener("click", function (e) {
  82.             var a = document.createElement('a');
  83.             var blob = new Blob([document.getElementById("lua-codewindow").innerText], { "type": "text/plain" });
  84.             a.href = window.URL.createObjectURL(blob);
  85.             a.download = "obf_" + luaEngine.getSessionId() + ".lua";
  86.             a.click();
  87.         });
  88.  
  89.         document.getElementById("lua-pre-1").addEventListener("click", function (e) {
  90.             if(startObfuscation())
  91.                 luaEngine.obfuscate("pre-1", 1, frontcallback);
  92.         })
  93.         document.getElementById("lua-pre-2").addEventListener("click", function (e) {
  94.             if(startObfuscation())
  95.                 luaEngine.obfuscate("pre-2", 2, frontcallback);
  96.         })
  97.         document.getElementById("lua-pre-3").addEventListener("click", function (e) {
  98.             if(startObfuscation())
  99.                 luaEngine.obfuscate("pre-3", 3, frontcallback);
  100.         })
  101.         document.getElementById("lua-pre-4").addEventListener("click", function (e) {
  102.             if(startObfuscation())
  103.                 luaEngine.obfuscate("pre-4", 4, frontcallback);
  104.         })
  105.         document.getElementById("lua-pre-5").addEventListener("click", function (e) {
  106.             if(startObfuscation())
  107.                 luaEngine.obfuscate("pre-5", 5, frontcallback);
  108.         })
  109.         document.getElementById("lua-cleanup3").addEventListener("click", function (e) {
  110.             if(startObfuscation())
  111.                 luaEngine.cleanup(frontcallback)
  112.         })
  113.         document.getElementById("lua-cleanup").addEventListener("click", function (e) {
  114.             if(startObfuscation())
  115.                 luaEngine.cleanup(frontcallback)
  116.         })
  117.         document.getElementById("lua-junkif").addEventListener("click", function (e) {
  118.             if(startObfuscation())
  119.                 luaEngine.obfuscate("junkif", 50, frontcallback);
  120.         })
  121.         document.getElementById("lua-reverseif").addEventListener("click", function (e) {
  122.             if(startObfuscation())
  123.                 luaEngine.obfuscate("reverseif", 65, frontcallback);
  124.         })
  125.         document.getElementById("lua-cffv1").addEventListener("click", function (e) {
  126.             if(startObfuscation())
  127.                 luaEngine.obfuscate("cffv1", 50, frontcallback);
  128.         })
  129.         document.getElementById("lua-cffv1-exp").addEventListener("click", function (e) {
  130.             if(startObfuscation())
  131.                 luaEngine.obfuscate("cffv1", 50, frontcallback);
  132.         })
  133.         document.getElementById("lua-literals").addEventListener("click", function (e) {
  134.             if(startObfuscation())
  135.                 luaEngine.obfuscate("literals", 50, frontcallback);
  136.         })
  137.         document.getElementById("lua-mbav1").addEventListener("click", function (e) {
  138.             if (startObfuscation())
  139.             luaEngine.obfuscate("MBAv1", 75, frontcallback);
  140.         })
  141.         document.getElementById("lua-variables").addEventListener("click", function (e) {
  142.             if(startObfuscation())
  143.                 luaEngine.obfuscate("variables", 50, frontcallback);
  144.         })
  145.         document.getElementById("lua-minify").addEventListener("click", function (e) {
  146.             if(startObfuscation())
  147.                 luaEngine.obfuscate("minify", 100, frontcallback);
  148.         })
  149.         document.getElementById("lua-minify2").addEventListener("click", function (e) {
  150.             if(startObfuscation())
  151.                 luaEngine.obfuscate("minify", 100, frontcallback);
  152.         })
  153.         document.getElementById("lua-beautify").addEventListener("click", function (e) {
  154.             if(startObfuscation())
  155.                 luaEngine.obfuscate("beautify", 100, frontcallback);
  156.         })
  157.         document.getElementById("lua-beautify2").addEventListener("click", function (e) {
  158.             if(startObfuscation())
  159.                 luaEngine.obfuscate("beautify", 100, frontcallback);
  160.         })
  161.         document.getElementById("lua-beautify3").addEventListener("click", function (e) {
  162.             if(startObfuscation())
  163.                 luaEngine.obfuscate("beautify", 100, frontcallback);
  164.         })
  165.         document.getElementById("lua-strings").addEventListener("click", function (e) {
  166.             if(startObfuscation())
  167.                 luaEngine.obfuscate("strings", 100, frontcallback);
  168.         })
  169.         document.getElementById("lua-tableindirection").addEventListener("click", function (e) {
  170.             if(startObfuscation())
  171.                 luaEngine.obfuscate("tableindirection", 100, frontcallback);
  172.         })
  173.         document.getElementById("lua-demo_vm").addEventListener("click", function (e) {
  174.             if(startObfuscation())
  175.                 luaEngine.obfuscate("demo_vm", 100, frontcallback);
  176.         })
  177.         document.getElementById("lua-demo_vm-exp").addEventListener("click", function (e) {
  178.             if(startObfuscation())
  179.                 luaEngine.obfuscate("demo_vm", 100, frontcallback);
  180.         })
  181.         //document.getElementById("lua-virtualize").addEventListener("click", function (e) {
  182.         //    luaEngine.obfuscate("virtualize", 100, frontcallback);
  183.         //})
  184.         //document.getElementById("lua-devirtualize").addEventListener("click", function (e) {
  185.         //    luaEngine.obfuscate("devirtualize", 100, frontcallback);
  186.         //})
  187.         //document.getElementById("lua-emulate").addEventListener("click", function (e) {
  188.         //    luaEngine.obfuscate("emulate", 0, frontcallback);
  189.         //})
  190.         document.getElementById("lua-undo").addEventListener("click", function (e) {
  191.             if(startObfuscation())
  192.                 luaEngine.obfuscate("undo", 0, frontcallback);
  193.         })
  194.         document.getElementById("lua-undoAll").addEventListener("click", function (e) {
  195.             if(startObfuscation())
  196.                 luaEngine.obfuscate("undoAll", 0, frontcallback);
  197.         })
  198.         document.getElementById("lua-reset").addEventListener("click", function (e) {
  199.             window.location.href = "/"
  200.         })
  201.         document.getElementById("lua-reset2").addEventListener("click", function (e) {
  202.             window.location.href = "/";
  203.         })
  204.  
  205.         // experimental
  206.         document.getElementById("lua-ssa").addEventListener("click", function (e) {
  207.             if (startObfuscation())
  208.                 luaEngine.obfuscate("ssa", 0, frontcallback);
  209.         })
  210.  
  211.         // landing page buttons
  212.         document.getElementById("btn-demo").addEventListener("click", function (e) {
  213.             if (!isObfuscating) {
  214.                 luaEngine.init(frontcallback, flags, true); // empty to get demo
  215.             }
  216.         })
  217.         document.getElementById("btn-uploadfile").addEventListener("click", function (e) {
  218.             if (!isObfuscating) {
  219.                 document.getElementById("lua-file").click();
  220.             }
  221.         })
  222.  
  223.         // on file uploaded
  224.  
  225.         luafile.addEventListener("change", function (e) {
  226.             if (!isObfuscating && this.files.length > 0) {
  227.                 // take first file
  228.                 codeWindow.style.filter = "blur(7px)";
  229.                 isObfuscating = true; // block UI buttons
  230.                 this.files[0].text().then(x => luaEngine.init(frontcallback, flags, true, x))
  231.             }
  232.         })
  233.     }
  234.  
  235.     // TODO: remove?
  236.     /*
  237.     function getCaretCoordinates() {
  238.         let x = 0;
  239.         let y = 0;
  240.         const isSupported = typeof window.getSelection !== "undefined";
  241.         if (isSupported) {
  242.             const selection = window.getSelection();
  243.             if (selection.rangeCount !== 0) {
  244.                 const range = selection.getRangeAt(0).cloneRange();
  245.                 range.collapse(true);
  246.                 const rect = range.getClientRects()[0];
  247.                 if (rect) {
  248.                     x = rect.left;
  249.                     y = rect.top;
  250.                 }
  251.             }
  252.         }
  253.         return { x, y };
  254.     }*/
  255.  
  256.     // TODO: remove?
  257.     /*
  258.     function getCaretIndex(element) {
  259.         let position = 0;
  260.         let isSupported = typeof window.getSelection !== "undefined";
  261.         if (isSupported) {
  262.             let selection = window.getSelection();
  263.             if (selection.rangeCount !== 0) {
  264.                 let range = window.getSelection().getRangeAt(0);
  265.                 let preCaretRange = range.cloneRange();
  266.                 preCaretRange.selectNodeContents(element);
  267.                 preCaretRange.setEnd(range.endContainer, range.endOffset);
  268.                 position = preCaretRange.toString().length;
  269.             }
  270.         }
  271.         return position;
  272.     }*/
  273.  
  274.     let frontcallback = function (lastEvent) {
  275.         //var startOff = getCaretIndex(codeWindow)
  276.  
  277.         //codeWindow.style.filter = "blur(0px)";
  278.         stopObfuscation();
  279.         let test = document.getElementById("lua-codewindow");
  280.  
  281. //        if (!luaEngine.parseScript($(".lang-lua"), lastEvent))
  282.         if (!luaEngine.parseScript(test, lastEvent))
  283.             return;
  284.  
  285.         // TODO: find a better way to count lines lol!
  286.         /*
  287.         let testLines = document.getElementById("notepad-lines-ul");
  288.         if (testLines != null && test != null) {
  289.             testLines.innerHTML = "";
  290.             var count = 1;
  291.             //let lineCount = test.innerText.split('\n').length;
  292.             for (var i = 0; i <= test.innerText.length;  i++) {
  293.                 if (test.innerText[i] == '\n' || i == test.innerText.length-1) {
  294.                     let txt = document.createTextNode(count++);
  295.                     var li = document.createElement("li");
  296.                     li.appendChild(txt);
  297.                     testLines.appendChild(li);
  298.                     if (count >= 2048)
  299.                         break;
  300.                 }
  301.             }
  302.         }*/
  303.  
  304.         // NOTE: skip range as we no longer want editable content?
  305.         /*
  306.         var newRange = document.createRange()
  307.         // quick fix, iterate over nodes
  308.         var index = 0
  309.         var targetChild = 0
  310.         var nextChild = codeWindow.firstChild;
  311.         for (var i = 0; i < codeWindow.children.length; i++) {
  312.             var child = codeWindow.children[i]
  313.             if (index + child.innerText.length >= startOff) {
  314.                 targetChild = i
  315.                 break;
  316.             }
  317.             index += child.innerText.length
  318.         }
  319.         newRange.setStart(codeWindow.childNodes[targetChild].firstChild, startOff - index)
  320.         newRange.collapse(true)
  321.         var sel = window.getSelection()
  322.         sel.removeAllRanges()
  323.         sel.addRange(newRange)
  324.         */
  325.  
  326.         // TODO: check size?
  327.         let lconsole = document.getElementById("lua-console");
  328.         if (lconsole != null && window.innerWidth > 600) {
  329.             lconsole.style.display = "block";
  330.         }
  331.        
  332.         // toogle UI elements
  333.         toggleHome(luaEngine.getSessionId() == null)
  334.     };
  335.  
  336.     let consolecallback = function (msg) {
  337.         // TODO?
  338.         let consoleul = document.getElementById("lua-console-ul");
  339.         if (consoleul != null) {
  340.             // Don't judge me for timestamp, judge ChatGPT
  341.             const date = new Date();
  342.             const hours = date.getHours().toString().padStart(2, '0');
  343.             const minutes = date.getMinutes().toString().padStart(2, '0');
  344.             const seconds = date.getSeconds().toString().padStart(2, '0');
  345.             const milliseconds = date.getMilliseconds().toString().padStart(3, '0');
  346.  
  347.             let li = document.createElement("li");
  348.             li.appendChild(document.createTextNode(`[${hours}:${minutes}:${seconds}.${milliseconds}]: ${msg}`));
  349.             consoleul.appendChild(li)
  350.         }
  351.     }
  352.     consolecallback("test... Hello World!");
  353.     consolecallback("test... Hello World!");
  354.     consolecallback("test... Hello World!");
  355.     consolecallback("test... Hello World!");
  356.     consolecallback("test... Hello World!");
  357.     consolecallback("test... Hello World!");
  358.     consolecallback("test... Hello World!");
  359.     consolecallback("test... Hello World!");
  360.     consolecallback("test... Hello World!");
  361.     consolecallback("test... Hello World!123");
  362.  
  363.    
  364.     // TODO: remove? (or auto upload?)
  365.     //codeWindow.addEventListener("input", function (e) {
  366.     //    luaEngine.updateScript(this.innerText, frontcallback)
  367.     //});
  368.  
  369.     // TODO: remove?
  370.     codeWindow.addEventListener("click", function (e) {
  371.         //toggleTooltip(e)
  372.     })
  373.  
  374.     let flags = document.getElementsByClassName(gtagz).length;
  375.  
  376.     // #==================================#
  377.     // #        Init Lua Engine           #
  378.     // #==================================#
  379.     luaEngine.init(frontcallback, flags)
  380.  
  381.     function updateTop(sessions) {
  382.         let landingpage = document.getElementById("home-landingpage")
  383.         let targetDOM = document.getElementById("lua-sessions");
  384.         let codewindow = document.getElementById("lua-codewindow");
  385.        
  386.         // main/home?
  387.         let spanHome = document.createElement("span");
  388.         spanHome.className = "top-tab-close";
  389.         //spanHome.appendChild(document.createTextNode("x"));
  390.         let txtHome = document.createTextNode("Home")
  391.         let aHome = document.createElement("a");
  392.         if (luaEngine.getSessionId() == null) {
  393.             aHome.href = "#";
  394.             aHome.style = "color: lightblue; text-decoration: none; cursor: default;";
  395.             landingpage.style.display = "flex";
  396.         } else {
  397.             aHome.href = "/";
  398.             aHome.style = "text-decoration: none;";
  399.         }
  400.         aHome.appendChild(txtHome)
  401.         let liHome = document.createElement("li");
  402.         liHome.className = "top-tab";
  403.         liHome.appendChild(aHome);
  404.         liHome.appendChild(spanHome)
  405.         targetDOM.appendChild(liHome);
  406.  
  407.         for (var i = 0; i < sessions.length; i++) {
  408.             let spanNode = document.createElement("span");
  409.             spanNode.className = "top-tab-close";
  410.             spanNode.appendChild(document.createTextNode("x"));
  411.             let txtNode = document.createTextNode(sessions[i])
  412.             let aNode = document.createElement("a");
  413.             if (luaEngine.getSessionId() == sessions[i]) {
  414.                 aNode.href = "#";
  415.                 aNode.style = "color: lightblue; text-decoration: none; cursor: default;";
  416.             } else {
  417.                 aNode.href = "./?session=" + sessions[i];
  418.                 aNode.style = "text-decoration: none;";
  419.             }
  420.             aNode.appendChild(txtNode)
  421.             let liNode = document.createElement("li");
  422.             liNode.className = "top-tab";
  423.             liNode.appendChild(aNode);
  424.             liNode.appendChild(spanNode);
  425.             targetDOM.appendChild(liNode);
  426.         }
  427.         codewindow.style.filter = "blur(0)";
  428.     }
  429.     luaEngine.getInstances(updateTop)
  430.  
  431.     // No longer writable
  432.     /*
  433.     document.getElementById('lua-codewindow').addEventListener('keydown', (evt) => {
  434.         // TODO filter out only specific key codes?
  435.         if (luaEngine.getSessionId() != null) {
  436.             evt.preventDefault();
  437.         }
  438.         //if (evt.keyCode === 13) {
  439.         //    // New lines are weird, the 'contenteditable' will add a <div> instead of a <span>
  440.         //    evt.preventDefault();
  441.         //    luaEngine.updateLastTick(); // prevent updating
  442.         //    document.execCommand('insertHTML', false, '<br/>') // simulate new line
  443.         //}
  444.     });
  445.     */
  446. };
  447.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement