Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // #==================================#
- // # toolbox-collapsible #
- // #==================================#
- var coll = document.getElementsByClassName("toolbox-collapsible");
- var i;
- for (i = 0; i < coll.length; i++) {
- coll[i].addEventListener("click", function () {
- this.classList.toggle("toolbox-hit");
- var content = this.nextElementSibling;
- if (content.style.display === "block") {
- content.style.display = "none";
- } else {
- content.style.display = "block";
- }
- /*if (content.style.height === "auto") {
- content.style.height = "0";
- } else {
- content.style.height = "auto";
- }*/
- });
- }
- let toolboxDiv = document.getElementById("notepad-toolbox1");
- let toolboxDownloadBtn = document.getElementById("toolbox-download-btn");
- let codeWindow = document.getElementById("lua-codewindow")
- let downloadBtn = document.getElementById("toolbox-download-btn");
- function toggleHome(state) {
- // toggle home/landing page elemts on/off
- if (toolboxDiv == null) {
- return;
- }
- if (state) {
- toolboxDiv.style.filter = "Saturate(0.1)";
- toolboxDownloadBtn.style.display = "none";
- //codeWindow.contentEditable = false;
- codeWindow.style.filter = "blur(0)";
- }
- else {
- toolboxDiv.style.filter = "none";
- toolboxDownloadBtn.style.display = "block";
- //codeWindow.contentEditable = true;
- codeWindow.style.filter = "blur(0)";
- }
- }
- // load on playground ONLY?
- window.onload = function () {
- // #==================================#
- // # UI Button #
- // #==================================#
- let isObfuscating = false
- function startObfuscation() {
- if (isObfuscating)
- return false
- codeWindow.style.filter = "blur(3px)";
- isObfuscating = true;
- return true
- }
- function stopObfuscation() {
- if (!isObfuscating)
- return false
- codeWindow.style.filter = "blur(0px)";
- isObfuscating = false;
- return true
- }
- let gtagz = "adsbygoogle";
- let luafile = document.getElementById("lua-file")
- if (luafile != null) {
- // NOTE: only load on index?
- // TODO: improve
- downloadBtn.addEventListener("click", function (e) {
- var a = document.createElement('a');
- var blob = new Blob([document.getElementById("lua-codewindow").innerText], { "type": "text/plain" });
- a.href = window.URL.createObjectURL(blob);
- a.download = "obf_" + luaEngine.getSessionId() + ".lua";
- a.click();
- });
- document.getElementById("lua-pre-1").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("pre-1", 1, frontcallback);
- })
- document.getElementById("lua-pre-2").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("pre-2", 2, frontcallback);
- })
- document.getElementById("lua-pre-3").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("pre-3", 3, frontcallback);
- })
- document.getElementById("lua-pre-4").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("pre-4", 4, frontcallback);
- })
- document.getElementById("lua-pre-5").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("pre-5", 5, frontcallback);
- })
- document.getElementById("lua-cleanup3").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.cleanup(frontcallback)
- })
- document.getElementById("lua-cleanup").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.cleanup(frontcallback)
- })
- document.getElementById("lua-junkif").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("junkif", 50, frontcallback);
- })
- document.getElementById("lua-reverseif").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("reverseif", 65, frontcallback);
- })
- document.getElementById("lua-cffv1").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("cffv1", 50, frontcallback);
- })
- document.getElementById("lua-cffv1-exp").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("cffv1", 50, frontcallback);
- })
- document.getElementById("lua-literals").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("literals", 50, frontcallback);
- })
- document.getElementById("lua-mbav1").addEventListener("click", function (e) {
- if (startObfuscation())
- luaEngine.obfuscate("MBAv1", 75, frontcallback);
- })
- document.getElementById("lua-variables").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("variables", 50, frontcallback);
- })
- document.getElementById("lua-minify").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("minify", 100, frontcallback);
- })
- document.getElementById("lua-minify2").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("minify", 100, frontcallback);
- })
- document.getElementById("lua-beautify").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("beautify", 100, frontcallback);
- })
- document.getElementById("lua-beautify2").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("beautify", 100, frontcallback);
- })
- document.getElementById("lua-beautify3").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("beautify", 100, frontcallback);
- })
- document.getElementById("lua-strings").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("strings", 100, frontcallback);
- })
- document.getElementById("lua-tableindirection").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("tableindirection", 100, frontcallback);
- })
- document.getElementById("lua-demo_vm").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("demo_vm", 100, frontcallback);
- })
- document.getElementById("lua-demo_vm-exp").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("demo_vm", 100, frontcallback);
- })
- //document.getElementById("lua-virtualize").addEventListener("click", function (e) {
- // luaEngine.obfuscate("virtualize", 100, frontcallback);
- //})
- //document.getElementById("lua-devirtualize").addEventListener("click", function (e) {
- // luaEngine.obfuscate("devirtualize", 100, frontcallback);
- //})
- //document.getElementById("lua-emulate").addEventListener("click", function (e) {
- // luaEngine.obfuscate("emulate", 0, frontcallback);
- //})
- document.getElementById("lua-undo").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("undo", 0, frontcallback);
- })
- document.getElementById("lua-undoAll").addEventListener("click", function (e) {
- if(startObfuscation())
- luaEngine.obfuscate("undoAll", 0, frontcallback);
- })
- document.getElementById("lua-reset").addEventListener("click", function (e) {
- window.location.href = "/"
- })
- document.getElementById("lua-reset2").addEventListener("click", function (e) {
- window.location.href = "/";
- })
- // experimental
- document.getElementById("lua-ssa").addEventListener("click", function (e) {
- if (startObfuscation())
- luaEngine.obfuscate("ssa", 0, frontcallback);
- })
- // landing page buttons
- document.getElementById("btn-demo").addEventListener("click", function (e) {
- if (!isObfuscating) {
- luaEngine.init(frontcallback, flags, true); // empty to get demo
- }
- })
- document.getElementById("btn-uploadfile").addEventListener("click", function (e) {
- if (!isObfuscating) {
- document.getElementById("lua-file").click();
- }
- })
- // on file uploaded
- luafile.addEventListener("change", function (e) {
- if (!isObfuscating && this.files.length > 0) {
- // take first file
- codeWindow.style.filter = "blur(7px)";
- isObfuscating = true; // block UI buttons
- this.files[0].text().then(x => luaEngine.init(frontcallback, flags, true, x))
- }
- })
- }
- // TODO: remove?
- /*
- function getCaretCoordinates() {
- let x = 0;
- let y = 0;
- const isSupported = typeof window.getSelection !== "undefined";
- if (isSupported) {
- const selection = window.getSelection();
- if (selection.rangeCount !== 0) {
- const range = selection.getRangeAt(0).cloneRange();
- range.collapse(true);
- const rect = range.getClientRects()[0];
- if (rect) {
- x = rect.left;
- y = rect.top;
- }
- }
- }
- return { x, y };
- }*/
- // TODO: remove?
- /*
- function getCaretIndex(element) {
- let position = 0;
- let isSupported = typeof window.getSelection !== "undefined";
- if (isSupported) {
- let selection = window.getSelection();
- if (selection.rangeCount !== 0) {
- let range = window.getSelection().getRangeAt(0);
- let preCaretRange = range.cloneRange();
- preCaretRange.selectNodeContents(element);
- preCaretRange.setEnd(range.endContainer, range.endOffset);
- position = preCaretRange.toString().length;
- }
- }
- return position;
- }*/
- let frontcallback = function (lastEvent) {
- //var startOff = getCaretIndex(codeWindow)
- //codeWindow.style.filter = "blur(0px)";
- stopObfuscation();
- let test = document.getElementById("lua-codewindow");
- // if (!luaEngine.parseScript($(".lang-lua"), lastEvent))
- if (!luaEngine.parseScript(test, lastEvent))
- return;
- // TODO: find a better way to count lines lol!
- /*
- let testLines = document.getElementById("notepad-lines-ul");
- if (testLines != null && test != null) {
- testLines.innerHTML = "";
- var count = 1;
- //let lineCount = test.innerText.split('\n').length;
- for (var i = 0; i <= test.innerText.length; i++) {
- if (test.innerText[i] == '\n' || i == test.innerText.length-1) {
- let txt = document.createTextNode(count++);
- var li = document.createElement("li");
- li.appendChild(txt);
- testLines.appendChild(li);
- if (count >= 2048)
- break;
- }
- }
- }*/
- // NOTE: skip range as we no longer want editable content?
- /*
- var newRange = document.createRange()
- // quick fix, iterate over nodes
- var index = 0
- var targetChild = 0
- var nextChild = codeWindow.firstChild;
- for (var i = 0; i < codeWindow.children.length; i++) {
- var child = codeWindow.children[i]
- if (index + child.innerText.length >= startOff) {
- targetChild = i
- break;
- }
- index += child.innerText.length
- }
- newRange.setStart(codeWindow.childNodes[targetChild].firstChild, startOff - index)
- newRange.collapse(true)
- var sel = window.getSelection()
- sel.removeAllRanges()
- sel.addRange(newRange)
- */
- // TODO: check size?
- let lconsole = document.getElementById("lua-console");
- if (lconsole != null && window.innerWidth > 600) {
- lconsole.style.display = "block";
- }
- // toogle UI elements
- toggleHome(luaEngine.getSessionId() == null)
- };
- let consolecallback = function (msg) {
- // TODO?
- let consoleul = document.getElementById("lua-console-ul");
- if (consoleul != null) {
- // Don't judge me for timestamp, judge ChatGPT
- const date = new Date();
- const hours = date.getHours().toString().padStart(2, '0');
- const minutes = date.getMinutes().toString().padStart(2, '0');
- const seconds = date.getSeconds().toString().padStart(2, '0');
- const milliseconds = date.getMilliseconds().toString().padStart(3, '0');
- let li = document.createElement("li");
- li.appendChild(document.createTextNode(`[${hours}:${minutes}:${seconds}.${milliseconds}]: ${msg}`));
- consoleul.appendChild(li)
- }
- }
- consolecallback("test... Hello World!");
- consolecallback("test... Hello World!");
- consolecallback("test... Hello World!");
- consolecallback("test... Hello World!");
- consolecallback("test... Hello World!");
- consolecallback("test... Hello World!");
- consolecallback("test... Hello World!");
- consolecallback("test... Hello World!");
- consolecallback("test... Hello World!");
- consolecallback("test... Hello World!123");
- // TODO: remove? (or auto upload?)
- //codeWindow.addEventListener("input", function (e) {
- // luaEngine.updateScript(this.innerText, frontcallback)
- //});
- // TODO: remove?
- codeWindow.addEventListener("click", function (e) {
- //toggleTooltip(e)
- })
- let flags = document.getElementsByClassName(gtagz).length;
- // #==================================#
- // # Init Lua Engine #
- // #==================================#
- luaEngine.init(frontcallback, flags)
- function updateTop(sessions) {
- let landingpage = document.getElementById("home-landingpage")
- let targetDOM = document.getElementById("lua-sessions");
- let codewindow = document.getElementById("lua-codewindow");
- // main/home?
- let spanHome = document.createElement("span");
- spanHome.className = "top-tab-close";
- //spanHome.appendChild(document.createTextNode("x"));
- let txtHome = document.createTextNode("Home")
- let aHome = document.createElement("a");
- if (luaEngine.getSessionId() == null) {
- aHome.href = "#";
- aHome.style = "color: lightblue; text-decoration: none; cursor: default;";
- landingpage.style.display = "flex";
- } else {
- aHome.href = "/";
- aHome.style = "text-decoration: none;";
- }
- aHome.appendChild(txtHome)
- let liHome = document.createElement("li");
- liHome.className = "top-tab";
- liHome.appendChild(aHome);
- liHome.appendChild(spanHome)
- targetDOM.appendChild(liHome);
- for (var i = 0; i < sessions.length; i++) {
- let spanNode = document.createElement("span");
- spanNode.className = "top-tab-close";
- spanNode.appendChild(document.createTextNode("x"));
- let txtNode = document.createTextNode(sessions[i])
- let aNode = document.createElement("a");
- if (luaEngine.getSessionId() == sessions[i]) {
- aNode.href = "#";
- aNode.style = "color: lightblue; text-decoration: none; cursor: default;";
- } else {
- aNode.href = "./?session=" + sessions[i];
- aNode.style = "text-decoration: none;";
- }
- aNode.appendChild(txtNode)
- let liNode = document.createElement("li");
- liNode.className = "top-tab";
- liNode.appendChild(aNode);
- liNode.appendChild(spanNode);
- targetDOM.appendChild(liNode);
- }
- codewindow.style.filter = "blur(0)";
- }
- luaEngine.getInstances(updateTop)
- // No longer writable
- /*
- document.getElementById('lua-codewindow').addEventListener('keydown', (evt) => {
- // TODO filter out only specific key codes?
- if (luaEngine.getSessionId() != null) {
- evt.preventDefault();
- }
- //if (evt.keyCode === 13) {
- // // New lines are weird, the 'contenteditable' will add a <div> instead of a <span>
- // evt.preventDefault();
- // luaEngine.updateLastTick(); // prevent updating
- // document.execCommand('insertHTML', false, '<br/>') // simulate new line
- //}
- });
- */
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement