You are not logged in.

#1 26 Aug 2015 00:28

Batcher
Member
Registered: 20 Jul 2015
Posts: 56

Copy /b into temp file

Is there a way using a batch script to copy the binary from one file and type it into a temp file then when the user calls the temp file from the batch script it inputs it into a file to recreate the original file ? Thanks

Offline

#2 26 Aug 2015 01:36

foxidrive
Member
Registered: 04 Apr 2013
Posts: 339

Re: Copy /b into temp file

certutil can be used in Modern Windows to encode a binary to a text representation and also back into the same binary file.

This script will make the part that you can put into your batch file - and that part recreates the binary file.



@echo off
if "%~1"=="" echo Syntax: "%~0" "file to be encoded.ext" & pause & goto :EOF
certutil /encode /f "%~1" "%~1.encoded.1"
find /v /i "CERTIFICATE---" <"%~1.encoded.1" >"%~1.encoded.2"


(
echo((
echo(echo(-----BEGIN CERTIFICATE-----
for /f "usebackq delims=" %%a in ("%~nx1.encoded.2") do echo(echo(%%a
echo(echo(-----END CERTIFICATE-----
echo(^)^>"%~nx1.decode"
echo(certutil /decode /f "%~nx1.decode" "%~nx1" ^>nul
echo(del "%~nx1.decode"
)>"%~nx1.encoded.txt"
del "%~nx1.encoded.?"

Offline

Board footer

Powered by