2015-06-15 70 views
1

我希望能夠簡單地運行Windows批處理文件並讓它創建一個.exe可執行文件。如何使用批處理文件創建EXE可執行文件?

我知道,你可以在批量創建與下面的腳本文件:

@echo off 
echo This will be in a text file! >> test.txt 
echo And this will be the second line! >> test.txt 

所以我想知道,將有可能複製EXE文件的源代碼,並在前面加一個「迴音」的每一行,以及「>> test.exe」和每一行的結尾?

我試圖在Notepad ++中打開39KB .exe,但它只是一堆黑色的NUL字符。

所以我非常想知道是否有方法將文件嵌入到批處理文件中?即使是一個音頻文件也許?

+0

請參閱:http://stackoverflow.com/questions/27383152/storing-large-file-within-batch-file/27384211#27384211 – Aacini

回答

1

下面介紹如何使用certutil實用程序完成此操作。 在這種情況下,它通過硬編碼的路徑來展示給whoami.exe,它是windows內置命令。

首先創建與嵌入式.exe文件將.bat腳本:

@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 

爲了您的exe文件,你需要將路徑更改爲exe.Then的container.bat應該是這樣的:

@echo off 
certutil -decode "%~f0" whoami.exe 
call whoami.exe 
exit /b %errorlevel% 
-----BEGIN CERTIFICATE----- 
... 
..base64 encoded content... 
... 
-----END CERTIFICATE---- 

certutil可以在這裏對base64和hex進行編碼/解碼base64更方便,因爲它可以嵌入批處理(BEGIN CERTIFICATEEND CERTIFICATE),並且base64編碼的字符串比hex更短。

相關問題