Computer Hope
Microsoft => Microsoft DOS => Topic started by: Hackoo on October 05, 2019, 04:35:08 AM
-
Hi ;)
The goal of this code is to drag and drop a file onto the script and it encodes or decodes it in Base64 with Certutil Command.
So my question is : "What can i do to escape special characters when a file to be encoded or decoded have them ?"
Thank you !
@echo off
Set "file=%~1"
If "%file%"=="" GOTO:EOF
>nul find "-----BEGIN CERTIFICATE-----" "%file%" && (
certutil -f -v -decode "%file%" "%file%"
) || (
certutil -f -v -encode "%file%" "%file%"
)
@EXIT
-
In C++ I have had to escape the escape character such as \\. In Batch you should also be able to do the same by a double escape using a batch escape character. The first escape is saying to escape the literal escape character. https://www.robvanderwoude.com/escapechars.php
-
I got a solution, so the problem is solved ;)
@echo off
Title Encode and Decode files into B64
setlocal enableextensions enabledelayedexpansion
set "count=0"
set scr="%~f0"
set "cmd=!cmdcmdline:*%~f0=!"
set "args=!cmd:~0,-1!"
set "args=!args:* =!"
for %%f in (!args!) do (
set /a "count+=1"
set infull[!count!]="%%~f"
)
for /l %%i in (1,1,!count!) do (
Set "file=!infull[%%i]!"
)
If [!file!]==[] GOTO:EOF
echo !file! & pause
>nul 2>&1 find /I "-----BEGIN CERTIFICATE-----" !file! && (
certutil -f -v -decode !file! !file!
) || (
certutil -f -v -encode !file! !file!
)
pause
@Exit