Hey guys, first time poster here. Here's a little (sort of) batch
file that:
1. Takes the input file and uses debug to DUMP it to hex.
2. Takes the dumped hex file and reformats it so that it can be
reassembled via debug, and writes this out to a new batch file.
3. You then take the contents of the resulting batch file
(EMBEDDED.BAT) and copy and paste them into your main batch file.
When the contents are executed it will recreate the file on the fly
for you to subsequently use!
Limitations? Heck yeah:
1. Files that can be embedded are currently limited to 64k (debug
limitation)
2. The batch code that gets created is way bigger than the original
file, so careful if you want to fit it on a floppy disk!
Any questions or comments, just email me. Thanks!
@echo off
:: Binary file embedding script. Copyright 2003, Julian Karst
:: Use this at your own risk!
:: Thanks a bunch to: http://www.datainstitute.com/debug1.htm
Echo Working...
REN %1 IN.TXT
:: Get the size of the file in question, and store it.
for /f "tokens=1,2,3,4" %%i in ('dir IN.TXT /-C ^| find /i "IN.TXT"')
do set FILESIZE=%%l
:: Find out how many 128 byte "chunks" we'll need to read
set /a CHUNKS=(FILESIZE/128)+1
:: Now we use a FOR loop and create a debug batch file
echo L >$$$.txt
echo D 0 >>$$$.txt
FOR /L %%i in (2,1,%CHUNKS%) do echo D >>$$$.txt
echo Q >>$$$.txt
debug IN.TXT <$$$.txt >RESULT.TXT
del $$$.txt
REN IN.txt %1
:: Now we need to convert the decimal file size to a hex value.
set HEXNUMS=0123456789ABCDEF
set /a RESULT=%FILESIZE%%%16
echo SET HEX=%%HEXNUMS:~%RESULT%,1%% >$$$.bat
call $$$.bat
set HEXSTRING=%HEX%
set /a FILESIZE=%FILESIZE%/16
set /a RESULT=%FILESIZE%%%16
echo SET HEX=%%HEXNUMS:~%RESULT%,1%% >$$$.bat
call $$$.bat
set HEXSTRING=%HEX%%HEXSTRING%
set /a FILESIZE=%FILESIZE%/16
set /a RESULT=%FILESIZE%%%16
echo SET HEX=%%HEXNUMS:~%RESULT%,1%% >$$$.bat
call $$$.bat
set HEXSTRING=%HEX%%HEXSTRING%
set HEXSTRING=%HEXSTRING: =%
set /a FILESIZE=%FILESIZE%/16
set /a RESULT=%FILESIZE%%%16
echo SET HEX=%%HEXNUMS:~%RESULT%,1%% >$$$.bat
call $$$.bat
set HEXSTRING=%HEX%%HEXSTRING%
set HEXSTRING=%HEXSTRING: =%
echo echo. >embedded.bat
echo echo N OUT.TXT ^>^>$$$.txt >>embedded.bat
type RESULT.TXT | find ":" >RESULT2.TXT
for /f "tokens=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17, 18 delims=:-
" %%a in (result2.txt) do echo echo E %%b %%c %%d %%e %%f %%g %%h %%i
%%j %%k %%l %%m %%n %%o %%p %%q %%r ^>^>$$$.txt >>embedded.bat
echo echo RCX ^>^>$$$.TXT >>embedded.bat
echo echo %HEXSTRING%^>^>$$$.txt >>embedded.bat
echo echo W ^>^>$$$.txt >>embedded.bat
echo echo Q ^>^>$$$.txt >>embedded.bat
echo debug ^<$$$.txt >>embedded.bat
echo del $$$.txt >>embedded.bat
del result?.TXT & del $$$.bat