Hi javascriptians,
You will have at some stage come across a piece of Javascript code that has been packed to compress as well as to obfusicate the code. If you want to get the original code from the compressed files you can use the another unpacking javascript code. I am getting this code from http://matthewfl.com/unPacker.html writen by mathew. I got this and used very much, so I wanted to share with my friends.
Thanks to Mathew
unpacker.js
-----------
//////////////////////////////////////////
// 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;
}
Save this file in unpacker.js
Example how to use
include the javascript file in a html page using
<script src="unpacker.js" ></script>
and call the function unPack() to unpack the code like following
<script>
code = "<unpacked file contents>"
var unpackedcontent = unPack(code);
document.write(unpackedcontent); // optional, to show the unpacked content.
</script>
If you have any issues, please feel free to contact me at codesmokers@gmail.com
No comments:
Post a Comment