home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / editor / dis86216.zip / DIS86.DOC < prev    next >
Text File  |  1992-12-20  |  44KB  |  1,140 lines

  1.  
  2.                     dis86 - Interactive 8086 Disassembler
  3.  
  4.   (C) COPYRIGHT 1985 - 92 by James R. Van Zandt,  ALL RIGHTS RESERVED
  5.  
  6.  
  7.  
  8.  
  9. You are encouraged to copy and distribute this program freely, provided:
  10.  
  11.     1)    No fee is charged beyond the actual cost for such copying and
  12.         distribution.
  13.  
  14.     2)    It is distributed ONLY in its original, unmodified state
  15.         (including documentation).
  16.  
  17. If you like this program, and find it of use, then your contribution of
  18. $25 will be appreciated.  For installation on a network file server
  19. with any number of users, a contribution of $125 is requested.  A
  20. current version program disk is available for $50.  Send contributions
  21. to:
  22.  
  23.             James R. Van Zandt
  24.             27 Spencer Dr.
  25.             Nashua NH 03062
  26.                        USA
  27.  
  28.             603-888-2272
  29.  
  30. If you find bugs (byte sequences which are incorrectly disassembled),
  31. please let me know.  I am also willing to listen to suggestions for
  32. improvements.  I can be reached at the above address or via e-mail
  33. as follows...
  34.  
  35.     MILNET:          jrv@mbunix.mitre.org
  36.     CompuServe:      internet:jrv@mbunix.mitre.org
  37.     
  38. Please indicate which version you have and where you downloaded it.
  39.  
  40. SYNOPSIS
  41.  
  42. Dis86 is a full-screen, interactive disassembler of object code for the
  43. 8086, 8087, 8088, 80186, 80286, and 80386 (products of Intel), and the
  44. V20 and V30 (products of NEC).  The 80386 disassemblies include 32 bit
  45. operands and addresses.  Dis86 implements the concept of a "current
  46. location" and allows use of the cursor keys to change it.  Code can
  47. come from a .EXE file (in which case the file header is properly
  48. interpreted), any other file (assumed to have no header), or anywhere
  49. in main memory (0000:0000 - F000:FFFF).  It can also read and write
  50. using absolute disk addresses (in which case the disk organization is
  51. shown).  Dis86 can install changes, even in a .EXE file, making it a
  52. convenient way to install patches.  The program runs on the IBM PC (and
  53. clones).
  54.  
  55.  
  56. REVISION HISTORY
  57.  
  58. 2.16   Fixed bug in disk reads and writes.
  59.        Checking for errors in disk reads and writes (write protect, etc.).
  60. 2.15   Printing # clusters as unsigned rather than int.
  61. 2.14   Correspondents are now asked to specify media type.  
  62.        F1 key brings up help display.
  63. 2.13   Handles DOS 5 and disks >32M.  For segment register editing: CR 
  64.        doesn't advance to next register, can leave register menu.  '&'
  65.        command prints user setable parameters.  Default attribute for
  66.        pop-up windows is white-on-blue.  Registers menu has border. 
  67.        getsa has string length argument.  Top line is highlighted.
  68. 2.12   Fixed file writing (switched from fopen/fseek/fwrite to
  69.        open/lseek/write due to new C library).
  70. 2.11   Fixed op codes for mov instructions involving CR 
  71.        (another error in the "Advance Information")
  72. 2.10   Fixed mov instructions involving CR, DR, and TR.
  73.        Printing always stops at the end of the code buffer.
  74. 2.03   Fixed reference searches to work with jumps or calls
  75.        that wrap around to the beginning of the segment.
  76. 2.02   Revised 32-bit MOD/RM and s-i-b byte decoding (Intel's "Advance 
  77.        Information" was wrong).  Searches continue to end of file.
  78. 2.00   Symbol table, Lotus-style menubar, immediate screen format change, 
  79.        accepts start address on command line.
  80.  
  81. 1.34   Fixed disassembly of instructions with both immediate data and offsets.
  82. 1.33   Using sensing I/O library: works on either IBM or Z-100.
  83. 1.32   hardware screen I/O on IBM - much faster
  84. 1.31   Follows short calls either forward or backward.
  85. 1.30   gets pathname from system if run under DOS 3.xx
  86. 1.29   pg up and pg dn page through the help display pages.
  87. 1.28   The file header pops up in the bottom half of the screen.
  88. 1.27   12-bit FAT entries can be entered as well as displayed.
  89. 1.26   Segment register menu pops up in corner rather than clearing
  90.        entire screen.  Beeps eliminated.
  91. 1.25   Foreground and background colors work in Z-100 version.  ESC and ^C 
  92.        abort commands that request keyboard input.  Correctly shows
  93.        last cluster on disk.
  94. 1.24   Cloning - can write optional parameters into object code.
  95. 1.23   Foreground and background colors may be set in IBM version.
  96. 1.22   Following FAT entries.
  97. 1.21   Eliminating trailing blanks in printout.
  98. 1.20   Absolute disk address mode installed.
  99. 1.15   Minor style changes, V command copies its expression to reply line.
  100. 1.14   Follows interrupts if disassembling from memory.
  101. 1.13   Fixed several small disassembly errors, installed V command.
  102.        Reversed bx+disp and bp+disp codes again...NOTE: description in
  103.        preliminary 80386 manual is WRONG.
  104. 1.12   Installed F format.
  105. 1.11   Reversed bx+disp and bp+disp codes.
  106. 1.10   Implemented s-i-b byte for 80386 code (previously omitted due to
  107.        oversight).
  108. 1.00   First publically released version.
  109.  
  110. SUMMARY OF CHANGES FROM VERSIONS BEFORE 2.00
  111.  
  112. Aside from added features, present users will note two significant
  113. changes in the user interface.
  114.  
  115. The S command now starts a search.  The segment register is chosen by
  116. selecting the corresponding item in the R menu.
  117.  
  118. Before version 2.00, the screen format commands (Ascii, Byte, Code,
  119. Data, Font, clUster) optionally accepted addresses.  It was necessary
  120. to follow them with a carriage return to indicate the absence of an
  121. address.  I found that I rarely needed to enter an address, and the
  122. extra keypress was annoying.  Now, screen format commands take effect
  123. immediately.  Moving to a new disassembly address requires a separate
  124. Go command.  If you prefer the option to change the format and address
  125. in a single command, you may indicate this in the Option menu.
  126.  
  127.  
  128. STARTING THE DISASSEMBLER
  129.  
  130. To disassemble a file, give the file name (optionally preceded by a path 
  131. name) on the command line:
  132.  
  133.         A>dis86 foo.exe
  134.  
  135. To disassemble from RAM, use an empty command line:
  136.  
  137.         A>dis86
  138.  
  139. To disassemble using absolute disk addresses, specify only the disk on
  140. the command line:
  141.  
  142.         A>dis86 b:
  143.  
  144. You can also indicate the screen format and starting address on the
  145. command line.  To disassemble from memory starting at ffff:0 (the boot
  146. address), type:
  147.  
  148.         A>dis86  -c ffff:0
  149.  
  150. You can use on the command line any of the expression operators that
  151. would be legal within the program.  For example, to examine the start
  152. of the stack segment, you could type:
  153.  
  154.         A>dis86  dis86.exe  -b ss:0
  155.  
  156. DISPLAY SCREEN
  157.  
  158. During disassembly, the screen will resemble the following:
  159.  
  160.         0000:0100      e9 01 90            jmp            9104
  161.         0000:0103      55                  push           bp       
  162.         0000:0104      8b ec               mov            bp,sp    
  163.         0000:0106      83 ec 0e            sub            sp,0e    
  164.         
  165.                                   ...
  166.         
  167.         0000:012C      50                  push           ax         
  168.         0000:012D      b8 69 00            mov            ax,0069    
  169.         0000:0130      50                  push           ax         
  170.         0000:0131      e8 e9 5c            call           5e1d       
  171.         dis86 1.00 - A SHAREWARE software product  (c) 1986, James R. Van Zandt
  172.         >
  173.         ... 0000:0100  0000:0100  0000:0100  
  174.  
  175. Lines 1 through 21 are the disassembled code.  Each line starts with
  176. the current address, followed by the actual bytes being disassembled. 
  177. The rest of the line is the assembly language equivalent, if any, of
  178. the code.  The display for A (ASCII), B (byte), D (data), F (font), and
  179. U (File Allocation Table) formats is similar.  All numbers are shown in
  180. hexadecimal.  
  181.  
  182. Line 22 is a message and prompt line showing, for example, the
  183. arguments needed for some commands.  Line 23 has the prompt.  Typed
  184. characters are echoed here.  Line 24 displays three addresses, which
  185. are the top three entries in the stack (see the 'cursor right' and
  186. 'cursor left' commands below).
  187.  
  188.  
  189. CURSOR KEYS
  190.  
  191. The "current location" is the address displayed on the first line
  192. of disassembly.  The cursor keys are used to adjust the current 
  193. location.
  194.  
  195. The up and down cursor keys (8 and 2 on the numeric pad) are used to
  196. move the current location a small amount.  <up> moves by one line
  197. except in C (code) format, when it moves up by one byte. (Note that <up>
  198. and <down> are not inverses in this case.):
  199.  
  200.         <up>     moves up by one line or byte (lower address)
  201.         <down>   moves down by one line (higher address)
  202.  
  203.  
  204. The <pg up> and <pg dn> keys (9 and 3 on the numeric pad) move the
  205. current location by larger amounts.  In C (code) format, they move by
  206. 32 bytes.  In the other formats, they move by 11 lines on the screen. 
  207. They will not move the cursor out of the disassembly buffer. 
  208. Otherwise, they are inverses.:
  209.  
  210.         <pg up>   moves up by 32 bytes (lower address)
  211.         <pg dn>   moves down by 32 bytes (higher address)
  212.  
  213.  
  214. The above keys change only the current location.  Other commands change 
  215. the current location by potentially large amounts, but first save it in 
  216. a stack.  The top three addresses in the stack are shown in the command
  217. area at the bottom of the screen.
  218.  
  219. If the instruction at the current location is a jump, call, or a
  220. reference to a data location, the cursor right key (6 on the numeric
  221. pad) will push the current location on the stack and go to the
  222. referenced location.  If the disassembly is from memory, interrupts can
  223. also be followed.  For a data reference, the disassembly format is
  224. changed to D (hex and ASCII).  If disassembly is from disk using
  225. absolute disk references and the disassembly format is U (display File
  226. Allocation Table, or FAT), then the next FAT entry is followed.
  227.  
  228.         <right>   follows a jump, call, interrupt, 
  229.                   data reference, or FAT entry
  230.  
  231. If disassembling a FAT, the next entry is followed, staying within the
  232. same FAT.  If disassembling from an address above the last FAT, the
  233. disassembler assumes a directory entry is being displayed, finds the
  234. next FAT reference (displacement 1A from the beginning of the current
  235. directory entry, which begins on a 32 byte boundary), and follows it
  236. into the first FAT.  Note that the disassembly format must be U before
  237. the disassembler will attempt to follow a FAT entry.  The natural
  238. format for displaying a directory entry would be D or A.  The
  239. appropriate command sequence would then be U <right>.
  240.  
  241. The cursor left or left arrow key (4 on the numeric pad) will pop the
  242. last address off the stack.  Note that right arrow followed by left
  243. arrow will return you to the same address, whereas left arrow
  244. (returning, let us say, to address X) followed by right arrow will only
  245. return you to the same address if there is an appropriate jump, call,
  246. or data reference at X.
  247.  
  248.         <left>    pops address stack
  249.  
  250. After using the right arrow or the G command (in the next section) to
  251. go to a new address, then using the left arrow key to pop the stack,
  252. you will sometimes want to return to the previous address.  The stack
  253. no longer holds the address.  However, the left arrow key saves the
  254. current location in a special "previous state" before popping the
  255. stack.
  256.  
  257. To return to the address stored in the "previous state", type shift
  258. right arrow on a Z-100, or control right arrow on an IBM PC.
  259.  
  260.         <ctrl><right>    returns to "previous state"   (IBM)
  261.         <shift><right>   returns to "previous state"   (Z-100)
  262.  
  263.  
  264. In summary, the unshifted keys on the numeric pad are:
  265.  
  266. <home> top of file          ^   up 1 line         <pg up>  up 32 bytes 
  267.                             |         
  268.  
  269. <--    pop addr stack                             -->      follow jump/call
  270.  
  271.                             |         
  272. <end>  end of file          v  down 1 line        <pg dn>  down 32 bytes  
  273.  
  274.  
  275. <ins>  setup options 
  276.  
  277. On the Z-100, the four keys with arrows on them may be used in addition
  278. to the 2, 4, 6, and 8 on the numeric pad.
  279.  
  280.  
  281. MOVING THE CURSOR
  282.  
  283. The command for moving the cursor to a specific address is
  284.  
  285.     G <expression> <ret>
  286.  
  287. The 'S' command starts a search.  It may be followed by three kinds of
  288. search patterns:
  289.  
  290.     S <expression> <expression> <expression> <ret>
  291.             The disassembler searches starting at the
  292.             current address for the specified sequence of
  293.             hex bytes.  If an expression has a segment
  294.             specified using the ':' operator (below), the
  295.             segment is ignored.
  296.  
  297.     S T [string] <ret>
  298.             The disassembler searches from the current
  299.             address for the specified ASCII string.  Cases
  300.             are not distinct, and the high order bit is
  301.             ignored.  The string can also be introduced by
  302.             a double quote.
  303.  
  304.     S R <expression> <ret>
  305.             The disassembler searches from the current
  306.             address for a reference (load, store, jump or
  307.             call) to the specified address.
  308.  
  309. Searches will continue to the end of the file, disk, or system memory. 
  310. Most searches should take a few seconds or less.  Long searches, such
  311. as those on the disk, can be interrupted with control-C.
  312.  
  313. An <expression> can involve any of these items:
  314.  
  315.     hex numbers    (either upper or lower case letters)
  316.     cs, ds, es, ss, fs, gs
  317.             currently assumed segment register values
  318.     $        current location
  319.     @        offset of top address on the stack
  320.     'x'        single characters
  321.     "jkl;"        multiple character strings
  322.     main            predefined symbols
  323.  
  324. ...and any of these operators:
  325.  
  326.     + - * /        add, subtract, multiply, divide
  327.     :        separate segment and offset
  328.  
  329. Note that G with no address is a noop.  
  330.  
  331. There are two ways to ask for a text string search.  For example,
  332.  
  333.     S T jones
  334.  
  335.     S "Jones"
  336.  
  337. In the first search, cases are not distinct and the high order bit
  338. is ignored.  In the second search, the high order bit must be 0 and
  339. the cases must match.  The second form can be intermixed with other
  340. expressions:
  341.  
  342.     S "Jones" 0d 0a 00
  343.  
  344. The reference search looks for three kinds of instructions:  far
  345. jumps and calls, short jumps and calls, and moves to or from the
  346. accumulator (al, ax, or eax).  
  347.  
  348. Jumps and calls having two byte displacements may be misinterpreted if
  349. the assumed code segment register value is incorrect.  In these
  350. instructions, the displacement is relative to the address of the
  351. following instruction, so it is relocatable (i.e., the entire program
  352. is still correct if it is moved to a new location).  However, the
  353. destination must be in the same 64K code segment.  If a jump has a
  354. displacement which is larger than the address difference from the jump
  355. to the end of the segment then the destination wraps around to the
  356. beginning of the segment.  If the assumed value of the code segment
  357. register is incorrect, this wrap around point may be incorrect so that
  358. the destination is incorrect by 64K (10000 hex).
  359.  
  360. Similarly, moves between the accumulator and memory may be
  361. misinterpreted if the assumed value of the data segment register is
  362. incorrect.
  363.  
  364.  
  365. CHANGING DISPLAY FORMAT
  366.  
  367. There are six letter commands to change the display format:
  368.  
  369.     A    ASCII data
  370.     B    byte data (hex)
  371.     D    data (both hex bytes and ASCII)
  372.     C    code
  373.     F    font
  374.     U    File Allocation Table entry
  375.  
  376. These commands, as with all letter commands, may be in upper or lower
  377. case.  In previous versions of the disassembler, these commands also
  378. accepted addresses.  In order to change display format without changing
  379. the address, it was necessary to add <ret>.  In this version, the
  380. format change takes place immediately.  If you prefer the previous
  381. method, you may select that option on the first option menu.
  382.  
  383. The number of bytes per line in A, B, or D formats can be changed using
  384. the W command or the width entry in the second option menu (see below).
  385.  
  386. In F format, one byte is shown per line, and each bit in that byte is
  387. represented by an astrisk.  This is suitable for displaying fonts for
  388. video displays, which are uniformly 8 bits wide.
  389.  
  390. In U (clUster number) format, bytes are displayed as File Allocation
  391. Table, or FAT entries.  This format is ordinarily useful only when
  392. disassembling using absolute disk addresses.  In that case, the
  393. disassembler will have determined how many clusters there are on the
  394. disk.  If there are fewer than 4097, then 12 bit FAT entries are
  395. assumed.  If there are 4097 or more, then 16 bit FAT entries are
  396. assumed.  Each pair of 12 bit FAT entries occupies three bytes.  If the
  397. cursor is set on the third byte of a pair of 12 bit entries, or the
  398. second byte of a 16 bit entry, the disassembler displays some dashes to
  399. signal that it is skipping that byte.  Otherwise, it starts by
  400. displaying the FAT entry that begins with that byte.
  401.  
  402. There are many explanations of how File Allocation Tables work.  One
  403. good one is in Ray Duncan's book "Advanced MSDOS" (Microsoft Press,
  404. 1986).
  405.  
  406. MISCELLANEOUS COMMANDS
  407.  
  408. The 'E' command allows the user to modify the program being
  409. disassembled.  Changes are initially made only in the disassembly
  410. buffer.  Before the buffer is overwritten or the disassembler
  411. terminates, the user is asked whether the changes are to be written to
  412. the file or RAM area being disassembled.  The values entered may be
  413. given in hex expressions or ASCII.  Values too large to fit into a byte
  414. are assumed to be words or double words.  Here are some examples:
  415.  
  416.     45 67 'A'            =>  45 67 41
  417.  
  418.     2ea+3                =>  ed 02
  419.  
  420.     9c/3                 =>  34
  421.  
  422.     "Alpha Beta" 0d 0a   =>  41 6c 70 68 61 20 42 65 74 61 0d 0a
  423.  
  424.  
  425. The 'P' command is used to print a disassembly listing to a file.  The
  426. first time this command is used, it prompts for a file name.  The
  427. default file name is "printout".  To actually send the listing to a
  428. printer, specify the filename "prn".  If the file already exists the
  429. new information will be appended.  The file is automatically closed
  430. before the disassembler exits.  The command also prompts for the
  431. beginning and end addresses of the code to be printed.  The default
  432. addresses print the current screen.  When the printing is finished, the
  433. current address is advanced to the first byte not printed.  Thus, you
  434. can repeat the sequence
  435.  
  436.         P <ret> <ret>
  437.  
  438. to print a large section.
  439.  
  440. The 'V' command requests an expression and displays its value.
  441.  
  442. The 'W' command is used to set the number of bytes displayed on each
  443. line for the A, B, and D formats.  This is useful for displaying
  444. tables.  For example, when dis86 is executed without a file, it
  445. displays bytes starting at address 0000:0000 and the width is set to
  446. four so each interrupt vector is shown on a separate line.
  447.  
  448.  
  449. MENUBAR COMMANDS
  450.  
  451. Entering '/' or <space> brings up the main menubar, which has six
  452. choices.  One choice is highlighted.  An explanation for that choice,
  453. or a preview of a lower level menu, appears on the next line.  The left
  454. and right cursor keys will move the highlight.  You may execute the
  455. highlighted choice by typing <ret> or <down>, or any choice by typing
  456. its first letter.  You may leave a menubar without making a choice by
  457. typing <esc> or <up>.
  458.  
  459. At first, you will probably use the cursor keys and read the
  460. explanations for confirmation.  As you get more familiar with the
  461. commands, you will start typing sequences automatically.  For example,
  462. the sequence /FQ will exit the disassembler.
  463.  
  464. Here is the whole hierarchy of menubar commands:
  465.  
  466.         File
  467.            Clone     /FC   write current parameters into object file
  468.            Save      /FS   save symbol table to file
  469.            Load      /FL   load symbol table from file
  470.            Quit      /FQ   quit to DOS
  471.         Header       /H    display file header or disk parameters
  472.         Options      /O    change setup options
  473.         Colors
  474.            Normal    /CN   display colors for normal text
  475.            Highlight /CH   display colors for highlighted text
  476.            Windows   /CW   display colors for text in windows
  477.         Registers    /R    reset/select segment registers
  478.         Symbols            symbolic labels for addresses
  479.            Insert    /SI   insert new symbols
  480.            Delete    /SD   delete existing symbols
  481.            Edit      /SE   change names and/or addresses of symbols
  482.            List      /SL   list the symbols in the symbol table
  483.         ?            /?    display help screens
  484.  
  485. In this version, the Header, Options, Registers, and ? commands can
  486. also be executed as single letter immediate commands.
  487.  
  488. The Clone command is used to write the current values of these
  489. parameters into the disassembler object code:
  490.  
  491.         wild card byte in search pattern
  492.         data bytes per line for A, B, and D formats
  493.         processor code
  494.         bit mode (for 80386 code)
  495.         display colors 
  496.         immediate/delayed display format changes
  497.  
  498. This will make the current parameter values the default values for
  499. subsequent executions.  (One exception: when disassembling from memory,
  500. the bytes per line is always set to four so that the interrupt vectors
  501. in low memory are displayed one per line.) This command prompts for the
  502. name of the object code file, which should include the drive and
  503. directory unless the file is in the current directory or somewhere in
  504. the path.  Under DOS 3.0 or later, the disassembler determines its own
  505. path name and offers it as the default.
  506.  
  507. The Quit subcommand returns control to DOS.  If a change has been made to
  508. the disassembler buffer, the user is asked whether to write out the
  509. changes.
  510.  
  511. The Header command displays the .EXE file header information, or the
  512. organization of the disk in absolute disk address mode.  This
  513. information is also displayed on the initial program screen.
  514.  
  515. The Options command or <ins> (0 on the numeric pad) bring up menus for
  516. changing setup options and allow the user to reset the disassembly
  517. window.  Use <space> or <ins> to move to the next screen, or <esc> to
  518. return to disassembly.  To save options for the next disassembly, use
  519. the clone command (above).
  520.  
  521. In the first options menu, use the right and left cursor keys or <ret>
  522. to change the entries.  The first item shows the processor which is
  523. supposed to execute the code being disassembled.  There is some
  524. conflict in op codes between the V20 and V30 on one hand and the 80286
  525. and 80386 on the other.  That is, the two families use the same op
  526. codes for different instructions.  The processor you indicate on this
  527. menu will determine which instruction Dis86 shows.  In addition, it
  528. will flag instructions not implemented by the indicated chip.
  529.  
  530. The next item lets the user specify 16 or 32 bit mode for the 80386. 
  531. In the 16 bit mode the 80386 is similar to the 8086.  In the 32 bit
  532. mode arithmetic is performed in 32 bit registers and all address
  533. offsets are 32 bits.  The 80386 itself selects the mode based on a bit
  534. in the segment table entry for the code segment.  The program may also
  535. include prefix bytes which change the assumed operand size or address
  536. size for one instruction (66H and 67H respectively).  The disassembler
  537. recognizes these prefixes.
  538.  
  539. The next item indicates whether display format changes take effect
  540. immediately, or allow the user to enter an address as well.
  541.  
  542. The last item selects whether displayed output should be done through
  543. the BIOS or directly to the video hardware (much faster, and the
  544. default).
  545.  
  546. In the second options menu, change an entry by typing over it.  The
  547. first item is the byte value which matches anything in a byte or
  548. character search (the "wild card" byte).  The second is the number of
  549. bytes displayed on each line for the A, B, or D formats.  The latter
  550. value can also be set using the W command.  The last item is the
  551. assumed load address (see below).
  552.  
  553. By using the <ins> key to enter the options menu and to step from one
  554. menu to the next, you can leave your right hand on the numeric pad.
  555.  
  556. The Colors command sets the display colors for three classes of text:
  557. normal text, highlighted text (used in the menubar itself), and text in
  558. the Options, Registers, or Header windows.  Foreground and background
  559. colors can be set independently.
  560.  
  561. The Registers command is used to display and/or change the assumed
  562. segment register values.  Entries may be full expressions.  For
  563. example, to copy the value from SS into DS, enter
  564.  
  565.         /R
  566.         
  567. use the cursor keys to select the DS register and type
  568.  
  569.         ss <ret> <esc>
  570.  
  571. This menu also selects the current segment register: The segment
  572. register indicated by the cursor when you type <esc> will be used to
  573. calculate the displayed addresses.
  574.  
  575. The Symbol command allows you to enter symbolic names for addresses. 
  576. These names will be used in place of the numeric values both in the
  577. address column along the left side of the display and to indicate the
  578. destinations of jumps or calls.  Symbols are also displayed for some
  579. data references.  Unfortunately, many data references use index
  580. registers, and symbols will not be shown for these.  
  581.  
  582. A symbol longer than 40 characters will be silently truncated.  A
  583. symbol must consist of alphanumeric characters, and must start with an
  584. alphabetic character.  An underscore is treated as alphabetic.  
  585.  
  586. You can use symbols within expressions.  For example, if "boot" is
  587. defined as "ffff:0000", you can type
  588.  
  589.     G boot <ret>
  590.  
  591. to move the cursor there.  
  592.  
  593. It is a good idea to included at least one character in each symbol
  594. that cannot occur in a hexadecimal number.  If a token can be
  595. interpreted as either a symbol or a number, its definition as a symbol
  596. will take precedence.  If you were to define "a" as "3", then the
  597. expression "a-1" would have the value "2".  To enter the hexadecimal
  598. number "a" you would have to type "0a" or an expression like "9+1".
  599.  
  600. Use the Save subcommand under the File command to save the symbol table
  601. to a disk file, and the Load subcommand to read it back during some
  602. future disassembly.  The symbol table file is straight ASCII and can
  603. be edited.  You may add comments: any line beginning with a semicolon
  604. ';' will be ignored by the disassembler.
  605.  
  606. Type '?' to get a series of help screens.  Type <esc> to return to the
  607. disassembly, <pg up> or <pg dn> to select a screen, or any other key to
  608. advance to the next screen
  609.  
  610.  
  611. TYPING REQUESTED DATA
  612.  
  613. Many commands supply default entries for requested data.  If you decide
  614. to accept the default, just enter <ret>.  For editing entries, you can
  615. position the cursor using the left and right cursor keys to move by one
  616. character, <home> (7 on the numeric pad) to move to the left end of the
  617. string, or <end> (1 on the numeric pad) to move to the right end.  Use
  618. the <del> or <backspace> keys to delete incorrect characters, or just
  619. type characters to be inserted.  Type <ins> to toggle between insert
  620. and replace modes.
  621.  
  622. In every case but one, you can also edit the default entry by making
  623. <right>, <end>, or <del> your first keystroke.  The exception is the
  624. default for the byte search function.
  625.  
  626. In edit mode, the five active unshifted keys on the numeric pad are:
  627.  
  628. <home> start of string
  629.  
  630.  
  631. <--    left one char                              -->      right one char
  632.  
  633.  
  634. <end>  end of string 
  635.  
  636.  
  637.  <ins> insert/delete
  638.  
  639.  
  640. In addition, the shifted cursor keys move by word.  On the IBM:
  641.  
  642.         <ctrl><right>    next word
  643.         <ctrl><left>     previous word
  644.  
  645. On the Z-100:
  646.  
  647.         <shift><right>   next word
  648.         <shift><left>    previous word
  649.  
  650.  
  651. DISASSEMBLY WINDOW
  652.  
  653. The disassembler uses a buffer to hold the code being disassembled. 
  654. For most purposes, this disassembly window is transparent to the user. 
  655. If the user requests an address within the file but outside the
  656. disassembly window, the appropriate code is automatically read in.  The
  657. existence of the window is apparent in only two cases: 
  658.  
  659.     1.    If the disassembler is started near the end of the window 
  660.         and reaches the end before it fills the screen, the
  661.         rest of the screen will be left blank.
  662.  
  663.     2.    If the contents of the buffer has been changed (see 'E'
  664.         command) the user is asked whether they should be
  665.         written out before the buffer is overwritten or control 
  666.         is returned to DOS.
  667.  
  668.  
  669. LOAD ADDRESS
  670.  
  671. Code from a .COM file is displayed as though its Program Segment Prefix
  672. were at 0000:0000 and its load address were 0000:0100.
  673.  
  674. Code from a .EXE file is displayed as though its load address were
  675. 0000:0000.  This puts its Program Segment Prefix is 10 paragraphs or
  676. 100 (hex) bytes lower.  This is somewhat awkward, because the DS and ES
  677. registers are initialized to point to the PSP.  The disassembler
  678. displays this segment value as -10.  The advantage of a load address of
  679. 0000:0000 is that no relocation is necessary.  The bytes displayed are
  680. exactly the same as those in the file.  This also means that the code
  681. can be modified (see below for the 'E' command) and written back to the
  682. file without being "unrelocated".
  683.  
  684.  
  685. SEGMENTATION
  686.  
  687. Addresses are displayed in segment:offset form, using the current
  688. assumed value of the current segment register.  The current segment
  689. register can be selected using the 'S' command to step among the
  690. available registers (CS, SS, DS, ES, FS, and GS - the last two only
  691. with 80386 code).  Changing segment registers or their values does not
  692. move the disassembler cursor.  Only the displayed segment and offset
  693. values will change to reflect the new assumptions.  An appropriate
  694. segment value (that is, between 0 and 65535 bytes before the address
  695. being disassembled) will result in a legal offset which will be
  696. displayed as a four digit hex number (0000 to FFFF).  An inappropriate
  697. segment value will result in an offset outside this range (negative, or
  698. greater than 64K).  Such offsets will be calculated and displayed,
  699. although they are illegal on the 8086.  Illegal offsets will have more
  700. than four digits.
  701.  
  702. The segment register values are initialized as indicated in the file 
  703. header (for .EXE files) or to zero (for other files or RAM).  The 
  704. disassembler has no way of determining the values which may be set 
  705. during execution.  For example, the initialization code for DeSmet C 
  706. programs reset DS to the same value as the initial SS before executing 
  707. main().
  708.  
  709. The assumed segment register values can be altered in two ways.  When
  710. the right arrow key is used to follow a far call or jump, the new code
  711. segment value is loaded into the CS register.  In addition, any segment
  712. register can be changed using the register menu reached by the 'R'
  713. command.  (The same menu is used to indicate which register should be
  714. used for the disassembly display: leave the cursor pointing to the
  715. desired register before leaving the menu with <space> or <esc>.) When
  716. the user specifies a new segment value on a G command, that value is
  717. used for subsequent displays but none of the assumed segment register
  718. values is changed.
  719.  
  720. The segmentation models of the protected modes of the 80286 and 80386 
  721. are not supported.
  722.  
  723.  
  724. ALIGNMENT
  725.  
  726. Dis86 will correctly disassemble code if started on the first byte of an 
  727. instruction.  If started in the middle of an instruction, it will 
  728. disassemble that instruction and perhaps several more incorrectly.  In 
  729. this case the disassembler is said to be out of alignment with the 
  730. object code.  The disassembler will tend to correct its alignment if it 
  731. continues long enough.  8086 instructions tend to be longer than, for 
  732. example, those for the 8080, so the disassembler will tend to stay out 
  733. of alignment for more bytes.  Generally speaking, the alignment will be 
  734. correct after the first half dozen lines.
  735.  
  736.  
  737. SUMMARY
  738.  
  739. Here are all the single letter commands:
  740.  
  741. A           ASCII data
  742. B           byte date (hex)
  743. C           code (disassembly)
  744. D           data (hex and ASCII)
  745. E           enter new data (follow with a series of hex expressions)
  746. F           font
  747.  
  748. G nnnn      goto address nnnn
  749. H           display file header information (for .EXE files only)
  750. O           change setup options
  751. P           print disassembly listing to file
  752.  
  753. R           change segment register values
  754. S           start a search
  755. U           display as FAT entries
  756. V           evaluate an expression
  757.  
  758. W           width: set bytes of data per line for A, B, and D formats
  759. X           exchange current address (at top of screen) with top of stack
  760. ?           display help screens
  761. /           display the main menubar
  762.  
  763.  
  764. EXAMPLE 1
  765.  
  766. In the examples, <left>, <right>, <up>, and <down> refer to the four
  767. cursor keys (4, 6, 8, and 2 on the numeric pad, plus the four arrow
  768. keys on the Z-100 keyboard).  <pg up> and <pg dn> refer to the 9 and 3
  769. on the numeric pad.
  770.  
  771. To investigate the bootstrap code, type
  772.  
  773.     A>dis86 <ret>
  774.  
  775. and press
  776.  
  777.     <space>
  778.  
  779. to advance to the disassembly display, which will be a D (data) format 
  780. display of the interrupt vectors.  Next type
  781.  
  782.     C G ffff:0000 <ret>
  783.  
  784. (for Code format at the Address ffff:0000).  On an IBM, the ROM release 
  785. date and machine ID appear in the last 16 bytes of the ROM.  To see
  786. them, type
  787.  
  788.     D
  789.  
  790. The release data is at addresses ffff:0005 - ffff:000c in ASCII.  The 
  791. machine ID is at ffff:000e.  Some of the possible values are:
  792.  
  793.     ff    IBM PC
  794.     fe    IBM XT and Portable IBM PC
  795.     fd    IBM PCjr
  796.     fc    IBM AT
  797.     2d    Compaq
  798.     9a    Compaq-Plus
  799.  
  800. Return to code format by typing
  801.  
  802.     C
  803.  
  804. One of the instructions displayed should be a jump.  If so, press
  805.  
  806.     <down>
  807.  
  808. enough times to bring the jump to the top line, then
  809.  
  810.     <right>
  811.  
  812. to follow the jump.  Note that the previous addresses were pushed onto 
  813. the stack, as shown on the bottom line.  To return to the most recent 
  814. address, press
  815.  
  816.     <left>
  817.  
  818. To leave the disassembler, press
  819.  
  820.     /FQ
  821.  
  822.  
  823. EXAMPLE 2
  824.  
  825. For a second example, let us disassemble the disassembler itself.  Begin 
  826. by typing
  827.  
  828.     A>dis86 dis86.exe <ret>
  829.  
  830. Note the header information, including the entry point of 0000:0000 and 
  831. the initial stack location of approximately 09e0:9eb8.  Proceed to the 
  832. disassembly screen by typing
  833.  
  834.     <space>
  835.  
  836. The disassembler starts in C (code) format at the entry point, which is 
  837. a jump to the initialization code.  To follow the jump, type
  838.  
  839.     <right>
  840.  
  841. One of the early instructions in the initialization code refers to the 
  842. first location in the stack segment.  Bring this location to the top of 
  843. the screen by typing
  844.  
  845.     <pg dn> <down> <down>
  846.  
  847. and follow the reference by typing
  848.  
  849.     <right>
  850.  
  851. Since it was a data reference, the disassembler automatically switched 
  852. to D (data) format.  Also, the addresses are displayed using the value 
  853. of segment register SS.  Note that the two previous addresses have been 
  854. pushed onto the stack, as shown at the bottom of the screen.  Return to 
  855. the initializing code by typing
  856.  
  857.     <left>
  858.  
  859. The initialization code gets rather involved, but one of its functions
  860. is to initialize DS to the same value as SS.  To reflect this, use the
  861. R command:
  862.  
  863.     R
  864.  
  865. DS is the first register in the list.  You need only move the cursor to
  866. that register and enter the appropriate value:
  867.  
  868.     ss <ret>
  869.  
  870. We will be disassembling code, so CS should be used to generate the
  871. displayed adresses.  To ensure this, leave the cursor pointing to CS
  872. before leaving the menu with
  873.  
  874.     <esc>
  875.  
  876. The code for the main program immediately followed the jump at 
  877. 0000:0000.  To return there, type
  878.  
  879.     <left>
  880.  
  881. Send a copy of this screen to the file "printout" by typing
  882.  
  883.     P <ret> <ret> <ret>
  884.  
  885. To inspect the data segment, type
  886.  
  887.     A G ds:0 <ret>
  888.  
  889. To display more characters on each line, use the W command:
  890.  
  891.     W 60 <ret>
  892.  
  893. Use the search command to find one of the messages:
  894.  
  895.     S T hime <ret>
  896.  
  897. This string won't be found.  To correct the spelling to "home" and try 
  898. again, type
  899.  
  900.     S T <right> o <ret>
  901.  
  902. Once again, leave the disassembler by pressing
  903.  
  904.     /FQ
  905.  
  906.  
  907. EXAMPLE 3
  908.  
  909. The third example will show how the disassembler can be used to
  910. undelete a disk file.  Begin by creating and deleting a short text file
  911. using redirection from the DOS prompt:
  912.  
  913.     A>type con >patriot.1
  914.     Now is the time for all good men to come to the aid of their country.<ret>
  915.     <ctrl-Z> <ret>
  916.  
  917.     A>copy patriot.1 patriot.2
  918.     A>erase patriot.1
  919.  
  920. Now, start the disassembler by typing
  921.  
  922.     A>dis86 a:
  923.  
  924. The disassembler first shows the disk header information, which for a
  925. 360 K floppy disk looks like this:
  926.  
  927.  
  928. Drive information for A:
  929.                FD media descriptor byte
  930.       200H =  512 bytes/sector
  931.       400H = 1024 bytes/cluster
  932.               354 clusters, or 362496 bytes, for disk files
  933. Sector    Offset (hex)    Length (sectors)
  934.     0           0                 1           BIOS parameters and boot code
  935.     1         200                 2           FAT 1
  936.     3         600                 2           FAT 2
  937.     5         a00                 7           root directory with 112 entries
  938.    12        1800                 2           cluster 2
  939.   718       59c00                 2           cluster 355 (last)
  940.  
  941.  
  942. Note in particular the byte offsets of 200 to the first FAT and a00 to
  943. the root directory, and the cluster size of 400.  Proceed to the first
  944. disassembly screen by typing
  945.  
  946.     <space>
  947.  
  948. The disassembler starts in D (data) mode at the first sector, which is
  949. the boot sector.  Now type
  950.  
  951.     D G a00
  952.  
  953. to show the disk directory and
  954.  
  955.     W 8
  956.  
  957. to set the display width to 8.  Each directory entry takes four
  958. lines:
  959.  
  960. 0000:0CA0      47 4c 49 20 20 20 20 20 |GLI     |
  961. 0000:0CA8      43 20 20 20 00 00 00 00 |C   ....|
  962. 0000:0CB0      00 00 00 00 00 00 65 79 |......ey|
  963. 0000:0CB8      5b 0f 6d 00 cd 2f 00 00 |[.m.M/..|
  964.  
  965. The fields in each entry are as follows:
  966.  
  967.                47 4c 49 20 20 20 20 20 |GLI     |
  968.      file name ^^^^^^^^^^^^^^^^^^^^^^^ 
  969.  
  970.                43 20 20 20 00 00 00 00 |C   ....|
  971.      extension ^^^^^^^^
  972.               attribute ^^
  973.                   reserved ^^^^^^^^^^^
  974.  
  975.                00 00 00 00 00 00 65 79 |......ey|
  976.       reserved ^^^^^^^^^^^^^^^^^
  977.                             time ^^^^^
  978.  
  979.                5b 0f 6d 00 cd 2f 00 00 |[.m.M/..|
  980.           date ^^^^^ 
  981.     starting cluster ^^^^^
  982.         file size in bytes ^^^^^^^^^^^
  983.  
  984. It's the file name and the last two fields we'll be concerned with.
  985. Search for the files we just created using a wild card as the first search
  986. byte:
  987.  
  988.     G S ff "ATRIOT" <ret>
  989.  
  990. Here, the text string must be typed in upper case.  The display should
  991. resemble this:
  992.  
  993.     0000:0B00      e5 41 54 52 49 4f 54 20 |eATRIOT |
  994.     0000:0B08      31 20 20 20 00 00 00 00 |1   ....|
  995.     0000:0B10      00 00 00 00 00 00 0d a4 |.......$|
  996.     0000:0B18      8c 0f a2 00 47 00 00 00 |..".G...|
  997.     0000:0B20      50 41 54 52 49 4f 54 20 |PATRIOT |
  998.     0000:0B28      32 20 20 20 00 00 00 00 |2   ....|
  999.     0000:0B30      00 00 00 00 00 00 0d a4 |.......$|
  1000.     0000:0B38      8c 0f a3 00 47 00 00 00 |..#.G...|
  1001.     0000:0B40      00 e5 e5 e5 e5 e5 e5 e5 |.eeeeeee|
  1002.     0000:0B48      e5 e5 e5 e5 e5 e5 e5 e5 |eeeeeeee|
  1003.     0000:0B50      e5 e5 e5 e5 e5 e5 e5 e5 |eeeeeeee|
  1004.  
  1005.  
  1006. In deleting PATRIOT.1, the ONLY change DOS made to the directory entry
  1007. was to replace the first byte of the file name by hex e5 (a lower case
  1008. 'e' with the high order bit set).  Looking at the third and fourth
  1009. bytes of the last line, we see that the file started at cluster a2. 
  1010. From the next four bytes, we learn that the file had length 47 (hex)
  1011. bytes.  This is less than the cluster size of 400, so the file had only
  1012. one cluster.  Note that PATRIOT.2 has the same length, and starts at
  1013. cluster a3.
  1014.  
  1015. To examine the initial cluster of the file, type
  1016.  
  1017.     H
  1018.  
  1019. to display the header information.  Note that clusters have length 400
  1020. and that cluster 2 starts at offset 1800.  Switch to ASCII format and
  1021. go to the beginning of the file by typing
  1022.  
  1023.     <ret>
  1024.     A G 1800+(a2-2)*400
  1025.  
  1026. The display should look like this
  1027.  
  1028.     0000:29800     |Now is t|
  1029.     0000:29808     |he time |
  1030.     0000:29810     |for all |
  1031.     0000:29818     |good men|
  1032.     0000:29820     | to come|
  1033.     0000:29828     | to the |
  1034.     0000:29830     |aid of t|
  1035.     0000:29838     |heir cou|
  1036.     0000:29840     |ntry... |
  1037.     0000:29848     |DOC ....|
  1038.     0000:29850     |.......5|
  1039.     0000:29858     |..:.Og..|
  1040.     0000:29860     |DIS86Z  |
  1041.  
  1042. The file information is present, although there appears to be some
  1043. garbage following it.
  1044.  
  1045. Each cluster has an entry in the File Allocation Table, or FAT.  When a
  1046. file is deleted, its clusters are marked as "free" by zeroing the
  1047. corresponding entries in the FAT.  Display the beginning of the FAT by
  1048. typing
  1049.  
  1050.     U G 200
  1051.  
  1052. To move to the FAT entry for cluster a2, type
  1053.  
  1054.     G A $+(a2*3)/2
  1055.  
  1056. (Recall that '$' stands for the current location.) In my case, the
  1057. display starts
  1058.  
  1059.     0000:02F3      000 fff 000 000
  1060.     0000:02F9      000 000 000 000
  1061.  
  1062. The second entry, which corresponds to cluster a3 of PATRIOT.2, has the
  1063. code for "last cluster".  The first entry, which corresponds to cluster
  1064. a2, is still zero so that file can be "undeleted".  To do that, we
  1065. change the entry to the value for "last cluster":
  1066.  
  1067.     E fff <ret>
  1068.  
  1069. We have to make the same change in the other copy of the FAT.  Recall
  1070. that each FAT is 400 (hex) bytes long:
  1071.  
  1072.     G $+400 <ret>
  1073.     E fff <ret>
  1074.  
  1075. To return to the directory entry type
  1076.  
  1077.     <left> <left> <left> 
  1078.  
  1079. At this point the disassembler must move its window so it asks our
  1080. permission to write the changes to the disk:
  1081.  
  1082.     Y <ret>
  1083.     <left> 
  1084.  
  1085. Now, restore the first byte of the filename:
  1086.  
  1087.     E 'P' <ret>
  1088.  
  1089. To leave the disassembler (and agree to write the directory change
  1090. out), type
  1091.  
  1092.     /FQ Y <ret>
  1093.  
  1094. To confirm that both files exist, ask for a directory listing
  1095.  
  1096.     A>dir pa*
  1097.  
  1098.  
  1099. NOTES
  1100.  
  1101. When there is more than one cluster in a file, the directory entry
  1102. contains the number of the first cluster.  The FAT entry corresponding
  1103. to the first cluster contains the number of the second cluster.  This
  1104. chain of cluster numbers continues, with the FAT entry for the last
  1105. cluster containing fff.  DOS often allocates all the clusters together
  1106. (making the file contiguous).  For example, in this fragment of a FAT
  1107.  
  1108.     0000:03CE      135 136 137 fff
  1109.     0000:03D4      139 fff 13b 13c
  1110.     0000:03DA      fff 13e 13f 143
  1111.  
  1112. there seems to be a file occupying the two clusters 138 and 139, and a
  1113. second file occupying the three clusters 13a, 13b, and 13c.  I say
  1114. "seems" because it is not obvious from just this printout that cluster
  1115. 138 (whose entry at 03d4 contains the pointer to 139) is actually the
  1116. first cluster of a file.  Only LAST clusters are explicitly marked in
  1117. the FAT.  To confirm that it is indeed the first cluster of a file, we
  1118. could search the rest of the FAT and verify that there was no pointer
  1119. to 138, or we could find the pointer to 138 in some directory entry.
  1120.  
  1121. Longer files are more trouble to unerase, but of course are also more
  1122. valuable.  To calculate the length in clusters for a longer file we
  1123. would use the V (evaluate) function.  For example, for a 1345 byte file
  1124. type:
  1125.  
  1126.     V 1345/400 <ret>
  1127.  
  1128. The answer, 3, is the number of full clusters.  Remember to add one for
  1129. the partially filled cluster at the end.  If there were four clusters
  1130. in the file in the file you want to undelete, then there will be zeros
  1131. in the four corresponding entries in the FAT.  The directory tells you
  1132. only where the first entry is.  The other three entries could be
  1133. literally anywhere else in the FAT, but since DOS assigns the next
  1134. available cluster to a growing file, they can probably be found shortly
  1135. after the first entry.  Even if you find four zero entries in a row
  1136. starting there, some of those free clusters could have belonged to some
  1137. other deleted file.  You still need to check the data in the clusters
  1138. to be sure.
  1139.  
  1140.