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-21 06:14
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] [Discussion] Non-compiled Batch Processing Encryption Scheme and Code DigestI View 110,325 Replies 364
Original Poster Posted 2006-07-10 10:52 ·  中国 新疆 克拉玛依 电信
初级用户
Credits 162
Posts 44
Joined 2006-03-24 22:35
20-year member
UID 52742
Status Offline
Although .bat files are convenient to use, their security is too weak. Anyone can open them to view or even modify the content. Is there a way to keep the file as a .bat without converting it to .exe, .com, or other formats, while preventing others from viewing and modifying its content? Is there any self-encryption method available? Experts, please provide a solution思路.


───────────────── Moderator's Note ─────────────────
The currently discussed solutions are as follows:
1. Inserting Unicode feature strings into batch code (Floor 7, yuanyong630)
Related discussions can be found on Floors 24, 25, 45, 48, etc.

Download link for the code implementation (Floor 27, pengfei):
Click to download: BAT Encryption Tool.rar

Effective for programs that use the IsTextUnicode function to identify encoding types, such as Notepad.
Ineffective for programs that do not use the IsTextUnicode function, such as type/edit/EditPlus/UltraEdit.

2. Adding a Unicode Byte Order Mark (BOM) to the header of batch code (Floor 40, zxcv)
Related discussions can be found on Floors 41, 43, 69, etc.

Download link for the code implementation (Floor 71, zxcv):
EncryBat.rar (zxcv)

Effective for programs that support Unicode encoding, such as Notepad, Word, UltraEdit, and type.
Ineffective for programs that do not support Unicode encoding, such as edit and WinRAR internal viewer.

3. Replacing carriage return-line feed characters in batch code with carriage return characters (Floor 17, electronixtar)
Related discussions can be found on Floor 26.

Effective for editors that separately recognize carriage return-line feed characters, such as edit.

4. Dictionary-based conversion of batch code (Floor 11, 3742668)
Related discussions and code implementations can be found on Floors 11 and 15.

The code is dynamically generated during plaintext execution, so this solution is independent of the editor.

Points Reward:
yuanyong630, 3742668, pengfei, and zxcv will each receive 8 points.
electronixtar will receive 4 points.
───────────────── Moderator's Note ─────────────────


[ Last edited by willsort on 2006-8-6 at 04:02 ]
Recent Ratings for This Post ( 3 in total) Click for details
RaterScoreTime
jonsonqf +2 2008-04-29 17:25
Wingl83 +2 2008-12-23 14:06
niels +1 2009-05-16 08:29
Floor 2 Posted 2006-07-10 11:27 ·  中国 四川 成都 联通
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
I knew this thread would become popular a long time ago, so I claimed the first comment spot, haha

[ Last edited by electronixtar on 2007-5-8 at 08:36 PM ]

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 3 Posted 2006-07-10 17:34 ·  中国 北京 鹏博士BGP
中级用户
★★
Credits 404
Posts 179
Joined 2006-03-30 14:44
20-year member
UID 53056
Status Offline
QuickBFC.EXE

After searching, this program essentially embeds batch files, so it can execute correctly as long as the environment is appropriate.
Floor 4 Posted 2006-07-10 19:19 ·  中国 广东 珠海 电信
初级用户
Credits 112
Posts 40
Joined 2006-06-23 19:52
19-year member
UID 57473
Gender Male
Status Offline
This QuickBFC.EXE can only package one batch file into an executable, which is not very useful.

Is there a tool that can package a group of batch files into an executable? This is because programs often consist of multiple batch files.
Floor 5 Posted 2006-07-10 19:22 ·  中国 北京 鹏博士BGP
中级用户
★★
Credits 404
Posts 179
Joined 2006-03-30 14:44
20-year member
UID 53056
Status Offline
Then go find something useful. Why don't you just write one for everyone? Spouting such nonsense.
Floor 6 Posted 2006-07-11 21:04 ·  中国 上海 虹口区 电信
高级用户
★★
Credits 653
Posts 252
Joined 2006-04-16 19:48
20-year member
UID 53939
Status Offline
Originally posted by kcdsw at 2006-7-10 19:22:
Then go find something useful. Why don't you just write one for everyone?
What nonsense are you talking about?


hoho, is that necessary? Why are you so angry?
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
jckjuc +1 2007-03-26 15:54
+1 2009-08-24 05:47
Floor 7 Posted 2006-07-13 11:28 ·  中国 北京 电信
初级用户
Credits 49
Posts 13
Joined 2006-07-13 11:21
19-year member
UID 58500
Status Offline
BAT File Encryption Method (Better than the Bat2Com software because that software does not support Chinese)

The method is:

Open "Notepad" and write the following statement at the beginning of the file

for /l %%a in (1,1,10) do ren *.jpg %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a %%a
Recent Ratings for This Post ( 5 in total) Click for details
RaterScoreTime
Eblis +2 2007-03-02 12:30
zhoushijay +8 2007-05-10 17:28
AlexZhang +2 2007-07-28 18:39
txratu +2 2008-03-19 17:29
qinchun36 +1 2008-10-31 00:30
Floor 8 Posted 2006-07-13 11:44 ·  中国 湖北 武汉 电信
中级用户
★★
Credits 245
Posts 103
Joined 2006-06-30 00:00
19-year member
UID 57801
Gender Male
Status Offline
Valid... Supported... Thank you... It is an absolute crystallization of wisdom and technology! Then, may I ask the person above, how can the content be displayed again? Where there is a shield, there must be a spear, right?
Floor 9 Posted 2006-07-13 12:47 ·  中国 山东 菏泽 电信
银牌会员
★★★
Credits 1,246
Posts 488
Joined 2003-11-11 00:00
22-year member
UID 12699
Gender Male
Status Offline
The 7th floor tested it and confirmed it works.
Floor 10 Posted 2006-07-13 12:57 ·  中国 北京 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
Let's all calm down. Zhaxi on the 4th floor, tasks that can be completed with multiple batch files can also be written into a single batch file; it just differs in terms of code volume.
Floor 11 Posted 2006-07-13 15:41 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline

『Floor 8』:

Effective... Supported... Thank you... It is definitely a crystallization of wisdom and technology!
May I ask the person above, how can I redisplay the content? Where there is a shield, there must be a spear, right?
『Floor 9』:

Tested on the 7th floor, it works.

I am too inexperienced; I can't figure out how the code on the 7th floor can实现加密代码的作用.
Could it be that friends on the 8th and 9th floors pasted the code from the 7th floor at the beginning of their own scripts, saved it, and then couldn't see their own code when they opened it? It seems a bit sensational.
Since everyone is so interested in encryption, I'll join in too:


Regarding BAT encryption, I也曾憧憬过 it a long time ago. However, due to the limitations of BAT, if you purely use BAT to encrypt BAT, even after encryption, others might still be able to view the source code very easily. But if the people you want to deal with are just unskilled beginners, the following method might be helpful:
In our system, there are quite a few default environment variables. For example, in my XP SP2, running the SET command gives the following list of variables:

ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\**\Application Data
CLIENTNAME=Console
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=GOOGLE
ComSpec=C:\WINDOWS\system32\cmd.exe
FP_NO_HOST_CHECK=NO
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\**
LOGONSERVER=\\GOOGLE
NUMBER_OF_PROCESSORS=2
OS=Windows_NT
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;"C:\Program Files\S
ymantec\Norton Ghost 2003\"
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 2 Stepping 9, GenuineIntel
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=0209
ProgramFiles=C:\Program Files
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\DOCUME~1\**\LOCALS~1\Temp
TMP=C:\DOCUME~1\**\LOCALS~1\Temp
USERDOMAIN=GOOGLE
USERNAME=**
USERPROFILE=C:\Documents and Settings\**
windir=C:\WINDOWS

In addition, there are some variable variables:

%CD% - Expands to the current directory string.
%DATE% - Expands to the current date in the same format as the DATE command.
%TIME% - Expands to the current time in the same format as the TIME command.
%RANDOM% - Expands to a random decimal number between 0 and 32767.
%ERRORLEVEL% - Expands to the current ERRORLEVEL value.
%CMDEXTVERSION% - Expands to the current command processor extension version number.
%CMDCMDLINE% - Expands to the original command line that invoked the command processor.

Using these environment variables, we can completely transform our scripts beyond recognition. For example:

@echo BBS.CN-DOS.NET

I believe everyone can immediately see that its function is to print the string bbs.cn-dos.net to the screen. Then can you immediately see the function of the following code? (It is only one line)

@%commonprogramfiles:~-2,1%%ComSpec:~-7,1%%pathext:~-1,1%%windir:~-3,1% %pathext:~11,1%%pathext:~11,1%%pathext:~22,1%%pathext:~0,1%%pathext:~1,1%%windir:~5,1%-%windir:~6,1%%windir:~7,1%%windir:~-1,1%%pathext:~0,1%%windir:~5,1%%PATHEXT:~6,1%%tmp:~-4,1%

Or define your own variables:

@echo off
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=fdip.cct+do-ept+ofu
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:.= %
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:t=s%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:c=b%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:+=.%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:u=t%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:o=n%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:f=e%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:d=c%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:i=h%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:p=o%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:~0,12%d%,:~13%
%,%
pause

How about it, a bit dazzling, isn't it?
Veterans will snicker: Just add echo before the %, % line and run it, and the code will display itself...
Oh no, fortunately, I am not to be trifled with either:

@echo off
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=abcd3742668fdip.cct+do-ept+ofu
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:.= %
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:t=s%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:c=b%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:+=.%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:u=t%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:o=n%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:f=e%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:d=c%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:i=h%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:p=o%
%windir:~-1,1%%ComSpec:~-1,1%%tmp:~-4,1%,=%,:~0,23%d%,:~24%
%,:*3742668=echo.^">nul&%
pause

To deal with beginners, the above method will already make them dazzled. However, this is just the beginning. There are also methods such as inserting misleading garbage code, advanced variable encryption, and automatic code modification after one run. The best is yet to come.
(To be continued)
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
regvip2008 +2 2008-01-22 12:01
Floor 12 Posted 2006-07-15 01:06 ·  中国 江苏 苏州 电信
初级用户
★★
Credits 160
Posts 75
Joined 2006-06-28 01:07
19-year member
UID 57661
Gender Male
Status Offline
Is this really effective?

Then why is that?

Could the experts please explain first?
Floor 13 Posted 2006-07-21 14:24 ·  中国 湖北 武汉 电信
中级用户
★★
Credits 245
Posts 103
Joined 2006-06-30 00:00
19-year member
UID 57801
Gender Male
Status Offline
That's strange. Now when pasting code, the BAT content can't be hidden again. It was working just a few days ago.
Floor 14 Posted 2006-07-21 15:32 ·  中国 浙江 台州 玉环市 电信
管理员
★★★★
DOS非常爱好者
Credits 6,215
Posts 2,601
Joined 2006-01-20 13:00
20-year member
UID 49256
Status Offline
The method in the 7th floor does not seem to work at all.
Floor 15 Posted 2006-07-21 15:48 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Moderator 3742668's encryption uses character truncation and character substitution. It seems necessary to master common cryptographic methods, but writing code this way requires manually maintaining a character substitution table, which is somewhat tedious.
1 2 3 25 Next ›
Forum Jump: