China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-23 22:38
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original - Share] ---------- Bat2Com Success Secret Technique Tutorial -------- View 2,440 Replies 12
Original Poster Posted 2008-12-02 11:07 ·  中国 广西 河池 电信
中级用户
★★
Credits 252
Posts 97
Joined 2006-09-17 12:00
19-year member
UID 62869
Gender Male
Status Offline
### 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 ]
Recent Ratings for This Post ( 6 in total) Click for details
RaterScoreTime
s11ss +7 2008-12-02 11:30
HAT +8 2008-12-02 13:23
tireless +7 2008-12-02 14:03
wxcute +4 2008-12-02 19:09
radem +4 2008-12-02 22:41
yishanju +3 2008-12-03 11:50
Attachments
b2c.rar (21.68 KiB, Downloads: 211)
Floor 2 Posted 2008-12-02 11:30 ·  中国 北京 海淀区 联通
银牌会员
★★★
Credits 2,098
Posts 566
Joined 2007-09-11 07:27
18-year member
UID 97070
Gender Male
Status Offline
Hard work.

Too many restrictions
Floor 3 Posted 2008-12-02 13:23 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Thanks for sharing, the original poster's spirit of research is worth us learning.
Floor 4 Posted 2008-12-02 19:11 ·  中国 福建 三明 电信
中级用户
★★
Credits 458
Posts 211
Joined 2006-07-26 19:42
19-year member
UID 59307
Status Offline
Thanks for sharing, learning from you.
┌───────┐
├→学习→实践→┤
└───────┘
Floor 5 Posted 2008-12-02 19:36 ·  中国 安徽 马鞍山 联通
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
Support lz.
Does not support errorlevel, restricted in some scenarios.
Windows 一键还原
http://www.yjhy.com
Floor 6 Posted 2008-12-02 22:40 ·  中国 广东 韶关 电信
高级用户
★★★
CMD感染者
Credits 691
Posts 383
Joined 2008-05-23 00:38
18-year member
UID 119451
Gender Male
Status Offline
The building owner has worked hard.
Admirable spirit.
Indeed an example for me to learn from.
Floor 7 Posted 2008-12-03 08:58 ·  中国 广西 桂林 电信
中级用户
★★
Credits 252
Posts 97
Joined 2006-09-17 12:00
19-year member
UID 62869
Gender Male
Status Offline
Originally posted by lianjiang2004 at 2008-12-2 19:36:
Support the LZ.
Does not support errorlevel, some occasions will be restricted.


No, errorlevel is well supported, and I have a lot of such in my program, because I use wbat
Floor 8 Posted 2008-12-04 11:42 ·  中国 安徽 马鞍山 联通
金牌会员
★★★★
Credits 3,946
Posts 1,884
Joined 2006-01-20 13:00
20-year member
UID 49283
Gender Male
Status Offline
Originally posted by goli2008 at 2008-12-3 08:58:


Incorrect, errorlevel is well supported, I have many such in my program, because I use wbat


Only tried it a long time ago, probably confused bat2exe with bat2com, hehe.
Windows 一键还原
http://www.yjhy.com
Floor 9 Posted 2008-12-05 10:13 ·  中国 山西 电信
银牌会员
★★★
天的白色影子
Credits 2,343
Posts 636
Joined 2004-03-06 00:00
22-year member
UID 19350
Gender Male
Status Offline
These days
There are still people playing bat2com
That's also a rare thing

As several people above said
Compilation software like bat2com/bat2exe/bat2exec has too many restrictions
I'm afraid it can only be applied to some simple code
It's very difficult to bypass the restrictions for slightly more complex code
And simple code usually has no need for compilation

Of course, as mentioned by the landlord
Combining tools like wbat, strings to achieve complex interfaces and functions can also be a way
This is a matter of personal preference

By the way
To say third-party tools
strings is not the best
It can only be said to be relatively popular

[ Last edited by qzwqzw on 2008-12-5 at 10:14 ]
Floor 10 Posted 2009-02-23 01:38 ·  中国 北京 联通
新手上路
Credits 3
Posts 2
Joined 2008-12-15 02:21
17-year member
UID 133911
Gender Male
Status Offline
2、Found a high-rise building about BAT encryption on the CN-DOS forum, climbed from floor 1 to floor 350 in one go, and the result was:
Great disappointment, these so-called encryptions can be said to be self-deceiving. The simplest cracking method is to first compress with RAR, then use RAR to view, and the encryption is clear at a glance. So I advise everyone, don't waste time and energy on BAT encryption anymore.

No need to compress, just switch to the directory with RAR and click view.
Floor 11 Posted 2009-02-23 11:03 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
What the original poster said is not about encryption, but about converting BAT to EXE or BAT to COM.
Floor 12 Posted 2009-02-23 21:16 ·  中国 广西 百色 电信
新手上路
Credits 1
Posts 1
Joined 2009-01-22 01:51
17-year member
UID 137229
Gender Male
Status Offline
Thanks to the LZ for sharing, learning and studying
Floor 13 Posted 2010-06-29 19:01 ·  中国 黑龙江 齐齐哈尔 联通
初级用户
Credits 27
Posts 13
Joined 2008-09-14 08:29
17-year member
UID 125607
Gender Male
Status Offline
Support
Forum Jump: