Reverse Engineer Packer javascript
June 11th, 2009 Filed Under Good to know, Javascript, Tips & Tricks, browser, debuggers, firefox, gyan
Have you ever seen a code something like this:
eval(function(p,a,c,k,e,r){e=funct.... etc....
And you suffer reading the encoded code. No suffers now; because I am going to tell you a trick that will convert your packer code in a readable script.
And it is really simple …. just replace the eval word with alert and refresh your page. You can now copy the code from the alert box.
If you face the problem of copying it from the alert box then open firefox browser with firebug pre-installed.
Open the console using F12 key and paste the code in the editable window.
Now replace the first word “eval” with “console.log” and hit run.
Probably you would need Javascript Tidy to make it properly readable.
Enjoy Madi!!
Post Linx
Permalink | Trackback |
|
Print This Article | Leave a Comment
javascript object looping
February 2nd, 2009 Filed Under Good to know, Javascript, Tips & Tricks, gyan
In javascript generally all of us must have seen the following construct.
for(i=0; i<arrayObj.length; i++)
{
// then the code
}
But more than 50% of the time you loop through some javascript object or some javascript array.
So in order to write less and convenient code, you can also write the same for in the following fashion
for(i in arrayObj)
{
//then the code
}
It pretty much does the same job of looping. The only difference is that it takes the help of the object to be looped through for looping.
And that means you cannot use this stylish construct for an artificial looping, because the for(i=0; i< ….. construct is nothing but artificial looping.
Someone will ask then how do we get the loop index. It is pretty straight forward to get the index in case of simple array. The “i” will always return the current index.
Post Linx
Permalink | Trackback |
|
Print This Article | 2 Comments
Ajax Data - HTML vs. XML vs. JSON
December 19th, 2008 Filed Under Good to know, Javascript, Thinking Out Loud, Tips & Tricks, gyan, json
Ever wondered why Ajax stands for ‘Asynchronous Javascript And Xml’? I was thinking about it and realized that the ‘x’ is never used or let us say of almost no use.
Classically when introduced by Microsoft, xmlhttprequest object might have been thought to transport XML for the data transfers, as that was the most popular format which was known as the lightest in weight. But they forgot about the json.
Moreover, the scenario where we are standing today is really different than what had been thought earlier.
What was needed classically was to make a hidden request - get the response - inject in html - and show the result. But for this people started using the xmlhttp object as htmlhttp object. I mean rather than only transporting data, they are using HTML strings attached with the data(or the other way round).
I will show how can we make the request and response lighter and show results faster on the page so that the users don’t have to wait even on the dial up connections.
First let us compare the strings that are sent in a response in different formats.
HTML: <div class=”resultArea”><h3>This is the result of your query</h3><p><span>Request Num:</span>4564545<br/><span>Status:</span>Pending</p></div>
XML:
<resultArea>
<heading>This is the result of your query</heading>
<requestNum>4564545</requestNum>
<status>Pending</status>
</resultArea>
JSON:
{heading:”This is the result of your query”, requestNum:”4564545″, status:”Pending”}
Clearly you can see which one uses less number of characters.
Not only that, you are only an eval() away from start using the object with the luxury of (.) dot notations. What else do you need?
Had we been using HTML, we would have transported unnecessary HTML text along with the pure data to the browser. Just imagine the amount of repetitive HTML in case of a tabular data.
Using XML is also not so convinient because besides being bulky with its starting and ending tags, it is also needed to read via the DOM to traverse through the XML, which is time consuming, resource hungry and inconvinient code.
Post Linx
Permalink | Trackback |
|
Print This Article | Leave a Comment
Cheating HTML javascript load delay
October 17th, 2008 Filed Under Good to know, Javascript, Tips & Tricks, browser, gyan, vivek
When you write the following code in your HTML:
<script language="javascript" type="text/javascript" src="www.somewhere.com/somejs.js"></script>
Your page halts till the javascript is fully loaded. Just imagine the scenario where you have more than 10 different javascript files from 3 or 4 different domains/locations on your page.That means the javascript loading is synchronous in nature. Which means, untill all the javascript is loaded and interpreted the HTML control doesn’t move to the next tag after the current script tag. Hence, you see a 4-5 seconds delay which is really embarrasing for a visitor. To overcome this problem, what you can do is make javascript to load asynchronously. Now what does that mean?That means, you load your javascript dynamically. And that means, create your script tag using createElement function and insert it in the head tag via DOM manipulation.If you do so, you can see all the script tags load parallely and your load time reduces drammatically and you see lesser time as a white page.Enjoy!!
Post Linx
Permalink | Trackback |
|
Print This Article | Leave a Comment
Smart javascript arrays
September 16th, 2008 Filed Under Good to know, Javascript, Tips & Tricks, gyan, snippet, vivek
Today I want to show you some really professional and efficient way to populate your javascript array.
When you declare an array you can do it simply by writing a short hand like:
var arrSalaries = [];
Notice that the square brackets[] itself delcares the array and you don’t have to write “new Array()”. So you save some characters like that. Thanks to javascript.
Sometimes you need to populate an array in a loop and generally people populate it like this:
for(i=0; i<something.length; i++)
{
arrSalaries[i] = something[i].amount;
}
There is nothing wrong in the code but a more robust way would be:
for(i=0; i<something.length; i++)
{
arrSalaries[arrSalaries.length] = something[i].amount;
}
This ensures that any exceptions(if any), would be taken care and the array would be properly populated. To be in simple words, let us say you have an exceptional continue statement in the for loop and the statement is executed on some event. In such a case, the array would be populated wrongly in the following fashion:
arrSalaries[0] = 200; arrSalaries[1] = 200; arrSalaries[3] = 200;// just now there was the exception arrSalaries[4] = 200; arrSalaries[6] = 200;// just now there was the exception
If you use the second method to populate the array you can avoid this problem.
Another thing in array(not everyone remembers) is the literal arrays.
So you can delcare an array with a literal like this:
var arrSalaries = []; arrSalaries["vivek"] = 5000; arrSalaries["shon"] = 5000;
And you can access them with a dot operator like:
alert(arrSalaries.vivek);
or the same way you declared it:
alert(arrSalaries["vivek"]);
One should always think to minimize the code as far as possible. Even a single character shows your optimization attitude.
Now after knowing this one obvious question comes to your mind that how to loop through this literal arrays:
The answer is the following code:
for(props in arrSalaries) //in case you have forgotten for ... in in javascript this is a reminder
{
alert(arrSalaries[props]);//props represent the literal
}
The above way can be implemented to dig out any built-in or custom object to scan their attributes and methods.
But as commented by Andrew Dupont in his article associative arrays should not be used for storing values with literals at all.
Andrew is technically correct in saying that because you loose all the basic methods in this kind of array.
Better use it like this:
var arrSalaries = {};
arrSalaries["vivek"] = 5000;
arrSalaries["shon"] = 5000;
So, what you replace is [] with {}. And hence, you come to know that {} is a shortcut of declaring an object. Enjoy madi !!
Post Linx
Permalink | Trackback |
|
Print This Article | 2 Comments

