 『楼 主』:
[原创--分享]---------- Bat2Com 成功密技教程 --------
使用 LLM 解释/回答一下
Bat2Com 成功密技教程
先说题外话,不喜或不同观点者勿怪:
1、说的是DOS,CMD可以不用看
2、在CN-DOS论坛上找到一个有关BAT加密的高楼大厦,一口气从1楼爬到350楼,试验一下,结果是:
大失所望,这些所谓的加密可说是自欺欺人,最简单的破解方法是先用RAR压缩,再用RAR查看,加密一目了然,所以奉劝各位,别再在BAT加密上浪费时间和精力了。
3、非要bat加密,只有bat2com。有人说了,bat2com将bat转换为COM或EXE的成功率很低,的确如此,我以前试过好几回,很少有成功的,那我还来这说什么?
稍别勿噪,我可以负责任的告诉你,bat2com真的很好很实用。
言归正传
一、转换不成功的原因分析
1、毫无疑问,bat2com肯定不是万能的,有一定的局限性,也有几个BUG,这是转换不成功的原因之一
2、你可能不太了解bat2com的处理规范,或你的BAT程序没有按bat2com的规范来编写,或者超出了bat2com的处理能力范围,这是转换不成功的最主要原因。
bat2com转换不成功的道理,与大多数CMD在dos下运行不成功的道理是一样的,只要你按dos规范来写CMD,那CMD就可以在dos下成功运行,废话:))
问题关键:是等bat2com的作者来修改、升级他的程序以适应你的BAT,还是修改你的BAT,让你的BAT适应bat2com的要求,成功还是失败,这是个问题。
二、bat2com的转换规范(以目前我手上的bat2com V1.5为例)
bat2com是按照bat的规范来处理的,对bat有很好的支持:
1、直接支持dos内部命令、外部命令,能带参数
2、直接支持IF、goto命令,支持GOTO的标号
3、忽略REM注解行
4、for命令是唯一的,直接以BAT方式执行。
5、每一行只执行唯一的一个命令,每个命令必须在一行中完成,即基本不支持|与>命令。
1-4 条与一般的bat要求是一致的,唯有第五条,是与常规bat的重大区别!!
三、基本要求,首先注意两点:
1、goto标号(:开头)不能重复,这比bat的要求严格。
2、保证你的BAT能在dos中以bat方式正确执行,这是前提条件,别以为这是废话。
四、解读bat2com与BAT的重要区别
(一)、最主要的一条:每一行只执行唯一的一个命令,每个命令必须在一行中完成,即基本不支持|与>命令 1、每行只能执行一个命令,就是说不允许有"|"( 管道),
2、除了echo 或者 dir之外,其他情况不允许再有转向命令(>,>>)
如:type a.txt | find "abc" -->非法(不能有|)
再如:find "abc' a.txt >b.txt --->非法(不能有>)
再再如:外部命令dspt.exe 0 /l >d.txt --->非法(不能有>)
再再再如: for %%i in (%a%) do echo %%i >>c.txt ->非法(不能有>,>>)
再再再再如:if %a%==1 if %b%==2 set c=3 -->非法(不能连续执行)
我敢打赌,所谓BAT2com成功率低,绝大数的bat就因为这一条!
如果你的BAT中已经没有了上述类似文本,我相信,你的bat2com已经成功了90%。
怎么样,有点眉目了吧,别急,还没完呢
(二)call 命令不会返回参数
举例如下:
set a=123
call b.bat ------>b.bat中的命令为:set a=abc
echo %a%
对于bat方式,执行上述命令后,echo 的结果是:abc
这是我们最常用的bat命令调用,也就是说,bat传送变量。
但是,对于bat2com,它执行的结果是:123 ------》 没错,还是123 !!
真的没错,这不是Bat2com的Bug,也不是bat的bug,这是标准的com、exe执行方式,
其实,这个应该很好理解,这与一个exe程序不能直接向另一个exe程序传递参数一样。
例如,如果你的bat中用到wbat.com,其中有个w.bat,若bat2com后,w.bat所传递的参数将无效。
如果你知道什么是全局变量、局部变量,那你该一点就通,如果还不了解,可以看看有关方面的书,也可做以下试验:
执行以下命令,你就会明白:
set a=123
echo %a% ------->结果是:123,没错
command /k
set a=abc
echo %a% ------->显示:abc,也没错
exit
echo %a% -------》结果是什么,是123或是abc? 自己做吧
就是全局变量与局部变量的简单显示,当然,如果你的bat根本就没有call命令,那你是不会在意的。
(三)极个别第三方软件bat2com后,运行不正常,人无完人,别太苛求,试验后确定吧,实在不行就Call。
五、bat2com有两个严重的bug,必须避开它:
1、变量名,如bat中有:
set a=1
set ab=2
set abc=3
这三条命令在bat中执行正确,但BAT2com中会认为是一样的,会出错,这是一个BUG,只要避开它就可了:即变量名不要有完全重合。
2、echo set a=c:>a.txt
echo dir %%a%%>>a.txt
这两条命令在bat中执行正确,但在bat2com中会在"c:"及%a%后面多出几个空格,
set a=c:变成了set a=c: ,会出现错误,这也是一个BUG,普通的文本输出没有问题,如有必要,也要避开它。
六、解决的办法推荐
如果你按照上述要求重新修改你的BAT程序,bat2com成功,将近在眼前!
1、通过call 调用子程序BAT,执行|或>命令
你肯定会说,我的程序一定要有如:type a.txt | find "abc" 或 dspt.exe 0 /l >d.txt 或echo set a=c:>a.txt
很简单啊,将它做子程序bat,通过call调用,记住,子程序不能再bat2com!
2、子程序的参数不能通过set命令传递给bat2com,可能过文件方式,如
echo %你的参数% >a.txt
然后再在主程序读取a.txt的内容作为参数即可,这也是exe文件之间传递参数的标准方式。
七、隆重推荐:strings.com
有关trings.com的下载及介绍,论坛上很多,请自行搜索。
我只想说,strings是dos-bat的最佳搭档,有了strings,几乎可以完成bat所想完成的任何操作,如果没有strings,我肯定不会写这编文章的。
如echo echo 123>b.txt >a.bat,或echo type a.txt | find "abc" >a.bat
想在bat成功执行上述,得到正确的a.bat,是很难的(通过prompt变通,可以,但比较复杂),在bat2com中是绝对不可能的,但是,strings却能轻易做到!
strings的write命令,可以完善代替echo,而且对于>|等echo不认的符号,解决的非常好,如:
strings write a.bat,strings vhao=char 62 --》 set vhao=>
strings write a.bat, echo 123%%vhao%%b.txt --》 echo echo 123>b.txt >a.bat
其中Vhao为>,可以任意定义为|等,运行a.bat即可得b.txt
处理call返回的参数,变量运算、分析处理等等,strings都能轻松做到。
strings功能还很多,所以我推荐。
八、补充:
1、建议在dos环境中进行bat2com
2、任何bat2com之前,必须确保bat文件能正确运行
3、com文件不得大于64KB!
4、bat2com能正确执行后,再执行com2exe,将文件转换为exe。
九、附言:
为了数据安全,我一直想找个bat加密或2com的方法,如前所述,几经失望,后来想自己弄个for dos程序,但有近1n年没玩c++了,头痛,后来找到bat2com的原程序,仔细一看,正中下怀,逐步明白以前转换不成功的原因所在,经过n次测试,终于成功bat2com。
如果bat2com的作者能看到此文,最好能修正BUG、升级bat2com,或者等我哪天有空了,重操C++,邦他完善一下。
衷心感谢bat2com的作者(不能确定是否董占山)、strings的作者、strings帮助中文翻译(cn-dos的insert)、以及中国DOS联盟的热心的DOS高手!
好了,这是本人经过N次测试得出的经验,难免错漏之处,欢迎补充、完善、指正。
欢迎交流,歌理 QQ107660899 2008.12.02
附件是:bat2com\com2exe\stringsSample Text
Last edited by goli2008 on 2008-12-2 at 11:10 ]
### Bat2Com Success Secret Technique Tutorial
First, off-topic remarks, those who don't like it or have different views, please excuse:
1. It's about DOS, so CMD can be ignored.
2. Found a tall building about BAT encryption on the CN-DOS forum, climbed from floor 1 to floor 350 in one go, tested it, and the result was: extremely disappointed. These so-called encryptions can be said to be self-deceiving. The simplest cracking method is to first compress with RAR, then view with RAR, and the encryption is clear at a glance. So I advise everyone, don't waste time and energy on BAT encryption anymore.
3. If you must encrypt BAT, only bat2com. Some people said that the success rate of bat2com converting BAT to COM or EXE is very low. It's indeed like that. I tried several times before, and there were few successes. Then why am I still talking about this?
Wait a minute, I can responsibly tell you that bat2com is really good and practical.
Back to the main topic
### 1. Analysis of Reasons for Unsuccessful Conversion
1. Undoubtedly, bat2com is not omnipotent, has certain limitations, and has a few BUGs. This is one of the reasons for unsuccessful conversion.
2. You may not be very familiar with the processing specifications of bat2com, or your BAT program is not written according to the specifications of bat2com, or it exceeds the processing capacity range of bat2com. This is the most main reason for unsuccessful conversion.
The reason why bat2com is not successful is the same as the reason why most CMDs don't run successfully under DOS. As long as you write CMD according to the DOS specifications, then CMD can run successfully under DOS. Nonsense:))
The key question: Is it waiting for the author of bat2com to modify and upgrade his program to adapt to your BAT, or modifying your BAT to make your BAT adapt to the requirements of bat2com. Success or failure, this is a question.
### 2. Conversion Specifications of bat2com (Taking the bat2com V1.5 in my hand as an example)
bat2com handles it according to the specifications of BAT and has good support for BAT:
1. Directly support DOS internal commands, external commands, and can take parameters.
2. Directly support IF, goto commands, and support the labels of GOTO.
3. Ignore REM comment lines.
4. The for command is unique and is executed directly in BAT mode.
5. Only one command is executed in each line, and each command must be completed in one line, that is, | and > commands are basically not supported.
Items 1-4 are consistent with the general BAT requirements. Only item 5 is a major difference from the conventional BAT!!
### 3. Basic Requirements, First Note Two Points:
1. The goto labels (: start) cannot be repeated, which is stricter than the requirements of BAT.
2. Ensure that your BAT can be correctly executed in DOS in BAT mode. This is the prerequisite condition. Don't think this is nonsense.
### 4. Interpreting the Important Differences Between bat2com and BAT
(1) The most main one: Only one command is executed in each line, and each command must be completed in one line, that is, | and > commands are basically not supported 1. Only one command can be executed in each line, that is, "|" (pipe) is not allowed.
2. Except for echo or dir, no other cases are allowed to have redirection commands (>,>>).
For example: type a.txt | find "abc" --> Illegal (cannot have |)
Another example: find "abc' a.txt >b.txt ---> Illegal (cannot have >)
Another example: External command dspt.exe 0 /l >d.txt ---> Illegal (cannot have >)
Another example: for %%i in (%a%) do echo %%i >>c.txt -> Illegal (cannot have >, >>)
Another example: if %a%==1 if %b%==2 set c=3 --> Illegal (cannot execute continuously)
I bet that the reason why the success rate of BAT2com is low is that most BATs are because of this one item!
If there are no similar texts in your BAT, I believe that your bat2com has been 90% successful.
How about it, a little bit clear? Don't worry, it's not over yet.
(2) The call command will not return parameters
For example:
set a=123
call b.bat ------> The command in b.bat is: set a=abc
echo %a%
For the BAT mode, after executing the above command, the result of echo is: abc
This is the most commonly used BAT command call, that is, BAT transmits variables.
However, for bat2com, the result of its execution is: 123 ------》 Correct, still 123!
Really correct. This is not a Bug of Bat2com, nor a Bug of BAT. This is the standard execution method of COM, EXE.
In fact, this should be easy to understand. This is the same as an EXE program cannot directly pass parameters to another EXE program.
For example, if your BAT uses wbat.com, and there is a w.bat in it, if after bat2com, the parameters passed by w.bat will be invalid.
If you know what global variables and local variables are, then you should understand it at once. If you still don't understand, you can read relevant books. You can also do the following test:
Execute the following commands, and you will understand:
set a=123
echo %a% -------> The result is: 123, correct
command /k
set a=abc
echo %a% -------> Display: abc, also correct
exit
echo %a% -------》 What is the result, is it 123 or abc? Do it yourself.
It is the simple display of global variables and local variables. Of course, if your BAT does not have the call command at all, then you will not care.
(3) A very small number of third-party software, after bat2com, run abnormally. No one is perfect, don't be too demanding. Determine after testing. If it really doesn't work, then Call.
### 5. bat2com has two serious BUGs, which must be avoided:
1. Variable names. For example, if there is in BAT:
set a=1
set ab=2
set abc=3
These three commands are executed correctly in BAT, but in BAT2com, they will be considered the same, and an error will occur. This is a BUG. Just avoid it: that is, the variable names should not be completely coincident.
2. echo set a=c:>a.txt
echo dir %%a%%>>a.txt
These two commands are executed correctly in BAT, but in bat2com, there will be several spaces after "c:" and %a%,
set a=c: becomes set a=c: , an error will occur. This is also a BUG. Ordinary text output is okay. If necessary, also avoid it.
### 6. Recommended Solutions
If you re-modify your BAT program according to the above requirements, the success of bat2com is just around the corner!
1. Call the subroutine BAT through call to execute | or > commands.
You will definitely say that my program must have such as: type a.txt | find "abc" or dspt.exe 0 /l >d.txt or echo set a=c:>a.txt
It's very simple! Treat it as a subroutine BAT and call it through call. Remember, the subroutine should not be bat2com again!
2. The parameters of the subroutine cannot be passed to bat2com through the set command. It can be passed through the file method, such as
echo %your parameter% >a.txt
Then read the content of a.txt as a parameter in the main program. This is also the standard way to pass parameters between EXE files.
7. Vigorously Recommended: strings.com
There are many downloads and introductions of trings.com on the forum. Please search by yourself.
I just want to say that strings is the best partner of DOS-BAT. With strings, almost any operation that BAT wants to complete can be done. If there is no strings, I definitely would not write this article.
For example, echo echo 123>b.txt >a.bat, or echo type a.txt | find "abc" >a.bat
It is very difficult to make the above be successfully executed in BAT to get the correct a.bat (it can be done through prompt variation, but it is more complicated). It is absolutely impossible in bat2com. However, strings can easily do it!
The write command of strings can perfectly replace echo, and for symbols like >| that echo does not recognize, it is very well solved. For example:
strings write a.bat,strings vhao=char 62 --》 set vhao=>
strings write a.bat, echo 123%%vhao%%b.txt --》 echo echo 123>b.txt >a.bat
Among them, Vhao is >, which can be arbitrarily defined as |, etc. Run a.bat to get b.txt.
Handling the parameters returned by call, variable operations, analysis and processing, etc., strings can easily do it.
strings has many functions, so I recommend it.
### 8. Supplementary:
1. It is recommended to carry out bat2com in the DOS environment.
2. Before any bat2com, it must be ensured that the BAT file can run correctly.
3. The COM file must not be larger than 64KB!
4. After bat2com can be executed correctly, then execute com2exe to convert the file to EXE.
### 9. Postscript:
In order to ensure data security, I have been looking for a method of BAT encryption or 2com. As mentioned above, after several disappointments, I later wanted to make a for DOS program by myself. But I haven't played C++ for nearly 10 years. It's headache. Later, I found the original program of bat2com. After taking a close look, it was just what I wanted. I gradually understood the reasons for the previous unsuccessful conversion. After several tests, I finally succeeded in bat2com.
If the author of bat2com can see this article, it is best to correct the BUGs and upgrade bat2com, or wait until I have time one day, take up C++ again, and help him improve it.
Sincerely thank the author of bat2com (cannot be sure if it is Dong Zhanshan), the author of strings, the Chinese translation of strings (insert of cn-dos), and the enthusiastic DOS experts of the China DOS Union!
Well, this is the experience I got after several tests. There are inevitable mistakes and omissions. Welcome to supplement, improve and correct.
Welcome to communicate, Ge Li QQ107660899 2008.12.02
The attachment is: bat2com\com2exe\stringsSample Text
Last edited by goli2008 on 2008-12-2 at 11:10 ]
此帖被 +33 点积分 点击查看详情 评分人:【 s11ss 】 | 分数: +7 | 时间:2008-12-2 11:30 | 评分人:【 HAT 】 | 分数: +8 | 时间:2008-12-2 13:23 | 评分人:【 tireless 】 | 分数: +7 | 时间:2008-12-2 14:03 | 评分人:【 wxcute 】 | 分数: +4 | 时间:2008-12-2 19:09 | 评分人:【 radem 】 | 分数: +4 | 时间:2008-12-2 22:41 | 评分人:【 yishanju 】 | 分数: +3 | 时间:2008-12-3 11:50 |
|
附件
1: b2c.rar (2008-12-2 11:07, 21.68 KiB,下载次数: 211)
|