Skip to content

Instantly share code, notes, and snippets.

@X-Gorn
Created July 8, 2024 05:15
Show Gist options
  • Save X-Gorn/e881afb007713a78c2fe429b08b6d7ce to your computer and use it in GitHub Desktop.
Save X-Gorn/e881afb007713a78c2fe429b08b6d7ce to your computer and use it in GitHub Desktop.
unPack javascript eval
//////////////////////////////////////////
// Un pack the code from the /packer/ //
// By matthew@matthewfl.com //
// 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