certutil - decode/encode BASE64/HEX strings.Print symbols by HEX code
1.ThethingIusedthisforwadtodecodeandencodeBASE64strings.(-decodeand-encodecommandswitches).Ithastwoannoyingfeatureshere-fordecodeandencodeitneeds
-----ENDCERTIFICATE-----and-----BEGINCERTIFICATE-----atbeginingandattheofbase64file.Anditprintsdecodedfileinlineswithmaxlengthof64symbols.
Soherearetwoveryveryverysimplescriptsthatusecertutiltodecodeandencodebase64string(anddealingwithbeginandendtags)(therearenochecksforfileexistenceandiftheparametersarecorrect-Irelyoncertutilerrormessages):
decode:
@echooff setlocal for/f"delims==tokens=1"%%Ain('type%1')do( setencoded=%%A ) remtwoadditionallinesareneededbycertutil echo-----BEGINCERTIFICATE----->%2.tmp echo%encoded%>>%2.tmp echo-----ENDCERTIFICATE----->>%2.tmp certutil/decode%2.tmp%2 del/S/Q%2.tmp endlocal
encode:
@echooff setlocal certutil/encode%1%1.encoded remcreateanemptyfile break>%2 setlocalENABLEDELAYEDEXPANSION ( for/f"eol=-"%%Ain('type%1.encoded')do( remthisnotworks-leftanemptyspaxesaftereachlinefromtypedfile remnull<(set/p#=%%A)>>%1.encoded setresult=!result!%%A ) ) endlocal&setresult=%result% echo%result%>>%2% del/S/Q endlocal
Thebadthingisthatthebase64stringsarestoredinavariableandthere'salimitationsforit'ssize.Butforasmallstringsitwokrs.
2.Muchmoreinteresting.Inthehelpitshowsthatthere'san-decodehexswitch.AndIwassurprisedtofindthatthere'salsoanundocumentesswitch-encodehex(strange-decodehexlooksmoredangerous,becauseitcanbeusedtoproducebinaries).Here'sanexamplestructureofencodedfile:
0000 73657420783d150d 0a73657420793d12 setx=...sety=. 0010 0d0a6563686f202a 2a2578252579252a ..echo**%x%%y%* 0020 2a
(justaseveryhexeditor)
ThiswasmyattempttocreatefilethatsetLFandCRtovariablessmile-andIstilldon'tknowwhyitwasunsuccessfulitprints"§↕"(anyhelpherewillbewelcomed-Idon'tknowwhatgoeswrong).
EDIT:I'vesetDECcodesinsteadHEX.Anywaystillnotworks.
Infactthedatathatisbehindthehexesisnotnecessary-it'sonlyforvisualisation.
Todecodethesamplejustusethis(ifthisaboveissavedinsample.hex):
certutil-decodehexsample.hexnot.working.bat
Anywayitworksforcreationofthefamousbeep.bat:
00006563686f2007
thispatterncanbeusedforcreationofbatthatechoesarandomsymbolsbyhex.Justeditthelastcharacter.
andthisisapatternforsettingasymbolbyhexto%#%variable(justeditthelastcharacter):
000073657420783d150d
AnywaytherearefewmorethingsthatIwanttotrywiththissmile
here'sahowforfilescanbeusedforhexsymbols