本帖最后由 cmd1152 于 2021-10-10 15:58 编辑
Version=1.0.0005 优化+Debug 版- @set "DeBug=1" % 0代表关闭DeBug,1代表打开DeBug %
- @%Cmd1152提供代码优化和Debug%
- @Echo Off
- set "Version=1.0.0005 优化+Debug 版"
- Cls
- call :Debug "修改窗口大小"
- Mode Con: Cols=120 Lines=16384
- call :Debug "修改颜色"
- Color 0F
- call :Debug "修改标题"
- Title Hope(R) Office EasyCommand EasyEnCode
- call :Debug "修改代码页"
- Chcp 936 > Nul
- Rem Hope(R) Office EasyCommand EasyEnCode
- Echo.
- call :Debug "绘图"
- Call :Type " "
- Call :Type "#" 116
- Echo.
- Call :Type " " 55
- Call :Type "EasyEnCode"
- Echo.
- Call :Type " "
- Call :Type "#" 116
- Echo.
- call :Debug "版权声明"
- Echo.
- Echo. ^>^> Hope(R) Office EasyCommand EasyEnCode [Version %Version%]
- Echo. ^>^> (C) Copyright 2016-2021 Hope Corp.
- Echo. ^>^> (C) Copyright 2020-2021 Hope2021 ^& Cmd1152 Corp.
- If "%~1"=="" (
- Set FileNum=1
- ) Else (
- Set FileNum=2
- )
- call :Debug "新建文件夹"
- Md "%UserProFile%\Desktop" >Nul 2>Nul
- Md "%UserProFile%\桌面" >Nul 2>Nul
- call :Debug "变量设置"
- Set "Pro=%0"
- Set "lnk=Hope(R) Office EasyCommand EasyEnCode [Version %Version%]"
- Set "Pro=%Pro:"=%"
- call :Debug "创建快捷方式"
- Mshta VBScript:Execute("Set a=CreateObject(""WScript.Shell""):Set b=a.CreateShortcut(a.SpecialFolders(""Desktop"") & ""\Hope Office EasyCommand EasyEnCode [Version %Version%].lnk""):b.TargetPath=""%Pro%"":b.WorkingDirectory=""%~dp0"":b.Save:close") >Nul 2>Nul
-
- @Goto :Main
-
- :Main
- Echo.
- Set "FileName=///*无此文件*///"
-
- If "%FileNum%"=="1" (
- call :Debug "没有调用函数"
- Set /P FileName=# ^>^> 请将需要加密的文件拖动至此窗体:
- ) Else (
- call :Debug "有调用函数"
- Set /P FileName=# ^>^> 请将需要加密的文件拖动至此窗体:%~1<Nul
- Echo.
- Set FileName=%~1
- Set FileNum=1
- )
- Set "FileName=%FileName:"=%"
- call :Debug "查找文件"
- For /F %%I in ('Dir /b') Do (
- If "%%I"=="%FileName%" (
- Set "FileName=%Cd%\%FileName%"
- )
- )
-
- Set FileName="%FileName%"
- call :Debug "判断文件是否存在"
- If Not Exist %FileName% (
- call :Debug "没有找到文件"
- Echo.
- Echo. ^>^> 无此文件!无法加密...
- @Goto :Main
- )
-
- Set FilenameExtension=%FileName:~-5%
- Set FilenameExtension=%FilenameExtension:~0,4%
- call :Debug "文件夹名字的递增"
- For /L %%i in (1,1,2048) Do (
- If Not Exist "File-%%i\" (
- Md "File-%%i\" >Nul 2>Nul
- Set EnCodeDir=File-%%i\
- Set Num=%%i
- @Goto :EnCode
- )
- )
- call :Debug "文件夹超过2048"
- Echo.
- Echo. ^>^> 可分配的内存已经占满,无法加密...
-
- @Goto :Main
-
- :EnCode
-
- Set "Choice="
- call :Debug "判断文件是否是批处理"
- If /I Not "%FilenameExtension%"==".Bat" (
- call :Debug "不是.bat文件"
- If /I Not "%FilenameExtension%"==".Cmd" (
- call :Debug "不是.Cmd文件"
- @Goto :Choice
- )
- )
- call :Debug "B变量设置"
- For /L %%i in (1,1,47) Do Call :RepeatBS
- call :Debug "绘图"
- Echo.
- Call :Type " "
- Call :Type "+"
- Call :Type "=" 4
- Call :Type "正在加密"
- Call :Type "=" 4
- Call :Type "+"
- Call :Type "=" 98
- Echo.
- call :Debug "[信息]"
- Echo.
- Echo. 开始加密时间: %Time%
- Echo.
- Echo. 文件名: %FileName%
- Echo.
- call :Debug "加密过程"
- Cd %EnCodeDir%
-
- Copy %FileName% "%cd%\File.Bat" > Nul
-
- For /F %%i in ('dir /b File.Bat') do (
- For /L %%j in (0,1,%%~zi) do (
- call :Debug for返回%%j,最后会返回%%~zi
- Set /P Bytes[FileName]=%Bs% 文件大小: %%j Byte[s] <Nul
- )
- )
- Echo.
-
- Call :VBScript_EnCode
- call :Debug "打开EnCode.VBS,并等待运行结束"
- Start /W "" "EnCode.VBS"
- call :Debug "删除EnCode.VBS"
- Del /f "EnCode.VBS" >nul 2>nul
- call :Debug "写入EnCode.Bat"
- >> "EnCode.Bat" Echo.
- >> "EnCode.Bat" Echo.Cls
- Type "File.Bat" >> "EnCode.Bat"
- call :Debug "删除File.Bat"
- Del /f "File.Bat" >nul 2>nul
- call :Debug "[信息]"
- Echo.
- Echo. 加密后的文件: "%Cd%\EnCode.Bat"
- Echo.
-
- For /F %%i in ('dir /b EnCode.Bat') do (
- For /L %%j in (0,1,%%~zi) do (
- call :Debug for返回%%j,最后会返回%%~zi
- Set /P Bytes[FileName]=%Bs% 加密后的大小: %%j Byte[s] <Nul
- )
- )
- Echo.
-
- call :Debug "返回加密时间"
- Echo.
- Echo. 加密结束时间: %Time%
- call :Debug "绘图"
- Echo.
- Call :Type " "
- Call :Type "+"
- Call :Type "=" 4
- Call :Type "=" 8
- Call :Type "=" 4
- Call :Type "+"
- Call :Type "=" 98
- Echo.
- call :Debug "Msg"
- Mshta VBScript:msgbox("加密%FileName:~1,-1%文件成功",64,"Hope(R) Office EasyCommand EasyEnCode [Version %Version%]")(window.close)
- call :Debug 用资源管理器打开%CD%
- Start Explorer "%Cd%"
- call :Debug "用记事本打开EnCode.Bat"
- Start "" "Notepad" "EnCode.Bat"
- call :Debug "加密完毕"
- Echo.
- Echo. ^>^> 加密完毕,是否要调试?[Y/N][输入完毕后请按下回车]
- Echo.
- Set /p "Choice=# ^>^> "
- Echo.
- call :Debug "绘图"
- Call :Type " "
- Call :Type "+"
- Call :Type "=" 4
- Call :Type "=" 8
- Call :Type "=" 4
- Call :Type "+"
- Call :Type "=" 98
- Echo.
-
- If /I Not "%Choice%"=="Y" (
- call :Debug "返回上一级"
- Cd..
- @Goto :Main
- )
- call :Debug "运行EnCode.Bat"
- Start "" "EnCode.Bat"
-
- Echo.
- call :Debug "绘图"
- Call :Type " "
- Call :Type "_" 116
- Echo.
- Call :Type " "
- Call :Type "_" 4
- Call :Type "Code"
- Call :Type "_" 108
- Echo.
- Echo.
- call :Debug "逐屏显示输出内容"
- More "EnCode.Bat"
-
- Echo.
- call :Debug "绘图"
- Call :Type " "
- Call :Type "_" 116
- Echo.
- Echo.
-
- Cd..
-
- @Goto :Main
-
- :RepeatBS
- call :Debug "Bs的设置"
- Set "Bs=%Bs%"
- @Goto :Eof
-
- :Type <Text> [Num]
- call :Debug "绘图引擎"
- %=Company {Hope Studio}=%
-
- %=Author {Hope Studio}=%
-
- If '%2'=='' (
- Set /p Text=#%~1<Nul
- @Goto :Eof
- )
- If Not '%2'=='' (
- For /l %%I in (1,1,%2) Do (
- Set /p Text=#%~1<Nul
- )
- )
-
- @Goto :Eof
-
- :VBScript_EnCode
- call :Debug "写入EnCode.VBS"
- > EnCode.VBS Echo.Function WriteTextFile(strPath, text)
- >> EnCode.VBS Echo.With CreateObject("ADODB.Stream")
- >> EnCode.VBS Echo..Open
- >> EnCode.VBS Echo..type = 2
- >> EnCode.VBS Echo..WriteText text
- >> EnCode.VBS Echo..SaveToFile strPath
- >> EnCode.VBS Echo..close()
- >> EnCode.VBS Echo.End With
- >> EnCode.VBS Echo.End Function
- >> EnCode.VBS Echo.
- >> EnCode.VBS Echo.Dim EnCode
- >> EnCode.VBS Echo.EnCode=WriteTextFile("EnCode.Bat","")
- call :Debug "写入EnCode.VBS结束"
- @Goto :Eof
-
- :Choice
- call :Debug "[提示信息]"
- Echo.
- Echo. ^>^> 此文件不是批处理文件,是否要加密?[Y/N][输入完毕后请按下回车]
- Echo.
- Set /p "Choice=# ^>^> "
- If /I Not "%Choice%"=="Y" (
- @Goto :Main
- )
- call :Debug "变量FilenameExtension=.Bat"
- Set "FilenameExtension=.Bat"
- @Goto :EnCode
-
- goto :eof
- :Debug
- if %debug%==1 (
- set /P= 调试:%~1<nul
- echo;
- )
- goto :eof
复制代码
|