Adsense-HeaderAd-Script


Advertisement #Header

13 Jul 2014

Regular Expression to hack a source code


There are many quality open source code available in github and code.google . Now if we wish to hack some source code, the best way to learn how it works is to see a log where the function name is displayed in the order it is executed.

Insert Debug Code using Regular Expression

By this technique, we can find the function using regular expression and insert our debug code inside each function.

Lets illustrate with a Javascript  Source Code and Notepad++ IDE

Regular Expression to Find functions

((\w*)\s*[:|=]\s*function\(\w*\)\s*\{)

Debug Code to insert inside each functions

console.log("functionName");

Regular Expression to Insert Debug Code inside Functions

$1 \n\tconsole\.log\("$2"\)\;

A sample Javascript before inserting Debug code
var SyntaxHighlighter = function() {
    var sh = {
        all: function(params)
        {
            attachEvent(
                window,'description'
            );
        }
    };
}();

Javascript code after inserting Debug code using Regular Expression
var SyntaxHighlighter = function() {
      console.log("SyntaxHighlighter");
    var sh = {
        all: function(params)
        {
            console.log("all");
            attachEvent(
                window,'description'
            );
        }
    };
}();


Note: Please enable "Regular expression" and ". matches newline" in Search Mode in Replace box in Notepad++ for inserting inside more than 1 function using regular expression.



How this Regular Expression Works


Find Regex :
((\w*)\s*[:|=]\s*function\(\w*\)\s*\{)
Replace Regex:
$1 \n\tconsole\.log\("$2"\)\;

No comments:

Post a Comment