[JS Reverse] Know how to distinguish scope in seconds

Scope is the basis of JS reverse engineering, how to distinguish which piece it belongs to.

1. Explanation of scope: scope is divided into global scope and handle scope. {Local scope: Variables are declared in the function. Variables are in the local scope. Global scope: Global variables. All scripts and functions in a web page can be used, which is called global scope. }
2. On the code, let's talk about variables first:


var  aaa;//声明一个全局变量,在所有函数外面,所有函数都可以调用到。
//这个就是全局作用域,比如我们的window变量。

function xxx(){
    
    

var  sss;//在这个函数内部声明的变量叫做局部变量,只有
//这个xxx函数可以调用这个sss变量,其他在xxx函数外面声明的
//函数无法调用这个sss变量。这个就是要局部作用域。如果在xxx函数内部声明
//的函数那么sss是可以被调用的。下面我再写一个例子


}

function person(){
    
    

var  h=0;  // 在person内部声明一个属于person的全局变量,person里的的所有函数
//都可以调用这个h这个变量。h就算是再person函数内部的声明全局作用域,
//调用只能在person函数内部,外面无法调用。

function myfucntion(){
    
    

var x=5  //x是myfunction函数的局部作用域,只能再myfunction内部调用,外部无法调用,
//就算是person也无法调用。因为它的作用域只在myfunction这个函数内部。

return h+x;

}

return myfucntion()
}




3. You understand the variables. If you don't understand, please comment below. I will answer them one by one. Now let's talk about the scope of the function. Aside from the code:



function test(){
    
    
return "第一个函数"
}

function test2(){
    
    
return "第二个函数"
}

function test3(){
    
    
return "第三个函数"
}

//这个三个函数都是全局函数,属于全局作用域。因为这个三个函数我们都可以直接调用,属于全局,
//下面我例举这个函数就叫做局部作用域。
function myfunction (){
    
    
function test(){
    
    
return "第一个函数"
}

function test2(){
    
    
return "第二个函数"
}

function test3(){
    
    
return "第三个函数"
}

}
//这种情况我们在外部是无法调用这个三个函数的,在外部只能调用这个myfunction这个全局函数,
//而这个test这三个函数我们需要在myfunction这个函数内部才能调用,因为它们三个函数的作用
//域是在myfunction函数内部的。



The scope of a function is not difficult, but it is important to understand which part it belongs to. In JS reverse engineering as long as we can distinguish words. There is nothing too big a problem.

4. The article is not easy to write. Please also ask the big guy to give the little brother a thumbs up, the little brother is grateful here.

Guess you like

Origin blog.csdn.net/weixin_44504978/article/details/112666921