Best way to decompress javascript files - javascript

There are many tools to compress a Javascript file (Packer YUI for example).
But how can I decompress them back to a human readable format?
I have compressed a file using a tool like Packer YUI , but I couldn't reach the source back again.
Is there any good software or tricks you can suggest to decompress the JS ?

You can't. Javascript compression is usually a lossy one, and the information is lost forever.
What you can do, is use a source formatter and a good refactoring tool and -- painfully -- reconstruct the original source. Even if you are not familiar with the code it should be possible; Jeff and a few others reverse engineered the WMD javascript code from a minified version.
Finally, you should consider using a version control system and proper backups to keep your source code safe.

This website is really cool. You can paste a minified JS, then you get a human readable view.

Try JSMinNpp (now called JSToolNpp) plugin for notepad++ (to compress and decompress).
http://www.sunjw.us/jstoolnpp/

DECOMPRESS JAVASCRIPT
A typical JavaScript compressed with /packer/ starts with the following code:
`eval(function(p,a,c,k,e,r)`…
`eval` can simply be replaced by alert.
The eval function evaluates a string argument that contains JavaScript. In most packers, eval is used, followed by document.write.
To decompress JavaScript, replace these methods by one of the following:
1. Replace eval by alert (The alert will simply print the code in a popup-window)
2. If the JavaScript appears after the <body> element, you can add a <textarea> like so:
`<textarea id="code"></textarea>`
Then, replace eval(…); by document.getElementById("code").value=…;.

A linter like ESLint can be handy as well. It can format the code using the "fix all auto-fixable problems" to a point where you can at least start doing manual editing with greater ease.

I never used Packer YUI. But if you use this javascript packer, you can always get your code back using this javascript beautifier which also decompresses the code.
Some javascipt minifier shorten the variable names while compressing the js. In that case you could never get your original code back even if you beautify it.

Related

finding the meaning of the obfuscated javascript

i saw this piece of code in an obfuscated javascript :
if(1s Q.is.ep=='a')
do you have any idea what this might mean? Im quite confused about the space..
thanks :)
The code looks like generated by Dean Edwards' packer (or another similar one). You could unpack it with this tool.
It's indeed JavaScript, however replaced keywords, method, variables with meaningless strings. The bottom half of the file you provided is actually a mapper between obscured and original.
And this, it the power of eval (and don't use eval if by all means you could do without it).

How can I decode this encoded JavaScript file?

I have to deal with a very strange JavaScript file. It's called with a standard
<script src=XXXX.js type=text/javascript></script>
but XXXX.js is somehow packed/encrypted/whatever. The first characters are:
##~^3wcAAA==###&0; mDkW
and there is not any pattern in it. there isn't any sign of known function as eval or equivalent.
How can I manage to read it's content? Is it a character set trick?
The creator might have used some kind of javascript obfuscator tool.
Try using the deobfuscator tool-plugin for firefox:
https://addons.mozilla.org/en-us/firefox/addon/javascript-deobfuscator/
You should look for the first few characters of your string, which could lead you to the right tool. I don't want to spoil the fun here, so I leave the rest to you ;)
If you know the method, I can recommend Cyber Chef to decode your script

javascript codes refacting using ruby

Suppose I have some javascript code like this:
function Person(){}
var pro=Person.prototype;
pro["setName"]=function(){}
pro["setAge"]=function(){}
....
Now,I will use the closure compiler to minify the source codes.
However,since Closure Compiler compilation never changes string literals,so I want to replace the myself.
So before compile the codes,I want to replace the string literals like this:
var a="setName",b="setAge";
function Person(){}
var pro=Person.prototype;
pro[a]=function(){}
pro[b]=function(){}
I want to use ruby to do this job,then I have two questions:
1)how to do the replacement?
I tried scan the files line by line,but how to find the string literals and do the replacement?
2)code conflict
Since I have to generate the variables like 'a,b',how to make sure that they are not conflict with my source codes? For example,I generate code like this:
var something="setName";
then how about if there is a varible or function named "something" defined in my source code?
If for some reason you are concerned about raw JS size instead of compressed JS (most people should only worry about compressed size). Perhaps you should consider enabling the "alias all strings" compiler options (available in the Closure Compiler's Java API)?
Instead of doing this you should consider using gzip to compress your files after closure minifies them.
gzip works by finding duplicated strings in the input data and replaces the second occurrence of the string with a pointer to the previous string. It will do this to all your input data, not just javascript string literals.
http://www.gzip.org/
I don't think your overall idea is correct, and I particularly think that doing 1) is too complicated to be able to answer within a single webpage. For 2), it is similarly difficult to do it from outside of the Javascript code, but you may be able to adjoin the original Javascript code with a couple of lines, referencing Here, run the Javascript, and get the list of variables.

How to setup Xcode for proper javascript formatting?

Xcode3 (and newer ;) doesn't properly format Javascript when I type something like:
doSomething(somewhere, function(err, result) {
It inserts a huge indentation. I tried to change Xcode formatting rules but no luck. One way or another it breaks indentations.
Is there a proper way to use Xcode for javascript development?
What worked fairly well for me is to switch the .js files to use C syntax coloring.
In XCode 4: Editor -> Syntax Coloring -> C
It still highlights numbers and strings and comments, and it indents braces in a sane way.
With some tweaking it is possible to modify the way Xcode indents JavaScript by supplying a custom xclangspec file. Xcode for formatting and syntax uses language definitions in xclangspec files kept in directory SharedFrameworks/DVTFoundation.framework/Versions/A/Resources. Since the formatting for C language works actually better for JavaScript than the Xcode original JavaScript formatting, it is possible to use some parts of definition for C in JS definition. More details you can find at http://www.conhar.com/xcode-and-javascript/.
A quick solution is to choose View -> Syntax Coloring -> Simple Coloring.
If you are okay to edit Javascript without fancy syntax highlight, this is pretty useful.
This way only the numbers and strings are colored, and the indentation stops being so annoying.
Unfortunatelly XCode has very limited formatting options.
But you can use uncrustify which is pretty good. You can find some information here:
Xcode source automatic formatting
Objective-C Tidy
These articles all talk about formatting objective-c code, however uncrustify can format the source code of various languages ;)
Hope this helps.
Uncrustify requires a .cfg file to setup which can be somewhat overwhelming. There's an alternative here

Complex wolframalpha ajax query

I want to write formulas in Mathematica format in my blog, inside tag's formula. What js should I use (and what libary), to replace those tag's, with http://www.wolframalpha.com/ search result image, when Dom gets loaded?
For example:
<formula>Limit[((3 + h)^(-1) + -1/3)/h, h -> 0]</formula>
gets replaced with:
If it's to complex or can not be done with javascript, please explain why.
You need to use wolframalpha API service, but it's not free and you can't do this using javascript because of same origin policy, only using server-side language.
It seems that your real question is: "how do I get nice math on Blogger.com", so I will answer this instead.
A proven solution (see e.g. Psychedelic Geometry, no affiliation) is to use the MathTex system by John Forkosh (who also hosts a public cgi) together with the ReplaceMath script by Randall Farmer. Browse some source for modified versions of the script.
Installation is a matter of including a single javascript file, after which you can inline LaTeX in your html as $latex <some LaTeX to be png'ified> $.
If you want to format output from Wolfram Alpha then #antyrat is correct. But if you just want to write nice-looking mathematical expressions for your blog you should look at Presentation MathML and LaTeX. There is a variety of utilities for rendering LaTeX into gif or png or similar formats.

Categories

Resources