how to dump with DEBUG ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

how to dump with DEBUG ?

#1 Post by Ed Dyreen » 08 Jun 2011 18:33

Code: Select all

::--------------------------------------------------------------------------------------------------------------------------
run asm:
F 9000:0 L 200 0
A
Mov dx,9000
Mov es,dx
Xor bx,bx
Mov cx,0001
Mov dx,0080
Mov ax,0301
Int 13
Int 20

U 100 L 12
G
Q

(Note: use 0081, 0082, 0083 for 2nd, 3rd, 4th harddisk respectively)

"debug" < "asm"
::--------------------------------------------------------------------------------------------------------------------------

::--------------------------------------------------------------------------------------------------------------------------
write and run com

N _CHO.COM
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

debug< "%scr%" >nul

_cho.com %date%
_cho.com . test first word
_cho.com . test second word.

::--------------------------------------------------------------------------------------------------------------------------

write asm ??
hexdump ??

Does anyone knows how to dump a .com file with debug ?

And the commands to create one from this asm ?

Where are the experts ? Guess I'll have to find the answer myself, I will :mrgreen:

chakri0113
Posts: 2
Joined: 07 May 2011 21:12

Re: how to dump with DEBUG ?

#2 Post by chakri0113 » 07 Aug 2011 04:53

Hi,

I am not an expert

I think a batch script written by "Terry Newton" will be the solution
Basing on the script, I have written my own script to find Machine Codes in an executable
First I will post the Original Script


I am posting the Original Script by "Terry Newton"

-----------


Code: Select all


@echo off
::======================================================
:: DISM.BAT - A Quicky Disassembler (C)1996 Terry Newton
:: Calls LIST to view if disfile not specified
:: Change 'set list=' line if LIST is not available
::======================================================
if '%1=='Shell goto comshell
if exist %1 goto do_it

:help
echo Uses the DEBUG command to dump and disassemble.
echo Rename EXE files before examining them!
echo Will delete the file AX.BAT if it exists.
echo.
echo Usage: %0 codefile [disfile]
echo LIST is used if disfile not specified
echo.
goto done

:do_it
command /e:5000 /c %0 Shell %1 %2
goto cleanup

:comshell
shift

:: set this to your lister program...
set list=LIST

:: Get hex filelength in evar CX
echo R>d_$
echo Q>>d_$
debug %1<d_$>d_$$
find "CX"<d_$$>d_$.bat
echo set CX=%%5>ax.bat
call d_$.bat

echo Disassembling %CX% (hex) bytes...

:: Add FF to evar CX
:: (yes - batch file math!)
echo H %CX% FF>d_$
echo Q>>d_$
debug<d_$>d_$$
find "  "<d_$$>d_$$$
echo N d_$.bat>d_$
echo E 0100 'AX '>>d_$
echo RCX>>d_$
echo 3>>d_$
echo W>>d_$
echo Q>>d_$
debug<d_$>nul
type d_$$$>>d_$.bat
echo set CX=%%1>ax.bat
call d_$.bat

:: Dump and disassemble from 0100 to evar CX
echo D 100 %CX%>d_$
echo.>>d_$
echo U 100 %CX%>>d_$
echo.>>d_$
echo Q>>d_$
if '%2==' goto listit
debug %1<d_$>%2
goto done

:listit
debug %1<d_$>dism_out
call %list% dism_out
goto done

:: Clean up temp files
:cleanup
del d_$??
del d_$.bat
del ax.bat
if exist dism_out del dism_out
:done



chakri0113
Posts: 2
Joined: 07 May 2011 21:12

Re: how to dump with DEBUG ?

#3 Post by chakri0113 » 07 Aug 2011 05:16

Hi,

Basing on the Original script, I have written a script to Search Machine Codes in Executable's ( EXE / COM ) files, using DEBUG

When we want to pass an EXE file as a Parameter, please ensure there is no "EXE" extension, you can rename it to FileName.E or FileName.EX or FileName.EXEX ....

Code: Select all


@Echo Off

  ::   -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ::
  ::                                ::
  ::                       SEARCH.BAT Version 2.22                        ::
  ::                                ::
  ::              Batch Script To Search For M/C Code & Bytes                ::
  ::                                ::
  ::                                ::
  ::    ReName The Executable, So That It Lacks The "EXE" Extension        ::
  ::                 Eg: Ren Gobman.Exe Gobman.Ex              ::
  ::                                ::
  ::              Works Fine Under Win98, Win2K, WinXP              ::
  ::                                ::
  ::                                ::
  ::   -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ::
  ::                                 ::   
  ::.       Syntax : Search %1 %2 %3 %4 %5 %6 %7 %8 %9 <Press Enter>        ::
  ::.                                 ::
  ::.           %1 Should Be A Valid FileName                 ::
  ::.           %2 - %9 Can Be Any Valid M/C Code              ::
  ::.                                ::
  ::.   (1) Example: Search Gobman.Ex  C7 06 50 54  <Press Enter>            ::
  ::.   (2) Example: Search Gobman.Ex  C6 06        <Press Enter>            ::
  ::.   (3) Example: Search Gobman.Ex  FF 0E        <Press Enter>            ::
  ::.   (4) Example: Search Gobman.Ex  FE 0E        <Press Enter>            ::
  ::.   (5) Example: Search Gobman.Ex  FF 06        <Press Enter>            ::
  ::.   (6) Example: Search CHAKRI.SAV F8 2A        <Press Enter>            ::
  ::    (7) Example: Search  Debug.Ex "Word Ptr"              ::
  ::    (8) Example: Search  Debug.Ex "Byte Ptr"              ::   
  ::.                                ::
  ::.  Explanations:                                                         ::
  ::. Ex(1) Searches In The File "Gobman.Ex"  For M/C Mov Word Ptr (C706)    ::
  ::. Ex(2) Searches In The File "Gobman.Ex"  For M/C Mov Byte Ptr (C606)    ::
  ::. Ex(3) Searches In The File "Gobman.Ex"  For M/C Dec Word Ptr (FF0E)    ::
  ::. Ex(4) Searches In The File "Gobman.Ex"  For M/C Dec Byte Ptr (FE0E)    ::
  ::. Ex(5) Searches In The File "Gobman.Ex"  For M/C Inc Word Ptr (FF06)    ::
  ::. Ex(6) Searches In The File "Chakri.Sav" For The Bytes        (F82A)    ::
  ::.                                ::
  ::. Result :                             ::
  ::.   A New File Viz., "Search - 'xxxxxxxx.yyy'.Txt" Will Be Created        ::
  ::."x.y" Is The File U Provide As Input & Contain Results Of Our Search    ::
  ::                                 ::
  ::   -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

::CheckSyntax
If [%1]==[] If [%2]==[] For %%C In (Cls Find Goto:Quit) Do %%C ":." Search.Bat | Find /V "["
If ['%1']==[''] Goto:FNF

:: *******************************************************************
::  --> Routine #01 <-- Collect All The Given Params
:: *******************************************************************
  If Not [%1] == []     Set P1=%1
  If Not [%2] == []     Set P2=%2
  If Not [%3] == []     Set P3=%3
  If Not [%4] == []     Set P4=%4
  If Not [%5] == []     Set P5=%5
  If Not [%6] == []     Set P6=%6 
  If Not [%7] == []     Set P7=%7
  If Not [%8] == []     Set P8=%8
  If Not [%9] == []     Set P9=%9 
  If Not [%1] == [@]     Set SFS="Search - "'%1'".Txt"
:: *******************************************************************


:: *******************************************************************
::  --> Routine #02 <-- First Find The Number Of Segment's In The File
:: *******************************************************************
   For %%C In ( R Q ) Do Echo %%C >> {{C}}
   > {{H}}  Debug %1   < {{C}}
   > $H.Bat Find "BX"  < {{H}}
   > AX.Bat Echo Set Segments=%%3
     Call $H.Bat

:: *******************************************************************
::  --> Routine  <-- Find The FileSize
:: *******************************************************************

   > $C.Bat Find "BX" < {{H}}
   > AX.Bat Echo Set FSize=%%3%%5
     Call $C.Bat   

   ::Echo FileSize = %FSize%

:: *******************************************************************
::  --> Routine #02 <-- Continues
:: *******************************************************************
   > {{H}} Debug %1   < {{C}}
   > $H.Bat Find "CS" < {{H}}


:: *******************************************************************
:: --> Routine #03 <-- Now We Have The Code Segment Addr In E-Var %CS1%
:: *******************************************************************
   > DS.Bat Echo Set CS1=%%5
     Call $H.bat


:: *******************************************************************
:: --> Routine #04 <--
:: *******************************************************************
:: Now We Are Concerned To Find The Next Code Segment Address
:: I.e We Need To Add 1000(h) Bytes, To The CS Register,
:: To Continue Our Search, In The Next Segment As Well
::
:: Add 1000(h) Or 4096(d) to E-Var CS1
:: *******************************************************************

  >  {{C}}   Echo H %CS1% 1000 
  >> {{C}}   Echo Q           
  >  {{H}}   Debug      <  {{C}} 
  >  {{A}}   Find /V "-"   <  {{H}}



:: *******************************************************************
:: --> Routine #05 <--
:: *******************************************************************
:: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
:: THIS IS THE TRICKIEST PART OF THIS BATCH SCRIPT
:: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

  >  {{C}}      Echo E 0100 'DS '
                For %%C In ( N$C.Bat RCX 3 W Q ) Do Echo %%C >> {{C}}

  >  Nul   Debug             <  {{C}} 
  >> $C.Bat   Type {{A}}       
  >  DS.Bat   Echo Set CS2=%%1
      Call $C.Bat

  >  {{K}}   Echo H %CS1% 2000 
  >> {{K}}   Echo Q           
  >  {{R}}   Debug             <  {{K}}
  >  {{I}}   Find /V "-"       <  {{R}}
  >  Nul   Debug             <  {{C}}
  >> $C.Bat   Type {{I}}       
 

  >  DS.Bat   Echo Set CS3=%%1
      Call $C.Bat

:: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
:: *******************************************************************


:: *******************************************************************
:: --> Routine #06 <-- Now Time To Code The Search Routine
:: *******************************************************************
      For %%C In ( {{H}} {{I}} {{C}} ) Do If Exist %%C Del %%C

   >  {{C}}     Echo S %CS1%:0 L FFFF %2 %3 %4 %5 %6 %7 %8 %9
   >> {{C}}     Echo S %CS2%:0 L FFFF %2 %3 %4 %5 %6 %7 %8 %9
   >> {{C}}     Echo S %CS3%:0 L FFFF %2 %3 %4 %5 %6 %7 %8 %9
   >> {{C}}     Echo Q

   ::Type {{C}}
   ::Pause

   > {{H}} Debug %1 < {{C}}


:: *******************************************************************
:: --> Routine #07 <--
:: *******************************************************************
:: =-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=
:: To Display The Number Of Offsets, Found 
:: =-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=
:: *******************************************************************

  >  {{C}}      Echo E 0100 'SET OFFSET='
                For %%C In ( N$C.Bat RCX B W Q ) Do Echo %%C >> {{C}}
  >  Nul   Debug            <  {{C}}


  >   {{I}}   Find /V "-"      <  {{H}}
  >>  $C.Bat    Find /C ":"      <  {{I}}
                Call $C.Bat

      If Not [%Offset%] == [@] Echo. ::*************************************::
   If Not [%Offset%] == [@] Echo.    Search Resulted In %Offset% Offset(s)
   If Not [%Offset%] == [@] Echo. ::*************************************::

   

:: *******************************************************************
:: --> Routine #08 <--
:: *******************************************************************
:: Redirect The Contents Of Tmp File ({{I}}),
:: Into A Reference File "Search-'xxxxxxxx.yyy'.Txt"
:: Where xxxxxxxx Is The File Name U Provide
:: Where      yyy Is The File Name Extension 
:: *******************************************************************
     >   %SFS%     Echo.
                  Echo. | Date | Find "E" /V >>                                  %SFS%
                  Echo. | Time | Find "E" /V >>                                  %SFS%
    >>   %SFS%     Echo.
    >>   %SFS%     Echo               Search File                             : %P1%   
    >>   %SFS%     Echo.
    >>   %SFS%     Echo               FileSize In Hex Bytes                   : %FSize%
    >>   %SFS%     Echo               Number Of Segments In File              : %Segments%
    >>   %SFS%     Echo.
    >>   %SFS%     Echo               First  Code Segment At Mem Loc          : %CS1%
    >>   %SFS%     Echo               Second Code Segment At Mem Loc          : %CS2%
    >>   %SFS%     Echo               Third  Code Segment At Mem Loc          : %CS3%
    >>   %SFS%     Echo.
    >>   %SFS%     Echo               For Bytes  : %P2% %P3% %P4% %P5% %P6% %P7% %P8% %P9% 
    >>   %SFS%     Echo.
    >>   %SFS%     Echo               *********************************************
    >>   %SFS%     Echo               Summary    : %Offset% Offsets Found
    >>   %SFS%     Echo               *********************************************
    >>   %SFS%     Find /V "-"       <  {{I}}

 

:: *******************************************************************
:: --> Routine #09 <--  CleanUp E-Vars
:: *******************************************************************

   For %%C In (     CS1 CS2 CS3 SEGMENTS OFFSET          ) Do Set %%C=
   For %%C In ( P1 P2 P3 P4 P5 P6 P7 P8 P9 SFS FSIZE     ) Do Set %%C=


:: *******************************************************************
:: --> Routine #10 <--  CleanUp Tmp Files
:: *******************************************************************
   For %%C In ( {{C}} {{H}} {{A}} {{K}} {{R}} {{I}} ) Do If Exist %%C Del %%C
   For %%C In (    $C.Bat $H.Bat AX.Bat DS.Bat      ) Do If Exist %%C Del %%C


:FNF
   If [%1]==[] Echo      ** Either File Does NOT Exist Or Bytes Not Specified **
             
:Quit

   If Exist "Search - '%1'.Txt" Find /I "^" "Search - '%1'.Txt"    >Nul
   If ErrorLevel 0 If Not ErrorLevel 1 Del "Search - '%1'.Txt"     >Nul
   If Exist "Search - '%1'.Txt"  Start NotePad "Search - '%1'.Txt" >Nul



Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: how to dump with DEBUG ?

#4 Post by Ed Dyreen » 07 Aug 2011 06:13

'
Looks promising, I've bookmarked because it's gonna take me a while to process your input.

I've been looking for ages for a good website for beginners that can teach me how to work with
Debug.exe in 16bit DOS environment, hard to find because most are for 32bit windows...

My goal is to write, debug, compile, decompile my own 16bit DOS apps using debug.exe.

Beware, I am trying to decompile a 16bit DOS application that won't run in windows, why ?
It's a DOS i387 floating point co-processor emulater.
I am trying to decompile it because it requires a key that I don't have.
The program is over 30years old and the company is out of business for over 10years.
So I don't think my attempts are illegal.
I've tried brute forcing it but I've calculated I will be dead by the time I succeed. :cry:
It is called Q87, I need it because my i386 is missing a floating point co-processor, tried getting my hands on one but
noone seems to have the 387SX version I require, it was develloped in the '80tees.

I wish the hubble telescope crashed in my backyard with the 387SX unit still intact :)

Code: Select all

EMM386 is active

Brute forcing Q87, run code: '000-723-496'

A demo of Q87 4.13 will now be run. Your application(s) will run for 20 minutes.

next run code: '000-723-497'
rebooting system...

Teach me more, I'm all eyes...

Thanx alot @chakri0113, I really appreciate :mrgreen:

Post Reply