If the target machine is Vista and higher then you can use certutil.exe
and create a base64 encoded text, which you can embed within the batch file.
This example has a base64 encoded file that is just a single space
, but the technique is the same with larger binaries.
This batch file uses certutil.exe
to decode
the certificate and data and create the file with a single space in it, no carriage return or line feed.
@echo off
(
echo -----BEGIN CERTIFICATE-----
echo IA==
echo -----END CERTIFICATE-----
)>file.tmp
certutil -decode file.tmp "file with a single space.txt" >nul
del file.tmp
To encode
a program file for placing inside the batch file you use a command line like this, replacing myprogram.exe
with your program name:
certutil -encode -f "myprogram.exe" file.tmp
and then place the contents of file.tmp
inside the batch file:
@echo off
(
echo -----BEGIN CERTIFICATE-----
echo place the data from file.tmp here
echo as it is listed inside the file
echo -----END CERTIFICATE-----
)>file.tmp
certutil -decode file.tmp "myprogram.exe" >nul
del file.tmp
It's fairly easy to add the echo to the front of each line and then use the data from file2.tmp
:
@echo off
for /f "delims=" %%a in (file.tmp) do >>file2.tmp (echo(echo %%a)