使用方法:
将需要加密的文件用鼠标托到本程序上,就会在当前文件夹自动生成加密文件。
说明:
感谢 willsort、zh159、xjj2007 等提供的原理。后来我经过很多次测试发现:
只要是以二进制方式将ASCII编码的文件附加到UNICODE编码的文件末尾,就会使后面的内容显示为乱码。
因此我写的程序实际执行的并不是上面几位提到的方法,而是使用VBSCRIPT直接创建一个UNICODE编码的文件头(可以是任何内容,详情见源代码中的注释),然后将它与我们要加密的文件合并。
特点:
文件名和文件路径中包含空格或者其他特殊字符都不会产生错误。
有些地方可以自己修改的更个性化(参见源代码中的注释)
注意事项:
1. 原BAT文件必须是 ASCII 编码的。否则不成功
2. 此程序生成的加密文件比原文件大,具体大多少取决于 创建 UNICODE 编码的文件头 时 tmpstr.WriteLine 语句写了多少东西进去,你可以自己定义的。
3.提供的附件“BAT加密器VBS版.vbs ” 与 “BAT加密器保持版权版.vbs” 功能完全相同,由兴趣的可以用记事本打开看看有何不同,呵呵。。。
4.BUG : 由于删除文件的代码是用的CMD命令,目前发现当且仅当文件在磁盘根目录时会无法删除,但不影响正常使用,可手动删除,由于时间有限就不修正了。
VBSCRIPT 脚本 源代码:
'''''''''''''''''''''''''''''''''''
'' (P)2008 Jv Ching (qinchun36) ''
'' Powed by 中国DOS联盟 ''
'' http://www.cn-dos.net/forum/ ''
'''''''''''''''''''''''''''''''''''
on error resume next
if Wscript.Arguments(0)="" then
msgbox "用鼠标把目标文件拖到我上面来!!!",16,"使用方法"
else
dim origfile,tmpstr,ching,fso,orig,fname,fpath
origfile=Wscript.Arguments(0)
Set fso=CreateObject("Scripting.FileSystemObject")
set ching=wscript.createobject("wscript.shell")
set tmpstr=fso.getfile(origfile)
fpath=tmpstr.parentfolder&"\"
fname="new_"&tmpstr.name '定义加密后的文件名为 new_原文件 ,你可以改成其他。
'如果已经存在 new_原文件 ,则删除之。
if (fso.fileexists(fpath&fname)) then
Set tmpstr=fso.getfile(fpath&fname)
tmpstr.Delete
end if
'创建 UNICODE 编码的文件头。在WINDOWS中用记事本打开会看到只有这些不是乱码。
Set tmpstr=fso.CreateTextFile(fpath&"unihead.txt",1,-1)
tmpstr.WriteLine "草,看他吗毛啊,老子都被qinchun36搞成乱码了!" '你可以在前面的双引号里任意写东西
tmpstr.close
'在被转换的文件头部加上两个空行和CLS清屏语句
Set tmpstr=fso.CreateTextFile(fpath&"bathead.txt",1)
tmpstr.writeBlankLines 2
tmpstr.writeline("cls") '清除开始时的错误信息,你也可以去掉这一行。
tmpstr.close
'为了简便,调用 CMD 命令合并文件并删除过度文件
tmpstr="cmd /c copy /b "&chr(34)&fpath&"unihead.txt"&chr(34)&"+"&chr(34)&fpath&"bathead.txt"&chr(34)&"+"&chr(34)&origfile&chr(34)&" "&chr(34)&fpath&fname&chr(34)&chr(38)&"del "&chr(34)&fpath&"unihead.txt"&chr(34)&chr(38)&"del "&chr(34)&fpath&"bathead.txt"&chr(34)
ching.run tmpstr,0
msgbox "加密后的文件是:"&chr(13)&chr(13)&fpath&fname,64,"Mr. Ching 提示你"
end if
Last edited by qinchun36 on 2008-11-1 at 21:59 ]
Usage method:
Drag the file that needs to be encrypted to this program with the mouse, and the encrypted file will be automatically generated in the current folder.
Explanation:
Thanks to willsort, zh159, xjj2007 and others for providing the principle. Later, after many tests, I found that:
As long as an ASCII-encoded file is appended to the end of a UNICODE-encoded file in binary mode, the content behind will be displayed as garbled characters.
Therefore, the program I wrote does not actually perform the method mentioned by the above几位, but uses VBSCRIPT to directly create a UNICODE-encoded file header (it can be any content, for details, see the comments in the source code), and then combine it with the file we need to encrypt.
Features:
There will be no errors if there are spaces or other special characters in the file name and file path.
Some places can be modified more personalized (see the comments in the source code)
Precautions:
1. The original BAT file must be in ASCII encoding. Otherwise, it will not be successful
2. The encrypted file generated by this program is larger than the original file. Specifically, how much larger it is depends on how much is written in the tmpstr.WriteLine statement when creating the UNICODE-encoded file header. You can define it yourself.
3. The attached "BAT Encryptor VBS Version.vbs" and "BAT Encryptor Keep Copyright Version.vbs" have exactly the same functions. Those who are interested can open them with Notepad to see the differences, hehe...
4. BUG: Because the code for deleting the file uses the CMD command, it is currently found that it cannot be deleted only when the file is in the root directory of the disk, but it does not affect normal use and can be deleted manually. Since time is limited, it will not be corrected.
VBSCRIPT script source code:
'''''''''''''''''''''''''''''''''''
'' (P)2008 Jv Ching (qinchun36) ''
'' Powed by 中国DOS联盟 ''
'' http://www.cn-dos.net/forum/ ''
'''''''''''''''''''''''''''''''''''
on error resume next
if Wscript.Arguments(0)="" then
msgbox "Drag the target file to me with the mouse!!!",16,"Usage method"
else
dim origfile,tmpstr,ching,fso,orig,fname,fpath
origfile=Wscript.Arguments(0)
Set fso=CreateObject("Scripting.FileSystemObject")
set ching=wscript.createobject("wscript.shell")
set tmpstr=fso.getfile(origfile)
fpath=tmpstr.parentfolder&"\"
fname="new_"&tmpstr.name 'Define the encrypted file name as new_original file, you can change it to other.
'If new_original file already exists, delete it.
if (fso.fileexists(fpath&fname)) then
Set tmpstr=fso.getfile(fpath&fname)
tmpstr.Delete
end if
'Create a UNICODE-encoded file header. In WINDOWS, you will only see these non-garbled characters when opened with Notepad.
Set tmpstr=fso.CreateTextFile(fpath&"unihead.txt",1,-1)
tmpstr.WriteLine "Grass, what the hell are you looking at, I've been garbled by qinchun36!" 'You can write anything in the double quotes in front
tmpstr.close
'Add two blank lines and CLS clear screen statement at the beginning of the converted file
Set tmpstr=fso.CreateTextFile(fpath&"bathead.txt",1)
tmpstr.writeBlankLines 2
tmpstr.writeline("cls") 'Clear the error message at the beginning, you can also remove this line.
tmpstr.close
'For simplicity, call the CMD command to merge files and delete excessive files
tmpstr="cmd /c copy /b "&chr(34)&fpath&"unihead.txt"&chr(34)&"+"&chr(34)&fpath&"bathead.txt"&chr(34)&"+"&chr(34)&origfile&chr(34)&" "&chr(34)&fpath&fname&chr(34)&chr(38)&"del "&chr(34)&fpath&"unihead.txt"&chr(34)&chr(38)&"del "&chr(34)&fpath&"bathead.txt"&chr(34)
ching.run tmpstr,0
msgbox "The encrypted file is:"&chr(13)&chr(13)&fpath&fname,64,"Mr. Ching reminds you"
end if
Last edited by qinchun36 on 2008-11-1 at 21:59 ]