如何使用批处理文件创建可执行文件? [英] How to create an EXE executable with batch file?
问题描述
我希望能够简单地运行 Windows 批处理文件并让它创建一个 .exe 可执行文件.
我知道您可以使用以下脚本批量创建文件:
@echo offecho 这将在一个文本文件中!>>测试.txtecho 这将是第二行!>>测试.txt
所以我想知道,是否可以复制 EXE 文件的源代码并在每一行前面添加一个echo",并在每行末尾添加一个>> test.exe"?>
我尝试在 Notepad ++ 中打开 39KB .exe,但它只是一堆黑色的 NUL 字符.
所以我很想问有没有办法在批处理文件中嵌入文件?甚至可能是音频文件?
这里是如何使用 certutil 实用程序完成的.在本例中,它使用指向 whoami.exe 的硬编码路径进行演示,该路径是 Windows 中的内置命令.
首先使用嵌入的 .exe 创建 .bat 的脚本:
@echo offcertutil -f -encode %windir%\system32\whoami.exe whoami.b64echo @echo off >container.batecho certutil -decode "%%~f0" whoami.exe>>container.batecho call whoami.exe>>container.batecho exit/b %%errorlevel%%>>container.bat输入 whoami.b64>>container.batdel whoami.b64
对于您的 exe,您需要更改 exe 的路径.然后 container.bat
应如下所示:
@echo offcertutil -decode "%~f0" whoami.exe调用 whoami.exe退出/b %errorlevel%-----开始认证-----.....base64 编码的内容......-----结束证书----
certutil 可以编码/解码 base64 和十六进制,这里 base64 更方便,因为它可以嵌入到批处理中,这要归功于附件(BEGIN CERTIFICATE
和 END CERTIFICATE
)和 base64 编码字符串比十六进制短.
I want to be able to simply run a Windows batch file and have it create a .exe executable.
I know that you can create files with the following script in batch:
@echo off
echo This will be in a text file! >> test.txt
echo And this will be the second line! >> test.txt
So I was wondering, would be possible to copy the source code of an EXE file and add an "echo" in front of every line, and a " >> test.exe" and the end of every line?
I tried to open the 39KB .exe in Notepad ++, but it was just a bunch of black NUL characters.
So I'm pretty much asking if there's a way to embed files inside batch files? Even an audio file maybe?
here's how it can be done with certutil utility. In this case it is demonstrated with hard-coded path to whoami.exe which is a builtin command in windows.
First a script that creates the .bat with the embedded .exe :
@echo off
certutil -f -encode %windir%\system32\whoami.exe whoami.b64
echo @echo off >container.bat
echo certutil -decode "%%~f0" whoami.exe>>container.bat
echo call whoami.exe>>container.bat
echo exit /b %%errorlevel%%>>container.bat
type whoami.b64>>container.bat
del whoami.b64
For your exe you'll need to change the path to the exe.Then the container.bat
should look like:
@echo off
certutil -decode "%~f0" whoami.exe
call whoami.exe
exit /b %errorlevel%
-----BEGIN CERTIFICATE-----
...
..base64 encoded content...
...
-----END CERTIFICATE----
certutil can encode/decode base64 and hex here base64 is more convenient because it can be embedded into batch thanks to enclosements (BEGIN CERTIFICATE
and END CERTIFICATE
) and base64 encoded strings are shorter than hex ones.
这篇关于如何使用批处理文件创建可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!