『第
3 楼』:
1.0.0002版本
@Mode Con: Cols=80 Lines=25 & @Color 3F & @Chcp 936 > Nul & Title Hope Any to Bat Version 1.0.0002 & @Echo Off
@Goto :Begin
:Begin
Cd /D "%~dp0"
@Call :LoadFunctions
@Goto :Main
:Main
Cd /D "%~dp0"
@Call :UserInteraction
@Goto :Main
:UserInteraction
@Call :PrintMenu
@Call :Choice
If "%ascKey%"=="1" Set /P Str=#1]<Nul & @Goto :NewProject
If "%ascKey%"=="2" Set /P Str=#2]<Nul & @Call :ReadHelp
If "%ascKey%"=="3" Set /P Str=#3]<Nul & @Exit 0
If 0 Equ 0 @Goto :Eof %= 防止因特殊字符而出错 =%
@Goto :Eof
:PrintMenu
@Cls
For /L %%I in (0,1,1) Do Echo.
Echo. 欢迎使用 Hope(R) Any2Bat 实用程序
Set /P Str=# <Nul
For /L %%I in (0,1,71) Do Set /P Str=#=<Nul
Echo.
For /L %%I in (0,1,2) Do Echo.
Echo. 1) 新建工程
Echo.
Echo. 2) 阅读帮助文档
Echo.
Echo. 3) 退出 Hope(R) Any2Bat
Echo.
Set /P Str=# 请选择:[ ]<Nul
@Goto :Eof
:Choice
%_Getch:#ascCode#=ascKey%
@Goto :Eof
:LoadFunctions
Set _Getch=Set "#ascCode#=" ^& ( For /F "Usebackq Delims=" %%_ in (`XCopy /L /W "%~f0" "%~f0" 2^^^>Nul`) Do If Not Defined #ascCode# ( Set "#ascCode#=%%_") ) ^& Call Set "#ascCode#=%%#ascCode#:~-1%%"
@Goto :Eof
:NewProject
@Call :PrintWizardTitle
Set FileName=//
Set /P FileName=# 请将需要打包的文件拖入此窗体:
Set FileName=%FileName:"=%
Set FileName="%FileName%"
If Exist %FileName% @Goto :NewProject1
If Not Exist %FileName% (
Echo.
Echo.
Echo. 无此文件!
Pause > Nul
@Goto :NewProject
)
@Goto :NewProject
:NewProject1
@Call :PrintWizardTitle
Set IsCompress=//
Set jFileName=//
For /F "Delims=" %%I in ('Dir /A-D /B %FileName%') Do (
%= 仅文件名 =%
Set jFileName=%%~nI
Set jstFileName=%%~nI
%= 仅文件拓展名 =%
Set jExtension=%%~xI
)
Set jFileName=%jFileName: =%
Echo. 需要将源文件压缩吗?
Echo.
Echo. 假如您的源文件体积较大,那么压缩后可以减小包的大小,增加解包的效率;如果
Echo. 您的源文件体积较小,那么压缩后可能会适得其反。
Echo.
Echo.
Set /P Str=# 需要压缩吗?[Y/N]:[ ]<Nul
@Call :Choice
If /I "%ascKey%"=="Y" (
Set /P Str=#Y]<Nul
Set IsCompress=True
@Goto :NewProject2
)
If /I "%ascKey%"=="N" (
Set /P Str=#N]<Nul
Set IsCompress=False
@Goto :NewProject2
)
If 0 Equ 0 @Goto :NewProject1 %= 防止因特殊字符而出错 =%
@Goto :NewProject1
:NewProject2
@Cls
Echo.
Echo. ^>^> 正在创建工程目录
FOR /F "TOKENS=2 DELIMS==" %%I IN ('WMIC PATH WIN32_OPERATINGSYSTEM GET LOCALDATETIME /VALUE ^| FINDSTR "="') DO (
SET "STRDATE=%%I"
)
SET "TODAY=%STRDATE:~0,4%%STRDATE:~4,2%%STRDATE:~6,2%"
SET "NOW=%STRDATE:~0,4%-%STRDATE:~4,2%-%STRDATE:~6,2% %STRDATE:~8,2%#%STRDATE:~10,2%#%STRDATE:~12,2%"
Md "Project_%NOW%" > Nul 2> Nul
Cd /D "Project_%NOW%"
Md "Temp" > Nul 2> Nul
Cd Temp
If /I "%IsCompress%"=="False" (
Copy %FileName% "%Cd%\Source.Src" > Nul 2> Nul
For /F "Delims=" %%I in ('Dir /B Source.Src') Do Set jFileSize=%%~zI
Set hFileName=Source.Src
Set FName=%jstFileName%%jExtension%
)
If /I "%IsCompress%"=="True" (
Copy %FileName% "%Cd%\Source.$" > Nul 2> Nul
Echo.
Echo. ^>^> 正在压缩
For /F "Delims=" %%I in ('Dir /B Source.$') Do Set jFileSize=%%~zI
MakeCAB /D CompressionType=lzx /D CompressionMemory=21 /D maxdisksize=%jFileSize% %FileName% "%Cd%\%jFileName%.Cab" > Nul 2> Nul
For /F %%I in ('Dir /B "%jFileName%.Cab"') Do Set jFileSize=%%~zI
Set hFileName=%jFileName%.Cab
Set FName=%jFileName%.Cab
)
@Call :GetHex
Cd..
Md "Release" > Nul 2> Nul
Copy "Temp\Hex.Tmp" "Release\Hex.Tmp" > Nul 2> Nul
Cd /D "Release"
@Call :MakeBatch
@Goto :NewProject3
:NewProject3
Echo.
Echo. ^>^> 已完成打包任务,是否进行查看和调试?
Echo.
Echo.
Set /P Str=# 需要调试和查看吗?[Y/N]:[ ]<Nul
@Call :Choice
If /I "%ascKey%"=="Y" (
Set /P Str=#Y]<Nul
Start Mk.Bat
Start Explorer "%Cd%"
@Goto :Main
)
If /I "%ascKey%"=="N" (
@Goto :Main
)
If 0 Equ 0 @Goto :NewProject1 %= 防止因特殊字符而出错 =%
@Goto :NewProject3
:GetHex
Echo.
Echo. ^>^> 正在获取文件十六进制信息,此步骤将耗费较多时间,请耐心等待……
Fsutil File CreateNew 1.$ %jFileSize% > Nul 2> Nul
FC /B "%hFileName%" 1.$ > 2.$
@Call :WriteVBS 1 2.$ 3.$
Echo.
Echo. ^>^> 正在整理文件十六进制信息,此步骤将耗费较多时间,请耐心等待……
Cscript //Nologo WriteBin.VBS
@Call :WriteVBS 2 %jFileSize%
Echo.
Echo. ^>^> 正在找回文件遗漏的十六进制信息,此步骤将耗费较多时间,请耐心等待……
Cscript //Nologo WriteBn2.VBS
FC /B "%hFileName%" 2.Tmp > 4.$
@Call :WriteVBS 1 4.$ 5.$
Echo.
Echo. ^>^> 正在重新整理文件十六进制信息,此步骤将耗费较多时间,请耐心等待……
Cscript //Nologo WriteBin.VBS
Type 3.$ > tHexS.$
Type 5.$ >> tHexS.$
Echo.
Echo. ^>^> 正在生成文件十六进制信息,此步骤将耗费较多时间,请耐心等待……
Sort /Unique tHexS.$ /O tHex.Tmp
Echo.
Echo. ^>^> 正在生成文件十六进制码,此步骤将耗费较多时间,请耐心等待……
@Call :WriteVBS 3 tHex.Tmp Hex.Tmp
Cscript //Nologo WriteBn3.VBS
@Goto :Eof
:MakeBatch
Echo.
Echo. ^>^> 正在生成批处理脚本,此步骤将耗费较多时间,请耐心等待……
(
Echo.Dim objFSO, objFile, strLine
Echo.Dim objOpFSO, objOpFile, strOpLine
Echo.Dim i
Echo.Set objFSO = CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objOpFSO = CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objFile = objFSO.OpenTextFile^("Hex.Tmp", 1^)
Echo.Set objOpFile = objOpFSO.CreateTextFile^("Mk.Bat"^)
Echo.objOpFile.Write "@Echo Off" ^& vbCrLf ^& "@Goto :Main" ^& vbCrLf ^& vbCrLf ^& ":Main" ^& vbCrLf ^& vbTab ^& "@Call :Mk_%jFileName%" ^& vbCrLf ^& "@Exit /B" ^& vbCrLf ^& vbCrLf ^& ":Mk_%jFileName%" ^& vbCrLf ^& "Cd. > Mk.$" ^& vbCrLf
Echo.i = 0
Echo.Do Until objFile.atendofstream
Echo. If i = 0 Then objOpFile.Write "(" ^& vbCrLf
Echo. If ^(i + 1^) Mod 256 = 0 Then objOpFile.Write ") >> Mk.$" ^& vbCrLf ^& "(" ^& vbCrLf
Echo. strLine = objFile.ReadLine
Echo. objOpFile.WriteLine "Echo." ^& strLine
Echo. i = i + 1
Echo.Loop
Echo.If i Mod 256 ^<^> 0 Then objOpFile.Write ") >> Mk.$" ^& vbCrLf
Echo.If i Mod 256 = 0 Then objOpFile.Write "Cd.) >> Mk.$" ^& vbCrLf
Echo.objFile.Close
Echo.objOpFile.Close
Echo.Set objFSO = Nothing
Echo.Set objOpFSO = Nothing
) > $Make.VBS
Cscript //Nologo $Make.VBS
(
Echo.^(
Echo.Echo.Dim objFSO, objFile, strLine
Echo.Echo.Dim objOpFSO, objOpFile, strOpLine
Echo.Echo.Dim i
Echo.Echo.Set objFSO = CreateObject^^^("Scripting.FileSystemObject"^^^)
Echo.Echo.Set objOpFSO = CreateObject^^^("Scripting.FileSystemObject"^^^)
Echo.Echo.Set objFile = objFSO.OpenTextFile^^^("Mk.$", 1^^^)
Echo.Echo.Set objOpFile = objOpFSO.CreateTextFile^^^("Mk_.VBS"^^^)
Echo.Echo.objOpFile.Write "Dim Bin_" ^^^& vbCrLf ^^^& "Bin_ = Array("
Echo.Echo.Do Until objFile.AtEndOfStream
Echo.Echo. strLine = objFile.ReadLine
Echo.Echo. For i = 1 To Len^^^(strLine^^^) Step 2
Echo.Echo. objOpFile.Write "&H" ^^^& Mid^^^(strLine, i, 2^^^) ^^^& ", "
Echo.Echo. Next
Echo.Echo. objOpFile.Write "_ " ^^^& vbCrLf
Echo.Echo.Loop
Echo.Echo.objOpFile.Write "-1)" ^^^& vbCrLf ^^^& vbCrLf
Echo.Echo.objOpFile.WriteLine "Call WriteBinary(""%FName%"", Bin_)"
Echo.Echo.objOpFile.Write vbCrLf
Echo.Echo.objOpFile.WriteLine "Sub WriteBinary(FileName, Buf)"
Echo.Echo.objOpFile.WriteLine " Dim I, aBuf, Size, bStream"
Echo.Echo.objOpFile.WriteLine " Size = UBound(Buf) - 1: ReDim aBuf(Size \ 2)"
Echo.Echo.objOpFile.WriteLine " For I = 0 To Size - 1 Step 2"
Echo.Echo.objOpFile.WriteLine " aBuf(I \ 2) = ChrW(Buf(I + 1) * 256 + Buf(I))"
Echo.Echo.objOpFile.WriteLine " Next"
Echo.Echo.objOpFile.WriteLine " If I = Size Then aBuf(I \ 2) = ChrW(Buf(I))"
Echo.Echo.objOpFile.WriteLine " aBuf=Join(aBuf, """")"
Echo.Echo.objOpFile.WriteLine " Set bStream = CreateObject(""ADODB.Stream"")"
Echo.Echo.objOpFile.WriteLine " bStream.Type = 1: bStream.Open"
Echo.Echo.objOpFile.WriteLine " With CreateObject(""ADODB.Stream"")"
Echo.Echo.objOpFile.WriteLine " .Type = 2 : .Open: .WriteText aBuf"
Echo.Echo.objOpFile.WriteLine " .Position = 2: .CopyTo bStream: .Close"
Echo.Echo.objOpFile.WriteLine " End With"
Echo.Echo.objOpFile.WriteLine " bStream.SaveToFile FileName, 2: bStream.Close"
Echo.Echo.objOpFile.WriteLine " Set bStream = Nothing"
Echo.Echo.objOpFile.WriteLine "End Sub"
Echo.Echo.objFile.Close
Echo.Echo.objOpFile.Close
Echo.Echo.Set objFSO = Nothing
Echo.Echo.Set objOpFSO = Nothing
Echo.^) ^> Mk$.VBS
) >> Mk.Bat
(
Echo.Cscript //Nologo Mk$.VBS
Echo.Cscript //Nologo Mk_.VBS
If /I %IsCompress%==True Echo.Expand /R "%FName%" ^> Nul 2^> Nul
If /I %IsCompress%==True Echo.If Exist "%FName%" Del /Q "%FName%" ^> Nul 2^> Nul
Echo.If Exist "Mk_.VBS" Del /Q "Mk_.VBS" ^> Nul 2^> Nul
Echo.If Exist "Mk$.VBS" Del /Q "Mk$.VBS" ^> Nul 2^> Nul
Echo.If Exist "Mk.$" Del /Q "Mk.$" ^> Nul 2^> Nul
Echo.@Goto :Eof
) >> Mk.Bat
If Exist Hex.Tmp Del /Q Hex.Tmp
If Exist $Make.VBS Del /Q $Make.VBS
@Goto :Eof
:WriteVBS
If %1==1 (
(
Echo.Dim objFSO, objFile, strLine
Echo.Dim objOpFSO, objOpFile, strOpLine
Echo.Set objFSO = CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objOpFSO = CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objFile = objFSO.OpenTextFile^("%2", 1^)
Echo.Set objOpFile = objOpFSO.CreateTextFile^("%3"^)
Echo.objFile.SkipLine
Echo.Do Until objFile.atendofstream
Echo. strLine = objFile.ReadLine
Echo. strOpLine = Split^(strLine, " "^)
Echo. objOpFile.WriteLine strOpLine^(0^) ^& strOpLine^(1^)
Echo.Loop
Echo.objFile.Close
Echo.objOpFile.Close
Echo.Set objFSO = Nothing
Echo.Set objOpFSO = Nothing
) > WriteBin.VBS
)
If %1==2 (
(
Echo.Dim objFSO, objFile, strLine, i
Echo.Set objFSO = CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objFile = objFSO.CreateTextFile^("2.Tmp"^)
Echo.For i = 0 To %2 - 1
Echo. objFile.Write Chr^(65^)
Echo.Next
Echo.objFile.Close
Echo.Set objFSO=Nothing
) > WriteBn2.VBS
)
If %1==3 (
(
Echo.Dim objFSO, objFile, strLine
Echo.Dim objOpFSO, objOpFile, strOp
Echo.Dim i
Echo.Set objFSO = CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objOpFSO = CreateObject^("Scripting.FileSystemObject"^)
Echo.Set objFile = objFSO.OpenTextFile^("%2", 1^)
Echo.Set objOpFile = objOpFSO.CreateTextFile^("%3"^)
Echo.i = 0
Echo.Do Until objFile.atendofstream
Echo. strLine = objFile.ReadLine
Echo. strOp = Split^(strLine, ":"^)
Echo. objOpFile.Write strOp^(1^)
Echo. If ^(i + 1^) Mod 32 = 0 Then objOpFile.Write vbCrLf
Echo. i = i + 1
Echo.Loop
Echo.objFile.Close
Echo.objOpFile.Close
Echo.Set objFSO = Nothing
Echo.Set objOpFSO = Nothing
) > WriteBn3.VBS
)
@Goto :Eof
:PrintWizardTitle
@Cls
For /L %%I in (0,1,1) Do Echo.
Echo. 新建工程向导
Set /P Str=# <Nul
For /L %%I in (0,1,71) Do Set /P Str=#=<Nul
Echo.
For /L %%I in (0,1,1) Do Echo.
@Goto :Eof
:ReadHelp
@Cls
For /L %%I in (0,1,1) Do Echo.
Echo. Hope(R) Any to Bat 自述文档
Echo.
Echo. Hope Any to Bat [Version 1.1.00002]
Echo. (C) Copyright 2016-2022 Hope Corp.
Echo.
Echo. ·Hope(R) Any to Bat 是什么
Echo. Hope(R) Any to Bat 是一款批处理嵌入包设计软件,它可以将任何文件插入到批
Echo. 处理脚本中,并自动设计解包程序。此程序支持VBS技术,能更快的完成操作。
Echo.
Echo. ·Hope(R) Any to Bat 更新日志
Echo. ·Version 1.0.0000 09/08/2021
Echo.
Echo. ·Version 1.0.0001[未发布] 19/08/2021
Echo. 首次尝试VBS内核,兼容性极差
Echo.
Echo. ·Version 1.0.0002 05/06/2022
Echo. 重新设计VBS内核,速度增强,
Echo. 更改了界面。
Echo. 未解决兼容性问题,打包程序目前只在 Windows 10 测试正常。
Pause > Nul
@Goto :Eof
|