home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / FILE / ANA015.ZIP / ANA.DOC next >
Encoding:
Text File  |  1990-09-17  |  15.6 KB  |  351 lines

  1.  
  2.  
  3. I had developed an utility that had been extremely useful in my last few years
  4. as a software developer. I would like to share it with you now. However I don't
  5. know a good way to distribute binaries. I have include here a user guide and if
  6. any of you are interested, let me know how to send it to you.
  7.  
  8. ANA Command summary
  9. Prepared by: Paul C. Tam
  10. For Version 0.15
  11. Published on 24 July 1990
  12.  
  13.     I was rushing to finish this document, some parts may be confusing. I
  14.     appreciate any comment or enhancement of this document. This version of
  15.     ANA are free, please feel free to copy.
  16.  
  17. 0   HIGHLIGHTS
  18.  
  19.     * Interpret binary data in structures YOU defined.
  20.     * Rearrange data bytes before interpretation.
  21.     * Report current machine data types.
  22.     * Dump binary data in very flexible format.
  23.     * Dump multiple files in same screen.
  24.     * Same user interface across various platforms.
  25.     * Built in calculator/converter.
  26.     * Save output to disk to future use.
  27.     * Search for patterns.
  28.     * Execute Operating System command with exit utility.
  29.     * And more......
  30.  
  31.  
  32. 1   INTER-OPERABILITY
  33.  
  34.     Inter-operational seems to be a hot buzzword these days. This software will
  35.     do just that. Since the software is extremely portable, there are versions
  36.     running on almost any operating system that has a C compiler. They have
  37.     exactly the same look and feel across all platforms.
  38.  
  39. 2   Introduction
  40.  
  41.      ANA is an utility program to assist users (especailly software developer)
  42. who are interested in ANAlyzing the binary contents of any file. This program
  43. may be easier for users who know C since the terminology used here is C like.
  44.      Its major function is primarily to display the hexadecimal contents of any
  45. file interactively. On top of it, there are a lot of features built in to make
  46. this utility more flexible and useful. Some of these features include: able to
  47. dump the display buffer into a file, set the display length and base, pack the
  48. display and search for combination of bytes (search has not yet been built).
  49.      An unique feature of this utility is perhaps its ability to analyze
  50. certain structure. This feature is especially geared for software developers.
  51. Sometimes data files are an array of records, each record contains information
  52. of different types. For example, the data file maybe a control file of a print
  53. queue. There are a number of records in there to represent the number of files
  54. waiting to be printed. Each record in turns contains different fields, these
  55. fields may indicate the file name to be printed, its priority and so on. They
  56. may have data type of character (1 byte), integer (2 or 4 bytes) and ASCII
  57. string.
  58.      Using ANA, user can create an ASCII file in which the structure is defined.
  59. ANA then maps the data file into the structure and intreprets them as a series
  60. of fields instead of a string of bytes.
  61.  
  62. 3    How to invoke ANA
  63.  
  64.      ANA can be invoked in any one of the following ways:
  65.  
  66.      1) ANA
  67.      2) ANA <data_file_name>
  68.      3) ANA <data_file_name> <start_address> <length_of_buffer>
  69.  
  70. 4    Inputs
  71.  
  72.      Inputs can be of form hexidecimal, decimal or ascii. Numerical inputs are
  73.      interpreted according to the default base, however they can be overridden
  74.      by a prefix. Any input prefixed by 0x are always hex no matter what the
  75.      current default state is and any input prefixed with \ are always decimal.
  76.      Single ascii character must be between single quotes, ascii string,
  77.      however, must be between a pair of delimitor which can be any characters.
  78.      e.g. command s strings is the same as command s 'tring', they both search
  79.      for "tring".
  80.  
  81. 5    Report
  82.  
  83.      Unpacked -
  84.  0x00000000: 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F |................|
  85.  0x00000010: 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F |................|
  86.  
  87.      Packed -
  88.  000102030405060708090A0B0C0D0E0F
  89.  101112131415161718191A1B1C1D1E1F
  90.  
  91.      The report format is fairly flexible. Report address, report data can be in
  92. either hexadecimal or decimal. The above format can vary depends on a
  93. number of parameters, these parameters can be set by various commands. However,
  94. the following are the default parameters unless otherwise overridden by their
  95. corresponding commands.
  96.  
  97.      Parameters     Defaults       Commands
  98.      Pack Mode      Unpacked       p (packed)
  99.      Address Base   Hexadecimal    b a (base)
  100.      Data Base        Hexadecimal       b d 
  101.      Buffer size    240 bytes      l (length)
  102.      Report width   16 bytes       w (width)
  103.      Start address  0              a (address)
  104.  
  105.  
  106. 6    Command Descriptions
  107.  
  108.      6.1  ? - Help
  109.           Display a brief description of commands available. This is useful for
  110.           commands review.
  111.  
  112.      6.2  ENTER - Display next buffer
  113.           Data is read from file into the data buffer and displayed. Then the
  114.           next starting address is updated so that the next ENTER will display
  115.           the following data.
  116.  
  117.      6.3  l - Set new buffer length
  118.           Define the size of the data buffer on the next display.
  119.  
  120.      6.4  a - Set new starting address
  121.           Define a new starting address of the data file rather than the
  122.           continuation of the last display buffer.
  123.  
  124.      6.5.1  b a - Toggle report address base
  125.           In the unpack mode, the address of the first byte of each report line
  126.           is shown. This address can be of base hexadecimal or decimal. This
  127.           command toggle the base.
  128.  
  129.      6.5.2  b d - Toggle report data base
  130.           Data reported can be of base hexadecimal or decimal. This command
  131.       toggle the base.
  132.  
  133.      6.5.3  b i - Toggle input base
  134.           All numerical inputs are interpreted on the current default base, this
  135.       command toggle the base. However, inputs prefixed with 0x are always 
  136.       interpreted as hex and inputs prefixed with \ are always decimal.
  137.  
  138.      6.6  c - Calculator functions
  139.           Sometimes it is necessary to do some arithmatic operations on the data
  140.           displayed. A simple set of arithmatic functions are available in ANA.
  141.           Currently, the calculator can only do integer arithmatic and is
  142.           limited to two operands and one operator (with only one exception for
  143.           conversion). The syntax of this command is the command keyword
  144.           followed by the operation followed by an ENTER. The following are
  145.           examples and descriptions of all available operations. Suppose X and
  146.           Y are two integers.
  147.  
  148.                c X * Y   ( X multiply Y )
  149.                c X / Y   ( X divided by Y )
  150.                c X + Y   ( X plus Y )
  151.                c X - Y   ( X minus Y )
  152.                c X % Y   ( reminder of X divided by Y )
  153.                c X & Y   ( X bit and with Y )
  154.                c X | Y   ( X bit or with Y )
  155.                c X ^ Y   ( X bit xor with Y )
  156.                c X > Y   ( X right shift Y bits )
  157.                c X < Y   ( X left shift Y bits )
  158.                c X       ( X can be hex, decimal or ASCII )
  159.  
  160.  
  161.      6.7  d - Download structure description file
  162.           Each structure description file maps only one structure, sometimes it
  163.           is desirable to map data to a different structure. This command loads
  164.           another descritpion file for the next mapping.
  165.      6.8  D - continuously dump
  166.       The whole work file starting at current location will be displayed 
  167.       continuously until the end of the file.
  168.  
  169.      6.9  i - information desk
  170.       This command display valuable information. Information includes the
  171.           data types in bytes of current machine, current work file name,
  172.           number, size, maximum work file allowed to open, number of work file
  173.           currently opened and the user input base, report data base and report
  174.           address base. Also the mapping alignments (read m command).
  175.  
  176.      6.10 m - Map data to structure
  177.           Maps the data in the data buffer just displayed into the structure
  178.           described by the SDF. Mapping currently starts at the beginning of
  179.           the data buffer, therefore user may have to adjust the starting
  180.           address before the mapping.
  181.       Data type will normally be aligned in a structure. For example, a
  182.           'short' after a 'char' will be put in even boundary and the byte after
  183.           the 'char' is meaningless. This utility will allow user to specify its
  184.           alignment boundary. The arguments are i for int, l for long, f for
  185.           float and d for double. Their defaults values are displayed in
  186.           information desk ('i'). 
  187.  
  188.      6.11 o - open another work file
  189.       More than one file can be worked on, this command open another work
  190.           file.
  191.  
  192.      6.12 p - Toggle packed display mode
  193.           As discussed above, report format can be either packed or
  194.           unpacked, this command toggle this format.
  195.  
  196.      6.13 q - Quit analyzer
  197.           Terminate and exit program.
  198.  
  199.      6.14 s - search for a pattern
  200.       a pattern is searched starting at current location. The pattern can be
  201.       a series of hex or decimal number, or an ascii string in a pair of
  202.       delimiters.
  203.  
  204.      6.15 t - Transfer data buffer to disk
  205.           It is possible to store the buffer just displayed into a disk file,
  206.       using this command will do just that. At the first execution of this
  207.           command, the user will be prompted for the disk file name unless it is      entered with the command. Any subsequent transfer will be appended to
  208.           the named file and any file name entered in the command line will be
  209.           ignored.
  210.  
  211.      6.16 u - use a different work file
  212.       If there are multiple work files opened (read o command), this command
  213.           is used to switch to a different work file.
  214.  
  215.      6.17 V - Display current version
  216.           This command displays the current version of the software and
  217.           copyright message.
  218.  
  219.      6.18 w - Set display row width
  220.           Especially after changing to packed display format from unpacked
  221.           format, usually it is desirable to display more data in one line. This
  222.           command allows user to adjust the display width. 
  223.  
  224.      6.19 z - zap old data with new data
  225.       Be care when using this command, it will replace the old data at
  226.           current location with the new data. There is no recovery from it. Data
  227.       like 's' command can be hex, decimal or ascii.
  228.  
  229.      6.20 ! - OS escape
  230.       Run a regular Operating System command.
  231.  
  232.      6.21 0 - Redisplay buffer
  233.           Sometimes data may be scrolled off the screen, this command will
  234.           redisplay data that was just displayed.
  235.  
  236.      6.22 + - report the next display buffer
  237.  
  238.      6.23 - - report the previous display buffer.
  239.  
  240.  
  241. 7    Structure mapping
  242.  
  243.      Mapping structure is one of the unique feature in this software. Rather
  244.      than just dumping the data file in bytes, user can define a structure
  245.      definition file (hereon called SDF) from which the data can be intrepreted
  246.      in a more flexible way. The SDF is a pure ASCII file in which each line
  247.      represents one data field and the whole file together defines a structure
  248.      to be mapped.
  249.  
  250.      The way to use this feature is of the following steps:
  251.      First, the SDF is created through any editor, this file must be named
  252.      "ana.fmt".
  253.      Second, display the beginning of the data structure by change the start
  254.      address and hit ENTER.
  255.      Finally, activate the mapping command to map the data buffer.
  256.  
  257.      Each line in the SDF represents one data type field, every line has the
  258.      following format:
  259.  
  260.      keyword user_defined_id [length/byte_arrangement]
  261.  
  262.      All types except "string" the third optional field is for byte rearrange-
  263.      ment. In case of data type string, a length field has to be specified
  264.      to indicate how many bytes are in the string. The user defined name is used
  265.      to assist user to identify the field, its content is arbitrary and is
  266.      limited to 20 characters. Name more than 20 characters will be truncated.
  267.  
  268.      The keywords currently supported are:
  269.  
  270.           int       signed interger
  271.           char      single character (byte)
  272.           string    string of characters
  273.           long      long signed integer
  274.           short     short signed integer
  275.           ulong     unsigned long integer
  276.           ushort    unsigned short integer
  277.           uint      unsigned integer
  278.           float     floating point number
  279.           double    double floating point number
  280.  
  281.      To allow more flexibility, it is also possible to interactively download
  282.      a new SDF so that more than one structure can be analyzed in a data file.
  283.  
  284.      EXAMPLE:
  285.      Suppose there is a file of employee records, each record starts with an
  286.      employee name of 10 characters, then an employee number of type long,
  287.      followed by his salary which is of type integer. Let's further assume that
  288.      integer is two bytes and a long integer is four bytes. Instead of just
  289.      dumping the data file in bytes, it is more useful to dump them in a more
  290.      descriptive form, in this case a string, a long integer and an integer.
  291.      SDF should look like this:
  292.  
  293.           string employee_name 10
  294.           long employee_no.
  295.           int  employee_salary
  296.  
  297.      When the ANA utility is executed, ANA detects the existance of the SDF,
  298.      it will then build the internal structure and enable the mapping facility.
  299.      User can display the portion of data that needs to be analyzed, and then
  300.      activates the mapping command, the display may look something like:
  301.  
  302.           employee_name = (John Doe  )
  303.           employee_no. = 999999 (0xF423F)
  304.           employee_salary = 5000 (0x1388)
  305.  
  306.      Notice that the string is shown inside a pair of paranthesis. The integers
  307.      are shown in decimal and have their corresponding hexadecimal values.
  308.  
  309.      User should be aware that computer always put data into their corresponding
  310.      type boundary. For example, for a machine that uses a two byte integer, a
  311.      structure like
  312.           structure {
  313.                character A;
  314.                integer 1;
  315.           }
  316.           may be stored as follow:
  317.                41 XX 00 01
  318.                    or
  319.                41 00 01
  320.  
  321.      In the first case, the character falls in the even boundary, since the
  322.      integer has to start also at the even boundary, there is a garbage byte in
  323.      between which does not mean anything. While in the second case, the
  324.      character falls in the odd boundary and therefore the integer can be put
  325.      right after the character.
  326.  
  327.      For the same reason, sometimes it is very confusing to just look at the
  328.      data byte by byte. It is better off to use the structure mapping.
  329.  
  330.      Furthermore, different CPUs have different characteristics. Some align
  331.      integer and long into even boundary while other might align integer in even
  332.      boundary and long in 4 byte boundary. This software will allow user to
  333.      customize the alignment. Command m [i/l/f/d] specify the alignment of the
  334.      data type used in structure mapping.
  335.  
  336.      To make life harder, some CPU swap bytes (our beloved 80x86 architecture)
  337.      and some don't. The third optional field in the format file are just for
  338.      that. It specifies the data rearrangement sequence. For example, an integer
  339.      made of 4 bytes is stored in a file as 0x11 0x22 0x33 0x44 (0x011223344),
  340.      a line in the format file:
  341.          int sample 
  342.      yields an output of
  343.          sample = 287454020 (0x11223344)
  344.      but if the format file is written as:
  345.          int sample 4321
  346.      the output will be
  347.          sample = 1144201745 (0x44332211)
  348.  
  349.      This feature is really useful if for example, someone tries to dump a file
  350. created in a 68000 machine in a 8086 machine.
  351.