In Linux we can do
echo -n -e \'\\x66\\x6f\\x6f\' > test.txt
to write HEX values to a file.
How can this be done simply in Windo
To write "HEX values to file":
set a=.
for /l %a in (0,1,255) do (
set /a dec=%a >nul
call cmd /c exit /b !dec!
set hex=!=exitcode!
set a=!a! !hex:~-2!
)
echo %a:~2% > file.txt
To create a binary file from batch with all the values, see here:
https://www.dostips.com/forum/viewtopic.php?f=3&t=5326
certutil
can do both: create a hex file from a binary, and create a binary file from a hex coded file:
certutil -f -decodeHex hex.txt out.bin >nul
certutil -f -encodeHex out.bin out.txt >nul
To write a binary file with given (decoded) hex value bytes, from CMD:
set data="66 6F 6F"
echo Dim File : Set File = CreateObject("Scripting.FileSystemObject").CreateTextFile("test.txt") > tmp.vbs
echo data = %data% >> tmp.vbs
echo data = Split (data) >> tmp.vbs
echo for each x in data >> tmp.vbs
echo File.write chr("&H" ^& x) >> tmp.vbs
echo next >> tmp.vbs
echo File.Close >> tmp.vbs
cscript //nologo tmp.vbs
If you're just after writing printable (from 0x20 through 0x7E) characters, then !=ExitCodeASCII!
is a good/faster (batch) solution.