If you do not believe in Console. WriteLine, your console program will lose response, and Console. writeline

Source: Internet
Author: User

If you do not believe in Console. WriteLine, your console program will lose response, and Console. writeline

I haven't updated my blog for a long time. Today is the yiyijian Junjie festival. If you are idle, let's talk about a recent interesting discovery.

First of all, let's talk about the code.

1 class Program 2 {3 static void Main (string [] args) 4 {5 var bytes = new byte [4096]; 6 for (int I = 0; I <bytes. length; I ++) 7 {8 bytes [I] = 7; 9} 10 11 Console. writeLine (Encoding. ASCII. getString (bytes); 12 string line = Console. readLine (); // You are dead. This part has no chance to run ............ 13 while (line! = "OK") 14 {15 Console. WriteLine (line); 16 line = Console. ReadLine (); 17} 18} 19}

If you are interested, you can create a console program and run it to see if the program will lose response. check the information in the reply. It seems that WIN8.1 and win10. my testing in WIN7SP1 will cause a loss of response. if you still use XP, you can test the result and send it to us.

Why does it fail?

The key lies in the ASCII code 7. See the ASCII code table.


ASCII 7 stands for BELL, that is, let the buzzer on the motherboard sound, just like the drop when your computer was just started. therefore, if ASCII 7 is output, the motherboard will be called a buzzer, but now WINDOWS is taking over, not in the DOS era, and beep is used for the buzzer. sys: The driver file is taken over. beep under WIN7. sys will sound from the sound card, the beep under XP. sys still uses the motherboard buzzer. in other words, the bot virus will modify this beep. sys, after all, the permission is ring0, and taking the highest permission and anti-virus software is the final principle ......
So we use Console. when WriteLine outputs ASCII code 7, it calls the system function to generate a voice, instead of simply printing text on the console. when we output a large number of ASCII code 7, we will constantly call this system function. You will find that a svchost process in the process that is responsible for DComLaunch is basically in an endless loop, your console program will not respond again until the system function is called ......

 

What can this thing do?
After talking about this, what is the value of using this question? In fact, the utilization value is still quite large. Many service programmers like to start a console program directly and print exception information on the console, if you directly display user input, I only need to send a bunch of ASCII code 7, and your service will basically go down ......
Although I did a test in C #, it does not mean that other languages have no impact. After all, they are made into WINDOWS console programs. If you have any other language environment, try again.

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.