Flappy Pig is cracked by experts for "Invincible" code analysis

Source: Internet
Author: User

When I got up this morning, I saw a message from my friend @ Laix. He left a piece of "strange code" saying that it would be amazing to execute the code on the console:

 
 
  1. 1._=~[];_={___:++_,$$$$:(![]+"")[_],__$:++_,$_$_:(![]+"")[_],_$_:++_,$_$$:({}+"")[_],$$_$:(_[_]+"")[_],_$$:++_,$$$_:(!""+"")[_],$__:++_,$_$:++_,$$__:({}+"")[_],$$_:++_,$$$:++_,$___:++_,$__$:++_};_.$_=(_.$_=_+"")[_.$_$]+(_._$=_.$_[_.__$])+(_.$$=(_.$+"")[_.__$])+((!_)+"")[_._$$]+(_.__=_.$_[_.$$_])+(_.$=(!""+"")[_.__$])+(_._=(!""+"")[_._$_])+_.$_[_.$_$]+_.__+_._$+_.$;_.$$=_.$+(!""+"")[_._$$]+_.__+_._+_.$+_.$$;_.$=(_.___)[_.$_][_.$_];_.$(_.$(_.$$+"\""+_.$$$$+(![]+"")[_._$_]+_.$_$_+"\\"+_.__$+_.$$_+_.___+"\\"+_.__$+_.$$_+_.___+"\\"+_.__$+_.$$$+_.__$+".\\"+_.__$+_.$_$+_.__$+"\\"+_.__$+_.$_$+_.$$_+"\\"+_.__$+_.$_$+_.__$+_.__+"();"+"\"")())(); 

This mess of code doesn't even contain letters. I opened Flappy Pig and tried chrome or firefox. F12 calls out the developer tool, input the code above, and press Enter ):

 

Then press the Space key to start the game ~~~~~ The magic thing happened, and pig was invincible. It won't die if it hits the pillar ~~~~~~

Next, we will analyze how this expert did it.

First, let's beautify the strange javascript:

 
 
  1. _ = ~ [];  
  2. _ = {  
  3. ___: ++_,  
  4. $$$$: (![] + "")[_],  
  5. __$: ++_,  
  6. $_$_: (![] + "")[_],  
  7. _$_: ++_,  
  8. $_$$: ({} + "")[_],  
  9. $$_$: (_[_] + "")[_],  
  10. _$$: ++_,  
  11. $$$_: (!"" + "")[_],  
  12. $__: ++_,  
  13. $_$: ++_,  
  14. $$__: ({} + "")[_],  
  15. $$_: ++_,  
  16. $$$: ++_,  
  17. $___: ++_,  
  18. $__$: ++_  
  19. };  
  20. _.$_ = (_.$_ = _ + "")[_.$_$] + (_._$ = _.$_[_.__$]) + (_.$$ = (_.$ + "")[_.__$]) + ((!_) + "")[_._$$] + (_.__ = _.$_[_.$$_]) + (_.$ = (!"" + "")[_.__$]) + (_._ = (!"" + "")[_._$_]) + _.$_[_.$_$] + _.__ + _._$ + _.$;  
  21. _.$$ = _.$ + (!"" + "")[_._$$] + _.__ + _._ + _.$ + _.$$;  
  22. _.$ = (_.___)[_.$_][_.$_];  
  23. _.$(_.$(_.$$ + "\"" + _.$$$$ + (![] + "")[_._$_] + _.$_$_ + "\\" + _.__$ + _.$$_ + _.___ + "\\" + _.__$ + _.$$_ + _.___ + "\\" + _.__$ + _.$$$ + _.__$ + ".\\" + _.__$ + _.$_$ + _.__$ + "\\" + _.__$ + _.$_$ + _.$$_ + "\\" + _.__$ + _.$_$ + _.__$ + _.__ + "();" + "\"")())(); 

We can see that, in fact_Is a variable. We usually do not name the variable like this ),~ []-1. You can execute it. Don't ask me why. I am a newbie, but I don't have a solid foundation in javascript, and I haven't fully understood it yet.) and so on, code can be further "Beautified", although this step is a little too large ):

 
 
  1. _ = ~ [];  
  2. _ = {  
  3. $$$: 7  
  4. $$$$: "f" 
  5. $$$_: "e" 
  6. $$_: 6  
  7. $$_$: "d" 
  8. $$__: "c" 
  9. $_$: 5  
  10. $_$$: "b" 
  11. $_$_: "a" 
  12. $__: 4  
  13. $__$: 9  
  14. $___: 8  
  15. _$$: 3  
  16. _$_: 2  
  17. __$: 1  
  18. ___: 0  
  19. };  
  20. _.$_ = "constructor";  
  21. _.$$ = "return" 
  22. _.$ = (0)[constructor][constructor];  
  23. 0["constructor"]["constructor"](  
  24. 0["constructor"]["constructor"](  
  25. "flappy.init ()" 
  26. )()  
  27. )(); 

The most critical code is(0)[constructor][constructor]In essenceflappy.init (), About(0)[constructor][constructor]From the analysis here, we can start flappy pig again, open the developer tool, and executeflappy.init ():

That's right. Pig is invincible.

Summary:

1. The core is to execute a sentence.flappy.init ()This is my negligence. Once again the game is initialized, it will produce bugs, and pig will be invincible.

2. This expert used complicated code and pieced together to execute a variety of tasks that I could not understand.flappy.init ().

3. I still have no knowledge of javascript.

4. @ Laix you are really naughty.

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.