DEBUG examples
Com2txt.bat (used SED.EXE)
...Output examples
Purpose
Restore.bat (used SED and STRINGS.COM)
Additional. (used MS-DOS)
Filesize (hex or dec and removes the CRLF to CON -- April 18, 01)
Into env variable (simply brief, beautiful & useful -- April 19, 01)
Put "quotes" around a text. (QUOTES.BAT -- April 19, 01)
Remove the CR+LF (April 20, 01)
Toolbox (name it DEBUG~it, BUGportal or getBUGS.bat -- April 29, 01)
Add hex numbers. (ADD_hex.bat -- May 05, 01)
dec2hex (dec2hex.bat -- May 13, 01)
Com2txt.bat
:: Date May 27, 2000
:: Author B.Pedersen
:: Tested on Win98.:
Copy & paste (1.355 byte:)
@Echo off
Echo Make a text copy (a .SCR file) of a .COM or any other file. You
Echo can later create the file (use Restore.BAT or) from the SCRipt:
If not exist "%windir%\command\SED.EXE" Exit
Echo DEBUG Filename - Filename.SCR |SED "s/^/\n\n\n/; s/-/</;" > CON
For %%c in ( . . . .----------------------------- . . . ) do Echo%%c
If %1'==' For %%c in (Echo.Dragÿandÿdropÿtheÿfileÿtoÿ%0 Exit) do %%c
For %%c in (LS : D) do C%%c %temp%\
Rem >%1.SCR
For %%v in (.RCX . .Q) do Echo%%v>>%1.SCR
Debug %1<%1.SCR |Sed "/^C/!d;s/CX\(.*\)/D100 L\1\nQ\nset b=\1/">DATA
Debug %1 < DATA |Sed "/:/!d; s/....:/E /; s/-/ /; s/ .*//" >%1.SCR
Sed "$!d;s/$/\ndel data/" DATA>DATA.BAT
Dir/b %1 | Sed "s/^/set x=/" >>DATA.BAT
For %%f in ( Call Del ) do %%f DATA.BAT
For %%v in (RCX %B% W Q -------"%X%.SCR"-------) do Echo %%v>>%1.SCR
For %%c in (Echo.------ Type) do %%c %1.SCR |MORE
Echo.>{TEST}.COM
Debug {TEST}.COM<%1.SCR> NUL
FC %0 %0 | Sed "/FC: /!d ; s/....\(.\{14\}\).*/set x=\1/" > {FC}.BAT
For %%f in (Call Del) do %%f {FC}.BAT
FC /b {TEST}.COM %1| Find "%X%" > NUL
If not errorlevel 1 Echo. ÿÿÿÿÿ ** The script was successful **
If errorlevel 1 Echo ** ERROR ** ERROR ** ERROR ** ERROR ** ERROR **
If errorlevel 1 Del %1.SCR
For %%v in (B X) do Set %%v=
For %%c in (Del Pause Cls Exit) do %%c {TEST}.COM
Output examples:
* WRITE.COM.SCR
E 0100 BB 80 00 43 80 3F 0D 75 FA C6 07 24 B4 09 BA 82
E 0110 00 39 DA 7F 02 CD 21 B4 4C CD 21
RCX
001B
W
Q
-------WRITE.COM.SCR-------
* Color.BAT.SCR
This batchfile contains special syntax (not included in
the other sections). If you want to see those? then you
must restore the batchfile from the script or, you most
be good to those Hx numbers.
- Hmmm, 40 Hx (see below) is 64 Dec so,... (See table.)
E 0100 40 45 63 68 6F 20 6F 66 66 0D 0A 54 79 70 65 20
E 0110 25 30 7C 46 69 6E 64 20 22 C3 22 7C 46 69 6E 64
E 0120 2F 76 20 22 30 22 3E 29 2E 63 6F 6D 0D 0A 46 6F
E 0130 72 20 25 25 63 20 69 6E 20 28 50 61 75 73 65 20
E 0140 43 61 6C 6C 20 45 63 68 6F 2E 28 FF 48 6D 6D 6D
E 0150 20 50 61 75 73 65 20 44 65 6C 20 43 6C 73 20 47
E 0160 6F 74 6F 29 20 64 6F 20 25 25 63 20 29 2E 63 6F
E 0170 6D 0D 0A B8 00 0B BB 08 00 CD 10 B8 00 06 B9 00
E 0180 00 BA 4F 18 B7 4F CD 10 B4 02 BA 00 00 B7 00 CD
E 0190 10 C3 0D 0A 3A 29 0D 0A
RCX
0098
W
Q
-------Color.BAT.SCR-------
Purpose
The above Color.BAT.SCR file, is created using drag and drop,
(Color.BAT file to the icon of Com2txt.BAT)
I can now delete my Color.BATch file and make it again,
(drag and drop the "Color.BAT.SCRipt" file to "Restore.BAT":)
Restore.bat (or: scr2com.bat)
@Echo off
Rem Make somefile from somefile.SCR
Rem Used SED.EXE and STRINGS.COM
Rem Tested on Win98
Rem Benny Pedersen, February 12, 00 -- (Updated Sept 13)
For %%c in (LS : D) do C%%c %temp%\
Set x=EXT
Strings x=FILE%x% %1
If not %x%==SCR For %%c in (Echo Bad_command... Goto) do %%c END. (reson:)
:: Set x=Name ( witout drive, path and the Ext .SCR )
Dir/b %1 | Sed "s/^/set x=/; s/\.SCR$//" > x.bat
For %%f in (Call Del) do %%f x.bat
If not exist "%x%" Goto Restore
Echo. File "%temp%\%x%" exist
Echo.1: Overwrite
Echo.2: Delete + Exit
Choice /c:123 3: Exit
If not errorlevel 3 Del "%x%"
If errorlevel 2 For %%c in (Set Cls Exit) do %%c x=
:Restore
Echo.>q
Debug q < %1 > NUL
@Copy q /v/b "%x%" > NUL
Erase q
Echo ** The file is created (%temp%\%x%) **
:End
For %%c in (Set Pause Cls Exit) do %%c x=
Additional for Win98:
@Echo off
:: The Writ.com file is identical to the writE.com file. (See the script.)
Echo N Writ.com> Writ
Echo A 100>> Writ
For %%v in ("MOV BX, 80" "INC BX" "CMP BYTE [BX], D" ) do Echo %%v>>Writ
For %%v in ("JNE 103" "MOV BYTE [BX], 24" "MOV AH, 9") do Echo %%v>>Writ
For %%v in ("MOV DX,82" "CMP DX,BX" "JG 117" "INT 21") do Echo %%v>>Writ
For %%v in (."MOV AH, 4C" ."INT 21" . .RCX .1B .W .Q ) do Echo%%v>> Writ
Echo.>Writ.com
Debug Writ.com < Writ > NUL
Echo Done.
Writ And now we see
Writ what
Echo this is about...
Del/p Writ.*
Cls
Filesize
@echo off
attrib %0 > %temp%.\~a.bat
REM SET X = Size of file ~a.bat (hex) > %temp%.\~x.scr
for %%v in (.rcx . .q) do echo%%v >> %temp%.\~x.scr
debug %temp%.\~a.bat < %temp%.\~x.scr > %temp%.\~x.bat
echo e106" SET X" 3D > %temp%.\~x.scr
for %%v in (rCX E w106 q) do echo %%v>> %temp%.\~x.scr
debug %temp%.\~x.bat < %temp%.\~x.scr > NUL
call %temp%.\~x.bat
echo. The size of "%temp%.\~a.bat" is %X% byte (hex),
REM Remove the CRLF from the output to CON: "(dec):" > %temp%.\~x.scr
for %%v in (L102 w F100LFF''1A L w102 q) do echo %%v>> %temp%.\~x.scr
echo. (dec): > %temp%.\~x.bat
debug %temp%.\~x.bat < %temp%.\~x.scr > NUL
type %temp%.\~x.bat > CON
REM And the file size is (dec): > %temp%.\~x.scr
for %%v in (F0L%X%''A rCX %X% w0 q) do echo %%v>> %temp%.\~x.scr
type %temp%.\~x.scr | debug %temp%.\~x.scr > NUL
find /v /c "" < %temp%.\~x.scr
del %temp%.\~*.*
set X=
Into environment variable
: The following is based on a solution by William Allen so, it was NOT
: a competition about, Who can write this more brief than another. The
: @ECHO OFF was actually working. (Tested on Win98).
:
@echo off> %temp%.\~.bat
for %%e in ( e5'SET'20'X'3D rcx 6 w5 q ) do echo %%e>> %temp%.\~.bat
type %temp%.\~.bat |debug %temp%.\~.bat> nul
echo Hello World>> %temp%.\~.bat
: FIND "ot" < %0>> %temp%.\~.bat
Into environment variables
@echo off
echo.. | choice /c'%1.> nul
for %%v in (0 1 2 3 4 5 6 7 8) do if errorlevel 0}%%v set L=0%%v0
echo ~%1> %temp%.\~#.bat
for %%v in (L0 f110L%L%''9''9''9''9''9''9'set'20'%%#'3D'#'D''A) do echo %%
v>>%temp%.\~#.bat
for %%v in (1 2 3 4 5 6 7 8) do echo e01%%vB'%%v'>>%temp%.\~#.bat
for %%v in (1 2 3 4 5 6 7 8) do echo m%%vL1 1%%vD>>%temp%.\~#.bat
for %%v in (rcx %L% w110 q ) do echo %%v>> %temp%.\~#.bat
type %temp%.\~#.bat |debug %temp%.\~#.bat> nul
call %temp%.\~#.bat n1 n2 n3 n4 n5 n6 n7 n8
for %%v in (%n1% %n2% %n3% %n4% %n5% %n6% %n7% %n8%) do echo. %%v
for %%v in (L CMDLINE n1 n2 n3 n4 n5 n6 n7 n8) do set %%v=
del %temp%.\~#.bat
Put "quotes" around a text
@echo off %{ QUOTES.BAT }%
if not exist %1 call goto EOF
rem: This batch code surrounds a text with quotes, i.e. "text" > %temp%.\~
for %%v in (L102 e101''22 w f100LFFF''22 L w101 q) do echo %%v >> %temp%.\~
debug %1 < %temp%.\~ > nul
echo.>>%1
del %temp%.\~
:EOF %{ PS.: The ASCII value of a quote (") is 22 hex. }%
Rik D'haveloose wrote:
SNIP... Same tehnique could be used to get rid of the CR+LF charachters
(hex 0D, 0A) from an echoed line of text (to append something later with
echo.....), although i then would prefer to use hex20 (space) instead of
the quote :-), and maybe some shorter version as:
FOR %%v in (L102 e100''20''20 w q) do echo %%v>>%temp%.\temp.sfd
^^ ^^
Hi Rik, Yes hex 20 can be used but also hex A or hex 9 as:
FOR %%v in (f0L2''A L2 w0 q) do echo %%v>>%temp%.\temp.sfd
Benny. ^
Toolbox
Updated April 2001, (click here to see the previous version).
Maybe under construction in September 2001. (All previous got
problems with COM files and I also got some new stuff 2 use).
The following batch can be used to starting the DEBUG prompt.
Some DEBUG commands i.e. suggestions are displayed before the
DEBUG prompt. My suggestions which are available and ready to
be copied and pasted can be used OR you can just ignore them.
You can as usually type DEBUG or DEBUG FILE at the DOS prompt
or you can use the below batch. Notis that 1 line is wrapped:
@echo off
if not exist %1 call goto: no_file. > %temp%.\~.bat
echo e100''09''20''40'set'20'%%1'3D > %temp%.\~.scr
for %%v in (rcx 10 w q) do echo.%%v>> %temp%.\~.scr
for %%v in (.rcx . .q) do echo%%v>> %temp%.\~.bat
type %temp%.\~.bat | debug %1 .... > %temp%.\~.bat
debug %temp%.\~.bat < %temp%.\~.scr > nul
call %temp%.\~.bat CX
attrib %1
echo mB800:1A L126 B800:0 > %temp%.\~.scr
echo fB800:A0 L084 '-' 32>> %temp%.\~.scr
echo q >> %temp%.\~.scr
debug < %temp%.\~.scr > nul
for %%v in (. .f0LFFFF''20 .L .e0E0'0123456789ABCDEF') do echo%%v
echo e0F0 0 1 2 3 4 5 6 7 8 9 A B C D E F
for %%v in (dE0L20 d100L%CX%) do echo.%%v
set CX=
goto end
:no_file
for %%v in (. . .eF0''0''1''2''3''4''5''6''7''8''9''A''B''C''D''E''F .f10
0LFF00''20 .fE0L10'0123456789ABCDEF' .dE0LD0 .) do echo%%v
:end
echo m B800:A0L4E4 B800:BC> %temp%.\~.scr
echo q >> %temp%.\~.scr
debug < %temp%.\~.scr > nul
debug %1
for %%v in (erase cls) do %%v %temp%.\~.*
EXIT.--Maybe under construction in September 2001.
@echo off
if not exist %1 call goto:no_file. > %temp%.\~.bat
echo exit|%comspec%/kprompt e100'set CX='$_rcx$_7$_w$_q|debug %temp%.\~.b
at>nul
echo exit|%comspec%/kprompt rcx$_$_ $Hfor %%%%%%%%v in (%%%%CX%%%%) do se
t CX=L%%%%%%%%v$_q|debug %1|find "C">>%temp%.\~.bat
for %%v in (cls call) do %%v %temp%.\~.bat [ CX ]
attrib %1
echo %- COLORS -%exit|%comspec%/kprompt mB800:1AL126 B800:0$_fB800:A0L84'
-'22$_q|debug>nul
for %%v in (. .f0LFFFF''20 .L .eE0'0123456789ABCDEF') do echo%%v
echo eF0 0 1 2 3 4 5 6 7 8 9 A B C D E F
for %%v in (dE0L20 d100%CX%) do echo.%%v
goto:end
:no_file
echo exit|%comspec%/kprompt $_eF0 0 1
2 3 4 5 6 7 8 9 A B C D E F$_f100LFF00 20$_eE0'0123456789ABCDEF'$_dE0LD0$_
:end
echo %- OFFSET -%exit|%comspec%/kprompt mB800:A0L4E4 B800:BC$_q|debug>nul
for %%v in ("set CX=" "debug %1" del:%temp%.\~.bat cls) do %%v
ADD_hex.bat
:Usage of ADD_hex.bat: call add_hex c [=] c + c
:Example: c = 5 + FAC9 would return c = FACE (hex) = 05 + 64201 (dec).
:Hint: x c + FFFE would return x = c - 2 (any value of c except c=1).
echo h%2 %4> %temp%.\add_hex1.bat
echo q>> %temp%.\add_hex1.bat
debug<%temp%.\add_hex1.bat |find "-"/v> %temp%.\add_hex1.bat
for %%v in (rcx B eF9'set'9'%%1'3D wF9 q) do echo %%v>> %temp%.\add_hex1.bat
type %temp%.\add_hex1.bat|debug %temp%.\add_hex1.bat>nul
call %temp%.\add_hex1 %1
del %temp%.\add_hex1.bat
dec2hex.bat
This file is based on an idea by Tom L. so, I
tried several ideas and I also tested it for speed, etc...
Example 1: (a file for testing the dec2hex.bat)
@echo off
call dec2hex 65535
echo %Hex%
set Hex=
Example 2: (a file for testing the dec2hex.bat)
@echo off
if not !!!!!'==%1' for %%! in (0 1 2 3 4 5 6 7 8 9) do call %0 %1! %2%%!
if !!!!!==%1 call dec2hex %2
if !!!!!==%1 echo %Hex%
if !!!!!==%1 echo %Hex%>> TESTING.TXT
if %Hex%==0FA0 for %%v in (set exit) do %%v Hex=
Several speed test have been performed. Thereby, the resulting file
below has been changed very much.
Note about line number 3: rem -------> -.tmp
It seems that the syntax: ctty nul > -.tmp
can't be used in any batch programs. They simply get unstable.
This also includes the "CTTY CON > file.ext" So, never use it!
@echo off > 0%1.#
rem dec2hex> -
rem -------> -.tmp
ctty nul
for %%v in (rcx 1 e100''A w q) do echo %%v>>-
type - | debug -
:opy
for %%v in (0.# 0?.# 0??.# 0???.# 0????.#) do ren %%v 0%%v
for %%v in (0 1 2 3 4 5 6 7 8 9) do if exist 0????%%v.# set Hex=%%v
echo.%Hex% | choice /c0123456789
for %%v in (2 3 4 5 6 7 8 9 :) do if errorlevel %%v copy /b -.tmp+-
if not exist 00000?.# copy /b -+-+-+-+- -A.tmp
ren 0?????.# 0????.# >-
if not exist 00000.# for %%c in (c c goto:) do %%copy /b -+-A.tmp
for %%v in (r q) do echo %%v>>-
debug -.tmp < - | find "AX=" >-.bat
echo set Hex=%%5> AX.bat
call -.bat
ctty con
for %%v in (-?.* 0*.# AX.bat) do del %%v
|