Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- DEBUG - Norton Guide http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]

    Using DEBUG scripts


    ----------------------------------------------------------------------

    Testing for DEBUG presence


    ISDEBUG.BAT
    @echo off
    rem     Create a Debug script that terminates Debug immediately
    echo Q > dbg.$$$
    Debug < dbg.$$$ > dbg(.$$$
    if exist dbg(.$$$ goto IS_DEBUG
    rem
    rem     Erase DOS's 'Bad command' message
    CLS
    echo Debug is not in path.
    goto EO_BAT
    :IS_DEBUG
    del *.$$$ > nul
    echo Debug is in path.
    :EO_BAT

    ----------------------------------------------------------------------

    Running DEBUG commands from a batch file

    SEARCH.BAT
    @echo off
    rem
    rem      Search for string thru 8 segments w/Debug and Find.
    rem      NOTE: Won't locate strings crossing segment border.
    rem
    if %1.==. goto usage
    echo Creating DEBUG script...
    echo S 0000:0 L 0  %1 %2 %3 %4 %5 %6 %7 %8 %9 > SEARCH.SCR
    echo S 1000:0 L 0  %1 %2 %3 %4 %5 %6 %7 %8 %9 >> SEARCH.SCR
    echo S 2000:0 L 0  %1 %2 %3 %4 %5 %6 %7 %8 %9 >> SEARCH.SCR
    echo S 3000:0 L 0  %1 %2 %3 %4 %5 %6 %7 %8 %9 >> SEARCH.SCR
    echo S 4000:0 L 0  %1 %2 %3 %4 %5 %6 %7 %8 %9 >> SEARCH.SCR
    echo S 5000:0 L 0  %1 %2 %3 %4 %5 %6 %7 %8 %9 >> SEARCH.SCR
    echo S 6000:0 L 0  %1 %2 %3 %4 %5 %6 %7 %8 %9 >> SEARCH.SCR
    echo S 7000:0 L 0  %1 %2 %3 %4 %5 %6 %7 %8 %9 >> SEARCH.SCR
    echo Q >> SEARCH.SCR
    rem
    echo Search matching %1 %2 %3 %4 %5 %6 %7 %8 %9 > HITLIST.TXT
    echo Searching...
    rem     Tell Find to filter out lines containing the Debug prompt
    DEBUG < SEARCH.SCR | FIND /V "-" >> HITLIST.TXT
    del SEARCH.SCR
    echo Results are in file HITLIST.TXT
    goto eo_bat
    :usage
    echo.
    echo Type what %0 should look for (max. 9 bytes):
    echo as hex bytes        e.g. %0 48 40 4C
    echo or quoted text      e.g. %0 "HAL"
    echo or both             e.g. %0 1B "[2J" 49 41 4D
    echo.
    :eo_bat


    ----------------------------------------------------------------------

    Writing small programs using DEBUG scripts


    Noprtscr changes one byte in the BIOS data area to trick the PC into
    believing that a PrtScr is currently taking place. This will effec-
    tively disable the Shift-PrtScr key combination.
    DEBUG < NOPRTSCR.SCR  will create NOPRTSCR.COM

    NOPRTSCR.SCR
    A 100
    MOV AX,0050
    PUSH AX
    POP ES
    MOV DI,0000
    ES:
    MOV BYTE PTR [DI],01
    MOV AX,4C00
    INT 21

    RCX
    11
    N NOPRTSCR.COM
    W
    Q
    ;                   ;1) Always put a blank line before 'R CX' to
                        ;   end the A(ssemble) command
                        ;2) Put a semicolon in the line after 'Q' to
                        ;   force a CR/LF, else DEBUG will wait forever,
                        ;   since it is reading from standard input,
                        ;   i.e. reboot necessary.
                        ;   Issuing ECHO Q >> debug.scr in a batch file
                        ;   will also do the job.


    --------------------


    ANSIX tests for ANSI.SYS presence and returns errorlevel 1 if it
    is loaded, 0 if not.

    ANSIX.SCR
    N ANSIX.COM
    A100
    JMP  010D           ;Skip over data
    ;<0102>
    DB   1B '[6n' '$'
    ;<0107>
    DB   0D 20 20 20 20 '$'
    ;<010D>
    MOV  DX,102         ;Display the ANSI Device Status Report string
    MOV  AH,09          ; to see if ANSI is loaded
    INT  21
    MOV  AH,0B          ;Check for key in the keyboard
    INT  21             ; buffer -- if there's anything
    CMP  AL,FF          ; there, ANSI is loaded
    JZ   0128           ;Go empty the buffer
    MOV  DX,107         ;Erase the garbage left by the
    MOV  AH,09          ; DSR string
    INT  21
    MOV  AX,4C00        ;Exit w/ errorlevel 0 = ANSI not loaded
    INT  21
    ;<0128>
    MOV  AH,6           ;Get key from keyboard buffer
    MOV  DL,FF          ; don't wait if buffer is empty
    INT  21             ; and don't print it to the screen.
    JNZ  128            ;Go back for more 'til buffer is empty
    MOV  AX,4C01        ;Exit w/ errorlevel 1 = ANSI loaded
    INT  21
    ;<0135>

    R CX
    35
    W
    Q
    ;
    ----------------------------------------------------------------------

    Debugging


    MYDBG.BAT
    @echo off
    echo Creating DEBUG script...
    rem  Load program at CS:0100h
    echo N MYPROG.COM > my.scr
    echo L      >> my.scr
    rem  Execute until breakpoint
    echo G 0140 >> my.scr
    rem  Execute 10 instructions, displaying register values
    echo T 0A   >> my.scr
    rem  More execution
    echo G 03E8 >> my.scr
    rem  Display registers before loop
    echo R      >> my.scr
    rem  Execute loop
    echo P      >> my.scr
    rem  Display registers after loop
    echo R      >> my.scr
    rem  Execute until termination
    echo G      >> my.scr
    rem  ...and quit DEBUG
    echo Q      >> my.scr
    rem
    echo Running DEBUG script...
    DEBUG < my.scr > MY.DBG
    rem  Display DEBUG's output on screen
    type MY.DBG | MORE
    :eo_bat

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson