It's fairly straightforward to turn the obfuscated code back into the effective javascript that runs - typically you just need to expand a bunch of eval
calls.
The tricky part, as others have stated, is giving names to the variables so that you can work out what something like v7 = a4.l2(h8, n1, p9)
means. Something I've found helpful is to start from the "edges" (library calls that can't be renamed" and then rename things as helpfully as possible. You'll often find that this knowledge then ripples through the code, making it easier to grasp the next layer down and give it a sensible name.
So for example, if you had some code like this:
z4 = "a";
o0 = "href"
...
pr = window.document;
...
q8 = pr.getElementByTagName(z4)[0];
...
function rr(o8, em)
{
return o8.getAttribute(em);
};
...
y5 = rr(q8, o0);
Then the last line is initially impenetrable, but if you decide that rr
could be called getNamedAttribute
, rename z4
as LITERAL_A
, o0
as LITERAL_HREF
and pr
as document
; then we can see that q8
is the result of document.getElementByTagName(LITERAL_A)[0]
, so we might call it firstAnchor
. Then q8 = getNamedAttribute(firstAnchor, LITERAL_HREF)
and all of a sudden it's clear it's the (string) target of the first hyperlink.
Since this transformation requires inference on behalf of the reader, it's not possible for this to be an automatic process (for exactly the same reason that a compiler won't warn you about inappropriate variable names).