Created
July 8, 2024 05:15
-
-
Save X-Gorn/e881afb007713a78c2fe429b08b6d7ce to your computer and use it in GitHub Desktop.
unPack javascript eval
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
////////////////////////////////////////// | |
// Un pack the code from the /packer/ // | |
// By [email protected] // | |
// http://matthewfl.com/unPacker.html // | |
////////////////////////////////////////// | |
// version 1.2 | |
function unPack (code) { | |
function indent (code) { | |
try { | |
var tabs = 0, old=-1, add=''; | |
for(var i=0;i<code.length;i++) { | |
if(code[i].indexOf("{") != -1) tabs++; | |
if(code[i].indexOf("}") != -1) tabs--; | |
if(old != tabs) { | |
old = tabs; | |
add = ""; | |
while (old > 0) { | |
add += "\t"; | |
old--; | |
} | |
old = tabs; | |
} | |
code[i] = add + code[i]; | |
} | |
} finally { | |
tabs = null; | |
old = null; | |
add = null; | |
} | |
return code; | |
} | |
var env = { | |
eval: function (c) { | |
code = c; | |
}, | |
window: {}, | |
document: {} | |
}; | |
eval("with(env) {" + code + "}"); | |
code = (code+"").replace(/;/g, ";\n").replace(/{/g, "\n{\n").replace(/}/g, "\n}\n").replace(/\n;\n/g, ";\n").replace(/\n\n/g, "\n"); | |
code = code.split("\n"); | |
code = indent(code); | |
code = code.join("\n"); | |
return code; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment