home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / FILUTL / P22V12.ZIP / PATCH22.DOC < prev    next >
Encoding:
Text File  |  1991-08-08  |  14.9 KB  |  371 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.                               PATCH22
  11.  
  12.  
  13.                      version 1.2  (8 August 1991)
  14.  
  15.                           Jurgen A. Doornik
  16.  
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.     1. Introduction.
  26.     ___________________________________________________________________
  27.  
  28.     PATCH22 can be used to make patches to any file. The main
  29.     advantage is that it gives a format to distribute patches. You
  30.     can avoid detailed description of DEBUG commands. Instead you
  31.     just supply PATCH22 with the patch in a *.P22 file.
  32.     PATCH22 can also accept patches on the command line.
  33.     Patches have a C-like character constant format, making
  34.     it easy to enter hexadecimal values. PATCH22 will show the
  35.     context of the patch, but can work silently as well.
  36.     PATCH22 is written in C (source code provided), and faster than
  37.     many other public domain patch programs.
  38.     PATCH22 is written by Jurgen Doornik.
  39.  
  40.     The disk (or archive) should contain the following files:
  41.  
  42.        PATCH22.C     - source code (MSC 6.0)
  43.        PATCH22.DOC   - this documentation
  44.        PATCH22.EXE   - executable file.
  45.        *.P22         - patch files (if any).
  46.  
  47.     If you have any suggestions for improvement, or find any bugs,
  48.     please report them to me, via email:
  49.  
  50.        BITNET/EARN: ECONZ@UK.AC.OX.VAX
  51.  
  52.     or by mail:
  53.  
  54.     Jurgen Doornik
  55.     Institute of Economics and Statistics
  56.     St Cross Building, Manor Road
  57.     Oxford OX1 3UL
  58.     United Kingdom
  59.  
  60.     Special thanks are due to Arjen Merckens, who spotted many bugs and
  61.     gave useful suggestions. Needless to say that all remaining errors
  62.     are mine.
  63.     Arjen is author of BOOTCOMP.zip: a package which uses the original
  64.     BIOS interrupts to detect ANY changes to the bootsector [possibly]
  65.     made by a virus. He also wrote ACD (ChDir FAST; more features than
  66.     LCD/NCD and free).
  67.  
  68.  
  69.     2. How to execute PATCH22.
  70.     ___________________________________________________________________
  71.  
  72.     PATCH22 can accept patches on the command line or from a file.
  73.  
  74.  
  75.     2.1 Command line patch.
  76.     _______________________
  77.  
  78.     form:   PATCH22 fname patch
  79.     fname   - file to be patched
  80.     patch   - patch command: +##*##si?search_text?new_text?
  81.  
  82.     If the patch line on the command line contains spaces, it must be
  83.     enclosed in double quotes.
  84.  
  85.     examples:
  86.     PATCH22 test.exe ?abc?cde?         replace (with confirmation)
  87.                                        every occurrence of abc with cde.
  88.     PATCH22 test.exe "?a c?c e?"       replace (with confirmation)
  89.                                        every occurrence of a c with c e.
  90.  
  91.     If in the last example the double quotes are omitted, PATCH22 will
  92.     think that the patch is ?a, and tell you that it expects a ?.
  93.  
  94.     2.2 Command file patch.
  95.     _______________________
  96.  
  97.     form:   PATCH22 @fname
  98.     @fname  - file with (multiple) PATCH22 commands, with format:
  99.               fname  +##*##si?Search_text?New_text?
  100.  
  101.     If the patch command is in a file, line breaks in the Search_text
  102.     and New_text are ignored.
  103.  
  104.     example:
  105.  
  106.         PATCH22 @test.p22
  107.  
  108.     where test.p22 looks like:
  109.         ; comment lines start with a semi colon.
  110.         test.exe ?a c?c e?
  111.         ; line breaks in the Search_text and New_text are ignored:
  112.         test.exe ?a cdd?c edd?
  113.         ; equals
  114.         test.exe ?a cd
  115.         d?c ed
  116.         d?
  117.         ; note that no double quotes are used here.
  118.  
  119.  
  120.     3. The patch command.
  121.     ___________________________________________________________________
  122.  
  123.     form:    +##*##si?Search_text?New_text?"
  124.     syntax:  patch = Conditions "?" Search_text "?" New_text "?".
  125.  
  126.     The syntax reads as follows:
  127.     "a"    indicates a literal text a.
  128.     [b]    indicates an optional item b.
  129.     {c}    indicates one or more occurences of c.
  130.     d|e    indicates either d or e.
  131.  
  132.     3.1 The Conditions.
  133.  
  134.     syntax: Conditions     = [Offset][Max_#_patches][Silent_mode].
  135.               Offset       = ["+"] long | "-" long.
  136.               Max_#_patches= "*" int.
  137.                 long       = ["0"] ["x" | "X"] digit {digit}.
  138.                 int        = ["0"] ["x" | "X"] digit {digit}.
  139.               Silent_mode  = "s".
  140.               Ignore_case  = "i".
  141.  
  142.     The Offset is a signed long integer, while the maximum number of patches
  143.     is a * followed by an unsigned integer. These integers can be decimal,
  144.     hexadecimal (leading 0x or 0X) or octal (leading 0).
  145.     An s indicates silent mode. Each number is read up to the first character
  146.     which is not part of it.
  147.     An i indicates case insensitive searching. The search string is converted
  148.     to uppercase, so comparosion is mad in uppercase. The default is case
  149.     sensitivity.
  150.     The Conditions field can be empty, in which case the Offset is zero,
  151.     every patch has to be confirmed, and there is no maximum number of
  152.     patches.
  153.  
  154.     examples: 0x131d       Offset is 131d (hexadecimal), no maximum
  155.                            number of patches.
  156.               +0177*12     Offset is 177 (octal), not more than 12 patches.
  157.               +177*12      Offset is 177 (decimal), not more than 12 patches.
  158.               *1s          Zero Offset, one patch, silent mode (no prompt for
  159.                            confirmation of patch).
  160.               *09?n?n?     The 0 in the Max_#_patches field indicates an octal
  161.                            number, but 9 is not octal, so scanning stops and
  162.                            a 0 is read. The 9 then is interpreted as the
  163.                            Offset. However a request of 0 patches generates
  164.                            an error message.
  165.  
  166.     3.2 The Search_text and New_text.
  167.     _________________________________
  168.  
  169.     syntax: Search_text    = [ {chars | escape_code} ].
  170.               escape_code  = "\a" | "\b" | "\f" | "\n" | "\r" | "\t" | "\v"
  171.                            | "\\" | "\?" | "\'" | "\""
  172.                            | "\" octal [octal [octal]]
  173.                            | "\x" hex [hex]
  174.                            | "\w" hex [hex [hex [hex]]]
  175.                            | "\h" hex hex {hex hex}.
  176.             New_text       = Search_text.
  177.  
  178.     The text is a C-type character constant. It may contain the C
  179.     escape codes
  180.     \a (07h), \b (08h), \f (0Ch), \n (0Ah), \r (0Dh), \t (09h), \v (0Bh);
  181.     or
  182.     \###   (octal byte, not more than 3 digits);
  183.     \x##   (hexadecimal byte, not more than 2 digits).
  184.     \w#### (hexadecimal word, not more than 4 digits).
  185.     The characters \ ? ' " must be written as: \" \\ \? \' \".
  186.     An additional escape code is \h, which indicates that the rest of the
  187.     text (up to the question mark which indicates the end) consists
  188.     of two-digit hexadecimal numbers.
  189.  
  190.     examples: \h0d0a00       three hexadecimal numbers:
  191.                              carriage return, line feed, null character.
  192.               \r\n\0         the same three characters, in escape codes,
  193.                              (note that \0 is an octal number).
  194.               «gr_»          literal text.
  195.               \x1\xa\wb000   two bytes and one word: 01h 0Ah B000h
  196.                              (since on IBM PC's low order byte comes before
  197.                              hi order byte this is written as 01h 0Ah 00h B0h)
  198.  
  199.     3.3 How the patch is executed.
  200.     ______________________________
  201.  
  202.     Assume non-silent mode (default).
  203.  
  204.     First PATCH22 locates the search string. If the search string is
  205.     empty, the first byte in the file matches. Then PATCH22 displays
  206.     the search string.
  207.  
  208.     Next it moves the file pointer Offset bytes from the start of the
  209.     found search string. (If the Offset is negative, PATCH22 will move
  210.     backwards.)
  211.     Then it will display the context with the bytes selected for modi-
  212.     fication highlighted. PATCH22 will also display the new text, and
  213.     prompt for confirmation of the patch.
  214.  
  215.     The file will be unchanged in size, unless the patch extends beyond
  216.     the current end of the file. The time and date stamp of the file are
  217.     updated.
  218.  
  219.     Example 1: replace a text with a new text
  220.     *1?\he8d30e?\h909090?         Only one patch is requested.
  221.  
  222.     Example 2: modify text at a certain offset from an identification text
  223.     168*1?<gr_>?\h010a00b0?       Modify the 4 bytes at offset 168 (decimal)
  224.                                   from the start of <gr_>. Don't make more
  225.                                   than one patch.
  226.  
  227.     Example 3: search for a certain text.
  228.     ?\h303132??                   PATCH22 will look for 012 (which has
  229.                                   hexadecimal ASCII code 30,31,32). PATCH22
  230.                                   will display the context without any
  231.                                   highlights, since the replace string is
  232.                                   empty. If if the patch is confirmed,
  233.                                   none will be made (although PATCH22 will
  234.                                   report it as a patch).
  235.  
  236.     Example 4: modify a text at a certain location in the file.
  237.     0x131d??\h707070?             There is no search string, so the first
  238.                                   byte will match. Then at offset 131d
  239.                                   from the start the text ppp will be
  240.                                   written. Note that this will overwrite
  241.                                   whatever is at offset 131d..131f.
  242.                                   With an empty search string, there will
  243.                                   be only one search, and hence not more
  244.                                   than one possible patch.
  245.  
  246.     Example 5: case insensitive patching.
  247.     i?\x73ymbol?symbol?           The search string is converted to upper-
  248.                                   case before the escape sequences are
  249.                                   converted. So here the search string
  250.                                   becomes sYMBOL. The first letter must match
  251.                                   exactly, the rest is case insensitive.
  252.                                   Examples of matching words are sYmBol and
  253.                                   sYMBol, a non matching word is Symbol.
  254.  
  255.  
  256.     4. Some notes.
  257.     ___________________________________________________________________
  258.  
  259.     I have used PATCH22 to write a configuration program for PC-GIVE
  260.     (an econometric program). In the help code, for example, the
  261.     configurable data is preceded by a signature. Using PATCH22, the
  262.     data after the signature can be modified in the executable file.
  263.     Of course the signature has to be unique if you want to do a silent
  264.     patch.
  265.  
  266.     NOTE that LINK has the capability to remove sequences of
  267.     repeated bytes (/Exepack). So make sure that you initialize the
  268.     configurable data to have different bytes.
  269.  
  270.     PATCH22 has a very simple password protection scheme, which
  271.     I shall use as an illustration.
  272.     By default there is no password, but when a password has been
  273.     installed, it has to be the first argument on the command line,
  274.     for PATCH22 to execute.
  275.  
  276.     The declaration in PATCH22.c looks like:
  277.  
  278.     char  sP22[] = { '«','p','2','2','_','»' };              /* signature */
  279.     char  sPassword[] = "\0 gf ggv aewf bvsbago";/* password: 21 chars+\0 */
  280.         /* leading \0 indicates no password; rest avoids .exe compression */
  281.  
  282.     Of course, you must be certain that the two strings are stored
  283.     consecutively in the executable (otherwise make it into one string).
  284.     Do not write
  285.     char  sPassword[22] = "";
  286.     This, in combination with /E, cannot be patched.
  287.     In this example «p22_» is the signature, written like this to
  288.     avoid the ending '\0'.
  289.  
  290.     To set the password to "user":
  291.         PATCH22 patch22.exe 6?«p22_»?user\0?
  292.     The 6 is the offset from the start of «p22_».
  293.     Then, to change the password:
  294.         PATCH22 user patch22.exe 6?«p22_»?anonymous\0?
  295.  
  296.  
  297.     If you have any useful (and legal!) patches of interest, I look
  298.     forward to receiving them. They can then be included with PATCH22.
  299.  
  300.  
  301.     5. License, warranty and disclaimer.
  302.     ___________________________________________________________________
  303.  
  304.     PATCH22 is written by Jurgen A. Doornik for the IBM PC using
  305.     DOS 2.0 or later. You may distribute PATCH22 given these
  306.     restrictions:
  307.  
  308.     o  the program shall be supplied in its original, unmodified
  309.        form, which includes this documentation;
  310.  
  311.     o  no fee is charged;
  312.  
  313.     o  the program may be included, or bundled, with any other
  314.        programs/products (including for-profit products) on the
  315.        condition that I shall receive one copy of the program/
  316.        product (as given/sold), and an update each time PATCH22
  317.        is bundled with the update.
  318.  
  319.     o  You may use and modify the source code for personal pur-
  320.        poses only, and on the condition that I shall receive
  321.        a copy of the modified version.
  322.  
  323.     For any other use contact me.
  324.  
  325.  
  326.  
  327.     Jurgen Doornik        BITNET: ECONZ@UK.AC.OX.VAX
  328.     Nuffield College
  329.     Oxford OX1 1NF
  330.     United Kingdom
  331.  
  332.  
  333.     DISCLAIMER:
  334.     I shall not be responsible for any damages or inconveniences
  335.     incurred due to the usage of PATCH22, nor to the usage of
  336.     files patched with PATCH22. I shall not be liable if PATCH22
  337.     is used to patch files illegally. More formally:
  338.  
  339.     IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW WILL JURGEN DOORNIK BE
  340.     LIABLE TO YOU FOR DAMAGES, INCLUDING ANY LOST PROFITS, LOST MONIES, OR
  341.     OTHER SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
  342.     USE OR INABILITY TO USE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR
  343.     DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY THIRD PARTIES)
  344.     THESE PROGRAMS, EVEN IF YOU HAVE BEEN ADVISED OF THE POSSIBILITY OF
  345.     SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  346.  
  347.  
  348.     6. Revision history.
  349.     ___________________________________________________________________
  350.  
  351.      8-08-91: released version 1.2
  352.     22-07-91: - The date/time stamp of a file is reset if any patches
  353.                 are made.
  354.               - Added (simple) password protection option, see ch 4.
  355.                 Maximum password length is 21 characters (excl. trailing \0).
  356.      7-07-91: - If user chooces Quit, now breaks out of while loop, instead
  357.                 of spooling to end of file.
  358.               - Corrected bug pointed out by Ernst Raedecker of Amsterdam:
  359.                 find function did not allow for search string matching
  360.                 within itself. EG. file PIET containing "wwwp bevalt", then
  361.                 patch22 PIET ?wwp?ord?
  362.                 failed.
  363.                 This is fixed by doing a fseek backwards after a partially
  364.                 successful match. As Ernst pointed out, the search can be
  365.                 done more efficiently.
  366.                 Thanks a lot for your comments, Ernst!
  367.               - Now the next search continues one byte after the start of
  368.                 the previous match.
  369.     12-05-91: released version 1.1
  370.  
  371.