今天来现场制作一个恶搞程序。。。
练习的知识点:
1. 在批处理中使用输入并保存为变量
2. 对两个值进行判断
3. 模块化地编写代码,以便修改和阅读
4. 创建文件,并在使用后删除
5. 了解一些其他知识
程序的过程是这样的:
首先名字要取得由吸引力,诱使别人来运行,比如“如花的私密自拍.bat”;
运行之后是显示一些文字,让别人输入;
把输入的东西存到变量,然后判断,根据不同的值进行不同的操作。
==========================
好了,开工!
1) 在一个地方,就桌面吧,新建一个文本文档,重命名为 “如花的私密自拍.bat”(不含引号)。
2) 右键“编辑”,开始写代码啦。作为批处理,我们一般都会屏蔽我们输入的命令的显示,因此先加这个再说
@echo offCOPY
为了美观,我们再设置一下界面的颜色大小标题什么的,注意如果设置了高度(lines),那么CMD界面就没有滚动条了
| title 绝色美女私密相册 | | color 4d | | mode con cols=40 lines=15COPY |
3) 准备工作弄好了,可以开始写主体了,首先我们必须得到一个输入值,然后才能进行判断,我们把输入的值放入一个叫 mima 的变量里面,变量可以理解为杯子,可以装水,也可以倒掉装酒,它里面的数据是可以随时改变的。
这个功能一行就能搞定,而且可以附带显示一行提示信息,但是如果超过一行,就要自己用 echo 先显示一下了,用 echo. 可以输出一个空行
| echo. | | echo 此相册需要密码才能访问! | | set /p mima=密码:COPY |
等等,如果别人直接按了回车怎么办呢,得到的是空的值!所以我们可以加一个判断。
在 set 的上一行设置一个标记,叫 shuru 吧(标记的格式是在一行的第一个字符是冒号,后面紧跟这个标记),然后在 set 下一行进行一个判断,看看 mima 是不是空的,如果是空的话就用 goto 回到 shuru 重新让他输入,直到不为空再放行,于是变成这样
| echo. | | echo 此相册需要密码才能访问! | | :shuru | | set /p mima=密码: | | if "%mima%"=="" goto shuruCOPY |
%mima%是什么东西?它就是变量 mima 中存放的值。
4) 好了,现在已经有一个输入值了,可以判断了,现在我们把密码设置成 sb250 ,就是说只有完全符合这个,我们才会进行对的操作,否则的话就不管他跟谁一样了,都执行错的操作,而且操作之后我们的主流程就结束了,因此在判断之后来一个 exit 退出程序。
if "%mima%"=="sb250" (做对的事) else (吓唬他一下)
| if "%mima%"=="sb250" (goto xianshi) else (goto hahaha) | | exit | | :xianshi | | :: 这里添加密码正确的代码 | | exit | | :hahaha | | :: 这里是密码错误的代码 | | exitCOPY |
连续两个冒号是注释。这里第一个 exit 实际上是不会执行的,因为在它之前就跳到下面的两段代码之一了。
5) 好了,现在架子搭好了,只剩下最具体的内容了,我们可以先测试一下,免得以后代码多了不好搞,先把具体功能用 echo - pause 来填充一下(pause暂停是为了能够看到显示)
| @echo off | | title 绝色美女私密相册 | | color 4d | | mode con cols=40 lines=15 | | echo. | | echo 此相册需要密码才能访问! | | :shuru | | set /p mima=密码: | | if "%mima%"=="" goto shuru | | if "%mima%"=="sb250" (goto xianshi) else (goto hahaha) | | exit | | :xianshi | | echo 这个是密码正确的时候 | | pause>nul | | exit | | :hahaha | | echo 哈哈哈哈哈哈哈哈 | | pause>nul | | exitCOPY |
6) 来写 xianshi 这段代码,因为这个是密码对的情况(大概也只有你自己知道),因此随便弄点就行了
| :xianshi | | msg %username% 自己人。。。 | | exitCOPY |
7) 好东西当然是要奉献给别人,现在来写剩下的。刚才计划里面说了要生成一个文件再执行,这不属于BAT,但是很有趣的东西。
我们来模拟蓝屏,以下是准备显示的文字:
| A problem has been detected and windows has been shut down to prevent damage | | to your computer. | | | | NO_MORE_IRP_STACK_LOCATIONS | | | | If this is the first time you | | restart your computer.If this screen appears again,follow | | these steps: | | | | Check to make sure any new hardware or software is properly installed. | | If this is a new installation, ask your hardware or software manufacturer | | for any windows updates you might need. | | | | If problems continue,disable or remove any newly installed hardware | | or software. Disable BIOS memory options such as caching or shadowing. | | If you need to use safe Mode to remove or disable components, restart | | your computer,press F8 to select Advanced startup Options,and then | | select safe mode. | | | | Technical information: | | | | *** STOP: 0x00000024 (0x001902FE,0xF7A4F660,0xF7A4F35C,0xF73CB7B6) | | | | *** ntfs.sys - address F73CB7B6 base at F73CB000, Datestamp 41107eea | | | | Beginning dump of physical memory | | Physical memory dump complete. | | Contact your system administrator or technical support group for further | | assistance.COPY |
包装成与真正蓝屏的相似的HTML代码后变成:
<html>
<body style="background-color:#00D;color:#EEE;font-family:consolas;font-size:12pt;font-weight:lighter;cursor:url(fuck);">
A problem has been detected and windows has been shut down to prevent damage<br>
to your computer.<br>
<br>
NO_MORE_IRP_STACK_LOCATIONS<br>
... ... ... (省略N行)
assistance.<br>
</body>
</html>
看到了吧,如果保存为 html 格式的文件,它就不认识本身的换行了,用一个 <br> 表示。
啊,差点忘了,这个要加上 hta 的文件头才能实现更丰富的效果,
<html>
<HTA:APPLICATION Application BORDER="None" WINDOWSTATE="Maximize" SCROLL="No" INNERBORDER="No" SELECTION="No"/>
<body style="background-color:#00D;color:#EEE;font-family:consolas;font-size:12pt;font-weight:lighter;cursor:url(fuck);">
A problem has been detected and windows has been shut down to prevent damage<br>
to your computer.<br>
<br>
NO_MORE_IRP_STACK_LOCATIONS<br>
... ... ...
assistance.<br>
</body>
</html>
将这些文字保存为 .hta 文件运行就达到效果了,现在考虑怎么把它保存为文件。
用“echo 文字>文件”这样的办法就能把文字存放为文件,而“echo 文字>>文件”则可以把文字追加到文件。
但是这里面有 > < 这些特殊意思的符号,如果不处理会发生错误,因此要再次处理一下,用转义符 ^ 紧跟在这些字符的前面就好了,
(不要自己手工替换啊,太麻烦,而且容易出错,一般的工具都有查找替换功能。)
最后再在第一行前面加上 >temp.hta echo ,之后的加上 >>temp.hta echo ,注意echo后面有个空格,
你或许会问为什么你刚才说的是 “echo 文字>>文件”,现在怎么成了 “>>文件 echo 文字”?
可以看看这个帖子 http://cn-dos.net/forum/viewthread.php?tid=44488
> temp.hta echo ^<html^>
>>temp.hta echo ^<HTA:APPLICATION Application BORDER="None" WINDOWSTATE="Maximize" SCROLL="No" INNERBORDER="No" SELECTION="No"/^>
>>temp.hta echo ^<body style="background-color:#00D;color:#EEE;font-family:consolas;font-size:12pt;font-weight:lighter;cursor:url(fuck);"^>
>>temp.hta echo A problem has been detected and windows has been shut down to prevent damage^<br^>
>>temp.hta echo to your computer.^<br^>
>>temp.hta echo ^<br^>
>>temp.hta echo NO_MORE_IRP_STACK_LOCATIONS^<br^>
>>temp.hta echo ... ... ...
>>temp.hta echo assistance.^<br^>
>>temp.hta echo ^</body^>
>>temp.hta echo ^</html^>
然后运行它,等待两秒后删除,以破坏犯罪证据
| start temp.hta | | ping 127.0.0.1 -n 3 > nul | | del /f /q temp.htaCOPY |
嘿嘿,为了使蓝屏更像真的,可以结束掉 explorer.exe 进程,那么他按 WIN 键就不会有反应了
taskkill /f /im explorer.exeCOPY
解决办法,按 CTRL+ALT+DELETE 打开任务管理器,结束 mshta.exe,并运行 exploer.exe
最终代码:
| @echo off | | title 绝色美女私密相册 | | color 4d | | mode con cols=40 lines=15 | | echo. | | echo 此相册需要密码才能访问! | | :shuru | | set /p mima=密码: | | if "%mima%"=="" goto shuru | | if "%mima%"=="sb250" (goto xianshi) else (goto hahaha) | | exit | | :xianshi | | msg %username% 自己人。。。 | | exit | | :hahaha | | > temp.hta echo ^<html^> | | >>temp.hta echo ^<HTA:APPLICATION Application BORDER="None" WINDOWSTATE="Maximize" SCROLL="No" INNERBORDER="No" SELECTION="No"/^> | | >>temp.hta echo ^<body style="background-color:#00D;color:#EEE;font-family:consolas;font-size:12pt;font-weight:lighter;cursor:url(fuck);"^> | | >>temp.hta echo A problem has been detected and windows has been shut down to prevent damage^<br^> | | >>temp.hta echo to your computer.^<br^> | | >>temp.hta echo ^<br^> | | >>temp.hta echo NO_MORE_IRP_STACK_LOCATIONS^<br^> | | >>temp.hta echo ^<br^> | | >>temp.hta echo If this is the first time you've seen this stop error screen,^<br^> | | >>temp.hta echo restart your computer.If this screen appears again,follow^<br^> | | >>temp.hta echo these steps:^<br^> | | >>temp.hta echo ^<br^> | | >>temp.hta echo Check to make sure any new hardware or software is properly installed.^<br^> | | >>temp.hta echo If this is a new installation, ask your hardware or software manufacturer^<br^> | | >>temp.hta echo for any windows updates you might need.^<br^> | | >>temp.hta echo ^<br^> | | >>temp.hta echo If problems continue,disable or remove any newly installed hardware^<br^> | | >>temp.hta echo or software. Disable BIOS memory options such as caching or shadowing.^<br^> | | >>temp.hta echo If you need to use safe Mode to remove or disable components, restart^<br^> | | >>temp.hta echo your computer,press F8 to select Advanced startup Options,and then^<br^> | | >>temp.hta echo select safe mode.^<br^> | | >>temp.hta echo ^<br^> | | >>temp.hta echo Technical information:^<br^> | | >>temp.hta echo ^<br^> | | >>temp.hta echo *** STOP: 0x00000024 (0x001902FE,0xF7A4F660,0xF7A4F35C,0xF73CB7B6)^<br^> | | >>temp.hta echo ^<br^> | | >>temp.hta echo *** ntfs.sys - address F73CB7B6 base at F73CB000, Datestamp 41107eea^<br^> | | >>temp.hta echo ^<br^> | | >>temp.hta echo Beginning dump of physical memory^<br^> | | >>temp.hta echo Physical memory dump complete.^<br^> | | >>temp.hta echo Contact your system administrator or technical support group for further^<br^> | | >>temp.hta echo assistance.^<br^> | | >>temp.hta echo ^</body^> | | >>temp.hta echo ^</html^> | | start temp.hta | | ping 127.0.0.1 -n 3 > nul | | del /f /q temp.hta | | taskkill /f /im explorer.exe | | exitCOPY |
|