UGLIFYJS2 Global Obfuscation

Source: Internet
Author: User

After cloning uglifyjs2 source from Git, go to directory:

NPM Link

If you compile and install UGLIFYJS2 successfully, you can call the UGLIFYJS command directly. However, there was a problem with global obfuscation, although the cache file Topvar.json as a global variable was specified, or it appears:

1) The confusion name conflicts with the local variables after the confusion of the global variables;

2) Confusion name conflicts of different global variables.

Check the documentation and do some testing, but no success. Finally, flip through the code and make the following changes:

1) Modify the SymbolDef.prototype.mangle function in the Scope.js file:

 1  //  2  if  (this . Scope instanceof   Ast_toplevel) { 3  console.log (this . Name +" = + "+ this  .mangled_name);   4  this . Mangled_name = "__" + this . Mangled_name + "__" ;  5 }  

For the confusion of global variables, add double underscore prefixes to avoid collisions. After this modification, you need to filter out the global symbols that have been used when calculating next_mangled_name.

2) Add the following processing in the function Next_mangled_name function:

1      while(true) {2Name = base54 (+ +)scope.cname);3         //Double underline filtering4         if(in_use[' __ ' + name + ' __ ') | |!is_identifier (NAME) | | Member (name, options.reserved))Continue;5         if(!names[name]) Break;6 Holes.push (scope.cname);7}

After this, the problem of global variable confusion is completely solved.

UGLIFYJS2 Global Obfuscation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.